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
@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

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::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);

View File

@ -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

View File

@ -72,7 +72,7 @@ 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);
return oAudioPlayer->playEffect(fullPath.c_str(), bLoop, pitch, pan, gain);
}
void SimpleAudioEngine::stopEffect(unsigned int nSoundId) {

View File

@ -48,6 +48,9 @@ namespace CocosDenshion
ALuint buffer;
ALuint source;
bool isLooped;
float pitch;
float pan;
float gain;
};
typedef map<string, soundData *> EffectsMap;
@ -434,7 +437,6 @@ 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);
EffectsMap::iterator iter = s_effects.find(fullPath);
@ -453,12 +455,21 @@ 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)