Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- FMOD sound wrapper and sound manager wrapper interfaces:
- //------------------------------------------------------------------------------
- //Copyright Charles Corbin
- //
- //FMOD audio system wrapping
- //------------------------------------------------------------------------------
- #pragma once
- #include <fmod.hpp>
- #include <windows.h>
- //*********************************************
- // FMOD Sound
- //*********************************************
- class FSound
- {
- FMOD::System* localSystem;
- FMOD::Channel* channel;
- FMOD::Sound* sound;
- FMOD_RESULT result;
- public:
- FSound(FMOD::System* inSystem){localSystem = inSystem;};
- ~FSound(){localSystem = NULL;};
- bool isPlaying();
- bool playOnce();
- bool playLooping();
- bool playLooping(int inCount);
- bool stop();
- bool mute();
- bool unMute();
- bool isMuted();
- bool pause();
- bool unPause();
- bool isPaused();
- void setVolume(float inVolume);
- float getVolume();
- void volumeUp(float inMag);
- void volumeDown(float inMag);
- void loadFull(char* fileName);
- void loadStream(char* fileName);
- };
- ********************************************************************************************************
- FMOD sound wrapper bodies:
- //*********************************************
- // FMOD Sound
- //*********************************************
- bool FSound::isPlaying()
- {
- bool out;
- channel->isPlaying(&out);
- return out;
- }
- bool FSound::playOnce()
- {
- return localSystem->playSound(FMOD_CHANNEL_FREE, sound, false, 0);
- }
- bool FSound::playLooping()
- {
- localSystem->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);
- channel->setMode(FMOD_LOOP_NORMAL);
- return true;
- }
- bool FSound::playLooping(int inCount)
- {
- localSystem->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);
- channel->setMode(FMOD_LOOP_NORMAL);
- channel->setLoopCount(inCount - 1);
- return true;
- }
- bool FSound::stop()
- {
- return channel->stop();
- }
- bool FSound::mute()
- {
- return channel->setMute(true);
- }
- bool FSound::unMute()
- {
- return channel->setMute(false);
- }
- bool FSound::isMuted()
- {
- bool out;
- channel->getMute(&out);
- return out;
- }
- bool FSound::pause()
- {
- return channel->setPaused(true);
- }
- bool FSound::unPause()
- {
- return channel->setPaused(false);
- }
- bool FSound::isPaused()
- {
- bool out = 0.0;
- channel->getPaused(&out);
- return out;
- }
- void FSound::setVolume(float inVolume)
- {
- channel->setVolume(inVolume);
- }
- float FSound::getVolume()
- {
- float out;
- channel->getVolume(&out);
- return out;
- }
- void FSound::volumeUp(float inMag)
- {
- if(getVolume() + inMag > 1.0f){return;}
- setVolume(getVolume() + inMag);
- }
- void FSound::volumeDown(float inMag)
- {
- if(getVolume() - inMag > 1.0f){return;}
- setVolume(getVolume() - inMag);
- }
- void FSound::loadFull(char* fileName)
- {
- if(!sound)
- {
- result = localSystem->createSound(fileName, FMOD_DEFAULT, 0, &sound);
- stringstream errMsg;
- errMsg << "can't load sound: " << fileName;
- throw Error(result, errMsg.str());
- }
- }
- void FSound::loadStream(char* fileName)
- {
- localSystem->createStream(fileName, FMOD_DEFAULT, 0, &sound);
- if(!sound)
- {
- stringstream errMsg;
- errMsg << "can't load sound: " << fileName;
- throw Error(result, errMsg.str());
- }
- }
- *********************************************************************************************************
- How this is being implemented in the actual game:
- in my game interface file i have:
- FSound* testSound;
- in the Game bodies file:
- void Level_1::activate()
- {
- //Audio Allocation
- testSound = audio->loadFSound("snd_laserbolt.wav", true);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement