如何混合音频样本?
我的问题并不完全与编程相关,但尽管如此,我认为 SO 是正确的提问地点。
在我的程序中,我生成一些音频数据并将曲目保存到 WAV 文件中。使用一个声音发生器一切都可以正常工作。但现在我想添加更多生成器并将生成的音频数据混合到一个文件中。不幸的是,它比乍一看更复杂。 此外,我没有找到关于如何混合一组音频样本的太多有用信息。
那么有谁可以给我建议吗?
编辑:
我正在用 C++ 编程。但这并不重要,因为我对混合两个音轨背后的理论感兴趣。我遇到的问题是我不能简单地总结样本,因为这通常会产生失真的声音。
My question is not completely programming-related, but nevertheless I think SO is the right place to ask.
In my program I generate some audio data and save the track to a WAV file. Everything works fine with one sound generator. But now I want to add more generators and mix the generated audio data into one file. Unfortunately it is more complicated than it seems at first sight.
Moreover I didn't find much useful information on how to mix a set of audio samples.
So is there anyone who can give me advice?
edit:
I'm programming in C++. But it doesn't matter, since I was interested in the theory behind mixing two audio tracks. The problem I have is that I cannot just sum up the samples, because this often produces distorted sound.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为您的问题是,对于您添加的每个音频源,您都必须降低级别。
如果应用程序将控制权交给用户,只需让他们直接控制级别即可。热是他们的责任,而不是你的。这就是“求和”。
如果混合是自动进行的,您即将踏上旅程。如果没有限制的话,您可能需要压缩。 (限制是压缩的极端版本。)
请注意,您对音频所做的任何操作(包括压缩和限制)都是一种失真形式,因此您将导致音频着色。您选择的压缩和限制算法将影响声音。
由于您不是实时生成音频,因此您可以进行“砖墙”限制。那是因为你对级别有预知。实时限制更加有限,因为你无法知道接下来会发生什么——你必须做出反应。
这是音乐、音效、声音还是什么?
程序员这里一直在处理这个问题。
I assume your problem is that for every audio source you're adding in, you're having to lower the levels.
If the app gives control to a user, just let them control the levels directly. Hotness is their responsibility, not yours. This is "summing."
If the mixing is automated, you're about to go on a journey. You'll probably need compression, if not limiting. (Limiting is an extreme version of compression.)
Note that anything you do to the audio (including compression and limiting) is a form of distortion, so you WILL have coloration of the audio. Your choice of compression and limiting algorithms will affect the sound.
Since you're not generating the audio in real time, you have the possibility of doing "brick wall" limiting. That's because you have foreknowledge of the levels. Realtime limiting is more limited because you can't know what's coming up--you have to be reactive.
Is this music, sound effects, voices, what?
Programmers here deal with this all the time.
混合音频样本意味着将它们添加在一起,仅此而已。通常,您会将它们添加到更大的数据类型中,以便您可以检测溢出并在转换回目标缓冲区之前限制值。如果您事先知道将会溢出,那么您可以在相加之前缩放它们的幅度 - 只需乘以 0 到 1 之间的浮点值,再次记住精度问题,也许首先转换为更大的数据类型。
如果您遇到本文未解决的特定问题,请随时更新您的原始问题。
Mixing audio samples means adding them together, that's all. Typically you do add them into a larger data type so that you can detect overflow and clamp the values before casting back into your destination buffer. If you know beforehand that you will have overflow then you can scale their amplitudes prior to addition - simply multiply by a floating point value between 0 and 1, again keeping in mind the issue of precision, perhaps converting to a larger data type first.
If you have a specific problem that is not addressed by this, feel free to update your original question.
两个样品的脏混合物
dirty mix of two samples
您从未说过什么编程语言和平台,但现在我假设 Windows 使用 C#。
http://www.codeplex.com/naudio
很棒的开源库,确实涵盖了很多内容您在大多数音频操作期间会遇到的事情。
You never said what programming language and platform, however for now I'll assume Windows using C#.
http://www.codeplex.com/naudio
Great open source library that really covers off lots of the stuff you'd encounter during most audio operations.