diff --git a/CocosDenshion/linux/AudioPlayer.h b/CocosDenshion/linux/AudioPlayer.h index 5d48659f34..074b230c0f 100644 --- a/CocosDenshion/linux/AudioPlayer.h +++ b/CocosDenshion/linux/AudioPlayer.h @@ -85,7 +85,8 @@ public: @param pszFilePath The path of the effect file,or the FileName of T_SoundResInfo @bLoop Whether to loop the effect playing, default value is false */ - virtual unsigned int playEffect(const char* pszFilePath, bool bLoop = false) = 0; + virtual unsigned int playEffect(const char* pszFilePath, bool bLoop, + float pitch, float pan, float gain) = 0; /** @brief Stop playing sound effect diff --git a/CocosDenshion/linux/FmodAudioPlayer.cpp b/CocosDenshion/linux/FmodAudioPlayer.cpp index 228eb55d5c..ef4f5bb9d2 100644 --- a/CocosDenshion/linux/FmodAudioPlayer.cpp +++ b/CocosDenshion/linux/FmodAudioPlayer.cpp @@ -283,7 +283,8 @@ void FmodAudioPlayer::setEffectsVolume(float volume) { } -unsigned int FmodAudioPlayer::playEffect(const char* pszFilePath, bool bLoop) { +unsigned int FmodAudioPlayer::playEffect(const char* pszFilePath, bool bLoop, + float pitch, float pan, float gain) { FMOD::Channel* pChannel; FMOD::Sound* pSound = NULL; @@ -311,6 +312,11 @@ unsigned int FmodAudioPlayer::playEffect(const char* pszFilePath, bool bLoop) { } pChannel->setChannelGroup(pChannelGroup); + pChannel->setPan(pan); + float freq = 0; + pChannel->getFrequency(&freq); + pChannel->setFrequency(pitch * freq); + pChannel->setVolume(gain); //set its loop pChannel->setLoopCount((bLoop) ? -1 : 0); diff --git a/CocosDenshion/linux/FmodAudioPlayer.h b/CocosDenshion/linux/FmodAudioPlayer.h index 66f429d220..4af2265425 100644 --- a/CocosDenshion/linux/FmodAudioPlayer.h +++ b/CocosDenshion/linux/FmodAudioPlayer.h @@ -101,7 +101,8 @@ public: @param pszFilePath The path of the effect file,or the FileName of T_SoundResInfo @bLoop Whether to loop the effect playing, default value is false */ - virtual unsigned int playEffect(const char* pszFilePath, bool bLoop = false); + virtual unsigned int playEffect(const char* pszFilePath, bool bLoop, + float pitch, float pan, float gain); /** @brief Stop playing sound effect diff --git a/CocosDenshion/linux/SimpleAudioEngineFMOD.cpp b/CocosDenshion/linux/SimpleAudioEngineFMOD.cpp index 2caa490f65..2cc2695cc7 100644 --- a/CocosDenshion/linux/SimpleAudioEngineFMOD.cpp +++ b/CocosDenshion/linux/SimpleAudioEngineFMOD.cpp @@ -70,9 +70,9 @@ void SimpleAudioEngine::preloadBackgroundMusic(const char* pszFilePath) { unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath, bool bLoop, float pitch, float pan, float gain) { - // Changing file path to full path - std::string fullPath = FileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath); - return oAudioPlayer->playEffect(fullPath.c_str(), bLoop); + // Changing file path to full path + std::string fullPath = FileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath); + return oAudioPlayer->playEffect(fullPath.c_str(), bLoop, pitch, pan, gain); } void SimpleAudioEngine::stopEffect(unsigned int nSoundId) { diff --git a/CocosDenshion/linux/SimpleAudioEngineOpenAL.cpp b/CocosDenshion/linux/SimpleAudioEngineOpenAL.cpp index d1e57c11e2..182f223b74 100644 --- a/CocosDenshion/linux/SimpleAudioEngineOpenAL.cpp +++ b/CocosDenshion/linux/SimpleAudioEngineOpenAL.cpp @@ -48,6 +48,9 @@ namespace CocosDenshion ALuint buffer; ALuint source; bool isLooped; + float pitch; + float pan; + float gain; }; typedef map EffectsMap; @@ -433,9 +436,8 @@ namespace CocosDenshion unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath, bool bLoop, float pitch, float pan, float gain) - { - // Changing file path to full path - std::string fullPath = FileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath); + { + std::string fullPath = FileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath); EffectsMap::iterator iter = s_effects.find(fullPath); @@ -453,13 +455,22 @@ namespace CocosDenshion } checkALError("playEffect:init"); - iter->second->isLooped = bLoop; - alSourcei(iter->second->source, AL_LOOPING, iter->second->isLooped ? AL_TRUE : AL_FALSE); - alSourcePlay(iter->second->source); + + soundData &d = *iter->second; + d.isLooped = bLoop; + d.pitch = pitch; + d.pan = pan; + d.gain = gain; + alSourcei(d.source, AL_LOOPING, d.isLooped ? AL_TRUE : AL_FALSE); + alSourcef(d.source, AL_GAIN, d.gain); + alSourcef(d.source, AL_PITCH, d.pitch); + float sourcePosAL[] = {d.pan, 0.0f, 0.0f};//Set position - just using left and right panning + alSourcefv(d.source, AL_POSITION, sourcePosAL); + alSourcePlay(d.source); checkALError("playEffect:alSourcePlay"); - return iter->second->source; - } + return d.source; + } void SimpleAudioEngine::stopEffect(unsigned int nSoundId) {