0

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

Kosmo零
  • 4,001
  • 9
  • 45
  • 88

1 Answers1

1

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.

Daniel
  • 78
  • 4
  • First formula `125510 / 1 / 4` gives 31377. This is wrong since real samples count for my ADPCM file is 229504. Second `125510 / 70` gives 1793. – Kosmo零 Jan 14 '18 at 10:01
  • I got you ! Thanks anyway you for check and time . But it looks me some strange. As I know ADPCM is fixed rate codec. According to wave format should work. Most probably we missing something. I'll check deeper too and try to find answer. If so I'll post it here. It interesting to me too – Daniel Jan 14 '18 at 10:20
  • Not a problem. Your calculations may be correct for `uncompressed` streams only. For compressed streams there is different rules. – Kosmo零 Jan 14 '18 at 10:21
  • I completed answer with info found. Thank you, it was interesting question. Unfortunately I don't have time for now to check it in code. Wish you good luck. – Daniel Jan 14 '18 at 13:40
  • Thank you for you investigation. It useful info. – Kosmo零 Jan 15 '18 at 07:48