mirror of https://github.com/axmolengine/axmol.git
Merge pull request #8072 from Dhilan007/v3-audio903
move AudioEngine to cocos2d:experimental namespace
This commit is contained in:
commit
da29b92ff4
|
@ -36,6 +36,7 @@
|
||||||
#define TIME_DELAY_PRECISION 0.0001
|
#define TIME_DELAY_PRECISION 0.0001
|
||||||
|
|
||||||
using namespace cocos2d;
|
using namespace cocos2d;
|
||||||
|
using namespace cocos2d::experimental;
|
||||||
|
|
||||||
const int AudioEngine::INVAILD_AUDIO_ID = -1;
|
const int AudioEngine::INVAILD_AUDIO_ID = -1;
|
||||||
const float AudioEngine::TIME_UNKNOWN = -1.0f;
|
const float AudioEngine::TIME_UNKNOWN = -1.0f;
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
|
|
||||||
using namespace cocos2d;
|
using namespace cocos2d;
|
||||||
|
using namespace cocos2d::experimental;
|
||||||
|
|
||||||
void PlayOverEvent(SLPlayItf caller, void* context, SLuint32 playEvent)
|
void PlayOverEvent(SLPlayItf caller, void* context, SLuint32 playEvent)
|
||||||
{
|
{
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
#define ERRORLOG(msg) log("fun:%s,line:%d,msg:%s",__func__,__LINE__,#msg)
|
#define ERRORLOG(msg) log("fun:%s,line:%d,msg:%s",__func__,__LINE__,#msg)
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
namespace experimental{
|
||||||
class AudioEngineImpl;
|
class AudioEngineImpl;
|
||||||
|
|
||||||
class AudioPlayer
|
class AudioPlayer
|
||||||
|
@ -102,7 +102,7 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // __AUDIO_ENGINE_INL_H_
|
#endif // __AUDIO_ENGINE_INL_H_
|
||||||
|
}
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
#endif // ERROR
|
#endif // ERROR
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
namespace experimental{
|
||||||
|
|
||||||
class EXPORT_DLL AudioProfile
|
class EXPORT_DLL AudioProfile
|
||||||
{
|
{
|
||||||
|
@ -265,6 +266,7 @@ protected:
|
||||||
friend class AudioEngineImpl;
|
friend class AudioEngineImpl;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
||||||
#endif // __AUDIO_ENGINE_H_
|
#endif // __AUDIO_ENGINE_H_
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
#define QUEUEBUFFER_TIME_STEP 0.1
|
#define QUEUEBUFFER_TIME_STEP 0.1
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
namespace experimental{
|
||||||
|
|
||||||
class AudioEngineImpl;
|
class AudioEngineImpl;
|
||||||
class AudioPlayer;
|
class AudioPlayer;
|
||||||
|
@ -91,6 +92,7 @@ private:
|
||||||
friend class AudioPlayer;
|
friend class AudioPlayer;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
}
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
||||||
#endif // __AUDIO_CACHE_H_
|
#endif // __AUDIO_CACHE_H_
|
||||||
|
|
|
@ -44,6 +44,7 @@ static ALvoid alBufferDataStaticProc(const ALint bid, ALenum format, ALvoid* da
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
using namespace cocos2d;
|
using namespace cocos2d;
|
||||||
|
using namespace cocos2d::experimental;
|
||||||
|
|
||||||
AudioCache::AudioCache()
|
AudioCache::AudioCache()
|
||||||
: _pcmData(nullptr)
|
: _pcmData(nullptr)
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
#include "AudioPlayer.h"
|
#include "AudioPlayer.h"
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
namespace experimental{
|
||||||
#define MAX_AUDIOINSTANCES 32
|
#define MAX_AUDIOINSTANCES 32
|
||||||
|
|
||||||
class AudioEngineThreadPool;
|
class AudioEngineThreadPool;
|
||||||
|
@ -88,6 +88,7 @@ private:
|
||||||
int _currentAudioID;
|
int _currentAudioID;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
}
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
#endif // __AUDIO_ENGINE_INL_H_
|
#endif // __AUDIO_ENGINE_INL_H_
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
#include "base/ccUtils.h"
|
#include "base/ccUtils.h"
|
||||||
|
|
||||||
using namespace cocos2d;
|
using namespace cocos2d;
|
||||||
|
using namespace cocos2d::experimental;
|
||||||
|
|
||||||
static ALCdevice *s_ALDevice = nullptr;
|
static ALCdevice *s_ALDevice = nullptr;
|
||||||
static ALCcontext *s_ALContext = nullptr;
|
static ALCcontext *s_ALContext = nullptr;
|
||||||
|
@ -47,88 +48,90 @@ static void AudioInterrupionListenerCallback(void* user_data, UInt32 interruptio
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace cocos2d {
|
namespace cocos2d {
|
||||||
class AudioEngineThreadPool
|
namespace experimental {
|
||||||
{
|
class AudioEngineThreadPool
|
||||||
public:
|
|
||||||
AudioEngineThreadPool()
|
|
||||||
: _running(true)
|
|
||||||
, _numThread(6)
|
|
||||||
{
|
{
|
||||||
_threads.reserve(_numThread);
|
public:
|
||||||
_tasks.reserve(_numThread);
|
AudioEngineThreadPool()
|
||||||
|
: _running(true)
|
||||||
|
, _numThread(6)
|
||||||
|
{
|
||||||
|
_threads.reserve(_numThread);
|
||||||
|
_tasks.reserve(_numThread);
|
||||||
|
|
||||||
for (int index = 0; index < _numThread; ++index) {
|
for (int index = 0; index < _numThread; ++index) {
|
||||||
_tasks.push_back(nullptr);
|
_tasks.push_back(nullptr);
|
||||||
_threads.push_back( std::thread( std::bind(&AudioEngineThreadPool::threadFunc,this,index) ) );
|
_threads.push_back( std::thread( std::bind(&AudioEngineThreadPool::threadFunc,this,index) ) );
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void addTask(const std::function<void()> &task){
|
|
||||||
_taskMutex.lock();
|
|
||||||
int targetIndex = -1;
|
|
||||||
for (int index = 0; index < _numThread; ++index) {
|
|
||||||
if (_tasks[index] == nullptr) {
|
|
||||||
targetIndex = index;
|
|
||||||
_tasks[index] = task;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (targetIndex == -1) {
|
|
||||||
_tasks.push_back(task);
|
|
||||||
_threads.push_back( std::thread( std::bind(&AudioEngineThreadPool::threadFunc,this,_numThread) ) );
|
|
||||||
|
|
||||||
_numThread++;
|
void addTask(const std::function<void()> &task){
|
||||||
}
|
|
||||||
_taskMutex.unlock();
|
|
||||||
|
|
||||||
_sleepCondition.notify_all();
|
|
||||||
}
|
|
||||||
|
|
||||||
void destroy()
|
|
||||||
{
|
|
||||||
_running = false;
|
|
||||||
_sleepCondition.notify_all();
|
|
||||||
|
|
||||||
for (int index = 0; index < _numThread; ++index) {
|
|
||||||
_threads[index].join();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool _running;
|
|
||||||
std::vector<std::thread> _threads;
|
|
||||||
std::vector< std::function<void ()> > _tasks;
|
|
||||||
|
|
||||||
void threadFunc(int index)
|
|
||||||
{
|
|
||||||
while (_running) {
|
|
||||||
std::function<void ()> task = nullptr;
|
|
||||||
_taskMutex.lock();
|
_taskMutex.lock();
|
||||||
task = _tasks[index];
|
int targetIndex = -1;
|
||||||
_taskMutex.unlock();
|
for (int index = 0; index < _numThread; ++index) {
|
||||||
|
if (_tasks[index] == nullptr) {
|
||||||
if (nullptr == task)
|
targetIndex = index;
|
||||||
{
|
_tasks[index] = task;
|
||||||
std::unique_lock<std::mutex> lk(_sleepMutex);
|
break;
|
||||||
_sleepCondition.wait(lk);
|
}
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
if (targetIndex == -1) {
|
||||||
|
_tasks.push_back(task);
|
||||||
|
_threads.push_back( std::thread( std::bind(&AudioEngineThreadPool::threadFunc,this,_numThread) ) );
|
||||||
|
|
||||||
task();
|
_numThread++;
|
||||||
|
}
|
||||||
_taskMutex.lock();
|
|
||||||
_tasks[index] = nullptr;
|
|
||||||
_taskMutex.unlock();
|
_taskMutex.unlock();
|
||||||
|
|
||||||
|
_sleepCondition.notify_all();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
int _numThread;
|
void destroy()
|
||||||
|
{
|
||||||
|
_running = false;
|
||||||
|
_sleepCondition.notify_all();
|
||||||
|
|
||||||
std::mutex _taskMutex;
|
for (int index = 0; index < _numThread; ++index) {
|
||||||
std::mutex _sleepMutex;
|
_threads[index].join();
|
||||||
std::condition_variable _sleepCondition;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
};
|
private:
|
||||||
|
bool _running;
|
||||||
|
std::vector<std::thread> _threads;
|
||||||
|
std::vector< std::function<void ()> > _tasks;
|
||||||
|
|
||||||
|
void threadFunc(int index)
|
||||||
|
{
|
||||||
|
while (_running) {
|
||||||
|
std::function<void ()> task = nullptr;
|
||||||
|
_taskMutex.lock();
|
||||||
|
task = _tasks[index];
|
||||||
|
_taskMutex.unlock();
|
||||||
|
|
||||||
|
if (nullptr == task)
|
||||||
|
{
|
||||||
|
std::unique_lock<std::mutex> lk(_sleepMutex);
|
||||||
|
_sleepCondition.wait(lk);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
task();
|
||||||
|
|
||||||
|
_taskMutex.lock();
|
||||||
|
_tasks[index] = nullptr;
|
||||||
|
_taskMutex.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int _numThread;
|
||||||
|
|
||||||
|
std::mutex _taskMutex;
|
||||||
|
std::mutex _sleepMutex;
|
||||||
|
std::condition_variable _sleepCondition;
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioEngineImpl::AudioEngineImpl()
|
AudioEngineImpl::AudioEngineImpl()
|
||||||
|
|
|
@ -32,6 +32,8 @@
|
||||||
#include "CCPlatformMacros.h"
|
#include "CCPlatformMacros.h"
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
namespace experimental{
|
||||||
|
|
||||||
class AudioCache;
|
class AudioCache;
|
||||||
class AudioEngineImpl;
|
class AudioEngineImpl;
|
||||||
|
|
||||||
|
@ -70,6 +72,8 @@ private:
|
||||||
|
|
||||||
friend class AudioEngineImpl;
|
friend class AudioEngineImpl;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
#endif // __AUDIO_PLAYER_H_
|
#endif // __AUDIO_PLAYER_H_
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#import <AudioToolbox/ExtendedAudioFile.h>
|
#import <AudioToolbox/ExtendedAudioFile.h>
|
||||||
|
|
||||||
using namespace cocos2d;
|
using namespace cocos2d;
|
||||||
|
using namespace cocos2d::experimental;
|
||||||
|
|
||||||
AudioPlayer::AudioPlayer()
|
AudioPlayer::AudioPlayer()
|
||||||
: _exitThread(false)
|
: _exitThread(false)
|
||||||
|
|
|
@ -31,14 +31,14 @@
|
||||||
|
|
||||||
static int lua_get_AudioProfile_name(lua_State* L)
|
static int lua_get_AudioProfile_name(lua_State* L)
|
||||||
{
|
{
|
||||||
cocos2d::AudioProfile* self = nullptr;
|
cocos2d::experimental::AudioProfile* self = nullptr;
|
||||||
|
|
||||||
#if COCOS2D_DEBUG >= 1
|
#if COCOS2D_DEBUG >= 1
|
||||||
tolua_Error tolua_err;
|
tolua_Error tolua_err;
|
||||||
if (!tolua_isusertype(L,1,"cc.AudioProfile",0,&tolua_err)) goto tolua_lerror;
|
if (!tolua_isusertype(L,1,"ccexp.AudioProfile",0,&tolua_err)) goto tolua_lerror;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
self = (cocos2d::AudioProfile*) tolua_tousertype(L,1,0);
|
self = (cocos2d::experimental::AudioProfile*) tolua_tousertype(L,1,0);
|
||||||
#if COCOS2D_DEBUG >= 1
|
#if COCOS2D_DEBUG >= 1
|
||||||
if (nullptr == self)
|
if (nullptr == self)
|
||||||
{
|
{
|
||||||
|
@ -60,14 +60,14 @@ tolua_lerror:
|
||||||
static int lua_set_AudioProfile_name(lua_State* L)
|
static int lua_set_AudioProfile_name(lua_State* L)
|
||||||
{
|
{
|
||||||
int argc = 0;
|
int argc = 0;
|
||||||
cocos2d::AudioProfile* self = nullptr;
|
cocos2d::experimental::AudioProfile* self = nullptr;
|
||||||
|
|
||||||
#if COCOS2D_DEBUG >= 1
|
#if COCOS2D_DEBUG >= 1
|
||||||
tolua_Error tolua_err;
|
tolua_Error tolua_err;
|
||||||
if (!tolua_isusertype(L,1,"cc.AudioProfile",0,&tolua_err)) goto tolua_lerror;
|
if (!tolua_isusertype(L,1,"ccexp.AudioProfile",0,&tolua_err)) goto tolua_lerror;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
self = (cocos2d::AudioProfile*) tolua_tousertype(L,1,0);
|
self = (cocos2d::experimental::AudioProfile*) tolua_tousertype(L,1,0);
|
||||||
#if COCOS2D_DEBUG >= 1
|
#if COCOS2D_DEBUG >= 1
|
||||||
if (nullptr == self)
|
if (nullptr == self)
|
||||||
{
|
{
|
||||||
|
@ -99,14 +99,14 @@ tolua_lerror:
|
||||||
|
|
||||||
static int lua_get_AudioProfile_maxInstances(lua_State* L)
|
static int lua_get_AudioProfile_maxInstances(lua_State* L)
|
||||||
{
|
{
|
||||||
cocos2d::AudioProfile* self = nullptr;
|
cocos2d::experimental::AudioProfile* self = nullptr;
|
||||||
|
|
||||||
#if COCOS2D_DEBUG >= 1
|
#if COCOS2D_DEBUG >= 1
|
||||||
tolua_Error tolua_err;
|
tolua_Error tolua_err;
|
||||||
if (!tolua_isusertype(L,1,"cc.AudioProfile",0,&tolua_err)) goto tolua_lerror;
|
if (!tolua_isusertype(L,1,"ccexp.AudioProfile",0,&tolua_err)) goto tolua_lerror;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
self = (cocos2d::AudioProfile*) tolua_tousertype(L,1,0);
|
self = (cocos2d::experimental::AudioProfile*) tolua_tousertype(L,1,0);
|
||||||
#if COCOS2D_DEBUG >= 1
|
#if COCOS2D_DEBUG >= 1
|
||||||
if (nullptr == self)
|
if (nullptr == self)
|
||||||
{
|
{
|
||||||
|
@ -128,14 +128,14 @@ tolua_lerror:
|
||||||
static int lua_set_AudioProfile_maxInstances(lua_State* L)
|
static int lua_set_AudioProfile_maxInstances(lua_State* L)
|
||||||
{
|
{
|
||||||
int argc = 0;
|
int argc = 0;
|
||||||
cocos2d::AudioProfile* self = nullptr;
|
cocos2d::experimental::AudioProfile* self = nullptr;
|
||||||
|
|
||||||
#if COCOS2D_DEBUG >= 1
|
#if COCOS2D_DEBUG >= 1
|
||||||
tolua_Error tolua_err;
|
tolua_Error tolua_err;
|
||||||
if (!tolua_isusertype(L,1,"cc.AudioProfile",0,&tolua_err)) goto tolua_lerror;
|
if (!tolua_isusertype(L,1,"ccexp.AudioProfile",0,&tolua_err)) goto tolua_lerror;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
self = (cocos2d::AudioProfile*) tolua_tousertype(L,1,0);
|
self = (cocos2d::experimental::AudioProfile*) tolua_tousertype(L,1,0);
|
||||||
#if COCOS2D_DEBUG >= 1
|
#if COCOS2D_DEBUG >= 1
|
||||||
if (nullptr == self)
|
if (nullptr == self)
|
||||||
{
|
{
|
||||||
|
@ -167,14 +167,14 @@ tolua_lerror:
|
||||||
|
|
||||||
static int lua_get_AudioProfile_minDelay(lua_State* L)
|
static int lua_get_AudioProfile_minDelay(lua_State* L)
|
||||||
{
|
{
|
||||||
cocos2d::AudioProfile* self = nullptr;
|
cocos2d::experimental::AudioProfile* self = nullptr;
|
||||||
|
|
||||||
#if COCOS2D_DEBUG >= 1
|
#if COCOS2D_DEBUG >= 1
|
||||||
tolua_Error tolua_err;
|
tolua_Error tolua_err;
|
||||||
if (!tolua_isusertype(L,1,"cc.AudioProfile",0,&tolua_err)) goto tolua_lerror;
|
if (!tolua_isusertype(L,1,"ccexp.AudioProfile",0,&tolua_err)) goto tolua_lerror;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
self = (cocos2d::AudioProfile*) tolua_tousertype(L,1,0);
|
self = (cocos2d::experimental::AudioProfile*) tolua_tousertype(L,1,0);
|
||||||
#if COCOS2D_DEBUG >= 1
|
#if COCOS2D_DEBUG >= 1
|
||||||
if (nullptr == self)
|
if (nullptr == self)
|
||||||
{
|
{
|
||||||
|
@ -196,14 +196,14 @@ tolua_lerror:
|
||||||
static int lua_set_AudioProfile_minDelay(lua_State* L)
|
static int lua_set_AudioProfile_minDelay(lua_State* L)
|
||||||
{
|
{
|
||||||
int argc = 0;
|
int argc = 0;
|
||||||
cocos2d::AudioProfile* self = nullptr;
|
cocos2d::experimental::AudioProfile* self = nullptr;
|
||||||
|
|
||||||
#if COCOS2D_DEBUG >= 1
|
#if COCOS2D_DEBUG >= 1
|
||||||
tolua_Error tolua_err;
|
tolua_Error tolua_err;
|
||||||
if (!tolua_isusertype(L,1,"cc.AudioProfile",0,&tolua_err)) goto tolua_lerror;
|
if (!tolua_isusertype(L,1,"ccexp.AudioProfile",0,&tolua_err)) goto tolua_lerror;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
self = (cocos2d::AudioProfile*) tolua_tousertype(L,1,0);
|
self = (cocos2d::experimental::AudioProfile*) tolua_tousertype(L,1,0);
|
||||||
#if COCOS2D_DEBUG >= 1
|
#if COCOS2D_DEBUG >= 1
|
||||||
if (nullptr == self)
|
if (nullptr == self)
|
||||||
{
|
{
|
||||||
|
@ -243,7 +243,7 @@ int lua_cocos2dx_audioengine_AudioEngine_setFinishCallback(lua_State* tolua_S)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if COCOS2D_DEBUG >= 1
|
#if COCOS2D_DEBUG >= 1
|
||||||
if (!tolua_isusertable(tolua_S,1,"cc.AudioEngine",0,&tolua_err)) goto tolua_lerror;
|
if (!tolua_isusertable(tolua_S,1,"ccexp.AudioEngine",0,&tolua_err)) goto tolua_lerror;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
argc = lua_gettop(tolua_S) - 1;
|
argc = lua_gettop(tolua_S) - 1;
|
||||||
|
@ -251,7 +251,7 @@ int lua_cocos2dx_audioengine_AudioEngine_setFinishCallback(lua_State* tolua_S)
|
||||||
if (argc == 2)
|
if (argc == 2)
|
||||||
{
|
{
|
||||||
int arg0;
|
int arg0;
|
||||||
ok &= luaval_to_int32(tolua_S, 2,(int *)&arg0, "cc.AudioEngine:setFinishCallback");
|
ok &= luaval_to_int32(tolua_S, 2,(int *)&arg0, "ccexp.AudioEngine:setFinishCallback");
|
||||||
|
|
||||||
#if COCOS2D_DEBUG >= 1
|
#if COCOS2D_DEBUG >= 1
|
||||||
if (!toluafix_isfunction(tolua_S,3,"LUA_FUNCTION",0,&tolua_err))
|
if (!toluafix_isfunction(tolua_S,3,"LUA_FUNCTION",0,&tolua_err))
|
||||||
|
@ -262,7 +262,7 @@ int lua_cocos2dx_audioengine_AudioEngine_setFinishCallback(lua_State* tolua_S)
|
||||||
|
|
||||||
LUA_FUNCTION handler = ( toluafix_ref_function(tolua_S,3,0));
|
LUA_FUNCTION handler = ( toluafix_ref_function(tolua_S,3,0));
|
||||||
|
|
||||||
cocos2d::AudioEngine::setFinishCallback(arg0, [handler](int audioID, std::string filePath){
|
cocos2d::experimental::AudioEngine::setFinishCallback(arg0, [handler](int audioID, std::string filePath){
|
||||||
LuaStack* stack = LuaEngine::getInstance()->getLuaStack();
|
LuaStack* stack = LuaEngine::getInstance()->getLuaStack();
|
||||||
|
|
||||||
stack->pushInt(audioID);
|
stack->pushInt(audioID);
|
||||||
|
@ -275,7 +275,7 @@ int lua_cocos2dx_audioengine_AudioEngine_setFinishCallback(lua_State* tolua_S)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
CCLOG("%s has wrong number of arguments: %d, was expecting %d\n ", "cc.AudioEngine:setFinishCallback",argc, 2);
|
CCLOG("%s has wrong number of arguments: %d, was expecting %d\n ", "ccexp.AudioEngine:setFinishCallback",argc, 2);
|
||||||
return 0;
|
return 0;
|
||||||
#if COCOS2D_DEBUG >= 1
|
#if COCOS2D_DEBUG >= 1
|
||||||
tolua_lerror:
|
tolua_lerror:
|
||||||
|
@ -292,7 +292,7 @@ int register_audioengine_module(lua_State* L)
|
||||||
register_all_cocos2dx_audioengine(L);
|
register_all_cocos2dx_audioengine(L);
|
||||||
if (L)
|
if (L)
|
||||||
{
|
{
|
||||||
lua_pushstring(L, "cc.AudioProfile");
|
lua_pushstring(L, "ccexp.AudioProfile");
|
||||||
lua_rawget(L, LUA_REGISTRYINDEX);
|
lua_rawget(L, LUA_REGISTRYINDEX);
|
||||||
if (lua_istable(L,-1))
|
if (lua_istable(L,-1))
|
||||||
{
|
{
|
||||||
|
@ -302,7 +302,7 @@ int register_audioengine_module(lua_State* L)
|
||||||
}
|
}
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
|
||||||
lua_pushstring(L, "cc.AudioEngine");
|
lua_pushstring(L, "ccexp.AudioEngine");
|
||||||
lua_rawget(L, LUA_REGISTRYINDEX);
|
lua_rawget(L, LUA_REGISTRYINDEX);
|
||||||
if (lua_istable(L,-1))
|
if (lua_istable(L,-1))
|
||||||
{
|
{
|
||||||
|
|
|
@ -25,7 +25,9 @@
|
||||||
#include "NewAudioEngineTest.h"
|
#include "NewAudioEngineTest.h"
|
||||||
#include "ui/CocosGUI.h"
|
#include "ui/CocosGUI.h"
|
||||||
|
|
||||||
|
using namespace cocos2d;
|
||||||
using namespace cocos2d::ui;
|
using namespace cocos2d::ui;
|
||||||
|
using namespace cocos2d::experimental;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
@ -166,7 +168,7 @@ Layer* restartAction()
|
||||||
bool _enabled;
|
bool _enabled;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SliderEx : public ui::Slider
|
class SliderEx : public Slider
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum class TouchEvent
|
enum class TouchEvent
|
||||||
|
|
|
@ -111,7 +111,7 @@ public:
|
||||||
private:
|
private:
|
||||||
static const int FILE_COUNT = 4;
|
static const int FILE_COUNT = 4;
|
||||||
std::string _files[FILE_COUNT];
|
std::string _files[FILE_COUNT];
|
||||||
AudioProfile _audioProfile;
|
cocos2d::experimental::AudioProfile _audioProfile;
|
||||||
|
|
||||||
int _audioCount;
|
int _audioCount;
|
||||||
Label* _showLabel;
|
Label* _showLabel;
|
||||||
|
|
|
@ -123,7 +123,7 @@ function AudioControlTest.create()
|
||||||
------playItem
|
------playItem
|
||||||
local function playAudio(tag, sender)
|
local function playAudio(tag, sender)
|
||||||
if AudioControlTest._audioID == cc.AUDIO_INVAILD_ID then
|
if AudioControlTest._audioID == cc.AUDIO_INVAILD_ID then
|
||||||
AudioControlTest._audioID = cc.AudioEngine:play2d("background.mp3", AudioControlTest._loopEnabled, AudioControlTest._volume)
|
AudioControlTest._audioID = ccexp.AudioEngine:play2d("background.mp3", AudioControlTest._loopEnabled, AudioControlTest._volume)
|
||||||
|
|
||||||
if AudioControlTest._audioID ~= cc.AUDIO_INVAILD_ID then
|
if AudioControlTest._audioID ~= cc.AUDIO_INVAILD_ID then
|
||||||
AudioControlTest._playItem:setEnabled(false)
|
AudioControlTest._playItem:setEnabled(false)
|
||||||
|
@ -133,7 +133,7 @@ function AudioControlTest.create()
|
||||||
AudioControlTest._playItem:setEnabled(true)
|
AudioControlTest._playItem:setEnabled(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
cc.AudioEngine:setFinishCallback(AudioControlTest._audioID,finishCallback)
|
ccexp.AudioEngine:setFinishCallback(AudioControlTest._audioID,finishCallback)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -145,7 +145,7 @@ function AudioControlTest.create()
|
||||||
------stopItem
|
------stopItem
|
||||||
local function stopAudio(tag, sender)
|
local function stopAudio(tag, sender)
|
||||||
if AudioControlTest._audioID ~= cc.AUDIO_INVAILD_ID then
|
if AudioControlTest._audioID ~= cc.AUDIO_INVAILD_ID then
|
||||||
cc.AudioEngine:stop(AudioControlTest._audioID)
|
ccexp.AudioEngine:stop(AudioControlTest._audioID)
|
||||||
AudioControlTest._audioID = cc.AUDIO_INVAILD_ID
|
AudioControlTest._audioID = cc.AUDIO_INVAILD_ID
|
||||||
AudioControlTest._playItem:setEnabled(true)
|
AudioControlTest._playItem:setEnabled(true)
|
||||||
end
|
end
|
||||||
|
@ -158,7 +158,7 @@ function AudioControlTest.create()
|
||||||
------pauseItem
|
------pauseItem
|
||||||
local function pauseAudio(tag, sender)
|
local function pauseAudio(tag, sender)
|
||||||
if AudioControlTest._audioID ~= cc.AUDIO_INVAILD_ID then
|
if AudioControlTest._audioID ~= cc.AUDIO_INVAILD_ID then
|
||||||
cc.AudioEngine:pause(AudioControlTest._audioID)
|
ccexp.AudioEngine:pause(AudioControlTest._audioID)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -169,7 +169,7 @@ function AudioControlTest.create()
|
||||||
------resumeItem
|
------resumeItem
|
||||||
local function resumeAudio(tag, sender)
|
local function resumeAudio(tag, sender)
|
||||||
if AudioControlTest._audioID ~= cc.AUDIO_INVAILD_ID then
|
if AudioControlTest._audioID ~= cc.AUDIO_INVAILD_ID then
|
||||||
cc.AudioEngine:resume(AudioControlTest._audioID)
|
ccexp.AudioEngine:resume(AudioControlTest._audioID)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -181,7 +181,7 @@ function AudioControlTest.create()
|
||||||
local function switchLoop(tag, sender)
|
local function switchLoop(tag, sender)
|
||||||
AudioControlTest._loopEnabled = not AudioControlTest._loopEnabled
|
AudioControlTest._loopEnabled = not AudioControlTest._loopEnabled
|
||||||
if AudioControlTest._audioID ~= cc.AUDIO_INVAILD_ID then
|
if AudioControlTest._audioID ~= cc.AUDIO_INVAILD_ID then
|
||||||
cc.AudioEngine:setLoop(AudioControlTest._audioID, AudioControlTest._loopEnabled)
|
ccexp.AudioEngine:setLoop(AudioControlTest._audioID, AudioControlTest._loopEnabled)
|
||||||
end
|
end
|
||||||
if AudioControlTest._loopEnabled then
|
if AudioControlTest._loopEnabled then
|
||||||
AudioControlTest.loopItem:setString("disable-loop")
|
AudioControlTest.loopItem:setString("disable-loop")
|
||||||
|
@ -196,7 +196,7 @@ function AudioControlTest.create()
|
||||||
|
|
||||||
------uncacheItem
|
------uncacheItem
|
||||||
local function uncache(tag, sender)
|
local function uncache(tag, sender)
|
||||||
cc.AudioEngine:uncache("background.mp3")
|
ccexp.AudioEngine:uncache("background.mp3")
|
||||||
AudioControlTest._audioID = cc.AUDIO_INVAILD_ID
|
AudioControlTest._audioID = cc.AUDIO_INVAILD_ID
|
||||||
AudioControlTest._playItem:setEnabled(true)
|
AudioControlTest._playItem:setEnabled(true)
|
||||||
end
|
end
|
||||||
|
@ -218,7 +218,7 @@ function AudioControlTest.create()
|
||||||
local function volumeSliderChangedEvent(sender,eventType)
|
local function volumeSliderChangedEvent(sender,eventType)
|
||||||
AudioControlTest._volume = sender:getPercent() / 100.0
|
AudioControlTest._volume = sender:getPercent() / 100.0
|
||||||
if AudioControlTest._audioID ~= cc.AUDIO_INVAILD_ID then
|
if AudioControlTest._audioID ~= cc.AUDIO_INVAILD_ID then
|
||||||
cc.AudioEngine:setVolume(AudioControlTest._audioID, AudioControlTest._volume)
|
ccexp.AudioEngine:setVolume(AudioControlTest._audioID, AudioControlTest._volume)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local volumeSlider = ccui.Slider:create()
|
local volumeSlider = ccui.Slider:create()
|
||||||
|
@ -247,7 +247,7 @@ function AudioControlTest.create()
|
||||||
AudioControlTest._updateTimeSlider = false
|
AudioControlTest._updateTimeSlider = false
|
||||||
else
|
else
|
||||||
if (AudioControlTest._audioID ~= cc.AUDIO_INVAILD_ID and AudioControlTest._duration ~= cc.AUDIO_TIME_UNKNOWN) then
|
if (AudioControlTest._audioID ~= cc.AUDIO_INVAILD_ID and AudioControlTest._duration ~= cc.AUDIO_TIME_UNKNOWN) then
|
||||||
cc.AudioEngine:setCurrentTime(AudioControlTest._audioID,AudioControlTest._duration * ratio)
|
ccexp.AudioEngine:setCurrentTime(AudioControlTest._audioID,AudioControlTest._duration * ratio)
|
||||||
end
|
end
|
||||||
AudioControlTest._updateTimeSlider = true
|
AudioControlTest._updateTimeSlider = true
|
||||||
end
|
end
|
||||||
|
@ -261,10 +261,10 @@ function AudioControlTest.create()
|
||||||
local function step(dt)
|
local function step(dt)
|
||||||
if AudioControlTest._audioID ~= cc.AUDIO_INVAILD_ID then
|
if AudioControlTest._audioID ~= cc.AUDIO_INVAILD_ID then
|
||||||
if AudioControlTest._duration == cc.AUDIO_TIME_UNKNOWN then
|
if AudioControlTest._duration == cc.AUDIO_TIME_UNKNOWN then
|
||||||
AudioControlTest._duration = cc.AudioEngine:getDuration(AudioControlTest._audioID)
|
AudioControlTest._duration = ccexp.AudioEngine:getDuration(AudioControlTest._audioID)
|
||||||
end
|
end
|
||||||
if AudioControlTest._duration ~= cc.AUDIO_TIME_UNKNOWN then
|
if AudioControlTest._duration ~= cc.AUDIO_TIME_UNKNOWN then
|
||||||
local time = cc.AudioEngine:getCurrentTime(AudioControlTest._audioID)
|
local time = ccexp.AudioEngine:getCurrentTime(AudioControlTest._audioID)
|
||||||
AudioControlTest._timeRatio = time / AudioControlTest._duration
|
AudioControlTest._timeRatio = time / AudioControlTest._duration
|
||||||
if AudioControlTest._updateTimeSlider then
|
if AudioControlTest._updateTimeSlider then
|
||||||
AudioControlTest._timeSlider:setRatio(AudioControlTest._timeRatio)
|
AudioControlTest._timeSlider:setRatio(AudioControlTest._timeRatio)
|
||||||
|
@ -277,7 +277,7 @@ function AudioControlTest.create()
|
||||||
|
|
||||||
function onNodeEvent(tag)
|
function onNodeEvent(tag)
|
||||||
if tag == "exit" then
|
if tag == "exit" then
|
||||||
cc.AudioEngine:stopAll()
|
ccexp.AudioEngine:stopAll()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
layer:registerScriptHandler(onNodeEvent)
|
layer:registerScriptHandler(onNodeEvent)
|
||||||
|
@ -302,7 +302,7 @@ function PlaySimultaneouslyTest.create()
|
||||||
local audioID = cc.AUDIO_INVAILD_ID
|
local audioID = cc.AUDIO_INVAILD_ID
|
||||||
--for k, v in pairs(PlaySimultaneouslyTest.files) do
|
--for k, v in pairs(PlaySimultaneouslyTest.files) do
|
||||||
for index=1,10 do
|
for index=1,10 do
|
||||||
audioID = cc.AudioEngine:play2d(PlaySimultaneouslyTest.files[index])
|
audioID = ccexp.AudioEngine:play2d(PlaySimultaneouslyTest.files[index])
|
||||||
|
|
||||||
if audioID ~= cc.AUDIO_INVAILD_ID then
|
if audioID ~= cc.AUDIO_INVAILD_ID then
|
||||||
PlaySimultaneouslyTest._playItem:setEnabled(false)
|
PlaySimultaneouslyTest._playItem:setEnabled(false)
|
||||||
|
@ -315,7 +315,7 @@ function PlaySimultaneouslyTest.create()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
cc.AudioEngine:setFinishCallback(audioID,finishCallback)
|
ccexp.AudioEngine:setFinishCallback(audioID,finishCallback)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -330,7 +330,7 @@ function PlaySimultaneouslyTest.create()
|
||||||
|
|
||||||
function onNodeEvent(tag)
|
function onNodeEvent(tag)
|
||||||
if tag == "exit" then
|
if tag == "exit" then
|
||||||
cc.AudioEngine:stopAll()
|
ccexp.AudioEngine:stopAll()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
layer:registerScriptHandler(onNodeEvent)
|
layer:registerScriptHandler(onNodeEvent)
|
||||||
|
@ -358,7 +358,7 @@ function AudioProfileTest.create()
|
||||||
AudioProfileTest._files[3] = "background.wav"
|
AudioProfileTest._files[3] = "background.wav"
|
||||||
AudioProfileTest._files[4] = "pew-pew-lei.wav"
|
AudioProfileTest._files[4] = "pew-pew-lei.wav"
|
||||||
|
|
||||||
AudioProfileTest._profile = cc.AudioProfile:new()
|
AudioProfileTest._profile = ccexp.AudioProfile:new()
|
||||||
AudioProfileTest._profile.name = "AudioProfileTest"
|
AudioProfileTest._profile.name = "AudioProfileTest"
|
||||||
AudioProfileTest._profile.maxInstances = 3
|
AudioProfileTest._profile.maxInstances = 3
|
||||||
AudioProfileTest._profile.minDelay = 1.0
|
AudioProfileTest._profile.minDelay = 1.0
|
||||||
|
@ -374,7 +374,7 @@ function AudioProfileTest.create()
|
||||||
local heightRatio = 0.7
|
local heightRatio = 0.7
|
||||||
for index=1,4 do
|
for index=1,4 do
|
||||||
local function itemClickCallback(tag, sender)
|
local function itemClickCallback(tag, sender)
|
||||||
local audioID = cc.AudioEngine:play2d(AudioProfileTest._files[tag],false,1.0,AudioProfileTest._profile)
|
local audioID = ccexp.AudioEngine:play2d(AudioProfileTest._files[tag],false,1.0,AudioProfileTest._profile)
|
||||||
if audioID ~= cc.AUDIO_INVAILD_ID then
|
if audioID ~= cc.AUDIO_INVAILD_ID then
|
||||||
AudioProfileTest._time = AudioProfileTest._minDelay
|
AudioProfileTest._time = AudioProfileTest._minDelay
|
||||||
AudioProfileTest._audioCount = AudioProfileTest._audioCount + 1
|
AudioProfileTest._audioCount = AudioProfileTest._audioCount + 1
|
||||||
|
@ -385,7 +385,7 @@ function AudioProfileTest.create()
|
||||||
AudioProfileTest._showLabel:setString(string.format("audio count:%d",AudioProfileTest._audioCount))
|
AudioProfileTest._showLabel:setString(string.format("audio count:%d",AudioProfileTest._audioCount))
|
||||||
end
|
end
|
||||||
|
|
||||||
cc.AudioEngine:setFinishCallback(audioID,finishCallback)
|
ccexp.AudioEngine:setFinishCallback(audioID,finishCallback)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -431,7 +431,7 @@ function AudioProfileTest.create()
|
||||||
|
|
||||||
function onNodeEvent(tag)
|
function onNodeEvent(tag)
|
||||||
if tag == "exit" then
|
if tag == "exit" then
|
||||||
cc.AudioEngine:stopAll()
|
ccexp.AudioEngine:stopAll()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
layer:registerScriptHandler(onNodeEvent)
|
layer:registerScriptHandler(onNodeEvent)
|
||||||
|
@ -452,10 +452,10 @@ function InvalidAudioFileTest.create()
|
||||||
local function playUnsupportedAudio(tag, sender)
|
local function playUnsupportedAudio(tag, sender)
|
||||||
local targetPlatform = cc.Application:getInstance():getTargetPlatform()
|
local targetPlatform = cc.Application:getInstance():getTargetPlatform()
|
||||||
if (cc.PLATFORM_OS_IPHONE == targetPlatform or cc.PLATFORM_OS_IPAD == targetPlatform) then
|
if (cc.PLATFORM_OS_IPHONE == targetPlatform or cc.PLATFORM_OS_IPAD == targetPlatform) then
|
||||||
cc.AudioEngine:play2d("background.ogg")
|
ccexp.AudioEngine:play2d("background.ogg")
|
||||||
end
|
end
|
||||||
if (cc.PLATFORM_OS_ANDROID == targetPlatform) then
|
if (cc.PLATFORM_OS_ANDROID == targetPlatform) then
|
||||||
cc.AudioEngine:play2d("background.caf")
|
ccexp.AudioEngine:play2d("background.caf")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -465,7 +465,7 @@ function InvalidAudioFileTest.create()
|
||||||
|
|
||||||
-- not-existent audio
|
-- not-existent audio
|
||||||
local function playNotExistentAudio(tag, sender)
|
local function playNotExistentAudio(tag, sender)
|
||||||
cc.AudioEngine:play2d("not-existent file.mp3")
|
ccexp.AudioEngine:play2d("not-existent file.mp3")
|
||||||
end
|
end
|
||||||
|
|
||||||
local playItem2 = cc.MenuItemFont:create("play not-existent file")
|
local playItem2 = cc.MenuItemFont:create("play not-existent file")
|
||||||
|
@ -490,7 +490,7 @@ function LargeAudioFileTest.create()
|
||||||
local layerSize = layer:getContentSize()
|
local layerSize = layer:getContentSize()
|
||||||
|
|
||||||
local function playAudio(tag, sender)
|
local function playAudio(tag, sender)
|
||||||
cc.AudioEngine:play2d("audio/Chee Lai(Arise).mp3")
|
ccexp.AudioEngine:play2d("audio/Chee Lai(Arise).mp3")
|
||||||
end
|
end
|
||||||
|
|
||||||
local playItem = cc.MenuItemFont:create("play large audio file")
|
local playItem = cc.MenuItemFont:create("play large audio file")
|
||||||
|
@ -503,7 +503,7 @@ function LargeAudioFileTest.create()
|
||||||
|
|
||||||
function onNodeEvent(tag)
|
function onNodeEvent(tag)
|
||||||
if tag == "exit" then
|
if tag == "exit" then
|
||||||
cc.AudioEngine:stopAll()
|
ccexp.AudioEngine:stopAll()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
layer:registerScriptHandler(onNodeEvent)
|
layer:registerScriptHandler(onNodeEvent)
|
||||||
|
|
|
@ -5,7 +5,7 @@ prefix = cocos2dx_audioengine
|
||||||
|
|
||||||
# create a target namespace (in javascript, this would create some code like the equiv. to `ns = ns || {}`)
|
# create a target namespace (in javascript, this would create some code like the equiv. to `ns = ns || {}`)
|
||||||
# all classes will be embedded in that namespace
|
# all classes will be embedded in that namespace
|
||||||
target_namespace = cc
|
target_namespace = ccexp
|
||||||
|
|
||||||
android_headers = -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.7/libs/armeabi-v7a/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.7/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.8/include
|
android_headers = -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.7/libs/armeabi-v7a/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.7/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.8/include
|
||||||
android_flags = -D_SIZE_T_DEFINED_
|
android_flags = -D_SIZE_T_DEFINED_
|
||||||
|
|
Loading…
Reference in New Issue