axmol/tests/cpp-tests/Classes/NewAudioEngineTest/NewAudioEngineTest.cpp

863 lines
27 KiB
C++
Raw Normal View History

2014-09-03 18:20:31 +08:00
/****************************************************************************
Copyright (c) 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.
****************************************************************************/
2014-09-30 01:45:43 +08:00
#include "platform/CCPlatformConfig.h"
2014-09-03 18:20:31 +08:00
#include "NewAudioEngineTest.h"
#include "ui/CocosGUI.h"
using namespace cocos2d;
2014-09-03 18:20:31 +08:00
using namespace cocos2d::ui;
using namespace cocos2d::experimental;
2014-09-03 18:20:31 +08:00
AudioEngineTests::AudioEngineTests()
2014-09-03 18:20:31 +08:00
{
2015-08-07 16:50:54 +08:00
ADD_TEST_CASE(AudioIssue11143Test);
ADD_TEST_CASE(AudioControlTest);
2015-08-07 16:50:54 +08:00
ADD_TEST_CASE(AudioLoadTest);
ADD_TEST_CASE(PlaySimultaneouslyTest);
ADD_TEST_CASE(AudioProfileTest);
ADD_TEST_CASE(InvalidAudioFileTest);
ADD_TEST_CASE(LargeAudioFileTest);
[big refactoring] Audio latency fix for Android. Support to preload effects on Android now. (#15875) * Audio latency fix for Android. Support preload effects on Android now. Squashed commits: [b6d80fe] log fix [a0a918e] Fixes assetFd didn't be released while PcmData is returned from cache. [4b956ba] Potential crash fix for PcmAudioPlayer while pause / resume. [398ab8c] Updates LOG_TAG position in AudioEngine-inl.cpp [e3634e7] include stdlib.h for posix_memalign [9004074] fixes setVolume logical error. [c96df46] Don't use another thread for mixing, enqueue is in a seperated thread, therefore doing mixing in another thread will waste more time. [0a4c1a8] Adds setLoop, setVolume, setPostion support for Track [c35fb20] Fixed include. [cdd9d32] Do mixing by ourself. (TO BE POLISHED) [6447025] µ -> u since µ could not be shown on some android devices. [97be0c6] Don't send a silence clip. [c1607ed] Make linter.py happy. [0898b54] Puts enqueue & SetPlayState in PcmAudioPlayer::play to thread pool. [b79fc01] Adds getDuration, getPosition support for PcmAudioPlayer [80fa2ab] minor fix of the code position of resetting state to State::INITIALIZED [d9c62f1] underrun fix for PcmAudioPlayer. [9c2212a] UrlAudioPlayer, playOverMutex should be static, and should be used in update method. [1519d2e] static variables [19da936] _pcmAudioPlayer Null pointer check in AudioPlayerProvider. [e6b0d14] Updates audio performance test. [fc01dd4] Registers foreground & background event in AudioEngine-inl.cpp(android), the callback should invoke `provider`'s pause & resume method. [e00a886] TBD: Pause & resume support for PcmAudioPlayerPool. Since OpenSLES audio resources are expensive and device shared, we should delete all unused PcmAudioPlayers in pool while pause and re-create them while resume. But this commit isn't finished yet, I don't find a better way to register pause&resume event in AudioEngine module. [9e42ea3] Interleave mono audio to stereo audio. PcmAudioPlayerPool only contains PcmAudioPlayers with 2 channels. [3f18d05] Adds a strategy for checking small size of different file formats. [753ff49] Adds performance test for AudioEngine. [09d3045] Releases an extra PcmAudioPlayer for UrlAudioPlayer while allocating PcmAudioPlayer fails. [9dd4477] Using std::move for PcmData move constructor & move assignment. [6ca3bcb] some fixes: 1) new -> new (std::nothrow) 2) break if allocate PcmAudioPlayer fails 3) renames 'initForPlayPcmData' to 'init' 4) PcmAudioPlayer destructor deadlock if 'init' failed [54675b6] include path fix. [a1903ca] More refactorings. [19b9498] Makes linter.py happy. :) [923c530] Fixes: 1) Avoid getFileInfo to be invoked twice 2) A critical bug fix for UrlAudioPlayer and adds detailed comments 3) __clang__ compiler option fix for AudioResamplerSinc.cpp. [5ec4faf] minor fix. [faaa0f3] output a log in the destructor of UrlAudioPlayer. [9c20355] NewAudioEngineTest,TestControll crash fix. [f114464] fixes an unused import. [1dc5dab] Better algorithm for allocating PcmAudioPlayer. [331a213] minor fix. [e54084a] null -> nullptr [f9a0389] Support uncache. [89a364f] Removes unused update, and TODO uncache functionality. [1732bf9] Supports AudioEngineImpl::setFinishCallback for android. [43d1596] UrlAudioPlayer::stop fix. [e2ee941] Test case fix in NewAudioEngineTest/AudioIssue11143Test [5c5ba01] More fixes for making cpp-tests/New Audio Engine Test happy. [8b554a3] Adds log while remove player from map. [ed71322] If original file is larger than 30k bytes, consider it's a large audio file. [fb1845a] Updates project.properties [6f3839f] minor log output fix in AudioEngine-inl.cpp [c68bc6c] Don't resample if the sample rate of the decoded pcm data matchs the device's. [43ca45f] PcmAudioPlayers also need to be removed while they play over, but should not be deleted since their lifecycle is managed by PcmAudioPlayerPool. [f5e63c9] Audio latency fix for Android. Support preload effects on Android now. * Supports to loading audio files asynchronously. * Crash fix for stop audio right after play2d. * Minor fix for logic in AudioMixerController.cpp * Adds missing files (CCThreadPool.h/.cpp). * Minor fix for including. * Minor fix for missing include <functional> in Track.h * update license information in audio.h * Don't use std::future/std::promise anymore since ndk counldn't support it well in armeabi arch. * isSmallFile postion updated, fixes large audio file goto the checking logic of cache. * std::atomic<int> isn't supported by ndk-r10e while compiling with `armeabi` arch, using a int with a mutex instead. * fixes __isnanf & posix_memalign doesn't exist on low api (<=16) devices. * namespace updated: cocos2d -> cocos2d::experimental * Removes commented code in AudioMixerController.h/.cpp * Removes unused code again, and fixes a memory leak of `Track` instance. * Oops, namespace changed. * Only outputs log in debug mode. * Uses ALOGV for outputing logs in AudioEngine-inl.cpp * const PcmData& -> PcmData for Track * Fixes a protential crash in NewAudioEngineTest * Adds `COCOS` prefix in header #ifndef COCOS_BALABALA #define COCOS_BALABALA * Uses _ prefix for cocos code style instead of `m` prefix. * Deletes AudioResamplerSinc related files. * Bug fix from @minggo's reply on github. * Don't need to invoke pause after in UrlAudioPlayer::prepare. * Updates ThreadPool class, uses enum class and adds const keyword.
2016-07-18 10:22:40 +08:00
ADD_TEST_CASE(AudioPerformanceTest);
ADD_TEST_CASE(AudioSwitchStateTest);
2016-07-27 14:00:34 +08:00
ADD_TEST_CASE(AudioSmallFileTest);
ADD_TEST_CASE(AudioPauseResumeAfterPlay);
ADD_TEST_CASE(AudioPreloadSameFileMultipleTimes);
2014-09-03 18:20:31 +08:00
}
namespace {
2014-09-03 18:20:31 +08:00
class TextButton : public cocos2d::Label
{
public:
static TextButton *create(const std::string& text, const std::function<void(TextButton*)> &onTriggered)
{
auto ret = new (std::nothrow) TextButton();
TTFConfig ttfconfig("fonts/arial.ttf",25);
if (ret && ret->setTTFConfig(ttfconfig)) {
ret->setString(text);
ret->_onTriggered = onTriggered;
ret->autorelease();
return ret;
}
delete ret;
return nullptr;
}
void setEnabled(bool enabled)
{
_enabled = enabled;
if(_enabled){
this->setColor(Color3B::WHITE);
}
else {
this->setColor(Color3B::GRAY);
}
}
private:
TextButton()
: _onTriggered(nullptr)
, _enabled(true)
2014-09-03 18:20:31 +08:00
{
auto listener = EventListenerTouchOneByOne::create();
listener->setSwallowTouches(true);
listener->onTouchBegan = CC_CALLBACK_2(TextButton::onTouchBegan, this);
listener->onTouchEnded = CC_CALLBACK_2(TextButton::onTouchEnded, this);
listener->onTouchCancelled = CC_CALLBACK_2(TextButton::onTouchCancelled, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
}
bool touchHits(Touch *touch)
{
auto hitPos = this->convertToNodeSpace(touch->getLocation());
if (hitPos.x >= 0 && hitPos.y >= 0 && hitPos.x <= _contentSize.width && hitPos.y <= _contentSize.height) {
return true;
}
return false;
}
bool onTouchBegan(Touch *touch, Event *event)
{
auto hits = touchHits(touch);
if (hits){
scaleButtonTo(0.95f);
}
return hits;
}
void onTouchEnded(Touch *touch, Event *event)
{
if(_enabled) {
auto hits = touchHits(touch);
if (hits && _onTriggered){
_onTriggered(this);
}
}
scaleButtonTo(1);
}
void onTouchCancelled(Touch *touch, Event *event)
{
scaleButtonTo(1);
}
void scaleButtonTo(float scale)
{
auto action = ScaleTo::create(0.05f, scale);
action->setTag(10000);
stopActionByTag(10000);
runAction(action);
}
std::function<void(TextButton*)> _onTriggered;
bool _enabled;
};
class SliderEx : public Slider
2014-09-03 18:20:31 +08:00
{
public:
static SliderEx* create(){
auto ret = new (std::nothrow) SliderEx();
if (ret && ret->init())
{
ret->loadBarTexture("cocosui/sliderTrack.png");
ret->loadSlidBallTextures("cocosui/sliderThumb.png", "cocosui/sliderThumb.png", "");
ret->loadProgressBarTexture("cocosui/sliderProgress.png");
2015-07-29 20:47:38 +08:00
ret->setTouchEnabled(true);
2014-09-03 18:20:31 +08:00
ret->autorelease();
return ret;
}
CC_SAFE_DELETE(ret);
return ret;
}
void setRatio(float ratio) {
2015-07-29 20:47:38 +08:00
ratio = clampf(ratio, 0.0f, 1.0f);
2014-09-03 18:20:31 +08:00
_ratio = ratio;
2015-07-29 20:47:38 +08:00
setPercent(100 * _ratio);
2014-09-03 18:20:31 +08:00
}
2015-07-29 20:47:38 +08:00
float getRatio () {
2015-07-30 17:14:08 +08:00
_ratio = 1.0f * _percent / _maxPercent;
2015-07-29 20:47:38 +08:00
return _ratio;
2014-09-03 18:20:31 +08:00
}
private:
float _ratio;
};
}
[big refactoring] Audio latency fix for Android. Support to preload effects on Android now. (#15875) * Audio latency fix for Android. Support preload effects on Android now. Squashed commits: [b6d80fe] log fix [a0a918e] Fixes assetFd didn't be released while PcmData is returned from cache. [4b956ba] Potential crash fix for PcmAudioPlayer while pause / resume. [398ab8c] Updates LOG_TAG position in AudioEngine-inl.cpp [e3634e7] include stdlib.h for posix_memalign [9004074] fixes setVolume logical error. [c96df46] Don't use another thread for mixing, enqueue is in a seperated thread, therefore doing mixing in another thread will waste more time. [0a4c1a8] Adds setLoop, setVolume, setPostion support for Track [c35fb20] Fixed include. [cdd9d32] Do mixing by ourself. (TO BE POLISHED) [6447025] µ -> u since µ could not be shown on some android devices. [97be0c6] Don't send a silence clip. [c1607ed] Make linter.py happy. [0898b54] Puts enqueue & SetPlayState in PcmAudioPlayer::play to thread pool. [b79fc01] Adds getDuration, getPosition support for PcmAudioPlayer [80fa2ab] minor fix of the code position of resetting state to State::INITIALIZED [d9c62f1] underrun fix for PcmAudioPlayer. [9c2212a] UrlAudioPlayer, playOverMutex should be static, and should be used in update method. [1519d2e] static variables [19da936] _pcmAudioPlayer Null pointer check in AudioPlayerProvider. [e6b0d14] Updates audio performance test. [fc01dd4] Registers foreground & background event in AudioEngine-inl.cpp(android), the callback should invoke `provider`'s pause & resume method. [e00a886] TBD: Pause & resume support for PcmAudioPlayerPool. Since OpenSLES audio resources are expensive and device shared, we should delete all unused PcmAudioPlayers in pool while pause and re-create them while resume. But this commit isn't finished yet, I don't find a better way to register pause&resume event in AudioEngine module. [9e42ea3] Interleave mono audio to stereo audio. PcmAudioPlayerPool only contains PcmAudioPlayers with 2 channels. [3f18d05] Adds a strategy for checking small size of different file formats. [753ff49] Adds performance test for AudioEngine. [09d3045] Releases an extra PcmAudioPlayer for UrlAudioPlayer while allocating PcmAudioPlayer fails. [9dd4477] Using std::move for PcmData move constructor & move assignment. [6ca3bcb] some fixes: 1) new -> new (std::nothrow) 2) break if allocate PcmAudioPlayer fails 3) renames 'initForPlayPcmData' to 'init' 4) PcmAudioPlayer destructor deadlock if 'init' failed [54675b6] include path fix. [a1903ca] More refactorings. [19b9498] Makes linter.py happy. :) [923c530] Fixes: 1) Avoid getFileInfo to be invoked twice 2) A critical bug fix for UrlAudioPlayer and adds detailed comments 3) __clang__ compiler option fix for AudioResamplerSinc.cpp. [5ec4faf] minor fix. [faaa0f3] output a log in the destructor of UrlAudioPlayer. [9c20355] NewAudioEngineTest,TestControll crash fix. [f114464] fixes an unused import. [1dc5dab] Better algorithm for allocating PcmAudioPlayer. [331a213] minor fix. [e54084a] null -> nullptr [f9a0389] Support uncache. [89a364f] Removes unused update, and TODO uncache functionality. [1732bf9] Supports AudioEngineImpl::setFinishCallback for android. [43d1596] UrlAudioPlayer::stop fix. [e2ee941] Test case fix in NewAudioEngineTest/AudioIssue11143Test [5c5ba01] More fixes for making cpp-tests/New Audio Engine Test happy. [8b554a3] Adds log while remove player from map. [ed71322] If original file is larger than 30k bytes, consider it's a large audio file. [fb1845a] Updates project.properties [6f3839f] minor log output fix in AudioEngine-inl.cpp [c68bc6c] Don't resample if the sample rate of the decoded pcm data matchs the device's. [43ca45f] PcmAudioPlayers also need to be removed while they play over, but should not be deleted since their lifecycle is managed by PcmAudioPlayerPool. [f5e63c9] Audio latency fix for Android. Support preload effects on Android now. * Supports to loading audio files asynchronously. * Crash fix for stop audio right after play2d. * Minor fix for logic in AudioMixerController.cpp * Adds missing files (CCThreadPool.h/.cpp). * Minor fix for including. * Minor fix for missing include <functional> in Track.h * update license information in audio.h * Don't use std::future/std::promise anymore since ndk counldn't support it well in armeabi arch. * isSmallFile postion updated, fixes large audio file goto the checking logic of cache. * std::atomic<int> isn't supported by ndk-r10e while compiling with `armeabi` arch, using a int with a mutex instead. * fixes __isnanf & posix_memalign doesn't exist on low api (<=16) devices. * namespace updated: cocos2d -> cocos2d::experimental * Removes commented code in AudioMixerController.h/.cpp * Removes unused code again, and fixes a memory leak of `Track` instance. * Oops, namespace changed. * Only outputs log in debug mode. * Uses ALOGV for outputing logs in AudioEngine-inl.cpp * const PcmData& -> PcmData for Track * Fixes a protential crash in NewAudioEngineTest * Adds `COCOS` prefix in header #ifndef COCOS_BALABALA #define COCOS_BALABALA * Uses _ prefix for cocos code style instead of `m` prefix. * Deletes AudioResamplerSinc related files. * Bug fix from @minggo's reply on github. * Don't need to invoke pause after in UrlAudioPlayer::prepare. * Updates ThreadPool class, uses enum class and adds const keyword.
2016-07-18 10:22:40 +08:00
AudioEngineTestDemo::AudioEngineTestDemo()
: _isDestroyed(std::make_shared<bool>(false))
{
}
2014-09-14 22:49:27 +08:00
void AudioEngineTestDemo::onExit()
2014-09-03 18:20:31 +08:00
{
[big refactoring] Audio latency fix for Android. Support to preload effects on Android now. (#15875) * Audio latency fix for Android. Support preload effects on Android now. Squashed commits: [b6d80fe] log fix [a0a918e] Fixes assetFd didn't be released while PcmData is returned from cache. [4b956ba] Potential crash fix for PcmAudioPlayer while pause / resume. [398ab8c] Updates LOG_TAG position in AudioEngine-inl.cpp [e3634e7] include stdlib.h for posix_memalign [9004074] fixes setVolume logical error. [c96df46] Don't use another thread for mixing, enqueue is in a seperated thread, therefore doing mixing in another thread will waste more time. [0a4c1a8] Adds setLoop, setVolume, setPostion support for Track [c35fb20] Fixed include. [cdd9d32] Do mixing by ourself. (TO BE POLISHED) [6447025] µ -> u since µ could not be shown on some android devices. [97be0c6] Don't send a silence clip. [c1607ed] Make linter.py happy. [0898b54] Puts enqueue & SetPlayState in PcmAudioPlayer::play to thread pool. [b79fc01] Adds getDuration, getPosition support for PcmAudioPlayer [80fa2ab] minor fix of the code position of resetting state to State::INITIALIZED [d9c62f1] underrun fix for PcmAudioPlayer. [9c2212a] UrlAudioPlayer, playOverMutex should be static, and should be used in update method. [1519d2e] static variables [19da936] _pcmAudioPlayer Null pointer check in AudioPlayerProvider. [e6b0d14] Updates audio performance test. [fc01dd4] Registers foreground & background event in AudioEngine-inl.cpp(android), the callback should invoke `provider`'s pause & resume method. [e00a886] TBD: Pause & resume support for PcmAudioPlayerPool. Since OpenSLES audio resources are expensive and device shared, we should delete all unused PcmAudioPlayers in pool while pause and re-create them while resume. But this commit isn't finished yet, I don't find a better way to register pause&resume event in AudioEngine module. [9e42ea3] Interleave mono audio to stereo audio. PcmAudioPlayerPool only contains PcmAudioPlayers with 2 channels. [3f18d05] Adds a strategy for checking small size of different file formats. [753ff49] Adds performance test for AudioEngine. [09d3045] Releases an extra PcmAudioPlayer for UrlAudioPlayer while allocating PcmAudioPlayer fails. [9dd4477] Using std::move for PcmData move constructor & move assignment. [6ca3bcb] some fixes: 1) new -> new (std::nothrow) 2) break if allocate PcmAudioPlayer fails 3) renames 'initForPlayPcmData' to 'init' 4) PcmAudioPlayer destructor deadlock if 'init' failed [54675b6] include path fix. [a1903ca] More refactorings. [19b9498] Makes linter.py happy. :) [923c530] Fixes: 1) Avoid getFileInfo to be invoked twice 2) A critical bug fix for UrlAudioPlayer and adds detailed comments 3) __clang__ compiler option fix for AudioResamplerSinc.cpp. [5ec4faf] minor fix. [faaa0f3] output a log in the destructor of UrlAudioPlayer. [9c20355] NewAudioEngineTest,TestControll crash fix. [f114464] fixes an unused import. [1dc5dab] Better algorithm for allocating PcmAudioPlayer. [331a213] minor fix. [e54084a] null -> nullptr [f9a0389] Support uncache. [89a364f] Removes unused update, and TODO uncache functionality. [1732bf9] Supports AudioEngineImpl::setFinishCallback for android. [43d1596] UrlAudioPlayer::stop fix. [e2ee941] Test case fix in NewAudioEngineTest/AudioIssue11143Test [5c5ba01] More fixes for making cpp-tests/New Audio Engine Test happy. [8b554a3] Adds log while remove player from map. [ed71322] If original file is larger than 30k bytes, consider it's a large audio file. [fb1845a] Updates project.properties [6f3839f] minor log output fix in AudioEngine-inl.cpp [c68bc6c] Don't resample if the sample rate of the decoded pcm data matchs the device's. [43ca45f] PcmAudioPlayers also need to be removed while they play over, but should not be deleted since their lifecycle is managed by PcmAudioPlayerPool. [f5e63c9] Audio latency fix for Android. Support preload effects on Android now. * Supports to loading audio files asynchronously. * Crash fix for stop audio right after play2d. * Minor fix for logic in AudioMixerController.cpp * Adds missing files (CCThreadPool.h/.cpp). * Minor fix for including. * Minor fix for missing include <functional> in Track.h * update license information in audio.h * Don't use std::future/std::promise anymore since ndk counldn't support it well in armeabi arch. * isSmallFile postion updated, fixes large audio file goto the checking logic of cache. * std::atomic<int> isn't supported by ndk-r10e while compiling with `armeabi` arch, using a int with a mutex instead. * fixes __isnanf & posix_memalign doesn't exist on low api (<=16) devices. * namespace updated: cocos2d -> cocos2d::experimental * Removes commented code in AudioMixerController.h/.cpp * Removes unused code again, and fixes a memory leak of `Track` instance. * Oops, namespace changed. * Only outputs log in debug mode. * Uses ALOGV for outputing logs in AudioEngine-inl.cpp * const PcmData& -> PcmData for Track * Fixes a protential crash in NewAudioEngineTest * Adds `COCOS` prefix in header #ifndef COCOS_BALABALA #define COCOS_BALABALA * Uses _ prefix for cocos code style instead of `m` prefix. * Deletes AudioResamplerSinc related files. * Bug fix from @minggo's reply on github. * Don't need to invoke pause after in UrlAudioPlayer::prepare. * Updates ThreadPool class, uses enum class and adds const keyword.
2016-07-18 10:22:40 +08:00
*_isDestroyed = true;
AudioEngine::uncacheAll();
TestCase::onExit();
2014-09-03 18:20:31 +08:00
}
std::string AudioEngineTestDemo::title() const
{
return "New Audio Engine Test";
}
// AudioControlTest
bool AudioControlTest::init()
{
auto ret = AudioEngineTestDemo::init();
_audioID = AudioEngine::INVALID_AUDIO_ID;
2014-09-03 18:20:31 +08:00
_loopEnabled = false;
_volume = 1.0f;
_duration = AudioEngine::TIME_UNKNOWN;
_timeRatio = 0.0f;
_updateTimeSlider = true;
std::string fontFilePath = "fonts/arial.ttf";
auto& layerSize = this->getContentSize();
auto playItem = TextButton::create("play", [&](TextButton* button){
if (_audioID == AudioEngine::INVALID_AUDIO_ID) {
_audioID = AudioEngine::play2d("background.mp3", _loopEnabled, _volume);
2014-09-03 18:20:31 +08:00
if(_audioID != AudioEngine::INVALID_AUDIO_ID) {
2014-09-03 18:20:31 +08:00
button->setEnabled(false);
AudioEngine::setFinishCallback(_audioID, [&](int id, const std::string& filePath){
_audioID = AudioEngine::INVALID_AUDIO_ID;
2014-09-03 18:20:31 +08:00
((TextButton*)_playItem)->setEnabled(true);
_timeRatio = 0.0f;
((SliderEx*)_timeSlider)->setRatio(_timeRatio);
});
}
}
});
_playItem = playItem;
playItem->setPosition(layerSize.width * 0.3f,layerSize.height * 0.8f);
2014-09-03 18:20:31 +08:00
addChild(playItem);
auto stopItem = TextButton::create("stop", [&](TextButton* button){
if (_audioID != AudioEngine::INVALID_AUDIO_ID ) {
AudioEngine::stop(_audioID);
2014-09-03 18:20:31 +08:00
_audioID = AudioEngine::INVALID_AUDIO_ID;
2014-09-03 18:20:31 +08:00
((TextButton*)_playItem)->setEnabled(true);
}
});
stopItem->setPosition(layerSize.width * 0.7f,layerSize.height * 0.8f);
2014-09-03 18:20:31 +08:00
addChild(stopItem);
auto pauseItem = TextButton::create("pause", [&](TextButton* button){
if (_audioID != AudioEngine::INVALID_AUDIO_ID ) {
AudioEngine::pause(_audioID);
2014-09-03 18:20:31 +08:00
}
});
pauseItem->setPosition(layerSize.width * 0.3f,layerSize.height * 0.7f);
2014-09-03 18:20:31 +08:00
addChild(pauseItem);
auto resumeItem = TextButton::create("resume", [&](TextButton* button){
if (_audioID != AudioEngine::INVALID_AUDIO_ID ) {
AudioEngine::resume(_audioID);
2014-09-03 18:20:31 +08:00
}
});
resumeItem->setPosition(layerSize.width * 0.7f,layerSize.height * 0.7f);
2014-09-03 18:20:31 +08:00
addChild(resumeItem);
auto loopItem = TextButton::create("enable-loop", [&](TextButton* button){
_loopEnabled = !_loopEnabled;
if (_audioID != AudioEngine::INVALID_AUDIO_ID) {
AudioEngine::setLoop(_audioID, _loopEnabled);
2014-09-03 18:20:31 +08:00
}
if (_loopEnabled){
2014-09-03 18:20:31 +08:00
button->setString("disable-loop");
}
else {
button->setString("enable-loop");
}
});
loopItem->setPosition(layerSize.width * 0.5f, layerSize.height * 0.5f);
2014-09-03 18:20:31 +08:00
addChild(loopItem);
auto volumeSlider = SliderEx::create();
volumeSlider->setPercent(100);
2015-07-29 20:47:38 +08:00
volumeSlider->addEventListener([&](Ref* sender, Slider::EventType event){
SliderEx *slider = dynamic_cast<SliderEx *>(sender);
_volume = slider->getRatio();
if (_audioID != AudioEngine::INVALID_AUDIO_ID ) {
AudioEngine::setVolume(_audioID, _volume);
2014-09-03 18:20:31 +08:00
}
});
volumeSlider->setPosition(Vec2(layerSize.width * 0.5f,layerSize.height * 0.35f));
addChild(volumeSlider);
auto timeSlider = SliderEx::create();
2015-07-29 20:47:38 +08:00
timeSlider->addEventListener([&](Ref* sender, Slider::EventType event){
SliderEx *slider = dynamic_cast<SliderEx *>(sender);
2014-09-03 18:20:31 +08:00
switch(event){
2015-07-29 20:47:38 +08:00
case Slider::EventType::ON_PERCENTAGE_CHANGED:
case Slider::EventType::ON_SLIDEBALL_DOWN:
2014-09-03 18:20:31 +08:00
_updateTimeSlider = false;
break;
2015-07-29 20:47:38 +08:00
case Slider::EventType::ON_SLIDEBALL_UP:
if (_audioID != AudioEngine::INVALID_AUDIO_ID && _duration != AudioEngine::TIME_UNKNOWN) {
2015-07-29 20:47:38 +08:00
float ratio = (float)slider->getPercent() / 100;
ratio = clampf(ratio, 0.0f, 1.0f);
AudioEngine::setCurrentTime(_audioID, _duration * ratio);
2014-09-03 18:20:31 +08:00
}
2015-07-29 20:47:38 +08:00
case Slider::EventType::ON_SLIDEBALL_CANCEL:
2014-09-03 18:20:31 +08:00
_updateTimeSlider = true;
break;
}
});
timeSlider->setPosition(Vec2(layerSize.width * 0.5f,layerSize.height * 0.25f));
addChild(timeSlider);
_timeSlider = timeSlider;
auto& volumeSliderPos = volumeSlider->getPosition();
auto& sliderSize = volumeSlider->getContentSize();
auto volumeLabel = Label::createWithTTF("volume: ", fontFilePath, 20);
volumeLabel->setAnchorPoint(Vec2::ANCHOR_MIDDLE_RIGHT);
volumeLabel->setPosition(volumeSliderPos.x - sliderSize.width / 2, volumeSliderPos.y);
addChild(volumeLabel);
auto& timeSliderPos = timeSlider->getPosition();
auto timeLabel = Label::createWithTTF("time: ", fontFilePath, 20);
timeLabel->setAnchorPoint(Vec2::ANCHOR_MIDDLE_RIGHT);
timeLabel->setPosition(timeSliderPos.x - sliderSize.width / 2, timeSliderPos.y);
addChild(timeLabel);
this->schedule(CC_CALLBACK_1(AudioControlTest::update, this), 0.1f, "update_key");
2014-09-03 18:20:31 +08:00
return ret;
}
void AudioControlTest::update(float dt)
{
if (_audioID != AudioEngine::INVALID_AUDIO_ID ) {
2014-09-03 18:20:31 +08:00
if(_duration == AudioEngine::TIME_UNKNOWN){
_duration = AudioEngine::getDuration(_audioID);
2014-09-03 18:20:31 +08:00
}
if(_duration != AudioEngine::TIME_UNKNOWN){
auto time = AudioEngine::getCurrentTime(_audioID);
2014-09-03 18:20:31 +08:00
_timeRatio = time / _duration;
if(_updateTimeSlider){
((SliderEx*)_timeSlider)->setRatio(_timeRatio);
}
}
}
}
AudioControlTest::~AudioControlTest()
{
}
std::string AudioControlTest::title() const
{
2015-08-07 16:50:54 +08:00
return "Audio control test";
}
bool AudioLoadTest::init()
{
if (AudioEngineTestDemo::init())
{
auto& layerSize = this->getContentSize();
auto stateLabel = Label::createWithTTF("status:", "fonts/arial.ttf", 30);
stateLabel->setPosition(layerSize.width / 2, layerSize.height * 0.7f);
addChild(stateLabel);
auto preloadItem = TextButton::create("preload", [&, stateLabel](TextButton* button){
stateLabel->setString("status:loading...");
[big refactoring] Audio latency fix for Android. Support to preload effects on Android now. (#15875) * Audio latency fix for Android. Support preload effects on Android now. Squashed commits: [b6d80fe] log fix [a0a918e] Fixes assetFd didn't be released while PcmData is returned from cache. [4b956ba] Potential crash fix for PcmAudioPlayer while pause / resume. [398ab8c] Updates LOG_TAG position in AudioEngine-inl.cpp [e3634e7] include stdlib.h for posix_memalign [9004074] fixes setVolume logical error. [c96df46] Don't use another thread for mixing, enqueue is in a seperated thread, therefore doing mixing in another thread will waste more time. [0a4c1a8] Adds setLoop, setVolume, setPostion support for Track [c35fb20] Fixed include. [cdd9d32] Do mixing by ourself. (TO BE POLISHED) [6447025] µ -> u since µ could not be shown on some android devices. [97be0c6] Don't send a silence clip. [c1607ed] Make linter.py happy. [0898b54] Puts enqueue & SetPlayState in PcmAudioPlayer::play to thread pool. [b79fc01] Adds getDuration, getPosition support for PcmAudioPlayer [80fa2ab] minor fix of the code position of resetting state to State::INITIALIZED [d9c62f1] underrun fix for PcmAudioPlayer. [9c2212a] UrlAudioPlayer, playOverMutex should be static, and should be used in update method. [1519d2e] static variables [19da936] _pcmAudioPlayer Null pointer check in AudioPlayerProvider. [e6b0d14] Updates audio performance test. [fc01dd4] Registers foreground & background event in AudioEngine-inl.cpp(android), the callback should invoke `provider`'s pause & resume method. [e00a886] TBD: Pause & resume support for PcmAudioPlayerPool. Since OpenSLES audio resources are expensive and device shared, we should delete all unused PcmAudioPlayers in pool while pause and re-create them while resume. But this commit isn't finished yet, I don't find a better way to register pause&resume event in AudioEngine module. [9e42ea3] Interleave mono audio to stereo audio. PcmAudioPlayerPool only contains PcmAudioPlayers with 2 channels. [3f18d05] Adds a strategy for checking small size of different file formats. [753ff49] Adds performance test for AudioEngine. [09d3045] Releases an extra PcmAudioPlayer for UrlAudioPlayer while allocating PcmAudioPlayer fails. [9dd4477] Using std::move for PcmData move constructor & move assignment. [6ca3bcb] some fixes: 1) new -> new (std::nothrow) 2) break if allocate PcmAudioPlayer fails 3) renames 'initForPlayPcmData' to 'init' 4) PcmAudioPlayer destructor deadlock if 'init' failed [54675b6] include path fix. [a1903ca] More refactorings. [19b9498] Makes linter.py happy. :) [923c530] Fixes: 1) Avoid getFileInfo to be invoked twice 2) A critical bug fix for UrlAudioPlayer and adds detailed comments 3) __clang__ compiler option fix for AudioResamplerSinc.cpp. [5ec4faf] minor fix. [faaa0f3] output a log in the destructor of UrlAudioPlayer. [9c20355] NewAudioEngineTest,TestControll crash fix. [f114464] fixes an unused import. [1dc5dab] Better algorithm for allocating PcmAudioPlayer. [331a213] minor fix. [e54084a] null -> nullptr [f9a0389] Support uncache. [89a364f] Removes unused update, and TODO uncache functionality. [1732bf9] Supports AudioEngineImpl::setFinishCallback for android. [43d1596] UrlAudioPlayer::stop fix. [e2ee941] Test case fix in NewAudioEngineTest/AudioIssue11143Test [5c5ba01] More fixes for making cpp-tests/New Audio Engine Test happy. [8b554a3] Adds log while remove player from map. [ed71322] If original file is larger than 30k bytes, consider it's a large audio file. [fb1845a] Updates project.properties [6f3839f] minor log output fix in AudioEngine-inl.cpp [c68bc6c] Don't resample if the sample rate of the decoded pcm data matchs the device's. [43ca45f] PcmAudioPlayers also need to be removed while they play over, but should not be deleted since their lifecycle is managed by PcmAudioPlayerPool. [f5e63c9] Audio latency fix for Android. Support preload effects on Android now. * Supports to loading audio files asynchronously. * Crash fix for stop audio right after play2d. * Minor fix for logic in AudioMixerController.cpp * Adds missing files (CCThreadPool.h/.cpp). * Minor fix for including. * Minor fix for missing include <functional> in Track.h * update license information in audio.h * Don't use std::future/std::promise anymore since ndk counldn't support it well in armeabi arch. * isSmallFile postion updated, fixes large audio file goto the checking logic of cache. * std::atomic<int> isn't supported by ndk-r10e while compiling with `armeabi` arch, using a int with a mutex instead. * fixes __isnanf & posix_memalign doesn't exist on low api (<=16) devices. * namespace updated: cocos2d -> cocos2d::experimental * Removes commented code in AudioMixerController.h/.cpp * Removes unused code again, and fixes a memory leak of `Track` instance. * Oops, namespace changed. * Only outputs log in debug mode. * Uses ALOGV for outputing logs in AudioEngine-inl.cpp * const PcmData& -> PcmData for Track * Fixes a protential crash in NewAudioEngineTest * Adds `COCOS` prefix in header #ifndef COCOS_BALABALA #define COCOS_BALABALA * Uses _ prefix for cocos code style instead of `m` prefix. * Deletes AudioResamplerSinc related files. * Bug fix from @minggo's reply on github. * Don't need to invoke pause after in UrlAudioPlayer::prepare. * Updates ThreadPool class, uses enum class and adds const keyword.
2016-07-18 10:22:40 +08:00
auto isDestroyed = _isDestroyed;
AudioEngine::preload("audio/SoundEffectsFX009/FX082.mp3", [isDestroyed, stateLabel](bool isSuccess){
if (*isDestroyed)
{
CCLOG("AudioLoadTest scene was destroyed, no need to set the label text.");
return;
}
2015-08-07 16:50:54 +08:00
if (isSuccess)
{
stateLabel->setString("status:load success");
}
else
{
stateLabel->setString("status:load fail");
}
});
});
preloadItem->setPosition(layerSize.width * 0.35f, layerSize.height * 0.5f);
addChild(preloadItem);
auto uncacheItem = TextButton::create("uncache", [&, stateLabel](TextButton* button){
stateLabel->setString("status:uncache");
AudioEngine::uncache("audio/SoundEffectsFX009/FX082.mp3");
});
uncacheItem->setPosition(layerSize.width * 0.65f, layerSize.height * 0.5f);
addChild(uncacheItem);
return true;
}
return false;
2014-09-03 18:20:31 +08:00
}
2015-08-07 16:50:54 +08:00
std::string AudioLoadTest::title() const
{
return "Audio preload/uncache test";
}
2014-09-03 18:20:31 +08:00
// PlaySimultaneouslyTest
bool PlaySimultaneouslyTest::init()
{
auto ret = AudioEngineTestDemo::init();
2014-09-09 10:48:07 +08:00
char text[36];
2014-09-03 18:20:31 +08:00
int tmp = 81;
for(int index = 0; index < TEST_COUNT; ++index){
2014-09-09 10:48:07 +08:00
sprintf(text,"audio/SoundEffectsFX009/FX0%d.mp3",tmp + index);
2014-09-03 18:20:31 +08:00
_files[index] = text;
}
_playingcount = 0;
2014-09-09 10:48:07 +08:00
auto playItem = TextButton::create("play-simultaneously", [&](TextButton* button){
2014-09-03 18:20:31 +08:00
int audioId;
_playingcount = 0;
button->setEnabled(false);
auto startTime = utils::gettime();
for(int index = 0; index < TEST_COUNT; ++index){
audioId = AudioEngine::play2d(_files[index]);
if(audioId != AudioEngine::INVALID_AUDIO_ID){
2014-09-03 18:20:31 +08:00
_playingcount += 1;
AudioEngine::setFinishCallback(audioId, [&](int id, const std::string& filePath){
2014-09-03 18:20:31 +08:00
_playingcount -= 1;
if(_playingcount <= 0){
((TextButton*)_playItem)->setEnabled(true);
}
});
}
else {
log("%s,%d,Fail to play file:%s",__FILE__,__LINE__ ,_files[index].c_str());
}
}
log("diff time:%lf",utils::gettime() - startTime);
});
playItem->setNormalizedPosition(Vec2(0.5f,0.5f));
this->addChild(playItem);
_playItem = playItem;
return ret;
}
PlaySimultaneouslyTest::~PlaySimultaneouslyTest()
{
}
std::string PlaySimultaneouslyTest::title() const
{
return "Simultaneously play multiple audio";
}
// AudioProfileTest
bool AudioProfileTest::init()
{
auto ret = AudioEngineTestDemo::init();
char text[30];
_files[0] = "background.mp3";
2014-09-22 15:38:12 +08:00
#if CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC
2014-09-03 18:20:31 +08:00
_files[1] = "background.caf";
#else
_files[1] = "background.ogg";
#endif
std::string fontFilePath = "fonts/arial.ttf";
_minDelay = 1.0f;
_time = 0.0f;
_audioProfile.name = "AudioProfileTest";
_audioProfile.maxInstances = 3;
_audioProfile.minDelay = 1.0;
2014-09-03 18:20:31 +08:00
Vec2 pos(0.5f,0.7f);
for(int index = 0; index < FILE_COUNT; ++index){
sprintf(text,"play %s",_files[index].c_str());
auto playItem = TextButton::create(text, [&](TextButton* button){
int index = button->getTag();
auto id = AudioEngine::play2d(_files[index], false, 1.0f, &_audioProfile);
if(id != AudioEngine::INVALID_AUDIO_ID){
2014-09-03 18:20:31 +08:00
_time = _minDelay;
_audioCount += 1;
char show[30];
sprintf(show,"audio count:%d",_audioCount);
_showLabel->setString(show);
AudioEngine::setFinishCallback(id, [&](int id, const std::string& filePath){
2014-09-03 18:20:31 +08:00
_audioCount -= 1;
char show[30];
sprintf(show,"audio count:%d",_audioCount);
_showLabel->setString(show);
});
}
});
playItem->setTag(index);
playItem->setNormalizedPosition(pos);
this->addChild(playItem);
2014-09-29 10:15:41 +08:00
pos.y -= 0.15f;
2014-09-03 18:20:31 +08:00
}
Vec2 origin = Director::getInstance()->getVisibleOrigin();
Size size = Director::getInstance()->getVisibleSize();
auto profileInfoLabel = Label::createWithTTF("AudioProfile Info:\n max instance:3 \n minimum delay:1.0", fontFilePath, 12);
profileInfoLabel->setAnchorPoint(Vec2::ANCHOR_MIDDLE_LEFT);
profileInfoLabel->setPosition(Vec2(origin.x, origin.y + size.height * 0.65f));
addChild(profileInfoLabel);
_audioCount = 0;
_showLabel = Label::createWithTTF("audio count:0", fontFilePath, 12);
_showLabel->setAnchorPoint(Vec2::ANCHOR_MIDDLE_LEFT);
_showLabel->setPosition(Vec2(origin.x, origin.y + size.height * 0.5f));
addChild(_showLabel);
auto timeSlider = SliderEx::create();
timeSlider->setEnabled(false);
timeSlider->setNormalizedPosition(pos);
addChild(timeSlider);
_timeSlider = timeSlider;
this->schedule(CC_CALLBACK_1(AudioProfileTest::update, this), 0.05f, "update_key");
2014-09-03 18:20:31 +08:00
return ret;
}
void AudioProfileTest::update(float dt)
{
if(_time > 0.0f)
{
_time -= dt;
((SliderEx*)_timeSlider)->setRatio(_time / _minDelay);
}
}
AudioProfileTest::~AudioProfileTest()
{
}
std::string AudioProfileTest::title() const
{
return "AudioProfileTest";
}
std::string AudioProfileTest::subtitle() const
{
return "See the console.";
}
// InvalidAudioFileTest
bool InvalidAudioFileTest::init()
{
auto ret = AudioEngineTestDemo::init();
auto playItem = TextButton::create("play unsupported media type", [&](TextButton* button){
2014-09-29 10:15:41 +08:00
#if CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC
AudioEngine::play2d("background.ogg");
2014-09-29 10:15:41 +08:00
#elif CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
AudioEngine::play2d("background.caf");
2014-09-03 18:20:31 +08:00
#endif
});
playItem->setNormalizedPosition(Vec2(0.5f, 0.6f));
this->addChild(playItem);
auto playItem2 = TextButton::create("play not-existent file", [&](TextButton* button){
2014-09-09 10:48:07 +08:00
AudioEngine::play2d("not-existent file.mp3");
2014-09-03 18:20:31 +08:00
});
playItem2->setNormalizedPosition(Vec2(0.5f, 0.4f));
this->addChild(playItem2);
return ret;
}
InvalidAudioFileTest::~InvalidAudioFileTest()
{
}
std::string InvalidAudioFileTest::title() const
{
return "Test invalid audio file";
}
std::string InvalidAudioFileTest::subtitle() const
{
return "Not crash,please see the console.";
}
// LargeAudioFileTest
bool LargeAudioFileTest::init()
{
auto ret = AudioEngineTestDemo::init();
auto playItem = TextButton::create("play large audio file", [&](TextButton* button){
2014-09-23 15:38:40 +08:00
AudioEngine::play2d("audio/LuckyDay.mp3");
2014-09-03 18:20:31 +08:00
});
playItem->setNormalizedPosition(Vec2::ANCHOR_MIDDLE);
this->addChild(playItem);
return ret;
}
LargeAudioFileTest::~LargeAudioFileTest()
{
}
std::string LargeAudioFileTest::title() const
{
return "Test large audio file";
}
2015-08-07 16:50:54 +08:00
bool AudioIssue11143Test::init()
{
if (AudioEngineTestDemo::init())
{
auto& layerSize = this->getContentSize();
auto playItem = TextButton::create("play", [](TextButton* button){
[big refactoring] Audio latency fix for Android. Support to preload effects on Android now. (#15875) * Audio latency fix for Android. Support preload effects on Android now. Squashed commits: [b6d80fe] log fix [a0a918e] Fixes assetFd didn't be released while PcmData is returned from cache. [4b956ba] Potential crash fix for PcmAudioPlayer while pause / resume. [398ab8c] Updates LOG_TAG position in AudioEngine-inl.cpp [e3634e7] include stdlib.h for posix_memalign [9004074] fixes setVolume logical error. [c96df46] Don't use another thread for mixing, enqueue is in a seperated thread, therefore doing mixing in another thread will waste more time. [0a4c1a8] Adds setLoop, setVolume, setPostion support for Track [c35fb20] Fixed include. [cdd9d32] Do mixing by ourself. (TO BE POLISHED) [6447025] µ -> u since µ could not be shown on some android devices. [97be0c6] Don't send a silence clip. [c1607ed] Make linter.py happy. [0898b54] Puts enqueue & SetPlayState in PcmAudioPlayer::play to thread pool. [b79fc01] Adds getDuration, getPosition support for PcmAudioPlayer [80fa2ab] minor fix of the code position of resetting state to State::INITIALIZED [d9c62f1] underrun fix for PcmAudioPlayer. [9c2212a] UrlAudioPlayer, playOverMutex should be static, and should be used in update method. [1519d2e] static variables [19da936] _pcmAudioPlayer Null pointer check in AudioPlayerProvider. [e6b0d14] Updates audio performance test. [fc01dd4] Registers foreground & background event in AudioEngine-inl.cpp(android), the callback should invoke `provider`'s pause & resume method. [e00a886] TBD: Pause & resume support for PcmAudioPlayerPool. Since OpenSLES audio resources are expensive and device shared, we should delete all unused PcmAudioPlayers in pool while pause and re-create them while resume. But this commit isn't finished yet, I don't find a better way to register pause&resume event in AudioEngine module. [9e42ea3] Interleave mono audio to stereo audio. PcmAudioPlayerPool only contains PcmAudioPlayers with 2 channels. [3f18d05] Adds a strategy for checking small size of different file formats. [753ff49] Adds performance test for AudioEngine. [09d3045] Releases an extra PcmAudioPlayer for UrlAudioPlayer while allocating PcmAudioPlayer fails. [9dd4477] Using std::move for PcmData move constructor & move assignment. [6ca3bcb] some fixes: 1) new -> new (std::nothrow) 2) break if allocate PcmAudioPlayer fails 3) renames 'initForPlayPcmData' to 'init' 4) PcmAudioPlayer destructor deadlock if 'init' failed [54675b6] include path fix. [a1903ca] More refactorings. [19b9498] Makes linter.py happy. :) [923c530] Fixes: 1) Avoid getFileInfo to be invoked twice 2) A critical bug fix for UrlAudioPlayer and adds detailed comments 3) __clang__ compiler option fix for AudioResamplerSinc.cpp. [5ec4faf] minor fix. [faaa0f3] output a log in the destructor of UrlAudioPlayer. [9c20355] NewAudioEngineTest,TestControll crash fix. [f114464] fixes an unused import. [1dc5dab] Better algorithm for allocating PcmAudioPlayer. [331a213] minor fix. [e54084a] null -> nullptr [f9a0389] Support uncache. [89a364f] Removes unused update, and TODO uncache functionality. [1732bf9] Supports AudioEngineImpl::setFinishCallback for android. [43d1596] UrlAudioPlayer::stop fix. [e2ee941] Test case fix in NewAudioEngineTest/AudioIssue11143Test [5c5ba01] More fixes for making cpp-tests/New Audio Engine Test happy. [8b554a3] Adds log while remove player from map. [ed71322] If original file is larger than 30k bytes, consider it's a large audio file. [fb1845a] Updates project.properties [6f3839f] minor log output fix in AudioEngine-inl.cpp [c68bc6c] Don't resample if the sample rate of the decoded pcm data matchs the device's. [43ca45f] PcmAudioPlayers also need to be removed while they play over, but should not be deleted since their lifecycle is managed by PcmAudioPlayerPool. [f5e63c9] Audio latency fix for Android. Support preload effects on Android now. * Supports to loading audio files asynchronously. * Crash fix for stop audio right after play2d. * Minor fix for logic in AudioMixerController.cpp * Adds missing files (CCThreadPool.h/.cpp). * Minor fix for including. * Minor fix for missing include <functional> in Track.h * update license information in audio.h * Don't use std::future/std::promise anymore since ndk counldn't support it well in armeabi arch. * isSmallFile postion updated, fixes large audio file goto the checking logic of cache. * std::atomic<int> isn't supported by ndk-r10e while compiling with `armeabi` arch, using a int with a mutex instead. * fixes __isnanf & posix_memalign doesn't exist on low api (<=16) devices. * namespace updated: cocos2d -> cocos2d::experimental * Removes commented code in AudioMixerController.h/.cpp * Removes unused code again, and fixes a memory leak of `Track` instance. * Oops, namespace changed. * Only outputs log in debug mode. * Uses ALOGV for outputing logs in AudioEngine-inl.cpp * const PcmData& -> PcmData for Track * Fixes a protential crash in NewAudioEngineTest * Adds `COCOS` prefix in header #ifndef COCOS_BALABALA #define COCOS_BALABALA * Uses _ prefix for cocos code style instead of `m` prefix. * Deletes AudioResamplerSinc related files. * Bug fix from @minggo's reply on github. * Don't need to invoke pause after in UrlAudioPlayer::prepare. * Updates ThreadPool class, uses enum class and adds const keyword.
2016-07-18 10:22:40 +08:00
AudioEngine::play2d("audio/SoundEffectsFX009/FX082.mp3", true);
AudioEngine::stopAll();
2015-08-07 16:50:54 +08:00
auto audioId = AudioEngine::play2d("audio/SoundEffectsFX009/FX082.mp3", true);
[big refactoring] Audio latency fix for Android. Support to preload effects on Android now. (#15875) * Audio latency fix for Android. Support preload effects on Android now. Squashed commits: [b6d80fe] log fix [a0a918e] Fixes assetFd didn't be released while PcmData is returned from cache. [4b956ba] Potential crash fix for PcmAudioPlayer while pause / resume. [398ab8c] Updates LOG_TAG position in AudioEngine-inl.cpp [e3634e7] include stdlib.h for posix_memalign [9004074] fixes setVolume logical error. [c96df46] Don't use another thread for mixing, enqueue is in a seperated thread, therefore doing mixing in another thread will waste more time. [0a4c1a8] Adds setLoop, setVolume, setPostion support for Track [c35fb20] Fixed include. [cdd9d32] Do mixing by ourself. (TO BE POLISHED) [6447025] µ -> u since µ could not be shown on some android devices. [97be0c6] Don't send a silence clip. [c1607ed] Make linter.py happy. [0898b54] Puts enqueue & SetPlayState in PcmAudioPlayer::play to thread pool. [b79fc01] Adds getDuration, getPosition support for PcmAudioPlayer [80fa2ab] minor fix of the code position of resetting state to State::INITIALIZED [d9c62f1] underrun fix for PcmAudioPlayer. [9c2212a] UrlAudioPlayer, playOverMutex should be static, and should be used in update method. [1519d2e] static variables [19da936] _pcmAudioPlayer Null pointer check in AudioPlayerProvider. [e6b0d14] Updates audio performance test. [fc01dd4] Registers foreground & background event in AudioEngine-inl.cpp(android), the callback should invoke `provider`'s pause & resume method. [e00a886] TBD: Pause & resume support for PcmAudioPlayerPool. Since OpenSLES audio resources are expensive and device shared, we should delete all unused PcmAudioPlayers in pool while pause and re-create them while resume. But this commit isn't finished yet, I don't find a better way to register pause&resume event in AudioEngine module. [9e42ea3] Interleave mono audio to stereo audio. PcmAudioPlayerPool only contains PcmAudioPlayers with 2 channels. [3f18d05] Adds a strategy for checking small size of different file formats. [753ff49] Adds performance test for AudioEngine. [09d3045] Releases an extra PcmAudioPlayer for UrlAudioPlayer while allocating PcmAudioPlayer fails. [9dd4477] Using std::move for PcmData move constructor & move assignment. [6ca3bcb] some fixes: 1) new -> new (std::nothrow) 2) break if allocate PcmAudioPlayer fails 3) renames 'initForPlayPcmData' to 'init' 4) PcmAudioPlayer destructor deadlock if 'init' failed [54675b6] include path fix. [a1903ca] More refactorings. [19b9498] Makes linter.py happy. :) [923c530] Fixes: 1) Avoid getFileInfo to be invoked twice 2) A critical bug fix for UrlAudioPlayer and adds detailed comments 3) __clang__ compiler option fix for AudioResamplerSinc.cpp. [5ec4faf] minor fix. [faaa0f3] output a log in the destructor of UrlAudioPlayer. [9c20355] NewAudioEngineTest,TestControll crash fix. [f114464] fixes an unused import. [1dc5dab] Better algorithm for allocating PcmAudioPlayer. [331a213] minor fix. [e54084a] null -> nullptr [f9a0389] Support uncache. [89a364f] Removes unused update, and TODO uncache functionality. [1732bf9] Supports AudioEngineImpl::setFinishCallback for android. [43d1596] UrlAudioPlayer::stop fix. [e2ee941] Test case fix in NewAudioEngineTest/AudioIssue11143Test [5c5ba01] More fixes for making cpp-tests/New Audio Engine Test happy. [8b554a3] Adds log while remove player from map. [ed71322] If original file is larger than 30k bytes, consider it's a large audio file. [fb1845a] Updates project.properties [6f3839f] minor log output fix in AudioEngine-inl.cpp [c68bc6c] Don't resample if the sample rate of the decoded pcm data matchs the device's. [43ca45f] PcmAudioPlayers also need to be removed while they play over, but should not be deleted since their lifecycle is managed by PcmAudioPlayerPool. [f5e63c9] Audio latency fix for Android. Support preload effects on Android now. * Supports to loading audio files asynchronously. * Crash fix for stop audio right after play2d. * Minor fix for logic in AudioMixerController.cpp * Adds missing files (CCThreadPool.h/.cpp). * Minor fix for including. * Minor fix for missing include <functional> in Track.h * update license information in audio.h * Don't use std::future/std::promise anymore since ndk counldn't support it well in armeabi arch. * isSmallFile postion updated, fixes large audio file goto the checking logic of cache. * std::atomic<int> isn't supported by ndk-r10e while compiling with `armeabi` arch, using a int with a mutex instead. * fixes __isnanf & posix_memalign doesn't exist on low api (<=16) devices. * namespace updated: cocos2d -> cocos2d::experimental * Removes commented code in AudioMixerController.h/.cpp * Removes unused code again, and fixes a memory leak of `Track` instance. * Oops, namespace changed. * Only outputs log in debug mode. * Uses ALOGV for outputing logs in AudioEngine-inl.cpp * const PcmData& -> PcmData for Track * Fixes a protential crash in NewAudioEngineTest * Adds `COCOS` prefix in header #ifndef COCOS_BALABALA #define COCOS_BALABALA * Uses _ prefix for cocos code style instead of `m` prefix. * Deletes AudioResamplerSinc related files. * Bug fix from @minggo's reply on github. * Don't need to invoke pause after in UrlAudioPlayer::prepare. * Updates ThreadPool class, uses enum class and adds const keyword.
2016-07-18 10:22:40 +08:00
char key[100] = {0};
sprintf(key, "play another sound %d", audioId);
2015-08-07 16:50:54 +08:00
button->scheduleOnce([audioId](float dt){
AudioEngine::stop(audioId);
AudioEngine::play2d("audio/SoundEffectsFX009/FX083.mp3");
[big refactoring] Audio latency fix for Android. Support to preload effects on Android now. (#15875) * Audio latency fix for Android. Support preload effects on Android now. Squashed commits: [b6d80fe] log fix [a0a918e] Fixes assetFd didn't be released while PcmData is returned from cache. [4b956ba] Potential crash fix for PcmAudioPlayer while pause / resume. [398ab8c] Updates LOG_TAG position in AudioEngine-inl.cpp [e3634e7] include stdlib.h for posix_memalign [9004074] fixes setVolume logical error. [c96df46] Don't use another thread for mixing, enqueue is in a seperated thread, therefore doing mixing in another thread will waste more time. [0a4c1a8] Adds setLoop, setVolume, setPostion support for Track [c35fb20] Fixed include. [cdd9d32] Do mixing by ourself. (TO BE POLISHED) [6447025] µ -> u since µ could not be shown on some android devices. [97be0c6] Don't send a silence clip. [c1607ed] Make linter.py happy. [0898b54] Puts enqueue & SetPlayState in PcmAudioPlayer::play to thread pool. [b79fc01] Adds getDuration, getPosition support for PcmAudioPlayer [80fa2ab] minor fix of the code position of resetting state to State::INITIALIZED [d9c62f1] underrun fix for PcmAudioPlayer. [9c2212a] UrlAudioPlayer, playOverMutex should be static, and should be used in update method. [1519d2e] static variables [19da936] _pcmAudioPlayer Null pointer check in AudioPlayerProvider. [e6b0d14] Updates audio performance test. [fc01dd4] Registers foreground & background event in AudioEngine-inl.cpp(android), the callback should invoke `provider`'s pause & resume method. [e00a886] TBD: Pause & resume support for PcmAudioPlayerPool. Since OpenSLES audio resources are expensive and device shared, we should delete all unused PcmAudioPlayers in pool while pause and re-create them while resume. But this commit isn't finished yet, I don't find a better way to register pause&resume event in AudioEngine module. [9e42ea3] Interleave mono audio to stereo audio. PcmAudioPlayerPool only contains PcmAudioPlayers with 2 channels. [3f18d05] Adds a strategy for checking small size of different file formats. [753ff49] Adds performance test for AudioEngine. [09d3045] Releases an extra PcmAudioPlayer for UrlAudioPlayer while allocating PcmAudioPlayer fails. [9dd4477] Using std::move for PcmData move constructor & move assignment. [6ca3bcb] some fixes: 1) new -> new (std::nothrow) 2) break if allocate PcmAudioPlayer fails 3) renames 'initForPlayPcmData' to 'init' 4) PcmAudioPlayer destructor deadlock if 'init' failed [54675b6] include path fix. [a1903ca] More refactorings. [19b9498] Makes linter.py happy. :) [923c530] Fixes: 1) Avoid getFileInfo to be invoked twice 2) A critical bug fix for UrlAudioPlayer and adds detailed comments 3) __clang__ compiler option fix for AudioResamplerSinc.cpp. [5ec4faf] minor fix. [faaa0f3] output a log in the destructor of UrlAudioPlayer. [9c20355] NewAudioEngineTest,TestControll crash fix. [f114464] fixes an unused import. [1dc5dab] Better algorithm for allocating PcmAudioPlayer. [331a213] minor fix. [e54084a] null -> nullptr [f9a0389] Support uncache. [89a364f] Removes unused update, and TODO uncache functionality. [1732bf9] Supports AudioEngineImpl::setFinishCallback for android. [43d1596] UrlAudioPlayer::stop fix. [e2ee941] Test case fix in NewAudioEngineTest/AudioIssue11143Test [5c5ba01] More fixes for making cpp-tests/New Audio Engine Test happy. [8b554a3] Adds log while remove player from map. [ed71322] If original file is larger than 30k bytes, consider it's a large audio file. [fb1845a] Updates project.properties [6f3839f] minor log output fix in AudioEngine-inl.cpp [c68bc6c] Don't resample if the sample rate of the decoded pcm data matchs the device's. [43ca45f] PcmAudioPlayers also need to be removed while they play over, but should not be deleted since their lifecycle is managed by PcmAudioPlayerPool. [f5e63c9] Audio latency fix for Android. Support preload effects on Android now. * Supports to loading audio files asynchronously. * Crash fix for stop audio right after play2d. * Minor fix for logic in AudioMixerController.cpp * Adds missing files (CCThreadPool.h/.cpp). * Minor fix for including. * Minor fix for missing include <functional> in Track.h * update license information in audio.h * Don't use std::future/std::promise anymore since ndk counldn't support it well in armeabi arch. * isSmallFile postion updated, fixes large audio file goto the checking logic of cache. * std::atomic<int> isn't supported by ndk-r10e while compiling with `armeabi` arch, using a int with a mutex instead. * fixes __isnanf & posix_memalign doesn't exist on low api (<=16) devices. * namespace updated: cocos2d -> cocos2d::experimental * Removes commented code in AudioMixerController.h/.cpp * Removes unused code again, and fixes a memory leak of `Track` instance. * Oops, namespace changed. * Only outputs log in debug mode. * Uses ALOGV for outputing logs in AudioEngine-inl.cpp * const PcmData& -> PcmData for Track * Fixes a protential crash in NewAudioEngineTest * Adds `COCOS` prefix in header #ifndef COCOS_BALABALA #define COCOS_BALABALA * Uses _ prefix for cocos code style instead of `m` prefix. * Deletes AudioResamplerSinc related files. * Bug fix from @minggo's reply on github. * Don't need to invoke pause after in UrlAudioPlayer::prepare. * Updates ThreadPool class, uses enum class and adds const keyword.
2016-07-18 10:22:40 +08:00
}, 0.3f, key);
2015-08-07 16:50:54 +08:00
});
playItem->setPosition(layerSize.width * 0.5f, layerSize.height * 0.5f);
addChild(playItem);
return true;
}
return false;
}
std::string AudioIssue11143Test::title() const
{
return "Test for issue 11143";
}
std::string AudioIssue11143Test::subtitle() const
{
return "2 seconds after first sound play,you should hear another sound.";
}
[big refactoring] Audio latency fix for Android. Support to preload effects on Android now. (#15875) * Audio latency fix for Android. Support preload effects on Android now. Squashed commits: [b6d80fe] log fix [a0a918e] Fixes assetFd didn't be released while PcmData is returned from cache. [4b956ba] Potential crash fix for PcmAudioPlayer while pause / resume. [398ab8c] Updates LOG_TAG position in AudioEngine-inl.cpp [e3634e7] include stdlib.h for posix_memalign [9004074] fixes setVolume logical error. [c96df46] Don't use another thread for mixing, enqueue is in a seperated thread, therefore doing mixing in another thread will waste more time. [0a4c1a8] Adds setLoop, setVolume, setPostion support for Track [c35fb20] Fixed include. [cdd9d32] Do mixing by ourself. (TO BE POLISHED) [6447025] µ -> u since µ could not be shown on some android devices. [97be0c6] Don't send a silence clip. [c1607ed] Make linter.py happy. [0898b54] Puts enqueue & SetPlayState in PcmAudioPlayer::play to thread pool. [b79fc01] Adds getDuration, getPosition support for PcmAudioPlayer [80fa2ab] minor fix of the code position of resetting state to State::INITIALIZED [d9c62f1] underrun fix for PcmAudioPlayer. [9c2212a] UrlAudioPlayer, playOverMutex should be static, and should be used in update method. [1519d2e] static variables [19da936] _pcmAudioPlayer Null pointer check in AudioPlayerProvider. [e6b0d14] Updates audio performance test. [fc01dd4] Registers foreground & background event in AudioEngine-inl.cpp(android), the callback should invoke `provider`'s pause & resume method. [e00a886] TBD: Pause & resume support for PcmAudioPlayerPool. Since OpenSLES audio resources are expensive and device shared, we should delete all unused PcmAudioPlayers in pool while pause and re-create them while resume. But this commit isn't finished yet, I don't find a better way to register pause&resume event in AudioEngine module. [9e42ea3] Interleave mono audio to stereo audio. PcmAudioPlayerPool only contains PcmAudioPlayers with 2 channels. [3f18d05] Adds a strategy for checking small size of different file formats. [753ff49] Adds performance test for AudioEngine. [09d3045] Releases an extra PcmAudioPlayer for UrlAudioPlayer while allocating PcmAudioPlayer fails. [9dd4477] Using std::move for PcmData move constructor & move assignment. [6ca3bcb] some fixes: 1) new -> new (std::nothrow) 2) break if allocate PcmAudioPlayer fails 3) renames 'initForPlayPcmData' to 'init' 4) PcmAudioPlayer destructor deadlock if 'init' failed [54675b6] include path fix. [a1903ca] More refactorings. [19b9498] Makes linter.py happy. :) [923c530] Fixes: 1) Avoid getFileInfo to be invoked twice 2) A critical bug fix for UrlAudioPlayer and adds detailed comments 3) __clang__ compiler option fix for AudioResamplerSinc.cpp. [5ec4faf] minor fix. [faaa0f3] output a log in the destructor of UrlAudioPlayer. [9c20355] NewAudioEngineTest,TestControll crash fix. [f114464] fixes an unused import. [1dc5dab] Better algorithm for allocating PcmAudioPlayer. [331a213] minor fix. [e54084a] null -> nullptr [f9a0389] Support uncache. [89a364f] Removes unused update, and TODO uncache functionality. [1732bf9] Supports AudioEngineImpl::setFinishCallback for android. [43d1596] UrlAudioPlayer::stop fix. [e2ee941] Test case fix in NewAudioEngineTest/AudioIssue11143Test [5c5ba01] More fixes for making cpp-tests/New Audio Engine Test happy. [8b554a3] Adds log while remove player from map. [ed71322] If original file is larger than 30k bytes, consider it's a large audio file. [fb1845a] Updates project.properties [6f3839f] minor log output fix in AudioEngine-inl.cpp [c68bc6c] Don't resample if the sample rate of the decoded pcm data matchs the device's. [43ca45f] PcmAudioPlayers also need to be removed while they play over, but should not be deleted since their lifecycle is managed by PcmAudioPlayerPool. [f5e63c9] Audio latency fix for Android. Support preload effects on Android now. * Supports to loading audio files asynchronously. * Crash fix for stop audio right after play2d. * Minor fix for logic in AudioMixerController.cpp * Adds missing files (CCThreadPool.h/.cpp). * Minor fix for including. * Minor fix for missing include <functional> in Track.h * update license information in audio.h * Don't use std::future/std::promise anymore since ndk counldn't support it well in armeabi arch. * isSmallFile postion updated, fixes large audio file goto the checking logic of cache. * std::atomic<int> isn't supported by ndk-r10e while compiling with `armeabi` arch, using a int with a mutex instead. * fixes __isnanf & posix_memalign doesn't exist on low api (<=16) devices. * namespace updated: cocos2d -> cocos2d::experimental * Removes commented code in AudioMixerController.h/.cpp * Removes unused code again, and fixes a memory leak of `Track` instance. * Oops, namespace changed. * Only outputs log in debug mode. * Uses ALOGV for outputing logs in AudioEngine-inl.cpp * const PcmData& -> PcmData for Track * Fixes a protential crash in NewAudioEngineTest * Adds `COCOS` prefix in header #ifndef COCOS_BALABALA #define COCOS_BALABALA * Uses _ prefix for cocos code style instead of `m` prefix. * Deletes AudioResamplerSinc related files. * Bug fix from @minggo's reply on github. * Don't need to invoke pause after in UrlAudioPlayer::prepare. * Updates ThreadPool class, uses enum class and adds const keyword.
2016-07-18 10:22:40 +08:00
// Enable profiles for this file
#undef CC_PROFILER_DISPLAY_TIMERS
#define CC_PROFILER_DISPLAY_TIMERS() Profiler::getInstance()->displayTimers()
#undef CC_PROFILER_PURGE_ALL
#define CC_PROFILER_PURGE_ALL() Profiler::getInstance()->releaseAllTimers()
#undef CC_PROFILER_START
#define CC_PROFILER_START(__name__) ProfilingBeginTimingBlock(__name__)
#undef CC_PROFILER_STOP
#define CC_PROFILER_STOP(__name__) ProfilingEndTimingBlock(__name__)
#undef CC_PROFILER_RESET
#define CC_PROFILER_RESET(__name__) ProfilingResetTimingBlock(__name__)
#undef CC_PROFILER_START_CATEGORY
#define CC_PROFILER_START_CATEGORY(__cat__, __name__) do{ if(__cat__) ProfilingBeginTimingBlock(__name__); } while(0)
#undef CC_PROFILER_STOP_CATEGORY
#define CC_PROFILER_STOP_CATEGORY(__cat__, __name__) do{ if(__cat__) ProfilingEndTimingBlock(__name__); } while(0)
#undef CC_PROFILER_RESET_CATEGORY
#define CC_PROFILER_RESET_CATEGORY(__cat__, __name__) do{ if(__cat__) ProfilingResetTimingBlock(__name__); } while(0)
#undef CC_PROFILER_START_INSTANCE
#define CC_PROFILER_START_INSTANCE(__id__, __name__) do{ ProfilingBeginTimingBlock( String::createWithFormat("%08X - %s", __id__, __name__)->getCString() ); } while(0)
#undef CC_PROFILER_STOP_INSTANCE
#define CC_PROFILER_STOP_INSTANCE(__id__, __name__) do{ ProfilingEndTimingBlock( String::createWithFormat("%08X - %s", __id__, __name__)->getCString() ); } while(0)
#undef CC_PROFILER_RESET_INSTANCE
#define CC_PROFILER_RESET_INSTANCE(__id__, __name__) do{ ProfilingResetTimingBlock( String::createWithFormat("%08X - %s", __id__, __name__)->getCString() ); } while(0)
bool AudioPerformanceTest::init()
{
if (AudioEngineTestDemo::init())
{
std::vector<std::string> audioFiles = {
"audio/SoundEffectsFX009/FX081.mp3",
"audio/SoundEffectsFX009/FX082.mp3",
"audio/SoundEffectsFX009/FX083.mp3",
"audio/SoundEffectsFX009/FX084.mp3",
"audio/SoundEffectsFX009/FX085.mp3",
"audio/SoundEffectsFX009/FX086.mp3",
"audio/SoundEffectsFX009/FX087.mp3",
"audio/SoundEffectsFX009/FX088.mp3",
"audio/SoundEffectsFX009/FX089.mp3",
"audio/SoundEffectsFX009/FX090.mp3"
};
for (const auto& audioFile : audioFiles)
{
AudioEngine::preload(audioFile);
}
auto& layerSize = this->getContentSize();
auto playItem = TextButton::create("Start Test", [this, audioFiles](TextButton* button){
button->setEnabled(false);
static_cast<TextButton*>(getChildByName("DisplayButton"))->setEnabled(true);
unschedule("test");
schedule([audioFiles](float dt){
int index = cocos2d::random(0, (int)(audioFiles.size()-1));
CC_PROFILER_START("play2d");
AudioEngine::play2d(audioFiles[index]);
CC_PROFILER_STOP("play2d");
}, 0.25f, "test");
});
playItem->setPosition(layerSize.width * 0.5f, layerSize.height * 2 / 3);
playItem->setName("PlayButton");
addChild(playItem);
auto displayItem = TextButton::create("Display Result", [this, playItem](TextButton* button){
unschedule("test");
AudioEngine::stopAll();
CC_PROFILER_DISPLAY_TIMERS();
playItem->setEnabled(true);
button->setEnabled(false);
});
displayItem->setEnabled(false);
displayItem->setPosition(layerSize.width * 0.5f, layerSize.height / 3);
displayItem->setName("DisplayButton");
addChild(displayItem);
return true;
}
return false;
}
std::string AudioPerformanceTest::title() const
{
return "Test Performance of AudioEngine::play2d, audio is played 1 time per second";
}
std::string AudioPerformanceTest::subtitle() const
{
return "Please see console for the result";
}
/////////////////////////////////////////////////////////////////////////
bool AudioSwitchStateTest::init()
{
if (AudioEngineTestDemo::init())
{
schedule([](float dt){
AudioEngine::uncacheAll();
AudioEngine::preload("audio/SoundEffectsFX009/FX081.mp3");
AudioEngine::play2d("audio/SoundEffectsFX009/FX082.mp3");
AudioEngine::play2d("audio/LuckyDay.mp3");
}, 0.1f, "AudioSwitchStateTest");
return true;
}
return false;
}
std::string AudioSwitchStateTest::title() const
{
return "play, preload, stop switch test";
}
std::string AudioSwitchStateTest::subtitle() const
{
return "Should not crash";
}
2016-07-27 14:00:34 +08:00
/////////////////////////////////////////////////////////////////////////
bool AudioSmallFileTest::init()
{
if (AudioEngineTestDemo::init())
{
AudioEngine::play2d("audio/SmallFile.mp3");
return true;
}
return false;
}
std::string AudioSmallFileTest::title() const
{
return "Playing small mp3 file";
}
std::string AudioSmallFileTest::subtitle() const
{
return "Should not crash";
}
/////////////////////////////////////////////////////////////////////////
void AudioPauseResumeAfterPlay::onEnter()
{
AudioEngineTestDemo::onEnter();
int audioId = AudioEngine::play2d("audio/SoundEffectsFX009/FX082.mp3");
AudioEngine::pause(audioId);
AudioEngine::resume(audioId);
for (int i = 0; i < 10; ++i)
{
AudioEngine::pause(audioId);
AudioEngine::resume(audioId);
}
}
std::string AudioPauseResumeAfterPlay::title() const
{
return "pause & resume right after play2d";
}
std::string AudioPauseResumeAfterPlay::subtitle() const
{
return "Should not crash";
}
/////////////////////////////////////////////////////////////////////////
void AudioPreloadSameFileMultipleTimes::onEnter()
{
AudioEngineTestDemo::onEnter();
for (int i = 0; i < 10; ++i)
{
AudioEngine::preload("audio/SoundEffectsFX009/FX082.mp3", [i](bool isSucceed){
log("111: %d preload %s", i, isSucceed ? "succeed" : "failed");
AudioEngine::preload("audio/SoundEffectsFX009/FX082.mp3", [i](bool isSucceed){
log("222: %d preload %s", i, isSucceed ? "succeed" : "failed");
AudioEngine::preload("audio/SoundEffectsFX009/FX082.mp3", [i](bool isSucceed){
log("333: %d preload %s", i, isSucceed ? "succeed" : "failed");
});
});
});
}
}
std::string AudioPreloadSameFileMultipleTimes::title() const
{
return "Preload same file multiple times";
}
std::string AudioPreloadSameFileMultipleTimes::subtitle() const
{
return "Should not crash";
}