Forums

Full Version: New sound engine
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Instead of using OpenAL, we could write our own sound mixing engine from scratch using the SDL low-level stuff:

http://www.libsdl.org/cgi/docwiki.cgi/Audio_20Examples

this way we'd have way more control over it, and it'd be just as portable as SDL.
I thought SDL didn't feature 3d sound...
It doesn't, what Joe's talking about is coding our own 3D sound stuff on top of SDL's simple sound lib (I'm guessing SDL_sound, not SDL_mixer).
Doesn't that sound like to coding you own software graphics renderer (instead of using d3d or ogl)?

What kind of control do you need over the sounds that openal does not allow? (i haven't used any of the two very much, and i'm interested in knowing some more)
Well I'm not sure if we could make something as good as OpenAL, but we could certainly come up with something simpler than it. This would also lessen the game's dependencies on outside libraries, which will make installation easier. I'm not sure if it's worth it, since I don't know how much coding it will take to get working.

Either way we go though, we're going to have to rewrite our sound code, because what's there doesn't work for more than a few sources. Play a Single Race sometime and you'll see what I mean.
So, the basic SDL audio (just part of libSDL) lets you feed data to the soundcard. SDL_mixer is another lib that will do things like let you load some WAV files and play them and the library will do sound mixing and feed data to the soundcard itself. We currently use no SDL-related sound, only OpenAL.

OpenAL is supposed to be like OpenGL, but for sound. It lets you load WAV files, adjust gains and pitch, and have them associated with 3D positions. The latter allows you to have positional sound, sound that fades away, and doppler effects. On Windows, OpenAL uses DirectSound to provide hardware accelerated sound.

The problems with OpenAL are numerous. For example:
* It doesn't manage your sources for you, so you have to manually activate and deactivate sources based on what is most likely to be audible if you have a lot of sources. We don't currently do this in VDrift, so there are a bunch of bugs related to running out of sources.
* The documentation is poor.
* On linux, it falls back to software sound mixing, which 1) sounds terrible and 2) has clicking artifacts for looped sounds
* Pitch adjustments are only allowed within a narrow range (no more than 2.0 pitch adjustment factor) and it sounds terrible with the software mixing.
* From my experience with gaming on Windows, hardware sound support is pretty buggy, and leads to all kinds of odd problems (sound unexpectedly go mute, get stuck looping, or in some cases using hardware sound causes the framerate to stutter whenever a sound is played).

In another project, I wrote a sound engine on top of the libSDL sound functions (which just let you feed data to the sound card manually) in about a day. This engine lets you load WAV files, create sources with positions, and play them. It supports an arbitrary number of sources with automatic activation/deactivation based on what's audible, correct looping without clicks or artifacts, 3D sound positioning, and distance attenuation. It sounds good and runs fast (although I haven't tested it to the extreme yet).

It'd be easy for me to port the above to VDrift. All I need to add is support for 1) pitch adjustment and 2) doppler effects. It'd probably take another day or so.

If you were around when we used to use FMOD, it'll end up sounding like that again (nice and smooth).
Wow, i didn't know openal was that problematic! ...and that it was that easy to fix it? Personally i would go for openal (that's what i was planning to do before i read that post, now i'm not sure), but if you code a new sound library and you happen to make it usable by more projects (which would be nice, since there apparently are no good open source sound libs?), that would change things.
i'll try to keep it generic enough that other projects could use it