Well, nevermind. I just fixed it :). Modified the save function like this:
bool save()
{
int bitsPerSample = 16;
int subchunk1size = 16;
int numChannels = 1;
int subchunk2size = WaveInHdr.dwBufferLength*numChannels;
int chunksize = 36+subchunk2size;
int audioFormat = 1;
int byteRate = sampleRate*numChannels*bitsPerSample/8;
int blockAlign = numChannels*bitsPerSample/8;
fstream myFile ("test.wav", ios::out | ios::binary);
// write the wav file per the wav file format
myFile.seekp (0, ios::beg);
myFile.write ("RIFF", 4); // chunk id
myFile.write ((char\*) &chunksize, 4); // chunk size (36 + SubChunk2Size))
myFile.write ("WAVE", 4); // format
myFile.write ("fmt ", 4); // subchunk1ID
myFile.write ((char\*) &subchunk1size, 4); // subchunk1size (16 for PCM)
myFile.write ((char\*) &audioFormat, 2); // AudioFormat (1 for PCM)
myFile.write ((char\*) &numChannels, 2); // NumChannels
myFile.write ((char\*) &sampleRate, 4); // sample rate
myFile.write ((char\*) &byteRate, 4); // byte rate (SampleRate \* NumChannels \* BitsPerSample/8)
myFile.write ((char\*) &blockAlign, 2); // block align (NumChannels \* BitsPerSample/8)
myFile.write ((char\*) &bitsPerSample, 2); // bits per sample
myFile.write ("data", 4); // subchunk2ID
myFile.write ((char\*) &subchunk2size, 4); // subchunk2size (NumSamples \* NumChannels \* BitsPerSample/8)
myFile.write (WaveInHdr.lpData, WaveInHdr.dwBufferLength); // data
return true;
}
Cheers Souldrift