How to determine samples count in ADPCM wav file?

1k Views Asked by At

I see no such field in canonical WAV structure, but maybe it possible to use existing fields for that?

I know that we can calc samples count for PCM stream easy (raw_sound_data_size / (bits_pers_sample / 8)), but what to do with ADPCM?

enter image description here

1

There are 1 best solutions below

5
On

Generally Subchank2Size is a size of data in bytes. And bitsPerSample how many bits in sample. So the number of samples should be:

samples = Subchank2Size / channels / ( bitsPerSample / 8 ).

Its true for uncompressed data

ADPCM data saved in "blocks". The block has three parts, the header, data, and padding. The three together are <nBlockAlign> bytes.

Header

typedef struct adpcmblockheader_tag {
  BYTE bPredictor[nChannels];
  int iDelta[nChannels];
  int iSamp1[nChannels];
  int iSamp2[nChannels];
} ADPCMBLOCKHEADER;

Data

The data is a bit string parsed in groups of (wBitsPerSample * nChannels).

Padding

Bit Padding is used to round off the block to an exact byte length.

More info about decoding ADPCM format can be found here

Unfortunately it seems there is no way to find exact samples count without enumerate all blocks.