I am trying to implement a piece of software that mix piano samples. I want to create a wav file containing one sound, the other and a mix of both.
I trunc the samples at one second so I have the following : [one second of sound 1][one second of sound 2][one second of soud 1 + sound 2]
The problem is that there is a weird sound artifact at each transition. Does somebody know where it comes from ?
Thanks in advance.
Here is the code I am using :
#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;
}