1

I'm learning how to read WAV files in C++, and extract data according to the header. I have a few WAV files lying around. By looking at the header of all of them, I see that they all follow the rules of wave files. However, files recordings produced by TeamSpeak are weird, but they're still playable in media players.

So looking at the standard format of WAV files, it looks like this:

enter image description here

So in all files that look normal, I get legitimate values for all the values from "AudioFormat" up to "BitsPerSample" (from the picture). However, in TeamSpeak files, ALL these values are exactly zero.

This, but the first 3 values are not zero. So there's "RIFF" and "WAVE" in the first and third strings, and the ChunkSize seems legit.

So my question is: How does the player know anything about such a file and recognize that this file is mono or stereo? The sample rate? Anything about it? Is it like there's something standard to assume when all these values are zero?


Update I examined the file with MediaInfo and got this:

General
Complete name                            : ts3_recording_16_10_02_17_53_54.wav
Format                                   : Wave
File size                                : 2.45 MiB
Duration                                 : 13 s 380 ms
Overall bit rate mode                    : Constant
Overall bit rate                         : 1 536 kb/s

Audio
Format                                   : PCM
Format settings, Endianness              : Little
Format settings, Sign                    : Signed
Codec ID                                 : 1
Duration                                 : 13 s 380 ms
Bit rate mode                            : Constant
Bit rate                                 : 1 536 kb/s
Channel(s)                               : 2 channels
Sampling rate                            : 48.0 kHz
Bit depth                                : 16 bits
Stream size                              : 2.45 MiB (100%)

Still though don't understand how it arrived at these conclusions.

Scott Stensland
  • 26,870
  • 12
  • 93
  • 104
The Quantum Physicist
  • 24,987
  • 19
  • 103
  • 189
  • In such case these wav files are compressed. – VuVirt Oct 02 '16 at 16:29
  • @VuVirt Actually it doesn't look compressed for many reasons. First, the file is really huge. Check the sample I provided. It's like 13 seconds and has size of 2.5 MB. Second, I'm able to convert it to mp3 with libmp3lame, which normally doesn't decode anything, just reads PCM samples (AFAIK). – The Quantum Physicist Oct 02 '16 at 16:36
  • http://www-mmsp.ece.mcgill.ca/documents/audioformats/wave/wave.html – VuVirt Oct 02 '16 at 16:37
  • I think libmp3lame will decode mp3. I also think you need to examine SubFormat as perthe above link. – VuVirt Oct 02 '16 at 16:37
  • @VuVirt Thanks. Let me read that and report here. – The Quantum Physicist Oct 02 '16 at 16:38
  • @VuVirt I mean with decode, not from mp3, but from those weird WAV formats that are not standard PCM *to* mp3. – The Quantum Physicist Oct 02 '16 at 16:38
  • What is the exact AudioFormat value? – VuVirt Oct 02 '16 at 17:07
  • @VuVirt zero... really zero! If you don't believe that, please feel free to look at the sample. I provided one in the question. – The Quantum Physicist Oct 02 '16 at 17:38
  • This means WAVE_FORMAT_UNKNOWN. I'll be able to examine the sample tomorrow. – VuVirt Oct 02 '16 at 17:47
  • @VuVirt Thank you. I'd be grateful. But my question is: All the values starting from AudioFormat and ending with BitsPerSample are zero. What does it mean "WAVE_FORMAT_UNKNOWN"? How does the player decide anything about this kind of file? How does it play it? – The Quantum Physicist Oct 02 '16 at 17:48
  • Can you try to examine the file with MediaInfo from here: http://mediaarea.net/en/MediaInfo – VuVirt Oct 02 '16 at 17:52
  • https://msdn.microsoft.com/en-us/library/windows/desktop/dd317599(v=vs.85).aspx. Here it says that wave format unknown is set for media subtype DTS – VuVirt Oct 02 '16 at 17:56
  • @VuVirt I added the information from MediaInfo. Please take a look at it. – The Quantum Physicist Oct 02 '16 at 18:00
  • If it's a dts wav then I think that players examine the actual data without taking into account the header itself. https://wiki.multimedia.cx/index.php?title=DTS – VuVirt Oct 02 '16 at 18:06
  • @VuVirt Oh! Let me read about that a little and report. Thanks for the hint. – The Quantum Physicist Oct 02 '16 at 18:11
  • Teamspeak uses speex and opus audio cosecs. You can try to examine those too. – VuVirt Oct 02 '16 at 18:27
  • Or maybe those files contain raw PCM data withoutany wave headers. – VuVirt Oct 02 '16 at 18:36
  • @VuVirt Actually the "RIFF" and "WAVE" and the size of the data is available in the file... but the second chunk is zeros. I don't know what that means. – The Quantum Physicist Oct 02 '16 at 18:55
  • @VuVirt I found something interesting... instead of "fmt " in Subchunk1ID, it says "JUNK"... so apparently all these zeros don't mean anything... I'm wondering whether a player just assumes everything about such a file. – The Quantum Physicist Oct 02 '16 at 19:05
  • It seems that the JUNK chain is added for some padding reasons. Can you check if you can find the fmt chunk later in the file and parse it properly? – VuVirt Oct 02 '16 at 19:31
  • You can read about junk chain here: http://netghost.narod.ru/gff/vendspec/micriff/ms_riff.txt – VuVirt Oct 02 '16 at 19:33
  • @VuVirt I found it... ffs this is getting crazy... it's getting way more complicated than I thought. Now I have to split my structs and modify all the methods... Thanks for the help. I just hope there's no more surprises. Btw, do you know where I can find a "catalog" of all possible AudioFormats? I downloaded some files and they have AudioFormat code 85, which I couldn't find anywhere. Would you know what that's about or where I could find info about it? – The Quantum Physicist Oct 02 '16 at 19:54
  • http://www.onicos.com/staff/iz/formats/wav.html – VuVirt Oct 02 '16 at 20:15
  • @VuVirt Absolutely. You helped me reach the answer. :) – The Quantum Physicist Oct 02 '16 at 20:47

1 Answers1

0

After examining your file with a hex editor with WAV binary templates, it is obvious that there is an additional "JUNK" chunk before the "fmt" one (screenshot attached). The JUNK chunk is possibly there for some padding reasons, but all it's values are 0s. You need to seek (fseek maybe) the wav file in your code for the first occurrence of "fmt" bytes and parse the WAVEFORMATEX info from there.

enter image description here

VuVirt
  • 1,887
  • 11
  • 13