音频编程,产生和谐

发布于 2024-11-15 23:14:58 字数 569 浏览 7 评论 0原文

我正在尝试开发一个类似于 C# 中的 tonematrix 的应用程序。我首先尝试使用 .net 和 NAudio 库,现在我尝试使用 XNA,但似乎我能得到的只是不和谐的声音。


使用 NAudio,我生成 8 个具有不同频率的简单正弦波,频率范围从 (440hz * 1) 到 (440hz * 8)。

对于 XNA,我使用同一音频文件的多个 SoundEffectInstance(如钢琴的 D4 音符),每个都有不同的音高值;音调值最多可以上升或下降一个八度。

在这两种情况下,当声音重叠时,我听到的是噪音而不是音乐。也许我全错了,这不是混合不同音调/频率的声音的问题。

我很难相信音调矩阵仅仅使用了一个“简单的正弦波合成器”,因为声音非常丰富,当它们混合在一起时,它们总是会产生和声曲调,而简单的正弦波总是听起来丑陋且不自然。我。

我创造和谐的方法是否不好?您知道tonematrix 使用的正弦波到底发生了什么吗?

I'm trying to develop an application similiar to the tonematrix in C#. I've tried first with .net and NAudio library, now I'm trying with XNA, but it seems like that all I can get is a cacophony.


With NAudio, I'm generating 8 simple sinewaves with differente frequencies, varying from (440hz * 1) to (440hz * 8).

With XNA, I'm using multiple SoundEffectInstance of the same audio file (like a D4 note of a piano), each one with a different Pitch value; the Pitch value can go up or down of a maximum of an octave.

In both cases, when the sounds overlap I'm getting noise instead of music. Maybe I got it all wrong and it is not a question of mixing sounds of varying pitch/frequency.

I find difficult to believe that the tonematrix is using nothing more than a "simple sinewave synthesizer", since the sounds are pretty rich and when they are mixed together they always generate an harmonic tune, while a simple sinewave is always sounding ugly and artificial to me.

Am I having a bad approach for creating harmonies? Do you have an idea of what is exactly happening to the sinewaves used by tonematrix?

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

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

发布评论

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

评论(2

眼趣 2024-11-22 23:14:58

我碰巧能够回答您的音乐问题,但此类问题可能最好在 https://music.stackexchange.com/。

首先是规模。这些东西通常使用五声音阶(来自维基百科:“这种音阶的任何音高都可以是以任何顺序或组合进行游戏而不会发生冲突”)。根据评论,您链接的示例使用从 A 到 A 的 D 大调五声音阶。

您会发现它不是使用直线正弦波,而是实际上使用 ADSR 信封 在开头给出令人愉悦的“冲击力”,在结尾给出(假的)“回声”。这很容易实现,因为您只需要调制幅度。

据我所知,将波形混合在一起时并没有做任何特别的事情。它很可能正在做简单的加法。

至于实现,如果您有一种生成正弦波的方法,而不是尝试对样本进行音调变换,为什么不使用 DynamicSoundEffectInstance 并为其提供正弦波呢?

XNA 的内置变调功能不太适合这项任务。您确定使用正确的值来调整它吗?

I happen to be able to answer your music questions, but these kind of questions are probably better asked on https://music.stackexchange.com/.

First of all the scale. These things generally use a pentatonic scales (from Wikipedia: "any pitches of such a scale may be played in any order or combination without clashing"). According to the comments, the example you linked uses D Major Pentatonic from A to A.

You will find that it is not using a straight up sine wave, but is in fact using an ADSR envelope to give it the pleasing "punch" at the start and (fake) "echo" at the end. This is easy to implement, as you only need to modulate the amplitude.

As far as I can tell, it is not doing anything special when mixing the waveforms together. Chances are it is doing simple addition.

As for implementation, if you have a method for generating sine waves, rather than attempting to pitch-shift a sample, why not use DynamicSoundEffectInstance and feed it your sine wave?

XNA's built-in pitch shifting isn't really well suited to this task. Are you sure you're using the correct values to tune it?

垂暮老矣 2024-11-22 23:14:58

如果您使用相同频率的倍数作为输入,则每个正弦波将比其他正弦波高一个八度。像这样将 8 个正弦波加在一起会在混合波形中产生一些非常高的峰值,因此您需要确保应用限制或减小整体音量,以免导致失真。如果没有看到您的代码,很难确定,但这可能是造成噪音的部分原因。

If you are using multiples of the same frequency as your inputs, each sine wave will be exactly one octave higher than the others. Adding together 8 sine waves like this will result some very high peaks in the mixed waveform, so you need to make sure you apply limiting or reduce the overall volume so as not to cause distortion. Without seeing your code it is hard to say for sure, but that may be part of the cause of your noise.

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