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
package/README.md CHANGED
@@ -19,19 +19,8 @@ check out the [Getting Started](https://docs.swmansion.com/react-native-audio-ap
19
19
 
20
20
  ### Planned
21
21
 
22
- ### <img src="https://img.shields.io/badge/Coming_in-0.9.0-orange" />
23
-
24
- - **JS Audio Worklets V1 🐎**<br />
25
- Receive events and data callbacks from audio thread to synchronize with UI on UI thread.
26
-
27
22
  ### <img src="https://img.shields.io/badge/Coming_in-x.x.x-orange" />
28
23
 
29
- - **Convolver Node 🐐**<br />
30
- Realistic reverb and spatial effects in the browser by applying impulse responses. It makes audio sound like it’s being played in real spaces, from small rooms to cathedrals, or through hardware like amps and speakers
31
-
32
- - **Decoding and utility modules 🔧**<br />
33
- Decode and modify audio data without the need to create AudioContext first through a set of utility classes
34
-
35
24
  - **DynamicCompressorNode 〽️**<br />
36
25
  Reduce the volume of loud sounds and boost quieter nodes to balance the audio signal, avoid clipping or distorted sounds
37
26
 
@@ -47,9 +36,22 @@ check out the [Getting Started](https://docs.swmansion.com/react-native-audio-ap
47
36
  - **Noise Cancellation 🦇**<br />
48
37
  System-based active noise and echo cancellation support
49
38
 
39
+ ### <a href="https://github.com/software-mansion/react-native-audio-api/releases/tag/0.10.0"><img src="https://img.shields.io/badge/Released_in-0.10.0-green" /></a>
40
+
41
+ - **Decoding and utility modules 🔧**<br />
42
+ Decode and modify audio data without the need to create AudioContext first through a set of utility classes
43
+
44
+ - **Convolver Node 🐐**<br />
45
+ Realistic reverb and spatial effects in the browser by applying impulse responses. It makes audio sound like it’s being played in real spaces, from small rooms to cathedrals, or through hardware like amps and speakers
46
+
50
47
  - **JS Audio Worklets V2 🐎**<br />
51
48
  Customize the process pipeline with JS functions running on audio thread.
52
49
 
50
+ ### <a href="https://github.com/software-mansion/react-native-audio-api/releases/tag/0.9.0"><img src="https://img.shields.io/badge/Released_in-0.9.0-green" /></a>
51
+
52
+ - **JS Audio Worklets V1 🐎**<br />
53
+ Receive events and data callbacks from audio thread to synchronize with UI on UI thread.
54
+
53
55
  ### <a href="https://github.com/software-mansion/react-native-audio-api/releases/tag/0.8.0"><img src="https://img.shields.io/badge/Released_in-0.8.0-green" /></a>
54
56
 
55
57
  - **Decoding support for m4a/mp4/aac/ogg/opus 📁** <br />
@@ -1,4 +1,5 @@
1
1
  require "json"
2
+ require_relative './scripts/rnaa_utils'
2
3
 
3
4
  package_json = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
5
 
@@ -8,6 +9,8 @@ folly_flags = "-DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-
8
9
  fabric_flags = $new_arch_enabled ? '-DRCT_NEW_ARCH_ENABLED' : ''
9
10
  version_flag = "-DAUDIOAPI_VERSION=#{package_json['version']}"
10
11
 
12
+ worklets_preprocessor_flag = check_if_worklets_enabled() ? '-DRN_AUDIO_API_ENABLE_WORKLETS=1' : ''
13
+
11
14
  Pod::Spec.new do |s|
12
15
  s.name = "RNAudioAPI"
13
16
  s.version = package_json["version"]
@@ -29,15 +32,23 @@ Pod::Spec.new do |s|
29
32
  sss.header_dir = "audioapi"
30
33
  sss.header_mappings_dir = "ios/audioapi"
31
34
  end
35
+
36
+ ss.subspec "audioapi_dsp" do |sss|
37
+ sss.source_files = "common/cpp/audioapi/dsp/**/*.{cpp}"
38
+ sss.header_dir = "audioapi/dsp"
39
+ sss.header_mappings_dir = "common/cpp/audioapi/dsp"
40
+ sss.compiler_flags = "-O3"
41
+ end
32
42
  end
33
43
 
34
44
  s.ios.frameworks = 'CoreFoundation', 'CoreAudio', 'AudioToolbox', 'Accelerate', 'MediaPlayer', 'AVFoundation'
35
45
 
36
46
  s.compiler_flags = "#{folly_flags}"
37
47
 
38
- # s.prepare_command = <<-CMD TODO: re-add when we have prebuilt libs put somewhere public
39
- # ruby -r './scripts/download-audioapi-libs.rb'
40
- # CMD
48
+ s.prepare_command = <<-CMD
49
+ chmod +x scripts/download-prebuilt-binaries.sh
50
+ scripts/download-prebuilt-binaries.sh ios
51
+ CMD
41
52
 
42
53
  # Assumes Pods dir is nested under ios project dir
43
54
  ios_dir = File.join(Pod::Config.instance.project_pods_root, '..')
@@ -46,13 +57,11 @@ Pod::Spec.new do |s|
46
57
  external_dir_relative = "common/cpp/audioapi/external"
47
58
  lib_dir = "$(PROJECT_DIR)/#{rn_audio_dir_relative}/#{external_dir_relative}/$(PLATFORM_NAME)"
48
59
 
49
- external_dir = File.join(__dir__, "common/cpp/audioapi/external")
50
-
51
60
  s.ios.vendored_frameworks = [
52
- 'common/cpp/audioapi/external/libavcodec.xcframework',
53
- 'common/cpp/audioapi/external/libavformat.xcframework',
54
- 'common/cpp/audioapi/external/libavutil.xcframework',
55
- 'common/cpp/audioapi/external/libswresample.xcframework'
61
+ 'common/cpp/audioapi/external/ffmpeg_ios/libavcodec.xcframework',
62
+ 'common/cpp/audioapi/external/ffmpeg_ios/libavformat.xcframework',
63
+ 'common/cpp/audioapi/external/ffmpeg_ios/libavutil.xcframework',
64
+ 'common/cpp/audioapi/external/ffmpeg_ios/libswresample.xcframework'
56
65
  ]
57
66
  s.pod_target_xcconfig = {
58
67
  "USE_HEADERMAP" => "YES",
@@ -68,8 +77,8 @@ s.pod_target_xcconfig = {
68
77
  $(PODS_TARGET_SRCROOT)/#{external_dir_relative}/include/vorbis
69
78
  $(PODS_TARGET_SRCROOT)/#{external_dir_relative}/ffmpeg_include
70
79
  ].join(" "),
71
- 'OTHER_CFLAGS' => "$(inherited) #{folly_flags} #{fabric_flags} #{version_flag}",
72
- 'OTHER_CPLUSPLUSFLAGS' => "$(inherited) #{folly_flags} #{fabric_flags} #{version_flag}"
80
+ 'OTHER_CFLAGS' => "$(inherited) #{folly_flags} #{fabric_flags} #{version_flag} #{worklets_preprocessor_flag}",
81
+ 'OTHER_CPLUSPLUSFLAGS' => "$(inherited) #{folly_flags} #{fabric_flags} #{version_flag} #{worklets_preprocessor_flag}",
73
82
  }
74
83
 
75
84
  s.user_target_xcconfig = {
@@ -88,10 +97,6 @@ s.user_target_xcconfig = {
88
97
  $(inherited)
89
98
  $(PODS_ROOT)/Headers/Public/RNAudioAPI
90
99
  $(PODS_TARGET_SRCROOT)/common/cpp
91
- #{external_dir}/include
92
- #{external_dir}/include/opus
93
- #{external_dir}/include/vorbis
94
- #{external_dir}/ffmpeg_include
95
100
  ].join(' ')
96
101
  }
97
102
  # Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
@@ -74,6 +74,30 @@ def resolveReactNativeWorkletsDirectory() {
74
74
  return null;
75
75
  }
76
76
 
77
+ def validateWorkletsVersion() {
78
+ def validationScript = file("${projectDir}/../scripts/validate-worklets-version.js")
79
+ if (!validationScript.exists()) {
80
+ logger.error("[AudioAPI] Worklets validation script not found at ${validationScript.absolutePath}")
81
+ return false
82
+ }
83
+
84
+ try {
85
+ def process = ["node", validationScript.absolutePath].execute()
86
+ process.waitForProcessOutput(System.out, System.err)
87
+ def exitCode = process.exitValue()
88
+
89
+ if (exitCode == 0) {
90
+ return true
91
+ } else {
92
+ logger.warn("[AudioAPI] Worklets version validation failed")
93
+ return false
94
+ }
95
+ } catch (Exception e) {
96
+ logger.error("[AudioAPI] Failed to validate worklets version: ${e.message}")
97
+ return false
98
+ }
99
+ }
100
+
77
101
  def toPlatformFileString(String path) {
78
102
  if (Os.isFamily(Os.FAMILY_WINDOWS)) {
79
103
  path = path.replace(File.separatorChar, '/' as char)
@@ -92,7 +116,7 @@ static def supportsNamespace() {
92
116
 
93
117
  def reactNativeRootDir = resolveReactNativeDirectory()
94
118
  def reactNativeWorkletsRootDir = resolveReactNativeWorkletsDirectory()
95
- def isWorkletsAvailable = reactNativeWorkletsRootDir != null
119
+ def isWorkletsAvailable = reactNativeWorkletsRootDir != null && validateWorkletsVersion()
96
120
 
97
121
  def reactProperties = new Properties()
98
122
  file("$reactNativeRootDir/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) }
@@ -123,7 +147,7 @@ android {
123
147
  defaultConfig {
124
148
  minSdkVersion getExtOrIntegerDefault("minSdkVersion")
125
149
  targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
126
-
150
+
127
151
  buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
128
152
  buildConfigField "boolean", "RN_AUDIO_API_ENABLE_WORKLETS", "${isWorkletsAvailable}"
129
153
 
@@ -277,10 +301,16 @@ def assertMinimalReactNativeVersion = task assertMinimalReactNativeVersionTask {
277
301
  }
278
302
  }
279
303
 
304
+ task downloadPrebuiltBinaries(type: Exec) {
305
+ commandLine 'chmod', '+x', '../scripts/download-prebuilt-binaries.sh'
306
+ commandLine 'bash', '../scripts/download-prebuilt-binaries.sh'
307
+ args 'android'
308
+ }
309
+
280
310
  // Make preBuild depend on the download task
281
311
  tasks.preBuild {
282
312
  dependsOn assertMinimalReactNativeVersion
283
- // dependsOn downloadStaticPrebuiltLibraries TODO: re-add when we have prebuilt libs put somewhere public
313
+ dependsOn downloadPrebuiltBinaries
284
314
  }
285
315
 
286
316
  task cleanCmakeCache() {
@@ -3,14 +3,17 @@ cmake_minimum_required(VERSION 3.12.0)
3
3
  file(GLOB_RECURSE ANDROID_CPP_SOURCES CONFIGURE_DEPENDS "${ANDROID_CPP_DIR}/audioapi/*.cpp")
4
4
  file(GLOB_RECURSE COMMON_CPP_SOURCES CONFIGURE_DEPENDS "${COMMON_CPP_DIR}/audioapi/*.cpp" "${COMMON_CPP_DIR}/audioapi/*.c")
5
5
 
6
+ set_source_files_properties(
7
+ ${COMMON_CPP_SOURCES}/dsp/*.cpp
8
+ PROPERTIES
9
+ COMPILE_FLAGS "-O3"
10
+ )
11
+
6
12
  set(INCLUDE_DIR ${COMMON_CPP_DIR}/audioapi/external/include)
7
13
  set(FFMPEG_INCLUDE_DIR ${COMMON_CPP_DIR}/audioapi/external/ffmpeg_include)
8
14
  set(EXTERNAL_DIR ${COMMON_CPP_DIR}/audioapi/external)
9
15
  set(JNI_LIBS_DIR ${COMMON_CPP_DIR}/../../android/src/main/jniLibs)
10
16
 
11
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-Bsymbolic")
12
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,-Bsymbolic")
13
-
14
17
  add_library(react-native-audio-api SHARED ${ANDROID_CPP_SOURCES} ${COMMON_CPP_SOURCES})
15
18
 
16
19
  foreach(lib IN ITEMS opus opusfile ogg vorbis vorbisenc vorbisfile crypto ssl)
@@ -51,6 +51,7 @@ void AudioAPIModule::registerNatives() {
51
51
  makeNativeMethod(
52
52
  "invokeHandlerWithEventNameAndEventBody",
53
53
  AudioAPIModule::invokeHandlerWithEventNameAndEventBody),
54
+ makeNativeMethod("closeAllContexts", AudioAPIModule::closeAllContexts),
54
55
  });
55
56
  }
56
57
 
@@ -101,4 +102,8 @@ void AudioAPIModule::invokeHandlerWithEventNameAndEventBody(
101
102
  eventName->toStdString(), body);
102
103
  }
103
104
  }
105
+
106
+ void AudioAPIModule::closeAllContexts() {
107
+ AudioAPIModuleInstaller::closeAllContexts();
108
+ }
104
109
  } // namespace audioapi
@@ -34,6 +34,7 @@ class AudioAPIModule : public jni::HybridClass<AudioAPIModule> {
34
34
 
35
35
  void injectJSIBindings();
36
36
  void invokeHandlerWithEventNameAndEventBody(jni::alias_ref<jni::JString> eventName, jni::alias_ref<jni::JMap<jstring, jobject>> eventBody);
37
+ void closeAllContexts();
37
38
 
38
39
  private:
39
40
  friend HybridBase;
@@ -1,8 +1,4 @@
1
- #include <android/log.h>
2
1
  #include <audioapi/android/core/AndroidAudioRecorder.h>
3
- #include <audioapi/android/core/utils/AndroidFileWriterBackend.h>
4
- #include <audioapi/android/core/utils/ffmpegBackend/FFmpegFileWriter.h>
5
- #include <audioapi/android/core/utils/miniaudioBackend/MiniAudioFileWriter.h>
6
2
  #include <audioapi/core/sources/RecorderAdapterNode.h>
7
3
  #include <audioapi/core/utils/Constants.h>
8
4
  #include <audioapi/events/AudioEventHandlerRegistry.h>
@@ -14,23 +10,22 @@
14
10
  namespace audioapi {
15
11
 
16
12
  AndroidAudioRecorder::AndroidAudioRecorder(
13
+ float sampleRate,
14
+ int bufferLength,
17
15
  const std::shared_ptr<AudioEventHandlerRegistry> &audioEventHandlerRegistry)
18
- : AudioRecorder(audioEventHandlerRegistry) {
16
+ : AudioRecorder(sampleRate, bufferLength, audioEventHandlerRegistry) {
19
17
  AudioStreamBuilder builder;
20
-
21
18
  builder.setSharingMode(SharingMode::Exclusive)
22
19
  ->setDirection(Direction::Input)
23
20
  ->setFormat(AudioFormat::Float)
24
21
  ->setFormatConversionAllowed(true)
25
22
  ->setPerformanceMode(PerformanceMode::None)
23
+ ->setChannelCount(1)
26
24
  ->setSampleRateConversionQuality(SampleRateConversionQuality::Medium)
27
25
  ->setDataCallback(this)
26
+ ->setSampleRate(static_cast<int>(sampleRate))
28
27
  ->openStream(mStream_);
29
28
 
30
- streamSampleRate_ = mStream_->getSampleRate();
31
- streamChannelCount_ = mStream_->getChannelCount();
32
- streamMaxBufferSizeInFrames_ = mStream_->getBufferSizeInFrames();
33
-
34
29
  nativeAudioRecorder_ = jni::make_global(NativeAudioRecorder::create());
35
30
  }
36
31
 
@@ -45,113 +40,54 @@ AndroidAudioRecorder::~AndroidAudioRecorder() {
45
40
  }
46
41
 
47
42
  void AndroidAudioRecorder::start() {
48
- if (isRecording()) {
43
+ if (isRunning_.load()) {
49
44
  return;
50
45
  }
51
46
 
52
- if (!mStream_ || !nativeAudioRecorder_) {
53
- __android_log_print(
54
- ANDROID_LOG_ERROR,
55
- "AndroidAudioRecorder",
56
- "Audio stream is not initialized.\n");
57
- return;
58
- }
59
-
60
- if (usesFileOutput()) {
61
- fileWriter_->openFile(
62
- streamSampleRate_, streamChannelCount_, streamMaxBufferSizeInFrames_);
63
- }
64
-
65
- if (usesCallback()) {
66
- // TODO: create circular buffer and converter?
67
- }
68
-
69
- if (isConnected()) {
70
- // TODO: set adapter node properties?
47
+ if (mStream_) {
48
+ jni::ThreadScope::WithClassLoader(
49
+ [this]() { nativeAudioRecorder_->start(); });
50
+ mStream_->requestStart();
71
51
  }
72
52
 
73
- nativeAudioRecorder_->start();
74
- mStream_->requestStart();
75
53
  isRunning_.store(true);
76
54
  }
77
55
 
78
- std::string AndroidAudioRecorder::stop() {
79
- if (!isRecording()) {
80
- return "";
81
- }
82
-
83
- if (!mStream_ || !nativeAudioRecorder_) {
84
- __android_log_print(
85
- ANDROID_LOG_ERROR,
86
- "AndroidAudioRecorder",
87
- "Audio stream is not initialized.\n");
88
- return "";
56
+ void AndroidAudioRecorder::stop() {
57
+ if (!isRunning_.load()) {
58
+ return;
89
59
  }
90
60
 
91
- nativeAudioRecorder_->stop();
92
- mStream_->requestStop();
93
61
  isRunning_.store(false);
94
62
 
95
- // TODO: sendRemainingData() ?
96
-
97
- if (usesFileOutput()) {
98
- return fileWriter_->closeFile();
99
- }
100
-
101
- return "";
102
- }
103
-
104
- void AndroidAudioRecorder::enableFileOutput(
105
- float sampleRate,
106
- size_t channelCount,
107
- size_t bitRate,
108
- size_t iosFlags,
109
- size_t androidFlags) {
110
- uint8_t format = static_cast<uint8_t>(androidFlags & 0xF);
111
-
112
- if (format == 1) {
113
- fileWriter_ = std::make_shared<MiniAudioFileWriter>(
114
- sampleRate, channelCount, bitRate, androidFlags);
115
- } else {
116
- fileWriter_ = std::make_shared<FFmpegAudioFileWriter>(
117
- sampleRate, channelCount, bitRate, androidFlags);
63
+ if (mStream_) {
64
+ jni::ThreadScope::WithClassLoader(
65
+ [this]() { nativeAudioRecorder_->stop(); });
66
+ mStream_->requestStop();
118
67
  }
119
68
 
120
- fileOutputEnabled_.store(true);
69
+ sendRemainingData();
121
70
  }
122
71
 
123
- void AndroidAudioRecorder::disableFileOutput() {
124
- fileOutputEnabled_.store(false);
125
- fileWriter_ = nullptr;
126
- }
127
-
128
- void AndroidAudioRecorder::pause() {}
129
-
130
- void AndroidAudioRecorder::resume() {}
131
-
132
72
  DataCallbackResult AndroidAudioRecorder::onAudioReady(
133
73
  oboe::AudioStream *oboeStream,
134
74
  void *audioData,
135
75
  int32_t numFrames) {
136
- if (usesFileOutput()) {
137
- fileWriter_->writeAudioData(audioData, numFrames);
76
+ if (isRunning_.load()) {
77
+ auto *inputChannel = static_cast<float *>(audioData);
78
+ writeToBuffers(inputChannel, numFrames);
138
79
  }
139
80
 
140
- return DataCallbackResult::Continue;
141
- }
142
-
143
- } // namespace audioapi
81
+ while (circularBuffer_->getNumberOfAvailableFrames() >= bufferLength_) {
82
+ auto bus = std::make_shared<AudioBus>(bufferLength_, 1, sampleRate_);
83
+ auto *outputChannel = bus->getChannel(0)->getData();
144
84
 
145
- // if (isRunning_.load()) {
146
- // auto *inputChannel = static_cast<float *>(audioData);
147
- // writeToBuffers(inputChannel, numFrames);
148
- // }
85
+ circularBuffer_->pop_front(outputChannel, bufferLength_);
149
86
 
150
- // while (circularBuffer_->getNumberOfAvailableFrames() >= bufferLength_) {
151
- // auto bus = std::make_shared<AudioBus>(bufferLength_, 1, sampleRate_);
152
- // auto *outputChannel = bus->getChannel(0)->getData();
87
+ invokeOnAudioReadyCallback(bus, bufferLength_);
88
+ }
153
89
 
154
- // circularBuffer_->pop_front(outputChannel, bufferLength_);
90
+ return DataCallbackResult::Continue;
91
+ }
155
92
 
156
- // invokeOnAudioReadyCallback(bus, bufferLength_);
157
- // }
93
+ } // namespace audioapi
@@ -5,7 +5,6 @@
5
5
  #include <oboe/Oboe.h>
6
6
  #include <functional>
7
7
  #include <memory>
8
- #include <string>
9
8
 
10
9
  #include <audioapi/android/core/NativeAudioRecorder.hpp>
11
10
 
@@ -14,41 +13,28 @@ namespace audioapi {
14
13
  using namespace oboe;
15
14
 
16
15
  class AudioBus;
17
- class CircularAudioArray;
18
- class AndroidFileWriterBackend;
19
- class AudioEventHandlerRegistry;
20
16
 
21
17
  class AndroidAudioRecorder : public AudioStreamDataCallback, public AudioRecorder {
22
18
  public:
23
- explicit AndroidAudioRecorder(const std::shared_ptr<AudioEventHandlerRegistry> &audioEventHandlerRegistry);
24
- ~AndroidAudioRecorder() override;
19
+ AndroidAudioRecorder(float sampleRate,
20
+ int bufferLength,
21
+ const std::shared_ptr<AudioEventHandlerRegistry> &audioEventHandlerRegistry
22
+ );
25
23
 
26
- void start() override;
27
- std::string stop() override;
24
+ ~AndroidAudioRecorder() override;
28
25
 
29
- void enableFileOutput(
30
- float sampleRate,
31
- size_t channelCount,
32
- size_t bitRate,
33
- size_t iosFlags,
34
- size_t androidFlags) override;
35
- void disableFileOutput() override;
26
+ void start() override;
27
+ void stop() override;
36
28
 
37
- void pause() override;
38
- void resume() override;
39
-
40
- DataCallbackResult onAudioReady(
41
- AudioStream *oboeStream,
42
- void *audioData,
43
- int32_t numFrames) override;
29
+ DataCallbackResult onAudioReady(
30
+ AudioStream *oboeStream,
31
+ void *audioData,
32
+ int32_t numFrames) override;
44
33
 
45
34
  private:
46
- std::shared_ptr<AndroidFileWriterBackend> fileWriter_;
47
- std::shared_ptr<AudioStream> mStream_;
48
- facebook::jni::global_ref<NativeAudioRecorder> nativeAudioRecorder_;
49
- int32_t streamSampleRate_;
50
- int32_t streamChannelCount_;
51
- int32_t streamMaxBufferSizeInFrames_;
35
+ std::shared_ptr<AudioStream> mStream_;
36
+
37
+ facebook::jni::global_ref<NativeAudioRecorder> nativeAudioRecorder_;
52
38
  };
53
39
 
54
40
  } // namespace audioapi
@@ -4,6 +4,7 @@
4
4
  #include <audioapi/core/utils/Constants.h>
5
5
  #include <audioapi/utils/AudioArray.h>
6
6
  #include <audioapi/utils/AudioBus.h>
7
+ #include <jni.h>
7
8
 
8
9
  namespace audioapi {
9
10
 
@@ -49,7 +50,8 @@ bool AudioPlayer::openAudioStream() {
49
50
 
50
51
  bool AudioPlayer::start() {
51
52
  if (mStream_) {
52
- nativeAudioPlayer_->start();
53
+ jni::ThreadScope::WithClassLoader(
54
+ [this]() { nativeAudioPlayer_->start(); });
53
55
  auto result = mStream_->requestStart();
54
56
  return result == oboe::Result::OK;
55
57
  }
@@ -59,7 +61,7 @@ bool AudioPlayer::start() {
59
61
 
60
62
  void AudioPlayer::stop() {
61
63
  if (mStream_) {
62
- nativeAudioPlayer_->stop();
64
+ jni::ThreadScope::WithClassLoader([this]() { nativeAudioPlayer_->stop(); });
63
65
  mStream_->requestStop();
64
66
  }
65
67
  }
@@ -22,15 +22,15 @@ class NativeAudioRecorder : public jni::JavaClass<NativeAudioRecorder> {
22
22
  return newInstance();
23
23
  }
24
24
 
25
- void start() {
26
- static const auto method = javaClassStatic()->getMethod<void()>("start");
27
- method(self());
28
- }
29
-
30
- void stop() {
31
- static const auto method = javaClassStatic()->getMethod<void()>("stop");
32
- method(self());
33
- }
25
+ void start() {
26
+ static const auto method = javaClassStatic()->getMethod<void()>("start");
27
+ method(self());
28
+ }
29
+
30
+ void stop() {
31
+ static const auto method = javaClassStatic()->getMethod<void()>("stop");
32
+ method(self());
33
+ }
34
34
  };
35
35
 
36
36
  } // namespace audioapi
@@ -5,6 +5,7 @@
5
5
  #include <audioapi/utils/AudioArray.h>
6
6
  #include <audioapi/utils/AudioBus.h>
7
7
 
8
+ #define MINIAUDIO_IMPLEMENTATION
8
9
  #include <audioapi/libs/miniaudio/decoders/libopus/miniaudio_libopus.h>
9
10
  #include <audioapi/libs/miniaudio/decoders/libvorbis/miniaudio_libvorbis.h>
10
11
  #include <audioapi/libs/miniaudio/miniaudio.h>
@@ -98,6 +99,11 @@ std::shared_ptr<AudioBuffer> AudioDecoder::decodeWithFilePath(
98
99
  sizeof(customBackends) / sizeof(customBackends[0]);
99
100
 
100
101
  if (ma_decoder_init_file(path.c_str(), &config, &decoder) != MA_SUCCESS) {
102
+ __android_log_print(
103
+ ANDROID_LOG_ERROR,
104
+ "AudioDecoder",
105
+ "Failed to initialize decoder for file: %s",
106
+ path.c_str());
101
107
  ma_decoder_uninit(&decoder);
102
108
  return nullptr;
103
109
  }
@@ -1,6 +1,7 @@
1
1
  package com.swmansion.audioapi
2
2
 
3
3
  import com.facebook.jni.HybridData
4
+ import com.facebook.react.bridge.LifecycleEventListener
4
5
  import com.facebook.react.bridge.Promise
5
6
  import com.facebook.react.bridge.ReactApplicationContext
6
7
  import com.facebook.react.bridge.ReadableArray
@@ -9,7 +10,6 @@ import com.facebook.react.common.annotations.FrameworkAPI
9
10
  import com.facebook.react.module.annotations.ReactModule
10
11
  import com.facebook.react.turbomodule.core.CallInvokerHolderImpl
11
12
  import com.swmansion.audioapi.system.MediaSessionManager
12
- import com.swmansion.audioapi.system.NativeFileInfo
13
13
  import com.swmansion.audioapi.system.PermissionRequestListener
14
14
  import java.lang.ref.WeakReference
15
15
 
@@ -17,7 +17,8 @@ import java.lang.ref.WeakReference
17
17
  @ReactModule(name = AudioAPIModule.NAME)
18
18
  class AudioAPIModule(
19
19
  reactContext: ReactApplicationContext,
20
- ) : NativeAudioAPIModuleSpec(reactContext) {
20
+ ) : NativeAudioAPIModuleSpec(reactContext),
21
+ LifecycleEventListener {
21
22
  companion object {
22
23
  const val NAME = NativeAudioAPIModuleSpec.NAME
23
24
  }
@@ -39,6 +40,8 @@ class AudioAPIModule(
39
40
  eventBody: Map<String, Any>,
40
41
  )
41
42
 
43
+ private external fun closeAllContexts()
44
+
42
45
  init {
43
46
  try {
44
47
  System.loadLibrary("react-native-audio-api")
@@ -60,12 +63,33 @@ class AudioAPIModule(
60
63
 
61
64
  override fun install(): Boolean {
62
65
  MediaSessionManager.initialize(WeakReference(this), reactContext)
63
- NativeFileInfo.initialize(reactContext)
64
66
  injectJSIBindings()
65
67
 
66
68
  return true
67
69
  }
68
70
 
71
+ override fun onHostResume() {
72
+ // do nothing
73
+ }
74
+
75
+ override fun onHostPause() {
76
+ // do nothing
77
+ }
78
+
79
+ override fun onHostDestroy() {
80
+ closeAllContexts()
81
+ }
82
+
83
+ override fun initialize() {
84
+ reactContext.get()?.addLifecycleEventListener(this)
85
+ }
86
+
87
+ override fun invalidate() {
88
+ closeAllContexts()
89
+ reactContext.get()?.removeLifecycleEventListener(this)
90
+ // think about cleaning up resources, singletons etc.
91
+ }
92
+
69
93
  override fun getDevicePreferredSampleRate(): Double = MediaSessionManager.getDevicePreferredSampleRate()
70
94
 
71
95
  override fun setAudioSessionActivity(
@@ -84,6 +108,10 @@ class AudioAPIModule(
84
108
  // noting to do here
85
109
  }
86
110
 
111
+ override fun disableSessionManagement() {
112
+ // nothing to do here
113
+ }
114
+
87
115
  override fun setLockScreenInfo(info: ReadableMap?) {
88
116
  MediaSessionManager.setLockScreenInfo(info)
89
117
  }