best way to write a LoadWav() function

Started by
3 comments, last by Da cobra 21 years, 7 months ago
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
Advertisement
Would work, but you could also put loadwave into the constructer..


classname wave1(file);
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
-Pac "The thing I like about friends in my classes is that they can't access my private members directly." "When listening to some one tell about their problem (whether it's code or not), don't listen to what went right or wrong, but what they assumed....."
I have:

DWORD Sound;

Sound = Audio()->LoadSound("file.wav");

Audio()->PlaySound( Sound );

And in Audio''s destructor everything is released from memory

/MindWipe
"To some its a six-pack, to me it's a support group."
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.




http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,

This topic is closed to new replies.

Advertisement