AudioEngine:Linux: implementation using FMOD, refactor to SimpleAudioEngine now as wrapper of AUdioEngine, upgrade FMOD binaries

This commit is contained in:
cesarpachon 2015-11-24 20:54:12 -05:00
parent 3f9b40c093
commit 40f6f76030
20 changed files with 681 additions and 1069 deletions

View File

@ -200,7 +200,7 @@ if(LINUX OR MACOSX OR WINDOWS)
find_package(Threads REQUIRED)
set(THREADS_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
cocos_find_package(FMODEX FMODEX REQUIRED)
cocos_find_package(FMOD FMOD REQUIRED)
cocos_find_package(Fontconfig FONTCONFIG REQUIRED)
cocos_find_package(GTK3 GTK3 REQUIRED)
endif()

View File

@ -60,9 +60,9 @@ set(_OpenalSoft_libs OpenAL32)
set(_zlib_inc zlib.h)
set(_zlib_libs z libzlib libz)
set(_fmod_prefix FMODEX)
set(_fmod_inc fmod.h)
set(_fmod_libs fmodex fmodex64 fmodexL fmodexL64)
set(_fmod_prefix FMOD)
set(_fmod_inc fmod.hpp)
set(_fmod_libs fmod fmod64 fmod fmod64)
set(all_prebuilt_libs
chipmunk

View File

@ -0,0 +1,51 @@
#.rst:
# FindFMOD
# ------------
#
# Locate FMOD Ex library
#
# This module defines
#
# ::
#
# FMOD_LIBRARIES, the library to link against
# FMOD_FOUND, if false, do not try to link to fmodex
# FMOD_INCLUDE_DIRS, where to find headers.
#
find_path(FMOD_INCLUDE_DIR fmod.hpp
HINTS ENV FMOD_DIR
PATH_SUFFIXES include/fmod include
PATHS
~/Library/Frameworks
/Library/Frameworks
/usr/local
/usr
/sw # Fink
/opt/local # DarwinPorts
/opt/csw # Blastwave
/opt
)
find_library(FMOD_LIBRARY NAMES fmod fmod64
HINTS ENV FMOD_DIR
PATH_SUFFIXES lib
PATHS
~/Library/Frameworks
/Library/Frameworks
/usr/local
/usr
/sw # Fink
/opt/local # DarwinPorts
/opt/csw # Blastwave
/opt
)
set(FMOD_INCLUDE_DIRS "${FMOD_INCLUDE_DIR}")
set(FMOD_LIBRARIES "${FMOD_LIBRARY}")
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
find_package_handle_standard_args(FMOD DEFAULT_MSG FMOD_LIBRARIES FMOD_INCLUDE_DIRS)
mark_as_advanced(FMOD_INCLUDE_DIR FMOD_LIBRARY FMOD_INCLUDE_DIRS FMOD_LIBRARIES)

View File

@ -1,51 +0,0 @@
#.rst:
# FindFMODEX
# ------------
#
# Locate FMOD Ex library
#
# This module defines
#
# ::
#
# FMODEX_LIBRARIES, the library to link against
# FMODEX_FOUND, if false, do not try to link to fmodex
# FMODEX_INCLUDE_DIRS, where to find headers.
#
find_path(FMODEX_INCLUDE_DIR fmod.h
HINTS ENV FMODEX_DIR
PATH_SUFFIXES include/fmodex include
PATHS
~/Library/Frameworks
/Library/Frameworks
/usr/local
/usr
/sw # Fink
/opt/local # DarwinPorts
/opt/csw # Blastwave
/opt
)
find_library(FMODEX_LIBRARY NAMES fmodex fmodex64
HINTS ENV FMODEX_DIR
PATH_SUFFIXES lib
PATHS
~/Library/Frameworks
/Library/Frameworks
/usr/local
/usr
/sw # Fink
/opt/local # DarwinPorts
/opt/csw # Blastwave
/opt
)
set(FMODEX_INCLUDE_DIRS "${FMODEX_INCLUDE_DIR}")
set(FMODEX_LIBRARIES "${FMODEX_LIBRARY}")
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
find_package_handle_standard_args(FMODEX DEFAULT_MSG FMODEX_LIBRARIES FMODEX_INCLUDE_DIRS)
mark_as_advanced(FMODEX_INCLUDE_DIR FMODEX_LIBRARY FMODEX_INCLUDE_DIRS FMODEX_LIBRARIES)

View File

@ -96,7 +96,7 @@ if(WINDOWS)
endforeach()
list(APPEND PLATFORM_SPECIFIC_LIBS ws2_32 winmm)
elseif(LINUX)
foreach(_pkg OPENGL GLEW GLFW3 FMODEX FONTCONFIG THREADS GTK3)
foreach(_pkg OPENGL GLEW GLFW3 FMOD FONTCONFIG THREADS GTK3)
cocos_use_pkg(cocos2d ${_pkg})
endforeach()
elseif(MACOSX OR APPLE)

View File

@ -24,8 +24,6 @@
#include "platform/CCPlatformConfig.h"
#if CC_TARGET_PLATFORM == CC_PLATFORM_WINRT || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
#include "audio/include/AudioEngine.h"
#include <condition_variable>
#include <queue>
@ -40,6 +38,8 @@
#include "win32/AudioEngine-win32.h"
#elif CC_TARGET_PLATFORM == CC_PLATFORM_WINRT
#include "winrt/AudioEngine-winrt.h"
#elif CC_TARGET_PLATFORM == CC_PLATFORM_LINUX
#include "linux/AudioEngine-linux.h"
#endif
#define TIME_DELAY_PRECISION 0.0001
@ -538,5 +538,3 @@ void AudioEngine::addTask(const std::function<void()>& task)
s_threadPool->addTask(task);
}
}
#endif

