best way to write a LoadWav() function
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
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
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
I have:
DWORD Sound;
Sound = Audio()->LoadSound("file.wav");
Audio()->PlaySound( Sound );
And in Audio''s destructor everything is released from memory
/MindWipe
DWORD Sound;
Sound = Audio()->LoadSound("file.wav");
Audio()->PlaySound( Sound );
And in Audio''s destructor everything is released from memory
/MindWipe
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement