mirror of https://github.com/axmolengine/axmol.git
Change 2 spaces to 4 spaces indentation
This commit is contained in:
parent
03be0de2fa
commit
3a80e7d8fb
|
@ -33,7 +33,7 @@ FMOD_RESULT F_CALLBACK channelCallback(FMOD_CHANNELCONTROL *channelcontrol,
|
|||
void *commandData1, void *commandData2)
|
||||
{
|
||||
|
||||
if(controltype == FMOD_CHANNELCONTROL_CHANNEL && callbacktype == FMOD_CHANNELCONTROL_CALLBACK_END){
|
||||
if(controltype == FMOD_CHANNELCONTROL_CHANNEL && callbacktype == FMOD_CHANNELCONTROL_CALLBACK_END){
|
||||
g_AudioEngineImpl->onSoundFinished((FMOD::Channel *)channelcontrol);
|
||||
}else{
|
||||
}
|
||||
|
@ -45,262 +45,262 @@ AudioEngineImpl::AudioEngineImpl(){
|
|||
}
|
||||
|
||||
AudioEngineImpl::~AudioEngineImpl(){
|
||||
FMOD_RESULT result;
|
||||
result = pSystem->close();
|
||||
ERRCHECKWITHEXIT(result);
|
||||
result = pSystem->release();
|
||||
ERRCHECKWITHEXIT(result);
|
||||
FMOD_RESULT result;
|
||||
result = pSystem->close();
|
||||
ERRCHECKWITHEXIT(result);
|
||||
result = pSystem->release();
|
||||
ERRCHECKWITHEXIT(result);
|
||||
}
|
||||
|
||||
|
||||
bool AudioEngineImpl::init(){
|
||||
FMOD_RESULT result;
|
||||
/*
|
||||
Create a System object and initialize.
|
||||
*/
|
||||
result = FMOD::System_Create(&pSystem);
|
||||
ERRCHECKWITHEXIT(result);
|
||||
FMOD_RESULT result;
|
||||
/*
|
||||
Create a System object and initialize.
|
||||
*/
|
||||
result = FMOD::System_Create(&pSystem);
|
||||
ERRCHECKWITHEXIT(result);
|
||||
|
||||
result = pSystem->setOutput(FMOD_OUTPUTTYPE_PULSEAUDIO);
|
||||
ERRCHECKWITHEXIT(result);
|
||||
result = pSystem->setOutput(FMOD_OUTPUTTYPE_PULSEAUDIO);
|
||||
ERRCHECKWITHEXIT(result);
|
||||
|
||||
result = pSystem->init(32, FMOD_INIT_NORMAL, 0);
|
||||
ERRCHECKWITHEXIT(result);
|
||||
result = pSystem->init(32, FMOD_INIT_NORMAL, 0);
|
||||
ERRCHECKWITHEXIT(result);
|
||||
|
||||
mapChannelInfo.clear();
|
||||
mapSound.clear();
|
||||
mapChannelInfo.clear();
|
||||
mapSound.clear();
|
||||
|
||||
auto scheduler = cocos2d::Director::getInstance()->getScheduler();
|
||||
scheduler->schedule(schedule_selector(AudioEngineImpl::update), this, 0.05f, false);
|
||||
auto scheduler = cocos2d::Director::getInstance()->getScheduler();
|
||||
scheduler->schedule(schedule_selector(AudioEngineImpl::update), this, 0.05f, false);
|
||||
|
||||
g_AudioEngineImpl = this;
|
||||
g_AudioEngineImpl = this;
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
int AudioEngineImpl::play2d(const std::string &fileFullPath ,bool loop ,float volume){
|
||||
int id = preload(fileFullPath, nullptr);
|
||||
if(id >= 0){
|
||||
mapChannelInfo[id].loop=loop;
|
||||
mapChannelInfo[id].channel->setPaused(true);
|
||||
mapChannelInfo[id].volume = volume;
|
||||
AudioEngine::_audioIDInfoMap[id].state = AudioEngine::AudioState::PAUSED;
|
||||
resume(id);
|
||||
}
|
||||
return id;
|
||||
int id = preload(fileFullPath, nullptr);
|
||||
if(id >= 0){
|
||||
mapChannelInfo[id].loop=loop;
|
||||
mapChannelInfo[id].channel->setPaused(true);
|
||||
mapChannelInfo[id].volume = volume;
|
||||
AudioEngine::_audioIDInfoMap[id].state = AudioEngine::AudioState::PAUSED;
|
||||
resume(id);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
void AudioEngineImpl::setVolume(int audioID,float volume){
|
||||
try{
|
||||
mapChannelInfo[audioID].channel->setVolume(volume);
|
||||
}catch(const std::out_of_range& oor){
|
||||
printf("AudioEngineImpl::setVolume: invalid audioID: %d\n", audioID);
|
||||
}
|
||||
try{
|
||||
mapChannelInfo[audioID].channel->setVolume(volume);
|
||||
}catch(const std::out_of_range& oor){
|
||||
printf("AudioEngineImpl::setVolume: invalid audioID: %d\n", audioID);
|
||||
}
|
||||
}
|
||||
|
||||
void AudioEngineImpl::setLoop(int audioID, bool loop){
|
||||
try{
|
||||
mapChannelInfo[audioID].channel->setLoopCount(loop?-1:0);
|
||||
}catch(const std::out_of_range& oor){
|
||||
printf("AudioEngineImpl::setLoop: invalid audioID: %d\n", audioID);
|
||||
}
|
||||
try{
|
||||
mapChannelInfo[audioID].channel->setLoopCount(loop?-1:0);
|
||||
}catch(const std::out_of_range& oor){
|
||||
printf("AudioEngineImpl::setLoop: invalid audioID: %d\n", audioID);
|
||||
}
|
||||
}
|
||||
|
||||
bool AudioEngineImpl::pause(int audioID){
|
||||
try{
|
||||
mapChannelInfo[audioID].channel->setPaused(true);
|
||||
AudioEngine::_audioIDInfoMap[audioID].state = AudioEngine::AudioState::PAUSED;
|
||||
return true;
|
||||
}catch(const std::out_of_range& oor){
|
||||
printf("AudioEngineImpl::pause: invalid audioID: %d\n", audioID);
|
||||
return false;
|
||||
}
|
||||
try{
|
||||
mapChannelInfo[audioID].channel->setPaused(true);
|
||||
AudioEngine::_audioIDInfoMap[audioID].state = AudioEngine::AudioState::PAUSED;
|
||||
return true;
|
||||
}catch(const std::out_of_range& oor){
|
||||
printf("AudioEngineImpl::pause: invalid audioID: %d\n", audioID);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool AudioEngineImpl::resume(int audioID){
|
||||
try{
|
||||
try{
|
||||
|
||||
if(!mapChannelInfo[audioID].channel){
|
||||
FMOD::Channel *channel = nullptr;
|
||||
FMOD::ChannelGroup *channelgroup = nullptr;
|
||||
//starts the sound in pause mode, use the channel to unpause
|
||||
FMOD_RESULT result = pSystem->playSound(mapChannelInfo[audioID].sound, channelgroup, true, &channel);
|
||||
if(ERRCHECK(result)){
|
||||
return false;
|
||||
}
|
||||
channel->setMode(mapChannelInfo[audioID].loop?FMOD_LOOP_NORMAL:FMOD_LOOP_OFF);
|
||||
channel->setLoopCount(mapChannelInfo[audioID].loop?-1:0);
|
||||
channel->setVolume(mapChannelInfo[audioID].volume);
|
||||
channel->setUserData((void *)mapChannelInfo[audioID].id);
|
||||
mapChannelInfo[audioID].channel = channel;
|
||||
if(!mapChannelInfo[audioID].channel){
|
||||
FMOD::Channel *channel = nullptr;
|
||||
FMOD::ChannelGroup *channelgroup = nullptr;
|
||||
//starts the sound in pause mode, use the channel to unpause
|
||||
FMOD_RESULT result = pSystem->playSound(mapChannelInfo[audioID].sound, channelgroup, true, &channel);
|
||||
if(ERRCHECK(result)){
|
||||
return false;
|
||||
}
|
||||
channel->setMode(mapChannelInfo[audioID].loop?FMOD_LOOP_NORMAL:FMOD_LOOP_OFF);
|
||||
channel->setLoopCount(mapChannelInfo[audioID].loop?-1:0);
|
||||
channel->setVolume(mapChannelInfo[audioID].volume);
|
||||
channel->setUserData((void *)mapChannelInfo[audioID].id);
|
||||
mapChannelInfo[audioID].channel = channel;
|
||||
}
|
||||
|
||||
mapChannelInfo[audioID].channel->setPaused(false);
|
||||
AudioEngine::_audioIDInfoMap[audioID].state = AudioEngine::AudioState::PLAYING;
|
||||
|
||||
return true;
|
||||
}catch(const std::out_of_range& oor){
|
||||
printf("AudioEngineImpl::resume: invalid audioID: %d\n", audioID);
|
||||
return false;
|
||||
}
|
||||
|
||||
mapChannelInfo[audioID].channel->setPaused(false);
|
||||
AudioEngine::_audioIDInfoMap[audioID].state = AudioEngine::AudioState::PLAYING;
|
||||
|
||||
return true;
|
||||
}catch(const std::out_of_range& oor){
|
||||
printf("AudioEngineImpl::resume: invalid audioID: %d\n", audioID);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool AudioEngineImpl::stop(int audioID){
|
||||
try{
|
||||
mapChannelInfo[audioID].channel->stop();
|
||||
mapChannelInfo[audioID].channel = nullptr;
|
||||
return true;
|
||||
}catch(const std::out_of_range& oor){
|
||||
printf("AudioEngineImpl::stop: invalid audioID: %d\n", audioID);
|
||||
return false;
|
||||
}
|
||||
try{
|
||||
mapChannelInfo[audioID].channel->stop();
|
||||
mapChannelInfo[audioID].channel = nullptr;
|
||||
return true;
|
||||
}catch(const std::out_of_range& oor){
|
||||
printf("AudioEngineImpl::stop: invalid audioID: %d\n", audioID);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void AudioEngineImpl::stopAll(){
|
||||
for (auto it = mapChannelInfo.begin(); it != mapChannelInfo.end(); ++it) {
|
||||
ChannelInfo & audioRef = it->second;
|
||||
audioRef.channel->stop();
|
||||
audioRef.channel = nullptr;
|
||||
}
|
||||
for (auto it = mapChannelInfo.begin(); it != mapChannelInfo.end(); ++it) {
|
||||
ChannelInfo & audioRef = it->second;
|
||||
audioRef.channel->stop();
|
||||
audioRef.channel = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
float AudioEngineImpl::getDuration(int audioID){
|
||||
try{
|
||||
FMOD::Sound * sound = mapChannelInfo[audioID].sound;
|
||||
unsigned int length;
|
||||
FMOD_RESULT result = sound->getLength(&length, FMOD_TIMEUNIT_MS);
|
||||
ERRCHECK(result);
|
||||
float duration = (float)length / 1000.0f;
|
||||
return duration;
|
||||
try{
|
||||
FMOD::Sound * sound = mapChannelInfo[audioID].sound;
|
||||
unsigned int length;
|
||||
FMOD_RESULT result = sound->getLength(&length, FMOD_TIMEUNIT_MS);
|
||||
ERRCHECK(result);
|
||||
float duration = (float)length / 1000.0f;
|
||||
return duration;
|
||||
}catch(const std::out_of_range& oor){
|
||||
printf("AudioEngineImpl::getDuration: invalid audioID: %d\n", audioID);
|
||||
return AudioEngine::TIME_UNKNOWN;
|
||||
}
|
||||
printf("AudioEngineImpl::getDuration: invalid audioID: %d\n", audioID);
|
||||
return AudioEngine::TIME_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
float AudioEngineImpl::getCurrentTime(int audioID){
|
||||
try{
|
||||
unsigned int position;
|
||||
FMOD_RESULT result = mapChannelInfo[audioID].channel->getPosition(&position, FMOD_TIMEUNIT_MS);
|
||||
ERRCHECK(result);
|
||||
float currenttime = position /1000.0f;
|
||||
return currenttime;
|
||||
try{
|
||||
unsigned int position;
|
||||
FMOD_RESULT result = mapChannelInfo[audioID].channel->getPosition(&position, FMOD_TIMEUNIT_MS);
|
||||
ERRCHECK(result);
|
||||
float currenttime = position /1000.0f;
|
||||
return currenttime;
|
||||
}catch(const std::out_of_range& oor){
|
||||
printf("AudioEngineImpl::getCurrentTime: invalid audioID: %d\n", audioID);
|
||||
return AudioEngine::TIME_UNKNOWN;
|
||||
}
|
||||
printf("AudioEngineImpl::getCurrentTime: invalid audioID: %d\n", audioID);
|
||||
return AudioEngine::TIME_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
bool AudioEngineImpl::setCurrentTime(int audioID, float time){
|
||||
try{
|
||||
unsigned int position = (unsigned int)(time * 1000.0f);
|
||||
FMOD_RESULT result = mapChannelInfo[audioID].channel->setPosition(position, FMOD_TIMEUNIT_MS);
|
||||
ERRCHECK(result);
|
||||
try{
|
||||
unsigned int position = (unsigned int)(time * 1000.0f);
|
||||
FMOD_RESULT result = mapChannelInfo[audioID].channel->setPosition(position, FMOD_TIMEUNIT_MS);
|
||||
ERRCHECK(result);
|
||||
}catch(const std::out_of_range& oor){
|
||||
printf("AudioEngineImpl::setCurrentTime: invalid audioID: %d\n", audioID);
|
||||
}
|
||||
printf("AudioEngineImpl::setCurrentTime: invalid audioID: %d\n", audioID);
|
||||
}
|
||||
}
|
||||
|
||||
void AudioEngineImpl::setFinishCallback(int audioID, const std::function<void (int, const std::string &)> &callback){
|
||||
try{
|
||||
FMOD::Channel * channel = mapChannelInfo[audioID].channel;
|
||||
mapChannelInfo[audioID].callback = callback;
|
||||
FMOD_RESULT result = channel->setCallback(channelCallback);
|
||||
ERRCHECK(result);
|
||||
try{
|
||||
FMOD::Channel * channel = mapChannelInfo[audioID].channel;
|
||||
mapChannelInfo[audioID].callback = callback;
|
||||
FMOD_RESULT result = channel->setCallback(channelCallback);
|
||||
ERRCHECK(result);
|
||||
}catch(const std::out_of_range& oor){
|
||||
printf("AudioEngineImpl::setFinishCallback: invalid audioID: %d\n", audioID);
|
||||
}
|
||||
printf("AudioEngineImpl::setFinishCallback: invalid audioID: %d\n", audioID);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AudioEngineImpl::onSoundFinished(FMOD::Channel * channel){
|
||||
size_t id;
|
||||
size_t id;
|
||||
try{
|
||||
void * data;
|
||||
channel->getUserData(&data);
|
||||
id = (size_t) data;
|
||||
if(mapChannelInfo[id].callback){
|
||||
mapChannelInfo[id].callback(id, mapChannelInfo[id].path);
|
||||
}
|
||||
mapChannelInfo[id].channel = nullptr;
|
||||
void * data;
|
||||
channel->getUserData(&data);
|
||||
id = (size_t) data;
|
||||
if(mapChannelInfo[id].callback){
|
||||
mapChannelInfo[id].callback(id, mapChannelInfo[id].path);
|
||||
}
|
||||
mapChannelInfo[id].channel = nullptr;
|
||||
}catch(const std::out_of_range& oor){
|
||||
printf("AudioEngineImpl::onSoundFinished: invalid audioID: %d\n", id);
|
||||
}
|
||||
printf("AudioEngineImpl::onSoundFinished: invalid audioID: %d\n", id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AudioEngineImpl::uncache(const std::string& path){
|
||||
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(path);
|
||||
std::map<std::string, FMOD::Sound *>::const_iterator it = mapSound.find(fullPath);
|
||||
if(it!=mapSound.end()){
|
||||
FMOD::Sound * sound = it->second;
|
||||
if(sound){
|
||||
sound->release();
|
||||
}
|
||||
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(path);
|
||||
std::map<std::string, FMOD::Sound *>::const_iterator it = mapSound.find(fullPath);
|
||||
if(it!=mapSound.end()){
|
||||
FMOD::Sound * sound = it->second;
|
||||
if(sound){
|
||||
sound->release();
|
||||
}
|
||||
mapSound.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AudioEngineImpl::uncacheAll(){
|
||||
for (auto it = mapSound.cbegin(); it != mapSound.cend(); ++it) {
|
||||
auto sound = it->second;
|
||||
if(sound){
|
||||
sound->release();
|
||||
}
|
||||
for (auto it = mapSound.cbegin(); it != mapSound.cend(); ++it) {
|
||||
auto sound = it->second;
|
||||
if(sound){
|
||||
sound->release();
|
||||
}
|
||||
}
|
||||
mapSound.clear();
|
||||
}
|
||||
|
||||
|
||||
int AudioEngineImpl::preload(const std::string& filePath, std::function<void(bool isSuccess)> callback){
|
||||
FMOD::Sound * sound = findSound(filePath);
|
||||
if(!sound){
|
||||
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(filePath);
|
||||
FMOD_RESULT result = pSystem->createSound(fullPath.c_str(), FMOD_LOOP_OFF, 0, &sound);
|
||||
if (ERRCHECK(result)){
|
||||
printf("sound effect in %s could not be preload\n", filePath.c_str());
|
||||
if(callback){
|
||||
callback(false);
|
||||
}
|
||||
return -1;
|
||||
FMOD::Sound * sound = findSound(filePath);
|
||||
if(!sound){
|
||||
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(filePath);
|
||||
FMOD_RESULT result = pSystem->createSound(fullPath.c_str(), FMOD_LOOP_OFF, 0, &sound);
|
||||
if (ERRCHECK(result)){
|
||||
printf("sound effect in %s could not be preload\n", filePath.c_str());
|
||||
if(callback){
|
||||
callback(false);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
mapSound[fullPath] = sound;
|
||||
}
|
||||
mapSound[fullPath] = sound;
|
||||
}
|
||||
|
||||
int id = mapChannelInfo.size() + 1;
|
||||
auto& chanelInfo = mapChannelInfo[id];
|
||||
chanelInfo.sound = sound;
|
||||
chanelInfo.id = (size_t) id;
|
||||
chanelInfo.channel = nullptr;
|
||||
chanelInfo.callback = nullptr;
|
||||
chanelInfo.path = filePath;
|
||||
//we are going to use UserData to store pointer to Channel when playing
|
||||
chanelInfo.sound->setUserData((void *)id);
|
||||
int id = mapChannelInfo.size() + 1;
|
||||
auto& chanelInfo = mapChannelInfo[id];
|
||||
chanelInfo.sound = sound;
|
||||
chanelInfo.id = (size_t) id;
|
||||
chanelInfo.channel = nullptr;
|
||||
chanelInfo.callback = nullptr;
|
||||
chanelInfo.path = filePath;
|
||||
//we are going to use UserData to store pointer to Channel when playing
|
||||
chanelInfo.sound->setUserData((void *)id);
|
||||
|
||||
if(callback){
|
||||
callback(true);
|
||||
}
|
||||
return id;
|
||||
if(callback){
|
||||
callback(true);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
void AudioEngineImpl::update(float dt){
|
||||
pSystem->update();
|
||||
pSystem->update();
|
||||
}
|
||||
|
||||
|
||||
FMOD::Sound * AudioEngineImpl::findSound(const std::string &path){
|
||||
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(path);
|
||||
std::map<std::string, FMOD::Sound *>::const_iterator it = mapSound.find(fullPath);
|
||||
return (it!=mapSound.end())?(it->second):nullptr;
|
||||
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(path);
|
||||
std::map<std::string, FMOD::Sound *>::const_iterator it = mapSound.find(fullPath);
|
||||
return (it!=mapSound.end())?(it->second):nullptr;
|
||||
}
|
||||
|
||||
|
||||
FMOD::Channel * AudioEngineImpl::getChannel(FMOD::Sound *sound){
|
||||
size_t id;
|
||||
void * data;
|
||||
sound->getUserData(&data);
|
||||
id = (size_t) data;
|
||||
return mapChannelInfo[id].channel;
|
||||
size_t id;
|
||||
void * data;
|
||||
sound->getUserData(&data);
|
||||
id = (size_t) data;
|
||||
return mapChannelInfo[id].channel;
|
||||
}
|
||||
|
|
|
@ -9,50 +9,50 @@ using namespace cocos2d::experimental;
|
|||
|
||||
|
||||
struct SimpleAudioEngineLinux{
|
||||
SimpleAudioEngine * engine = nullptr;
|
||||
int musicid;
|
||||
float effectsvolume;
|
||||
std::string musicpath;
|
||||
SimpleAudioEngine * engine = nullptr;
|
||||
int musicid;
|
||||
float effectsvolume;
|
||||
std::string musicpath;
|
||||
};
|
||||
|
||||
SimpleAudioEngineLinux * g_SimpleAudioEngineLinux = nullptr;
|
||||
SimpleAudioEngineLinux * g_SimpleAudioEngineLinux = nullptr;
|
||||
|
||||
|
||||
SimpleAudioEngine* SimpleAudioEngine::getInstance(){
|
||||
if(!g_SimpleAudioEngineLinux){
|
||||
g_SimpleAudioEngineLinux = new SimpleAudioEngineLinux();
|
||||
g_SimpleAudioEngineLinux->engine = new SimpleAudioEngine();
|
||||
}
|
||||
return g_SimpleAudioEngineLinux->engine;
|
||||
if(!g_SimpleAudioEngineLinux){
|
||||
g_SimpleAudioEngineLinux = new SimpleAudioEngineLinux();
|
||||
g_SimpleAudioEngineLinux->engine = new SimpleAudioEngine();
|
||||
}
|
||||
return g_SimpleAudioEngineLinux->engine;
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::end(){
|
||||
void SimpleAudioEngine::end(){
|
||||
if(g_SimpleAudioEngineLinux){
|
||||
delete g_SimpleAudioEngineLinux->engine;
|
||||
delete g_SimpleAudioEngineLinux;
|
||||
delete g_SimpleAudioEngineLinux->engine;
|
||||
delete g_SimpleAudioEngineLinux;
|
||||
}
|
||||
g_SimpleAudioEngineLinux = nullptr;
|
||||
}
|
||||
g_SimpleAudioEngineLinux = nullptr;
|
||||
}
|
||||
|
||||
|
||||
SimpleAudioEngine::SimpleAudioEngine(){
|
||||
g_SimpleAudioEngineLinux->musicid = -1;
|
||||
g_SimpleAudioEngineLinux->effectsvolume = 1.0f;
|
||||
}
|
||||
SimpleAudioEngine::SimpleAudioEngine(){
|
||||
g_SimpleAudioEngineLinux->musicid = -1;
|
||||
g_SimpleAudioEngineLinux->effectsvolume = 1.0f;
|
||||
}
|
||||
|
||||
SimpleAudioEngine::~SimpleAudioEngine(){
|
||||
SimpleAudioEngine::~SimpleAudioEngine(){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::preloadBackgroundMusic(const char* filePath){
|
||||
g_SimpleAudioEngineLinux->musicpath = filePath;
|
||||
AudioEngine::preload(filePath);
|
||||
}
|
||||
void SimpleAudioEngine::preloadBackgroundMusic(const char* filePath){
|
||||
g_SimpleAudioEngineLinux->musicpath = filePath;
|
||||
AudioEngine::preload(filePath);
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::playBackgroundMusic(const char* filePath, bool loop){
|
||||
g_SimpleAudioEngineLinux->musicpath = filePath;
|
||||
g_SimpleAudioEngineLinux->musicid = AudioEngine::play2d(filePath, loop);
|
||||
}
|
||||
void SimpleAudioEngine::playBackgroundMusic(const char* filePath, bool loop){
|
||||
g_SimpleAudioEngineLinux->musicpath = filePath;
|
||||
g_SimpleAudioEngineLinux->musicid = AudioEngine::play2d(filePath, loop);
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::stopBackgroundMusic(bool releaseData){
|
||||
AudioEngine::stop(g_SimpleAudioEngineLinux->musicid);
|
||||
|
@ -61,38 +61,38 @@ SimpleAudioEngine* SimpleAudioEngine::getInstance(){
|
|||
}
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::pauseBackgroundMusic(){
|
||||
AudioEngine::pause(g_SimpleAudioEngineLinux->musicid);
|
||||
}
|
||||
void SimpleAudioEngine::pauseBackgroundMusic(){
|
||||
AudioEngine::pause(g_SimpleAudioEngineLinux->musicid);
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::resumeBackgroundMusic(){
|
||||
AudioEngine::resume(g_SimpleAudioEngineLinux->musicid);
|
||||
}
|
||||
void SimpleAudioEngine::resumeBackgroundMusic(){
|
||||
AudioEngine::resume(g_SimpleAudioEngineLinux->musicid);
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::rewindBackgroundMusic(){
|
||||
AudioEngine::setCurrentTime(g_SimpleAudioEngineLinux->musicid, 0);
|
||||
}
|
||||
|
||||
bool SimpleAudioEngine::willPlayBackgroundMusic(){
|
||||
return g_SimpleAudioEngineLinux->musicid != -1;
|
||||
}
|
||||
bool SimpleAudioEngine::willPlayBackgroundMusic(){
|
||||
return g_SimpleAudioEngineLinux->musicid != -1;
|
||||
}
|
||||
|
||||
bool SimpleAudioEngine::isBackgroundMusicPlaying(){
|
||||
return AudioEngine::getState(g_SimpleAudioEngineLinux->musicid) == AudioEngine::AudioState::PLAYING;
|
||||
}
|
||||
|
||||
//
|
||||
// properties
|
||||
//
|
||||
//
|
||||
// properties
|
||||
//
|
||||
|
||||
/**
|
||||
* The volume of the background music within the range of 0.0 as the minimum and 1.0 as the maximum.
|
||||
* @js getMusicVolume
|
||||
* @lua getMusicVolume
|
||||
*/
|
||||
float SimpleAudioEngine::getBackgroundMusicVolume(){
|
||||
return AudioEngine::getVolume(g_SimpleAudioEngineLinux->musicid);
|
||||
}
|
||||
/**
|
||||
* The volume of the background music within the range of 0.0 as the minimum and 1.0 as the maximum.
|
||||
* @js getMusicVolume
|
||||
* @lua getMusicVolume
|
||||
*/
|
||||
float SimpleAudioEngine::getBackgroundMusicVolume(){
|
||||
return AudioEngine::getVolume(g_SimpleAudioEngineLinux->musicid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the volume of background music.
|
||||
|
@ -105,12 +105,12 @@ SimpleAudioEngine* SimpleAudioEngine::getInstance(){
|
|||
AudioEngine::setVolume(g_SimpleAudioEngineLinux->musicid, volume);
|
||||
}
|
||||
|
||||
/**
|
||||
* The volume of the effects within the range of 0.0 as the minimum and 1.0 as the maximum.
|
||||
*/
|
||||
float SimpleAudioEngine::getEffectsVolume(){
|
||||
return g_SimpleAudioEngineLinux->effectsvolume;
|
||||
}
|
||||
/**
|
||||
* The volume of the effects within the range of 0.0 as the minimum and 1.0 as the maximum.
|
||||
*/
|
||||
float SimpleAudioEngine::getEffectsVolume(){
|
||||
return g_SimpleAudioEngineLinux->effectsvolume;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the volume of sound effects.
|
||||
|
@ -121,23 +121,23 @@ SimpleAudioEngine* SimpleAudioEngine::getInstance(){
|
|||
g_SimpleAudioEngineLinux->effectsvolume = volume;
|
||||
}
|
||||
|
||||
/**
|
||||
* Play sound effect with a file path, pitch, pan and gain.
|
||||
*
|
||||
* @param filePath The path of the effect file.
|
||||
* @param loop Determines whether to loop the effect playing or not. The default value is false.
|
||||
* @param pitch Frequency, normal value is 1.0. Will also change effect play time.
|
||||
* @param pan Stereo effect, in the range of [-1..1] where -1 enables only left channel.
|
||||
* @param gain Volume, in the range of [0..1]. The normal value is 1.
|
||||
* @return The sound id.
|
||||
*
|
||||
* @note Full support is under development, now there are limitations:
|
||||
* - no pitch effect on Samsung Galaxy S2 with OpenSL backend enabled;
|
||||
* - no pitch/pan/gain on win32.
|
||||
*/
|
||||
unsigned int SimpleAudioEngine::playEffect(const char* filePath, bool loop, float pitch, float pan, float gain){
|
||||
return AudioEngine::play2d(filePath, loop, gain);
|
||||
}
|
||||
/**
|
||||
* Play sound effect with a file path, pitch, pan and gain.
|
||||
*
|
||||
* @param filePath The path of the effect file.
|
||||
* @param loop Determines whether to loop the effect playing or not. The default value is false.
|
||||
* @param pitch Frequency, normal value is 1.0. Will also change effect play time.
|
||||
* @param pan Stereo effect, in the range of [-1..1] where -1 enables only left channel.
|
||||
* @param gain Volume, in the range of [0..1]. The normal value is 1.
|
||||
* @return The sound id.
|
||||
*
|
||||
* @note Full support is under development, now there are limitations:
|
||||
* - no pitch effect on Samsung Galaxy S2 with OpenSL backend enabled;
|
||||
* - no pitch/pan/gain on win32.
|
||||
*/
|
||||
unsigned int SimpleAudioEngine::playEffect(const char* filePath, bool loop, float pitch, float pan, float gain){
|
||||
return AudioEngine::play2d(filePath, loop, gain);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pause playing sound effect.
|
||||
|
@ -148,12 +148,12 @@ SimpleAudioEngine* SimpleAudioEngine::getInstance(){
|
|||
AudioEngine::pause(soundId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pause all playing sound effect.
|
||||
*/
|
||||
void SimpleAudioEngine::pauseAllEffects(){
|
||||
AudioEngine::pauseAll();
|
||||
}
|
||||
/**
|
||||
* Pause all playing sound effect.
|
||||
*/
|
||||
void SimpleAudioEngine::pauseAllEffects(){
|
||||
AudioEngine::pauseAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resume playing sound effect.
|
||||
|
@ -164,12 +164,12 @@ SimpleAudioEngine* SimpleAudioEngine::getInstance(){
|
|||
AudioEngine::resume(soundId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resume all playing sound effect.
|
||||
*/
|
||||
void SimpleAudioEngine::resumeAllEffects(){
|
||||
AudioEngine::resumeAll();
|
||||
}
|
||||
/**
|
||||
* Resume all playing sound effect.
|
||||
*/
|
||||
void SimpleAudioEngine::resumeAllEffects(){
|
||||
AudioEngine::resumeAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop playing sound effect.
|
||||
|
@ -180,12 +180,12 @@ SimpleAudioEngine* SimpleAudioEngine::getInstance(){
|
|||
AudioEngine::stop(soundId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop all playing sound effects.
|
||||
*/
|
||||
void SimpleAudioEngine::stopAllEffects(){
|
||||
AudioEngine::stopAll();
|
||||
}
|
||||
/**
|
||||
* Stop all playing sound effects.
|
||||
*/
|
||||
void SimpleAudioEngine::stopAllEffects(){
|
||||
AudioEngine::stopAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Preload a compressed audio file.
|
||||
|
@ -199,13 +199,13 @@ SimpleAudioEngine* SimpleAudioEngine::getInstance(){
|
|||
AudioEngine::preload(filePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unload the preloaded effect from internal buffer.
|
||||
*
|
||||
* @param filePath The path of the effect file.
|
||||
*/
|
||||
void SimpleAudioEngine::unloadEffect(const char* filePath){
|
||||
AudioEngine::uncache(filePath);
|
||||
}
|
||||
/**
|
||||
* Unload the preloaded effect from internal buffer.
|
||||
*
|
||||
* @param filePath The path of the effect file.
|
||||
*/
|
||||
void SimpleAudioEngine::unloadEffect(const char* filePath){
|
||||
AudioEngine::uncache(filePath);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue