   Audio Systems
  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?   
  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.   ;  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?   ;  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)   ;Quote:Original post by EmrldDrgnHow 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?;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.   ;Quote:Original post by EmrldDrgnQuote: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.   