react-native-audio-api 0.11.0-alpha.0 → 0.11.0-nightly-bfab178-20251107

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (350) hide show
  1. package/README.md +13 -11
  2. package/RNAudioAPI.podspec +20 -15
  3. package/android/build.gradle +33 -3
  4. package/android/src/main/cpp/audioapi/CMakeLists.txt +6 -3
  5. package/android/src/main/cpp/audioapi/android/AudioAPIModule.cpp +5 -0
  6. package/android/src/main/cpp/audioapi/android/AudioAPIModule.h +1 -0
  7. package/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.cpp +30 -94
  8. package/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.h +14 -28
  9. package/android/src/main/cpp/audioapi/android/core/AudioPlayer.cpp +4 -2
  10. package/android/src/main/cpp/audioapi/android/core/NativeAudioRecorder.hpp +9 -9
  11. package/android/src/main/cpp/audioapi/android/core/utils/AudioDecoder.cpp +6 -0
  12. package/android/src/main/java/com/swmansion/audioapi/AudioAPIModule.kt +31 -3
  13. package/android/src/main/java/com/swmansion/audioapi/system/AudioFocusListener.kt +21 -9
  14. package/android/src/main/java/com/swmansion/audioapi/system/LockScreenManager.kt +27 -6
  15. package/android/src/main/java/com/swmansion/audioapi/system/MediaNotificationManager.kt +11 -0
  16. package/android/src/oldarch/NativeAudioAPIModuleSpec.java +4 -0
  17. package/common/cpp/audioapi/AudioAPIModuleInstaller.h +30 -2
  18. package/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.cpp +18 -0
  19. package/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.h +1 -0
  20. package/common/cpp/audioapi/HostObjects/effects/BiquadFilterNodeHostObject.cpp +1 -1
  21. package/common/cpp/audioapi/HostObjects/effects/ConvolverNodeHostObject.cpp +47 -0
  22. package/common/cpp/audioapi/HostObjects/effects/ConvolverNodeHostObject.h +20 -0
  23. package/common/cpp/audioapi/HostObjects/inputs/AudioRecorderHostObject.cpp +18 -80
  24. package/common/cpp/audioapi/HostObjects/inputs/AudioRecorderHostObject.h +6 -15
  25. package/common/cpp/audioapi/HostObjects/sources/AudioBufferBaseSourceNodeHostObject.cpp +1 -1
  26. package/common/cpp/audioapi/HostObjects/sources/AudioBufferSourceNodeHostObject.cpp +1 -1
  27. package/common/cpp/audioapi/HostObjects/sources/AudioScheduledSourceNodeHostObject.cpp +1 -1
  28. package/common/cpp/audioapi/core/AudioNode.h +3 -2
  29. package/common/cpp/audioapi/core/AudioParam.cpp +2 -2
  30. package/common/cpp/audioapi/core/BaseAudioContext.cpp +10 -0
  31. package/common/cpp/audioapi/core/BaseAudioContext.h +2 -0
  32. package/common/cpp/audioapi/core/effects/BiquadFilterNode.cpp +69 -32
  33. package/common/cpp/audioapi/core/effects/BiquadFilterNode.h +37 -1
  34. package/common/cpp/audioapi/core/effects/ConvolverNode.cpp +210 -0
  35. package/common/cpp/audioapi/core/effects/ConvolverNode.h +55 -0
  36. package/common/cpp/audioapi/core/inputs/AudioRecorder.cpp +49 -102
  37. package/common/cpp/audioapi/core/inputs/AudioRecorder.h +28 -46
  38. package/common/cpp/audioapi/core/sources/AudioBufferBaseSourceNode.cpp +14 -17
  39. package/common/cpp/audioapi/core/sources/AudioBufferBaseSourceNode.h +0 -1
  40. package/common/cpp/audioapi/core/sources/AudioBufferSourceNode.cpp +8 -14
  41. package/common/cpp/audioapi/core/sources/AudioBufferSourceNode.h +0 -1
  42. package/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.cpp +14 -18
  43. package/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.h +2 -2
  44. package/common/cpp/audioapi/core/sources/StreamerNode.cpp +64 -64
  45. package/common/cpp/audioapi/core/sources/StreamerNode.h +38 -10
  46. package/common/cpp/audioapi/core/utils/AudioNodeManager.cpp +5 -0
  47. package/common/cpp/audioapi/core/utils/Constants.h +2 -1
  48. package/common/cpp/audioapi/core/utils/worklets/SafeIncludes.h +12 -8
  49. package/common/cpp/audioapi/core/utils/worklets/WorkletsRunner.cpp +3 -3
  50. package/common/cpp/audioapi/core/utils/worklets/WorkletsRunner.h +1 -1
  51. package/common/cpp/audioapi/dsp/AudioUtils.cpp +1 -1
  52. package/common/cpp/audioapi/dsp/Convolver.cpp +213 -0
  53. package/common/cpp/audioapi/dsp/Convolver.h +45 -0
  54. package/common/cpp/audioapi/dsp/FFT.cpp +0 -26
  55. package/common/cpp/audioapi/dsp/FFT.h +26 -2
  56. package/common/cpp/audioapi/events/AudioEventHandlerRegistry.h +1 -1
  57. package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/avcodec.h +4 -4
  58. package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/codec.h +1 -1
  59. package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/codec_desc.h +1 -1
  60. package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/codec_id.h +3 -1
  61. package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/codec_par.h +2 -2
  62. package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/defs.h +3 -0
  63. package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/packet.h +1 -1
  64. package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/smpte_436m.h +254 -0
  65. package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/version.h +1 -1
  66. package/common/cpp/audioapi/external/ffmpeg_include/libavformat/avformat.h +6 -6
  67. package/common/cpp/audioapi/external/ffmpeg_include/libavformat/version.h +2 -2
  68. package/common/cpp/audioapi/external/ffmpeg_include/libavformat/version_major.h +2 -0
  69. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/avassert.h +5 -2
  70. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/avutil.h +2 -2
  71. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/channel_layout.h +2 -2
  72. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/csp.h +1 -1
  73. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/dict.h +1 -1
  74. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/ffversion.h +1 -1
  75. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/film_grain_params.h +1 -1
  76. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/frame.h +1 -1
  77. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/hdr_dynamic_vivid_metadata.h +3 -3
  78. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/hwcontext.h +1 -1
  79. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/hwcontext_opencl.h +1 -1
  80. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/hwcontext_qsv.h +0 -1
  81. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/hwcontext_vulkan.h +1 -1
  82. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/iamf.h +2 -2
  83. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/lfg.h +2 -2
  84. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/log.h +2 -2
  85. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/mathematics.h +1 -1
  86. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/opt.h +4 -4
  87. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/rational.h +1 -1
  88. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/rc4.h +1 -1
  89. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/refstruct.h +1 -1
  90. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/spherical.h +6 -0
  91. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/tdrdi.h +1 -1
  92. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/tx.h +1 -1
  93. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/version.h +3 -3
  94. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/video_hint.h +1 -1
  95. package/common/cpp/audioapi/external/ffmpeg_include/libswresample/swresample.h +1 -1
  96. package/common/cpp/audioapi/external/ffmpeg_include/libswresample/version.h +1 -1
  97. package/common/cpp/audioapi/libs/ffmpeg/FFmpegDecoding.cpp +2 -3
  98. package/common/cpp/audioapi/libs/ffmpeg/relinking.md +24 -0
  99. package/common/cpp/audioapi/utils/AlignedAllocator.hpp +50 -0
  100. package/common/cpp/audioapi/utils/AudioBus.cpp +28 -0
  101. package/common/cpp/audioapi/utils/AudioBus.h +3 -0
  102. package/common/cpp/audioapi/utils/ThreadPool.hpp +59 -1
  103. package/common/cpp/test/CMakeLists.txt +19 -14
  104. package/common/cpp/test/src/AudioParamTest.cpp +1 -1
  105. package/common/cpp/test/src/AudioScheduledSourceTest.cpp +134 -0
  106. package/common/cpp/test/src/ConstantSourceTest.cpp +1 -1
  107. package/common/cpp/test/src/GainTest.cpp +1 -1
  108. package/common/cpp/test/src/MockAudioEventHandlerRegistry.h +4 -4
  109. package/common/cpp/test/src/OscillatorTest.cpp +1 -1
  110. package/common/cpp/test/src/StereoPannerTest.cpp +1 -1
  111. package/common/cpp/test/src/biquad/BiquadFilterChromium.cpp +389 -0
  112. package/common/cpp/test/src/biquad/BiquadFilterChromium.h +64 -0
  113. package/common/cpp/test/src/biquad/BiquadFilterTest.cpp +284 -0
  114. package/common/cpp/test/src/biquad/BiquadFilterTest.h +40 -0
  115. package/ios/audioapi/ios/AudioAPIModule.h +2 -1
  116. package/ios/audioapi/ios/AudioAPIModule.mm +13 -0
  117. package/ios/audioapi/ios/core/IOSAudioRecorder.h +9 -18
  118. package/ios/audioapi/ios/core/IOSAudioRecorder.mm +28 -70
  119. package/ios/audioapi/ios/core/NativeAudioRecorder.h +6 -2
  120. package/ios/audioapi/ios/core/NativeAudioRecorder.m +73 -5
  121. package/ios/audioapi/ios/system/AudioEngine.mm +3 -3
  122. package/ios/audioapi/ios/system/AudioSessionManager.h +2 -0
  123. package/ios/audioapi/ios/system/AudioSessionManager.mm +24 -0
  124. package/ios/audioapi/ios/system/LockScreenManager.h +0 -1
  125. package/ios/audioapi/ios/system/LockScreenManager.mm +6 -19
  126. package/lib/commonjs/api.js +141 -76
  127. package/lib/commonjs/api.js.map +1 -1
  128. package/lib/commonjs/api.web.js +8 -0
  129. package/lib/commonjs/api.web.js.map +1 -1
  130. package/lib/commonjs/core/AudioContext.js +1 -1
  131. package/lib/commonjs/core/AudioContext.js.map +1 -1
  132. package/lib/commonjs/core/AudioRecorder.js +12 -157
  133. package/lib/commonjs/core/AudioRecorder.js.map +1 -1
  134. package/lib/commonjs/core/BaseAudioContext.js +28 -25
  135. package/lib/commonjs/core/BaseAudioContext.js.map +1 -1
  136. package/lib/commonjs/core/ConvolverNode.js +37 -0
  137. package/lib/commonjs/core/ConvolverNode.js.map +1 -0
  138. package/lib/commonjs/core/OfflineAudioContext.js +1 -1
  139. package/lib/commonjs/core/OfflineAudioContext.js.map +1 -1
  140. package/lib/commonjs/specs/NativeAudioAPIModule.js.map +1 -1
  141. package/lib/commonjs/system/AudioManager.js +3 -0
  142. package/lib/commonjs/system/AudioManager.js.map +1 -1
  143. package/lib/commonjs/types.js +0 -46
  144. package/lib/commonjs/types.js.map +1 -1
  145. package/lib/commonjs/utils/index.js +19 -21
  146. package/lib/commonjs/utils/index.js.map +1 -1
  147. package/lib/commonjs/web-core/AudioContext.js +12 -0
  148. package/lib/commonjs/web-core/AudioContext.js.map +1 -1
  149. package/lib/commonjs/web-core/ConvolverNode.js +40 -0
  150. package/lib/commonjs/web-core/ConvolverNode.js.map +1 -0
  151. package/lib/commonjs/web-core/ConvolverNodeOptions.js +6 -0
  152. package/lib/commonjs/web-core/ConvolverNodeOptions.js.map +1 -0
  153. package/lib/commonjs/web-core/OfflineAudioContext.js +12 -0
  154. package/lib/commonjs/web-core/OfflineAudioContext.js.map +1 -1
  155. package/lib/module/api.js +16 -15
  156. package/lib/module/api.js.map +1 -1
  157. package/lib/module/api.web.js +1 -0
  158. package/lib/module/api.web.js.map +1 -1
  159. package/lib/module/core/AudioContext.js +2 -2
  160. package/lib/module/core/AudioContext.js.map +1 -1
  161. package/lib/module/core/AudioRecorder.js +12 -157
  162. package/lib/module/core/AudioRecorder.js.map +1 -1
  163. package/lib/module/core/BaseAudioContext.js +29 -26
  164. package/lib/module/core/BaseAudioContext.js.map +1 -1
  165. package/lib/module/core/ConvolverNode.js +31 -0
  166. package/lib/module/core/ConvolverNode.js.map +1 -0
  167. package/lib/module/core/OfflineAudioContext.js +2 -2
  168. package/lib/module/core/OfflineAudioContext.js.map +1 -1
  169. package/lib/module/specs/NativeAudioAPIModule.js.map +1 -1
  170. package/lib/module/system/AudioManager.js +3 -0
  171. package/lib/module/system/AudioManager.js.map +1 -1
  172. package/lib/module/types.js +1 -45
  173. package/lib/module/types.js.map +1 -1
  174. package/lib/module/utils/index.js +15 -2
  175. package/lib/module/utils/index.js.map +1 -1
  176. package/lib/module/web-core/AudioContext.js +12 -0
  177. package/lib/module/web-core/AudioContext.js.map +1 -1
  178. package/lib/module/web-core/ConvolverNode.js +34 -0
  179. package/lib/module/web-core/ConvolverNode.js.map +1 -0
  180. package/lib/module/web-core/ConvolverNodeOptions.js +4 -0
  181. package/lib/module/web-core/ConvolverNodeOptions.js.map +1 -0
  182. package/lib/module/web-core/OfflineAudioContext.js +12 -0
  183. package/lib/module/web-core/OfflineAudioContext.js.map +1 -1
  184. package/lib/typescript/api.d.ts +19 -17
  185. package/lib/typescript/api.d.ts.map +1 -1
  186. package/lib/typescript/api.web.d.ts +1 -0
  187. package/lib/typescript/api.web.d.ts.map +1 -1
  188. package/lib/typescript/core/AudioContext.d.ts.map +1 -1
  189. package/lib/typescript/core/AudioRecorder.d.ts +6 -58
  190. package/lib/typescript/core/AudioRecorder.d.ts.map +1 -1
  191. package/lib/typescript/core/BaseAudioContext.d.ts +3 -1
  192. package/lib/typescript/core/BaseAudioContext.d.ts.map +1 -1
  193. package/lib/typescript/core/ConvolverNode.d.ts +12 -0
  194. package/lib/typescript/core/ConvolverNode.d.ts.map +1 -0
  195. package/lib/typescript/events/types.d.ts +0 -16
  196. package/lib/typescript/events/types.d.ts.map +1 -1
  197. package/lib/typescript/interfaces.d.ts +8 -39
  198. package/lib/typescript/interfaces.d.ts.map +1 -1
  199. package/lib/typescript/specs/NativeAudioAPIModule.d.ts +1 -0
  200. package/lib/typescript/specs/NativeAudioAPIModule.d.ts.map +1 -1
  201. package/lib/typescript/system/AudioManager.d.ts +1 -0
  202. package/lib/typescript/system/AudioManager.d.ts.map +1 -1
  203. package/lib/typescript/types.d.ts +8 -74
  204. package/lib/typescript/types.d.ts.map +1 -1
  205. package/lib/typescript/utils/index.d.ts +5 -2
  206. package/lib/typescript/utils/index.d.ts.map +1 -1
  207. package/lib/typescript/web-core/AudioContext.d.ts +3 -0
  208. package/lib/typescript/web-core/AudioContext.d.ts.map +1 -1
  209. package/lib/typescript/web-core/BaseAudioContext.d.ts +2 -0
  210. package/lib/typescript/web-core/BaseAudioContext.d.ts.map +1 -1
  211. package/lib/typescript/web-core/ConvolverNode.d.ts +11 -0
  212. package/lib/typescript/web-core/ConvolverNode.d.ts.map +1 -0
  213. package/lib/typescript/web-core/ConvolverNodeOptions.d.ts +6 -0
  214. package/lib/typescript/web-core/ConvolverNodeOptions.d.ts.map +1 -0
  215. package/lib/typescript/web-core/OfflineAudioContext.d.ts +3 -0
  216. package/lib/typescript/web-core/OfflineAudioContext.d.ts.map +1 -1
  217. package/package.json +14 -5
  218. package/scripts/download-prebuilt-binaries.sh +61 -0
  219. package/scripts/rnaa_utils.rb +8 -0
  220. package/scripts/validate-worklets-version.js +28 -0
  221. package/src/api.ts +45 -18
  222. package/src/api.web.ts +1 -0
  223. package/src/core/AudioContext.ts +3 -2
  224. package/src/core/AudioRecorder.ts +20 -190
  225. package/src/core/BaseAudioContext.ts +67 -60
  226. package/src/core/ConvolverNode.ts +35 -0
  227. package/src/core/OfflineAudioContext.ts +2 -2
  228. package/src/events/types.ts +0 -18
  229. package/src/interfaces.ts +15 -47
  230. package/src/specs/NativeAudioAPIModule.ts +1 -0
  231. package/src/system/AudioManager.ts +4 -0
  232. package/src/types.ts +9 -84
  233. package/src/utils/index.ts +22 -2
  234. package/src/web-core/AudioContext.tsx +25 -0
  235. package/src/web-core/BaseAudioContext.tsx +2 -0
  236. package/src/web-core/ConvolverNode.tsx +43 -0
  237. package/src/web-core/ConvolverNodeOptions.tsx +6 -0
  238. package/src/web-core/OfflineAudioContext.tsx +25 -0
  239. package/android/src/main/cpp/audioapi/android/core/utils/AndroidFileWriterBackend.h +0 -33
  240. package/android/src/main/cpp/audioapi/android/core/utils/FileUtils.h +0 -34
  241. package/android/src/main/cpp/audioapi/android/core/utils/FileUtilts.cpp +0 -133
  242. package/android/src/main/cpp/audioapi/android/core/utils/MiniaudioImplementation.cpp +0 -3
  243. package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/FFmpegAudioFileOptions.cpp +0 -154
  244. package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/FFmpegAudioFileOptions.h +0 -41
  245. package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/FFmpegFileWriter.cpp +0 -431
  246. package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/FFmpegFileWriter.h +0 -112
  247. package/android/src/main/cpp/audioapi/android/core/utils/miniaudioBackend/MiniAudioFileOptions.cpp +0 -47
  248. package/android/src/main/cpp/audioapi/android/core/utils/miniaudioBackend/MiniAudioFileOptions.h +0 -28
  249. package/android/src/main/cpp/audioapi/android/core/utils/miniaudioBackend/MiniAudioFileWriter.cpp +0 -237
  250. package/android/src/main/cpp/audioapi/android/core/utils/miniaudioBackend/MiniAudioFileWriter.h +0 -46
  251. package/android/src/main/cpp/audioapi/android/system/NativeFileInfo.hpp +0 -31
  252. package/android/src/main/java/com/swmansion/audioapi/system/NativeFileInfo.kt +0 -18
  253. package/android/src/main/jniLibs/arm64-v8a/libavcodec.so +0 -0
  254. package/android/src/main/jniLibs/arm64-v8a/libavformat.so +0 -0
  255. package/android/src/main/jniLibs/arm64-v8a/libavutil.so +0 -0
  256. package/android/src/main/jniLibs/arm64-v8a/libswresample.so +0 -0
  257. package/android/src/main/jniLibs/armeabi-v7a/libavcodec.so +0 -0
  258. package/android/src/main/jniLibs/armeabi-v7a/libavformat.so +0 -0
  259. package/android/src/main/jniLibs/armeabi-v7a/libavutil.so +0 -0
  260. package/android/src/main/jniLibs/armeabi-v7a/libswresample.so +0 -0
  261. package/android/src/main/jniLibs/x86/libavcodec.so +0 -0
  262. package/android/src/main/jniLibs/x86/libavformat.so +0 -0
  263. package/android/src/main/jniLibs/x86/libavutil.so +0 -0
  264. package/android/src/main/jniLibs/x86/libswresample.so +0 -0
  265. package/android/src/main/jniLibs/x86_64/libavcodec.so +0 -0
  266. package/android/src/main/jniLibs/x86_64/libavformat.so +0 -0
  267. package/android/src/main/jniLibs/x86_64/libavutil.so +0 -0
  268. package/android/src/main/jniLibs/x86_64/libswresample.so +0 -0
  269. package/common/cpp/audioapi/external/arm64-v8a/libcrypto.a +0 -0
  270. package/common/cpp/audioapi/external/arm64-v8a/libogg.a +0 -0
  271. package/common/cpp/audioapi/external/arm64-v8a/libopus.a +0 -0
  272. package/common/cpp/audioapi/external/arm64-v8a/libopusfile.a +0 -0
  273. package/common/cpp/audioapi/external/arm64-v8a/libssl.a +0 -0
  274. package/common/cpp/audioapi/external/arm64-v8a/libvorbis.a +0 -0
  275. package/common/cpp/audioapi/external/arm64-v8a/libvorbisenc.a +0 -0
  276. package/common/cpp/audioapi/external/arm64-v8a/libvorbisfile.a +0 -0
  277. package/common/cpp/audioapi/external/armeabi-v7a/libcrypto.a +0 -0
  278. package/common/cpp/audioapi/external/armeabi-v7a/libogg.a +0 -0
  279. package/common/cpp/audioapi/external/armeabi-v7a/libopus.a +0 -0
  280. package/common/cpp/audioapi/external/armeabi-v7a/libopusfile.a +0 -0
  281. package/common/cpp/audioapi/external/armeabi-v7a/libssl.a +0 -0
  282. package/common/cpp/audioapi/external/armeabi-v7a/libvorbis.a +0 -0
  283. package/common/cpp/audioapi/external/armeabi-v7a/libvorbisenc.a +0 -0
  284. package/common/cpp/audioapi/external/armeabi-v7a/libvorbisfile.a +0 -0
  285. package/common/cpp/audioapi/external/iphoneos/libcrypto.a +0 -0
  286. package/common/cpp/audioapi/external/iphoneos/libogg.a +0 -0
  287. package/common/cpp/audioapi/external/iphoneos/libopus.a +0 -0
  288. package/common/cpp/audioapi/external/iphoneos/libopusfile.a +0 -0
  289. package/common/cpp/audioapi/external/iphoneos/libssl.a +0 -0
  290. package/common/cpp/audioapi/external/iphoneos/libvorbis.a +0 -0
  291. package/common/cpp/audioapi/external/iphoneos/libvorbisenc.a +0 -0
  292. package/common/cpp/audioapi/external/iphoneos/libvorbisfile.a +0 -0
  293. package/common/cpp/audioapi/external/iphonesimulator/libcrypto.a +0 -0
  294. package/common/cpp/audioapi/external/iphonesimulator/libogg.a +0 -0
  295. package/common/cpp/audioapi/external/iphonesimulator/libopus.a +0 -0
  296. package/common/cpp/audioapi/external/iphonesimulator/libopusfile.a +0 -0
  297. package/common/cpp/audioapi/external/iphonesimulator/libssl.a +0 -0
  298. package/common/cpp/audioapi/external/iphonesimulator/libvorbis.a +0 -0
  299. package/common/cpp/audioapi/external/iphonesimulator/libvorbisenc.a +0 -0
  300. package/common/cpp/audioapi/external/iphonesimulator/libvorbisfile.a +0 -0
  301. package/common/cpp/audioapi/external/libavcodec.xcframework/Info.plist +0 -44
  302. package/common/cpp/audioapi/external/libavcodec.xcframework/ios-arm64/libavcodec.framework/Info.plist +0 -1
  303. package/common/cpp/audioapi/external/libavcodec.xcframework/ios-arm64/libavcodec.framework/libavcodec +0 -0
  304. package/common/cpp/audioapi/external/libavcodec.xcframework/ios-arm64_x86_64-simulator/libavcodec.framework/Info.plist +0 -1
  305. package/common/cpp/audioapi/external/libavcodec.xcframework/ios-arm64_x86_64-simulator/libavcodec.framework/libavcodec +0 -0
  306. package/common/cpp/audioapi/external/libavformat.xcframework/Info.plist +0 -44
  307. package/common/cpp/audioapi/external/libavformat.xcframework/ios-arm64/libavformat.framework/Info.plist +0 -1
  308. package/common/cpp/audioapi/external/libavformat.xcframework/ios-arm64/libavformat.framework/libavformat +0 -0
  309. package/common/cpp/audioapi/external/libavformat.xcframework/ios-arm64_x86_64-simulator/libavformat.framework/Info.plist +0 -1
  310. package/common/cpp/audioapi/external/libavformat.xcframework/ios-arm64_x86_64-simulator/libavformat.framework/libavformat +0 -0
  311. package/common/cpp/audioapi/external/libavutil.xcframework/Info.plist +0 -44
  312. package/common/cpp/audioapi/external/libavutil.xcframework/ios-arm64/libavutil.framework/Info.plist +0 -1
  313. package/common/cpp/audioapi/external/libavutil.xcframework/ios-arm64/libavutil.framework/libavutil +0 -0
  314. package/common/cpp/audioapi/external/libavutil.xcframework/ios-arm64_x86_64-simulator/libavutil.framework/Info.plist +0 -1
  315. package/common/cpp/audioapi/external/libavutil.xcframework/ios-arm64_x86_64-simulator/libavutil.framework/libavutil +0 -0
  316. package/common/cpp/audioapi/external/libswresample.xcframework/Info.plist +0 -44
  317. package/common/cpp/audioapi/external/libswresample.xcframework/ios-arm64/libswresample.framework/Info.plist +0 -1
  318. package/common/cpp/audioapi/external/libswresample.xcframework/ios-arm64/libswresample.framework/libswresample +0 -0
  319. package/common/cpp/audioapi/external/libswresample.xcframework/ios-arm64_x86_64-simulator/libswresample.framework/Info.plist +0 -1
  320. package/common/cpp/audioapi/external/libswresample.xcframework/ios-arm64_x86_64-simulator/libswresample.framework/libswresample +0 -0
  321. package/common/cpp/audioapi/external/x86/libcrypto.a +0 -0
  322. package/common/cpp/audioapi/external/x86/libogg.a +0 -0
  323. package/common/cpp/audioapi/external/x86/libopus.a +0 -0
  324. package/common/cpp/audioapi/external/x86/libopusfile.a +0 -0
  325. package/common/cpp/audioapi/external/x86/libssl.a +0 -0
  326. package/common/cpp/audioapi/external/x86/libvorbis.a +0 -0
  327. package/common/cpp/audioapi/external/x86/libvorbisenc.a +0 -0
  328. package/common/cpp/audioapi/external/x86/libvorbisfile.a +0 -0
  329. package/common/cpp/audioapi/external/x86_64/libcrypto.a +0 -0
  330. package/common/cpp/audioapi/external/x86_64/libogg.a +0 -0
  331. package/common/cpp/audioapi/external/x86_64/libopus.a +0 -0
  332. package/common/cpp/audioapi/external/x86_64/libopusfile.a +0 -0
  333. package/common/cpp/audioapi/external/x86_64/libssl.a +0 -0
  334. package/common/cpp/audioapi/external/x86_64/libvorbis.a +0 -0
  335. package/common/cpp/audioapi/external/x86_64/libvorbisenc.a +0 -0
  336. package/common/cpp/audioapi/external/x86_64/libvorbisfile.a +0 -0
  337. package/common/cpp/audioapi/libs/ffmpeg/INSTRUCTIONS.md +0 -32
  338. package/common/cpp/audioapi/libs/ffmpeg/create_xcframework.sh +0 -111
  339. package/common/cpp/audioapi/libs/ffmpeg/ffmpeg_setup.sh +0 -391
  340. package/ios/audioapi/ios/core/IOSAudioFileOptions.h +0 -35
  341. package/ios/audioapi/ios/core/IOSAudioFileOptions.mm +0 -135
  342. package/ios/audioapi/ios/core/IOSAudioFileWriter.h +0 -38
  343. package/ios/audioapi/ios/core/IOSAudioFileWriter.mm +0 -187
  344. package/lib/commonjs/utils/bitEnums.js +0 -33
  345. package/lib/commonjs/utils/bitEnums.js.map +0 -1
  346. package/lib/module/utils/bitEnums.js +0 -27
  347. package/lib/module/utils/bitEnums.js.map +0 -1
  348. package/lib/typescript/utils/bitEnums.d.ts +0 -4
  349. package/lib/typescript/utils/bitEnums.d.ts.map +0 -1
  350. package/src/utils/bitEnums.ts +0 -51
