2013-07-05 16:28:06 +08:00
|
|
|
#ifndef OPENAL
|
|
|
|
|
2012-08-02 13:02:59 +08:00
|
|
|
#include "SimpleAudioEngine.h"
|
|
|
|
#include "FmodAudioPlayer.h"
|
2013-01-27 19:20:49 +08:00
|
|
|
#include "cocos2d.h"
|
|
|
|
USING_NS_CC;
|
2012-08-02 13:02:59 +08:00
|
|
|
|
|
|
|
namespace CocosDenshion {
|
|
|
|
|
|
|
|
static AudioPlayer* oAudioPlayer;
|
|
|
|
|
|
|
|
SimpleAudioEngine::SimpleAudioEngine() {
|
|
|
|
oAudioPlayer = FmodAudioPlayer::sharedPlayer();
|
|
|
|
}
|
|
|
|
|
|
|
|
SimpleAudioEngine::~SimpleAudioEngine() {
|
|
|
|
}
|
|
|
|
|
2013-07-19 13:40:45 +08:00
|
|
|
SimpleAudioEngine* SimpleAudioEngine::getInstance() {
|
2012-08-02 13:02:59 +08:00
|
|
|
static SimpleAudioEngine s_SharedEngine;
|
|
|
|
return &s_SharedEngine;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleAudioEngine::end() {
|
|
|
|
oAudioPlayer->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// BackgroundMusic
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void SimpleAudioEngine::playBackgroundMusic(const char* pszFilePath,
|
|
|
|
bool bLoop) {
|
2013-01-27 19:20:49 +08:00
|
|
|
// Changing file path to full path
|
2013-07-12 12:03:39 +08:00
|
|
|
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(pszFilePath);
|
2013-01-27 19:20:49 +08:00
|
|
|
oAudioPlayer->playBackgroundMusic(fullPath.c_str(), bLoop);
|
2012-08-02 13:02:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleAudioEngine::stopBackgroundMusic(bool bReleaseData) {
|
|
|
|
oAudioPlayer->stopBackgroundMusic(bReleaseData);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleAudioEngine::pauseBackgroundMusic() {
|
|
|
|
oAudioPlayer->pauseBackgroundMusic();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleAudioEngine::resumeBackgroundMusic() {
|
|
|
|
oAudioPlayer->resumeBackgroundMusic();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleAudioEngine::rewindBackgroundMusic() {
|
|
|
|
oAudioPlayer->rewindBackgroundMusic();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SimpleAudioEngine::willPlayBackgroundMusic() {
|
|
|
|
return oAudioPlayer->willPlayBackgroundMusic();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SimpleAudioEngine::isBackgroundMusicPlaying() {
|
|
|
|
return oAudioPlayer->isBackgroundMusicPlaying();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleAudioEngine::preloadBackgroundMusic(const char* pszFilePath) {
|
2013-01-27 19:20:49 +08:00
|
|
|
// Changing file path to full path
|
2013-07-12 12:03:39 +08:00
|
|
|
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(pszFilePath);
|
2013-01-27 19:20:49 +08:00
|
|
|
return oAudioPlayer->preloadBackgroundMusic(fullPath.c_str());
|
2012-08-02 13:02:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// effect function
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-06-03 20:11:00 +08:00
|
|
|
unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath, bool bLoop,
|
|
|
|
float pitch, float pan, float gain) {
|
2013-06-03 20:59:50 +08:00
|
|
|
// Changing file path to full path
|
2013-07-12 12:03:39 +08:00
|
|
|
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(pszFilePath);
|
2013-06-03 20:59:50 +08:00
|
|
|
return oAudioPlayer->playEffect(fullPath.c_str(), bLoop, pitch, pan, gain);
|
2012-08-02 13:02:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleAudioEngine::stopEffect(unsigned int nSoundId) {
|
|
|
|
return oAudioPlayer->stopEffect(nSoundId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleAudioEngine::preloadEffect(const char* pszFilePath) {
|
2013-01-27 19:20:49 +08:00
|
|
|
// Changing file path to full path
|
2013-07-12 12:03:39 +08:00
|
|
|
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(pszFilePath);
|
2013-01-27 19:20:49 +08:00
|
|
|
return oAudioPlayer->preloadEffect(fullPath.c_str());
|
2012-08-02 13:02:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleAudioEngine::unloadEffect(const char* pszFilePath) {
|
2013-01-27 19:20:49 +08:00
|
|
|
// Changing file path to full path
|
2013-07-12 12:03:39 +08:00
|
|
|
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(pszFilePath);
|
2013-01-27 19:20:49 +08:00
|
|
|
return oAudioPlayer->unloadEffect(fullPath.c_str());
|
2012-08-02 13:02:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleAudioEngine::pauseEffect(unsigned int uSoundId) {
|
|
|
|
oAudioPlayer->pauseEffect(uSoundId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleAudioEngine::pauseAllEffects() {
|
|
|
|
oAudioPlayer->pauseAllEffects();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleAudioEngine::resumeEffect(unsigned int uSoundId) {
|
|
|
|
oAudioPlayer->resumeEffect(uSoundId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleAudioEngine::resumeAllEffects() {
|
|
|
|
oAudioPlayer->resumeAllEffects();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleAudioEngine::stopAllEffects() {
|
|
|
|
oAudioPlayer->stopAllEffects();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// volume interface
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
float SimpleAudioEngine::getBackgroundMusicVolume() {
|
|
|
|
return oAudioPlayer->getBackgroundMusicVolume();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleAudioEngine::setBackgroundMusicVolume(float volume) {
|
|
|
|
return oAudioPlayer->setBackgroundMusicVolume(volume);
|
|
|
|
}
|
|
|
|
|
|
|
|
float SimpleAudioEngine::getEffectsVolume() {
|
2013-03-02 08:12:42 +08:00
|
|
|
return oAudioPlayer->getEffectsVolume();
|
2012-08-02 13:02:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleAudioEngine::setEffectsVolume(float volume) {
|
|
|
|
return oAudioPlayer->setEffectsVolume(volume);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // end of namespace CocosDenshion
|
2013-07-05 16:28:06 +08:00
|
|
|
|
|
|
|
#endif
|