CocosDenshion: (pitch/pan/gain) added Linux code for OpenAL and FMOD.

This commit is contained in:
Sergey Shambir 2013-06-03 16:59:50 +04:00
parent ab1038a540
commit b9b36d7b56
5 changed files with 33 additions and 14 deletions

View File

@ -85,7 +85,8 @@ public:
@param pszFilePath The path of the effect file,or the FileName of T_SoundResInfo @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 @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 @brief Stop playing sound effect

View File

@ -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::Channel* pChannel;
FMOD::Sound* pSound = NULL; FMOD::Sound* pSound = NULL;
@ -311,6 +312,11 @@ unsigned int FmodAudioPlayer::playEffect(const char* pszFilePath, bool bLoop) {
} }
pChannel->setChannelGroup(pChannelGroup); pChannel->setChannelGroup(pChannelGroup);
pChannel->setPan(pan);
float freq = 0;
pChannel->getFrequency(&freq);
pChannel->setFrequency(pitch * freq);
pChannel->setVolume(gain);
//set its loop //set its loop
pChannel->setLoopCount((bLoop) ? -1 : 0); pChannel->setLoopCount((bLoop) ? -1 : 0);

View File

@ -101,7 +101,8 @@ public:
@param pszFilePath The path of the effect file,or the FileName of T_SoundResInfo @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 @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 @brief Stop playing sound effect

View File

@ -72,7 +72,7 @@ unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath, bool bLoop,
float pitch, float pan, float gain) { float pitch, float pan, float gain) {
// Changing file path to full path // Changing file path to full path
std::string fullPath = FileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath); std::string fullPath = FileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);
return oAudioPlayer->playEffect(fullPath.c_str(), bLoop); return oAudioPlayer->playEffect(fullPath.c_str(), bLoop, pitch, pan, gain);
} }
void SimpleAudioEngine::stopEffect(unsigned int nSoundId) { void SimpleAudioEngine::stopEffect(unsigned int nSoundId) {

View File

@ -48,6 +48,9 @@ namespace CocosDenshion
ALuint buffer; ALuint buffer;
ALuint source; ALuint source;
bool isLooped; bool isLooped;
float pitch;
float pan;
float gain;
}; };
typedef map<string, soundData *> EffectsMap; typedef map<string, soundData *> EffectsMap;
@ -434,7 +437,6 @@ namespace CocosDenshion
unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath, bool bLoop, unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath, bool bLoop,
float pitch, float pan, float gain) 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); EffectsMap::iterator iter = s_effects.find(fullPath);
@ -453,12 +455,21 @@ namespace CocosDenshion
} }
checkALError("playEffect:init"); checkALError("playEffect:init");
iter->second->isLooped = bLoop;
alSourcei(iter->second->source, AL_LOOPING, iter->second->isLooped ? AL_TRUE : AL_FALSE); soundData &d = *iter->second;
alSourcePlay(iter->second->source); 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"); checkALError("playEffect:alSourcePlay");
return iter->second->source; return d.source;
} }
void SimpleAudioEngine::stopEffect(unsigned int nSoundId) void SimpleAudioEngine::stopEffect(unsigned int nSoundId)