react-native-audio-api 0.8.3-nightly-ea268f4-20251005 → 0.8.3

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 (282) hide show
  1. package/README.md +39 -40
  2. package/RNAudioAPI.podspec +12 -17
  3. package/android/build.gradle +4 -44
  4. package/android/src/main/cpp/audioapi/CMakeLists.txt +0 -65
  5. package/android/src/main/cpp/audioapi/android/AudioAPIModule.cpp +1 -29
  6. package/android/src/main/cpp/audioapi/android/AudioAPIModule.h +0 -14
  7. package/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.cpp +1 -7
  8. package/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.h +1 -6
  9. package/android/src/main/cpp/audioapi/android/core/AudioPlayer.cpp +1 -1
  10. package/android/src/main/java/com/swmansion/audioapi/AudioAPIModule.kt +1 -11
  11. package/android/src/main/java/com/swmansion/audioapi/system/MediaSessionManager.kt +2 -15
  12. package/common/cpp/audioapi/AudioAPIModuleInstaller.h +18 -53
  13. package/common/cpp/audioapi/HostObjects/AnalyserNodeHostObject.h +149 -0
  14. package/common/cpp/audioapi/HostObjects/AudioBufferBaseSourceNodeHostObject.h +76 -0
  15. package/common/cpp/audioapi/HostObjects/AudioBufferHostObject.h +120 -0
  16. package/common/cpp/audioapi/HostObjects/AudioBufferQueueSourceNodeHostObject.h +67 -0
  17. package/common/cpp/audioapi/HostObjects/AudioBufferSourceNodeHostObject.h +142 -0
  18. package/common/cpp/audioapi/HostObjects/AudioContextHostObject.h +46 -6
  19. package/common/cpp/audioapi/HostObjects/AudioNodeHostObject.cpp +6 -70
  20. package/common/cpp/audioapi/HostObjects/AudioNodeHostObject.h +66 -10
  21. package/common/cpp/audioapi/HostObjects/AudioParamHostObject.h +91 -17
  22. package/common/cpp/audioapi/HostObjects/AudioRecorderHostObject.h +86 -0
  23. package/common/cpp/audioapi/HostObjects/AudioScheduledSourceNodeHostObject.h +56 -0
  24. package/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.cpp +6 -362
  25. package/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.h +241 -29
  26. package/common/cpp/audioapi/HostObjects/BiquadFilterNodeHostObject.h +89 -0
  27. package/common/cpp/audioapi/HostObjects/GainNodeHostObject.h +27 -0
  28. package/common/cpp/audioapi/HostObjects/OfflineAudioContextHostObject.h +50 -6
  29. package/common/cpp/audioapi/HostObjects/OscillatorNodeHostObject.h +65 -0
  30. package/common/cpp/audioapi/HostObjects/{sources/RecorderAdapterNodeHostObject.h → RecorderAdapterNodeHostObject.h} +2 -1
  31. package/common/cpp/audioapi/HostObjects/StereoPannerNodeHostObject.h +29 -0
  32. package/common/cpp/audioapi/HostObjects/StreamerNodeHostObject.h +30 -0
  33. package/common/cpp/audioapi/core/AudioContext.cpp +2 -3
  34. package/common/cpp/audioapi/core/AudioContext.h +1 -2
  35. package/common/cpp/audioapi/core/AudioNode.h +1 -1
  36. package/common/cpp/audioapi/core/AudioParam.cpp +2 -2
  37. package/common/cpp/audioapi/core/AudioParam.h +1 -1
  38. package/common/cpp/audioapi/core/{utils/AudioParamEventQueue.cpp → AudioParamEventQueue.cpp} +7 -13
  39. package/common/cpp/audioapi/core/BaseAudioContext.cpp +3 -47
  40. package/common/cpp/audioapi/core/BaseAudioContext.h +4 -13
  41. package/common/cpp/audioapi/core/{utils/Constants.h → Constants.h} +0 -5
  42. package/common/cpp/audioapi/core/OfflineAudioContext.cpp +3 -4
  43. package/common/cpp/audioapi/core/OfflineAudioContext.h +1 -2
  44. package/common/cpp/audioapi/core/effects/PeriodicWave.cpp +1 -1
  45. package/common/cpp/audioapi/core/effects/StereoPannerNode.cpp +1 -1
  46. package/common/cpp/audioapi/core/inputs/AudioRecorder.cpp +1 -1
  47. package/common/cpp/audioapi/core/inputs/AudioRecorder.h +2 -2
  48. package/common/cpp/audioapi/core/sources/AudioBufferBaseSourceNode.cpp +10 -47
  49. package/common/cpp/audioapi/core/sources/AudioBufferBaseSourceNode.h +3 -18
  50. package/common/cpp/audioapi/core/sources/AudioBufferQueueSourceNode.cpp +12 -94
  51. package/common/cpp/audioapi/core/sources/AudioBufferQueueSourceNode.h +2 -8
  52. package/common/cpp/audioapi/core/sources/AudioBufferSourceNode.cpp +42 -33
  53. package/common/cpp/audioapi/core/sources/AudioBufferSourceNode.h +8 -6
  54. package/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.cpp +6 -1
  55. package/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.h +1 -1
  56. package/common/cpp/audioapi/core/sources/StreamerNode.h +8 -0
  57. package/common/cpp/audioapi/dsp/Windows.cpp +1 -1
  58. package/common/cpp/audioapi/events/AudioEventHandlerRegistry.cpp +1 -1
  59. package/common/cpp/audioapi/events/AudioEventHandlerRegistry.h +1 -2
  60. package/common/cpp/audioapi/events/AudioEventHandlerRegistryHostObject.h +48 -0
  61. package/common/cpp/audioapi/jsi/AudioArrayBuffer.h +1 -14
  62. package/common/cpp/audioapi/jsi/JsiHostObject.h +12 -6
  63. package/common/cpp/audioapi/jsi/JsiPromise.cpp +0 -49
  64. package/common/cpp/audioapi/jsi/JsiPromise.h +1 -29
  65. package/common/cpp/audioapi/utils/AudioBus.cpp +1 -1
  66. package/common/cpp/test/CMakeLists.txt +3 -11
  67. package/common/cpp/test/GainTest.cpp +1 -2
  68. package/common/cpp/test/OscillatorTest.cpp +1 -2
  69. package/ios/audioapi/ios/AudioAPIModule.mm +5 -32
  70. package/ios/audioapi/ios/core/IOSAudioPlayer.mm +1 -1
  71. package/ios/audioapi/ios/core/IOSAudioRecorder.h +1 -2
  72. package/ios/audioapi/ios/core/IOSAudioRecorder.mm +1 -1
  73. package/ios/audioapi/ios/events/IOSAudioEventHandlerRegistry.h +7 -0
  74. package/ios/audioapi/ios/events/IOSAudioEventHandlerRegistry.mm +12 -0
  75. package/lib/commonjs/api.js +2 -36
  76. package/lib/commonjs/api.js.map +1 -1
  77. package/lib/commonjs/api.web.js +0 -8
  78. package/lib/commonjs/api.web.js.map +1 -1
  79. package/lib/commonjs/core/AudioBufferBaseSourceNode.js +7 -7
  80. package/lib/commonjs/core/AudioBufferBaseSourceNode.js.map +1 -1
  81. package/lib/commonjs/core/AudioBufferQueueSourceNode.js +6 -1
  82. package/lib/commonjs/core/AudioBufferQueueSourceNode.js.map +1 -1
  83. package/lib/commonjs/core/AudioBufferSourceNode.js +0 -15
  84. package/lib/commonjs/core/AudioBufferSourceNode.js.map +1 -1
  85. package/lib/commonjs/core/AudioContext.js +1 -10
  86. package/lib/commonjs/core/AudioContext.js.map +1 -1
  87. package/lib/commonjs/core/AudioScheduledSourceNode.js +4 -4
  88. package/lib/commonjs/core/AudioScheduledSourceNode.js.map +1 -1
  89. package/lib/commonjs/core/BaseAudioContext.js +11 -66
  90. package/lib/commonjs/core/BaseAudioContext.js.map +1 -1
  91. package/lib/commonjs/core/OfflineAudioContext.js +2 -11
  92. package/lib/commonjs/core/OfflineAudioContext.js.map +1 -1
  93. package/lib/commonjs/core/OscillatorNode.js +0 -6
  94. package/lib/commonjs/core/OscillatorNode.js.map +1 -1
  95. package/lib/commonjs/hooks/{useSystemVolume.js → useSytemVolume.js} +1 -1
  96. package/lib/commonjs/hooks/useSytemVolume.js.map +1 -0
  97. package/lib/commonjs/utils/index.js +0 -9
  98. package/lib/commonjs/utils/index.js.map +1 -1
  99. package/lib/commonjs/web-core/AudioContext.js +0 -4
  100. package/lib/commonjs/web-core/AudioContext.js.map +1 -1
  101. package/lib/commonjs/web-core/AudioScheduledSourceNode.js +1 -1
  102. package/lib/commonjs/web-core/AudioScheduledSourceNode.js.map +1 -1
  103. package/lib/commonjs/web-core/OfflineAudioContext.js +0 -4
  104. package/lib/commonjs/web-core/OfflineAudioContext.js.map +1 -1
  105. package/lib/module/api.js +2 -6
  106. package/lib/module/api.js.map +1 -1
  107. package/lib/module/api.web.js +0 -1
  108. package/lib/module/api.web.js.map +1 -1
  109. package/lib/module/core/AudioBufferBaseSourceNode.js +7 -7
  110. package/lib/module/core/AudioBufferBaseSourceNode.js.map +1 -1
  111. package/lib/module/core/AudioBufferQueueSourceNode.js +6 -1
  112. package/lib/module/core/AudioBufferQueueSourceNode.js.map +1 -1
  113. package/lib/module/core/AudioBufferSourceNode.js +0 -15
  114. package/lib/module/core/AudioBufferSourceNode.js.map +1 -1
  115. package/lib/module/core/AudioContext.js +1 -10
  116. package/lib/module/core/AudioContext.js.map +1 -1
  117. package/lib/module/core/AudioScheduledSourceNode.js +4 -4
  118. package/lib/module/core/AudioScheduledSourceNode.js.map +1 -1
  119. package/lib/module/core/BaseAudioContext.js +11 -66
  120. package/lib/module/core/BaseAudioContext.js.map +1 -1
  121. package/lib/module/core/OfflineAudioContext.js +2 -11
  122. package/lib/module/core/OfflineAudioContext.js.map +1 -1
  123. package/lib/module/core/OscillatorNode.js +0 -6
  124. package/lib/module/core/OscillatorNode.js.map +1 -1
  125. package/lib/module/hooks/{useSystemVolume.js → useSytemVolume.js} +1 -1
  126. package/lib/module/hooks/useSytemVolume.js.map +1 -0
  127. package/lib/module/utils/index.js +0 -8
  128. package/lib/module/utils/index.js.map +1 -1
  129. package/lib/module/web-core/AudioContext.js +0 -4
  130. package/lib/module/web-core/AudioContext.js.map +1 -1
  131. package/lib/module/web-core/AudioScheduledSourceNode.js +1 -1
  132. package/lib/module/web-core/AudioScheduledSourceNode.js.map +1 -1
  133. package/lib/module/web-core/OfflineAudioContext.js +0 -4
  134. package/lib/module/web-core/OfflineAudioContext.js.map +1 -1
  135. package/lib/typescript/api.d.ts +4 -8
  136. package/lib/typescript/api.d.ts.map +1 -1
  137. package/lib/typescript/api.web.d.ts +0 -1
  138. package/lib/typescript/api.web.d.ts.map +1 -1
  139. package/lib/typescript/core/AudioBufferBaseSourceNode.d.ts +2 -2
  140. package/lib/typescript/core/AudioBufferBaseSourceNode.d.ts.map +1 -1
  141. package/lib/typescript/core/AudioBufferQueueSourceNode.d.ts +1 -1
  142. package/lib/typescript/core/AudioBufferQueueSourceNode.d.ts.map +1 -1
  143. package/lib/typescript/core/AudioBufferSourceNode.d.ts +0 -4
  144. package/lib/typescript/core/AudioBufferSourceNode.d.ts.map +1 -1
  145. package/lib/typescript/core/AudioContext.d.ts +0 -1
  146. package/lib/typescript/core/AudioContext.d.ts.map +1 -1
  147. package/lib/typescript/core/AudioScheduledSourceNode.d.ts +1 -1
  148. package/lib/typescript/core/BaseAudioContext.d.ts +11 -19
  149. package/lib/typescript/core/BaseAudioContext.d.ts.map +1 -1
  150. package/lib/typescript/core/OfflineAudioContext.d.ts +0 -1
  151. package/lib/typescript/core/OfflineAudioContext.d.ts.map +1 -1
  152. package/lib/typescript/core/OscillatorNode.d.ts +0 -3
  153. package/lib/typescript/core/OscillatorNode.d.ts.map +1 -1
  154. package/lib/typescript/events/types.d.ts +0 -2
  155. package/lib/typescript/events/types.d.ts.map +1 -1
  156. package/lib/typescript/hooks/{useSystemVolume.d.ts → useSytemVolume.d.ts} +1 -1
  157. package/lib/typescript/hooks/useSytemVolume.d.ts.map +1 -0
  158. package/lib/typescript/interfaces.d.ts +3 -21
  159. package/lib/typescript/interfaces.d.ts.map +1 -1
  160. package/lib/typescript/types.d.ts +1 -2
  161. package/lib/typescript/types.d.ts.map +1 -1
  162. package/lib/typescript/utils/index.d.ts +0 -8
  163. package/lib/typescript/utils/index.d.ts.map +1 -1
  164. package/lib/typescript/web-core/AudioBufferSourceNode.d.ts +1 -1
  165. package/lib/typescript/web-core/AudioContext.d.ts +2 -4
  166. package/lib/typescript/web-core/AudioContext.d.ts.map +1 -1
  167. package/lib/typescript/web-core/AudioScheduledSourceNode.d.ts +1 -1
  168. package/lib/typescript/web-core/BaseAudioContext.d.ts +0 -2
  169. package/lib/typescript/web-core/BaseAudioContext.d.ts.map +1 -1
  170. package/lib/typescript/web-core/OfflineAudioContext.d.ts +2 -4
  171. package/lib/typescript/web-core/OfflineAudioContext.d.ts.map +1 -1
  172. package/package.json +2 -3
  173. package/src/api.ts +3 -12
  174. package/src/api.web.ts +0 -1
  175. package/src/core/AudioBufferBaseSourceNode.ts +9 -9
  176. package/src/core/AudioBufferQueueSourceNode.ts +9 -1
  177. package/src/core/AudioBufferSourceNode.ts +0 -28
  178. package/src/core/AudioContext.ts +1 -12
  179. package/src/core/AudioScheduledSourceNode.ts +5 -5
  180. package/src/core/BaseAudioContext.ts +13 -149
  181. package/src/core/OfflineAudioContext.ts +2 -18
  182. package/src/core/OscillatorNode.ts +0 -11
  183. package/src/events/types.ts +0 -2
  184. package/src/interfaces.ts +5 -59
  185. package/src/types.ts +1 -3
  186. package/src/utils/index.ts +0 -21
  187. package/src/web-core/AudioBufferSourceNode.tsx +1 -1
  188. package/src/web-core/AudioContext.tsx +2 -7
  189. package/src/web-core/AudioScheduledSourceNode.tsx +1 -1
  190. package/src/web-core/BaseAudioContext.tsx +0 -2
  191. package/src/web-core/OfflineAudioContext.tsx +2 -7
  192. package/android/src/main/cpp/audioapi/android/core/NativeAudioRecorder.hpp +0 -36
  193. package/android/src/main/java/com/swmansion/audioapi/core/NativeAudioRecorder.kt +0 -24
  194. package/common/cpp/audioapi/HostObjects/AudioContextHostObject.cpp +0 -57
  195. package/common/cpp/audioapi/HostObjects/AudioParamHostObject.cpp +0 -105
  196. package/common/cpp/audioapi/HostObjects/OfflineAudioContextHostObject.cpp +0 -70
  197. package/common/cpp/audioapi/HostObjects/WorkletNodeHostObject.h +0 -18
  198. package/common/cpp/audioapi/HostObjects/WorkletProcessingNodeHostObject.h +0 -18
  199. package/common/cpp/audioapi/HostObjects/analysis/AnalyserNodeHostObject.cpp +0 -148
  200. package/common/cpp/audioapi/HostObjects/analysis/AnalyserNodeHostObject.h +0 -37
  201. package/common/cpp/audioapi/HostObjects/effects/BiquadFilterNodeHostObject.cpp +0 -92
  202. package/common/cpp/audioapi/HostObjects/effects/BiquadFilterNodeHostObject.h +0 -29
  203. package/common/cpp/audioapi/HostObjects/effects/GainNodeHostObject.cpp +0 -20
  204. package/common/cpp/audioapi/HostObjects/effects/GainNodeHostObject.h +0 -19
  205. package/common/cpp/audioapi/HostObjects/effects/StereoPannerNodeHostObject.cpp +0 -21
  206. package/common/cpp/audioapi/HostObjects/effects/StereoPannerNodeHostObject.h +0 -21
  207. package/common/cpp/audioapi/HostObjects/events/AudioEventHandlerRegistryHostObject.cpp +0 -41
  208. package/common/cpp/audioapi/HostObjects/events/AudioEventHandlerRegistryHostObject.h +0 -28
  209. package/common/cpp/audioapi/HostObjects/inputs/AudioRecorderHostObject.cpp +0 -69
  210. package/common/cpp/audioapi/HostObjects/inputs/AudioRecorderHostObject.h +0 -33
  211. package/common/cpp/audioapi/HostObjects/sources/AudioBufferBaseSourceNodeHostObject.cpp +0 -73
  212. package/common/cpp/audioapi/HostObjects/sources/AudioBufferBaseSourceNodeHostObject.h +0 -29
  213. package/common/cpp/audioapi/HostObjects/sources/AudioBufferHostObject.cpp +0 -94
  214. package/common/cpp/audioapi/HostObjects/sources/AudioBufferHostObject.h +0 -46
  215. package/common/cpp/audioapi/HostObjects/sources/AudioBufferQueueSourceNodeHostObject.cpp +0 -60
  216. package/common/cpp/audioapi/HostObjects/sources/AudioBufferQueueSourceNodeHostObject.h +0 -25
  217. package/common/cpp/audioapi/HostObjects/sources/AudioBufferSourceNodeHostObject.cpp +0 -152
  218. package/common/cpp/audioapi/HostObjects/sources/AudioBufferSourceNodeHostObject.h +0 -37
  219. package/common/cpp/audioapi/HostObjects/sources/AudioScheduledSourceNodeHostObject.cpp +0 -52
  220. package/common/cpp/audioapi/HostObjects/sources/AudioScheduledSourceNodeHostObject.h +0 -25
  221. package/common/cpp/audioapi/HostObjects/sources/ConstantSourceNodeHostObject.cpp +0 -19
  222. package/common/cpp/audioapi/HostObjects/sources/ConstantSourceNodeHostObject.h +0 -21
  223. package/common/cpp/audioapi/HostObjects/sources/OscillatorNodeHostObject.cpp +0 -55
  224. package/common/cpp/audioapi/HostObjects/sources/OscillatorNodeHostObject.h +0 -27
  225. package/common/cpp/audioapi/HostObjects/sources/StreamerNodeHostObject.cpp +0 -22
  226. package/common/cpp/audioapi/HostObjects/sources/StreamerNodeHostObject.h +0 -28
  227. package/common/cpp/audioapi/HostObjects/sources/WorkletSourceNodeHostObject.h +0 -18
  228. package/common/cpp/audioapi/core/effects/WorkletNode.cpp +0 -87
  229. package/common/cpp/audioapi/core/effects/WorkletNode.h +0 -65
  230. package/common/cpp/audioapi/core/effects/WorkletProcessingNode.cpp +0 -89
  231. package/common/cpp/audioapi/core/effects/WorkletProcessingNode.h +0 -52
  232. package/common/cpp/audioapi/core/sources/ConstantSourceNode.cpp +0 -51
  233. package/common/cpp/audioapi/core/sources/ConstantSourceNode.h +0 -26
  234. package/common/cpp/audioapi/core/sources/WorkletSourceNode.cpp +0 -82
  235. package/common/cpp/audioapi/core/sources/WorkletSourceNode.h +0 -47
  236. package/common/cpp/audioapi/core/utils/worklets/SafeIncludes.h +0 -52
  237. package/common/cpp/audioapi/core/utils/worklets/WorkletsRunner.cpp +0 -9
  238. package/common/cpp/audioapi/core/utils/worklets/WorkletsRunner.h +0 -73
  239. package/common/cpp/audioapi/utils/ThreadPool.hpp +0 -104
  240. package/common/cpp/test/AudioParamTest.cpp +0 -204
  241. package/lib/commonjs/core/ConstantSourceNode.js +0 -17
  242. package/lib/commonjs/core/ConstantSourceNode.js.map +0 -1
  243. package/lib/commonjs/core/WorkletNode.js +0 -11
  244. package/lib/commonjs/core/WorkletNode.js.map +0 -1
  245. package/lib/commonjs/core/WorkletProcessingNode.js +0 -11
  246. package/lib/commonjs/core/WorkletProcessingNode.js.map +0 -1
  247. package/lib/commonjs/core/WorkletSourceNode.js +0 -11
  248. package/lib/commonjs/core/WorkletSourceNode.js.map +0 -1
  249. package/lib/commonjs/hooks/useSystemVolume.js.map +0 -1
  250. package/lib/commonjs/web-core/ConstantSourceNode.js +0 -17
  251. package/lib/commonjs/web-core/ConstantSourceNode.js.map +0 -1
  252. package/lib/module/core/ConstantSourceNode.js +0 -11
  253. package/lib/module/core/ConstantSourceNode.js.map +0 -1
  254. package/lib/module/core/WorkletNode.js +0 -5
  255. package/lib/module/core/WorkletNode.js.map +0 -1
  256. package/lib/module/core/WorkletProcessingNode.js +0 -5
  257. package/lib/module/core/WorkletProcessingNode.js.map +0 -1
  258. package/lib/module/core/WorkletSourceNode.js +0 -5
  259. package/lib/module/core/WorkletSourceNode.js.map +0 -1
  260. package/lib/module/hooks/useSystemVolume.js.map +0 -1
  261. package/lib/module/web-core/ConstantSourceNode.js +0 -11
  262. package/lib/module/web-core/ConstantSourceNode.js.map +0 -1
  263. package/lib/typescript/core/ConstantSourceNode.d.ts +0 -9
  264. package/lib/typescript/core/ConstantSourceNode.d.ts.map +0 -1
  265. package/lib/typescript/core/WorkletNode.d.ts +0 -4
  266. package/lib/typescript/core/WorkletNode.d.ts.map +0 -1
  267. package/lib/typescript/core/WorkletProcessingNode.d.ts +0 -4
  268. package/lib/typescript/core/WorkletProcessingNode.d.ts.map +0 -1
  269. package/lib/typescript/core/WorkletSourceNode.d.ts +0 -4
  270. package/lib/typescript/core/WorkletSourceNode.d.ts.map +0 -1
  271. package/lib/typescript/hooks/useSystemVolume.d.ts.map +0 -1
  272. package/lib/typescript/web-core/ConstantSourceNode.d.ts +0 -8
  273. package/lib/typescript/web-core/ConstantSourceNode.d.ts.map +0 -1
  274. package/src/core/ConstantSourceNode.ts +0 -13
  275. package/src/core/WorkletNode.ts +0 -3
  276. package/src/core/WorkletProcessingNode.ts +0 -3
  277. package/src/core/WorkletSourceNode.ts +0 -3
  278. package/src/web-core/ConstantSourceNode.tsx +0 -12
  279. /package/common/cpp/audioapi/HostObjects/{destinations/AudioDestinationNodeHostObject.h → AudioDestinationNodeHostObject.h} +0 -0
  280. /package/common/cpp/audioapi/HostObjects/{effects/PeriodicWaveHostObject.h → PeriodicWaveHostObject.h} +0 -0
  281. /package/common/cpp/audioapi/core/{utils/AudioParamEventQueue.h → AudioParamEventQueue.h} +0 -0
  282. /package/src/hooks/{useSystemVolume.ts → useSytemVolume.ts} +0 -0
