软件混音的实现
2010-01-07 14:22
169 查看
软件混音的实现
声明:这篇文章是我从一个网站上看到的,收藏到这里以备将来需要!
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 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;
}
相关文章推荐
- 软件混音的实现
- 软件混音的实现
- 使用Virtual Audio Cable软件实现电脑混音支持电脑录音
- 软件混音的实现
- 软件混音的实现
- 软件混音的实现
- 软件混音的实现
- 使用Virtual Audio Cable软件实现电脑混音支持电脑录音
- Windows phone 北京地铁软件实现
- Python结合wxPython实现身份证更新换代、显示基本公民信息软件
- iOS 软件更新代码实现
- 计算器软件的代码实现
- 使用C#的WebService实现客户端软件在线升级
- Android应用之个人应用软件开发(3)【SQLite数据库及理财功能实现】
- 利用Directsound编程实现实时混音
- 用socket来写一个聊天软件吧(三)实现发送不同的消息
- 采用软件nginx实现web服务器集群
- 软件架构:Quartz的个性实现
- 正在准备写一个Java实现的HTTP的负载均衡软件