• 博客访问： 2412191
• 博文数量： 401
• 博客积分： 12926
• 博客等级： 上将
• 技术积分： 4567
• 用 户 组： 普通用户
• 注册时间： 2009-02-22 14:51

2015年（16）

2014年（4）

2013年（12）

2012年（82）

2011年（98）

2010年（112）

2009年（77）

2012-09-27 17:11:48

Step 1,

Get the Raw data of the two files, (Example, of the sample 8bit and 8Kh, means one sample is of
8bit)

Step 2

Let the two audio signal be A and B respectively, the range is between 0 and 255. Where A and B are the
Sample Values (Each raw data) And store the resultant into the Y

If Both the samples Values are possitve

Y = A + B - A * B / 255

Where Y is the resultant signal which contains both signal A and B, merging two audio streams into single
stream by this method solves the problem of overflow and information loss to an extent.

If the range of 8-bit sampling is between -127 to 128

If both A and B are negative Y = A +B - (A * B / (-127))
Else Y = A + B - A * B / 128

Similarly for the nbit (ex 16bit data)

For n-bit sampling audio signal

If both A and B are negative Y = A + B - (A * B / (-(2 pow(n-1) -1)))
Else Y = A + B - (A * B / (2 pow(n-1))

Step 3.

If some thing is unclear and ambigious let me know.

Regards
Ranjeet Gupta.

#include
#include
#include
#include

int main(int argc,char *argv[]) {
char mixname;
FILE *pcm1, *pcm2, *mix;
char sample1, sample2;
int value;

pcm1 = fopen(argv,"r");
pcm2 = fopen(argv,"r");

strcpy (mixname, argv);
strcat (mixname, "_temp.wav");
mix = fopen(mixname, "w");

while(!feof(pcm1)) {

sample1 = fgetc(pcm1);
sample2 = fgetc(pcm2);

if ((sample1 < 0) && (sample2 < 0)) {
value = sample1 + sample2 - (sample1 * sample2 / -(pow(2,16-1)-1));
}else{
value = sample1 + sample2 - (sample1 * sample2 / (pow(2,16-1)-1));
}

fputc(value, mix);
}

fclose(pcm1);
fclose(pcm2);
fclose(mix);

return 0;
}