数字混音原理

来源:互联网 发布:淘宝孕妇装取名 编辑:程序博客网 时间:2024/05/02 03:05
计划在新版本的“语音合成助手”(iphone上appstore中可以下载这款软件)中加入混音技术,目前正在调研这方面的知识,现转载一篇文章,以备查看。

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 Brespectively, the range is between 0 and 255. Where A and B are the
Sample Values (Each raw data) And store theresultant into the Y

If Both the samples Values are possitve

Y = A + B - A * B /255 

Where Y is the resultant signal whichcontains both signal A and B, merging two audio streams into single 
stream by this method solves the problem ofoverflow 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.

Add the Header to the Resultant (mixed) dataand play back.

If some thing is unclear and ambigious letme know.

Regards
Ranjeet Gupta.

还有简单C程序示意代码,但是其中包含了核心算法:

#include 
#include 
#include 
#include 

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

pcm1 = fopen(argv[1],"r");
pcm2 = fopen(argv[2],"r");

strcpy (mixname, argv[1]);
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;
}

原创粉丝点击