音频应用

 找回密码
 快速注册

QQ登录

只需一步,快速开始

阅读: 18785|回复: 2

[音视频] 混音软实现

[复制链接]

349

积分

2

听众

-6

音贝

音频应用

Rank: 1

积分
349
发表于 2006-6-26 | |阅读模式
音频应用公众号资讯免费发布推广
混音软实现
Hi !!!!
I am not sure weather I have fully understood your question or not, I persume that you are asking
"How can we mix two or more audio stream", If this is the question then I am explaning below the
mixing of the two audio stream (You Can Mix More Audio Stream),
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.
Add the Header to the Resultant (mixed) data and play back.
If some thing is unclear and ambigious let me 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;
}

另外,如果只是在Symbian上实现混音,在Nokia 的官方网站上,也有一个SoundMixer的examples
http://www.forum.nokia.com/info/ ... ample_v1_0.zip.html
欢迎厂家入驻,推文!免费!微信:yinpinyingyong

1196

积分

2

听众

-84

音贝

音频应用新手发布

Rank: 3

积分
1196
发表于 2006-6-26 |
混音软实现 分享
欢迎厂家入驻,推文!免费!微信:yinpinyingyong

349

积分

2

听众

-6

音贝

音频应用

Rank: 1

积分
349
 楼主| 发表于 2006-6-26 |

谢谢合鸣啊   

欢迎厂家入驻,推文!免费!微信:yinpinyingyong
您需要登录后才可以回帖 登录 | 快速注册

本版积分规则

音频应用搜索

小黑屋|手机版|音频应用官网微博|音频招标|音频应用 (鄂ICP备16002437号)

Powered by Audio app

快速回复 返回顶部 返回列表