@@ -1,6 +1,6 @@
1
1
  #include <audioapi/core/BaseAudioContext.h>
2
+ #include <audioapi/core/Constants.h>
2
3
  #include <audioapi/core/effects/StereoPannerNode.h>
3
- #include <audioapi/core/utils/Constants.h>
4
4
  #include <audioapi/utils/AudioArray.h>
5
5
  #include <audioapi/utils/AudioBus.h>
6
6
 
@@ -1,4 +1,4 @@
1
- #include <audioapi/HostObjects/sources/AudioBufferHostObject.h>
1
+ #include <audioapi/HostObjects/AudioBufferHostObject.h>
2
2
  #include <audioapi/core/inputs/AudioRecorder.h>
3
3
  #include <audioapi/core/sources/AudioBuffer.h>
4
4
  #include <audioapi/core/sources/RecorderAdapterNode.h>
@@ -1,11 +1,11 @@
1
1
  #pragma once
2
2
 
3
+
3
4
  #include <memory>
4
- #include <atomic>
5
5
  #include <mutex>
6
+ #include <atomic>
6
7
 
7
8
  namespace audioapi {
8
-
9
9
  class RecorderAdapterNode;
10
10
  class AudioBus;
11
11
  class CircularAudioArray;
@@ -1,18 +1,14 @@
1
1
  #include <audioapi/core/AudioParam.h>
2
2
  #include <audioapi/core/BaseAudioContext.h>
3
+ #include <audioapi/core/Constants.h>
3
4
  #include <audioapi/core/sources/AudioBufferBaseSourceNode.h>
4
- #include <audioapi/core/utils/Constants.h>
5
5
  #include <audioapi/events/AudioEventHandlerRegistry.h>
6
6
  #include <audioapi/utils/AudioArray.h>
7
7
  #include <audioapi/utils/AudioBus.h>
8
8
 
9
9
  namespace audioapi {
10
- AudioBufferBaseSourceNode::AudioBufferBaseSourceNode(
11
- BaseAudioContext *context,
12
- bool pitchCorrection)
13
- : AudioScheduledSourceNode(context),
14
- pitchCorrection_(pitchCorrection),
15
- vReadIndex_(0.0) {
10
+ AudioBufferBaseSourceNode::AudioBufferBaseSourceNode(BaseAudioContext *context)
11
+ : AudioScheduledSourceNode(context), vReadIndex_(0.0) {
16
12
  onPositionChangedInterval_ = static_cast<int>(context->getSampleRate() * 0.1);
17
13
 
18
14
  detuneParam_ = std::make_shared<AudioParam>(
@@ -28,7 +24,12 @@ AudioBufferBaseSourceNode::AudioBufferBaseSourceNode(
28
24
  }
29
25
 
30
26
  AudioBufferBaseSourceNode::~AudioBufferBaseSourceNode() {
31
- clearOnPositionChangedCallback();
27
+ if (onPositionChangedCallbackId_ != 0 &&
28
+ context_->audioEventHandlerRegistry_ != nullptr) {
29
+ context_->audioEventHandlerRegistry_->unregisterHandler(
30
+ "positionChanged", onPositionChangedCallbackId_);
31
+ onPositionChangedCallbackId_ = 0;
32
+ }
32
33
  }
33
34
 
34
35
  std::shared_ptr<AudioParam> AudioBufferBaseSourceNode::getDetuneParam() const {
@@ -61,7 +62,7 @@ void AudioBufferBaseSourceNode::setOnPositionChangedInterval(int interval) {
61
62
  context_->getSampleRate() * static_cast<float>(interval) / 1000);
62
63
  }
63
64
 
64
- int AudioBufferBaseSourceNode::getOnPositionChangedInterval() const {
65
+ int AudioBufferBaseSourceNode::getOnPositionChangedInterval() {
65
66
  return onPositionChangedInterval_;
66
67
  }
67
68
 
@@ -124,45 +125,7 @@ void AudioBufferBaseSourceNode::processWithPitchCorrection(
124
125
  if (detune != 0.0f) {
125
126
  stretch_->setTransposeSemitones(detune);
126
127
  }
127
-
128
128
  sendOnPositionChangedEvent();
129
129
  }
130
130
 
131
- void AudioBufferBaseSourceNode::processWithoutPitchCorrection(
132
- const std::shared_ptr<AudioBus> &processingBus,
133
- int framesToProcess) {
134
- size_t startOffset = 0;
135
- size_t offsetLength = 0;
136
-
137
- auto computedPlaybackRate = getComputedPlaybackRateValue(framesToProcess);
138
- updatePlaybackInfo(processingBus, framesToProcess, startOffset, offsetLength);
139
-
140
- if (computedPlaybackRate == 0.0f || (!isPlaying() && !isStopScheduled())) {
141
- processingBus->zero();
142
- return;
143
- }
144
-
145
- if (std::fabs(computedPlaybackRate) == 1.0) {
146
- processWithoutInterpolation(
147
- processingBus, startOffset, offsetLength, computedPlaybackRate);
148
- } else {
149
- processWithInterpolation(
150
- processingBus, startOffset, offsetLength, computedPlaybackRate);
151
- }
152
-
153
- sendOnPositionChangedEvent();
154
- }
155
-
156
- float AudioBufferBaseSourceNode::getComputedPlaybackRateValue(
157
- int framesToProcess) {
158
- auto time = context_->getCurrentTime();
159
-
160
- auto playbackRate =
161
- playbackRateParam_->processKRateParam(framesToProcess, time);
162
- auto detune = std::pow(
163
- 2.0f, detuneParam_->processKRateParam(framesToProcess, time) / 1200.0f);
164
-
165
- return playbackRate * detune;
166
- }
167
-
168
131
  } // namespace audioapi
@@ -14,8 +14,8 @@ class AudioParam;
14
14
 
15
15
  class AudioBufferBaseSourceNode : public AudioScheduledSourceNode {
16
16
  public:
17
- explicit AudioBufferBaseSourceNode(BaseAudioContext *context, bool pitchCorrection);
18
- ~AudioBufferBaseSourceNode() override;
17
+ explicit AudioBufferBaseSourceNode(BaseAudioContext *context);
18
+ virtual ~AudioBufferBaseSourceNode();
19
19
 
20
20
  [[nodiscard]] std::shared_ptr<AudioParam> getDetuneParam() const;
21
21
  [[nodiscard]] std::shared_ptr<AudioParam> getPlaybackRateParam() const;
@@ -23,12 +23,9 @@ class AudioBufferBaseSourceNode : public AudioScheduledSourceNode {
23
23
  void clearOnPositionChangedCallback();
24
24
  void setOnPositionChangedCallbackId(uint64_t callbackId);
25
25
  void setOnPositionChangedInterval(int interval);
26
- [[nodiscard]] int getOnPositionChangedInterval() const;
26
+ [[nodiscard]] int getOnPositionChangedInterval();
27
27
 
28
28
  protected:
29
- // pitch correction
30
- bool pitchCorrection_;
31
-
32
29
  std::mutex bufferLock_;
33
30
 
34
31
  // pitch correction
@@ -50,25 +47,13 @@ class AudioBufferBaseSourceNode : public AudioScheduledSourceNode {
50
47
  virtual double getCurrentPosition() const = 0;
51
48
 
52
49
  void sendOnPositionChangedEvent();
53
-
54
50
  void processWithPitchCorrection(const std::shared_ptr<AudioBus> &processingBus,
55
51
  int framesToProcess);
56
- void processWithoutPitchCorrection(const std::shared_ptr<AudioBus> &processingBus,
57
- int framesToProcess);
58
-
59
- float getComputedPlaybackRateValue(int framesToProcess);
60
-
61
52
  virtual void processWithoutInterpolation(
62
53
  const std::shared_ptr<AudioBus>& processingBus,
63
54
  size_t startOffset,
64
55
  size_t offsetLength,
65
56
  float playbackRate) = 0;
66
-
67
- virtual void processWithInterpolation(
68
- const std::shared_ptr<AudioBus>& processingBus,
69
- size_t startOffset,
70
- size_t offsetLength,
71
- float playbackRate) = 0;
72
57
  };
73
58
 
74
59
  } // namespace audioapi
@@ -1,7 +1,7 @@
1
1
  #include <audioapi/core/AudioParam.h>
2
2
  #include <audioapi/core/BaseAudioContext.h>
3
+ #include <audioapi/core/Constants.h>
3
4
  #include <audioapi/core/sources/AudioBufferQueueSourceNode.h>
4
- #include <audioapi/core/utils/Constants.h>
5
5
  #include <audioapi/core/utils/Locker.h>
6
6
  #include <audioapi/dsp/AudioUtils.h>
7
7
  #include <audioapi/events/AudioEventHandlerRegistry.h>
@@ -11,9 +11,8 @@
11
11
  namespace audioapi {
12
12
 
13
13
  AudioBufferQueueSourceNode::AudioBufferQueueSourceNode(
14
- BaseAudioContext *context,
15
- bool pitchCorrection)
16
- : AudioBufferBaseSourceNode(context, pitchCorrection) {
14
+ BaseAudioContext *context)
15
+ : AudioBufferBaseSourceNode(context) {
17
16
  buffers_ = {};
18
17
  stretch_->presetDefault(channelCount_, context_->getSampleRate());
19
18
 
@@ -91,17 +90,13 @@ void AudioBufferQueueSourceNode::processNode(
91
90
  const std::shared_ptr<AudioBus> &processingBus,
92
91
  int framesToProcess) {
93
92
  if (auto locker = Locker::tryLock(getBufferLock())) {
94
- // no audio data to fill, zero the output and return.
93
+ // No audio data to fill, zero the output and return.
95
94
  if (buffers_.empty()) {
96
95
  processingBus->zero();
97
96
  return;
98
97
  }
99
98
 
100
- if (!pitchCorrection_) {
101
- processWithoutPitchCorrection(processingBus, framesToProcess);
102
- } else {
103
- processWithPitchCorrection(processingBus, framesToProcess);
104
- }
99
+ processWithPitchCorrection(processingBus, framesToProcess);
105
100
 
106
101
  handleStopScheduled();
107
102
  } else {
@@ -140,7 +135,6 @@ void AudioBufferQueueSourceNode::processWithoutInterpolation(
140
135
 
141
136
  assert(readIndex >= 0);
142
137
  assert(writeIndex >= 0);
143
- assert(readIndex + framesToCopy <= buffer->getLength());
144
138
  assert(writeIndex + framesToCopy <= processingBus->getSize());
145
139
 
146
140
  processingBus->copy(
@@ -155,7 +149,7 @@ void AudioBufferQueueSourceNode::processWithoutInterpolation(
155
149
  buffers_.pop();
156
150
 
157
151
  std::unordered_map<std::string, EventValue> body = {
158
- {"bufferId", std::to_string(bufferId)}, {"isLast", buffers_.empty()}};
152
+ {"bufferId", std::to_string(bufferId)}};
159
153
  context_->audioEventHandlerRegistry_->invokeHandlerWithEventBody(
160
154
  "ended", onEndedCallbackId_, body);
161
155
 
@@ -164,12 +158,13 @@ void AudioBufferQueueSourceNode::processWithoutInterpolation(
164
158
  readIndex = 0;
165
159
 
166
160
  break;
167
- }
161
+ } else {
162
+ data = buffers_.front();
163
+ bufferId = data.first;
164
+ buffer = data.second;
168
165
 
169
- data = buffers_.front();
170
- bufferId = data.first;
171
- buffer = data.second;
172
- readIndex = 0;
166
+ readIndex = 0;
167
+ }
173
168
  }
174
169
  }
175
170
 
@@ -177,81 +172,4 @@ void AudioBufferQueueSourceNode::processWithoutInterpolation(
177
172
  vReadIndex_ = static_cast<double>(readIndex);
178
173
  }
179
174
 
180
- void AudioBufferQueueSourceNode::processWithInterpolation(
181
- const std::shared_ptr<AudioBus> &processingBus,
182
- size_t startOffset,
183
- size_t offsetLength,
184
- float playbackRate) {
185
- size_t writeIndex = startOffset;
186
- size_t framesLeft = offsetLength;
187
-
188
- auto data = buffers_.front();
189
- auto bufferId = data.first;
190
- auto buffer = data.second;
191
-
192
- while (framesLeft > 0) {
193
- auto readIndex = static_cast<size_t>(vReadIndex_);
194
- size_t nextReadIndex = readIndex + 1;
195
- auto factor =
196
- static_cast<float>(vReadIndex_ - static_cast<double>(readIndex));
197
-
198
- bool crossBufferInterpolation = false;
199
- std::shared_ptr<AudioBuffer> nextBuffer = nullptr;
200
-
201
- if (nextReadIndex >= buffer->getLength()) {
202
- if (buffers_.size() > 1) {
203
- auto tempQueue = buffers_;
204
- tempQueue.pop();
205
- nextBuffer = tempQueue.front().second;
206
- nextReadIndex = 0;
207
- crossBufferInterpolation = true;
208
- } else {
209
- nextReadIndex = readIndex;
210
- }
211
- }
212
-
213
- for (int i = 0; i < processingBus->getNumberOfChannels(); i += 1) {
214
- float *destination = processingBus->getChannel(i)->getData();
215
- const float *currentSource = buffer->bus_->getChannel(i)->getData();
216
-
217
- if (crossBufferInterpolation) {
218
- const float *nextSource = nextBuffer->bus_->getChannel(i)->getData();
219
- float currentSample = currentSource[readIndex];
220
- float nextSample = nextSource[nextReadIndex];
221
- destination[writeIndex] =
222
- currentSample + factor * (nextSample - currentSample);
223
- } else {
224
- destination[writeIndex] = dsp::linearInterpolate(
225
- currentSource, readIndex, nextReadIndex, factor);
226
- }
227
- }
228
-
229
- writeIndex += 1;
230
- // queue source node always use positive playbackRate
231
- vReadIndex_ += std::abs(playbackRate);
232
- framesLeft -= 1;
233
-
234
- if (vReadIndex_ >= static_cast<double>(buffer->getLength())) {
235
- playedBuffersDuration_ += buffer->getDuration();
236
- buffers_.pop();
237
-
238
- std::unordered_map<std::string, EventValue> body = {
239
- {"bufferId", std::to_string(bufferId)}};
240
- context_->audioEventHandlerRegistry_->invokeHandlerWithEventBody(
241
- "ended", onEndedCallbackId_, body);
242
-
243
- if (buffers_.empty()) {
244
- processingBus->zero(writeIndex, framesLeft);
245
- vReadIndex_ = 0.0;
246
- break;
247
- }
248
-
249
- vReadIndex_ = vReadIndex_ - buffer->getLength();
250
- data = buffers_.front();
251
- bufferId = data.first;
252
- buffer = data.second;
253
- }
254
- }
255
- }
256
-
257
175
  } // namespace audioapi
@@ -17,14 +17,14 @@ class AudioParam;
17
17
 
18
18
  class AudioBufferQueueSourceNode : public AudioBufferBaseSourceNode {
19
19
  public:
20
- explicit AudioBufferQueueSourceNode(BaseAudioContext *context, bool pitchCorrection);
20
+ explicit AudioBufferQueueSourceNode(BaseAudioContext *context);
21
21
  ~AudioBufferQueueSourceNode() override;
22
22
 
23
23
  void stop(double when) override;
24
24
  void pause();
25
25
 
26
26
  std::string enqueueBuffer(const std::shared_ptr<AudioBuffer> &buffer);
27
- void dequeueBuffer(size_t bufferId);
27
+ void dequeueBuffer(const size_t bufferId);
28
28
  void clearBuffers();
29
29
  void disable() override;
30
30
 
@@ -46,12 +46,6 @@ class AudioBufferQueueSourceNode : public AudioBufferBaseSourceNode {
46
46
  size_t startOffset,
47
47
  size_t offsetLength,
48
48
  float playbackRate) override;
49
-
50
- void processWithInterpolation(
51
- const std::shared_ptr<AudioBus>& processingBus,
52
- size_t startOffset,
53
- size_t offsetLength,
54
- float playbackRate) override;
55
49
  };
56
50
 
57
51
  } // namespace audioapi
@@ -1,7 +1,7 @@
1
1
  #include <audioapi/core/AudioParam.h>
2
2
  #include <audioapi/core/BaseAudioContext.h>
3
+ #include <audioapi/core/Constants.h>
3
4
  #include <audioapi/core/sources/AudioBufferSourceNode.h>
4
- #include <audioapi/core/utils/Constants.h>
5
5
  #include <audioapi/core/utils/Locker.h>
6
6
  #include <audioapi/dsp/AudioUtils.h>
7
7
  #include <audioapi/events/AudioEventHandlerRegistry.h>
@@ -13,11 +13,12 @@ namespace audioapi {
13
13
  AudioBufferSourceNode::AudioBufferSourceNode(
14
14
  BaseAudioContext *context,
15
15
  bool pitchCorrection)
16
- : AudioBufferBaseSourceNode(context, pitchCorrection),
16
+ : AudioBufferBaseSourceNode(context),
17
17
  loop_(false),
18
18
  loopSkip_(false),
19
19
  loopStart_(0),
20
- loopEnd_(0) {
20
+ loopEnd_(0),
21
+ pitchCorrection_(pitchCorrection) {
21
22
  buffer_ = std::shared_ptr<AudioBuffer>(nullptr);
22
23
  alignedBus_ = std::shared_ptr<AudioBus>(nullptr);
23
24
 
@@ -29,8 +30,6 @@ AudioBufferSourceNode::~AudioBufferSourceNode() {
29
30
 
30
31
  buffer_.reset();
31
32
  alignedBus_.reset();
32
-
33
- clearOnLoopEndedCallback();
34
33
  }
35
34
 
36
35
  bool AudioBufferSourceNode::getLoop() const {
@@ -125,21 +124,6 @@ void AudioBufferSourceNode::disable() {
125
124
  alignedBus_.reset();
126
125
  }
127
126
 
128
- void AudioBufferSourceNode::clearOnLoopEndedCallback() {
129
- if (onLoopEndedCallbackId_ == 0 || context_ == nullptr ||
130
- context_->audioEventHandlerRegistry_ == nullptr) {
131
- return;
132
- }
133
-
134
- context_->audioEventHandlerRegistry_->unregisterHandler(
135
- "loopEnded", onLoopEndedCallbackId_);
136
- onLoopEndedCallbackId_ = 0;
137
- }
138
-
139
- void AudioBufferSourceNode::setOnLoopEndedCallbackId(uint64_t callbackId) {
140
- onLoopEndedCallbackId_ = callbackId;
141
- }
142
-
143
127
  void AudioBufferSourceNode::processNode(
144
128
  const std::shared_ptr<AudioBus> &processingBus,
145
129
  int framesToProcess) {
@@ -167,19 +151,35 @@ double AudioBufferSourceNode::getCurrentPosition() const {
167
151
  static_cast<int>(vReadIndex_), buffer_->getSampleRate());
168
152
  }
169
153
 
170
- void AudioBufferSourceNode::sendOnLoopEndedEvent() {
171
- auto onLoopEndedCallbackId =
172
- onLoopEndedCallbackId_.load(std::memory_order_acquire);
173
- if (onLoopEndedCallbackId != 0) {
174
- context_->audioEventHandlerRegistry_->invokeHandlerWithEventBody(
175
- "loopEnded", onLoopEndedCallbackId_, {});
176
- }
177
- }
178
-
179
154
  /**
180
155
  * Helper functions
181
156
  */
182
157
 
158
+ void AudioBufferSourceNode::processWithoutPitchCorrection(
159
+ const std::shared_ptr<AudioBus> &processingBus,
160
+ int framesToProcess) {
161
+ size_t startOffset = 0;
162
+ size_t offsetLength = 0;
163
+
164
+ auto computedPlaybackRate = getComputedPlaybackRateValue(framesToProcess);
165
+ updatePlaybackInfo(processingBus, framesToProcess, startOffset, offsetLength);
166
+
167
+ if (computedPlaybackRate == 0.0f || (!isPlaying() && !isStopScheduled())) {
168
+ processingBus->zero();
169
+ return;
170
+ }
171
+
172
+ if (std::fabs(computedPlaybackRate) == 1.0) {
173
+ processWithoutInterpolation(
174
+ processingBus, startOffset, offsetLength, computedPlaybackRate);
175
+ } else {
176
+ processWithInterpolation(
177
+ processingBus, startOffset, offsetLength, computedPlaybackRate);
178
+ }
179
+
180
+ sendOnPositionChangedEvent();
181
+ }
182
+
183
183
  void AudioBufferSourceNode::processWithoutInterpolation(
184
184
  const std::shared_ptr<AudioBus> &processingBus,
185
185
  size_t startOffset,
@@ -243,8 +243,6 @@ void AudioBufferSourceNode::processWithoutInterpolation(
243
243
  playbackState_ = PlaybackState::STOP_SCHEDULED;
244
244
  break;
245
245
  }
246
-
247
- sendOnLoopEndedEvent();
248
246
  }
249
247
  }
250
248
 
@@ -306,12 +304,23 @@ void AudioBufferSourceNode::processWithInterpolation(
306
304
  playbackState_ = PlaybackState::STOP_SCHEDULED;
307
305
  break;
308
306
  }
309
-
310
- sendOnLoopEndedEvent();
311
307
  }
312
308
  }
313
309
  }
314
310
 
311
+ float AudioBufferSourceNode::getComputedPlaybackRateValue(int framesToProcess) {
312
+ auto time = context_->getCurrentTime();
313
+
314
+ auto sampleRateFactor =
315
+ alignedBus_->getSampleRate() / context_->getSampleRate();
316
+ auto playbackRate =
317
+ playbackRateParam_->processKRateParam(framesToProcess, time);
318
+ auto detune = std::pow(
319
+ 2.0f, detuneParam_->processKRateParam(framesToProcess, time) / 1200.0f);
320
+
321
+ return playbackRate * sampleRateFactor * detune;
322
+ }
323
+
315
324
  double AudioBufferSourceNode::getVirtualStartFrame() {
316
325
  auto loopStartFrame = loopStart_ * context_->getSampleRate();
317
326
 
@@ -34,9 +34,6 @@ class AudioBufferSourceNode : public AudioBufferBaseSourceNode {
34
34
  void start(double when, double offset, double duration = -1);
35
35
  void disable() override;
36
36
 
37
- void clearOnLoopEndedCallback();
38
- void setOnLoopEndedCallbackId(uint64_t callbackId);
39
-
40
37
  protected:
41
38
  void processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override;
42
39
  double getCurrentPosition() const override;
@@ -48,12 +45,15 @@ class AudioBufferSourceNode : public AudioBufferBaseSourceNode {
48
45
  double loopStart_;
49
46
  double loopEnd_;
50
47
 
48
+ // pitch correction
49
+ bool pitchCorrection_;
50
+
51
51
  // User provided buffer
52
52
  std::shared_ptr<AudioBuffer> buffer_;
53
53
  std::shared_ptr<AudioBus> alignedBus_;
54
54
 
55
- std::atomic<uint64_t> onLoopEndedCallbackId_ = 0; // 0 means no callback
56
- void sendOnLoopEndedEvent();
55
+ void processWithoutPitchCorrection(const std::shared_ptr<AudioBus> &processingBus,
56
+ int framesToProcess);
57
57
 
58
58
  void processWithoutInterpolation(
59
59
  const std::shared_ptr<AudioBus>& processingBus,
@@ -65,7 +65,9 @@ class AudioBufferSourceNode : public AudioBufferBaseSourceNode {
65
65
  const std::shared_ptr<AudioBus>& processingBus,
66
66
  size_t startOffset,
67
67
  size_t offsetLength,
68
- float playbackRate) override;
68
+ float playbackRate);
69
+
70
+ float getComputedPlaybackRateValue(int framesToProcess);
69
71
 
70
72
  double getVirtualStartFrame();
71
73
  double getVirtualEndFrame();
@@ -17,7 +17,12 @@ AudioScheduledSourceNode::AudioScheduledSourceNode(BaseAudioContext *context)
17
17
  }
18
18
 
19
19
  AudioScheduledSourceNode::~AudioScheduledSourceNode() {
20
- clearOnEndedCallback();
20
+ if (onEndedCallbackId_ != 0 &&
21
+ context_->audioEventHandlerRegistry_ != nullptr) {
22
+ context_->audioEventHandlerRegistry_->unregisterHandler(
23
+ "ended", onEndedCallbackId_);
24
+ onEndedCallbackId_ = 0;
25
+ }
21
26
  }
22
27
 
23
28
  void AudioScheduledSourceNode::start(double when) {
@@ -27,7 +27,7 @@ class AudioScheduledSourceNode : public AudioNode {
27
27
  // FINISHED: The node has finished playing.
28
28
  enum class PlaybackState { UNSCHEDULED, SCHEDULED, PLAYING, STOP_SCHEDULED, FINISHED };
29
29
  explicit AudioScheduledSourceNode(BaseAudioContext *context);
30
- ~AudioScheduledSourceNode() override;
30
+ virtual ~AudioScheduledSourceNode();
31
31
 
32
32
  void start(double when);
33
33
  virtual void stop(double when);
@@ -43,6 +43,14 @@ class StreamerNode : public AudioScheduledSourceNode {
43
43
  bool initialize(const std::string& inputUrl);
44
44
  void stop(double when) override;
45
45
 
46
+ private:
47
+ static constexpr int SIZE = 4'000'000; // 4MB
48
+
49
+ public:
50
+ static constexpr int getEstimatedSize() {
51
+ return StreamerNode::SIZE;
52
+ } // in bytes
53
+
46
54
  protected:
47
55
  void processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override;
48
56
 
@@ -1,4 +1,4 @@
1
- #include <audioapi/core/utils/Constants.h>
1
+ #include <audioapi/core/Constants.h>
2
2
  #include <audioapi/dsp/Windows.h>
3
3
 
4
4
  namespace audioapi::dsp {
@@ -1,4 +1,4 @@
1
- #include <audioapi/HostObjects/sources/AudioBufferHostObject.h>
1
+ #include <audioapi/HostObjects/AudioBufferHostObject.h>
2
2
  #include <audioapi/events/AudioEventHandlerRegistry.h>
3
3
 
4
4
  namespace audioapi {
@@ -53,9 +53,8 @@ class AudioEventHandlerRegistry : public IAudioEventHandlerRegistry {
53
53
  "volumeChange",
54
54
  };
55
55
 
56
- static constexpr std::array<std::string_view, 6> AUDIO_API_EVENT_NAMES = {
56
+ static constexpr std::array<std::string_view, 5> AUDIO_API_EVENT_NAMES = {
57
57
  "ended",
58
- "loopEnded",
59
58
  "audioReady",
60
59
  "positionChanged",
61
60
  "audioError",
@@ -0,0 +1,48 @@
1
+ #pragma once
2
+
3
+ #include <audioapi/jsi/JsiHostObject.h>
4
+ #include <audioapi/events/AudioEventHandlerRegistry.h>
5
+
6
+ #include <jsi/jsi.h>
7
+ #include <ReactCommon/CallInvoker.h>
8
+ #include <memory>
9
+ #include <unordered_map>
10
+ #include <vector>
11
+ #include <string>
12
+
13
+ namespace audioapi {
14
+ using namespace facebook;
15
+
16
+ class AudioEventHandlerRegistryHostObject : public JsiHostObject {
17
+ public:
18
+ explicit AudioEventHandlerRegistryHostObject(const std::shared_ptr<AudioEventHandlerRegistry>& eventHandlerRegistry) {
19
+ eventHandlerRegistry_ = eventHandlerRegistry;
20
+
21
+ addFunctions(
22
+ JSI_EXPORT_FUNCTION(AudioEventHandlerRegistryHostObject, addAudioEventListener),
23
+ JSI_EXPORT_FUNCTION(AudioEventHandlerRegistryHostObject, removeAudioEventListener));
24
+ }
25
+
26
+ JSI_HOST_FUNCTION(addAudioEventListener) {
27
+ auto eventName = args[0].getString(runtime).utf8(runtime);
28
+ auto callback = std::make_shared<jsi::Function>(args[1].getObject(runtime).getFunction(runtime));
29
+
30
+ auto listenerId = eventHandlerRegistry_->registerHandler(eventName, callback);
31
+
32
+ return jsi::String::createFromUtf8(runtime, std::to_string(listenerId));
33
+ }
34
+
35
+ JSI_HOST_FUNCTION(removeAudioEventListener) {
36
+ auto eventName = args[0].getString(runtime).utf8(runtime);
37
+ uint64_t listenerId = std::stoull(args[1].getString(runtime).utf8(runtime));
38
+
39
+ eventHandlerRegistry_->unregisterHandler(eventName, listenerId);
40
+
41
+ return jsi::Value::undefined();
42
+ }
43
+
44
+ private:
45
+ std::shared_ptr<AudioEventHandlerRegistry> eventHandlerRegistry_;
46
+ };
47
+ } // namespace audioapi
48
+
@@ -9,20 +9,7 @@ using namespace facebook;
9
9
  class AudioArrayBuffer : public jsi::MutableBuffer {
10
10
  public:
11
11
  AudioArrayBuffer(uint8_t *data, size_t size): data_(data), size_(size) {}
12
- ~AudioArrayBuffer() override {
13
- if (data_ == nullptr) {
14
- return;
15
- }
16
- delete[] data_;
17
- }
18
- AudioArrayBuffer(AudioArrayBuffer &&other) noexcept
19
- : data_(other.data_), size_(other.size_) {
20
- other.data_ = nullptr;
21
- }
22
-
23
- AudioArrayBuffer(const AudioArrayBuffer &) = delete;
24
- AudioArrayBuffer &operator=(const AudioArrayBuffer &) = delete;
25
- AudioArrayBuffer &operator=(AudioArrayBuffer &&other) = delete;
12
+ ~AudioArrayBuffer() override = default;
26
13
 
27
14
  [[nodiscard]] size_t size() const override;
28
15
  uint8_t *data() override;