Generating tones with SDL audio

“Tone”? What kind of timbre do you want? What kind of accuracy? Quality
requirements?

There’s a lot more to this than you may realize at first, but here’s some
code to play around with for starters:

http://olofson.net/mixed.html	(Look for "speaker.tar.gz".)

Obviously, the emulation is the interesting part. Who wants to drive a
real PC speaker these days? :slight_smile:

You can quite easily replace the highpass filtered square wave with saw
or triangle, and sine isn’t too hard either, unless you want it very
fast. (No point in worrying about that unless you want many voices.)

However, if you want high quality and anything but sine, you’ll have to
look into more advanced oscillators. One of the best
complexity/flexibility/performance tradeoffs seems to be wavetables with
some kind of interpolation. (Cubic/4-point works very well as long as
you’re careful with the highest octave of the wavetable data.)

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter | -------------------------------------> http://olofson.net -'On Thursday 16 May 2002 19:36, James wrote:

Is it possible (or is there some library) to generate tones using SDL’s
audio functions?

I.e so I can generate a 100Hz tone that lasts 2 seconds, etc.