View File

@ -15,10 +15,9 @@ if(WINDOWS)
elseif(LINUX)
set(COCOS_AUDIO_PLATFORM_SRC
audio/linux/SimpleAudioEngineFMOD.cpp
audio/linux/FmodAudioPlayer.cpp
audio/linux/FmodAudioPlayer.h
audio/linux/AudioPlayer.h
audio/linux/SimpleAudioEngine.cpp
audio/linux/AudioEngine-linux.h
audio/linux/AudioEngine-linux.cpp
)
elseif(MACOSX)

View File

@ -23,7 +23,6 @@
****************************************************************************/
#include "platform/CCPlatformConfig.h"
#if CC_TARGET_PLATFORM == CC_PLATFORM_WINRT || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
#ifndef __AUDIO_ENGINE_H_
#define __AUDIO_ENGINE_H_
@ -360,4 +359,3 @@ NS_CC_END
/// @}
#endif // __AUDIO_ENGINE_H_
#endif

View File

@ -0,0 +1,302 @@
/**
* @author cesarpachon
*/
#include <cstring>
#include "AudioEngine-linux.h"
#include "cocos2d.h"
using namespace cocos2d;
using namespace cocos2d::experimental;
AudioEngineImpl * g_AudioEngineImpl = nullptr;
void ERRCHECKWITHEXIT(FMOD_RESULT result) {
if (result != FMOD_OK) {
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
}
}
bool ERRCHECK(FMOD_RESULT result) {
if (result != FMOD_OK) {
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
return true;
}
return false;
}
FMOD_RESULT F_CALLBACK channelCallback(FMOD_CHANNELCONTROL *channelcontrol,
FMOD_CHANNELCONTROL_TYPE controltype,
FMOD_CHANNELCONTROL_CALLBACK_TYPE callbacktype,
void *commandData1, void *commandData2)
{
if(controltype == FMOD_CHANNELCONTROL_CHANNEL && callbacktype == FMOD_CHANNELCONTROL_CALLBACK_END){
g_AudioEngineImpl->onSoundFinished((FMOD::Channel *)channelcontrol);
}else{
}
return FMOD_OK;
}
AudioEngineImpl::AudioEngineImpl(){
};
AudioEngineImpl::~AudioEngineImpl(){
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);
result = pSystem->setOutput(FMOD_OUTPUTTYPE_PULSEAUDIO);
ERRCHECKWITHEXIT(result);
result = pSystem->init(32, FMOD_INIT_NORMAL, 0);
ERRCHECKWITHEXIT(result);
mapChannelInfo.clear();
mapSound.clear();
auto scheduler = cocos2d::Director::getInstance()->getScheduler();
scheduler->schedule(schedule_selector(AudioEngineImpl::update), this, 0.05f, false);
g_AudioEngineImpl = this;
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;
};
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);
}
};
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);
}
};
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;
}
};
bool AudioEngineImpl::resume(int audioID){
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;
}
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;
}
};
void AudioEngineImpl::stopAll(){
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;
}catch(const std::out_of_range& oor){
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;
}catch(const std::out_of_range& oor){
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);
}catch(const std::out_of_range& oor){
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);
}catch(const std::out_of_range& oor){
printf("AudioEngineImpl::setFinishCallback: invalid audioID: %d\n", audioID);
}
};
void AudioEngineImpl::onSoundFinished(FMOD::Channel * channel){
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;
}catch(const std::out_of_range& oor){
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();
}
mapSound.erase(it);
}
};
void AudioEngineImpl::uncacheAll(){
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;
}
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);
if(callback){
callback(true);
}
return id;
};
void AudioEngineImpl::update(float dt){
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;
}
FMOD::Channel * AudioEngineImpl::getChannel(FMOD::Sound *sound){
size_t id;
void * data;
sound->getUserData(&data);
id = (size_t) data;
return mapChannelInfo[id].channel;
};

View File

@ -0,0 +1,106 @@
/****************************************************************************
Copyright (c) 2015 Chukong Technologies Inc.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "platform/CCPlatformConfig.h"
#if CC_TARGET_PLATFORM == CC_PLATFORM_LINUX
#ifndef __AUDIO_ENGINE_LINUX_H_
#define __AUDIO_ENGINE_LINUX_H_
#include <functional>
#include <iostream>
#include <map>
#include "fmod.hpp"
#include "fmod_errors.h"
#include "AudioEngine.h"
#include "base/CCRef.h"
NS_CC_BEGIN
namespace experimental{
#define MAX_AUDIOINSTANCES 32
class CC_DLL AudioEngineImpl : public cocos2d::Ref
{
public:
AudioEngineImpl();
~AudioEngineImpl();
bool init();
int play2d(const std::string &fileFullPath ,bool loop ,float volume);
void setVolume(int audioID,float volume);
void setLoop(int audioID, bool loop);
bool pause(int audioID);
bool resume(int audioID);
bool stop(int audioID);
void stopAll();
float getDuration(int audioID);
float getCurrentTime(int audioID);
bool setCurrentTime(int audioID, float time);
void setFinishCallback(int audioID, const std::function<void (int, const std::string &)> &callback);
void uncache(const std::string& filePath);
void uncacheAll();
int preload(const std::string& filePath, std::function<void(bool isSuccess)> callback);
void update(float dt);
/**
* used internally by ffmod callback
*/
void onSoundFinished(FMOD::Channel * channel);
private:
/**
* returns null if a sound with the given path is not found
*/
FMOD::Sound * findSound(const std::string &path);
FMOD::Channel * getChannel(FMOD::Sound *);
struct ChannelInfo{
size_t id;
std::string path;
FMOD::Sound * sound;
FMOD::Channel * channel;
bool loop;
float volume;
std::function<void (int, const std::string &)> callback;
};
std::map<int, ChannelInfo> mapChannelInfo;
std::map<std::string, FMOD::Sound *> mapSound;
FMOD::System* pSystem;
};
}
NS_CC_END
#endif // __AUDIO_ENGINE_LINUX_H_
#endif

View File

@ -1,158 +0,0 @@
/****************************************************************************
Copyright (c) 2011 Laschweinski
Copyright (c) 2013-2014 Chukong Technologies Inc.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef AUDIOPLAYER_H_
#define AUDIOPLAYER_H_
namespace CocosDenshion {
class AudioPlayer {
public:
virtual void close() = 0;
/**
@brief Preload background music
@param pszFilePath The path of the background music file,or the FileName of T_SoundResInfo
*/
virtual void preloadBackgroundMusic(const char* pszFilePath) = 0;
/**
@brief Play background music
@param pszFilePath The path of the background music file,or the FileName of T_SoundResInfo
@param bLoop Whether the background music loop or not
*/
virtual void playBackgroundMusic(const char* pszFilePath, bool bLoop = false) = 0;
/**
@brief Stop playing background music
@param bReleaseData If release the background music data or not.As default value is false
*/
virtual void stopBackgroundMusic(bool bReleaseData = false) = 0;
/**
@brief Pause playing background music
*/
virtual void pauseBackgroundMusic() = 0;
/**
@brief Resume playing background music
*/
virtual void resumeBackgroundMusic() = 0;
/**
@brief Rewind playing background music
*/
virtual void rewindBackgroundMusic() = 0;
virtual bool willPlayBackgroundMusic() = 0;
/**
@brief Whether the background music is playing
@return If is playing return true,or return false
*/
virtual bool isBackgroundMusicPlaying() = 0;
// properties
/**
@brief The volume of the background music max value is 1.0,the min value is 0.0
*/
virtual float getBackgroundMusicVolume() = 0;
/**
@brief set the volume of background music
@param volume must be in 0.0~1.0
*/
virtual void setBackgroundMusicVolume(float volume) = 0;
/**
@brief The volume of the effects max value is 1.0,the min value is 0.0
*/
virtual float getEffectsVolume() = 0;
/**
@brief set the volume of sound effecs
@param volume must be in 0.0~1.0
*/
virtual void setEffectsVolume(float volume) = 0;
// for sound effects
/**
@brief Play sound effect
@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,
float pitch, float pan, float gain) = 0;
/**
@brief Stop playing sound effect
@param nSoundId The return value of function playEffect
*/
virtual void stopEffect(unsigned int nSoundId) = 0;
/**
@brief preload a compressed audio file
@details the compressed audio will be decode to wave, then write into an
internal buffer in SimpleaudioEngine
*/
virtual void preloadEffect(const char* pszFilePath) = 0;
/**
@brief unload the preloaded effect from internal buffer
@param[in] pszFilePath The path of the effect file,or the FileName of T_SoundResInfo
*/
virtual void unloadEffect(const char* pszFilePath) = 0;
/**
@brief pause an effect identified by sound id
@param[in] uSoundId sound id
*/
virtual void pauseEffect(unsigned int uSoundId) = 0;
/**
@brief pause all playing effects
*/
virtual void pauseAllEffects() = 0;
/**
@brief resume an effect identified by sound id
@param[in] uSoundId sound id
*/
virtual void resumeEffect(unsigned int uSoundId) = 0;
/**
@brief resume a effect identified by sound id
*/
virtual void resumeAllEffects() = 0;
/**
@brief stop all playing effects
*/
virtual void stopAllEffects() = 0;
};
}
#endif /* AUDIOPLAYER_H_ */

