sizeof(waveheader.BitsPerSample) should be replaced by sizeof(short)
sizeof(waveheader.BitsPerSample)
sizeof(short)