Archived

This topic is now archived and is closed to further replies.

best way to write a LoadWav() function

This topic is 5574 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

I''m wondering if this is the right way to write a function to load a wav? a class with member functions LoadWav() & PlayWav() and then for every sound : classname wave1 ; classname wave2 ; wave1.loadwav(...) ; wave2.loadwav(...) ; wave1.playwav() ; wave2.playwav() ; any tips/suggestions will be appreciated

Share this post


Link to post
Share on other sites
What I tend to do when handling multiple wavs, or just resources in general is to create a soundmanger class that holds an array (or an stl::map) of all the sounds. By mapping I can assiocate a number or a string or whatever to the sound file.

so for example basic syntax would be :

CSoundManger MySounds;
MySounds.AddWave(MapKey,data);
//the MapKey would be how I keep track of the sound to access it again. the data would be a sound already loaded, or better yet just a filename so the addwave() function would load the sound for me.Then:

MySounds.PlaySound(Mapkey);
//This function would search through the map listing and find the entry matching MapKey and play that sound.

The reason I do this instead of having instead each class hold it''s own sounds, is because the sounds are centeralized in one class, so I don''t duplicate code. Also init and deinit is easy. And checking for errors would be simplier.

Hope this helps:
Pactuul

Share this post


Link to post
Share on other sites
hiya,

instead of stl maps i used stl vectors, then i just make an enum listing on top of my code and use this enums to identity which song on my stl vector array i need.




Share this post


Link to post
Share on other sites