[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sound worries

>> i`ve had no problems so far coding the
>> graphics and main game engine in C using SVGALib

I did the same thing, except I used fbcon.

>> however i now have
>> come to a point where i want to add music and sound effects.   The
>> question is  HOW!!!!!  i looked at OSS but it doesn`t actually do
>> multichannel mixing (as far as i could see anyway),

What a coincidence!  I just got my own sound code working last night.
I used OSS and did my own mixing (I've never programmed sound before, and I
couldn't find any way for the hardware to do it).

Here are the routines I've written:
1) init_sound - This opens the sound device (/dev/dsp, with a simple unix
open()) and configures it (using ioctl).
2) new_sound - This loads a sound file from disk.  If you use "sox" to
convert your sounds to raw format you can do this with a simple fread.
3) init_mixing_buffer - this is just my own structure which stores the
sound as they are mixed
4) mix_sound - whenever I need to play a sound I call this.  It adds the
sound to the mixing buffer.
5) play_sounds - This is called inside the game loop.  It just uses unix
write() to send the next section of the mixing buffer to the sound_device,
and updates the mixing buffer.

The OSS web site can help fill in the details(pay special attention to the
fragment size and count - these have to be small for interactive
applications.  Does anyone have a good explanation of this?)
It took a page or so of code, I can send it to you if you want.