View File

@ -1,477 +0,0 @@
/****************************************************************************
Copyright (c) 2011 Laschweinski
Copyright (c) 2013-2014 Chukong Technologies Inc.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "FmodAudioPlayer.h"
#include <stdio.h>
#include "stdlib.h"
#include "assert.h"
#include "string.h"
#define szMusicSuffix "|"
namespace CocosDenshion {
FmodAudioPlayer* FmodAudioPlayer::sharedPlayer() {
static FmodAudioPlayer s_SharedPlayer;
return &s_SharedPlayer;
}
void ERRCHECKWITHEXIT(FMOD_RESULT result) {
if (result != FMOD_OK) {
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
// exit(-1);
}
}
bool ERRCHECK(FMOD_RESULT result) {
if (result != FMOD_OK) {
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
return true;
}
return false;
}
FmodAudioPlayer::FmodAudioPlayer() :
pMusic(0), pBGMChannel(0), iSoundChannelCount(0) {
init();
}
void FmodAudioPlayer::init() {
//init
FMOD_RESULT result;
FMOD::ChannelGroup *masterChannelGroup;
/*
Create a System object and initialize.
*/
result = FMOD::System_Create(&pSystem);
ERRCHECKWITHEXIT(result);
result = pSystem->setOutput(FMOD_OUTPUTTYPE_ALSA);
ERRCHECKWITHEXIT(result);
result = pSystem->init(32, FMOD_INIT_NORMAL, 0);
ERRCHECKWITHEXIT(result);
result = pSystem->createChannelGroup("Channel Group", &pChannelGroup);
ERRCHECKWITHEXIT(result);
result = pSystem->getMasterChannelGroup(&masterChannelGroup);
ERRCHECKWITHEXIT(result);
result = masterChannelGroup->addGroup(pChannelGroup);
ERRCHECKWITHEXIT(result);
mapEffectSound.clear();
}
void FmodAudioPlayer::close() {
FMOD_RESULT result;
//BGM
if (pBGMChannel != NULL) {
result = pBGMChannel->stop();
ERRCHECKWITHEXIT(result);
pBGMChannel = 0;
}
if (pMusic != NULL) {
result = pMusic->release();
ERRCHECKWITHEXIT(result);
pMusic = 0;
}
result = pChannelGroup->release();
ERRCHECKWITHEXIT(result);
sMusicPath.clear();
result = pSystem->close();
ERRCHECKWITHEXIT(result);
result = pSystem->release();
ERRCHECKWITHEXIT(result);
init();
}
FmodAudioPlayer::~FmodAudioPlayer() {
FMOD_RESULT result;
//BGM
if (pBGMChannel != NULL) {
result = pBGMChannel->stop();
ERRCHECKWITHEXIT(result);
}
if (pMusic != NULL) {
result = pMusic->release();
ERRCHECKWITHEXIT(result);
}
result = pChannelGroup->release();
ERRCHECKWITHEXIT(result);
result = pSystem->close();
ERRCHECKWITHEXIT(result);
result = pSystem->release();
ERRCHECKWITHEXIT(result);
}
// BGM
void FmodAudioPlayer::preloadBackgroundMusic(const char* pszFilePath) {
FMOD_RESULT result;
pSystem->update();
string sNewMusicPath = string(pszFilePath) + szMusicSuffix;
if (pMusic && sNewMusicPath != sMusicPath) {
//release old
result = pMusic->release();
ERRCHECKWITHEXIT(result);
sMusicPath = sNewMusicPath;
}
result = pSystem->createSound(pszFilePath, FMOD_LOOP_NORMAL, 0, &pMusic);
ERRCHECK(result);
}
void FmodAudioPlayer::playBackgroundMusic(const char* pszFilePath, bool bLoop) {
pSystem->update();
if (pMusic == NULL) {
//did not load it
//load the new music
FMOD_RESULT result = pSystem->createSound(pszFilePath, FMOD_LOOP_NORMAL,
0, &pMusic);
if (!ERRCHECK(result)) {
sMusicPath = string(pszFilePath) + szMusicSuffix;
}
} else {
string sNewMusicPath = string(pszFilePath) + szMusicSuffix;
if (pBGMChannel) {
pBGMChannel->stop();
pBGMChannel = 0;
}
if (sNewMusicPath != sMusicPath) {
pMusic->release();
//load the new music
FMOD_RESULT result = pSystem->createSound(pszFilePath,
FMOD_LOOP_NORMAL, 0, &pMusic);
if (!ERRCHECK(result)) {
sMusicPath = sNewMusicPath;
}
}
}
FMOD_RESULT result = pSystem->playSound(FMOD_CHANNEL_FREE, pMusic, true,
&pBGMChannel);
if (!ERRCHECK(result)) {
pBGMChannel->setLoopCount((bLoop) ? -1 : 0);
result = pBGMChannel->setPaused(false);
}
}
void FmodAudioPlayer::stopBackgroundMusic(bool bReleaseData) {
FMOD_RESULT result;
pSystem->update();
if (pBGMChannel == NULL || pMusic == NULL) {
return;
}
if (bReleaseData) {
result = pBGMChannel->stop();
ERRCHECKWITHEXIT(result);
result = pMusic->release();
ERRCHECKWITHEXIT(result);
pBGMChannel = 0;
pMusic = 0;
} else {
result = pBGMChannel->stop();
ERRCHECKWITHEXIT(result);
pBGMChannel = 0;
}
sMusicPath.clear();
}
void FmodAudioPlayer::pauseBackgroundMusic() {
if (pBGMChannel == NULL) {
return;
}
pSystem->update();
FMOD_RESULT result = pBGMChannel->setPaused(true);
ERRCHECKWITHEXIT(result);
}
void FmodAudioPlayer::resumeBackgroundMusic() {
if (pBGMChannel == NULL) {
return;
}
pSystem->update();
FMOD_RESULT result = pBGMChannel->setPaused(false);
ERRCHECKWITHEXIT(result);
}
void FmodAudioPlayer::rewindBackgroundMusic() {
if (pBGMChannel == NULL) {
return;
}
pSystem->update();
FMOD_RESULT result = pBGMChannel->setPosition(0, FMOD_TIMEUNIT_MS);
ERRCHECKWITHEXIT(result);
}
bool FmodAudioPlayer::willPlayBackgroundMusic() {
pSystem->update();
return false; //do it according to win
}
bool FmodAudioPlayer::isBackgroundMusicPlaying() {
bool bPlaying;
if (pBGMChannel == NULL) {
return false;
}
pSystem->update();
FMOD_RESULT result = pBGMChannel->isPlaying(&bPlaying);
ERRCHECKWITHEXIT(result);
return bPlaying;
}
float FmodAudioPlayer::getBackgroundMusicVolume() {
float fVolumn;
if (pBGMChannel == NULL) {
return 0;
}
pSystem->update();
FMOD_RESULT result = pBGMChannel->getVolume(&fVolumn);
ERRCHECKWITHEXIT(result);
return fVolumn;
}
void FmodAudioPlayer::setBackgroundMusicVolume(float volume) {
if (pBGMChannel == NULL) {
return;
}
pSystem->update();
FMOD_RESULT result = pBGMChannel->setVolume(volume);
ERRCHECKWITHEXIT(result);
}
//~BGM
// for sound effects
float FmodAudioPlayer::getEffectsVolume() {
float fVolumn;
pSystem->update();
FMOD_RESULT result = pChannelGroup->getVolume(&fVolumn);
ERRCHECKWITHEXIT(result);
return fVolumn;
}
void FmodAudioPlayer::setEffectsVolume(float volume) {
pSystem->update();
FMOD_RESULT result = pChannelGroup->setVolume(volume);
ERRCHECKWITHEXIT(result);
}
unsigned int FmodAudioPlayer::playEffect(const char* pszFilePath, bool bLoop,
float pitch, float pan, float gain) {
FMOD::Channel* pChannel;
FMOD::Sound* pSound = NULL;
do {
pSystem->update();
map<string, FMOD::Sound*>::iterator l_it = mapEffectSound.find(
string(pszFilePath));
if (l_it == mapEffectSound.end()) {
//no load it yet
preloadEffect(pszFilePath);
l_it = mapEffectSound.find(string(pszFilePath));
}
pSound = l_it->second;
if (pSound==NULL){
break;
}
FMOD_RESULT result = pSystem->playSound(FMOD_CHANNEL_FREE, pSound, true,
&pChannel);
if (ERRCHECK(result)) {
printf("sound effect in %s could not be played", pszFilePath);
break;
}
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);
result = pChannel->setPaused(false);
mapEffectSoundChannel[iSoundChannelCount] = pChannel;
return iSoundChannelCount++;
} while (0);
return 0;
}
void FmodAudioPlayer::stopEffect(unsigned int nSoundId) {
FMOD::Channel* pChannel;
pSystem->update();
map<unsigned int, FMOD::Channel*>::iterator l_it =
mapEffectSoundChannel.find(nSoundId);
if (l_it == mapEffectSoundChannel.end()) {
//no play yet
return;
}
pChannel = l_it->second;
//stop the channel;
pChannel->stop();
//delete from the map;
mapEffectSoundChannel.erase(nSoundId);
}
void FmodAudioPlayer::pauseEffect(unsigned int uSoundId) {
FMOD::Channel* pChannel;
pSystem->update();
map<unsigned int, FMOD::Channel*>::iterator l_it =
mapEffectSoundChannel.find(uSoundId);
if (l_it == mapEffectSoundChannel.end()) {
//no play yet
return;
}
pChannel = l_it->second;
//pause the channel;
pChannel->setPaused(true);
}
void FmodAudioPlayer::pauseAllEffects() {
FMOD::Channel* pChannel;
pSystem->update();
map<unsigned int, FMOD::Channel*>::iterator l_it =
mapEffectSoundChannel.begin();
for (; l_it != mapEffectSoundChannel.end(); l_it++) {
pChannel = l_it->second;
//pause the channel;
pChannel->setPaused(true);
}
}
void FmodAudioPlayer::resumeEffect(unsigned int uSoundId) {
FMOD::Channel* pChannel;
pSystem->update();
map<unsigned int, FMOD::Channel*>::iterator l_it =
mapEffectSoundChannel.find(uSoundId);
if (l_it == mapEffectSoundChannel.end()) {
//no play yet
return;
}
pChannel = l_it->second;
//resume the channel;
pChannel->setPaused(false);
}
void FmodAudioPlayer::resumeAllEffects() {
FMOD::Channel* pChannel;
pSystem->update();
map<unsigned int, FMOD::Channel*>::iterator l_it =
mapEffectSoundChannel.begin();
for (; l_it != mapEffectSoundChannel.end(); l_it++) {
pChannel = l_it->second;
//resume the channel;
pChannel->setPaused(false);
}
}
void FmodAudioPlayer::stopAllEffects() {
FMOD::Channel* pChannel;
pSystem->update();
map<unsigned int, FMOD::Channel*>::iterator l_it =
mapEffectSoundChannel.begin();
for (; l_it != mapEffectSoundChannel.end(); l_it++) {
pChannel = l_it->second;
//resume the channel;
pChannel->stop();
}
mapEffectSoundChannel.clear();
}
void FmodAudioPlayer::preloadEffect(const char* pszFilePath) {
FMOD::Sound* pLoadSound;
pSystem->update();
FMOD_RESULT result = pSystem->createSound(pszFilePath, FMOD_LOOP_NORMAL, 0,
&pLoadSound);
if (ERRCHECK(result)){
printf("sound effect in %s could not be preload", pszFilePath);
return;
}
mapEffectSound[string(pszFilePath)] = pLoadSound;
}
void FmodAudioPlayer::unloadEffect(const char* pszFilePath) {
FMOD::Sound* pSound;
pSystem->update();
map<string, FMOD::Sound*>::iterator l_it = mapEffectSound.find(
string(pszFilePath));
if (l_it == mapEffectSound.end()) {
//no load yet
return;
}
pSound = l_it->second;
//release the sound;
pSound->release();
//delete from the map
mapEffectSound.erase(string(pszFilePath));
}
//~for sound effects
} /* namespace CocosDenshion */

