编程合并音频两块 [英] Programmatically merging two pieces of audio

查看:152
本文介绍了编程合并音频两块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个不同的音频片段样品的两个数组。如果我只是以编程方式添加它们放在一起将这个是一个音频编辑套件分层一条轨道上的另一个等价?就像如果我有低音其他鼓的一个音频剪辑,我希望他们一起玩。

I have two arrays of samples of two different audio clips. If I just programmatically add them together will this be the equivalent of layering one track over another in an audio editing suite? Like if I have one audio clip of bass the other of a drum and I want them playing together.

我可能会做这样的事情:

I would probably do something like this:

 for (int i = 0; i < length_of_array; i++){
   final_array[i] = first_array[i] + second_array[i];
 }

如果它不这样做就这样,我能得到什么是正确的做法一些迹象?

If it is not done this way, could I get some indication of what would be the correct way?

推荐答案

这是一个正确的做法。合并被称为音频行话混合。

This IS a correct way. Merging is called MIXING in audio jargon.

但是:

如果您的样品很短(16位有符号) - 你将不得不使用INT(32位有符号)加法,然后手动裁剪样品。如果不这样做,你的价值观将包裹,你就会有这么多的乐趣听你做了什么:)

If your samples are short (16 bit signed) - you will have to use int (32 bit signed) for addition and then clip the samples manually. If you don't, your values will wrap and you'll have so much fun listening to what you did :)

下面来了code:

short first_array[1024];
short second_array[1024];
short final_array[1024];
for (int i = 0; i < length_of_array; i++)
{
    int mixed=(int)first_array[i] + (int)second_array[i];
    if (mixed>32767) mixed=32767;
    if (mixed<-32768) mixed=-32768;
    final_array[i] = (short)mixed;
}

在大多数情况下,你不需要任何其他为正常的音频样本,作为剪切将在极为罕见的情况发生。我从实践中谈论这个,而不是从理论。

In MOST cases you don't need anything else for normal audio samples, as the clipping will occur in extremely rare conditions. I am talking this from practice, not from theory.

这篇关于编程合并音频两块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