I've just finnished implimenting FMOD into my summer project. It's pretty simple(I think) but it gets the job done. Showboat here about your FMOD , or any other MUSIC api implimentations.
Feel free to comment on mine, or any others (daring enough who) posted.
PS: as you can see, my music.cpp isn't actually finished. I left a couple functions empty for quick testing purposes. I'm filling them in now, but i'm sure you get the idea of their structure.
This is the class files
And then any where you Init,Code:////////////////////////////////////////////////// /********MUSIC.H***************/ ///////////////////////////////////////////////// #ifndef PR_MUSIC #define PR_MUSIC #include "global.h" #include "fmod.h" #define MAX_CHANNELS 32 typedef enum AUDIOTYPE { AT_SONG, AT_SAMPLE, AT_STREAM }; class FMODAudio { public: FMODAudio( AUDIOTYPE type, bool loop ); ~FMODAudio(); public: void LoadFile(char* filename); void Play(); void Stop(); void SetVolume(int volume); void Pause(); private: AUDIOTYPE m_type; FMUSIC_MODULE* m_SoHandle; // .MOD, .S3M, .XM, .IT, .MID, .RMI, .SGT or .FSB FSOUND_STREAM* m_StHandle; // .WAV, .MP2, .MP3, .OGG or .RAW FSOUND_SAMPLE* m_SaHandle; // .WAV, .MP2, .MP3, .OGG or .RAW int m_id; // what channel should this use (if it does) bool m_loop; public: // class management static bool sm_channels[MAX_CHANNELS]; // what channels are being used? }; #ifdef NEED_PR_MUSIC bool FMODAudio::sm_channels[32]; #endif // initialization function prototype void FMODAudioInit(); #endif ////////////////////////////////////////////////// /********MUSIC.CPP*************/ ///////////////////////////////////////////////// #define NEED_PR_MUSIC #include "global.h" #define MAX_CHANNELS 32 FMODAudio::~FMODAudio() { // clean up // use appropriate function // based on sound type switch(m_type) { case AT_SAMPLE: FSOUND_Sample_Free(m_SaHandle); break; case AT_SONG: FMUSIC_FreeSong(m_SoHandle); break; case AT_STREAM: FSOUND_Stream_Close(m_StHandle); break; default: break; } sm_channels[m_id] = true; // make channel available for new instances }; FMODAudio::FMODAudio(AUDIOTYPE type, bool loop) { m_type = type; // what kind of audio is it? m_loop = loop; // does sound loop until told to stop? for(int i = 0; i < MAX_CHANNELS; i++) { // find a channel that is available if( sm_channels[i] ) { sm_channels[i] = false; // set it no longer available m_id = i; // and assign id to this class instance break; } } }; //////////////////// // loads sound file void FMODAudio::LoadFile(char *filename) { // use appropriate function // for the sound type switch(m_type){ case AT_SONG: m_SoHandle = FMUSIC_LoadSong(filename); break; case AT_SAMPLE: m_SaHandle = FSOUND_Sample_Load (m_id,filename,0,0,0); break; case AT_STREAM: m_StHandle = FSOUND_Stream_Open(filename, 0, 0, 0); break; } }; //////////////////// // play loaded sound void FMODAudio::Play() { // use appropriate function // for the sound type switch(m_type) { case AT_SONG: FMUSIC_SetLooping (m_SoHandle, m_loop); // set looping condition FMUSIC_PlaySong(m_SoHandle); // play it break; case AT_SAMPLE: FSOUND_PlaySound (m_id,m_SaHandle); break; case AT_STREAM: FSOUND_Stream_Play (m_id,m_StHandle); break; } }; void FMODAudio::Stop() {}; void FMODAudio::Pause() {}; void FMODAudio::SetVolume(int volume) {}; void FMODAudioInit() { for(int i = 0; i < MAX_CHANNELS; i++ ) { FMODAudio::sm_channels[i] = true; } }
Code:// FMOD INITIATION FSOUND_Init (44100, 32, 0); FMODAudioInit(); // construct sound object FMODAudio *music = new FMODAudio(AT_STREAM, true); music->LoadFile("data/music/05.mp3"); music->Play();



LinkBack URL
About LinkBacks



