PCM wave files with extended format chunk in header aren't recognised
If you try to encode a PCM wav file which has an extended format chunk
(of type WAVEFORMATEX), the encoder will return:
"Warning: Unrecognised format chunk in WAV header", and then an error message.
The extended format chunk is optional, but allowed by the standard.
Here is the structure of the extended format chunk
typedef struct waveformat_extended_tag {
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 extra size */} WAVEFORMATEX;
A quick solution would be to simply change the following bit of code from the
function wav_open in audio.c
if(len!=16)
{
fprintf(stderr, "Warning: Unrecognised format chunk in WAV
header\n");
return 0; /* Weird format chunk */
}
if(fread(buf,1,16,in) < 16)
{
fprintf(stderr, "Warning: Unexpected EOF in reading WAV
header\n");
return 0;
}
with the following
if(len<16)
{
fprintf(stderr, "Warning: Unrecognised format chunk in WAV
header\n");
return 0; /* Weird format chunk */
}
if(fread(buf,1,len,in) < len)
{
fprintf(stderr, "Warning: Unexpected EOF in reading WAV
header\n");
return 0;
}
optionally you could also check that:
(READ_U16_LE(buf+16) + 18) == len