1
votes

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 writeWavis been called every time a packet is received (size = 1024).

1
I get it from a receiver in a Udp thread the receive packets of audio. I send the same data to the speakers and to the file. I'm sure is something in that I wrote, the data is good.David

1 Answers

1
votes

It looks like your for loop is wrong.

To process 1024 items it should be:

for (int i = 0; i < 1024; i++)