I must create a 16 bit (bit per sample), 8kHz (samplerate) mono (1 channel) wave file, of unknown time length. Most of the code do the job fine, but I have problems with the ChunkSize and Subchunk2Size bytes. I simply do not understand them. In that document it says it's 4 + (8 + SubChunk1Size) + (8 + SubChunk2Size). I just made it the size of the byte array minus 8 (It says: This is the size of the entire file in bytes minus 8 bytes for the two fields not included in this count). The SubChunk2Size, I just don't understand it. It says it must be NumSamples * NumChannels * BitsPerSample/8, it doesn't work anyway.
But also, I don't know if each one of these properties must have their bytes inverted. Because, according to this document: http://ist.uwaterloo.ca/~schepers/formats/WAV.TXT, those two properties have a "lo/hi" format. I don't know if this is true or not, since I haven't seen something like this specified in any document. So, I'm pretty much confused of what should I do with these properties. The current code of my program is the following code:
It should work according to those specifications. The problem is... it doesn't work. The audio files generated with this code seems corrupted with any media player. Why? That's what I'd like to know. There is almost no clear information about how to write WAV headers on the internet, and the information I found is quite unclear in most cases, so I come to you with hopes of clarifying things out. Thanks in advance.