混合声波(iOS 上的 CoreAudio)

发布于 2024-12-21 12:59:37 字数 532 浏览 2 评论 0原文

在我看来,CoreAudio 在混合到单个通道时将声波添加在一起。我的程序将发出合成声音。我知道每个声音的幅度。当我一起演奏它们时,我应该将它们加在一起并乘以所得的波以保持在范围内吗?我可以这样做:

MaxAmplitude = max1 + max2 + max3 //Maximum amplitude of each sound wave
if MaxAmplitude > 1 then //Over range
    Output = (wave1 + wave2 + wave3)/MaxAmplitude //Meet range
else
    Output = (wave1 + wave2 + wave3) //Normal addition
end if

我可以这样做吗?我是否应该预先分析声波以找到实际的最大幅度(因为最大值点可能与时间轴上不匹配)并使用它?

我想要的是一种方法,可以同时播放几种合成声音,而不会极大地降低音量,并且听起来无缝。如果我用几种合成乐器演奏和弦,我不想要求单个音符实际上是静音的。

谢谢。

It seems to me that CoreAudio adds sound waves together when mixing into a single channel. My program will make synthesised sounds. I know the amplitudes of each of the sounds. When I play them together should I add them together and multiply the resultant wave to keep within the range? I can do it like this:

MaxAmplitude = max1 + max2 + max3 //Maximum amplitude of each sound wave
if MaxAmplitude > 1 then //Over range
    Output = (wave1 + wave2 + wave3)/MaxAmplitude //Meet range
else
    Output = (wave1 + wave2 + wave3) //Normal addition
end if

Can I do it this way? Should I pre-analyse the sound waves to find the actual maximum amplitude (Because the maximum points may not match on the timeline) and use that?

What I want is a method to play several synthesised sounds together without reducing the volume throughout extremely and sounding seamless. If I play a chord with several synthesised instruments, I don't want to require single notes to be practically silent.

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

街角卖回忆 2024-12-28 12:59:37

在单个样本的基础上突然改变比例,这就是“if”语句所做的,听起来很糟糕,类似于剪辑。

您可以研究自适应 AGC(自动增益控制),它会更慢地改变比例因子,但仍然可能在快速瞬态期间削波或突然发生音量变化。

如果您使用 AGC 算法的前瞻来防止突然的瞬变削波,那么您的延迟将会变得更糟。

如果您确实使用 AGC,那么孤立的音符听起来可能比在和弦中演奏时的声音大得多,这可能无法正确代表音乐作品的意图(尽管这种类型的压缩在烦人的电视和广播广告中很常见)。

缩小混音器输出音量,以便音符永远不会削波或音量减小,除非乐曲指示,这将导致大量通道的混音音量大大降低(这就是为什么在收音机上正确再现古典音乐的原因)通常太安静,无法吸引足够的观众来赚足够的钱)。

这都是一个权衡。

Changing the scale suddenly on a single sample basis, which is what your "if" statement does, can sound very bad, similar to clipping.

You can look into adaptive AGC (automatic gain control) which will change the scale factor more slowly, but could still clip or get sudden volume changes during fast transients.

If you use lookahead with the AGC algorithm to prevent sudden transients from clipping, then your latency will get worse.

If you do use AGC, then isolated notes may sound like they were played much more loudly than when played in a chord, which may not correctly represent a musical composition's intent (although this type of compression is common in annoying TV and radio commercials).

Scaling down the mixer output volume so that the notes will never clip or have their volume reduced other than when the composition indicates will result in a mix with greatly reduced volume for a large number of channels (which is why properly reproduced classical music on the radio is often too quiet to draw enough viewers to make enough money).

It's all a trade-off.

早茶月光 2024-12-28 12:59:37

我不认为这是一个问题。如果您知道所有波(所有时间)的最大幅度,它应该可以工作。确保不要在每个样本的基础上改变幅度,而是针对每个“音符”进行决定。这是一个非常简单的算法,但可以满足您的需求。

I don't see this is a problem. If you know the max amplitude of all your waves (for all time) it should work. Be sure not to change the amplitude on per sample basis but decide for every "note-on". It is a very simple algorithm but could suit your needs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文