react-native-audio-api 0.11.0-alpha.1 → 0.11.0-nightly-9f40b78-20251108

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 (362) 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 -142
  8. package/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.h +13 -40
  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/AudioContextHostObject.cpp +12 -17
  19. package/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.cpp +18 -0
  20. package/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.h +1 -0
  21. package/common/cpp/audioapi/HostObjects/OfflineAudioContextHostObject.cpp +26 -30
  22. package/common/cpp/audioapi/HostObjects/effects/BiquadFilterNodeHostObject.cpp +1 -1
  23. package/common/cpp/audioapi/HostObjects/effects/ConvolverNodeHostObject.cpp +47 -0
  24. package/common/cpp/audioapi/HostObjects/effects/ConvolverNodeHostObject.h +20 -0
  25. package/common/cpp/audioapi/HostObjects/inputs/AudioRecorderHostObject.cpp +18 -97
  26. package/common/cpp/audioapi/HostObjects/inputs/AudioRecorderHostObject.h +6 -18
  27. package/common/cpp/audioapi/HostObjects/sources/AudioBufferBaseSourceNodeHostObject.cpp +1 -1
  28. package/common/cpp/audioapi/HostObjects/sources/AudioBufferSourceNodeHostObject.cpp +1 -1
  29. package/common/cpp/audioapi/HostObjects/sources/AudioScheduledSourceNodeHostObject.cpp +1 -1
  30. package/common/cpp/audioapi/HostObjects/utils/AudioStretcherHostObject.cpp +15 -26
  31. package/common/cpp/audioapi/core/AudioNode.h +3 -2
  32. package/common/cpp/audioapi/core/AudioParam.cpp +2 -2
  33. package/common/cpp/audioapi/core/BaseAudioContext.cpp +10 -0
  34. package/common/cpp/audioapi/core/BaseAudioContext.h +2 -0
  35. package/common/cpp/audioapi/core/effects/BiquadFilterNode.cpp +69 -32
  36. package/common/cpp/audioapi/core/effects/BiquadFilterNode.h +37 -1
  37. package/common/cpp/audioapi/core/effects/ConvolverNode.cpp +210 -0
  38. package/common/cpp/audioapi/core/effects/ConvolverNode.h +55 -0
  39. package/common/cpp/audioapi/core/inputs/AudioRecorder.cpp +82 -36
  40. package/common/cpp/audioapi/core/inputs/AudioRecorder.h +31 -52
  41. package/common/cpp/audioapi/core/sources/AudioBufferBaseSourceNode.cpp +14 -17
  42. package/common/cpp/audioapi/core/sources/AudioBufferBaseSourceNode.h +0 -1
  43. package/common/cpp/audioapi/core/sources/AudioBufferQueueSourceNode.cpp +7 -0
  44. package/common/cpp/audioapi/core/sources/AudioBufferQueueSourceNode.h +1 -0
  45. package/common/cpp/audioapi/core/sources/AudioBufferSourceNode.cpp +8 -14
  46. package/common/cpp/audioapi/core/sources/AudioBufferSourceNode.h +0 -1
  47. package/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.cpp +14 -19
  48. package/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.h +3 -3
  49. package/common/cpp/audioapi/core/sources/StreamerNode.cpp +64 -64
  50. package/common/cpp/audioapi/core/sources/StreamerNode.h +38 -10
  51. package/common/cpp/audioapi/core/utils/AudioNodeManager.cpp +5 -0
  52. package/common/cpp/audioapi/core/utils/Constants.h +2 -1
  53. package/common/cpp/audioapi/core/utils/worklets/SafeIncludes.h +12 -8
  54. package/common/cpp/audioapi/core/utils/worklets/WorkletsRunner.cpp +3 -3
  55. package/common/cpp/audioapi/core/utils/worklets/WorkletsRunner.h +1 -1
  56. package/common/cpp/audioapi/dsp/AudioUtils.cpp +1 -1
  57. package/common/cpp/audioapi/dsp/Convolver.cpp +213 -0
  58. package/common/cpp/audioapi/dsp/Convolver.h +45 -0
  59. package/common/cpp/audioapi/dsp/FFT.cpp +0 -26
  60. package/common/cpp/audioapi/dsp/FFT.h +26 -2
  61. package/common/cpp/audioapi/events/AudioEventHandlerRegistry.h +1 -1
  62. package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/avcodec.h +4 -4
  63. package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/codec.h +1 -1
  64. package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/codec_desc.h +1 -1
  65. package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/codec_id.h +3 -1
  66. package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/codec_par.h +2 -2
  67. package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/defs.h +3 -0
  68. package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/packet.h +1 -1
  69. package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/smpte_436m.h +254 -0
  70. package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/version.h +1 -1
  71. package/common/cpp/audioapi/external/ffmpeg_include/libavformat/avformat.h +6 -6
  72. package/common/cpp/audioapi/external/ffmpeg_include/libavformat/version.h +2 -2
  73. package/common/cpp/audioapi/external/ffmpeg_include/libavformat/version_major.h +2 -0
  74. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/avassert.h +5 -2
  75. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/avutil.h +2 -2
  76. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/channel_layout.h +2 -2
  77. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/csp.h +1 -1
  78. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/dict.h +1 -1
  79. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/ffversion.h +1 -1
  80. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/film_grain_params.h +1 -1
  81. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/frame.h +1 -1
  82. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/hdr_dynamic_vivid_metadata.h +3 -3
  83. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/hwcontext.h +1 -1
  84. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/hwcontext_opencl.h +1 -1
  85. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/hwcontext_qsv.h +0 -1
  86. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/hwcontext_vulkan.h +1 -1
  87. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/iamf.h +2 -2
  88. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/lfg.h +2 -2
  89. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/log.h +2 -2
  90. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/mathematics.h +1 -1
  91. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/opt.h +4 -4
  92. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/rational.h +1 -1
  93. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/rc4.h +1 -1
  94. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/refstruct.h +1 -1
  95. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/spherical.h +6 -0
  96. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/tdrdi.h +1 -1
  97. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/tx.h +1 -1
  98. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/version.h +3 -3
  99. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/video_hint.h +1 -1
  100. package/common/cpp/audioapi/external/ffmpeg_include/libswresample/swresample.h +1 -1
  101. package/common/cpp/audioapi/external/ffmpeg_include/libswresample/version.h +1 -1
  102. package/common/cpp/audioapi/jsi/JsiPromise.cpp +33 -56
  103. package/common/cpp/audioapi/jsi/JsiPromise.h +41 -11
  104. package/common/cpp/audioapi/libs/ffmpeg/FFmpegDecoding.cpp +2 -3
  105. package/common/cpp/audioapi/libs/ffmpeg/relinking.md +24 -0
  106. package/common/cpp/audioapi/utils/AlignedAllocator.hpp +50 -0
  107. package/common/cpp/audioapi/utils/AudioBus.cpp +28 -0
  108. package/common/cpp/audioapi/utils/AudioBus.h +3 -0
  109. package/common/cpp/audioapi/utils/ThreadPool.hpp +59 -1
  110. package/common/cpp/test/CMakeLists.txt +19 -14
  111. package/common/cpp/test/src/AudioParamTest.cpp +1 -1
  112. package/common/cpp/test/src/AudioScheduledSourceTest.cpp +134 -0
  113. package/common/cpp/test/src/ConstantSourceTest.cpp +1 -1
  114. package/common/cpp/test/src/GainTest.cpp +1 -1
  115. package/common/cpp/test/src/MockAudioEventHandlerRegistry.h +4 -4
  116. package/common/cpp/test/src/OscillatorTest.cpp +1 -1
  117. package/common/cpp/test/src/StereoPannerTest.cpp +1 -1
  118. package/common/cpp/test/src/biquad/BiquadFilterChromium.cpp +389 -0
  119. package/common/cpp/test/src/biquad/BiquadFilterChromium.h +64 -0
  120. package/common/cpp/test/src/biquad/BiquadFilterTest.cpp +284 -0
  121. package/common/cpp/test/src/biquad/BiquadFilterTest.h +40 -0
  122. package/ios/audioapi/ios/AudioAPIModule.h +2 -1
  123. package/ios/audioapi/ios/AudioAPIModule.mm +34 -9
  124. package/ios/audioapi/ios/core/IOSAudioRecorder.h +10 -28
  125. package/ios/audioapi/ios/core/IOSAudioRecorder.mm +30 -117
  126. package/ios/audioapi/ios/core/NativeAudioRecorder.h +9 -4
  127. package/ios/audioapi/ios/core/NativeAudioRecorder.m +71 -29
  128. package/ios/audioapi/ios/core/utils/AudioDecoder.mm +0 -1
  129. package/ios/audioapi/ios/system/AudioEngine.mm +3 -3
  130. package/ios/audioapi/ios/system/AudioSessionManager.h +2 -0
  131. package/ios/audioapi/ios/system/AudioSessionManager.mm +24 -0
  132. package/ios/audioapi/ios/system/LockScreenManager.h +0 -1
  133. package/ios/audioapi/ios/system/LockScreenManager.mm +6 -19
  134. package/lib/commonjs/api.js +141 -76
  135. package/lib/commonjs/api.js.map +1 -1
  136. package/lib/commonjs/api.web.js +8 -0
  137. package/lib/commonjs/api.web.js.map +1 -1
  138. package/lib/commonjs/core/AudioContext.js +1 -1
  139. package/lib/commonjs/core/AudioContext.js.map +1 -1
  140. package/lib/commonjs/core/AudioRecorder.js +13 -171
  141. package/lib/commonjs/core/AudioRecorder.js.map +1 -1
  142. package/lib/commonjs/core/BaseAudioContext.js +28 -25
  143. package/lib/commonjs/core/BaseAudioContext.js.map +1 -1
  144. package/lib/commonjs/core/ConvolverNode.js +37 -0
  145. package/lib/commonjs/core/ConvolverNode.js.map +1 -0
  146. package/lib/commonjs/core/OfflineAudioContext.js +1 -1
  147. package/lib/commonjs/core/OfflineAudioContext.js.map +1 -1
  148. package/lib/commonjs/specs/NativeAudioAPIModule.js.map +1 -1
  149. package/lib/commonjs/system/AudioManager.js +3 -0
  150. package/lib/commonjs/system/AudioManager.js.map +1 -1
  151. package/lib/commonjs/types.js +0 -46
  152. package/lib/commonjs/types.js.map +1 -1
  153. package/lib/commonjs/utils/index.js +19 -21
  154. package/lib/commonjs/utils/index.js.map +1 -1
  155. package/lib/commonjs/web-core/AudioContext.js +12 -0
  156. package/lib/commonjs/web-core/AudioContext.js.map +1 -1
  157. package/lib/commonjs/web-core/ConvolverNode.js +40 -0
  158. package/lib/commonjs/web-core/ConvolverNode.js.map +1 -0
  159. package/lib/commonjs/web-core/ConvolverNodeOptions.js +6 -0
  160. package/lib/commonjs/web-core/ConvolverNodeOptions.js.map +1 -0
  161. package/lib/commonjs/web-core/OfflineAudioContext.js +12 -0
  162. package/lib/commonjs/web-core/OfflineAudioContext.js.map +1 -1
  163. package/lib/module/api.js +16 -15
  164. package/lib/module/api.js.map +1 -1
  165. package/lib/module/api.web.js +1 -0
  166. package/lib/module/api.web.js.map +1 -1
  167. package/lib/module/core/AudioContext.js +2 -2
  168. package/lib/module/core/AudioContext.js.map +1 -1
  169. package/lib/module/core/AudioRecorder.js +13 -171
  170. package/lib/module/core/AudioRecorder.js.map +1 -1
  171. package/lib/module/core/BaseAudioContext.js +29 -26
  172. package/lib/module/core/BaseAudioContext.js.map +1 -1
  173. package/lib/module/core/ConvolverNode.js +31 -0
  174. package/lib/module/core/ConvolverNode.js.map +1 -0
  175. package/lib/module/core/OfflineAudioContext.js +2 -2
  176. package/lib/module/core/OfflineAudioContext.js.map +1 -1
  177. package/lib/module/specs/NativeAudioAPIModule.js.map +1 -1
  178. package/lib/module/system/AudioManager.js +3 -0
  179. package/lib/module/system/AudioManager.js.map +1 -1
  180. package/lib/module/types.js +1 -45
  181. package/lib/module/types.js.map +1 -1
  182. package/lib/module/utils/index.js +15 -2
  183. package/lib/module/utils/index.js.map +1 -1
  184. package/lib/module/web-core/AudioContext.js +12 -0
  185. package/lib/module/web-core/AudioContext.js.map +1 -1
  186. package/lib/module/web-core/ConvolverNode.js +34 -0
  187. package/lib/module/web-core/ConvolverNode.js.map +1 -0
  188. package/lib/module/web-core/ConvolverNodeOptions.js +4 -0
  189. package/lib/module/web-core/ConvolverNodeOptions.js.map +1 -0
  190. package/lib/module/web-core/OfflineAudioContext.js +12 -0
  191. package/lib/module/web-core/OfflineAudioContext.js.map +1 -1
  192. package/lib/typescript/api.d.ts +19 -17
  193. package/lib/typescript/api.d.ts.map +1 -1
  194. package/lib/typescript/api.web.d.ts +1 -0
  195. package/lib/typescript/api.web.d.ts.map +1 -1
  196. package/lib/typescript/core/AudioContext.d.ts.map +1 -1
  197. package/lib/typescript/core/AudioRecorder.d.ts +7 -62
  198. package/lib/typescript/core/AudioRecorder.d.ts.map +1 -1
  199. package/lib/typescript/core/BaseAudioContext.d.ts +3 -1
  200. package/lib/typescript/core/BaseAudioContext.d.ts.map +1 -1
  201. package/lib/typescript/core/ConvolverNode.d.ts +12 -0
  202. package/lib/typescript/core/ConvolverNode.d.ts.map +1 -0
  203. package/lib/typescript/events/types.d.ts +0 -16
  204. package/lib/typescript/events/types.d.ts.map +1 -1
  205. package/lib/typescript/interfaces.d.ts +9 -42
  206. package/lib/typescript/interfaces.d.ts.map +1 -1
  207. package/lib/typescript/specs/NativeAudioAPIModule.d.ts +1 -0
  208. package/lib/typescript/specs/NativeAudioAPIModule.d.ts.map +1 -1
  209. package/lib/typescript/system/AudioManager.d.ts +1 -0
  210. package/lib/typescript/system/AudioManager.d.ts.map +1 -1
  211. package/lib/typescript/types.d.ts +8 -79
  212. package/lib/typescript/types.d.ts.map +1 -1
  213. package/lib/typescript/utils/index.d.ts +5 -2
  214. package/lib/typescript/utils/index.d.ts.map +1 -1
  215. package/lib/typescript/web-core/AudioContext.d.ts +3 -0
  216. package/lib/typescript/web-core/AudioContext.d.ts.map +1 -1
  217. package/lib/typescript/web-core/BaseAudioContext.d.ts +2 -0
  218. package/lib/typescript/web-core/BaseAudioContext.d.ts.map +1 -1
  219. package/lib/typescript/web-core/ConvolverNode.d.ts +11 -0
  220. package/lib/typescript/web-core/ConvolverNode.d.ts.map +1 -0
  221. package/lib/typescript/web-core/ConvolverNodeOptions.d.ts +6 -0
  222. package/lib/typescript/web-core/ConvolverNodeOptions.d.ts.map +1 -0
  223. package/lib/typescript/web-core/OfflineAudioContext.d.ts +3 -0
  224. package/lib/typescript/web-core/OfflineAudioContext.d.ts.map +1 -1
  225. package/package.json +14 -5
  226. package/scripts/download-prebuilt-binaries.sh +61 -0
  227. package/scripts/rnaa_utils.rb +8 -0
  228. package/scripts/validate-worklets-version.js +28 -0
  229. package/src/api.ts +45 -18
  230. package/src/api.web.ts +1 -0
  231. package/src/core/AudioContext.ts +3 -2
  232. package/src/core/AudioRecorder.ts +24 -211
  233. package/src/core/BaseAudioContext.ts +67 -60
  234. package/src/core/ConvolverNode.ts +35 -0
  235. package/src/core/OfflineAudioContext.ts +2 -2
  236. package/src/events/types.ts +0 -18
  237. package/src/interfaces.ts +16 -52
  238. package/src/specs/NativeAudioAPIModule.ts +1 -0
  239. package/src/system/AudioManager.ts +4 -0
  240. package/src/types.ts +9 -90
  241. package/src/utils/index.ts +22 -2
  242. package/src/web-core/AudioContext.tsx +25 -0
  243. package/src/web-core/BaseAudioContext.tsx +2 -0
  244. package/src/web-core/ConvolverNode.tsx +43 -0
  245. package/src/web-core/ConvolverNodeOptions.tsx +6 -0
  246. package/src/web-core/OfflineAudioContext.tsx +25 -0
  247. package/android/src/main/cpp/audioapi/android/core/utils/AndroidFileWriterBackend.h +0 -37
  248. package/android/src/main/cpp/audioapi/android/core/utils/AndroidRecorderCallback.cpp +0 -187
  249. package/android/src/main/cpp/audioapi/android/core/utils/AndroidRecorderCallback.h +0 -57
  250. package/android/src/main/cpp/audioapi/android/core/utils/FileUtils.h +0 -34
  251. package/android/src/main/cpp/audioapi/android/core/utils/FileUtilts.cpp +0 -133
  252. package/android/src/main/cpp/audioapi/android/core/utils/MiniaudioImplementation.cpp +0 -3
  253. package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/FFmpegAudioFileOptions.cpp +0 -154
  254. package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/FFmpegAudioFileOptions.h +0 -41
  255. package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/FFmpegFileWriter.cpp +0 -429
  256. package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/FFmpegFileWriter.h +0 -113
  257. package/android/src/main/cpp/audioapi/android/core/utils/miniaudioBackend/MiniAudioFileOptions.cpp +0 -47
  258. package/android/src/main/cpp/audioapi/android/core/utils/miniaudioBackend/MiniAudioFileOptions.h +0 -28
  259. package/android/src/main/cpp/audioapi/android/core/utils/miniaudioBackend/MiniAudioFileWriter.cpp +0 -269
  260. package/android/src/main/cpp/audioapi/android/core/utils/miniaudioBackend/MiniAudioFileWriter.h +0 -47
  261. package/android/src/main/cpp/audioapi/android/system/NativeFileInfo.hpp +0 -31
  262. package/android/src/main/java/com/swmansion/audioapi/system/NativeFileInfo.kt +0 -18
  263. package/android/src/main/jniLibs/arm64-v8a/libavcodec.so +0 -0
  264. package/android/src/main/jniLibs/arm64-v8a/libavformat.so +0 -0
  265. package/android/src/main/jniLibs/arm64-v8a/libavutil.so +0 -0
  266. package/android/src/main/jniLibs/arm64-v8a/libswresample.so +0 -0
  267. package/android/src/main/jniLibs/armeabi-v7a/libavcodec.so +0 -0
  268. package/android/src/main/jniLibs/armeabi-v7a/libavformat.so +0 -0
  269. package/android/src/main/jniLibs/armeabi-v7a/libavutil.so +0 -0
  270. package/android/src/main/jniLibs/armeabi-v7a/libswresample.so +0 -0
  271. package/android/src/main/jniLibs/x86/libavcodec.so +0 -0
  272. package/android/src/main/jniLibs/x86/libavformat.so +0 -0
  273. package/android/src/main/jniLibs/x86/libavutil.so +0 -0
  274. package/android/src/main/jniLibs/x86/libswresample.so +0 -0
  275. package/android/src/main/jniLibs/x86_64/libavcodec.so +0 -0
  276. package/android/src/main/jniLibs/x86_64/libavformat.so +0 -0
  277. package/android/src/main/jniLibs/x86_64/libavutil.so +0 -0
  278. package/android/src/main/jniLibs/x86_64/libswresample.so +0 -0
  279. package/common/cpp/audioapi/external/arm64-v8a/libcrypto.a +0 -0
  280. package/common/cpp/audioapi/external/arm64-v8a/libogg.a +0 -0
  281. package/common/cpp/audioapi/external/arm64-v8a/libopus.a +0 -0
  282. package/common/cpp/audioapi/external/arm64-v8a/libopusfile.a +0 -0
  283. package/common/cpp/audioapi/external/arm64-v8a/libssl.a +0 -0
  284. package/common/cpp/audioapi/external/arm64-v8a/libvorbis.a +0 -0
  285. package/common/cpp/audioapi/external/arm64-v8a/libvorbisenc.a +0 -0
  286. package/common/cpp/audioapi/external/arm64-v8a/libvorbisfile.a +0 -0
  287. package/common/cpp/audioapi/external/armeabi-v7a/libcrypto.a +0 -0
  288. package/common/cpp/audioapi/external/armeabi-v7a/libogg.a +0 -0
  289. package/common/cpp/audioapi/external/armeabi-v7a/libopus.a +0 -0
  290. package/common/cpp/audioapi/external/armeabi-v7a/libopusfile.a +0 -0
  291. package/common/cpp/audioapi/external/armeabi-v7a/libssl.a +0 -0
  292. package/common/cpp/audioapi/external/armeabi-v7a/libvorbis.a +0 -0
  293. package/common/cpp/audioapi/external/armeabi-v7a/libvorbisenc.a +0 -0
  294. package/common/cpp/audioapi/external/armeabi-v7a/libvorbisfile.a +0 -0
  295. package/common/cpp/audioapi/external/iphoneos/libcrypto.a +0 -0
  296. package/common/cpp/audioapi/external/iphoneos/libogg.a +0 -0
  297. package/common/cpp/audioapi/external/iphoneos/libopus.a +0 -0
  298. package/common/cpp/audioapi/external/iphoneos/libopusfile.a +0 -0
  299. package/common/cpp/audioapi/external/iphoneos/libssl.a +0 -0
  300. package/common/cpp/audioapi/external/iphoneos/libvorbis.a +0 -0
  301. package/common/cpp/audioapi/external/iphoneos/libvorbisenc.a +0 -0
  302. package/common/cpp/audioapi/external/iphoneos/libvorbisfile.a +0 -0
  303. package/common/cpp/audioapi/external/iphonesimulator/libcrypto.a +0 -0
  304. package/common/cpp/audioapi/external/iphonesimulator/libogg.a +0 -0
  305. package/common/cpp/audioapi/external/iphonesimulator/libopus.a +0 -0
  306. package/common/cpp/audioapi/external/iphonesimulator/libopusfile.a +0 -0
  307. package/common/cpp/audioapi/external/iphonesimulator/libssl.a +0 -0
  308. package/common/cpp/audioapi/external/iphonesimulator/libvorbis.a +0 -0
  309. package/common/cpp/audioapi/external/iphonesimulator/libvorbisenc.a +0 -0
  310. package/common/cpp/audioapi/external/iphonesimulator/libvorbisfile.a +0 -0
  311. package/common/cpp/audioapi/external/libavcodec.xcframework/Info.plist +0 -44
  312. package/common/cpp/audioapi/external/libavcodec.xcframework/ios-arm64/libavcodec.framework/Info.plist +0 -1
  313. package/common/cpp/audioapi/external/libavcodec.xcframework/ios-arm64/libavcodec.framework/libavcodec +0 -0
  314. package/common/cpp/audioapi/external/libavcodec.xcframework/ios-arm64_x86_64-simulator/libavcodec.framework/Info.plist +0 -1
  315. package/common/cpp/audioapi/external/libavcodec.xcframework/ios-arm64_x86_64-simulator/libavcodec.framework/libavcodec +0 -0
  316. package/common/cpp/audioapi/external/libavformat.xcframework/Info.plist +0 -44
  317. package/common/cpp/audioapi/external/libavformat.xcframework/ios-arm64/libavformat.framework/Info.plist +0 -1
  318. package/common/cpp/audioapi/external/libavformat.xcframework/ios-arm64/libavformat.framework/libavformat +0 -0
  319. package/common/cpp/audioapi/external/libavformat.xcframework/ios-arm64_x86_64-simulator/libavformat.framework/Info.plist +0 -1
  320. package/common/cpp/audioapi/external/libavformat.xcframework/ios-arm64_x86_64-simulator/libavformat.framework/libavformat +0 -0
  321. package/common/cpp/audioapi/external/libavutil.xcframework/Info.plist +0 -44
  322. package/common/cpp/audioapi/external/libavutil.xcframework/ios-arm64/libavutil.framework/Info.plist +0 -1
  323. package/common/cpp/audioapi/external/libavutil.xcframework/ios-arm64/libavutil.framework/libavutil +0 -0
  324. package/common/cpp/audioapi/external/libavutil.xcframework/ios-arm64_x86_64-simulator/libavutil.framework/Info.plist +0 -1
  325. package/common/cpp/audioapi/external/libavutil.xcframework/ios-arm64_x86_64-simulator/libavutil.framework/libavutil +0 -0
  326. package/common/cpp/audioapi/external/libswresample.xcframework/Info.plist +0 -44
  327. package/common/cpp/audioapi/external/libswresample.xcframework/ios-arm64/libswresample.framework/Info.plist +0 -1
  328. package/common/cpp/audioapi/external/libswresample.xcframework/ios-arm64/libswresample.framework/libswresample +0 -0
  329. package/common/cpp/audioapi/external/libswresample.xcframework/ios-arm64_x86_64-simulator/libswresample.framework/Info.plist +0 -1
  330. package/common/cpp/audioapi/external/libswresample.xcframework/ios-arm64_x86_64-simulator/libswresample.framework/libswresample +0 -0
  331. package/common/cpp/audioapi/external/x86/libcrypto.a +0 -0
  332. package/common/cpp/audioapi/external/x86/libogg.a +0 -0
  333. package/common/cpp/audioapi/external/x86/libopus.a +0 -0
  334. package/common/cpp/audioapi/external/x86/libopusfile.a +0 -0
  335. package/common/cpp/audioapi/external/x86/libssl.a +0 -0
  336. package/common/cpp/audioapi/external/x86/libvorbis.a +0 -0
  337. package/common/cpp/audioapi/external/x86/libvorbisenc.a +0 -0
  338. package/common/cpp/audioapi/external/x86/libvorbisfile.a +0 -0
  339. package/common/cpp/audioapi/external/x86_64/libcrypto.a +0 -0
  340. package/common/cpp/audioapi/external/x86_64/libogg.a +0 -0
  341. package/common/cpp/audioapi/external/x86_64/libopus.a +0 -0
  342. package/common/cpp/audioapi/external/x86_64/libopusfile.a +0 -0
  343. package/common/cpp/audioapi/external/x86_64/libssl.a +0 -0
  344. package/common/cpp/audioapi/external/x86_64/libvorbis.a +0 -0
  345. package/common/cpp/audioapi/external/x86_64/libvorbisenc.a +0 -0
  346. package/common/cpp/audioapi/external/x86_64/libvorbisfile.a +0 -0
  347. package/common/cpp/audioapi/libs/ffmpeg/INSTRUCTIONS.md +0 -32
  348. package/common/cpp/audioapi/libs/ffmpeg/create_xcframework.sh +0 -111
  349. package/common/cpp/audioapi/libs/ffmpeg/ffmpeg_setup.sh +0 -391
  350. package/ios/audioapi/ios/core/IOSAudioFileOptions.h +0 -36
  351. package/ios/audioapi/ios/core/IOSAudioFileOptions.mm +0 -140
  352. package/ios/audioapi/ios/core/IOSAudioFileWriter.h +0 -51
  353. package/ios/audioapi/ios/core/IOSAudioFileWriter.mm +0 -223
  354. package/ios/audioapi/ios/core/IOSRecorderCallback.h +0 -57
  355. package/ios/audioapi/ios/core/IOSRecorderCallback.mm +0 -189
  356. package/lib/commonjs/utils/bitEnums.js +0 -33
  357. package/lib/commonjs/utils/bitEnums.js.map +0 -1
  358. package/lib/module/utils/bitEnums.js +0 -27
  359. package/lib/module/utils/bitEnums.js.map +0 -1
  360. package/lib/typescript/utils/bitEnums.d.ts +0 -4
  361. package/lib/typescript/utils/bitEnums.d.ts.map +0 -1
  362. package/src/utils/bitEnums.ts +0 -51
@@ -0,0 +1,284 @@
1
+ #include <test/src/biquad/BiquadFilterChromium.h>
2
+ #include <test/src/biquad/BiquadFilterTest.h>
3
+
4
+ namespace audioapi {
5
+
6
+ void BiquadFilterTest::expectCoefficientsNear(
7
+ const std::shared_ptr<BiquadFilterNode> &biquadNode,
8
+ const BiquadCoefficients &expected) {
9
+ EXPECT_NEAR(biquadNode->b0_, expected.b0, tolerance);
10
+ EXPECT_NEAR(biquadNode->b1_, expected.b1, tolerance);
11
+ EXPECT_NEAR(biquadNode->b2_, expected.b2, tolerance);
12
+ EXPECT_NEAR(biquadNode->a1_, expected.a1, tolerance);
13
+ EXPECT_NEAR(biquadNode->a2_, expected.a2, tolerance);
14
+ }
15
+
16
+ void BiquadFilterTest::testLowpass(float frequency, float Q) {
17
+ auto node = std::make_shared<BiquadFilterNode>(context.get());
18
+ float normalizedFrequency = frequency / nyquistFrequency;
19
+
20
+ node->setLowpassCoefficients(normalizedFrequency, Q);
21
+ expectCoefficientsNear(
22
+ node, calculateLowpassCoefficients(normalizedFrequency, Q));
23
+ }
24
+
25
+ void BiquadFilterTest::testHighpass(float frequency, float Q) {
26
+ auto node = std::make_shared<BiquadFilterNode>(context.get());
27
+ float normalizedFrequency = frequency / nyquistFrequency;
28
+
29
+ node->setHighpassCoefficients(normalizedFrequency, Q);
30
+ expectCoefficientsNear(
31
+ node, calculateHighpassCoefficients(normalizedFrequency, Q));
32
+ }
33
+
34
+ void BiquadFilterTest::testBandpass(float frequency, float Q) {
35
+ auto node = std::make_shared<BiquadFilterNode>(context.get());
36
+ float normalizedFrequency = frequency / nyquistFrequency;
37
+
38
+ node->setBandpassCoefficients(normalizedFrequency, Q);
39
+ expectCoefficientsNear(
40
+ node, calculateBandpassCoefficients(normalizedFrequency, Q));
41
+ }
42
+
43
+ void BiquadFilterTest::testNotch(float frequency, float Q) {
44
+ auto node = std::make_shared<BiquadFilterNode>(context.get());
45
+ float normalizedFrequency = frequency / nyquistFrequency;
46
+
47
+ node->setNotchCoefficients(normalizedFrequency, Q);
48
+ expectCoefficientsNear(
49
+ node, calculateNotchCoefficients(normalizedFrequency, Q));
50
+ }
51
+
52
+ void BiquadFilterTest::testAllpass(float frequency, float Q) {
53
+ auto node = std::make_shared<BiquadFilterNode>(context.get());
54
+ float normalizedFrequency = frequency / nyquistFrequency;
55
+
56
+ node->setAllpassCoefficients(normalizedFrequency, Q);
57
+ expectCoefficientsNear(
58
+ node, calculateAllpassCoefficients(normalizedFrequency, Q));
59
+ }
60
+
61
+ void BiquadFilterTest::testPeaking(float frequency, float Q, float gain) {
62
+ auto node = std::make_shared<BiquadFilterNode>(context.get());
63
+ float normalizedFrequency = frequency / nyquistFrequency;
64
+
65
+ node->setPeakingCoefficients(normalizedFrequency, Q, gain);
66
+ expectCoefficientsNear(
67
+ node, calculatePeakingCoefficients(normalizedFrequency, Q, gain));
68
+ }
69
+
70
+ void BiquadFilterTest::testLowshelf(float frequency, float gain) {
71
+ auto node = std::make_shared<BiquadFilterNode>(context.get());
72
+ float normalizedFrequency = frequency / nyquistFrequency;
73
+
74
+ node->setLowshelfCoefficients(normalizedFrequency, gain);
75
+ expectCoefficientsNear(
76
+ node, calculateLowshelfCoefficients(normalizedFrequency, gain));
77
+ }
78
+
79
+ void BiquadFilterTest::testHighshelf(float frequency, float gain) {
80
+ auto node = std::make_shared<BiquadFilterNode>(context.get());
81
+ float normalizedFrequency = frequency / nyquistFrequency;
82
+
83
+ node->setHighshelfCoefficients(normalizedFrequency, gain);
84
+ expectCoefficientsNear(
85
+ node, calculateHighshelfCoefficients(normalizedFrequency, gain));
86
+ }
87
+
88
+ INSTANTIATE_TEST_SUITE_P(
89
+ Frequencies,
90
+ BiquadFilterFrequencyTest,
91
+ ::testing::Values(
92
+ 0.0f, // 0 Hz - the filter should block all input signal
93
+ 10.0f, // very low frequency
94
+ 350.0f, // default
95
+ nyquistFrequency - 0.0001f, // frequency near Nyquist
96
+ nyquistFrequency)); // maximal frequency
97
+
98
+ INSTANTIATE_TEST_SUITE_P(
99
+ QEdgeCases,
100
+ BiquadFilterQTestLowpassHighpass,
101
+ ::testing::Values(
102
+ -770.63678f, // min value for lowpass and highpass
103
+ 0.0f, // default
104
+ 770.63678f)); // max value for lowpass and highpass
105
+
106
+ INSTANTIATE_TEST_SUITE_P(
107
+ QEdgeCases,
108
+ BiquadFilterQTestRestTypes, // bandpass, notch, allpass, peaking
109
+ ::testing::Values(
110
+ 0.0f, // default and min value
111
+ MOST_POSITIVE_SINGLE_FLOAT));
112
+
113
+ INSTANTIATE_TEST_SUITE_P(
114
+ GainEdgeCases,
115
+ BiquadFilterGainTest,
116
+ ::testing::Values(
117
+ -40.0f,
118
+ 0.0f, // default
119
+ 40.0f));
120
+
121
+ TEST_P(BiquadFilterFrequencyTest, SetLowpassCoefficients) {
122
+ float frequency = GetParam();
123
+ float Q = 1.0f;
124
+ testLowpass(frequency, Q);
125
+ }
126
+
127
+ TEST_P(BiquadFilterFrequencyTest, SetHighpassCoefficients) {
128
+ float frequency = GetParam();
129
+ float Q = 1.0f;
130
+ testHighpass(frequency, Q);
131
+ }
132
+
133
+ TEST_P(BiquadFilterFrequencyTest, SetBandpassCoefficients) {
134
+ float frequency = GetParam();
135
+ float Q = 1.0f;
136
+ testBandpass(frequency, Q);
137
+ }
138
+
139
+ TEST_P(BiquadFilterFrequencyTest, SetNotchCoefficients) {
140
+ float frequency = GetParam();
141
+ float Q = 1.0f;
142
+ testNotch(frequency, Q);
143
+ }
144
+
145
+ TEST_P(BiquadFilterFrequencyTest, SetAllpassCoefficients) {
146
+ float frequency = GetParam();
147
+ float Q = 1.0f;
148
+ testAllpass(frequency, Q);
149
+ }
150
+
151
+ TEST_P(BiquadFilterFrequencyTest, SetPeakingCoefficients) {
152
+ float frequency = GetParam();
153
+ float Q = 1.0f;
154
+ float gain = 2.0f;
155
+ testPeaking(frequency, Q, gain);
156
+ }
157
+
158
+ TEST_P(BiquadFilterFrequencyTest, SetLowshelfCoefficients) {
159
+ float frequency = GetParam();
160
+ float gain = 2.0f;
161
+ testLowshelf(frequency, gain);
162
+ }
163
+
164
+ TEST_P(BiquadFilterFrequencyTest, SetHighshelfCoefficients) {
165
+ float frequency = GetParam();
166
+ float gain = 2.0f;
167
+ testHighshelf(frequency, gain);
168
+ }
169
+
170
+ TEST_P(BiquadFilterQTestLowpassHighpass, SetLowpassCoefficients) {
171
+ float frequency = 1000.0f;
172
+ float Q = GetParam();
173
+ testLowpass(frequency, Q);
174
+ }
175
+
176
+ TEST_P(BiquadFilterQTestLowpassHighpass, SetHighpassCoefficients) {
177
+ float frequency = 1000.0f;
178
+ float Q = GetParam();
179
+ testHighpass(frequency, Q);
180
+ }
181
+
182
+ TEST_P(BiquadFilterQTestRestTypes, SetBandpassCoefficients) {
183
+ float frequency = 1000.0f;
184
+ float Q = GetParam();
185
+ testBandpass(frequency, Q);
186
+ }
187
+
188
+ TEST_P(BiquadFilterQTestRestTypes, SetNotchCoefficients) {
189
+ float frequency = 1000.0f;
190
+ float Q = GetParam();
191
+ testNotch(frequency, Q);
192
+ }
193
+
194
+ TEST_P(BiquadFilterQTestRestTypes, SetAllpassCoefficients) {
195
+ float frequency = 1000.0f;
196
+ float Q = GetParam();
197
+ testAllpass(frequency, Q);
198
+ }
199
+
200
+ TEST_P(BiquadFilterQTestRestTypes, SetPeakingCoefficients) {
201
+ float frequency = 1000.0f;
202
+ float Q = GetParam();
203
+ float gain = 2.0f;
204
+ testPeaking(frequency, Q, gain);
205
+ }
206
+
207
+ TEST_P(BiquadFilterGainTest, SetPeakingCoefficients) {
208
+ float frequency = 1000.0f;
209
+ float Q = 1.0f;
210
+ float gain = GetParam();
211
+ testPeaking(frequency, Q, gain);
212
+ }
213
+
214
+ TEST_P(BiquadFilterGainTest, SetLowshelfCoefficients) {
215
+ float frequency = 1000.0f;
216
+ float gain = GetParam();
217
+ testLowshelf(frequency, gain);
218
+ }
219
+
220
+ TEST_P(BiquadFilterGainTest, SetHighshelfCoefficients) {
221
+ float frequency = 1000.0f;
222
+ float gain = GetParam();
223
+ testHighshelf(frequency, gain);
224
+ }
225
+
226
+ TEST_F(BiquadFilterTest, GetFrequencyResponse) {
227
+ auto node = std::make_shared<BiquadFilterNode>(context.get());
228
+
229
+ float frequency = 1000.0f;
230
+ float Q = 1.0f;
231
+ float normalizedFrequency = frequency / nyquistFrequency;
232
+
233
+ node->setLowpassCoefficients(normalizedFrequency, Q);
234
+ auto coeffs = calculateLowpassCoefficients(normalizedFrequency, Q);
235
+
236
+ std::vector<float> TestFrequencies = {
237
+ -0.0001f,
238
+ 0.0f,
239
+ 0.0001f,
240
+ 0.25f * nyquistFrequency,
241
+ 0.5f * nyquistFrequency,
242
+ 0.75f * nyquistFrequency,
243
+ nyquistFrequency - 0.0001f,
244
+ nyquistFrequency,
245
+ nyquistFrequency + 0.0001f};
246
+
247
+ std::vector<float> magResponseNode(TestFrequencies.size());
248
+ std::vector<float> phaseResponseNode(TestFrequencies.size());
249
+ std::vector<float> magResponseExpected(TestFrequencies.size());
250
+ std::vector<float> phaseResponseExpected(TestFrequencies.size());
251
+
252
+ node->getFrequencyResponse(
253
+ TestFrequencies.data(),
254
+ magResponseNode.data(),
255
+ phaseResponseNode.data(),
256
+ TestFrequencies.size());
257
+ getFrequencyResponse(
258
+ coeffs,
259
+ TestFrequencies,
260
+ magResponseExpected,
261
+ phaseResponseExpected,
262
+ nyquistFrequency);
263
+
264
+ for (size_t i = 0; i < TestFrequencies.size(); ++i) {
265
+ float f = TestFrequencies[i];
266
+ if (std::isnan(magResponseExpected[i])) {
267
+ EXPECT_TRUE(std::isnan(magResponseNode[i]))
268
+ << "Expected NaN at frequency " << f;
269
+ } else {
270
+ EXPECT_NEAR(magResponseNode[i], magResponseExpected[i], tolerance)
271
+ << "Magnitude mismatch at " << f << " Hz";
272
+ }
273
+
274
+ if (std::isnan(phaseResponseExpected[i])) {
275
+ EXPECT_TRUE(std::isnan(phaseResponseNode[i]))
276
+ << "Expected NaN at frequency " << f;
277
+ } else {
278
+ EXPECT_NEAR(phaseResponseNode[i], phaseResponseExpected[i], tolerance)
279
+ << "Phase mismatch at " << f << " Hz";
280
+ }
281
+ }
282
+ }
283
+
284
+ } // namespace audioapi
@@ -0,0 +1,40 @@
1
+ #pragma once
2
+
3
+ #include <audioapi/core/OfflineAudioContext.h>
4
+ #include <audioapi/core/effects/BiquadFilterNode.h>
5
+ #include <audioapi/core/utils/worklets/SafeIncludes.h>
6
+ #include <gtest/gtest.h>
7
+ #include <test/src/MockAudioEventHandlerRegistry.h>
8
+ #include <memory>
9
+
10
+ static constexpr int sampleRate = 44100;
11
+ static constexpr float nyquistFrequency = sampleRate / 2.0f;
12
+ static constexpr float tolerance = 0.0001f;
13
+
14
+ namespace audioapi {
15
+ class BiquadFilterTest : public ::testing::Test {
16
+ protected:
17
+ std::shared_ptr<MockAudioEventHandlerRegistry> eventRegistry;
18
+ std::unique_ptr<OfflineAudioContext> context;
19
+
20
+ void SetUp() override {
21
+ eventRegistry = std::make_shared<MockAudioEventHandlerRegistry>();
22
+ context = std::make_unique<OfflineAudioContext>(2, 5 * sampleRate, sampleRate, eventRegistry, RuntimeRegistry{});
23
+ }
24
+
25
+ void expectCoefficientsNear(const std::shared_ptr<BiquadFilterNode> &node, const BiquadCoefficients &expected);
26
+ void testLowpass(float frequency, float Q);
27
+ void testHighpass(float frequency, float Q);
28
+ void testBandpass(float frequency, float Q);
29
+ void testNotch(float frequency, float Q);
30
+ void testAllpass(float frequency, float Q);
31
+ void testPeaking(float frequency, float Q, float gain);
32
+ void testLowshelf(float frequency, float gain);
33
+ void testHighshelf(float frequency, float gain);
34
+ };
35
+
36
+ class BiquadFilterQTestLowpassHighpass : public BiquadFilterTest, public ::testing::WithParamInterface<float> {};
37
+ class BiquadFilterQTestRestTypes : public BiquadFilterTest, public ::testing::WithParamInterface<float> {};
38
+ class BiquadFilterFrequencyTest : public BiquadFilterTest, public ::testing::WithParamInterface<float> {};
39
+ class BiquadFilterGainTest : public BiquadFilterTest, public ::testing::WithParamInterface<float> {};
40
+ } // namespace audioapi
@@ -1,5 +1,6 @@
1
1
  #ifdef RCT_NEW_ARCH_ENABLED
