Problem with .Wav Speex header

Apr 6, 2013 at 1:21 PM
I have installed Speex Voice ACM Codec 1.0.1.1 codec and they seem to have DIFFERENT .wav header then one described in C# code in this NSpeex package.

I can read .wav files created with “Speex Voice ACM Codec 1.0.1.1”, and decode them successfully, but when I create .wav files, “Speex Voice ACM Codec 1.0.1.1” does not recognize my header. I checked with Hex editor, and there are some bytes in .wav header that “Speex Voice ACM Codec 1.0.1.1” creates, and I do not create, and they are different then what is in NSpeex.PcmWaveWriter class.

So, I agree with this part:
raf.Write(WAVE_FORMAT_SPEEX); // Format tag: Speex
raf.Write((short)channels); // Number of channels
raf.Write(sampleRate); // Sampling frequency
raf.Write((CalculateEffectiveBitrate(mode, channels, quality) + 7) >> 3); // Average bytes per second
raf.Write((short)CalculateBlockSize(mode, channels, quality)); // Blocksize of data
raf.Write((short)quality); // Bits per sample

But, not with the rest what is in the code of NSpeex.PcmWaveWriter class.

In Hex editor I see (after above mentioned part) this in .wav file created by “Speex Voice ACM Codec 1.0.1.1”:
//byte[] speexSpecific ={
// 0x00, 0x01, 0x02, 0x00,0x0a, 0x00,
// 0x00, 0x00, 0xf4, 0x01,
// 0x03, 0x00, 0x00, 0x00};
But I do not know what is that and how to create .wav header to be compatible with “Speex Voice ACM Codec 1.0.1.1”.
Again, I can decode their .wav files, and create my .wav files that I can decode, but that codec seems to not recognize my .wav header.

Speex is supposed to be “Open source”, can someone reveal the secret bytes in .wav (speex) header?
Apr 9, 2013 at 2:51 PM
I found it! This explains exactly 14 bytes I was missing (check SPEEX_WFX_EXTRA_BYTES=14)


//typedef struct tWAVEFORMATEX
//{
// WORD wFormatTag; / format type /
// WORD nChannels; / number of channels (i.e. mono, stereo...) /
// DWORD nSamplesPerSec; / sample rate /
// DWORD nAvgBytesPerSec; / for buffer estimation /
// WORD nBlockAlign; / block size of data /
// WORD wBitsPerSample; / number of bits per sample of mono data /
// WORD cbSize; / the count in bytes of the size of /
// / extra information (after cbSize) /
//} WAVEFORMATEX, *PWAVEFORMATEX, NEAR *NPWAVEFORMATEX, FAR *LPWAVEFORMATEX;

//#define WAVE_FORMAT_SPEEX 0xa109
//#define SPEEXWAVEFORMAT_VERSION 0x0100 // 1.0
//#define SPEEX_WFX_EXTRA_BYTES 14

///*
// wfx.wFormatTag = WAVE_FORMAT_SPEEX
// wfx.nChannels = 1,2
// wfx.nSamplesPerSec = 8000,16000,32000
// wfx.nAvgBytesPerSec = ...
// wfx.nBlockAlign = CBR? ... : 1
// wfx.wBitsPerSample = 16
// wfx.cbSize = SPEEX_WFX_EXTRA_BYTES

// For VBR:
// wfx.nAvgBytesPerSec = SPEEX_BITRATE_24600;
//*/

//typedef struct speexwaveformat_tag
//{
// WAVEFORMATEX wfx;

// WORD nVersion; // SPEEXWAVEFORMAT_VERSION
// WORD nFramesPerBlock;// 1..
// WORD nQuality; // 0..10
// WORD nMode; // SPEEX_MODE_...
// WORD nVbrQuality; // 0..1000 ,float [0.00 , 10.00]
// WORD nComplexity; // 1..10
// WORD nFlags; // SPEEX_FLAG_...
//} SPEEXWAVEFORMAT;
// CBR,ABR,VBR

//#define SPEEX_MODE_CBR 0
//#define SPEEX_MODE_ABR 1
//#define SPEEX_MODE_VBR 2

//// flags
//#define SPEEX_FLAG_VAD 0x0001
//#define SPEEX_FLAG_DTX 0x0002

//#define SPEEX_DEF_QUALITY 3
//#define SPEEX_DEF_COMPLEXITY 3
//#define SPEEX_DEF_VBR_QUALITY 500