View File

@ -1,190 +0,0 @@
/****************************************************************************
Copyright (c) 2011 Laschweinski
Copyright (c) 2013-2014 Chukong Technologies Inc.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef FMODAUDIOPLAYER_H_
#define FMODAUDIOPLAYER_H_
#include "fmod.hpp"
#include "fmod_errors.h"
#include "AudioPlayer.h"
#include "string"
#include <map>
using namespace std;
namespace CocosDenshion {
class FmodAudioPlayer : public AudioPlayer{
public:
FmodAudioPlayer();
virtual ~FmodAudioPlayer();
static FmodAudioPlayer* sharedPlayer();
virtual void close();
/**
@brief Preload background music
@param pszFilePath The path of the background music file,or the FileName of T_SoundResInfo
*/
virtual void preloadBackgroundMusic(const char* pszFilePath);
/**
@brief Play background music
@param pszFilePath The path of the background music file,or the FileName of T_SoundResInfo
@param bLoop Whether the background music loop or not
*/
virtual void playBackgroundMusic(const char* pszFilePath, bool bLoop);
/**
@brief Stop playing background music
@param bReleaseData If release the background music data or not.As default value is false
*/
virtual void stopBackgroundMusic(bool bReleaseData);
/**
@brief Pause playing background music
*/
virtual void pauseBackgroundMusic();
/**
@brief Resume playing background music
*/
virtual void resumeBackgroundMusic();
/**
@brief Rewind playing background music
*/
virtual void rewindBackgroundMusic();
virtual bool willPlayBackgroundMusic();
/**
@brief Whether the background music is playing
@return If is playing return true,or return false
*/
virtual bool isBackgroundMusicPlaying();
// properties
/**
@brief The volume of the background music max value is 1.0,the min value is 0.0
*/
virtual float getBackgroundMusicVolume();
/**
@brief set the volume of background music
@param volume must be in 0.0~1.0
*/
virtual void setBackgroundMusicVolume(float volume);
/**
@brief The volume of the effects max value is 1.0,the min value is 0.0
*/
virtual float getEffectsVolume();
/**
@brief set the volume of sound effecs
@param volume must be in 0.0~1.0
*/
virtual void setEffectsVolume(float volume);
// for sound effects
/**
@brief Play sound effect
@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,
float pitch, float pan, float gain);
/**
@brief Stop playing sound effect
@param nSoundId The return value of function playEffect
*/
virtual void stopEffect(unsigned int nSoundId);
/**
@brief preload a compressed audio file
@details the compressed audio will be decode to wave, then write into an
internal buffer in SimpleaudioEngine
*/
virtual void preloadEffect(const char* pszFilePath);
/**
@brief unload the preloaded effect from internal buffer
@param[in] pszFilePath The path of the effect file,or the FileName of T_SoundResInfo
*/
virtual void unloadEffect(const char* pszFilePath);
/**
@brief pause an effect identified by sound id
@param[in] uSoundId sound id
*/
virtual void pauseEffect(unsigned int uSoundId);
/**
@brief pause all playing effects
*/
virtual void pauseAllEffects();
/**
@brief resume an effect identified by sound id
@param[in] uSoundId sound id
*/
virtual void resumeEffect(unsigned int uSoundId);
/**
@brief resume a effect identified by sound id
*/
virtual void resumeAllEffects();
/**
@brief stop all playing effects
*/
virtual void stopAllEffects();
private:
void init();
map<string, FMOD::Sound*> mapEffectSound;
map<unsigned int, FMOD::Channel*> mapEffectSoundChannel;
FMOD::System* pSystem;
FMOD::Sound* pMusic; //BGM
FMOD::Channel* pBGMChannel;
FMOD::ChannelGroup* pChannelGroup;
unsigned int iSoundChannelCount;
string sMusicPath;
};
} /* namespace CocosDenshion */
#endif /* FMODAUDIOPLAYER_H_ */

View File

@ -0,0 +1,211 @@
#include <iostream>
#include "../include/SimpleAudioEngine.h"
#include "../include/AudioEngine.h"
using namespace CocosDenshion;
using namespace cocos2d;
using namespace cocos2d::experimental;
struct SimpleAudioEngineLinux{
SimpleAudioEngine * engine = nullptr;
int musicid;
float effectsvolume;
std::string musicpath;
};
SimpleAudioEngineLinux * g_SimpleAudioEngineLinux = nullptr;
SimpleAudioEngine* SimpleAudioEngine::getInstance(){
if(!g_SimpleAudioEngineLinux){
g_SimpleAudioEngineLinux = new SimpleAudioEngineLinux();
g_SimpleAudioEngineLinux->engine = new SimpleAudioEngine();
}
return g_SimpleAudioEngineLinux->engine;
};
void SimpleAudioEngine::end(){
if(g_SimpleAudioEngineLinux){
delete g_SimpleAudioEngineLinux->engine;
delete g_SimpleAudioEngineLinux;
}
g_SimpleAudioEngineLinux = nullptr;
};
SimpleAudioEngine::SimpleAudioEngine(){
g_SimpleAudioEngineLinux->musicid = -1;
g_SimpleAudioEngineLinux->effectsvolume = 1.0f;
};
SimpleAudioEngine::~SimpleAudioEngine(){
};
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::stopBackgroundMusic(bool releaseData){
AudioEngine::stop(g_SimpleAudioEngineLinux->musicid);
if(releaseData){
AudioEngine::uncache(g_SimpleAudioEngineLinux->musicpath.c_str());
}
};
void SimpleAudioEngine::pauseBackgroundMusic(){
AudioEngine::pause(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::isBackgroundMusicPlaying(){
return AudioEngine::getState(g_SimpleAudioEngineLinux->musicid) == AudioEngine::AudioState::PLAYING;
};
//
// 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);
};
/**
* Set the volume of background music.
*
* @param volume must be within the range of 0.0 as the minimum and 1.0 as the maximum.
* @js setMusicVolume
* @lua setMusicVolume
*/
void SimpleAudioEngine::setBackgroundMusicVolume(float volume){
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;
};
/**
* Set the volume of sound effects.
*
* @param volume must be within the range of 0.0 as the minimum and 1.0 as the maximum.
*/
void SimpleAudioEngine::setEffectsVolume(float volume){
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);
};
/**
* Pause playing sound effect.
*
* @param soundId The return value of function playEffect.
*/
void SimpleAudioEngine::pauseEffect(unsigned int soundId){
AudioEngine::pause(soundId);
};
/**
* Pause all playing sound effect.
*/
void SimpleAudioEngine::pauseAllEffects(){
AudioEngine::pauseAll();
};
/**
* Resume playing sound effect.
*
* @param soundId The return value of function playEffect.
*/
void SimpleAudioEngine::resumeEffect(unsigned int soundId){
AudioEngine::resume(soundId);
};
/**
* Resume all playing sound effect.
*/
void SimpleAudioEngine::resumeAllEffects(){
AudioEngine::resumeAll();
};
/**
* Stop playing sound effect.
*
* @param soundId The return value of function playEffect.
*/
void SimpleAudioEngine::stopEffect(unsigned int soundId){
AudioEngine::stop(soundId);
};
/**
* Stop all playing sound effects.
*/
void SimpleAudioEngine::stopAllEffects(){
AudioEngine::stopAll();
};
/**
* Preload a compressed audio file.
*
* The compressed audio will be decoded to wave, then written into an internal buffer in SimpleAudioEngine.
*
* @param filePath The path of the effect file.
* @js NA
*/
void SimpleAudioEngine::preloadEffect(const char* filePath){
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);
};