2
2
  #import <React/RCTCallInvokerModule.h>
3
+ #import <React/RCTInvalidating.h>
3
4
  #import <rnaudioapi/rnaudioapi.h>
4
5
  #else // RCT_NEW_ARCH_ENABLED
5
6
  #import <React/RCTBridgeModule.h>
@@ -14,7 +15,7 @@
14
15
 
15
16
  @interface AudioAPIModule : RCTEventEmitter
16
17
  #ifdef RCT_NEW_ARCH_ENABLED
17
- <NativeAudioAPIModuleSpec, RCTCallInvokerModule>
18
+ <NativeAudioAPIModuleSpec, RCTCallInvokerModule, RCTInvalidating>
18
19
  #else
19
20
  <RCTBridgeModule>
20
21
  #endif // RCT_NEW_ARCH_ENABLED
@@ -54,6 +54,8 @@ RCT_EXPORT_MODULE(AudioAPIModule);
54
54
 
55
55
  _eventHandler = nullptr;
56
56
 
57
+ audioapi::AudioAPIModuleInstaller::closeAllContexts();
58
+
57
59
  [super invalidate];
58
60
  }
59
61
 
@@ -116,18 +118,25 @@ RCT_EXPORT_METHOD(
116
118
  setAudioSessionActivity : (BOOL)enabled resolve : (RCTPromiseResolveBlock)resolve reject : (RCTPromiseRejectBlock)
117
119
  reject)
