我正在合并两个pcm数据,结果pcm有额外的grrrrrrrrrr噪音。我的代码是:
int main(void)
{
FILE *rCAudio;
FILE *raudio;
FILE *wtest;
rCAudio=fopen("Audio1.pcm","rb"); //Reading first pcm file
if(rCAudio==NULL)
cout<<"Errr";
raudio=fopen("Audio2.pcm","rb"); //Reading second pcm file
if(raudio==NULL)
cout<<"Errr";
fopen_s(&wtest,"AudioMerge.pcm","ab"); // Writing final pcm file
short* first= new short[1792];;
short* second= new short[1792];;
short* merge = new short[1792];
short sample1,sample2;
while(1)
{
fread(first,2,1792,rCAudio);
fread(second,2,1792,raudio);
for(int j=0;j<1792;j++)
{
sample1 = first[j];
sample2 = second[j];
int mixedi=(int)sample1 + (int)sample2;
if (mixedi>32767) mixedi=32767;
if (mixedi<-32768) mixedi=-32768;
merge[j] =(short)mixedi;
}
fwrite(merge,2,1972,wtest);
}
}
答案 0 :(得分:0)
我得到了解决方案,问题是: 我在BYTE中一次写了4096字节的Audio1.pcm,在BYTE中一次写了4096字节的Audio2.pcm。但我一次只能读取1972个字节。
所以我通过在BYTE中一次读取4096个字节来纠正它,并在BYTE中一次用4096个字节保存第三个合并文件。