View File

@ -1,168 +0,0 @@
/****************************************************************************
Copyright (c) 2011 Laschweinski
Copyright (c) 2013-2014 Chukong Technologies Inc.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef OPENAL
#include "audio/include/SimpleAudioEngine.h"
#include "FmodAudioPlayer.h"
#include "cocos2d.h"
USING_NS_CC;
namespace CocosDenshion {
static AudioPlayer* oAudioPlayer;
SimpleAudioEngine::SimpleAudioEngine() {
oAudioPlayer = FmodAudioPlayer::sharedPlayer();
}
SimpleAudioEngine::~SimpleAudioEngine() {
}
SimpleAudioEngine* SimpleAudioEngine::getInstance() {
static SimpleAudioEngine s_SharedEngine;
return &s_SharedEngine;
}
void SimpleAudioEngine::end() {
if(oAudioPlayer)
{
oAudioPlayer->close();
}
}
//////////////////////////////////////////////////////////////////////////
// BackgroundMusic
//////////////////////////////////////////////////////////////////////////
void SimpleAudioEngine::playBackgroundMusic(const char* pszFilePath,
bool bLoop) {
// Changing file path to full path
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(pszFilePath);
oAudioPlayer->playBackgroundMusic(fullPath.c_str(), bLoop);
}
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) {
// Changing file path to full path
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(pszFilePath);
return oAudioPlayer->preloadBackgroundMusic(fullPath.c_str());
}
//////////////////////////////////////////////////////////////////////////
// effect function
//////////////////////////////////////////////////////////////////////////
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::getInstance()->fullPathForFilename(pszFilePath);
return oAudioPlayer->playEffect(fullPath.c_str(), bLoop, pitch, pan, gain);
}
void SimpleAudioEngine::stopEffect(unsigned int nSoundId) {
return oAudioPlayer->stopEffect(nSoundId);
}
void SimpleAudioEngine::preloadEffect(const char* pszFilePath) {
// Changing file path to full path
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(pszFilePath);
return oAudioPlayer->preloadEffect(fullPath.c_str());
}
void SimpleAudioEngine::unloadEffect(const char* pszFilePath) {
// Changing file path to full path
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(pszFilePath);
return oAudioPlayer->unloadEffect(fullPath.c_str());
}
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() {
return oAudioPlayer->getEffectsVolume();
}
void SimpleAudioEngine::setEffectsVolume(float volume) {
return oAudioPlayer->setEffectsVolume(volume);
}
} // end of namespace CocosDenshion
#endif

View File

@ -1,5 +1,5 @@
{
"version":"v3-deps-75",
"version":"v3-deps-78",
"zip_file_size":"119277304",
"repo_name":"cocos2d-x-3rd-party-libs-bin",
"repo_parent":"https://github.com/cocos2d/",

View File

@ -23,8 +23,6 @@
****************************************************************************/
#include "platform/CCPlatformConfig.h"
#if CC_TARGET_PLATFORM == CC_PLATFORM_WINRT || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
#include "NewAudioEngineTest.h"
#include "ui/CocosGUI.h"
@ -635,4 +633,3 @@ std::string AudioIssue11143Test::subtitle() const
return "2 seconds after first sound play,you should hear another sound.";
}
#endif