118
120
  {
119
- if ([self.audioSessionManager setActive:enabled]) {
120
- resolve(@"true");
121
- return;
122
- }
123
-
124
- resolve(@"false");
121
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
122
+ if (!self.audioSessionManager.shouldManageSession) {
123
+ [self.audioSessionManager setShouldManageSession:true];
124
+ }
125
+ if ([self.audioSessionManager setActive:enabled]) {
126
+ resolve(@"true");
127
+ return;
128
+ }
129
+ resolve(@"false");
130
+ });
125
131
  }
126
132
 
127
133
  RCT_EXPORT_METHOD(
128
134
  setAudioSessionOptions : (NSString *)category mode : (NSString *)mode options : (NSArray *)
129
135
  options allowHaptics : (BOOL)allowHaptics)
130
136
  {
137
+ if (!self.audioSessionManager.shouldManageSession) {
138
+ [self.audioSessionManager setShouldManageSession:true];
139
+ }
131
140
  [self.audioSessionManager setAudioSessionOptions:category mode:mode options:options allowHaptics:allowHaptics];
132
141
  }
133
142
 
@@ -165,19 +174,30 @@ RCT_EXPORT_METHOD(
165
174
  requestRecordingPermissions : (nonnull RCTPromiseResolveBlock)resolve reject : (nonnull RCTPromiseRejectBlock)
166
175
  reject)
