Generating Waveforms In Software

Started by
4 comments, last by PurpleAmethyst 18 years, 10 months ago
Hi, I am writing a little sound effects generator program and am trying to write some waveform generators in software. I am wondering what the most effecient way to generate the follwing waveforms in software might be sinus, sawtooth, triangle, square and noise. Noise and sinus are obvious and I've found ample information on the web about how to generate them, but was wondering about the others. I know they can be generated by summing sinus waveforms of different phases, but this seems a little bit over the top for a simple proggy. So if anyone has any tips or links I'd appreciate it! Patrick
Advertisement
the nice thing about 'creating' things in software is that your imagination is the only limiting factor.

you want a sawtooth? x = (y * a) mod b

as simple as that.

actually noise is the least obvious one.
Quote:Original post by Eelco
you want a sawtooth? x = (y * a) mod b

as simple as that.

Not quite that simple... Yes, it is the "obvious" way to do it, and for a game or a simple sound application it might be good enough. However, sampling such a signal leads to aliasing and quite audible sound artifacts that are unacceptable for high quality sound applications. To avoid aliasing you must produce a bandlimited version of the waveform, which is much less straight-forward to implement efficiently.

Summing sinus waves (truncated harmonic series) is a simple way to generate bandlimited waveforms, but unfortunately it is quite inefficient in most cases. If you google for "bandlimited oscillators" you can probably find some useful theory, implementation considerations and even sample code you can learn from. This paper by Stilson and Smith is a classic on the subject: http://ccrma-www.stanford.edu/~stilti/papers/blit.pdf

Of course, this might be overkill if sound quality is not a priority, but at least one should be aware of these potential problems then dealing with digital signals.
Yeah I knew the sawtooth could be done like that, but as AP said above it has problems, although many simple hardware oscillators do generate waveforms like that. Thanks for the paper, I'll let you know how I get on with the sound app. I don't need realtime, although it would be nice, so perhaps the mathematical functions would do.
ah so you want Hardware waveforms. couldnt see that from your OP.
Quote:Original post by Eelco
ah so you want Hardware waveforms. couldnt see that from your OP.


No, I was just commenting that your method is used by hardware synth chips!

I'm finding that paper a little hard to understand, but I'll get there in the end!

This topic is closed to new replies.

Advertisement