View File

@ -23,7 +23,6 @@
****************************************************************************/
#include "platform/CCPlatformConfig.h"
#if CC_TARGET_PLATFORM == CC_PLATFORM_WINRT || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
#ifndef __NEWAUDIOENGINE_TEST_H_
#define __NEWAUDIOENGINE_TEST_H_
@ -165,4 +164,3 @@ public:
};
#endif /* defined(__NEWAUDIOENGINE_TEST_H_) */
#endif

View File

@ -26,9 +26,7 @@ public:
addTest("Actions - Progress", [](){return new (std::nothrow) ActionsProgressTests(); });
addTest("Allocator - Basic", [](){return new (std::nothrow) AllocatorTests(); });
addTest("Audio - CocosDenshion", []() { return new (std::nothrow) CocosDenshionTests(); });
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
addTest("Audio - NewAudioEngine", []() { return new (std::nothrow) AudioEngineTests(); });
#endif
#if CC_ENABLE_BOX2D_INTEGRATION
addTest("Box2d - Basic", []() { return new (std::nothrow) Box2DTests(); });
addTest("Box2d - TestBed", []() { return new (std::nothrow) Box2dTestBedSuite(); });

View File

@ -9,9 +9,7 @@
#include "ChipmunkTest/ChipmunkTest.h"
#include "ClippingNodeTest/ClippingNodeTest.h"
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
#include "NewAudioEngineTest/NewAudioEngineTest.h"
#endif
#if (CC_TARGET_PLATFORM != CC_PLATFORM_EMSCRIPEN)
#if (CC_TARGET_PLATFORM != CC_PLATFORM_MARMALADE)
// bada don't support libcurl