167
176
  {
168
- [self.audioSessionManager requestRecordingPermissions:resolve reject:reject];
177
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
178
+ [self.audioSessionManager requestRecordingPermissions:resolve reject:reject];
179
+ });
169
180
  }
170
181
 
171
182
  RCT_EXPORT_METHOD(
172
183
  checkRecordingPermissions : (nonnull RCTPromiseResolveBlock)resolve reject : (nonnull RCTPromiseRejectBlock)reject)
173
184
  {
174
- [self.audioSessionManager checkRecordingPermissions:resolve reject:reject];
185
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
186
+ [self.audioSessionManager checkRecordingPermissions:resolve reject:reject];
187
+ });
175
188
  }
176
189
 
177
190
  RCT_EXPORT_METHOD(
178
191
  getDevicesInfo : (nonnull RCTPromiseResolveBlock)resolve reject : (nonnull RCTPromiseRejectBlock)reject)
179
192
  {
180
- [self.audioSessionManager getDevicesInfo:resolve reject:reject];
193
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
194
+ [self.audioSessionManager getDevicesInfo:resolve reject:reject];
195
+ });
196
+ }
197
+
198
+ RCT_EXPORT_METHOD(disableSessionManagement)
199
+ {
200
+ [self.audioSessionManager disableSessionManagement];
181
201
  }
