void FmodAudioPlayer::close() { FMOD_RESULT result; //BGM if (pBGMChannel != NULL) { result = pBGMChannel->stop(); ERRCHECKWITHEXIT(result); pBGMChannel = 0; } if (pMusic != NULL) { result = pMusic->release(); ERRCHECKWITHEXIT(result); pMusic = 0; } result = pChannelGroup->release(); ERRCHECKWITHEXIT(result); sMusicPath.clear(); result = pSystem->close(); ERRCHECKWITHEXIT(result); result = pSystem->release(); ERRCHECKWITHEXIT(result); init(); }
FmodAudioPlayer::~FmodAudioPlayer() { FMOD_RESULT result; //BGM if (pBGMChannel != NULL) { result = pBGMChannel->stop(); ERRCHECKWITHEXIT(result); } if (pMusic != NULL) { result = pMusic->release(); ERRCHECKWITHEXIT(result); } result = pChannelGroup->release(); ERRCHECKWITHEXIT(result); result = pSystem->close(); ERRCHECKWITHEXIT(result); result = pSystem->release(); ERRCHECKWITHEXIT(result); }
void FmodAudioPlayer::stopBackgroundMusic(bool bReleaseData) { FMOD_RESULT result; pSystem->update(); if ((pBGMChannel == NULL) || (pMusic == NULL)) { return; } if (bReleaseData) { result = pBGMChannel->stop(); ERRCHECKWITHEXIT(result); result = pMusic->release(); ERRCHECKWITHEXIT(result); pBGMChannel = 0; pMusic = 0; } else { result = pBGMChannel->stop(); ERRCHECKWITHEXIT(result); pBGMChannel = 0; } sMusicPath.clear(); }
// for sound effects float FmodAudioPlayer::getEffectsVolume() { float fVolumn; pSystem->update(); FMOD_RESULT result = pChannelGroup->getVolume(&fVolumn); ERRCHECKWITHEXIT(result); return fVolumn; }
void FmodAudioPlayer::rewindBackgroundMusic() { if (pBGMChannel == NULL) { return; } pSystem->update(); FMOD_RESULT result = pBGMChannel->setPosition(0, FMOD_TIMEUNIT_MS); ERRCHECKWITHEXIT(result); }
void FmodAudioPlayer::resumeBackgroundMusic() { if (pBGMChannel == NULL) { return; } pSystem->update(); FMOD_RESULT result = pBGMChannel->setPaused(false); ERRCHECKWITHEXIT(result); }
void FmodAudioPlayer::setBackgroundMusicVolume(float volume) { if (pBGMChannel == NULL) { return; } pSystem->update(); FMOD_RESULT result = pBGMChannel->setVolume(volume); ERRCHECKWITHEXIT(result); }
float FmodAudioPlayer::getBackgroundMusicVolume() { float fVolumn; if (pBGMChannel == NULL) { return 0; } pSystem->update(); FMOD_RESULT result = pBGMChannel->getVolume(&fVolumn); ERRCHECKWITHEXIT(result); return fVolumn; }
bool FmodAudioPlayer::isBackgroundMusicPlaying() { bool bPlaying; if (pBGMChannel == NULL) { return false; } pSystem->update(); FMOD_RESULT result = pBGMChannel->isPlaying(&bPlaying); ERRCHECKWITHEXIT(result); return bPlaying; }
void FmodAudioPlayer::init() { //init FMOD_RESULT result; FMOD::ChannelGroup *masterChannelGroup; unsigned int version; /* * Create a System object and initialize. */ result = FMOD::System_Create(&pSystem); ERRCHECKWITHEXIT(result); result = pSystem->setOutput(FMOD_OUTPUTTYPE_ALSA); ERRCHECKWITHEXIT(result); result = pSystem->init(32, FMOD_INIT_NORMAL, 0); ERRCHECKWITHEXIT(result); result = pSystem->createChannelGroup("Channel Group", &pChannelGroup); ERRCHECKWITHEXIT(result); result = pSystem->getMasterChannelGroup(&masterChannelGroup); ERRCHECKWITHEXIT(result); result = masterChannelGroup->addGroup(pChannelGroup); ERRCHECKWITHEXIT(result); mapEffectSound.clear(); }
// BGM void FmodAudioPlayer::preloadBackgroundMusic(const char* pszFilePath) { FMOD_RESULT result; pSystem->update(); string sNewMusicPath = string(pszFilePath) + szMusicSuffix; if (pMusic && sNewMusicPath != sMusicPath) { //release old result = pMusic->release(); ERRCHECKWITHEXIT(result); sMusicPath = sNewMusicPath; } result = pSystem->createSound(pszFilePath, FMOD_LOOP_NORMAL, 0, &pMusic); ERRCHECK(result); }
void FmodAudioPlayer::setEffectsVolume(float volume) { pSystem->update(); FMOD_RESULT result = pChannelGroup->setVolume(volume); ERRCHECKWITHEXIT(result); }