1

I'm writing a program (c++, vs2010,win7) that records audio into a wav file. When I try to hear the audio it has a lot of white noise. I tried to reopen the file with another program that I wrote. The only thing this program does is :

Char buffer[8000*60*2] = {} 
File *wav, *out
Wav = fopen ("raw", "r+") 
Out = fopen("out", "a+") 
fread(buffer, sizeof (char) *8000*60*2,1,wav)
fwrite(buffer, sizeof (char) *8000*60*2,1,out) 
fclose (wav) 
fclose (out) 

After I pass the raw data through this program I can hear a small part of the original wav file without any noise(i open this in audacity as raw data). My problem is that I'm not changing anything in the data just writing it again and like a magic I can hear clearly. What am I missing? I don't make any change of the data. When I write the data I write it as a short var. data is short fwrite(data, 1024,1,wav)

4

1 回答 1

1

在编写 WAVE 文件时,很多事情可能会导致它产生噪音。以下是您应该寻找的几件事:

限制值

vanilla WAVE 文件有一个 16 位数据值(如果是立体声,则为两个值),因此如果您放大这些值和它们超过了该限制,那么您将获得一个随机*值,因此在写入文件时会产生噪音。

用二进制写

正如罗杰在原始问题的评论中提到的那样,以二进制形式编写很重要,因为如果您尝试使用标准“r”写入文件,您只会得到很多白噪声。

缺少标题

有时,如果您忘记了标题,您可能还会在输出 WAVE 文件中获得噪音。

希望这会有所帮助。

于 2017-10-26T18:08:19.603 回答