182
202
 
183
203
  #ifdef RCT_NEW_ARCH_ENABLED
@@ -220,4 +240,9 @@ RCT_EXPORT_METHOD(
220
240
  }
221
241
  }
222
242
 
243
+ - (dispatch_queue_t)methodQueue
244
+ {
245
+ return dispatch_queue_create("swmansion.audioapi.Queue", DISPATCH_QUEUE_SERIAL);
246
+ }
247
+
223
248
  @end
@@ -1,11 +1,8 @@
1
1
  #pragma once
2
2
 
3
- #ifdef __OBJC__ // when compiled as C++
3
+ #ifdef __OBJC__ // when compiled as Objective-C++
4
4
  #import <NativeAudioRecorder.h>
5
- #else
6
- typedef struct objc_object AVAudioFile;
7
- typedef struct objc_object NSURL;
8
- typedef struct objc_object AudioBufferList;
5
+ #else // when compiled as C++
9
6
  typedef struct objc_object NativeAudioRecorder;
10
7
  #endif // __OBJC__
11
8
 
@@ -15,36 +12,21 @@ namespace audioapi {
15
12
 
16
13
  class AudioBus;
17
14
  class CircularAudioArray;
18
- class IOSAudioFileWriter;
19
- class IOSRecorderCallback;
20
- class AudioEventHandlerRegistry;
21
15
 
22
16
  class IOSAudioRecorder : public AudioRecorder {
23
17
  public:
24
- IOSAudioRecorder(const std::shared_ptr<AudioEventHandlerRegistry> &audioEventHandlerRegistry);
25
- ~IOSAudioRecorder() override;
26
-
27
- std::string start() override;
28
- std::tuple<std::string, double, double> stop() override;
29
-
30
- void enableFileOutput(float sampleRate, size_t channelCount, size_t bitRate, size_t iosFlags, size_t androidFlags)
31
- override;
32
- void disableFileOutput() override;
18
+ IOSAudioRecorder(
19
+ float sampleRate,
20
+ int bufferLength,
21
+ const std::shared_ptr<AudioEventHandlerRegistry> &audioEventHandlerRegistry);
33
22
 
34
- void pause() override;
35
- void resume() override;
36
-
37
- void setOnAudioReadyCallback(float sampleRate, size_t bufferLength, size_t channelCount, uint64_t callbackId)
38
- override;
39
- void clearOnAudioReadyCallback() override;
23
+ ~IOSAudioRecorder() override;
40
24
 
41
- double getCurrentDuration() const override;
25
+ void start() override;
26
+ void stop() override;
42
27
 
43
28
  private:
44
- std::shared_ptr<IOSAudioFileWriter> fileWriter_;
45
- std::shared_ptr<IOSRecorderCallback> callback_;
46
- std::string filePath_{""};
47
- NativeAudioRecorder *nativeRecorder_;
29
+ NativeAudioRecorder *audioRecorder_;
48
30
  };
49
31
 
50
32
  } // namespace audioapi