@@ -5,131 +5,78 @@
5
5
  #include <audioapi/events/AudioEventHandlerRegistry.h>
6
6
  #include <audioapi/utils/AudioBus.h>
7
7
  #include <audioapi/utils/CircularAudioArray.h>
8
+ #include <audioapi/utils/CircularOverflowableAudioArray.h>
8
9
 
9
10
  namespace audioapi {
10
11
 
11
12
  AudioRecorder::AudioRecorder(
13
+ float sampleRate,
14
+ int bufferLength,
12
15
  const std::shared_ptr<AudioEventHandlerRegistry> &audioEventHandlerRegistry)
13
- : audioEventHandlerRegistry_(audioEventHandlerRegistry) {
16
+ : sampleRate_(sampleRate),
17
+ bufferLength_(bufferLength),
18
+ audioEventHandlerRegistry_(audioEventHandlerRegistry) {
19
+ constexpr int minRingBufferSize = 8192;
20
+ ringBufferSize_ = std::max(2 * bufferLength, minRingBufferSize);
21
+ circularBuffer_ = std::make_shared<CircularAudioArray>(ringBufferSize_);
14
22
  isRunning_.store(false);
15
- fileOutputEnabled_.store(false);
16
- callbackOutputEnabled_.store(false);
17
- isConnected_.store(false);
18
- }
19
-
20
- bool AudioRecorder::isRecording() {
21
- return isRunning_.load();
22
- }
23
-
24
- void AudioRecorder::connect(const std::shared_ptr<RecorderAdapterNode> &node) {
25
- // node->init();
26
- // adapterNodeLock_.lock();
27
- // adapterNode_ = node;
28
- // adapterNodeLock_.unlock();
29
- // isConnected_.store(true);
30
- // node->init(ringBufferSize_);
31
- // adapterNodeLock_.lock();
32
- // adapterNode_ = node;
33
- // adapterNodeLock_.unlock();
34
23
  }
35
24
 
36
- void AudioRecorder::disconnect() {
37
- // adapterNodeLock_.lock();
38
- // adapterNode_ = nullptr;
39
- // adapterNodeLock_.unlock();
40
- // isConnected_.store(false);
41
- }
42
-
43
- void AudioRecorder::setOnAudioReadyCallback(
44
- float sampleRate,
45
- size_t bufferLength,
46
- size_t channelCount,
47
- uint64_t callbackId) {
48
- callbackProperties_.sampleRate = sampleRate;
49
- callbackProperties_.bufferLength = bufferLength;
50
- callbackProperties_.channelCount = channelCount;
51
- callbackProperties_.callbackId = callbackId;
52
-
53
- callbackOutputEnabled_.store(true);
54
- }
55
-
56
- void AudioRecorder::clearOnAudioReadyCallback() {
57
- callbackOutputEnabled_.store(false);
58
- callbackProperties_ = CallbackProperties{};
25
+ void AudioRecorder::setOnAudioReadyCallbackId(uint64_t callbackId) {
26
+ onAudioReadyCallbackId_ = callbackId;
59
27
  }
60
28
 
61
29
  void AudioRecorder::invokeOnAudioReadyCallback(
62
30
  const std::shared_ptr<AudioBus> &bus,
63
31
  int numFrames) {
64
- // if (!hasCallback()) {
65
- // return;
66
- // }
67
-
68
- // auto audioBuffer = std::make_shared<AudioBuffer>(bus);
69
- // auto audioBufferHostObject =
70
- // std::make_shared<AudioBufferHostObject>(audioBuffer);
71
-
72
- // std::unordered_map<std::string, EventValue> body = {};
73
- // body.insert({"buffer", audioBufferHostObject});
74
- // body.insert({"numFrames", numFrames});
75
-
76
- // if (audioEventHandlerRegistry_ != nullptr) {
77
- // audioEventHandlerRegistry_->invokeHandlerWithEventBody(
78
- // "audioReady", onAudioReadyCallbackId_, body);
79
- // }
32
+ auto audioBuffer = std::make_shared<AudioBuffer>(bus);
33
+ auto audioBufferHostObject =
34
+ std::make_shared<AudioBufferHostObject>(audioBuffer);
35
+
36
+ std::unordered_map<std::string, EventValue> body = {};
37
+ body.insert({"buffer", audioBufferHostObject});
38
+ body.insert({"numFrames", numFrames});
39
+
40
+ if (audioEventHandlerRegistry_ != nullptr) {
41
+ audioEventHandlerRegistry_->invokeHandlerWithEventBody(
42
+ "audioReady", onAudioReadyCallbackId_, body);
43
+ }
80
44
  }
81
45
 
82
- void AudioRecorder::sendRemainingCallbackData() {
83
- // if (!hasCallback()) {
84
- // return;
85
- // }
86
-
87
- // auto bus = std::make_shared<AudioBus>(
88
- // circularBuffer_->getNumberOfAvailableFrames(), 1, sampleRate_);
89
- // auto *outputChannel = bus->getChannel(0)->getData();
90
- // auto availableFrames =
91
- // static_cast<int>(circularBuffer_->getNumberOfAvailableFrames());
46
+ void AudioRecorder::sendRemainingData() {
47
+ auto bus = std::make_shared<AudioBus>(
48
+ circularBuffer_->getNumberOfAvailableFrames(), 1, sampleRate_);
49
+ auto *outputChannel = bus->getChannel(0)->getData();
50
+ auto availableFrames =
51
+ static_cast<int>(circularBuffer_->getNumberOfAvailableFrames());
92
52
 
93
- // circularBuffer_->pop_front(
94
- // outputChannel, circularBuffer_->getNumberOfAvailableFrames());
53
+ circularBuffer_->pop_front(
54
+ outputChannel, circularBuffer_->getNumberOfAvailableFrames());
95
55
 
96
- // invokeOnAudioReadyCallback(bus, availableFrames);
56
+ invokeOnAudioReadyCallback(bus, availableFrames);
97
57
  }
98
58
 
99
- bool AudioRecorder::usesCallback() const {
100
- return callbackOutputEnabled_.load();
59
+ void AudioRecorder::connect(const std::shared_ptr<RecorderAdapterNode> &node) {
60
+ node->init(ringBufferSize_);
61
+ adapterNodeLock_.lock();
62
+ adapterNode_ = node;
63
+ adapterNodeLock_.unlock();
101
64
  }
102
65
 
103
- bool AudioRecorder::usesFileOutput() const {
104
- return fileOutputEnabled_.load();
66
+ void AudioRecorder::disconnect() {
67
+ adapterNodeLock_.lock();
68
+ adapterNode_ = nullptr;
69
+ adapterNodeLock_.unlock();
105
70
  }
106
71
 
107
- bool AudioRecorder::isConnected() const {
108
- return isConnected_.load();
72
+ void AudioRecorder::writeToBuffers(const float *data, int numFrames) {
73
+ if (adapterNodeLock_.try_lock()) {
74
+ if (adapterNode_ != nullptr) {
75
+ adapterNode_->buff_->write(data, numFrames);
76
+ }
77
+ adapterNodeLock_.unlock();
78
+ }
79
+ circularBuffer_->push_back(data, numFrames);
109
80
  }
110
81
 
111
- // AudioRecorder::AudioRecorder(
112
- // const std::shared_ptr<AudioEventHandlerRegistry>
113
- // &audioEventHandlerRegistry)
114
- // audioEventHandlerRegistry_(audioEventHandlerRegistry) {
115
- // constexpr int minRingBufferSize = 8192;
116
- // ringBufferSize_ = std::max(2 * bufferLength, minRingBufferSize);
117
-
118
- // circularBuffer_ = std::make_shared<CircularAudioArray>(ringBufferSize_);
119
- // isRunning_.store(false);
120
- // }
121
-
122
- // void AudioRecorder::writeToBuffers(const float *data, int numFrames) {
123
- // if (adapterNodeLock_.try_lock()) {
124
- // if (adapterNode_ != nullptr) {
125
- // adapterNode_->buff_->write(data, numFrames);
126
- // }
127
- // adapterNodeLock_.unlock();
128
- // }
129
-
130
- // if (hasCallback()) {
131
- // circularBuffer_->push_back(data, numFrames);
132
- // }
133
- // }
134
-
135
82
  } // namespace audioapi
@@ -3,71 +3,53 @@
3
3
  #include <memory>
4
4
  #include <atomic>
5
5
  #include <mutex>
6
- #include <string>
7
6
 
8
7
  namespace audioapi {
9
8
 
10
9
  class RecorderAdapterNode;
11
10
  class AudioBus;
12
11
  class CircularAudioArray;
12
+ class CircularOverflowableAudioArray;
13
13
  class AudioEventHandlerRegistry;
14
14
 
15
15
  class AudioRecorder {
16
16
  public:
17
- explicit AudioRecorder(const std::shared_ptr<AudioEventHandlerRegistry> &audioEventHandlerRegistry);
18
- virtual ~AudioRecorder() = default;
19
-
20
- virtual void start() = 0;
21
- virtual std::string stop() = 0;
22
-
23
- bool isRecording();
24
-
25
- virtual void enableFileOutput(
17
+ explicit AudioRecorder(
26
18
  float sampleRate,
27
- size_t channelCount,
28
- size_t bitRate,
29
- size_t iosFlags,
30
- size_t androidFlags) = 0;
31
- virtual void disableFileOutput() = 0;
19
+ int bufferLength,
20
+ const std::shared_ptr<AudioEventHandlerRegistry> &audioEventHandlerRegistry
21
+ );
32
22
 
33
- virtual void pause() = 0;
34
- virtual void resume() = 0;
23
+ virtual ~AudioRecorder() = default;
35
24
 
36
- void connect(const std::shared_ptr<RecorderAdapterNode> &node);
37
- void disconnect();
25
+ void setOnAudioReadyCallbackId(uint64_t callbackId);
26
+ void invokeOnAudioReadyCallback(const std::shared_ptr<AudioBus> &bus, int numFrames);
27
+ void sendRemainingData();
38
28
 
39
- void setOnAudioReadyCallback(
40
- float sampleRate,
41
- size_t bufferLength,
42
- size_t channelCount,
43
- uint64_t callbackId);
44
- void clearOnAudioReadyCallback();
29
+ /// @brief
30
+ /// # Connects the recorder to the adapter node.
31
+ ///
32
+ /// The adapter node will be used to read audio data from the recorder.
33
+ /// @note Few frames of audio might not yet be written to the buffer when connecting.
34
+ void connect(const std::shared_ptr<RecorderAdapterNode> &node);
45
35
 
46
- void invokeOnAudioReadyCallback(
47
- const std::shared_ptr<AudioBus> &bus,
48
- int numFrames);
49
- void sendRemainingCallbackData();
36
+ /// @brief
37
+ /// # Disconnects the recorder from the adapter node.
38
+ ///
39
+ /// The adapter node will no longer be used to read audio data from the recorder.
40
+ /// @note Last few frames of audio might be written to the buffer after disconnecting.
41
+ void disconnect();
50
42
 
51
- bool usesCallback() const;
52
- bool usesFileOutput() const;
53
- bool isConnected() const;
43
+ virtual void start() = 0;
44
+ virtual void stop() = 0;
54
45
 
55
46
  protected:
56
- struct CallbackProperties {
57
- float sampleRate;
58
- size_t bufferLength;
59
- size_t channelCount;
60
- uint64_t callbackId;
61
- };
62
-
63
- CallbackProperties callbackProperties_;
64
- // size_t ringBufferSize_;
47
+ float sampleRate_;
48
+ int bufferLength_;
49
+ size_t ringBufferSize_;
65
50
 
66
51
  std::atomic<bool> isRunning_;
67
- std::atomic<bool> fileOutputEnabled_;
68
- std::atomic<bool> callbackOutputEnabled_;
69
- std::atomic<bool> isConnected_;
70
- // std::shared_ptr<CircularAudioArray> circularBuffer_;
52
+ std::shared_ptr<CircularAudioArray> circularBuffer_;
71
53
 
72
54
  mutable std::mutex adapterNodeLock_;
73
55
  std::shared_ptr<RecorderAdapterNode> adapterNode_ = nullptr;
@@ -75,7 +57,7 @@ class AudioRecorder {
75
57
  std::shared_ptr<AudioEventHandlerRegistry> audioEventHandlerRegistry_;
76
58
  uint64_t onAudioReadyCallbackId_ = 0;
77
59
 
78
- // void writeToBuffers(const float *data, int numFrames);
60
+ void writeToBuffers(const float *data, int numFrames);
79
61
  };
80
62
 
81
63
  } // namespace audioapi
@@ -36,20 +36,15 @@ std::shared_ptr<AudioParam> AudioBufferBaseSourceNode::getPlaybackRateParam()
36
36
  return playbackRateParam_;
37
37
  }
38
38
 
39
- void AudioBufferBaseSourceNode::clearOnPositionChangedCallback() {
40
- if (onPositionChangedCallbackId_ == 0 || context_ == nullptr ||
41
- context_->audioEventHandlerRegistry_ == nullptr) {
42
- return;
43
- }
44
-
45
- context_->audioEventHandlerRegistry_->unregisterHandler(
46
- "positionChanged", onPositionChangedCallbackId_);
47
- onPositionChangedCallbackId_ = 0;
48
- }
49
-
50
39
  void AudioBufferBaseSourceNode::setOnPositionChangedCallbackId(
51
40
  uint64_t callbackId) {
52
- onPositionChangedCallbackId_ = callbackId;
41
+ auto oldCallbackId = onPositionChangedCallbackId_.exchange(
42
+ callbackId, std::memory_order_acq_rel);
43
+
44
+ if (oldCallbackId != 0) {
45
+ audioEventHandlerRegistry_->unregisterHandler(
46
+ "positionChanged", oldCallbackId);
47
+ }
53
48
  }
54
49
 
55
50
  void AudioBufferBaseSourceNode::setOnPositionChangedInterval(int interval) {
@@ -66,14 +61,16 @@ std::mutex &AudioBufferBaseSourceNode::getBufferLock() {
66
61
  }
67
62
 
68
63
  void AudioBufferBaseSourceNode::sendOnPositionChangedEvent() {
69
- if (onPositionChangedCallbackId_ != 0 &&
70
- onPositionChangedTime_ > onPositionChangedInterval_ &&
71
- context_->audioEventHandlerRegistry_ != nullptr) {
64
+ auto onPositionChangedCallbackId =
65
+ onPositionChangedCallbackId_.load(std::memory_order_acquire);
66
+
67
+ if (onPositionChangedCallbackId != 0 &&
68
+ onPositionChangedTime_ > onPositionChangedInterval_) {
72
69
  std::unordered_map<std::string, EventValue> body = {
73
70
  {"value", getCurrentPosition()}};
74
71
 
75
- context_->audioEventHandlerRegistry_->invokeHandlerWithEventBody(
76
- "positionChanged", onPositionChangedCallbackId_, body);
72
+ audioEventHandlerRegistry_->invokeHandlerWithEventBody(
73
+ "positionChanged", onPositionChangedCallbackId, body);
77
74
 
78
75
  onPositionChangedTime_ = 0;
79
76
  }
@@ -19,7 +19,6 @@ class AudioBufferBaseSourceNode : public AudioScheduledSourceNode {
19
19
  [[nodiscard]] std::shared_ptr<AudioParam> getDetuneParam() const;
20
20
  [[nodiscard]] std::shared_ptr<AudioParam> getPlaybackRateParam() const;
21
21
 
22
- void clearOnPositionChangedCallback();
23
22
  void setOnPositionChangedCallbackId(uint64_t callbackId);
24
23
  void setOnPositionChangedInterval(int interval);
25
24
  [[nodiscard]] int getOnPositionChangedInterval() const;
@@ -123,19 +123,13 @@ void AudioBufferSourceNode::disable() {
123
123
  alignedBus_.reset();
124
124
  }
125
125
 
126
- void AudioBufferSourceNode::clearOnLoopEndedCallback() {
127
- if (onLoopEndedCallbackId_ == 0 || context_ == nullptr ||
128
- context_->audioEventHandlerRegistry_ == nullptr) {
129
- return;
130
- }
131
-
132
- context_->audioEventHandlerRegistry_->unregisterHandler(
133
- "loopEnded", onLoopEndedCallbackId_);
134
- onLoopEndedCallbackId_ = 0;
135
- }
136
-
137
126
  void AudioBufferSourceNode::setOnLoopEndedCallbackId(uint64_t callbackId) {
138
- onLoopEndedCallbackId_ = callbackId;
127
+ auto oldCallbackId =
128
+ onLoopEndedCallbackId_.exchange(callbackId, std::memory_order_acq_rel);
129
+
130
+ if (oldCallbackId != 0) {
131
+ audioEventHandlerRegistry_->unregisterHandler("loopEnded", oldCallbackId);
132
+ }
139
133
  }
140
134
 
141
135
  std::shared_ptr<AudioBus> AudioBufferSourceNode::processNode(
@@ -171,8 +165,8 @@ void AudioBufferSourceNode::sendOnLoopEndedEvent() {
171
165
  auto onLoopEndedCallbackId =
172
166
  onLoopEndedCallbackId_.load(std::memory_order_acquire);
173
167
  if (onLoopEndedCallbackId != 0) {
174
- context_->audioEventHandlerRegistry_->invokeHandlerWithEventBody(
175
- "loopEnded", onLoopEndedCallbackId_, {});
168
+ audioEventHandlerRegistry_->invokeHandlerWithEventBody(
169
+ "loopEnded", onLoopEndedCallbackId, {});
176
170
  }
177
171
  }
178
172
 
@@ -34,7 +34,6 @@ class AudioBufferSourceNode : public AudioBufferBaseSourceNode {
34
34
  void start(double when, double offset, double duration = -1);
35
35
  void disable() override;
36
36
 
37
- void clearOnLoopEndedCallback();
38
37
  void setOnLoopEndedCallbackId(uint64_t callbackId);
39
38
 
40
39
  protected:
@@ -14,6 +14,7 @@ AudioScheduledSourceNode::AudioScheduledSourceNode(BaseAudioContext *context)
14
14
  stopTime_(-1.0),
15
15
  playbackState_(PlaybackState::UNSCHEDULED) {
16
16
  numberOfInputs_ = 0;
17
+ audioEventHandlerRegistry_ = context_->audioEventHandlerRegistry_;
17
18
  }
18
19
 
19
20
  void AudioScheduledSourceNode::start(double when) {
@@ -45,19 +46,13 @@ bool AudioScheduledSourceNode::isStopScheduled() {
45
46
  return playbackState_ == PlaybackState::STOP_SCHEDULED;
46
47
  }
47
48
 
48
- void AudioScheduledSourceNode::clearOnEndedCallback() {
49
- if (onEndedCallbackId_ == 0 || context_ == nullptr ||
50
- context_->audioEventHandlerRegistry_ == nullptr) {
51
- return;
52
- }
53
-
54
- context_->audioEventHandlerRegistry_->unregisterHandler(
55
- "ended", onEndedCallbackId_);
56
- onEndedCallbackId_ = 0;
57
- }
58
-
59
49
  void AudioScheduledSourceNode::setOnEndedCallbackId(const uint64_t callbackId) {
60
- onEndedCallbackId_ = callbackId;
50
+ auto oldCallbackId =
51
+ onEndedCallbackId_.exchange(callbackId, std::memory_order_acq_rel);
52
+
53
+ if (oldCallbackId != 0) {
54
+ audioEventHandlerRegistry_->unregisterHandler("ended", oldCallbackId);
55
+ }
61
56
  }
62
57
 
63
58
  void AudioScheduledSourceNode::updatePlaybackInfo(
@@ -76,7 +71,7 @@ void AudioScheduledSourceNode::updatePlaybackInfo(
76
71
  auto sampleRate = context_->getSampleRate();
77
72
 
78
73
  size_t firstFrame = context_->getCurrentSampleFrame();
79
- size_t lastFrame = firstFrame + framesToProcess;
74
+ size_t lastFrame = firstFrame + framesToProcess - 1;
80
75
 
81
76
  size_t startFrame =
82
77
  std::max(dsp::timeToSampleFrame(startTime_, sampleRate), firstFrame);
@@ -105,7 +100,7 @@ void AudioScheduledSourceNode::updatePlaybackInfo(
105
100
  ? std::max(startFrame, firstFrame) - firstFrame
106
101
  : 0;
107
102
  nonSilentFramesToProcess =
108
- std::max(std::min(lastFrame, stopFrame), startFrame) - startFrame;
103
+ std::max(std::min(lastFrame, stopFrame) + 1, startFrame) - startFrame;
109
104
 
110
105
  assert(startOffset <= framesToProcess);
111
106
  assert(nonSilentFramesToProcess <= framesToProcess);
@@ -124,7 +119,7 @@ void AudioScheduledSourceNode::updatePlaybackInfo(
124
119
 
125
120
  // stop will happen in this render quantum
126
121
  // zero remaining frames after stop frame
127
- if (stopFrame < lastFrame && stopFrame >= firstFrame) {
122
+ if (stopFrame <= lastFrame && stopFrame >= firstFrame) {
128
123
  playbackState_ = PlaybackState::STOP_SCHEDULED;
129
124
  startOffset = 0;
130
125
  nonSilentFramesToProcess = stopFrame - firstFrame;
@@ -160,9 +155,10 @@ void AudioScheduledSourceNode::updatePlaybackInfo(
160
155
  void AudioScheduledSourceNode::disable() {
161
156
  AudioNode::disable();
162
157
 
163
- if (context_->audioEventHandlerRegistry_ != nullptr) {
164
- context_->audioEventHandlerRegistry_->invokeHandlerWithEventBody(
165
- "ended", onEndedCallbackId_, {});
158
+ auto onEndedCallbackId = onEndedCallbackId_.load(std::memory_order_acquire);
159
+ if (onEndedCallbackId != 0) {
160
+ audioEventHandlerRegistry_->invokeHandlerWithEventBody(
161
+ "ended", onEndedCallbackId, {});
166
162
  }
167
163
  }
168
164
 
@@ -16,7 +16,7 @@
16
16
 
17
17
  namespace audioapi {
18
18
 
19
- class AudioEventHandlerRegistry;
19
+ class IAudioEventHandlerRegistry;
20
20
 
21
21
  class AudioScheduledSourceNode : public AudioNode {
22
22
  public:
@@ -37,7 +37,6 @@ class AudioScheduledSourceNode : public AudioNode {
37
37
  bool isFinished();
38
38
  bool isStopScheduled();
39
39
 
40
- void clearOnEndedCallback();
41
40
  void setOnEndedCallbackId(uint64_t callbackId);
42
41
 
43
42
  void disable() override;
@@ -49,6 +48,7 @@ class AudioScheduledSourceNode : public AudioNode {
49
48
  PlaybackState playbackState_;
50
49
 
51
50
  std::atomic<uint64_t> onEndedCallbackId_ = 0;
51
+ std::shared_ptr<IAudioEventHandlerRegistry> audioEventHandlerRegistry_;
52
52
 
53
53
  void updatePlaybackInfo(
54
54
  const std::shared_ptr<AudioBus>& processingBus,