[SDL] How to generate sound of given frequency and duration ?
david at olofson.net
Wed Jul 9 23:56:01 PDT 2003
On Wednesday 09 July 2003 16.51, Wladimir Mutel wrote:
> I am trying to port one old DOS game that just beeps its sounds to
> PC-Speaker or AdLib if it finds one. The frequency and duration is
> computed at run-time. What do I have to use in SDL to port this
> functionality ?
There isn't anything like it, really, so it has to be emulated on top
of the digital audio ("PCM") API.
Many platforms don't have anything remotely like the PC speaker in the
hardware, and most that do don't offer any useful APIs for them. So,
there's no point in having SDL support such things.
And who *really* wants the Real Thing anyway...? :-)
> May be there is some extension or 3rd-party library
> to achieve this ?
Actually, there is - and it's even specifically meant to play sounds
created for a DOS game and the PC speaker:
(Look for speaker.tar.gz way down on that page.)
It's even got a high pass filter to make it sound more like the Real
Thing, and a feedback delay to make it bearable with headphones. :-)
Seriously, it's just a fun hack, but it might do the job for you.
You may want to throw the "sound effect sequencer" away if you have
your own code for that part. The actual speaker emulator can be used
on it's own.
> I am porting to SDL under Linux+X11 now, but I would prefer to
> know about portable functions for sound generation.
Well, there *are* drivers for the Real Thing (the horrible PC speaker,
that is) through Linux console and X11, but those aren't very
portable, and can't offer the same control as programming the speaker
to the metal. I just hacked them to see if it would work - and it
does, sort of...
However, the normal output method is through the speaker emulator,
which uses the normal SDL audio API for output. That's about as
portable as it gets.
//David Olofson - Programmer, Composer, Open Source Advocate
.- The Return of Audiality! --------------------------------.
| Free/Open Source Audio Engine for use in Games or Studio. |
| RT and off-line synth. Scripting. Sample accurate timing. |
`-----------------------------------> http://audiality.org -'
--- http://olofson.net --- http://www.reologica.se ---
More information about the SDL