Hi,
About a week ago, out of boredom, I started working on
little retro-styled '80s kind of video game, written
in a pretty simple-minded way with gnome, and the graphics
done just by using line drawing primitives. It was just
something to do, I didn't imagine it would amount to anything.
Well, it's turning out surprisingly well (not great, but
better than I was expecting.) So now I'm thinking to add
sound, but apart from some MIDI programming, I really haven't
done any audio programming before (unless you count some
Extended BASIC code on a ti99/4a back in the '80s -- and
nobody would count that.)
So, I found libao (
http://xiph.org/ao/doc/ ) which looks
nice and simple, and the sample program I tried
(
http://xiph.org/ao/doc/ao_example.c ) worked right off
the bat, and the idea of synthesizing my own sounds by
constructing waveforms using sine waves is appealing for
a retro styled app like mine (though I have no experience
doing that and only a vague memory of trigonometry), but
I wonder about how to mix sound (add the waveforms, I guess)
and construct them on the fly (or trigger pre-computed
chunks of audio).
In the example code, it plays a one second chunk of audio
with one library call initiating the playback.
So, I imagine that for a game, in order to satisfy the
real-time-ish requirements, I'd instead construct maybe
1/10th or 1/20th second chunks, which would be queued up
in my program for playback, and whenever some event happens
which demands some sound be produced _right now_ (like the
user presses the "fire" button, and so needs some bleeping
laser gun sounds to be produced) I would then start adding
(arithmetic addition) laser-gun-waveform-data into whatever
chunks were already in the queue, and so out would come
the sound...
Does that seem like a reasonable approach?
By chopping the sound up into 1/10t or 1/20th second chunks,
am I apt to cause distortion of some kind?
Is there some other library I might be better off with?
(I looked at SDL, but it seems heavily tilted towards
graphics, and I already have the graphics stuff going alright
under just regular old gnome.)
I might also want to playback some ogg encoded files for maybe
prerecorded sound effects and music to be mixed
in with the synthesized sound effects. libao won't do that by itself, but
I think there are some other libs on
xiph.org that do that, but
I'm not sure how well they'd accomodate mixing random bits of
sound in with them.
Saw this:
http://www.underbit.com/products/mad/
fixed point mpeg decoder library... Not sure how
easy it'd be to mix in other sounds with its output.
Maybe just decode into memory buffer.
Anyway, just looking for suggestions, esp. if what
I've described so far seems wrong.
-- steve
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com