软件混音的实现
2005-11-07 17:36
519 查看
Symbian 6.1上实现的混音是个比较麻烦的问题,因为程序只能同时播放一个音乐,实现混音就需要程序自己来实现。下面是我从newlc上找到的一个关于PCM脉冲编码的音频信号的混音实现,其中包含了一个关键的混音算法!
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 <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
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/sw.nokia.com/id/70a2bde5-9b14-41b3-89ae-198b0d8d380d/SoundMixer_Example_v1_0.zip.html
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 <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
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/sw.nokia.com/id/70a2bde5-9b14-41b3-89ae-198b0d8d380d/SoundMixer_Example_v1_0.zip.html
相关文章推荐
- 软件混音的实现
- 使用Virtual Audio Cable软件实现电脑混音支持电脑录音
- 软件混音的实现
- 软件混音的实现
- 软件混音的实现
- 使用Virtual Audio Cable软件实现电脑混音支持电脑录音
- 软件混音的实现
- 软件混音的实现
- PlantUML —— 应用于 Eclipse 的简单快速的 UML 编辑软件,astah 很强大,UML,MAINMIND, CLASSDesign等都可以实现。
- 【jiasuba】分享:USBoot软件 实现从优盘引导系统
- 软件实现的施密特触发器
- CCSv6.0以上版本实现软件仿真
- Android 自定义控件 轻松实现360软件详情页
- HTML5进阶(二)HBuilder实现软件自动升级
- 中国象棋软件-引擎实现(四)搜索算法
- Android学习之CoordinatorLayout轻松实现360软件详情页
- 在WinForm中使用Web Services 来实现 软件 自动升级( Auto Update ) (C#)
- 围棋打谱软件中自动提子功能的实现,C/C++源码
- Android 调用已安装市场,进行软件评分的功能实现
- 用delphi 实现文件下载,可以用于软件的升级