void SimpleAudioEngine::preloadEffect(const char* pszFilePath) { int nRet = 0; CCAudioOut* pEffectPlayer = NULL; do { BREAK_IF(! pszFilePath); string strFilePath = fullPathFromRelativePath(pszFilePath); nRet = _Hash(strFilePath.c_str()); BREAK_IF(s_List.end() != s_List.find(nRet)); //AppLog("not find effect, create it..."); if (s_List.size() >= 64) { // get the first effect, and remove it form list //AppLog("effect preload more than 64, delete the first effect"); pEffectPlayer = s_List.begin()->second; pEffectPlayer->Finalize(); s_List.erase(s_List.begin()->first); } if (pEffectPlayer == NULL) pEffectPlayer = new CCAudioOut; pEffectPlayer->Initialize(strFilePath.c_str()); s_List.insert(Effect(nRet, pEffectPlayer)); } while (0); }
void SimpleAudioEngine::unloadEffect(const char* pszFilePath) { string strFilePath = fullPathFromRelativePath(pszFilePath); unsigned int nSoundId = _Hash(strFilePath.c_str()); CCAudioOut*& pPlayer = s_List[nSoundId]; pPlayer->Stop(); }
KDvoid SimpleAudioEngine::preloadBackgroundMusic ( const KDchar* szFilePath ) { if ( !szFilePath ) { return; } std::string sPath = FileUtils::getInstance ( )->fullPathForFilename ( szFilePath ); KDuint uID = _Hash ( sPath.c_str ( ) ); this->stopBackgroundMusic ( true ); SoundList::iterator it = l_aMusicList.find ( uID ); if ( it == l_aMusicList.end ( ) ) { XMSound* pSound = xmSoundOpen ( sPath.c_str ( ), XM_SOUND_NORMAL ); if ( pSound ) { xmSoundSetCallback ( pSound, background_callBack ); l_aMusicList.insert ( Sound ( uID, pSound ) ); } } }
KDuint SimpleAudioEngine::playEffect ( const KDchar* szFilePath, KDbool bLoop, KDfloat fPitch, KDfloat fPan, KDfloat fGain ) { if (!szFilePath) { return 0; } std::string sPath = FileUtils::getInstance()->fullPathForFilename(szFilePath); KDuint uRet = _Hash(sPath.c_str()); preloadEffect(szFilePath); SoundList::iterator it = l_aEffectList.find(uRet); if (it != l_aEffectList.end()) { xmSoundSetRepeat(it->second, bLoop); xmSoundSetVolume(it->second, fGain); xmSoundSetPitch(it->second, fPitch); xmSoundSetPan(it->second, fPan); xmSoundRewind(it->second); } else { uRet = 0; } return uRet; }
void SimpleAudioEngine::playBackgroundMusic(const char* pszFilePath, bool bLoop) { if (! pszFilePath) { return; } sharedMusic().Open(_FullPath(pszFilePath).c_str(), _Hash(pszFilePath)); sharedMusic().Play((bLoop) ? -1 : 1); }
void SimpleAudioEngine::unloadEffect(const char* pszFilePath) { unsigned int nID = _Hash(pszFilePath); EffectList::iterator p = sharedList().find(nID); if (p != sharedList().end()) { delete p->second; p->second = nullptr; sharedList().erase(nID); } }
unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath) { unsigned int nRet = _Hash(pszFilePath); preloadEffect(pszFilePath); EffectList::iterator p = s_List.find(nRet); if (p != s_List.end()) { p->second.Rewind(); } return nRet; }
bool SimpleAudioEngine::isEffectPlaying(const char* pszFilePath) { unsigned int nRet = _Hash(pszFilePath); bool result = false; EffectList::iterator p = sharedList().find(nRet); if (p != sharedList().end()) { return p->second->IsPlaying(); } return result; }
unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath, bool bLoop) { unsigned int nRet = _Hash(pszFilePath); preloadEffect(pszFilePath); EffectList::iterator p = sharedList().find(nRet); if (p != sharedList().end()) { p->second->Play((bLoop) ? -1 : 1); } return nRet; }
unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath, bool bLoop/* = false*/, float pitch/* = 1.0f*/, float pan/* = 0.0f*/, float gain/* = 1.0f*/) { unsigned int nRet = _Hash(pszFilePath); preloadEffect(pszFilePath); EffectList::iterator p = sharedList().find(nRet); if (p != sharedList().end()) { p->second->Play(bLoop); } return nRet; }
void QBSoundWin::unloadEffect(const char* filename) { QBSoundLocker locker(&mMutex,"unloadEffect"); if (filename) { unsigned int nRet = _Hash(filename); EffectList::iterator p = sharedList().find(nRet); if (p != sharedList().end()) { delete p->second; p->second = NULL; sharedList().erase(nRet); } } }
unsigned int QBSoundWin::playEffect(const char* filename,bool bLoop,float pitch, float pan, float gain) { QBSoundLocker locker(&mMutex,"playEffect"); if (filename) { unsigned int nRet = _Hash(filename); do { if (filename==NULL) break; unsigned int nRet = _Hash(filename); if (sharedList().end() != sharedList().find(nRet)) break; sharedList().insert(make_pair(nRet,new EffectBuffer())); EffectBuffer* buffer = sharedList()[nRet]; if (buffer->load(filename)!=0) { sharedList().erase(nRet); } } while (0); EffectList::iterator p = sharedList().find(nRet); if (p != sharedList().end()) { EffectBuffer* effect = p->second; findPlayer(soundID)->setVolume(gain); findPlayer(soundID)->play((unsigned char*)effect->pcmbuffer,effect->pcmsize); soundID ++; if (soundID > 9999) soundID = 1; } return soundID; } return 0; }
KDvoid SimpleAudioEngine::unloadEffect ( const KDchar* szFilePath ) { if (!szFilePath) { return; } std::string sPath = FileUtils::getInstance()->fullPathForFilename(szFilePath); KDuint uID = _Hash(sPath.c_str()); SoundList::iterator it = l_aEffectList.find(uID); if (it != l_aEffectList.end()) { xmSoundClose(it->second); l_aEffectList.erase(uID); } }
KDuint SimpleAudioEngine::preloadEffect(const KDchar* szFilePath, const KDchar* szKey) { std::string sPath = FileUtils::getInstance()->fullPathForFilename(szFilePath); KDuint uID = _Hash(szKey ? szKey : sPath.c_str()); SoundList::iterator it = l_aEffectList.find(uID); if (it == l_aEffectList.end()) { XMSound* pSound = xmSoundOpen(sPath.c_str(), XM_SOUND_EFFECT); if (pSound) { l_aEffectList.insert(Sound(uID, pSound)); } } return uID; }
void QBSoundWin::preloadEffect(const char* filename) { QBSoundLocker locker(&mMutex,"preloadEffect"); do { if (filename==NULL) break; unsigned int nRet = _Hash(filename); if (sharedList().end() != sharedList().find(nRet)) break; sharedList().insert(make_pair(nRet,new EffectBuffer())); EffectBuffer* buffer = sharedList()[nRet]; if (buffer->load(filename)!=0) { sharedList().erase(nRet); } } while (0); }
void QBSoundMac::preloadEffect(const char* filename) { QBSoundLocker locker(&mMutex,"preloadEffect"); do { if (filename==NULL) break; unsigned int nRet = _Hash(filename); if (effectTrack.end() != effectTrack.find(nRet)) break; effectTrack.insert(make_pair(nRet,new EffectBuffer())); EffectBuffer* buffer = effectTrack[nRet]; if (buffer->load(filename)!=0) { effectTrack.erase(nRet); } } while (0); }
KDvoid SimpleAudioEngine::playBackgroundMusic ( const KDchar* szFilePath, bool bLoop ) { if ( !szFilePath ) { return; } std::string sPath = FileUtils::getInstance ( )->fullPathForFilename ( szFilePath ); KDuint uRet = _Hash ( sPath.c_str ( ) ); preloadBackgroundMusic ( sPath.c_str ( ) ); SoundList::iterator it = l_aMusicList.find ( uRet ); if ( it != l_aMusicList.end ( ) ) { l_uCurrentMusic = uRet; xmSoundSetRepeat ( it->second, bLoop ); this->rewindBackgroundMusic ( ); } }
void SimpleAudioEngine::preloadEffect(const char* pszFilePath) { int nRet = 0; do { BREAK_IF(! pszFilePath); nRet = _Hash(pszFilePath); BREAK_IF(sharedList().end() != sharedList().find(nRet)); sharedList().insert(Effect(nRet, new MciPlayer())); MciPlayer * pPlayer = sharedList()[nRet]; pPlayer->Open(_FullPath(pszFilePath), nRet); BREAK_IF(nRet == pPlayer->GetSoundID()); sharedList().erase(nRet); nRet = 0; } while (0); }
void SimpleAudioEngine::preloadEffect(const char* pszFilePath) { int nRet = 0; do { BREAK_IF(! pszFilePath); nRet = _Hash(pszFilePath); BREAK_IF(s_List.end() != s_List.find(nRet)); s_List.insert(Effect(nRet, MciPlayer())); MciPlayer& player = s_List[nRet]; player.Open(_FullPath(pszFilePath), nRet); BREAK_IF(nRet == player.GetSoundID()); s_List.erase(nRet); nRet = 0; } while (0); }
// for sound effects unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath, bool bLoop/* = false*/) { result r = E_FAILURE; string strFilePath = fullPathFromRelativePath(pszFilePath); unsigned int nRet = _Hash(strFilePath.c_str()); preloadEffect(pszFilePath); EffectList::iterator p = s_List.find(nRet); if (p != s_List.end()) { p->second->SetVolume((int) (s_fEffectsVolume * 99)); int volume = p->second->GetVolume(); if (s_fEffectsVolume > 0.0f && volume == 0) { p->second->SetVolume(1); } if (AUDIOOUT_STATE_PLAYING == p->second->GetState()) { return nRet; // Stop waste a lot of time, so just return. //r = p->second->Stop(); } if (s_fEffectsVolume > 0.0f) { r = p->second->Play(bLoop); } if (IsFailed(r)) { AppLog("play effect fails, error code = %d", r); } } return nRet; }
unsigned int class_hash_code(const std::type_info& info) { // hash name() to size_t value by pseudorandomizing transform return _Hash(info.name()); }
void SimpleAudioEngine::unloadEffect(const char* pszFilePath) { unsigned int nID = _Hash(pszFilePath); s_List.erase(nID); }