我正在尝试实现一个混合钢琴样本的软件。我想创建一个包含一种声音、另一种声音和两者混合的 wav 文件。
我在一秒钟内截断样本,所以我有以下内容:[一秒钟的声音 1][一秒钟的声音 2][一秒钟的声音 1 + 声音 2]
问题是每次过渡都有一个奇怪的声音伪影。有人知道它来自哪里吗?
提前致谢。
这是我正在使用的代码:
#include "stdafx.h"
#include <cstdlib>
#include <sndfile.h>
int _tmain(int argc, _TCHAR* argv[])
{
SF_INFO sInfo1;
SF_INFO sInfo2;
SF_INFO sInfo3;
SNDFILE *sFile1 = NULL;
SNDFILE *sFile2 = NULL;
SNDFILE *sFile3 = NULL;
double *buff1;
double *buff2;
double *buff3;
sf_count_t count1 = 0;
sf_count_t count2 = 0;
sf_count_t count3 = 0;
buff1 = (double*)malloc(88200*sizeof(double));
buff2 = (double*)malloc(88200*sizeof(double));
buff3 = (double*)malloc(88200*sizeof(double));
sInfo1.format = 0;
sInfo2.format = 0;
sFile1 = sf_open("C:/samples/mezzo forte/mcg_mf_022.wav", SFM_READ, &sInfo1);
sFile2 = sf_open("C:/samples/mezzo forte/mcg_mf_046.wav", SFM_READ, &sInfo2);
sInfo3 = sInfo2;
sFile3 = sf_open("C:/samples/test1.wav", SFM_WRITE, &sInfo3);
count1 = sf_read_double(sFile1, buff1, 88200);
count2 = sf_read_double(sFile2, buff2, 88200);
for(int i=0; i<88200; i++)
{
buff3[i] = buff1[i] + buff2[i] - ( buff1[i] * buff2[i] );
}
count1 = sf_write_double(sFile3, buff1, 88200);
count2 = sf_write_double(sFile3, buff2, 88200);
count3 = sf_write_double(sFile3, buff3, 88200);
sf_close(sFile1);
sf_close(sFile2);
sf_close(sFile3);
free(buff1);
free(buff2);
free(buff3);
//getchar();
return 0;
}