Jump to content

View more

Image of the Day

Boxes as reward for our ranking mode. ヾ(☆▽☆)
#indiedev #gamedev #gameart #screenshotsaturday https://t.co/ALF1InmM7K
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now

XAudio2 - Size of FMT Chunk for ADPCM Files larger than WAVEFORMATEXTENSIBLE struct

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 pknight   Members   


Posted 01 July 2013 - 03:38 AM

I'm writing a parser for wave files in C++, designed to work with XAudio2.


I have no problems reading in PCM wave files. My parser extracts the chunk size for the format chunk of a PCM file as 16 bytes. I copy this data into a WAVEFORMATEX or WAVEFORMATEXTENSIBLE struct and it fills struct as I expect.


I used the "AdpcmEncode" utility that comes with the June 2010 DirectX SDK to encode my PCM file to ADPCM.


Now my parser extracts the size of the format chunk as 50 bytes.


I notice that the size of the WAVEFORMATEXTENSIBLE struct is 40 bytes. Is there something wrong with my parser here or is there another type of struct that I should be copying this data to?


The parser seems to be working OK as from the ADPCM file I extract wFormatTag = 2 (i.e. ADPCM encoding) and cbSize = 32 (i.e. 32 extra bytes + 18 bytes for the WAVEFORMATEX struct = 50 bytes total). I'm wondering why this chunk won't fit into a WAVEFORMATEXTENSIBLE struct and what the extra 10 bytes of data might be for.


Any help here will be much appreciated.

#2 pknight   Members   


Posted 01 July 2013 - 04:34 AM

Just trying to figure this out myself as I go . . . 


From - http://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.ixaudio2.ixaudio2.createsourcevoice(v=vs.85).aspx


Note  Data formats such as ADPCM that require more information than provided by WAVEFORMATEX have aWAVEFORMATEX structure as the first member in their format structures. When you create a source voice with one of those formats, cast the format's structure as a WAVEFORMATEX structure and use it as the value forpSourceFormat.


I assumed I'd be using WAVEFORMATEXTENSIBLE, but it doesn't actually say that here.


From - http://msdn.microsoft.com/en-us/library/windows/desktop/ee415711(v=vs.85).aspx


In order to use ADPCM encoded data in XAudio2, you need to initialize a ADPCMWAVEFORMAT structure with ADPCM specific values, and pass it as an argument to IXAudio2::CreateSourceVoice when you create a source voice. For an example of loading and playing a sound in XAudio2, see How to: Play a Sound with XAudio2.


Getting closer. There doesn't appear to be an MSDN page for ADPCMWAVEFORMAT, however the Japanese site has:



Edited by pknight, 01 July 2013 - 04:35 AM.

#3 Ashaman73   Members   


Posted 01 July 2013 - 04:43 AM

I think, that the additional 10 bytes are meta-information for the specific format appended to WAVEFORMATEXTENSIBLE, accordingly to this page. Quote:


If wFormatTag = WAVE_FORMAT_EXTENSIBLE, set cbSize to sizeof(WAVEFORMATEXTENSIBLE)-sizeof(WAVEFORMATEX) plus the size of any format-specific data that is appended to the WAVEFORMATEXTENSIBLE structure.





Gnoblins: Website - Facebook - Twitter - Youtube - Steam Greenlit - IndieDB - Gamedev Log

#4 pknight   Members   


Posted 01 July 2013 - 04:50 AM

Thanks for the reply Ashaman. I think that I have got to the bottom of what the format specific data is for ADPCM files and exactly what type of struct I need to fill. Here are my comments below in case it helps anyone else with the same question:
This is from the Japanese MSDN page, here http://translate.google.com.au/translate?hl=en&sl=ja&u=http://msdn.microsoft.com/ja-jp/library/cc677007(v%3Dvs.85).aspx&prev=/search%3Fq%3Dadpcmwaveformat%2Bmsdn%26biw%3D1067%26bih%3D460
typedef struct adpcmwaveformat_tag {
WORD wSamplesPerBlock;
WORD wNumCoef;


(apologies for the formatting)


Now we have in this struct:


WAVEFORMATEX = 18 bytes, as usual

2 x WORD = 2 x 2 bytes


Then a variable size component which will be 7 x sizeof(ADPCMCOEFSET), which is 7 x 4 bytes, or 28 bytes. I got the 7 as per the msdn site's comment:



wNumCoef The number of entries in aCoef. Note (AdpcmEncode) ADPCM command line encoder always, seven entries are included in the array of data compression factor of the ADPCM data that is generated by.


So total size = 18 + 4 + 28 = 50 bytes, which is what my parser is pulling out of the ADPCM file.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.