2014-09-03 18:20:31 +08:00
|
|
|
/****************************************************************************
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2014-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2022-04-25 12:06:43 +08:00
|
|
|
Copyright (c) 2021-2022 Bytedance Inc.
|
2014-09-03 18:20:31 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
https://axys1.github.io/
|
2014-09-03 18:20:31 +08:00
|
|
|
|
|
|
|
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"
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
USING_NS_AX;
|
2022-08-08 18:02:17 +08:00
|
|
|
using namespace axys::ui;
|
2014-09-03 18:20:31 +08:00
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
AudioEngineTests::AudioEngineTests()
|
2014-09-03 18:20:31 +08:00
|
|
|
{
|
2015-04-03 14:31:03 +08:00
|
|
|
ADD_TEST_CASE(AudioControlTest);
|
2020-08-01 19:25:39 +08:00
|
|
|
ADD_TEST_CASE(AudioWavTest);
|
2015-08-07 16:50:54 +08:00
|
|
|
ADD_TEST_CASE(AudioLoadTest);
|
2015-04-03 14:31:03 +08:00
|
|
|
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);
|
2016-07-27 14:00:34 +08:00
|
|
|
ADD_TEST_CASE(AudioSmallFileTest);
|
2016-12-15 09:58:47 +08:00
|
|
|
ADD_TEST_CASE(AudioSmallFile2Test);
|
2017-03-15 16:46:19 +08:00
|
|
|
ADD_TEST_CASE(AudioSmallFile3Test);
|
2016-08-22 09:43:06 +08:00
|
|
|
ADD_TEST_CASE(AudioPauseResumeAfterPlay);
|
2016-09-01 11:46:27 +08:00
|
|
|
ADD_TEST_CASE(AudioPreloadSameFileMultipleTimes);
|
2016-09-01 16:06:29 +08:00
|
|
|
ADD_TEST_CASE(AudioPlayFileInWritablePath);
|
2016-12-02 13:52:37 +08:00
|
|
|
ADD_TEST_CASE(AudioIssue16938Test);
|
2017-03-27 17:28:39 +08:00
|
|
|
ADD_TEST_CASE(AudioPlayInFinishedCB);
|
2017-04-10 10:14:06 +08:00
|
|
|
ADD_TEST_CASE(AudioUncacheInFinishedCB);
|
metal support for cocos2d-x (#19305)
* remove deprecated files
* remove some deprecated codes
* remove more deprecated codes
* remove ui deprecated codes
* remove more deprecated codes
* remove deprecated codes in ccmenuitem
* remove more deprecated codes in ui
* remove more deprecated codes in ui
* remove more deprecated codes in ui
* remove more deprecated codes
* remove more deprecated codes
* remove more deprecated codes
* remove vr related codes and ignore some modules
* remove allocator
* remove some config
* 【Feature】add back-end project file
* [Feature] add back-end file
* add pipeline descriptor and shader cache
* [Feature] support sprite for backend
* [Feature] remove unneeded code
* [Feature] according to es2.0 spec, you must use clamp-to-edge as texture wrap mode, and no mipmapping for non-power-of-two texture
* [Feature] set texture wrap mode to clamp-to-edge, and no mipmapping for non-power-of-two texture
* [Feature] remove macro define to .cpp file
* [Feature] add log info
* [Feature] add PipelineDescriptor for TriangleCommand
* [Feature] add PipelineDescriptor object as member of TriangleCommand
* [Feature] add getPipelineDescriptor method
* add renderbackend
* complete pipeline descriptor
* [Feature] add viewport in RenderCommand
* set viewport when rendrering
* [Feature] occur error when using RendererBackend, to be fixed.
* a workaround to fix black screen on macOS 10.14 (#19090)
* add rendererbackend init function
* fix typo
* [Feature] modify testFile
* [BugFix] modify shader path
* [Feature] set default viewport
* fix projection
* [Feature] modify log info
* [BugFix] change viewport data type to int
* [BugFix] add BindGroup to PipelienDescriptor
* [BugFix] change a_position to vec3 in sprite.vert
* [BugFix] set vertexLayout according to V3F_C4B_T2F structure
* [Feature] revert a_position to vec4
* [Feature] renderer should not use gl codes directly
* [Feature] it's better not use default value parameter
* fix depth test setting
* rendererbackend -> renderer
* clear color and depth at begin
* add metal backend
* metal support normalized attribute
* simplify codes
* update external
* add render pass desctriptor in pipeline descriptor
* fix warnings
* fix crash and memeory leak
* refactor Texture2D
* put pipeline descriptor into render command
* simplify codes
* [Feature] update Sprite
* fix crash when closing app
* [Feature] update SpriteBatchNode and TextureAtlas
* support render texture(not finish)
* [Feature] remove unused code
* make tests work on mac
* fix download-deps path error
* make tests work on iOS
* [Feature] support ttf under normal label effect
* refactor triangle command processing
* let renderer handle more common commands
* refactor backend
* make render texture work
* [Feature] refactor backend for GL
* [Feature]Renaming to make it easy to understand
* [Feature] change warp mode to CLAMP_TO_EDGE
* fix ghost
* simplify visit render queue logic
* support progress timer without rial mode
* support partcile system
* Feature/update label (#149)
* [BugFix] fix compile error
* [Feature] support outline effect in ios
* [Feature] add shader file
* [BugFix] fix begin and end RenderPass
* [Feature] update CustomCommand
* [Feature] revert project.pbxproj
* [Feature] simplify codes
* [BugFix] pack AI88 to RGBA8888 only when outline enable
* [Feature] support shadow effect in Label
* [Feature] support BMFont
* [Feature] support glow effect
* [Feature] simplify shader files
* LabelAtlas work
* handle blend function correctly
* support tile map
* don't share buffer in metal
* alloc buffer size as needed
* support more tilemap
* Merge branch 'minggo/metal-support' into feature/updateLabel
* minggo/metal-support:
support tile map
handle blend function correctly
LabelAtlas work
Feature/update label (#149)
support partcile system
# Conflicts:
# cocos/2d/CCLabel.cpp
# cocos/2d/CCSprite.cpp
# cocos/2d/CCSpriteBatchNode.cpp
# cocos/renderer/CCQuadCommand.cpp
# cocos/renderer/CCQuadCommand.h
* render texture work without saving file
* use global viewport
* grid3d works
* remove grabber
* tiled3d works
* [BugFix] fix label bug
* [Feature] add updateSubData for buffer
* [Feature] remove setVertexCount
* support depth test
* add callback command
* [Feature] add UITest
* [Feature] update UITest
* [Feature] remove unneeded codes
* fix custom command issue
* fix layer color blend issue
* [BugFix] fix iOS compile error
* [Feature] remove unneeded codes
* [Feature] fix updateVertexBuffer
* layerradial works
* add draw test back
* fix batch issue
* fix compiling error
* [BugFix] support ETC1
* [BugFix] get the correct pipelineDescriptor
* [BugFix] skip draw when backendTexture nullptr
* clipping node support
* [Feature] add shader files
* fix stencil issue in metal
* [Feature] update UILayoutTest
* [BugFix] skip drawing when vertexCount is zero
* refactor renderer
* add set global z order for stencil manager commands
* fix warnings caused by type
* remove viewport in render command
* [Feature] fix warnings caused by type
* [BugFix] clear vertexCount and indexCount for CustomComand when needed
* [Feature] update clear for CustomCommand
* ios use metal
* fix viewport issue
* fix LayerColorGradient crash
* [cmake] transport to android and windows (#160)
* save point 1
* compile on windows
* run on android
* revert useless change
* android set CC_ENABLE_CACHE_TEXTURE_DATA to 1
* add initGlew
* fix android crash
* add TODO new-renderer
* review update
* revert onGLFWWindowPosCallback
* fix android compiling error
* Impl progress radial (#162)
* progresstimer add radial impl
* default drawType to element
* dec invoke times of createVertexBuffer (#163)
* support depth/stencil format for gl backend
* simplify progress timer codes
* support motionstreak, effect is wrong
* fix motionstreak issue
* [Feature] update Scissor Test (#161)
* [Feature] update Scissor Test
* [Feature] update ScissorTest
* [Feature] rename function
* [Feature] get constant reference if needed
* [Feature] show render status (#164)
* improve performance
* fix depth state
* fill error that triangle vertex/index number bigger than buffer
* fix compiline error in release mode
* fix buffer conflict between CPU and GPU on iOS/macOS
* Renderer refactor (#165)
* use one vertes/index buffer with opengl
* fix error on windows
* custom command support index format config
* CCLayer: compact vertex data structure
* update comment
* fix doc
* support fast tilemap
* pass index format instead
* fix some wrong effect
* fix render texture error
* fix texture per-element size
* fix texture format error
* BlendFunc type refactor, GLenum -> backend::BlendFactor (#167)
* BlendFunc use backend::BlendFactor as inner field
* update comments
* use int to replace GLenum
* update xcode project fiel
* rename to GLBlendConst
* add ccConstants.h
* update xcode project file
* update copyright
* remove primitive command
* remove CCPrimitive.cpp/.h
* remove deprecated files
* remove unneeded files
* remove multiple view support
* remove multiple view support
* remove the usage of frame buffer in camera
* director don't use frame buffer
* remove FrameBuffer
* remove BatchCommand
* add some api reference
* add physics2d back
* fix crash when close app on mac
* improve render texture
* fix rendertexture issue
* fix rendertexture issue
* simplify codes
* CMake support for mac & ios (#169)
* update cmake
* fix compile error
* update 3rd libs version
* remove CCThread.h/.cpp
* remove ccthread
* use audio engine to implement simple audio engine
* remove unneeded codes
* remove deprecated codes
* remove winrt macro
* remove CC_USE_WIC
* set partcile blend function in more elegant way
* remove unneeded codes
* remove unneeded codes
* cmake works on windows
* update project setting
* improve performance
* GLFloat -> float
* sync v3 cmake improvements into metal-support (#172)
* pick: modern cmake, compile definitions improvement (#19139)
* modern cmake, use target_compile_definitions partly
* simplify macro define, remove USE_*
* modern cmake, macro define
* add physics 2d macro define into ccConfig.h
* remove USE_CHIPMUNK macro in build.gradle
* remove CocosSelectModule.cmake
* shrink useless define
* simplify compile options config, re-add if necessary
* update external for tmp CI test
* un-quote target_compile_options value
* add "-g" parameter only when debug mode
* keep single build type when generator Xcode & VS projecy
* update external for tmp CI tes
* add static_cast<char>(-1), fix -Wc++11-narrowing
* simplify win32 compile define
* not modify code, only improve compile options
# Conflicts:
# .gitignore
# cmake/Modules/CocosConfigDepend.cmake
# cocos/CMakeLists.txt
# external/config.json
# tests/cpp-tests/CMakeLists.txt
* modern cmake, improve cmake_compiler_flags (#19145)
* cmake_compiler_flags
* Fix typo
* Fix typo2
* Remove chanages from Android.mk
* correct lua template cmake build (#19149)
* don't add -Wno-deprecated into jsb target
* correct lua template cmake build
* fix win32 lua template compile error
* prevent cmake in-source-build friendly (#19151)
* pick: Copy resources to "Resources/" on win32 like in linux configuration
* add "/Z7" for cpp-tests on windows
* [cmake] fix iOS xcode property setting failed (#19208)
* fix iOS xcode property setting failed
* use search_depend_libs_recursive at dlls collect
* fix typo
* [cmake] add find_host_library into iOS toolchain file (#19230)
* pick: [lua android] use luajit & template cmake update (#19239)
* increase cmake stability , remove tests/CMakeLists.txt (#19261)
* cmake win32 Precompiled header (#19273)
* Precompiled header
* Fix
* Precompiled header for cocos
* Precompiled header jscocos2d
* Fix for COCOS2D_DEBUG is always 1 on Android (#19291)
Related #19289
* little build fix, tests cpp-tests works on mac
* sync v3 build related codes into metal-support (#173)
* strict initialization for std::array
* remove proj.win32 project configs
* modern cmake, cmake_cleanup_remove_unused_variables (#19146)
* Switch travis CI to xenial (#19207)
* Switch travis CI to xenial
* Remove language: android
* Set language: cpp
* Fix java problem
* Update sdkmanager
* Fix sdkmanger
* next sdkmanager fix
* Remove xenial from android
* revert to sdk-tools-{system}-3859397
* Remove linux cmake install
* Update before-install.sh
* Update .travis.yml
* Simplify install-deps-linux.sh, tested on Ubuntu 16.04 (#19212)
* Simplify install-deps-linux.sh
* Cleanup
* pick: install ninja
* update cocos2d-console submodule
* for metal-support alpha release, we only test cpp
* add HelloCpp into project(Cocos2d-x) for tmp test
* update extenal metal-support-4
* update uniform setting
* [Feature] update BindGroup
* [Feature] empty-test
* [Feature] cpp-test
* [Feature] fix GL compiler error
* [Feature] fix GL crash
* [Feature] empty-test
* [Feature] cpp-tests
* [feature] improve frameRate
* [feature] fix opengl compile error
* [feature] fix opengl compile error
* [BugFix] fix compute maxLocation error
* [Feature] update setting unifrom
* [Feature] fix namespace
* [Feature] remove unneeded code
* [Bugfix] fix project file
* [Feature] update review
* [texture2d] impl texture format support (#175)
* texture update
* update
* update texture
* commit
* compile on windows
* ddd
* rename
* rename methods
* no crash
* save gl
* save
* save
* rename
* move out pixel format convert functions
* metal crash
* update
* update android
* support gles compressed texture format
* support more compress format
* add more conversion methods
* ss
* save
* update conversion methods
* add PVRTC format support
* reformat
* add marco linux
* fix GL marcro
* pvrtc supported only by ios 8.0+
* remove unused cmake
* revert change
* refactor Texture2D::initWithData
* fix conversion log
* refactor Texture2D::initWithData
* remove some OpenGL constants for PVRTC
* add todo
* fix typo
* AutoTest works on mac/iOS by disable part cases, sync v3 bug fix (#174)
* review cpp-tests, and fix part issues on start auto test
* sync png format fix: Node:Particle3D abnormal texture effects #19204
* fix cpp-tests SpritePolygon crash, wrong png format (#19170)
* fix wrong png convert format from sRGB to Gray
* erase plist index if all frames was erased
* test_A8.png have I8 format, fix it
* [CCSpriteCache] allow re-add plist & add testcase (#19175)
* allow re-add plist & add testcase
* remove comments/rename method/update testcase
* fix isSpriteFramesWithFileLoaded & add testcase
* remove used variable
* remove unused variable
* fix double free issues when js/lua-tests exit on iOS (#19236)
* disable part cases, AutoTest works without crash on mac
* update cocos2dx files json, to test cocos new next
* fix spritecache plist parsing issue (#19269)
* [linux] Fix FileUtils::getContents with folder (#19157)
* fix FileUtils::getContents on linux/mac
* use stat.st_mode
* simplify
* [CCFileUtils] win32 getFileSize (#19176)
* win32 getFileSize
* fix stat
* [cpp test-Android]20:FileUtils/2 change title (#19197)
* sync #19200
* sync #19231
* [android lua] improve performance of lua loader (#19234)
* [lua] improve performance of lua loader
* remove cache fix
* Revert "fix spritecache plist parsing issue (#19269)"
This reverts commit f3a85ece4307a7b90816c34489d1ed2c8fd11baf.
* remove win32 project files ref in template.json
* add metal framework lnk ref into cpp template
* test on iOS, and disable part cases
* alBufferData instead of alBufferDataStatic for small audio file on Apple (#19227)
* changes AudioCache to use alBufferData instead of alBufferDataStatic
(also makes test 19 faster to trigger openal bugs faster)
The original problem: CrashIfClientProvidedBogusAudioBufferList
https://github.com/cocos2d/cocos2d-x/issues/18948
is not happening anymore, but there's still a not very frequent issue
that makes OpenAL crash with a call stack like this.
AudioCache::readDataTask > alBufferData > CleanUpDeadBufferList
It happes more frequently when the device is "cold", which means after
half an hour of not using the device (locked).
I could not find the actual source code for iOS OpenAL, so I used the
macOS versions:
https://opensource.apple.com/source/OpenAL/OpenAL-48.7/Source/OpenAL/oalImp.cpp.auto.html
They seem to use CAGuard.h to make sure the dead buffer list
has no threading issues. I'm worried because the CAGuard code I found
has macos and win32 define but no iOS, so I'm not sure. I guess the
iOS version is different and has the guard.
I could not find a place in the code that's unprotected by the locks
except the InitializeBufferMap() which should not be called more than
once from cocos, and there's a workaround in AudioEngine-impl for it.
I reduced the occurence of the CleanUpDeadBufferList crash by moving
the guard in ~AudioCache to cover the alDeleteBuffers call.
* remove hack method "setTimeout" on audio
* AutoTest works on iOS
* support set ios deployment target for root project
* enable all texture2d cases, since Jiang have fixed
* add CCTextureUtils to xcode project file (#176)
* add leak cases for SpriteFrameCache (#177)
* re-add SpriteFrameCache cases
* update template file json
* Update SpriteFrameCacheTest.cpp
* fix compiling error
2019-01-18 15:08:25 +08:00
|
|
|
|
|
|
|
ADD_TEST_CASE(AudioIssue18597Test);
|
|
|
|
ADD_TEST_CASE(AudioIssue11143Test);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
// FIXME: Please keep AudioSwitchStateTest to the last position since this test case doesn't work well on each
|
|
|
|
// platforms.
|
2016-09-01 16:06:29 +08:00
|
|
|
ADD_TEST_CASE(AudioSwitchStateTest);
|
2014-09-03 18:20:31 +08:00
|
|
|
}
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
class TextButton : public axis::Label
|
2021-12-28 16:06:23 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
static TextButton* create(std::string_view text, const std::function<void(TextButton*)>& onTriggered)
|
2014-09-03 18:20:31 +08:00
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
auto ret = new TextButton();
|
|
|
|
|
|
|
|
TTFConfig ttfconfig("fonts/arial.ttf", 25);
|
|
|
|
if (ret->setTTFConfig(ttfconfig))
|
2014-09-03 18:20:31 +08:00
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
ret->setString(text);
|
|
|
|
ret->_onTriggered = onTriggered;
|
|
|
|
|
|
|
|
ret->autorelease();
|
|
|
|
|
|
|
|
return ret;
|
2014-09-03 18:20:31 +08:00
|
|
|
}
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
delete ret;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setEnabled(bool enabled)
|
|
|
|
{
|
|
|
|
_enabled = enabled;
|
|
|
|
if (_enabled)
|
2014-09-03 18:20:31 +08:00
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
this->setColor(Color3B::WHITE);
|
2014-09-03 18:20:31 +08:00
|
|
|
}
|
2021-12-28 16:06:23 +08:00
|
|
|
else
|
2014-09-03 18:20:31 +08:00
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
this->setColor(Color3B::GRAY);
|
2014-09-03 18:20:31 +08:00
|
|
|
}
|
2021-12-28 16:06:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
TextButton() : _onTriggered(nullptr), _enabled(true)
|
|
|
|
{
|
|
|
|
auto listener = EventListenerTouchOneByOne::create();
|
|
|
|
listener->setSwallowTouches(true);
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
listener->onTouchBegan = AX_CALLBACK_2(TextButton::onTouchBegan, this);
|
|
|
|
listener->onTouchEnded = AX_CALLBACK_2(TextButton::onTouchEnded, this);
|
|
|
|
listener->onTouchCancelled = AX_CALLBACK_2(TextButton::onTouchCancelled, this);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
_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)
|
2014-09-03 18:20:31 +08:00
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
return true;
|
2014-09-03 18:20:31 +08:00
|
|
|
}
|
2021-12-28 16:06:23 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool onTouchBegan(Touch* touch, Event* event)
|
|
|
|
{
|
|
|
|
auto hits = touchHits(touch);
|
|
|
|
if (hits)
|
2014-09-03 18:20:31 +08:00
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
scaleButtonTo(0.95f);
|
2014-09-03 18:20:31 +08:00
|
|
|
}
|
2021-12-28 16:06:23 +08:00
|
|
|
return hits;
|
|
|
|
}
|
|
|
|
|
|
|
|
void onTouchEnded(Touch* touch, Event* event)
|
|
|
|
{
|
|
|
|
if (_enabled)
|
2014-09-03 18:20:31 +08:00
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
auto hits = touchHits(touch);
|
|
|
|
if (hits && _onTriggered)
|
|
|
|
{
|
|
|
|
_onTriggered(this);
|
2014-09-03 18:20:31 +08:00
|
|
|
}
|
|
|
|
}
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
scaleButtonTo(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void onTouchCancelled(Touch* touch, Event* event) { scaleButtonTo(1); }
|
|
|
|
|
|
|
|
void scaleButtonTo(float scale)
|
2014-09-03 18:20:31 +08:00
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
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
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static SliderEx* create()
|
|
|
|
{
|
|
|
|
auto ret = new SliderEx();
|
|
|
|
if (ret->init())
|
|
|
|
{
|
|
|
|
ret->loadBarTexture("cocosui/sliderTrack.png");
|
|
|
|
ret->loadSlidBallTextures("cocosui/sliderThumb.png", "cocosui/sliderThumb.png", "");
|
|
|
|
ret->loadProgressBarTexture("cocosui/sliderProgress.png");
|
|
|
|
ret->setTouchEnabled(true);
|
|
|
|
|
|
|
|
ret->autorelease();
|
|
|
|
|
2014-09-03 18:20:31 +08:00
|
|
|
return ret;
|
|
|
|
}
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_SAFE_DELETE(ret);
|
2021-12-28 16:06:23 +08:00
|
|
|
return ret;
|
|
|
|
}
|
2014-09-03 18:20:31 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void setRatio(float ratio)
|
|
|
|
{
|
|
|
|
ratio = clampf(ratio, 0.0f, 1.0f);
|
|
|
|
|
|
|
|
_ratio = ratio;
|
|
|
|
setPercent(100 * _ratio);
|
|
|
|
}
|
|
|
|
|
|
|
|
float getRatio()
|
|
|
|
{
|
|
|
|
_ratio = 1.0f * _percent / _maxPercent;
|
|
|
|
return _ratio;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
float _ratio;
|
|
|
|
};
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
AudioEngineTestDemo::AudioEngineTestDemo() : _isDestroyed(std::make_shared<bool>(false)) {}
|
[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
|
|
|
|
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;
|
2016-09-01 11:46:27 +08:00
|
|
|
AudioEngine::uncacheAll();
|
2015-04-03 14:31:03 +08:00
|
|
|
TestCase::onExit();
|
2014-09-03 18:20:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string AudioEngineTestDemo::title() const
|
|
|
|
{
|
|
|
|
return "New Audio Engine Test";
|
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
void AudioEngineTestDemo::onBackCallback(axis::Ref* sender)
|
2017-04-13 17:58:49 +08:00
|
|
|
{
|
|
|
|
AudioEngine::end();
|
|
|
|
TestCase::onBackCallback(sender);
|
|
|
|
}
|
|
|
|
|
2014-09-03 18:20:31 +08:00
|
|
|
// AudioControlTest
|
|
|
|
bool AudioControlTest::init()
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
auto ret = AudioEngineTestDemo::init();
|
|
|
|
_audioID = AudioEngine::INVALID_AUDIO_ID;
|
|
|
|
_loopEnabled = false;
|
|
|
|
_volume = 1.0f;
|
|
|
|
_duration = AudioEngine::TIME_UNKNOWN;
|
|
|
|
_timeRatio = 0.0f;
|
2014-09-03 18:20:31 +08:00
|
|
|
_updateTimeSlider = true;
|
2021-12-28 16:06:23 +08:00
|
|
|
_isStopped = false;
|
|
|
|
|
2014-09-03 18:20:31 +08:00
|
|
|
std::string fontFilePath = "fonts/arial.ttf";
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-09-03 18:20:31 +08:00
|
|
|
auto& layerSize = this->getContentSize();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2016-09-01 16:06:29 +08:00
|
|
|
_playOverLabel = Label::createWithSystemFont("Play Over", "", 30);
|
2021-12-28 16:06:23 +08:00
|
|
|
_playOverLabel->setPosition(Vec2(layerSize / 2) + Vec2(0, 30));
|
2016-09-01 16:06:29 +08:00
|
|
|
_playOverLabel->setVisible(false);
|
|
|
|
addChild(_playOverLabel, 99999);
|
2021-10-06 11:24:39 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
auto playItem = TextButton::create("play", [&](TextButton* button) {
|
|
|
|
if (_audioID == AudioEngine::INVALID_AUDIO_ID)
|
|
|
|
{
|
2020-08-01 12:55:33 +08:00
|
|
|
_audioID = AudioEngine::play2d("background.mp3", _loopEnabled, _volume);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
if (_audioID != AudioEngine::INVALID_AUDIO_ID)
|
|
|
|
{
|
2016-09-01 16:06:29 +08:00
|
|
|
_isStopped = false;
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-09-03 18:20:31 +08:00
|
|
|
button->setEnabled(false);
|
2021-12-28 16:06:23 +08:00
|
|
|
AudioEngine::setFinishCallback(_audioID, [&](int id, std::string_view filePath) {
|
2016-09-01 16:06:29 +08:00
|
|
|
log("_audioID(%d), _isStopped:(%d), played over!!!", _audioID, _isStopped);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2016-09-01 16:06:29 +08:00
|
|
|
_playOverLabel->setVisible(true);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
scheduleOnce([&](float dt) { _playOverLabel->setVisible(false); }, 2.0f, "hide_play_over_label");
|
|
|
|
|
|
|
|
assert(!_isStopped); // Stop audio should not trigger finished callback
|
2015-01-01 08:51:45 +08:00
|
|
|
_audioID = AudioEngine::INVALID_AUDIO_ID;
|
2014-09-03 18:20:31 +08:00
|
|
|
((TextButton*)_playItem)->setEnabled(true);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-09-03 18:20:31 +08:00
|
|
|
_timeRatio = 0.0f;
|
|
|
|
((SliderEx*)_timeSlider)->setRatio(_timeRatio);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2021-12-28 16:06:23 +08:00
|
|
|
_playItem = playItem;
|
|
|
|
playItem->setPosition(layerSize.width * 0.3f, layerSize.height * 0.8f);
|
2014-09-03 18:20:31 +08:00
|
|
|
addChild(playItem);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
auto stopItem = TextButton::create("stop", [&](TextButton* button) {
|
|
|
|
if (_audioID != AudioEngine::INVALID_AUDIO_ID)
|
|
|
|
{
|
2016-09-01 16:06:29 +08:00
|
|
|
_isStopped = true;
|
2014-09-05 11:13:51 +08:00
|
|
|
AudioEngine::stop(_audioID);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2015-01-01 08:51:45 +08:00
|
|
|
_audioID = AudioEngine::INVALID_AUDIO_ID;
|
2014-09-03 18:20:31 +08:00
|
|
|
((TextButton*)_playItem)->setEnabled(true);
|
|
|
|
}
|
|
|
|
});
|
2021-12-28 16:06:23 +08:00
|
|
|
stopItem->setPosition(layerSize.width * 0.7f, layerSize.height * 0.8f);
|
2014-09-03 18:20:31 +08:00
|
|
|
addChild(stopItem);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
auto pauseItem = TextButton::create("pause", [&](TextButton* button) {
|
|
|
|
if (_audioID != AudioEngine::INVALID_AUDIO_ID)
|
|
|
|
{
|
2014-09-05 11:13:51 +08:00
|
|
|
AudioEngine::pause(_audioID);
|
2014-09-03 18:20:31 +08:00
|
|
|
}
|
|
|
|
});
|
2021-12-28 16:06:23 +08:00
|
|
|
pauseItem->setPosition(layerSize.width * 0.3f, layerSize.height * 0.7f);
|
2014-09-03 18:20:31 +08:00
|
|
|
addChild(pauseItem);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
auto resumeItem = TextButton::create("resume", [&](TextButton* button) {
|
|
|
|
if (_audioID != AudioEngine::INVALID_AUDIO_ID)
|
|
|
|
{
|
2014-09-05 11:13:51 +08:00
|
|
|
AudioEngine::resume(_audioID);
|
2014-09-03 18:20:31 +08:00
|
|
|
}
|
|
|
|
});
|
2021-12-28 16:06:23 +08:00
|
|
|
resumeItem->setPosition(layerSize.width * 0.7f, layerSize.height * 0.7f);
|
2014-09-03 18:20:31 +08:00
|
|
|
addChild(resumeItem);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
auto loopItem = TextButton::create("enable-loop", [&](TextButton* button) {
|
2014-09-03 18:20:31 +08:00
|
|
|
_loopEnabled = !_loopEnabled;
|
2015-07-08 10:48:20 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
if (_audioID != AudioEngine::INVALID_AUDIO_ID)
|
|
|
|
{
|
2014-09-05 11:13:51 +08:00
|
|
|
AudioEngine::setLoop(_audioID, _loopEnabled);
|
2014-09-03 18:20:31 +08:00
|
|
|
}
|
2021-12-28 16:06:23 +08:00
|
|
|
if (_loopEnabled)
|
|
|
|
{
|
2014-09-03 18:20:31 +08:00
|
|
|
button->setString("disable-loop");
|
|
|
|
}
|
2021-12-28 16:06:23 +08:00
|
|
|
else
|
|
|
|
{
|
2014-09-03 18:20:31 +08:00
|
|
|
button->setString("enable-loop");
|
|
|
|
}
|
|
|
|
});
|
2015-07-08 10:48:20 +08:00
|
|
|
loopItem->setPosition(layerSize.width * 0.5f, layerSize.height * 0.5f);
|
2014-09-03 18:20:31 +08:00
|
|
|
addChild(loopItem);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-09-03 18:20:31 +08:00
|
|
|
auto volumeSlider = SliderEx::create();
|
|
|
|
volumeSlider->setPercent(100);
|
2021-12-28 16:06:23 +08:00
|
|
|
volumeSlider->addEventListener([&](Ref* sender, Slider::EventType event) {
|
|
|
|
SliderEx* slider = dynamic_cast<SliderEx*>(sender);
|
|
|
|
_volume = slider->getRatio();
|
|
|
|
if (_audioID != AudioEngine::INVALID_AUDIO_ID)
|
|
|
|
{
|
2014-09-05 11:13:51 +08:00
|
|
|
AudioEngine::setVolume(_audioID, _volume);
|
2014-09-03 18:20:31 +08:00
|
|
|
}
|
|
|
|
});
|
2021-12-28 16:06:23 +08:00
|
|
|
volumeSlider->setPosition(Vec2(layerSize.width * 0.5f, layerSize.height * 0.35f));
|
2014-09-03 18:20:31 +08:00
|
|
|
addChild(volumeSlider);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-09-03 18:20:31 +08:00
|
|
|
auto timeSlider = SliderEx::create();
|
2021-12-28 16:06:23 +08:00
|
|
|
timeSlider->addEventListener([&](Ref* sender, Slider::EventType event) {
|
|
|
|
SliderEx* slider = dynamic_cast<SliderEx*>(sender);
|
|
|
|
switch (event)
|
|
|
|
{
|
|
|
|
case Slider::EventType::ON_SLIDEBALL_DOWN:
|
|
|
|
_updateTimeSlider = false;
|
|
|
|
break;
|
|
|
|
case Slider::EventType::ON_SLIDEBALL_UP:
|
|
|
|
if (_audioID != AudioEngine::INVALID_AUDIO_ID && _duration != AudioEngine::TIME_UNKNOWN)
|
|
|
|
{
|
|
|
|
float ratio = (float)slider->getPercent() / 100;
|
|
|
|
ratio = clampf(ratio, 0.0f, 1.0f);
|
|
|
|
AudioEngine::setCurrentTime(_audioID, _duration * ratio);
|
|
|
|
}
|
|
|
|
case Slider::EventType::ON_SLIDEBALL_CANCEL:
|
|
|
|
_updateTimeSlider = true;
|
|
|
|
case Slider::EventType::ON_PERCENTAGE_CHANGED:
|
|
|
|
default:
|
|
|
|
// ignore
|
|
|
|
break;
|
2014-09-03 18:20:31 +08:00
|
|
|
}
|
|
|
|
});
|
2021-12-28 16:06:23 +08:00
|
|
|
timeSlider->setPosition(Vec2(layerSize.width * 0.5f, layerSize.height * 0.25f));
|
2014-09-03 18:20:31 +08:00
|
|
|
addChild(timeSlider);
|
|
|
|
_timeSlider = timeSlider;
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-09-03 18:20:31 +08:00
|
|
|
auto& volumeSliderPos = volumeSlider->getPosition();
|
2021-12-28 16:06:23 +08:00
|
|
|
auto& sliderSize = volumeSlider->getContentSize();
|
|
|
|
auto volumeLabel = Label::createWithTTF("volume: ", fontFilePath, 20);
|
2014-09-03 18:20:31 +08:00
|
|
|
volumeLabel->setAnchorPoint(Vec2::ANCHOR_MIDDLE_RIGHT);
|
|
|
|
volumeLabel->setPosition(volumeSliderPos.x - sliderSize.width / 2, volumeSliderPos.y);
|
|
|
|
addChild(volumeLabel);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-09-03 18:20:31 +08:00
|
|
|
auto& timeSliderPos = timeSlider->getPosition();
|
2021-12-28 16:06:23 +08:00
|
|
|
auto timeLabel = Label::createWithTTF("time: ", fontFilePath, 20);
|
2014-09-03 18:20:31 +08:00
|
|
|
timeLabel->setAnchorPoint(Vec2::ANCHOR_MIDDLE_RIGHT);
|
|
|
|
timeLabel->setPosition(timeSliderPos.x - sliderSize.width / 2, timeSliderPos.y);
|
|
|
|
addChild(timeLabel);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
this->schedule(AX_CALLBACK_1(AudioControlTest::update, this), 0.1f, "update_key");
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-09-03 18:20:31 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioControlTest::update(float dt)
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
if (_audioID != AudioEngine::INVALID_AUDIO_ID)
|
|
|
|
{
|
|
|
|
if (_duration == AudioEngine::TIME_UNKNOWN)
|
|
|
|
{
|
2014-09-05 11:13:51 +08:00
|
|
|
_duration = AudioEngine::getDuration(_audioID);
|
2014-09-03 18:20:31 +08:00
|
|
|
}
|
2021-12-28 16:06:23 +08:00
|
|
|
if (_duration != AudioEngine::TIME_UNKNOWN)
|
|
|
|
{
|
|
|
|
auto time = AudioEngine::getCurrentTime(_audioID);
|
2014-09-03 18:20:31 +08:00
|
|
|
_timeRatio = time / _duration;
|
2021-12-28 16:06:23 +08:00
|
|
|
if (_updateTimeSlider)
|
|
|
|
{
|
2014-09-03 18:20:31 +08:00
|
|
|
((SliderEx*)_timeSlider)->setRatio(_timeRatio);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
AudioControlTest::~AudioControlTest() {}
|
2014-09-03 18:20:31 +08:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
auto preloadItem = TextButton::create("preload", [&, stateLabel](TextButton* button) {
|
2015-08-07 16:50:54 +08:00
|
|
|
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;
|
2021-12-28 16:06:23 +08:00
|
|
|
AudioEngine::preload("audio/SoundEffectsFX009/FX082.mp3", [isDestroyed, stateLabel](bool isSuccess) {
|
[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
|
|
|
if (*isDestroyed)
|
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("AudioLoadTest scene was destroyed, no need to set the label text.");
|
[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
|
|
|
return;
|
|
|
|
}
|
2021-12-28 16:06:23 +08:00
|
|
|
|
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);
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
auto uncacheItem = TextButton::create("uncache", [&, stateLabel](TextButton* button) {
|
2015-08-07 16:50:54 +08:00
|
|
|
stateLabel->setString("status:uncache");
|
|
|
|
AudioEngine::uncache("audio/SoundEffectsFX009/FX082.mp3");
|
|
|
|
});
|
|
|
|
uncacheItem->setPosition(layerSize.width * 0.65f, layerSize.height * 0.5f);
|
|
|
|
addChild(uncacheItem);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2015-08-07 16:50:54 +08:00
|
|
|
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";
|
|
|
|
}
|
|
|
|
|
2020-08-01 19:25:39 +08:00
|
|
|
// AudioWavTest
|
2021-12-28 16:06:23 +08:00
|
|
|
AudioWavTest::~AudioWavTest() {}
|
2020-08-01 19:25:39 +08:00
|
|
|
|
|
|
|
std::string AudioWavTest::title() const
|
|
|
|
{
|
|
|
|
return "Audio wav test";
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AudioWavTest::init()
|
|
|
|
{
|
|
|
|
if (AudioEngineTestDemo::init())
|
|
|
|
{
|
|
|
|
// list wav files, the wav samples download from wav wiki
|
|
|
|
_wavFiles = FileUtils::getInstance()->listFiles("wav-samples");
|
|
|
|
|
|
|
|
auto& layerSize = this->getContentSize();
|
|
|
|
|
|
|
|
_stateLabel = Label::createWithTTF("wav file:", "fonts/arial.ttf", 30);
|
|
|
|
_stateLabel->setPosition(layerSize.width / 2, layerSize.height * 0.7f);
|
|
|
|
addChild(_stateLabel);
|
|
|
|
|
|
|
|
auto playPrev = TextButton::create("Play Prev", [=](TextButton* button) {
|
2021-12-28 16:06:23 +08:00
|
|
|
if (_curIndex > 0)
|
|
|
|
{
|
2020-08-01 19:25:39 +08:00
|
|
|
AudioEngine::stop(_audioID);
|
|
|
|
_audioID = AudioEngine::play2d(_wavFiles[--_curIndex]);
|
2021-12-28 16:06:23 +08:00
|
|
|
_stateLabel->setString(StringUtils::format("[index: %d] %s", _curIndex,
|
|
|
|
FileUtils::getFileShortName(_wavFiles[_curIndex]).c_str()));
|
2020-08-01 19:25:39 +08:00
|
|
|
}
|
2021-12-28 16:06:23 +08:00
|
|
|
});
|
2020-08-01 19:25:39 +08:00
|
|
|
playPrev->setPosition(layerSize.width * 0.35f, layerSize.height * 0.5f);
|
|
|
|
addChild(playPrev);
|
|
|
|
|
|
|
|
auto playNext = TextButton::create("Play Next", [=](TextButton* button) {
|
2021-12-28 16:06:23 +08:00
|
|
|
if (_curIndex != -1 && _curIndex < (_wavFiles.size() - 1))
|
|
|
|
{
|
2020-08-01 19:25:39 +08:00
|
|
|
AudioEngine::stop(_audioID);
|
|
|
|
_audioID = AudioEngine::play2d(_wavFiles[++_curIndex]);
|
2021-12-28 16:06:23 +08:00
|
|
|
_stateLabel->setString(StringUtils::format("[index: %d] %s", _curIndex,
|
|
|
|
FileUtils::getFileShortName(_wavFiles[_curIndex]).c_str()));
|
2020-08-01 19:25:39 +08:00
|
|
|
}
|
2021-12-28 16:06:23 +08:00
|
|
|
});
|
2020-08-01 19:25:39 +08:00
|
|
|
playNext->setPosition(layerSize.width * 0.65f, layerSize.height * 0.5f);
|
|
|
|
addChild(playNext);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioWavTest::onEnter()
|
|
|
|
{
|
|
|
|
AudioEngineTestDemo::onEnter();
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
if (!_wavFiles.empty())
|
|
|
|
{
|
2020-08-01 19:25:39 +08:00
|
|
|
_curIndex = 0;
|
2021-12-28 16:06:23 +08:00
|
|
|
_audioID = AudioEngine::play2d(_wavFiles[_curIndex]);
|
|
|
|
_stateLabel->setString(StringUtils::format("[index: %d] %s", _curIndex,
|
|
|
|
FileUtils::getFileShortName(_wavFiles[_curIndex]).c_str()));
|
2020-08-01 19:25:39 +08:00
|
|
|
}
|
|
|
|
}
|
2015-08-07 16:50:54 +08:00
|
|
|
|
2014-09-03 18:20:31 +08:00
|
|
|
// PlaySimultaneouslyTest
|
|
|
|
bool PlaySimultaneouslyTest::init()
|
|
|
|
{
|
|
|
|
auto ret = AudioEngineTestDemo::init();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-09-09 10:48:07 +08:00
|
|
|
char text[36];
|
2014-09-03 18:20:31 +08:00
|
|
|
int tmp = 81;
|
2021-12-28 16:06:23 +08:00
|
|
|
for (int index = 0; index < TEST_COUNT; ++index)
|
|
|
|
{
|
|
|
|
sprintf(text, "audio/SoundEffectsFX009/FX0%d.mp3", tmp + index);
|
2014-09-03 18:20:31 +08:00
|
|
|
_files[index] = text;
|
|
|
|
}
|
|
|
|
_playingcount = 0;
|
2021-12-28 16:06:23 +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();
|
2021-12-28 16:06:23 +08:00
|
|
|
for (int index = 0; index < TEST_COUNT; ++index)
|
|
|
|
{
|
2014-09-05 11:13:51 +08:00
|
|
|
audioId = AudioEngine::play2d(_files[index]);
|
2021-12-28 16:06:23 +08:00
|
|
|
if (audioId != AudioEngine::INVALID_AUDIO_ID)
|
|
|
|
{
|
2014-09-03 18:20:31 +08:00
|
|
|
_playingcount += 1;
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
AudioEngine::setFinishCallback(audioId, [&](int id, std::string_view filePath) {
|
2014-09-03 18:20:31 +08:00
|
|
|
_playingcount -= 1;
|
2021-12-28 16:06:23 +08:00
|
|
|
if (_playingcount <= 0)
|
|
|
|
{
|
2014-09-03 18:20:31 +08:00
|
|
|
((TextButton*)_playItem)->setEnabled(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2021-12-28 16:06:23 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
log("%s,%d,Fail to play file:%s", __FILE__, __LINE__, _files[index].c_str());
|
2014-09-03 18:20:31 +08:00
|
|
|
}
|
|
|
|
}
|
2021-12-28 16:06:23 +08:00
|
|
|
log("diff time:%lf", utils::gettime() - startTime);
|
2014-09-03 18:20:31 +08:00
|
|
|
});
|
2021-12-28 16:06:23 +08:00
|
|
|
playItem->setPositionNormalized(Vec2(0.5f, 0.5f));
|
2014-09-03 18:20:31 +08:00
|
|
|
this->addChild(playItem);
|
|
|
|
_playItem = playItem;
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-09-03 18:20:31 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
PlaySimultaneouslyTest::~PlaySimultaneouslyTest() {}
|
2014-09-03 18:20:31 +08:00
|
|
|
|
|
|
|
std::string PlaySimultaneouslyTest::title() const
|
|
|
|
{
|
|
|
|
return "Simultaneously play multiple audio";
|
|
|
|
}
|
|
|
|
|
|
|
|
// AudioProfileTest
|
|
|
|
bool AudioProfileTest::init()
|
|
|
|
{
|
|
|
|
auto ret = AudioEngineTestDemo::init();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-09-03 18:20:31 +08:00
|
|
|
char text[30];
|
|
|
|
_files[0] = "background.mp3";
|
2022-07-15 19:17:01 +08:00
|
|
|
#if AX_TARGET_PLATFORM == AX_PLATFORM_IOS || AX_TARGET_PLATFORM == AX_PLATFORM_MAC
|
2014-09-03 18:20:31 +08:00
|
|
|
_files[1] = "background.caf";
|
|
|
|
#else
|
|
|
|
_files[1] = "background.ogg";
|
|
|
|
#endif
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-09-03 18:20:31 +08:00
|
|
|
std::string fontFilePath = "fonts/arial.ttf";
|
2021-12-28 16:06:23 +08:00
|
|
|
_minDelay = 1.0f;
|
|
|
|
_time = 0.0f;
|
2014-09-05 11:13:51 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
_audioProfile.name = "AudioProfileTest";
|
2014-09-05 11:13:51 +08:00
|
|
|
_audioProfile.maxInstances = 3;
|
2021-12-28 16:06:23 +08:00
|
|
|
_audioProfile.minDelay = 1.0;
|
|
|
|
|
|
|
|
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) {
|
2014-09-03 18:20:31 +08:00
|
|
|
int index = button->getTag();
|
2021-12-28 16:06:23 +08:00
|
|
|
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];
|
2021-12-28 16:06:23 +08:00
|
|
|
sprintf(show, "audio count:%d", _audioCount);
|
2014-09-03 18:20:31 +08:00
|
|
|
_showLabel->setString(show);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
AudioEngine::setFinishCallback(id, [&](int id, std::string_view filePath) {
|
2014-09-03 18:20:31 +08:00
|
|
|
_audioCount -= 1;
|
|
|
|
char show[30];
|
2021-12-28 16:06:23 +08:00
|
|
|
sprintf(show, "audio count:%d", _audioCount);
|
2014-09-03 18:20:31 +08:00
|
|
|
_showLabel->setString(show);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
playItem->setTag(index);
|
2016-10-27 09:45:40 +08:00
|
|
|
playItem->setPositionNormalized(pos);
|
2014-09-03 18:20:31 +08:00
|
|
|
this->addChild(playItem);
|
2014-09-29 10:15:41 +08:00
|
|
|
pos.y -= 0.15f;
|
2014-09-03 18:20:31 +08:00
|
|
|
}
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-09-03 18:20:31 +08:00
|
|
|
Vec2 origin = Director::getInstance()->getVisibleOrigin();
|
2021-12-28 16:06:23 +08:00
|
|
|
Size size = Director::getInstance()->getVisibleSize();
|
|
|
|
|
|
|
|
auto profileInfoLabel =
|
|
|
|
Label::createWithTTF("AudioProfile Info:\n max instance:3 \n minimum delay:1.0", fontFilePath, 12);
|
2014-09-03 18:20:31 +08:00
|
|
|
profileInfoLabel->setAnchorPoint(Vec2::ANCHOR_MIDDLE_LEFT);
|
|
|
|
profileInfoLabel->setPosition(Vec2(origin.x, origin.y + size.height * 0.65f));
|
|
|
|
addChild(profileInfoLabel);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-09-03 18:20:31 +08:00
|
|
|
_audioCount = 0;
|
2021-12-28 16:06:23 +08:00
|
|
|
_showLabel = Label::createWithTTF("audio count:0", fontFilePath, 12);
|
2014-09-03 18:20:31 +08:00
|
|
|
_showLabel->setAnchorPoint(Vec2::ANCHOR_MIDDLE_LEFT);
|
|
|
|
_showLabel->setPosition(Vec2(origin.x, origin.y + size.height * 0.5f));
|
|
|
|
addChild(_showLabel);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-09-03 18:20:31 +08:00
|
|
|
auto timeSlider = SliderEx::create();
|
|
|
|
timeSlider->setEnabled(false);
|
2016-10-27 09:45:40 +08:00
|
|
|
timeSlider->setPositionNormalized(pos);
|
2014-09-03 18:20:31 +08:00
|
|
|
addChild(timeSlider);
|
|
|
|
_timeSlider = timeSlider;
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
this->schedule(AX_CALLBACK_1(AudioProfileTest::update, this), 0.05f, "update_key");
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-09-03 18:20:31 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioProfileTest::update(float dt)
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
if (_time > 0.0f)
|
2014-09-03 18:20:31 +08:00
|
|
|
{
|
|
|
|
_time -= dt;
|
|
|
|
((SliderEx*)_timeSlider)->setRatio(_time / _minDelay);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
AudioProfileTest::~AudioProfileTest() {}
|
2014-09-03 18:20:31 +08:00
|
|
|
|
|
|
|
std::string AudioProfileTest::title() const
|
|
|
|
{
|
|
|
|
return "AudioProfileTest";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string AudioProfileTest::subtitle() const
|
|
|
|
{
|
|
|
|
return "See the console.";
|
|
|
|
}
|
|
|
|
|
|
|
|
// InvalidAudioFileTest
|
|
|
|
bool InvalidAudioFileTest::init()
|
|
|
|
{
|
|
|
|
auto ret = AudioEngineTestDemo::init();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
auto playItem = TextButton::create("play unsupported media type", [&](TextButton* button) {
|
2022-07-15 19:17:01 +08:00
|
|
|
#if AX_TARGET_PLATFORM == AX_PLATFORM_IOS || AX_TARGET_PLATFORM == AX_PLATFORM_MAC
|
2014-09-05 11:13:51 +08:00
|
|
|
AudioEngine::play2d("background.ogg");
|
2022-07-15 19:17:01 +08:00
|
|
|
#elif AX_TARGET_PLATFORM == AX_PLATFORM_ANDROID || AX_TARGET_PLATFORM == AX_PLATFORM_WIN32
|
2021-12-28 16:06:23 +08:00
|
|
|
AudioEngine::play2d("background.caf");
|
2014-09-03 18:20:31 +08:00
|
|
|
#endif
|
|
|
|
});
|
2016-10-27 09:45:40 +08:00
|
|
|
playItem->setPositionNormalized(Vec2(0.5f, 0.6f));
|
2014-09-03 18:20:31 +08:00
|
|
|
this->addChild(playItem);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
auto playItem2 = TextButton::create("play not-existent file",
|
|
|
|
[&](TextButton* button) { AudioEngine::play2d("not-existent file.mp3"); });
|
2016-10-27 09:45:40 +08:00
|
|
|
playItem2->setPositionNormalized(Vec2(0.5f, 0.4f));
|
2014-09-03 18:20:31 +08:00
|
|
|
this->addChild(playItem2);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-09-03 18:20:31 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
InvalidAudioFileTest::~InvalidAudioFileTest() {}
|
2014-09-03 18:20:31 +08:00
|
|
|
|
|
|
|
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();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
auto playItem = TextButton::create("play large audio file",
|
|
|
|
[&](TextButton* button) { AudioEngine::play2d("audio/LuckyDay.mp3"); });
|
2016-10-27 09:45:40 +08:00
|
|
|
playItem->setPositionNormalized(Vec2::ANCHOR_MIDDLE);
|
2014-09-03 18:20:31 +08:00
|
|
|
this->addChild(playItem);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-09-03 18:20:31 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
LargeAudioFileTest::~LargeAudioFileTest() {}
|
2014-09-03 18:20:31 +08:00
|
|
|
|
|
|
|
std::string LargeAudioFileTest::title() const
|
|
|
|
{
|
|
|
|
return "Test large audio file";
|
|
|
|
}
|
|
|
|
|
2018-07-11 09:36:57 +08:00
|
|
|
bool AudioIssue18597Test::init()
|
|
|
|
{
|
|
|
|
if (AudioEngineTestDemo::init())
|
|
|
|
{
|
|
|
|
auto& layerSize = this->getContentSize();
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
// test case for https://github.com/cocos2d/cocos2d-x/issues/18597
|
|
|
|
this->schedule(
|
|
|
|
[=](float dt) {
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("issues 18597 audio crash test");
|
2021-12-28 16:06:23 +08:00
|
|
|
for (int i = 0; i < 2; ++i)
|
|
|
|
{
|
|
|
|
auto id = AudioEngine::play2d("audio/MUS_BGM_Battle_Round1_v1.caf", true, 1.0f);
|
|
|
|
this->runAction(Sequence::create(DelayTime::create(8.0f),
|
|
|
|
CallFunc::create([=]() { AudioEngine::stop(id); }), nullptr));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
2.0, 10000, 0.0, "audio test");
|
2018-07-11 09:36:57 +08:00
|
|
|
// add label to show the side effect of "UnqueueBuffers Before alSourceStop"
|
2021-12-28 16:06:23 +08:00
|
|
|
_time = 0.0;
|
2018-07-11 09:36:57 +08:00
|
|
|
auto labelTime = Label::createWithBMFont("fonts/bitmapFontTest2.fnt", "time: ");
|
|
|
|
labelTime->setPosition(layerSize.width * 0.5f, layerSize.height * 0.5f);
|
|
|
|
labelTime->setTag(999);
|
|
|
|
this->addChild(labelTime);
|
|
|
|
// update label quickly
|
2021-12-28 16:06:23 +08:00
|
|
|
this->schedule(
|
|
|
|
[=](float dt) {
|
|
|
|
_time += dt;
|
|
|
|
char timeString[20] = {0};
|
|
|
|
sprintf(timeString, "Time %2.2f", _time);
|
|
|
|
dynamic_cast<Label*>(this->getChildByTag(999))->setString(timeString);
|
|
|
|
},
|
|
|
|
0.05, 1000000, 0, "update label quickly");
|
2018-07-11 09:36:57 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string AudioIssue18597Test::title() const
|
|
|
|
{
|
|
|
|
return "Test for issue 18597";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string AudioIssue18597Test::subtitle() const
|
|
|
|
{
|
|
|
|
return "no crash for more than 10 minutes";
|
|
|
|
}
|
|
|
|
|
2015-08-07 16:50:54 +08:00
|
|
|
bool AudioIssue11143Test::init()
|
|
|
|
{
|
|
|
|
if (AudioEngineTestDemo::init())
|
|
|
|
{
|
|
|
|
auto& layerSize = this->getContentSize();
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
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();
|
2021-12-28 16:06:23 +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);
|
2021-12-28 16:06:23 +08:00
|
|
|
button->scheduleOnce(
|
|
|
|
[audioId](float dt) {
|
|
|
|
AudioEngine::stop(audioId);
|
|
|
|
AudioEngine::play2d("audio/SoundEffectsFX009/FX083.mp3");
|
|
|
|
},
|
|
|
|
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
|
2022-07-15 19:17:01 +08:00
|
|
|
#undef AX_PROFILER_DISPLAY_TIMERS
|
|
|
|
#define AX_PROFILER_DISPLAY_TIMERS() Profiler::getInstance()->displayTimers()
|
|
|
|
#undef AX_PROFILER_PURGE_ALL
|
|
|
|
#define AX_PROFILER_PURGE_ALL() Profiler::getInstance()->releaseAllTimers()
|
|
|
|
|
|
|
|
#undef AX_PROFILER_START
|
|
|
|
#define AX_PROFILER_START(__name__) ProfilingBeginTimingBlock(__name__)
|
|
|
|
#undef AX_PROFILER_STOP
|
|
|
|
#define AX_PROFILER_STOP(__name__) ProfilingEndTimingBlock(__name__)
|
|
|
|
#undef AX_PROFILER_RESET
|
|
|
|
#define AX_PROFILER_RESET(__name__) ProfilingResetTimingBlock(__name__)
|
|
|
|
|
|
|
|
#undef AX_PROFILER_START_CATEGORY
|
|
|
|
#define AX_PROFILER_START_CATEGORY(__cat__, __name__) \
|
2021-12-28 16:06:23 +08:00
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
if (__cat__) \
|
|
|
|
ProfilingBeginTimingBlock(__name__); \
|
|
|
|
} while (0)
|
2022-07-15 19:17:01 +08:00
|
|
|
#undef AX_PROFILER_STOP_CATEGORY
|
|
|
|
#define AX_PROFILER_STOP_CATEGORY(__cat__, __name__) \
|
2021-12-28 16:06:23 +08:00
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
if (__cat__) \
|
|
|
|
ProfilingEndTimingBlock(__name__); \
|
|
|
|
} while (0)
|
2022-07-15 19:17:01 +08:00
|
|
|
#undef AX_PROFILER_RESET_CATEGORY
|
|
|
|
#define AX_PROFILER_RESET_CATEGORY(__cat__, __name__) \
|
2021-12-28 16:06:23 +08:00
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
if (__cat__) \
|
|
|
|
ProfilingResetTimingBlock(__name__); \
|
|
|
|
} while (0)
|
[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
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
#undef AX_PROFILER_START_INSTANCE
|
|
|
|
#define AX_PROFILER_START_INSTANCE(__id__, __name__) \
|
2021-12-28 16:06:23 +08:00
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
ProfilingBeginTimingBlock(String::createWithFormat("%08X - %s", __id__, __name__)->getCString()); \
|
|
|
|
} while (0)
|
2022-07-15 19:17:01 +08:00
|
|
|
#undef AX_PROFILER_STOP_INSTANCE
|
|
|
|
#define AX_PROFILER_STOP_INSTANCE(__id__, __name__) \
|
2021-12-28 16:06:23 +08:00
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
ProfilingEndTimingBlock(String::createWithFormat("%08X - %s", __id__, __name__)->getCString()); \
|
|
|
|
} while (0)
|
2022-07-15 19:17:01 +08:00
|
|
|
#undef AX_PROFILER_RESET_INSTANCE
|
|
|
|
#define AX_PROFILER_RESET_INSTANCE(__id__, __name__) \
|
2021-12-28 16:06:23 +08:00
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
ProfilingResetTimingBlock(String::createWithFormat("%08X - %s", __id__, __name__)->getCString()); \
|
|
|
|
} while (0)
|
[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
|
|
|
|
|
|
|
bool AudioPerformanceTest::init()
|
|
|
|
{
|
|
|
|
if (AudioEngineTestDemo::init())
|
|
|
|
{
|
|
|
|
std::vector<std::string> audioFiles = {
|
2021-12-28 16:06:23 +08:00
|
|
|
"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"};
|
|
|
|
|
[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
|
|
|
for (const auto& audioFile : audioFiles)
|
|
|
|
{
|
|
|
|
AudioEngine::preload(audioFile);
|
|
|
|
}
|
2021-12-28 16:06:23 +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
|
|
|
auto& layerSize = this->getContentSize();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
auto playItem = TextButton::create("Start Test", [this, audioFiles](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
|
|
|
button->setEnabled(false);
|
|
|
|
static_cast<TextButton*>(getChildByName("DisplayButton"))->setEnabled(true);
|
2021-12-28 16:06:23 +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
|
|
|
unschedule("test");
|
2021-12-28 16:06:23 +08:00
|
|
|
schedule(
|
|
|
|
[audioFiles](float dt) {
|
2022-07-11 17:50:21 +08:00
|
|
|
int index = axis::random(0, (int)(audioFiles.size() - 1));
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_PROFILER_START("play2d");
|
2021-12-28 16:06:23 +08:00
|
|
|
AudioEngine::play2d(audioFiles[index]);
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_PROFILER_STOP("play2d");
|
2021-12-28 16:06:23 +08:00
|
|
|
},
|
|
|
|
0.25f, "test");
|
[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
|
|
|
});
|
|
|
|
playItem->setPosition(layerSize.width * 0.5f, layerSize.height * 2 / 3);
|
|
|
|
playItem->setName("PlayButton");
|
|
|
|
addChild(playItem);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
auto displayItem = TextButton::create("Display Result", [this, playItem](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
|
|
|
unschedule("test");
|
|
|
|
AudioEngine::stopAll();
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_PROFILER_DISPLAY_TIMERS();
|
[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
|
|
|
playItem->setEnabled(true);
|
|
|
|
button->setEnabled(false);
|
|
|
|
});
|
|
|
|
displayItem->setEnabled(false);
|
|
|
|
displayItem->setPosition(layerSize.width * 0.5f, layerSize.height / 3);
|
|
|
|
displayItem->setName("DisplayButton");
|
|
|
|
addChild(displayItem);
|
2021-12-28 16:06:23 +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
|
|
|
return true;
|
|
|
|
}
|
2021-12-28 16:06:23 +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
|
|
|
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";
|
|
|
|
}
|
|
|
|
|
2016-07-21 14:57:59 +08:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2021-10-06 11:24:39 +08:00
|
|
|
void AudioSwitchStateTest::onEnter()
|
2016-07-21 14:57:59 +08:00
|
|
|
{
|
2021-10-06 11:24:39 +08:00
|
|
|
AudioEngineTestDemo::onEnter();
|
|
|
|
|
|
|
|
//
|
|
|
|
// !!!Notes:
|
|
|
|
// a. No special reason, but we must play the tests audio at onEnter for this test suite only.
|
|
|
|
// b. The latst audio test scene will stop all audio players,
|
|
|
|
// so if play any sound at init funciton, you can't herer
|
|
|
|
// c. Please refer to AudioEngineTestDemo::onExit
|
2021-12-28 16:06:23 +08:00
|
|
|
//
|
2021-10-06 11:24:39 +08:00
|
|
|
AudioEngine::preload("audio/SoundEffectsFX009/FX081.mp3");
|
|
|
|
AudioEngine::play2d("audio/SoundEffectsFX009/FX082.mp3");
|
|
|
|
AudioEngine::play2d("audio/LuckyDay.mp3");
|
2016-07-21 14:57:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string AudioSwitchStateTest::title() const
|
|
|
|
{
|
|
|
|
return "play, preload, stop switch test";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string AudioSwitchStateTest::subtitle() const
|
|
|
|
{
|
2019-10-31 16:05:57 +08:00
|
|
|
return "Should not crash. No sound is ok";
|
2016-07-21 14:57:59 +08:00
|
|
|
}
|
2016-07-27 14:00:34 +08:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void AudioSmallFileTest::onEnter()
|
2016-07-27 14:00:34 +08:00
|
|
|
{
|
2021-10-06 11:24:39 +08:00
|
|
|
AudioEngineTestDemo::onEnter();
|
|
|
|
|
|
|
|
//
|
|
|
|
// !!!Notes:
|
|
|
|
// a. No special reason, but we must play the tests audio at onEnter for this test suite only.
|
|
|
|
// b. The latst audio test scene will stop all audio players,
|
|
|
|
// so if play any sound at init funciton, you can't hear it
|
|
|
|
// c. Please refer to AudioEngineTestDemo::onExit
|
2021-12-28 16:06:23 +08:00
|
|
|
//
|
2021-10-06 11:24:39 +08:00
|
|
|
AudioEngine::play2d("audio/SmallFile.mp3");
|
2016-07-27 14:00:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string AudioSmallFileTest::title() const
|
|
|
|
{
|
|
|
|
return "Playing small mp3 file";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string AudioSmallFileTest::subtitle() const
|
|
|
|
{
|
|
|
|
return "Should not crash";
|
|
|
|
}
|
2016-08-22 09:43:06 +08:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2016-12-15 09:58:47 +08:00
|
|
|
void AudioSmallFile2Test::onEnter()
|
|
|
|
{
|
|
|
|
AudioEngineTestDemo::onEnter();
|
|
|
|
|
2021-10-06 11:24:39 +08:00
|
|
|
//
|
|
|
|
// !!!Notes:
|
|
|
|
// a. No special reason, but we must play the tests audio at onEnter for this test suite only.
|
|
|
|
// b. The latst audio test scene will stop all audio players,
|
|
|
|
// so if play any sound at init funciton, you can't hear it
|
|
|
|
// c. Please refer to AudioEngineTestDemo::onExit
|
2021-12-28 16:06:23 +08:00
|
|
|
//
|
2021-10-06 11:24:39 +08:00
|
|
|
AudioEngine::play2d("audio/SmallFile2.mp3");
|
2016-12-15 09:58:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string AudioSmallFile2Test::title() const
|
|
|
|
{
|
|
|
|
return "Play small mp3 file 2";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string AudioSmallFile2Test::subtitle() const
|
|
|
|
{
|
|
|
|
return "Should not crash and should not have rasp!";
|
|
|
|
}
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2017-03-15 16:46:19 +08:00
|
|
|
void AudioSmallFile3Test::onEnter()
|
|
|
|
{
|
|
|
|
AudioEngineTestDemo::onEnter();
|
|
|
|
|
2021-10-06 11:24:39 +08:00
|
|
|
//
|
|
|
|
// !!!Notes:
|
|
|
|
// a. No special reason, but we must play the tests audio at onEnter for this test suite only.
|
|
|
|
// b. The latst audio test scene will stop all audio players,
|
|
|
|
// so if play any sound at init funciton, you can't hear it
|
|
|
|
// c. Please refer to AudioEngineTestDemo::onExit
|
2021-12-28 16:06:23 +08:00
|
|
|
//
|
2021-10-06 11:24:39 +08:00
|
|
|
AudioEngine::play2d("audio/SmallFile3.mp3");
|
2017-03-15 16:46:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string AudioSmallFile3Test::title() const
|
|
|
|
{
|
|
|
|
return "Play small mp3 file 3";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string AudioSmallFile3Test::subtitle() const
|
|
|
|
{
|
|
|
|
return "Should not crash!";
|
|
|
|
}
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2016-09-01 11:43:37 +08:00
|
|
|
void AudioPauseResumeAfterPlay::onEnter()
|
2016-08-22 09:43:06 +08:00
|
|
|
{
|
2016-09-01 11:43:37 +08:00
|
|
|
AudioEngineTestDemo::onEnter();
|
|
|
|
|
|
|
|
int audioId = AudioEngine::play2d("audio/SoundEffectsFX009/FX082.mp3");
|
|
|
|
AudioEngine::pause(audioId);
|
|
|
|
AudioEngine::resume(audioId);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2016-09-01 11:43:37 +08:00
|
|
|
for (int i = 0; i < 10; ++i)
|
2016-08-22 09:43:06 +08:00
|
|
|
{
|
|
|
|
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";
|
|
|
|
}
|
2016-09-01 11:46:27 +08:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2016-12-02 13:52:37 +08:00
|
|
|
void AudioIssue16938Test::onEnter()
|
|
|
|
{
|
|
|
|
AudioEngineTestDemo::onEnter();
|
|
|
|
|
|
|
|
AudioEngine::play2d("audio/EntireFramesTest.mp3");
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string AudioIssue16938Test::title() const
|
|
|
|
{
|
|
|
|
return "Issue 16938 Test";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string AudioIssue16938Test::subtitle() const
|
|
|
|
{
|
|
|
|
return "Should heard the entire audio frames";
|
|
|
|
}
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2016-09-01 11:46:27 +08:00
|
|
|
void AudioPreloadSameFileMultipleTimes::onEnter()
|
|
|
|
{
|
|
|
|
AudioEngineTestDemo::onEnter();
|
|
|
|
|
|
|
|
for (int i = 0; i < 10; ++i)
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
AudioEngine::preload("audio/SoundEffectsFX009/FX082.mp3", [i](bool isSucceed) {
|
2016-09-01 11:46:27 +08:00
|
|
|
log("111: %d preload %s", i, isSucceed ? "succeed" : "failed");
|
2021-12-28 16:06:23 +08:00
|
|
|
AudioEngine::preload("audio/SoundEffectsFX009/FX082.mp3", [i](bool isSucceed) {
|
2016-09-01 11:46:27 +08:00
|
|
|
log("222: %d preload %s", i, isSucceed ? "succeed" : "failed");
|
2021-12-28 16:06:23 +08:00
|
|
|
AudioEngine::preload("audio/SoundEffectsFX009/FX082.mp3", [i](bool isSucceed) {
|
2016-09-01 11:46:27 +08:00
|
|
|
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";
|
|
|
|
}
|
2016-09-01 16:06:29 +08:00
|
|
|
|
|
|
|
void AudioPlayFileInWritablePath::onEnter()
|
|
|
|
{
|
|
|
|
AudioEngineTestDemo::onEnter();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
auto fileUtils = FileUtils::getInstance();
|
2016-09-01 16:06:29 +08:00
|
|
|
std::string writablePath = fileUtils->getWritablePath();
|
2021-12-28 16:06:23 +08:00
|
|
|
std::string musicFile = "background.mp3";
|
2016-09-01 16:06:29 +08:00
|
|
|
std::string saveFilePath = writablePath + "background_in_writable_dir.mp3";
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2017-03-22 11:17:52 +08:00
|
|
|
_oldSearchPaths = fileUtils->getOriginalSearchPaths();
|
2016-09-01 16:06:29 +08:00
|
|
|
fileUtils->addSearchPath(writablePath, true);
|
|
|
|
|
|
|
|
if (!fileUtils->isFileExist(saveFilePath))
|
|
|
|
{
|
|
|
|
Data data = fileUtils->getDataFromFile(musicFile);
|
2021-12-28 16:06:23 +08:00
|
|
|
FILE* fp = fopen(saveFilePath.c_str(), "wb");
|
2016-09-01 16:06:29 +08:00
|
|
|
if (fp != nullptr)
|
|
|
|
{
|
|
|
|
fwrite(data.getBytes(), data.getSize(), 1, fp);
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
}
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2016-09-01 16:06:29 +08:00
|
|
|
AudioEngine::play2d(saveFilePath);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioPlayFileInWritablePath::onExit()
|
|
|
|
{
|
|
|
|
AudioEngineTestDemo::onExit();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2016-09-01 16:06:29 +08:00
|
|
|
FileUtils::getInstance()->setSearchPaths(_oldSearchPaths);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string AudioPlayFileInWritablePath::title() const
|
|
|
|
{
|
|
|
|
return "Play audio in writable path";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string AudioPlayFileInWritablePath::subtitle() const
|
|
|
|
{
|
|
|
|
return "Could play audio";
|
|
|
|
}
|
2017-03-27 17:28:39 +08:00
|
|
|
|
|
|
|
//
|
|
|
|
void AudioPlayInFinishedCB::onEnter()
|
|
|
|
{
|
|
|
|
AudioEngineTestDemo::onEnter();
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
auto item = MenuItemFont::create("Play 3 files one by one", [this](Ref* sender) {
|
2017-03-27 17:28:39 +08:00
|
|
|
playMusic("background.mp3");
|
|
|
|
playMusic("background.mp3");
|
|
|
|
playMusic("background.mp3");
|
|
|
|
});
|
|
|
|
|
|
|
|
item->setPosition(VisibleRect::center());
|
|
|
|
|
|
|
|
auto menu = Menu::create(item, nullptr);
|
|
|
|
menu->setPosition(Vec2::ANCHOR_BOTTOM_LEFT);
|
|
|
|
addChild(menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioPlayInFinishedCB::onExit()
|
|
|
|
{
|
|
|
|
AudioEngineTestDemo::onExit();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string AudioPlayInFinishedCB::title() const
|
|
|
|
{
|
|
|
|
return "Click menu item to play 3 audio files";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string AudioPlayInFinishedCB::subtitle() const
|
|
|
|
{
|
|
|
|
return "After played over, click again, should also hear 3 audios";
|
|
|
|
}
|
|
|
|
|
2021-12-28 15:58:56 +08:00
|
|
|
void AudioPlayInFinishedCB::doPlay(std::string_view filename)
|
2017-03-27 17:28:39 +08:00
|
|
|
{
|
|
|
|
int playID = AudioEngine::play2d(filename, false, 1);
|
2021-12-28 16:06:23 +08:00
|
|
|
AudioEngine::setFinishCallback(playID, [this](int finishID, std::string_view file) {
|
2017-03-27 17:28:39 +08:00
|
|
|
_playList.pop_front();
|
2021-12-28 16:06:23 +08:00
|
|
|
log("finish music %s", file.data());
|
|
|
|
if (!_playList.empty())
|
|
|
|
{
|
2021-12-28 15:58:56 +08:00
|
|
|
std::string_view name = _playList.front();
|
2017-03-27 17:28:39 +08:00
|
|
|
doPlay(name);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-12-28 15:58:56 +08:00
|
|
|
void AudioPlayInFinishedCB::playMusic(std::string_view filename)
|
2017-03-27 17:28:39 +08:00
|
|
|
{
|
2022-08-08 13:18:33 +08:00
|
|
|
_playList.emplace_back(std::string{filename});
|
2021-12-28 16:06:23 +08:00
|
|
|
if (_playList.size() == 1)
|
|
|
|
{
|
2017-03-27 17:28:39 +08:00
|
|
|
doPlay(filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-31 09:38:45 +08:00
|
|
|
//
|
|
|
|
void AudioUncacheInFinishedCB::onEnter()
|
|
|
|
{
|
|
|
|
AudioEngineTestDemo::onEnter();
|
|
|
|
|
|
|
|
int id = AudioEngine::play2d("background.mp3");
|
2021-12-28 16:06:23 +08:00
|
|
|
AudioEngine::setFinishCallback(id, [](int i, std::string_view str) { AudioEngine::uncacheAll(); });
|
2017-03-31 09:38:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void AudioUncacheInFinishedCB::onExit()
|
|
|
|
{
|
|
|
|
AudioEngineTestDemo::onExit();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string AudioUncacheInFinishedCB::title() const
|
|
|
|
{
|
|
|
|
return "UncacheAll in finshed callback";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string AudioUncacheInFinishedCB::subtitle() const
|
|
|
|
{
|
|
|
|
return "Should not crash";
|
|
|
|
}
|