Jump to content
  • Advertisement
Sign in to follow this  
EmrldDrgn

Audio Systems

This topic is 3354 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How are your audio systems typically structured? I'm about to start on one, and I'm struggling with how to organize it. My thought right now is to have a class which loads audio files based on a filepath in one of two ways, either completely into memory or in a stream-based way. This class would keep track of what audio files it had loaded, so that it doesn't load them unnecessarily. Since doing all this is API specific, this class would be derived from an ABC "AudioLoader" interface the rest of the code would talk to, and it would return pointers to an ABC "Audio" interface that avoids the API-specific audio structures. My problem is that I don't really know where to go from there. What do I do with these newly-loaded resources?

Share this post


Link to post
Share on other sites
Advertisement
I'm using irrKlang and I'm making it mimic the way textures are handled in OpenGL:

ie:
When loading a song, an int is returned; I keep track of them inside the Sound class with a std::map<int, *nativereferencetoyoursoundlibrary>

Then all subsequent Sound class members are as follow:
int Load( std::string path );
void Play( int );
void Stop( int );
void Destroy( int );
int GetPlayingPosition( int );

It keeps it simple, everything is hidden inside the Sound class. Not very sophisticated but incredibly effective.

Share this post


Link to post
Share on other sites
I guess what I'm trying to ask is, I have all the classes implemented that handle HOW to play audio, but I don't know how to set up the classes that handle WHEN. Does that make sense?

Share this post


Link to post
Share on other sites
I don't know if this will answer your question, but I do something like so:

1) Prebuffer common (small) sounds into memory at the start of the application (or level).

2) Run stream and sound management in its own thread.

3) Dispatch commands to that thread/sound system when events occur that require a sound be played/stopped etc.

Note that I use Audiere, and therefore #2 is handled transparently for me :)

Is this the kind of advice you are looking for? (If it is and you want more detail, I can expand. Also knowing what language/platform you are using would help)

Share this post


Link to post
Share on other sites
Quote:
Original post by EmrldDrgn
How are your audio systems typically structured? I'm about to start on one, and I'm struggling with how to organize it.

My thought right now is to have a class which loads audio files based on a filepath in one of two ways, either completely into memory or in a stream-based way. This class would keep track of what audio files it had loaded, so that it doesn't load them unnecessarily.


This should be adapted from your normal resource management code. For me, it was simply a matter of extending the generic code into a sound specific version (and then again into an API specific version).

Quote:

My problem is that I don't really know where to go from there. What do I do with these newly-loaded resources?


Whatever you want. I mean, you requested them in the first place. Why request them if you're not going to use them for something?

Quote:

I guess what I'm trying to ask is, I have all the classes implemented that handle HOW to play audio, but I don't know how to set up the classes that handle WHEN. Does that make sense?


Not really. You (almost certainly) have some sort of event or script that says 'play sound XYZ'. Fetch sound, play sound, continue event/script. Where's the problem?

Share this post


Link to post
Share on other sites
Quote:
This should be adapted from your normal resource management code. For me, it was simply a matter of extending the generic code into a sound specific version (and then again into an API specific version).

How do you determine what's "normal" resource management? Are you suggesting that I ought to have some wholely-generic Resource interface which Audio resources implement?

Quote:

Not really. You (almost certainly) have some sort of event or script that says 'play sound XYZ'. Fetch sound, play sound, continue event/script. Where's the problem?

I mean things like what part of the engine should "own" the resources, keep track of the references, things like that. But I guess that's probably too specific a question to answer, depending too much on the rest of my code. I'll just have to figure it out myself.

Share this post


Link to post
Share on other sites
Quote:
Original post by EmrldDrgn
Quote:
This should be adapted from your normal resource management code. For me, it was simply a matter of extending the generic code into a sound specific version (and then again into an API specific version).

How do you determine what's "normal" resource management?


It doesn't really matter? I mean resource management requirements within games are pretty consistent. There's a variety of ways to solve the problem, but in the end, audio is just one more resource.

Quote:

Are you suggesting that I ought to have some wholely-generic Resource interface which Audio resources implement?


Not at all, but I expect that you have some resource management system already from which you can at the very least steal code to make the implementation easier. Or at least follow the same pattern with audio as you do with models and textures.

Quote:

Quote:

Not really. You (almost certainly) have some sort of event or script that says 'play sound XYZ'. Fetch sound, play sound, continue event/script. Where's the problem?

I mean things like what part of the engine should "own" the resources, keep track of the references, things like that. But I guess that's probably too specific a question to answer, depending too much on the rest of my code. I'll just have to figure it out myself.


That was/is the jist of my reply... How do you already do it for textures/models/etc? Consistency will help you here. Audio isn't anything special as far as resource management goes.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!