I'm recording audio into a wav file and also stream the same audio to the speakers (c++
, vs2010
, win7
).
when i hear it in the speakers i can hear the audio clear, but when i write it to a wav file i get a weird ticking/electricity noise added to the audio, i try to open the file using audacity and i can clearly see that there is a peak every 0.05 sec.
i don't know from where the noise is been added can you help me?
i added the writing into a file from my code:
writeWav(char *filename,short *data)
{
FILE *wav;
wav = fopen(filename,"ab+");
for(int i=0;i<1024;i++)
{
writeLE(data[i],2,wav);
}
fclose(wav);
}
void writeLE(short data,int nBytes,FILE *wav) //write in little-endian
{
unsigned buf;
while(nBytes > 0)
{
buf = word & 0xff;
fwrite(&buf,1,1,wav);
nBytes--;
word >>= 8;
}
}
the function writeWav
is been called every time a packet is received (size = 1024).