@@ -1,157 +1,70 @@
1
1
  #import <AVFoundation/AVFoundation.h>
2
- #import <Foundation/Foundation.h>
3
- #include <unordered_map>
4
2
 
5
3
  #include <audioapi/core/utils/Constants.h>
6
4
  #include <audioapi/dsp/VectorMath.h>
7
5
  #include <audioapi/events/AudioEventHandlerRegistry.h>
8
- #include <audioapi/ios/core/IOSAudioFileWriter.h>
9
6
  #include <audioapi/ios/core/IOSAudioRecorder.h>
10
- #include <audioapi/ios/core/IOSRecorderCallback.h>
11
7
  #include <audioapi/utils/AudioArray.h>
12
8
  #include <audioapi/utils/AudioBus.h>
13
9
  #include <audioapi/utils/CircularAudioArray.h>
14
10
  #include <audioapi/utils/CircularOverflowableAudioArray.h>
11
+ #include <unordered_map>
15
12
 
16
13
  namespace audioapi {
17
14
 
18
- IOSAudioRecorder::IOSAudioRecorder(const std::shared_ptr<AudioEventHandlerRegistry> &audioEventHandlerRegistry)
19
- : AudioRecorder(audioEventHandlerRegistry), fileWriter_(nullptr)
15
+ IOSAudioRecorder::IOSAudioRecorder(
16
+ float sampleRate,
17
+ int bufferLength,
18
+ const std::shared_ptr<AudioEventHandlerRegistry> &audioEventHandlerRegistry)
19
+ : AudioRecorder(sampleRate, bufferLength, audioEventHandlerRegistry)
20
20
  {
21
- AudioReceiverBlock receiverBlock = ^(const AudioBufferList *inputBuffer, int numFrames) {
22
- if (usesFileOutput()) {
23
- fileWriter_->writeAudioData(inputBuffer, numFrames);
21
+ AudioReceiverBlock audioReceiverBlock = ^(const AudioBufferList *inputBuffer, int numFrames) {
22
+ if (isRunning_.load()) {
23
+ auto *inputChannel = static_cast<float *>(inputBuffer->mBuffers[0].mData);
24
+ writeToBuffers(inputChannel, numFrames);
24
25
  }
25
26
 
26
- if (usesCallback()) {
27
- callback_->receiveAudioData(inputBuffer, numFrames);
27
+ while (circularBuffer_->getNumberOfAvailableFrames() >= bufferLength_) {
28
+ auto bus = std::make_shared<AudioBus>(bufferLength_, 1, sampleRate_);
29
+ auto *outputChannel = bus->getChannel(0)->getData();
30
+
31
+ circularBuffer_->pop_front(outputChannel, bufferLength_);
32
+
33
+ invokeOnAudioReadyCallback(bus, bufferLength_);
28
34
  }
29
35
  };
30
36
 
31
- nativeRecorder_ = [[NativeAudioRecorder alloc] initWithReceiverBlock:receiverBlock];
37
+ audioRecorder_ = [[NativeAudioRecorder alloc] initWithReceiverBlock:audioReceiverBlock
38
+ bufferLength:bufferLength
39
+ sampleRate:sampleRate];
32
40
  }
33
41
 
34
42
  IOSAudioRecorder::~IOSAudioRecorder()
35
43
  {
36
44
  stop();
37
- [nativeRecorder_ cleanup];
38
- }
39
- std::string IOSAudioRecorder::start()
40
- {
41
- size_t maxInputBufferLength = [nativeRecorder_ getBufferSize];
42
-
43
- if (isRecording()) {
44
- return filePath_;
45
- }
46
-
47
- if (usesFileOutput()) {
48
- filePath_ = fileWriter_->openFile([nativeRecorder_ getInputFormat], maxInputBufferLength);
49
- }
50
-
51
- if (usesCallback()) {
52
- callback_->prepare([nativeRecorder_ getInputFormat], maxInputBufferLength);
53
- }
54
-
55
- if (isConnected()) {
56
- // TODO: set adapter node properties?
57
- }
58
-
59
- [nativeRecorder_ start];
60
- state_.store(RecorderState::Recording);
61
-
62
- return filePath_;
45
+ [audioRecorder_ cleanup];
63
46
  }
64
47
 
65
- std::tuple<std::string, double, double> IOSAudioRecorder::stop()
48
+ void IOSAudioRecorder::start()
66
49
  {
67
- std::string filePath = filePath_;
68
- double outputFileSize = 0;
69
- double outputDuration = 0;
70
-
71
- if (!isRecording()) {
72
- return {filePath, 0, 0};
73
- }
74
-
75
- [nativeRecorder_ stop];
76
- state_.store(RecorderState::Idle);
77
-
78
- if (usesFileOutput()) {
79
- auto [size, duration] = fileWriter_->closeFile();
80
- outputFileSize = size;
81
- outputDuration = duration;
82
- }
83
-
84
- if (usesCallback()) {
85
- callback_->cleanup();
86
- }
87
-
88
- filePath_ = "";
89
- return {filePath, outputFileSize, outputDuration};
90
- }
91
-
92
- void IOSAudioRecorder::enableFileOutput(
93
- float sampleRate,
94
- size_t channelCount,
95
- size_t bitRate,
96
- size_t iosFlags,
97
- size_t androidFlags)
98
- {
99
- fileOutputEnabled_.store(true);
100
- fileWriter_ = std::make_shared<IOSAudioFileWriter>(sampleRate, channelCount, bitRate, iosFlags);
101
- }
102
-
103
- void IOSAudioRecorder::disableFileOutput()
104
- {
105
- fileOutputEnabled_.store(false);
106
- fileWriter_ = nullptr;
107
- }
108
-
109
- void IOSAudioRecorder::pause()
110
- {
111
- if (!isRecording()) {
50
+ if (isRunning_.load()) {
112
51
  return;
113
52
  }
114
53
 
115
- [nativeRecorder_ stop];
116
- state_.store(RecorderState::Paused);
54
+ [audioRecorder_ start];
55
+ isRunning_.store(true);
117
56
  }
118
57
 
119
- void IOSAudioRecorder::resume()
58
+ void IOSAudioRecorder::stop()
120
59
  {
121
- if (!isPaused()) {
60
+ if (!isRunning_.load()) {
122
61
  return;
123
62
  }
124
63
 
125
- [nativeRecorder_ start];
126
- state_.store(RecorderState::Recording);
127
- }
128
-
129
- void IOSAudioRecorder::setOnAudioReadyCallback(
130
- float sampleRate,
131
- size_t bufferLength,
132
- size_t channelCount,
133
- uint64_t callbackId)
134
- {
135
- callback_ = std::make_shared<IOSRecorderCallback>(
136
- audioEventHandlerRegistry_, sampleRate, bufferLength, channelCount, callbackId);
137
- callbackOutputEnabled_.store(true);
138
- }
139
-
140
- void IOSAudioRecorder::clearOnAudioReadyCallback()
141
- {
142
- callbackOutputEnabled_.store(false);
143
- callback_ = nullptr;
144
- }
145
-
146
- double IOSAudioRecorder::getCurrentDuration() const
147
- {
148
- double duration = 0.0;
149
-
150
- if (usesFileOutput() && fileWriter_) {
151
- duration = fileWriter_->getCurrentDuration();
152
- }
64
+ isRunning_.store(false);
65
+ [audioRecorder_ stop];
153
66
 
154
- return duration;
67
+ sendRemainingData();
155
68
  }
156
69
 
157
70
  } // namespace audioapi
@@ -7,15 +7,20 @@ typedef void (^AudioReceiverBlock)(const AudioBufferList *inputBuffer, int numFr
7
7
 
8
8
  @interface NativeAudioRecorder : NSObject
9
9
 
10
+ @property (nonatomic, assign) int bufferLength;
11
+ @property (nonatomic, assign) float sampleRate;
12
+
10
13
  @property (nonatomic, strong) AVAudioSinkNode *sinkNode;
11
14
  @property (nonatomic, copy) AVAudioSinkNodeReceiverBlock receiverSinkBlock;
12
15
  @property (nonatomic, copy) AudioReceiverBlock receiverBlock;
13
16
 
14
- - (instancetype)initWithReceiverBlock:(AudioReceiverBlock)receiverBlock;
15
-
16
- - (AVAudioFormat *)getInputFormat;
17
+ @property (nonatomic, strong) AVAudioConverter *audioConverter;
18
+ @property (nonatomic, strong) AVAudioFormat *inputFormat;
19
+ @property (nonatomic, strong) AVAudioFormat *outputFormat;
17
20
 
18
- - (int)getBufferSize;
21
+ - (instancetype)initWithReceiverBlock:(AudioReceiverBlock)receiverBlock
22
+ bufferLength:(int)bufferLength
23
+ sampleRate:(float)sampleRate;
19
24
 
20
25
  - (void)start;
21
26