开发者

Audio programming, generating an harmony

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 al开发者_JAVA百科l 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?


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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