Sound Source management.

Alright, so guess what I got distracted by a sound source management.

See, I found out that you can only have a limited number of sound sources. It is limited because each one represents a hardware sound source unless of course your using a software device. But in any case they are a limited resource.

Now from what I was reading you could have anywhere from like 14 to hundreds. Fun times. Well anyway the general consensus among posts I saw on the topic was that the best way to handle it is to allocate all of your source up front. Basically create sources until you get an openal error and that is your max. It sounds like a big hack and it is but I see no way to query the api for the max number of supported sources.

Also if you allocate on demand there is always that chance you won't be able to get a source.
Another thing most of the people agreed on was that you have to create some sort of priority system to handle giving the sources out.

Well, my solution was to use a priority queue adapter from the STL and over loaded less than operator. A source that isn't doing anything is always lower priority than one that is. And if there are no idle sources a priority value is checked.

At least that is how it is supposed to work I haven't tested it all that much. My sound plays that's good enough for now. My guess is that the queue won't stay perfectly sorted because the status of the sound source changes in between push and pop calls.

However All things equal the first playing source will be returned to the end of the idle sources. each additional one will be returned to the end of the idle ones. So in theory the first source used will be the first idle source to be reused. Which should give it plenty of time to do it's thing.

If it does indeed work out like that then no additional work from me should be required to make this thing work well. I really love reusable code. People who want to rewrite everything should be punched in the face.

But anyway this new audio system sports from new features as well. I was having problems with alut so I tossed it and now I'm setting up the context & device myself. This allows me to do some fallback stuff to make sure the user gets something even if it is a software device.

Also I can log when things like that fall through. The main reason I dumped alut though is that the sample loading functions seem to be next to worthless. I was using a deprecated version of one in my OpenAL scene node. I never changed it and that worked fine. However when I tried the shiny new one it figuratively gave me the finger.

Now part of the issue with the old method was giving it the frequency and such. Which it should be able to figure out if it is the one loading the header information. But anyway I also didn't want to use something that could be dropped from the api completely at any time.

So I added sndfile to the project. It is a library for just reading & writing audio files. The author seems more geared toward Linux but there is a windows version and it works pretty good.

The license is LGPL so you have to open source changes to the library but it is still safe to create closed source projects that link against it.

I know what your thinking blah blah blah. Well including this library adds support for a desent sized collection of audio file formats including ogg/vorbis. Which by the way I will probably be using primarily.

Now sndfile doesn't support mp3 for the same reason I'm going to try to avoid it in the project. There are patent issues in some countries. Using an unemcumbered format will serve the project much better as it widens the userbase. Granted this project is only availible in one language but hey it's a start.

Oh, also I didn't know this but if you have openal in automatic mode it using X-Ram so I'm taking advantage of xram if the computer running it has it. That makes me happy again I love reusable code. Saves so much time. And also makes my code do cool things I didn't think of.

Oh, before I forget there is one issue that I haven't done anything with. I'm not cleaning up the sources when the application shutsdown. I'm sure killing the context & device does the trick but I feel like a hack relying on that.

I think I'm gonna sack out early ish tonight may have someone calling about a job sometime this week wouldn't want to miss that call.


Popular posts from this blog

VK9 - Milestone13 Completed

VK9 - Milestone16 Completed

VK9 - Milestone23 Completed