PDA

View Full Version : BEST way to do sounds



Structural
01-12-2003, 06:43 AM
As there is NO sound in openGL I thought I'd ask you lot how you solve this.

I have a simple pong game here and I'd love to embed a bit of sound in it. A simple wav would do to play when the ball hits a wall or something.
I have globally looked into several libraries as openAL and Fmod, but there are quite a few things unclear to about those libraries that aren't explained in the helps either:
Do I need to supply a DLL for them to work?
I haven't done anything with sound yet simply because I couldn't find info on that.

On the other hand, NeHe uses a windows sound call to use sound, but I feel a bit uncertain about that thing too. I don't want my app to load that file every time an event happens, as that'd slow it down too much.

Anyone any thoughts about this?

Bob
01-12-2003, 06:55 AM
There are a few options, depending on what you need, and what platform(s) you target.

The simplest way, on Windows, is PlaySound. For a pong game this should be enough if all you need is a boink when the ball hits a paddle or a wall. For more advanced stuff, there are DirectSound, FMOD (http://www.fmod.org) , Bass (http://www.un4seen.com/music/) and OpenAL (http://www.openal.org/home/) . I believe all but DirectSound can be used under other systems than Windows.

I use FMOD, and I can highly recomend it.

EDIT: Sorry, didn't read your question completely. You already knew about those I mentioned. Can only speak for FMOD, since that's what I'm using. FMOD requires a DLL under Windows. But that's no problem, jusy chip the DLL with your program if you plan to distribute it.

[This message has been edited by Bob (edited 01-12-2003).]

Structural
01-12-2003, 07:15 AM
I'm mainly worried about the delay of "PlaySound"... doesn't it access the HD every time it has to play the sound? If the ball is moving around at incredible rates and it has to play the thing 3 times each second there is bound to be a delay when it accesses the HD.
Do you have experience with this?

Bob
01-12-2003, 07:43 AM
You can place the sound as a resource in your program and play it from there. Have no experience with resources in Windows, but I would guess they are stored in memory. I suggest you take one of the APIs I suggested and use that instead. You can do so much more with them, and, at least FMOD, is very simple to use.

Nick Nougat
01-12-2003, 10:33 AM
You can even use PlaySound() to play sound images directly from RAM. Just use SND_MEMORY as flag in fdwSound.
I'm not sure if the delay is OK when using SND_MEMORY, but I'd give it a shot if you don't have too many sounds...
Nick

marcus256
01-12-2003, 09:57 PM
Hi!

Just wanted to mention another option: libMikMod (http://www.mikmod.org/) . It's the most portable sound toolkit you will ever find (>12 platforms supported), and it is very easy to use (not to mention completely free, and it's also possible to link it statically).

You get 32 channels for sound sample playback and MOD music playback (16 different MOD formats supported) + easy control of things like panning, reverb and interpolation quality.

Structural
01-12-2003, 11:44 PM
Thanks,
I shall test the SND_MEMORY tonight, as I don't have a sound card in this computer (at work, behind a P2 233Mhz http://www.opengl.org/discussion_boards/ubb/frown.gif)

Marcus, does MikMod use an external file for sound or is it directly embedded in the executable? Heh heh... for me it doesn't "feel" right having to supply a 3rd party dll... something I still have to get used to...

marcus256
01-13-2003, 02:34 AM
Originally posted by Structural:
Marcus, does MikMod use an external file for sound or is it directly embedded in the executable? Heh heh... for me it doesn't "feel" right having to supply a 3rd party dll... something I still have to get used to...

It can do both (that was what I meant with "link statically"). You get the source, so you can build it pretty much the way you like. I think there is a MSVC Makefile in the distro. I had to tweak it a bit to compile with MinGW32 (my preferred compiler), and I did a static library then (static = ends up in the executable file).

I have made a few apps which use no external files at all (I even integrated the music module into the exe using a bin2c program and libMikMod:s custom file I/O facilities to create a "mem loader").

rpxmaster
01-13-2003, 10:42 PM
SMPEG + libvorbis + Timidity + MikMod + Simple DirectMedia Layer == SDL_mixer, guys. Enjoy, this is what you're looking for :-)
http://www.libsdl.org/projects/SDL_mixer/
Free software rules. To my knowledge, only license you have to worry about is the LGPL.