Need some help with SDL_Mixer

Started by
6 comments, last by JimDaniel 16 years, 5 months ago
I'm having two problems. Maybe you guys can help me out. 1. The first problem I'm having is with setting sound channels manually. When I pass in the default macro FIRST_AVAILABLE everything works beautifully. However, to call the HaltChannel function to stop a particular sound I need to pass in the channel to stop. How can I get this information if I'm using the first available macro? Also, if I try to set the channels manually, like say I pass in 1-5 for the channels I need in order to know which channel to stop, the sound doesn't play at all. 2. The second problem is with how quickly sound files load in my app, when I call LoadWAV. The way my app (not a game) works, I need to be able to load sounds on the fly, and sometimes with larger files it takes ~10s, which is unacceptable. Other than pre-loading everything, which impractical as there are tons of sound files, is there any other way to get a faster response time? Maybe LoadWAV isn't the correct function to call for my purposes? I had another question related to this. These sound files are all ambient background tracks, so in a way they work more like music files - only I need to be able to mix up to five tracks at once, adjust a single track volume on the fly, and start and stop a single track at any given time. Would it be better to use the SDL_mixer music functions for this? Sorry, this is quite a bit to read, but I'd appreciate any advice. Thanks! Daniel
Advertisement
I'm not sure SDL_mixer can handle what you're asking it to do. Certainly mixing 5 channels is possible but loading them in with LoadWAV is the only way to do it unless you compress them with Ogg Vorbis and play them in mono only through the audio compression support. It'll increase the CPU usage but it won't degrade the sound quality too badly.

Another option would be to mix the tracks using the music module support by preloading the samples into an .XM file and using the MikMod music player built in to the library. An editor you could use to do this is at MilkyTracker.net. It runs on anything.
Thanks for the advice. Its possible I may have to look elsewhere for my needs.

But just to make sure, my app is an ambient sound player which supports up to five simultaneous tracks, where the user is able to stop a sound, load another sound, and set the volume of any particular track on the fly. Just from what I've described, do you think SDL_mixer is capable? I guess maybe what I need is a way to stream the audio instead of loading it. Is that what you meant by the ogg compression...etc? This sound stuff is new to me.

If this is all not easily accomplished with SDL_mixer, is there another library more suitable?

Thanks again, Daniel
From my recollection, SDL is not very good for what you want to do, because SDL_Mixer makes certain assumptions about your sound usage that don't really fit with wanting to stream multiple sources at once. There are probably ways of doing what you want, but you'll have to work at a lower level. (Or find a better library.)
You may want to have a look at OpenAL instead, the SDL_mixer is fairly simplistic and is meant as a basic sound player for regular apps only. You're looking for streaming technology basically, which means it'll require a bit more effort.

here is a reference to using streaming files in OpenAL using the ogg vorbis file format:

http://www.devmaster.net/articles/openal-tutorials/lesson8.php.

The way this works is by double-buffering the sound files and loading in chunks. It can be summed up as follows:

Load next chunk in back buffer, swap to the front buffer to play. Continue loading next chunk in back buffer.

EuanIcarus Scene Engine: C# OpenSource Cross Platform Engine and Design StudioFiles http://www.sourceforge.net/projects/icarusVideos http://www.youtube.com/user/emacinnesMain Website: http://www.pointscape.com.sg/joomla
Thanks for the all the advice. I'm looking into OpenAL. Pretty powerful features there, although the library works at a much lower level. So, a regular media player such as Windows Media or iTunes, those work by streaming data?
Yes, they do. SDL_Mixer does streaming, but assumes you only ever want to stream one source at once, if I remember correctly. If you looked at the source you might be able to learn how to use the normal SDL sound routines to do what you want. But if OpenAL suits you, that is fine too.
I ended up using FMOD to do what I needed - streaming multiple channels. Its not free for commercial use, however this is an independent project. But what a powerful/easy-to-use library. I highly recommend it to other hobbyist and independent developers. I just replaced my SDL_mixer code with the equivalent FMOD code and it was working in no time...

This topic is closed to new replies.

Advertisement