react-native-audio-api 0.8.3 → 0.9.0-nightly-96a5bcd-20251007

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 (312) hide show
  1. package/README.md +40 -39
  2. package/RNAudioAPI.podspec +17 -12
  3. package/android/build.gradle +44 -4
  4. package/android/src/main/cpp/audioapi/CMakeLists.txt +65 -0
  5. package/android/src/main/cpp/audioapi/android/AudioAPIModule.cpp +29 -1
  6. package/android/src/main/cpp/audioapi/android/AudioAPIModule.h +14 -0
  7. package/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.cpp +7 -1
  8. package/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.h +6 -1
  9. package/android/src/main/cpp/audioapi/android/core/AudioPlayer.cpp +1 -1
  10. package/android/src/main/cpp/audioapi/android/core/NativeAudioRecorder.hpp +36 -0
  11. package/android/src/main/cpp/audioapi/android/core/{AudioDecoder.cpp → utils/AudioDecoder.cpp} +79 -75
  12. package/android/src/main/java/com/swmansion/audioapi/AudioAPIModule.kt +11 -1
  13. package/android/src/main/java/com/swmansion/audioapi/core/NativeAudioRecorder.kt +24 -0
  14. package/android/src/main/java/com/swmansion/audioapi/system/MediaSessionManager.kt +15 -2
  15. package/common/cpp/audioapi/AudioAPIModuleInstaller.h +129 -38
  16. package/common/cpp/audioapi/HostObjects/AudioContextHostObject.cpp +57 -0
  17. package/common/cpp/audioapi/HostObjects/AudioContextHostObject.h +6 -46
  18. package/common/cpp/audioapi/HostObjects/AudioNodeHostObject.cpp +70 -6
  19. package/common/cpp/audioapi/HostObjects/AudioNodeHostObject.h +10 -66
  20. package/common/cpp/audioapi/HostObjects/AudioParamHostObject.cpp +105 -0
  21. package/common/cpp/audioapi/HostObjects/AudioParamHostObject.h +17 -91
  22. package/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.cpp +262 -6
  23. package/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.h +26 -241
  24. package/common/cpp/audioapi/HostObjects/OfflineAudioContextHostObject.cpp +70 -0
  25. package/common/cpp/audioapi/HostObjects/OfflineAudioContextHostObject.h +6 -50
  26. package/common/cpp/audioapi/HostObjects/WorkletNodeHostObject.h +18 -0
  27. package/common/cpp/audioapi/HostObjects/WorkletProcessingNodeHostObject.h +18 -0
  28. package/common/cpp/audioapi/HostObjects/analysis/AnalyserNodeHostObject.cpp +148 -0
  29. package/common/cpp/audioapi/HostObjects/analysis/AnalyserNodeHostObject.h +37 -0
  30. package/common/cpp/audioapi/HostObjects/effects/BiquadFilterNodeHostObject.cpp +92 -0
  31. package/common/cpp/audioapi/HostObjects/effects/BiquadFilterNodeHostObject.h +29 -0
  32. package/common/cpp/audioapi/HostObjects/effects/GainNodeHostObject.cpp +20 -0
  33. package/common/cpp/audioapi/HostObjects/effects/GainNodeHostObject.h +19 -0
  34. package/common/cpp/audioapi/HostObjects/effects/StereoPannerNodeHostObject.cpp +21 -0
  35. package/common/cpp/audioapi/HostObjects/effects/StereoPannerNodeHostObject.h +21 -0
  36. package/common/cpp/audioapi/HostObjects/events/AudioEventHandlerRegistryHostObject.cpp +41 -0
  37. package/common/cpp/audioapi/HostObjects/events/AudioEventHandlerRegistryHostObject.h +28 -0
  38. package/common/cpp/audioapi/HostObjects/inputs/AudioRecorderHostObject.cpp +69 -0
  39. package/common/cpp/audioapi/HostObjects/inputs/AudioRecorderHostObject.h +33 -0
  40. package/common/cpp/audioapi/HostObjects/sources/AudioBufferBaseSourceNodeHostObject.cpp +73 -0
  41. package/common/cpp/audioapi/HostObjects/sources/AudioBufferBaseSourceNodeHostObject.h +29 -0
  42. package/common/cpp/audioapi/HostObjects/sources/AudioBufferHostObject.cpp +94 -0
  43. package/common/cpp/audioapi/HostObjects/sources/AudioBufferHostObject.h +46 -0
  44. package/common/cpp/audioapi/HostObjects/sources/AudioBufferQueueSourceNodeHostObject.cpp +60 -0
  45. package/common/cpp/audioapi/HostObjects/sources/AudioBufferQueueSourceNodeHostObject.h +25 -0
  46. package/common/cpp/audioapi/HostObjects/sources/AudioBufferSourceNodeHostObject.cpp +152 -0
  47. package/common/cpp/audioapi/HostObjects/sources/AudioBufferSourceNodeHostObject.h +37 -0
  48. package/common/cpp/audioapi/HostObjects/sources/AudioScheduledSourceNodeHostObject.cpp +52 -0
  49. package/common/cpp/audioapi/HostObjects/sources/AudioScheduledSourceNodeHostObject.h +25 -0
  50. package/common/cpp/audioapi/HostObjects/sources/ConstantSourceNodeHostObject.cpp +19 -0
  51. package/common/cpp/audioapi/HostObjects/sources/ConstantSourceNodeHostObject.h +21 -0
  52. package/common/cpp/audioapi/HostObjects/sources/OscillatorNodeHostObject.cpp +55 -0
  53. package/common/cpp/audioapi/HostObjects/sources/OscillatorNodeHostObject.h +27 -0
  54. package/common/cpp/audioapi/HostObjects/{RecorderAdapterNodeHostObject.h → sources/RecorderAdapterNodeHostObject.h} +1 -2
  55. package/common/cpp/audioapi/HostObjects/sources/StreamerNodeHostObject.cpp +22 -0
  56. package/common/cpp/audioapi/HostObjects/sources/StreamerNodeHostObject.h +28 -0
  57. package/common/cpp/audioapi/HostObjects/sources/WorkletSourceNodeHostObject.h +18 -0
  58. package/common/cpp/audioapi/HostObjects/utils/AudioDecoderHostObject.cpp +107 -0
  59. package/common/cpp/audioapi/HostObjects/utils/AudioDecoderHostObject.h +28 -0
  60. package/common/cpp/audioapi/core/AudioContext.cpp +3 -4
  61. package/common/cpp/audioapi/core/AudioContext.h +2 -1
  62. package/common/cpp/audioapi/core/AudioNode.cpp +3 -3
  63. package/common/cpp/audioapi/core/AudioNode.h +2 -2
  64. package/common/cpp/audioapi/core/AudioParam.cpp +2 -2
  65. package/common/cpp/audioapi/core/AudioParam.h +1 -1
  66. package/common/cpp/audioapi/core/BaseAudioContext.cpp +47 -38
  67. package/common/cpp/audioapi/core/BaseAudioContext.h +17 -16
  68. package/common/cpp/audioapi/core/OfflineAudioContext.cpp +4 -5
  69. package/common/cpp/audioapi/core/OfflineAudioContext.h +2 -1
  70. package/common/cpp/audioapi/core/analysis/AnalyserNode.cpp +3 -1
  71. package/common/cpp/audioapi/core/analysis/AnalyserNode.h +1 -1
  72. package/common/cpp/audioapi/core/destinations/AudioDestinationNode.h +1 -1
  73. package/common/cpp/audioapi/core/effects/BiquadFilterNode.cpp +3 -1
  74. package/common/cpp/audioapi/core/effects/BiquadFilterNode.h +1 -1
  75. package/common/cpp/audioapi/core/effects/GainNode.cpp +3 -1
  76. package/common/cpp/audioapi/core/effects/GainNode.h +1 -1
  77. package/common/cpp/audioapi/core/effects/PeriodicWave.cpp +1 -1
  78. package/common/cpp/audioapi/core/effects/StereoPannerNode.cpp +18 -13
  79. package/common/cpp/audioapi/core/effects/StereoPannerNode.h +1 -1
  80. package/common/cpp/audioapi/core/effects/WorkletNode.cpp +89 -0
  81. package/common/cpp/audioapi/core/effects/WorkletNode.h +65 -0
  82. package/common/cpp/audioapi/core/effects/WorkletProcessingNode.cpp +91 -0
  83. package/common/cpp/audioapi/core/effects/WorkletProcessingNode.h +52 -0
  84. package/common/cpp/audioapi/core/inputs/AudioRecorder.cpp +1 -1
  85. package/common/cpp/audioapi/core/inputs/AudioRecorder.h +2 -2
  86. package/common/cpp/audioapi/core/sources/AudioBufferBaseSourceNode.cpp +47 -10
  87. package/common/cpp/audioapi/core/sources/AudioBufferBaseSourceNode.h +18 -3
  88. package/common/cpp/audioapi/core/sources/AudioBufferQueueSourceNode.cpp +98 -14
  89. package/common/cpp/audioapi/core/sources/AudioBufferQueueSourceNode.h +9 -3
  90. package/common/cpp/audioapi/core/sources/AudioBufferSourceNode.cpp +37 -44
  91. package/common/cpp/audioapi/core/sources/AudioBufferSourceNode.h +7 -9
  92. package/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.cpp +1 -6
  93. package/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.h +1 -1
  94. package/common/cpp/audioapi/core/sources/ConstantSourceNode.cpp +53 -0
  95. package/common/cpp/audioapi/core/sources/ConstantSourceNode.h +26 -0
  96. package/common/cpp/audioapi/core/sources/OscillatorNode.cpp +7 -2
  97. package/common/cpp/audioapi/core/sources/OscillatorNode.h +1 -1
  98. package/common/cpp/audioapi/core/sources/RecorderAdapterNode.cpp +3 -1
  99. package/common/cpp/audioapi/core/sources/RecorderAdapterNode.h +1 -1
  100. package/common/cpp/audioapi/core/sources/StreamerNode.cpp +9 -1
  101. package/common/cpp/audioapi/core/sources/StreamerNode.h +1 -9
  102. package/common/cpp/audioapi/core/sources/WorkletSourceNode.cpp +84 -0
  103. package/common/cpp/audioapi/core/sources/WorkletSourceNode.h +47 -0
  104. package/common/cpp/audioapi/core/types/AudioFormat.h +16 -0
  105. package/common/cpp/audioapi/core/utils/AudioDecoder.h +36 -90
  106. package/common/cpp/audioapi/core/{AudioParamEventQueue.cpp → utils/AudioParamEventQueue.cpp} +13 -7
  107. package/common/cpp/audioapi/core/{Constants.h → utils/Constants.h} +5 -0
  108. package/common/cpp/audioapi/core/utils/worklets/SafeIncludes.h +52 -0
  109. package/common/cpp/audioapi/core/utils/worklets/WorkletsRunner.cpp +9 -0
  110. package/common/cpp/audioapi/core/utils/worklets/WorkletsRunner.h +73 -0
  111. package/common/cpp/audioapi/dsp/Windows.cpp +1 -1
  112. package/common/cpp/audioapi/events/AudioEventHandlerRegistry.cpp +1 -1
  113. package/common/cpp/audioapi/events/AudioEventHandlerRegistry.h +2 -1
  114. package/common/cpp/audioapi/jsi/AudioArrayBuffer.h +14 -1
  115. package/common/cpp/audioapi/jsi/JsiHostObject.h +6 -12
  116. package/common/cpp/audioapi/jsi/JsiPromise.cpp +49 -0
  117. package/common/cpp/audioapi/jsi/JsiPromise.h +29 -1
  118. package/common/cpp/audioapi/libs/ffmpeg/FFmpegDecoding.cpp +241 -282
  119. package/common/cpp/audioapi/libs/ffmpeg/FFmpegDecoding.h +57 -19
  120. package/common/cpp/audioapi/utils/AudioBus.cpp +1 -1
  121. package/common/cpp/audioapi/utils/ThreadPool.hpp +104 -0
  122. package/common/cpp/test/AudioParamTest.cpp +204 -0
  123. package/common/cpp/test/CMakeLists.txt +13 -4
  124. package/common/cpp/test/GainTest.cpp +11 -10
  125. package/common/cpp/test/OscillatorTest.cpp +2 -1
  126. package/common/cpp/test/StereoPannerTest.cpp +129 -0
  127. package/ios/audioapi/ios/AudioAPIModule.mm +32 -5
  128. package/ios/audioapi/ios/core/IOSAudioPlayer.mm +1 -1
  129. package/ios/audioapi/ios/core/IOSAudioRecorder.mm +1 -1
  130. package/ios/audioapi/ios/core/utils/AudioDecoder.mm +160 -0
  131. package/lib/commonjs/api.js +50 -3
  132. package/lib/commonjs/api.js.map +1 -1
  133. package/lib/commonjs/api.web.js +8 -0
  134. package/lib/commonjs/api.web.js.map +1 -1
  135. package/lib/commonjs/core/AudioBufferBaseSourceNode.js +7 -7
  136. package/lib/commonjs/core/AudioBufferBaseSourceNode.js.map +1 -1
  137. package/lib/commonjs/core/AudioBufferQueueSourceNode.js +1 -6
  138. package/lib/commonjs/core/AudioBufferQueueSourceNode.js.map +1 -1
  139. package/lib/commonjs/core/AudioBufferSourceNode.js +15 -0
  140. package/lib/commonjs/core/AudioBufferSourceNode.js.map +1 -1
  141. package/lib/commonjs/core/AudioContext.js +10 -1
  142. package/lib/commonjs/core/AudioContext.js.map +1 -1
  143. package/lib/commonjs/core/AudioDecoder.js +48 -0
  144. package/lib/commonjs/core/AudioDecoder.js.map +1 -0
  145. package/lib/commonjs/core/AudioScheduledSourceNode.js +4 -4
  146. package/lib/commonjs/core/AudioScheduledSourceNode.js.map +1 -1
  147. package/lib/commonjs/core/BaseAudioContext.js +76 -28
  148. package/lib/commonjs/core/BaseAudioContext.js.map +1 -1
  149. package/lib/commonjs/core/ConstantSourceNode.js +17 -0
  150. package/lib/commonjs/core/ConstantSourceNode.js.map +1 -0
  151. package/lib/commonjs/core/OfflineAudioContext.js +11 -2
  152. package/lib/commonjs/core/OfflineAudioContext.js.map +1 -1
  153. package/lib/commonjs/core/OscillatorNode.js +6 -0
  154. package/lib/commonjs/core/OscillatorNode.js.map +1 -1
  155. package/lib/commonjs/core/WorkletNode.js +11 -0
  156. package/lib/commonjs/core/WorkletNode.js.map +1 -0
  157. package/lib/commonjs/core/WorkletProcessingNode.js +11 -0
  158. package/lib/commonjs/core/WorkletProcessingNode.js.map +1 -0
  159. package/lib/commonjs/core/WorkletSourceNode.js +11 -0
  160. package/lib/commonjs/core/WorkletSourceNode.js.map +1 -0
  161. package/lib/commonjs/hooks/{useSytemVolume.js → useSystemVolume.js} +1 -1
  162. package/lib/commonjs/hooks/useSystemVolume.js.map +1 -0
  163. package/lib/commonjs/utils/index.js +9 -0
  164. package/lib/commonjs/utils/index.js.map +1 -1
  165. package/lib/commonjs/web-core/AudioContext.js +4 -0
  166. package/lib/commonjs/web-core/AudioContext.js.map +1 -1
  167. package/lib/commonjs/web-core/AudioScheduledSourceNode.js +1 -1
  168. package/lib/commonjs/web-core/AudioScheduledSourceNode.js.map +1 -1
  169. package/lib/commonjs/web-core/ConstantSourceNode.js +17 -0
  170. package/lib/commonjs/web-core/ConstantSourceNode.js.map +1 -0
  171. package/lib/commonjs/web-core/OfflineAudioContext.js +4 -0
  172. package/lib/commonjs/web-core/OfflineAudioContext.js.map +1 -1
  173. package/lib/module/api.js +8 -3
  174. package/lib/module/api.js.map +1 -1
  175. package/lib/module/api.web.js +1 -0
  176. package/lib/module/api.web.js.map +1 -1
  177. package/lib/module/core/AudioBufferBaseSourceNode.js +7 -7
  178. package/lib/module/core/AudioBufferBaseSourceNode.js.map +1 -1
  179. package/lib/module/core/AudioBufferQueueSourceNode.js +1 -6
  180. package/lib/module/core/AudioBufferQueueSourceNode.js.map +1 -1
  181. package/lib/module/core/AudioBufferSourceNode.js +15 -0
  182. package/lib/module/core/AudioBufferSourceNode.js.map +1 -1
  183. package/lib/module/core/AudioContext.js +10 -1
  184. package/lib/module/core/AudioContext.js.map +1 -1
  185. package/lib/module/core/AudioDecoder.js +42 -0
  186. package/lib/module/core/AudioDecoder.js.map +1 -0
  187. package/lib/module/core/AudioScheduledSourceNode.js +4 -4
  188. package/lib/module/core/AudioScheduledSourceNode.js.map +1 -1
  189. package/lib/module/core/BaseAudioContext.js +76 -28
  190. package/lib/module/core/BaseAudioContext.js.map +1 -1
  191. package/lib/module/core/ConstantSourceNode.js +11 -0
  192. package/lib/module/core/ConstantSourceNode.js.map +1 -0
  193. package/lib/module/core/OfflineAudioContext.js +11 -2
  194. package/lib/module/core/OfflineAudioContext.js.map +1 -1
  195. package/lib/module/core/OscillatorNode.js +6 -0
  196. package/lib/module/core/OscillatorNode.js.map +1 -1
  197. package/lib/module/core/WorkletNode.js +5 -0
  198. package/lib/module/core/WorkletNode.js.map +1 -0
  199. package/lib/module/core/WorkletProcessingNode.js +5 -0
  200. package/lib/module/core/WorkletProcessingNode.js.map +1 -0
  201. package/lib/module/core/WorkletSourceNode.js +5 -0
  202. package/lib/module/core/WorkletSourceNode.js.map +1 -0
  203. package/lib/module/hooks/{useSytemVolume.js → useSystemVolume.js} +1 -1
  204. package/lib/module/hooks/useSystemVolume.js.map +1 -0
  205. package/lib/module/utils/index.js +8 -0
  206. package/lib/module/utils/index.js.map +1 -1
  207. package/lib/module/web-core/AudioContext.js +4 -0
  208. package/lib/module/web-core/AudioContext.js.map +1 -1
  209. package/lib/module/web-core/AudioScheduledSourceNode.js +1 -1
  210. package/lib/module/web-core/AudioScheduledSourceNode.js.map +1 -1
  211. package/lib/module/web-core/ConstantSourceNode.js +11 -0
  212. package/lib/module/web-core/ConstantSourceNode.js.map +1 -0
  213. package/lib/module/web-core/OfflineAudioContext.js +4 -0
  214. package/lib/module/web-core/OfflineAudioContext.js.map +1 -1
  215. package/lib/typescript/api.d.ts +11 -5
  216. package/lib/typescript/api.d.ts.map +1 -1
  217. package/lib/typescript/api.web.d.ts +1 -0
  218. package/lib/typescript/api.web.d.ts.map +1 -1
  219. package/lib/typescript/core/AudioBufferBaseSourceNode.d.ts +2 -2
  220. package/lib/typescript/core/AudioBufferBaseSourceNode.d.ts.map +1 -1
  221. package/lib/typescript/core/AudioBufferQueueSourceNode.d.ts +1 -1
  222. package/lib/typescript/core/AudioBufferQueueSourceNode.d.ts.map +1 -1
  223. package/lib/typescript/core/AudioBufferSourceNode.d.ts +4 -0
  224. package/lib/typescript/core/AudioBufferSourceNode.d.ts.map +1 -1
  225. package/lib/typescript/core/AudioContext.d.ts +1 -0
  226. package/lib/typescript/core/AudioContext.d.ts.map +1 -1
  227. package/lib/typescript/core/AudioDecoder.d.ts +4 -0
  228. package/lib/typescript/core/AudioDecoder.d.ts.map +1 -0
  229. package/lib/typescript/core/AudioScheduledSourceNode.d.ts +1 -1
  230. package/lib/typescript/core/BaseAudioContext.d.ts +21 -16
  231. package/lib/typescript/core/BaseAudioContext.d.ts.map +1 -1
  232. package/lib/typescript/core/ConstantSourceNode.d.ts +9 -0
  233. package/lib/typescript/core/ConstantSourceNode.d.ts.map +1 -0
  234. package/lib/typescript/core/OfflineAudioContext.d.ts +1 -0
  235. package/lib/typescript/core/OfflineAudioContext.d.ts.map +1 -1
  236. package/lib/typescript/core/OscillatorNode.d.ts +3 -0
  237. package/lib/typescript/core/OscillatorNode.d.ts.map +1 -1
  238. package/lib/typescript/core/WorkletNode.d.ts +4 -0
  239. package/lib/typescript/core/WorkletNode.d.ts.map +1 -0
  240. package/lib/typescript/core/WorkletProcessingNode.d.ts +4 -0
  241. package/lib/typescript/core/WorkletProcessingNode.d.ts.map +1 -0
  242. package/lib/typescript/core/WorkletSourceNode.d.ts +4 -0
  243. package/lib/typescript/core/WorkletSourceNode.d.ts.map +1 -0
  244. package/lib/typescript/events/types.d.ts +2 -0
  245. package/lib/typescript/events/types.d.ts.map +1 -1
  246. package/lib/typescript/hooks/{useSytemVolume.d.ts → useSystemVolume.d.ts} +1 -1
  247. package/lib/typescript/hooks/useSystemVolume.d.ts.map +1 -0
  248. package/lib/typescript/interfaces.d.ts +27 -6
  249. package/lib/typescript/interfaces.d.ts.map +1 -1
  250. package/lib/typescript/types.d.ts +2 -1
  251. package/lib/typescript/types.d.ts.map +1 -1
  252. package/lib/typescript/utils/index.d.ts +8 -0
  253. package/lib/typescript/utils/index.d.ts.map +1 -1
  254. package/lib/typescript/web-core/AudioBufferSourceNode.d.ts +1 -1
  255. package/lib/typescript/web-core/AudioContext.d.ts +4 -2
  256. package/lib/typescript/web-core/AudioContext.d.ts.map +1 -1
  257. package/lib/typescript/web-core/AudioScheduledSourceNode.d.ts +1 -1
  258. package/lib/typescript/web-core/BaseAudioContext.d.ts +2 -0
  259. package/lib/typescript/web-core/BaseAudioContext.d.ts.map +1 -1
  260. package/lib/typescript/web-core/ConstantSourceNode.d.ts +8 -0
  261. package/lib/typescript/web-core/ConstantSourceNode.d.ts.map +1 -0
  262. package/lib/typescript/web-core/OfflineAudioContext.d.ts +4 -2
  263. package/lib/typescript/web-core/OfflineAudioContext.d.ts.map +1 -1
  264. package/package.json +3 -2
  265. package/src/api.ts +17 -3
  266. package/src/api.web.ts +1 -0
  267. package/src/core/AudioBufferBaseSourceNode.ts +9 -9
  268. package/src/core/AudioBufferQueueSourceNode.ts +1 -9
  269. package/src/core/AudioBufferSourceNode.ts +28 -0
  270. package/src/core/AudioContext.ts +12 -1
  271. package/src/core/AudioDecoder.ts +78 -0
  272. package/src/core/AudioScheduledSourceNode.ts +5 -5
  273. package/src/core/BaseAudioContext.ts +174 -41
  274. package/src/core/ConstantSourceNode.ts +13 -0
  275. package/src/core/OfflineAudioContext.ts +18 -2
  276. package/src/core/OscillatorNode.ts +11 -0
  277. package/src/core/WorkletNode.ts +3 -0
  278. package/src/core/WorkletProcessingNode.ts +3 -0
  279. package/src/core/WorkletSourceNode.ts +3 -0
  280. package/src/events/types.ts +2 -0
  281. package/src/interfaces.ts +77 -11
  282. package/src/types.ts +3 -1
  283. package/src/utils/index.ts +21 -0
  284. package/src/web-core/AudioBufferSourceNode.tsx +1 -1
  285. package/src/web-core/AudioContext.tsx +7 -2
  286. package/src/web-core/AudioScheduledSourceNode.tsx +1 -1
  287. package/src/web-core/BaseAudioContext.tsx +2 -0
  288. package/src/web-core/ConstantSourceNode.tsx +12 -0
  289. package/src/web-core/OfflineAudioContext.tsx +7 -2
  290. package/common/cpp/audioapi/HostObjects/AnalyserNodeHostObject.h +0 -149
  291. package/common/cpp/audioapi/HostObjects/AudioBufferBaseSourceNodeHostObject.h +0 -76
  292. package/common/cpp/audioapi/HostObjects/AudioBufferHostObject.h +0 -120
  293. package/common/cpp/audioapi/HostObjects/AudioBufferQueueSourceNodeHostObject.h +0 -67
  294. package/common/cpp/audioapi/HostObjects/AudioBufferSourceNodeHostObject.h +0 -142
  295. package/common/cpp/audioapi/HostObjects/AudioRecorderHostObject.h +0 -86
  296. package/common/cpp/audioapi/HostObjects/AudioScheduledSourceNodeHostObject.h +0 -56
  297. package/common/cpp/audioapi/HostObjects/BiquadFilterNodeHostObject.h +0 -89
  298. package/common/cpp/audioapi/HostObjects/GainNodeHostObject.h +0 -27
  299. package/common/cpp/audioapi/HostObjects/OscillatorNodeHostObject.h +0 -65
  300. package/common/cpp/audioapi/HostObjects/StereoPannerNodeHostObject.h +0 -29
  301. package/common/cpp/audioapi/HostObjects/StreamerNodeHostObject.h +0 -30
  302. package/common/cpp/audioapi/events/AudioEventHandlerRegistryHostObject.h +0 -48
  303. package/ios/audioapi/ios/core/AudioDecoder.mm +0 -156
  304. package/ios/audioapi/ios/events/IOSAudioEventHandlerRegistry.h +0 -7
  305. package/ios/audioapi/ios/events/IOSAudioEventHandlerRegistry.mm +0 -12
  306. package/lib/commonjs/hooks/useSytemVolume.js.map +0 -1
  307. package/lib/module/hooks/useSytemVolume.js.map +0 -1
  308. package/lib/typescript/hooks/useSytemVolume.d.ts.map +0 -1
  309. /package/common/cpp/audioapi/HostObjects/{AudioDestinationNodeHostObject.h → destinations/AudioDestinationNodeHostObject.h} +0 -0
  310. /package/common/cpp/audioapi/HostObjects/{PeriodicWaveHostObject.h → effects/PeriodicWaveHostObject.h} +0 -0
  311. /package/common/cpp/audioapi/core/{AudioParamEventQueue.h → utils/AudioParamEventQueue.h} +0 -0
  312. /package/src/hooks/{useSytemVolume.ts → useSystemVolume.ts} +0 -0
@@ -1,7 +1,7 @@
1
1
  #include <audioapi/core/AudioParam.h>
2
2
  #include <audioapi/core/BaseAudioContext.h>
3
- #include <audioapi/core/Constants.h>
4
3
  #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,8 +11,9 @@
11
11
  namespace audioapi {
12
12
 
13
13
  AudioBufferQueueSourceNode::AudioBufferQueueSourceNode(
14
- BaseAudioContext *context)
15
- : AudioBufferBaseSourceNode(context) {
14
+ BaseAudioContext *context,
15
+ bool pitchCorrection)
16
+ : AudioBufferBaseSourceNode(context, pitchCorrection) {
16
17
  buffers_ = {};
17
18
  stretch_->presetDefault(channelCount_, context_->getSampleRate());
18
19
 
@@ -86,22 +87,28 @@ void AudioBufferQueueSourceNode::disable() {
86
87
  buffers_ = {};
87
88
  }
88
89
 
89
- void AudioBufferQueueSourceNode::processNode(
90
+ std::shared_ptr<AudioBus> AudioBufferQueueSourceNode::processNode(
90
91
  const std::shared_ptr<AudioBus> &processingBus,
91
92
  int framesToProcess) {
92
93
  if (auto locker = Locker::tryLock(getBufferLock())) {
93
- // No audio data to fill, zero the output and return.
94
+ // no audio data to fill, zero the output and return.
94
95
  if (buffers_.empty()) {
95
96
  processingBus->zero();
96
- return;
97
+ return processingBus;
97
98
  }
98
99
 
99
- processWithPitchCorrection(processingBus, framesToProcess);
100
+ if (!pitchCorrection_) {
101
+ processWithoutPitchCorrection(processingBus, framesToProcess);
102
+ } else {
103
+ processWithPitchCorrection(processingBus, framesToProcess);
104
+ }
100
105
 
101
106
  handleStopScheduled();
102
107
  } else {
103
108
  processingBus->zero();
104
109
  }
110
+
111
+ return processingBus;
105
112
  }
106
113
 
107
114
  double AudioBufferQueueSourceNode::getCurrentPosition() const {
@@ -135,6 +142,7 @@ void AudioBufferQueueSourceNode::processWithoutInterpolation(
135
142
 
136
143
  assert(readIndex >= 0);
137
144
  assert(writeIndex >= 0);
145
+ assert(readIndex + framesToCopy <= buffer->getLength());
138
146
  assert(writeIndex + framesToCopy <= processingBus->getSize());
139
147
 
140
148
  processingBus->copy(
@@ -149,7 +157,7 @@ void AudioBufferQueueSourceNode::processWithoutInterpolation(
149
157
  buffers_.pop();
150
158
 
151
159
  std::unordered_map<std::string, EventValue> body = {
152
- {"bufferId", std::to_string(bufferId)}};
160
+ {"bufferId", std::to_string(bufferId)}, {"isLast", buffers_.empty()}};
153
161
  context_->audioEventHandlerRegistry_->invokeHandlerWithEventBody(
154
162
  "ended", onEndedCallbackId_, body);
155
163
 
@@ -158,13 +166,12 @@ void AudioBufferQueueSourceNode::processWithoutInterpolation(
158
166
  readIndex = 0;
159
167
 
160
168
  break;
161
- } else {
162
- data = buffers_.front();
163
- bufferId = data.first;
164
- buffer = data.second;
165
-
166
- readIndex = 0;
167
169
  }
170
+
171
+ data = buffers_.front();
172
+ bufferId = data.first;
173
+ buffer = data.second;
174
+ readIndex = 0;
168
175
  }
169
176
  }
170
177
 
@@ -172,4 +179,81 @@ void AudioBufferQueueSourceNode::processWithoutInterpolation(
172
179
  vReadIndex_ = static_cast<double>(readIndex);
173
180
  }
174
181
 
182
+ void AudioBufferQueueSourceNode::processWithInterpolation(
183
+ const std::shared_ptr<AudioBus> &processingBus,
184
+ size_t startOffset,
185
+ size_t offsetLength,
186
+ float playbackRate) {
187
+ size_t writeIndex = startOffset;
188
+ size_t framesLeft = offsetLength;
189
+
190
+ auto data = buffers_.front();
191
+ auto bufferId = data.first;
192
+ auto buffer = data.second;
193
+
194
+ while (framesLeft > 0) {
195
+ auto readIndex = static_cast<size_t>(vReadIndex_);
196
+ size_t nextReadIndex = readIndex + 1;
197
+ auto factor =
198
+ static_cast<float>(vReadIndex_ - static_cast<double>(readIndex));
199
+
200
+ bool crossBufferInterpolation = false;
201
+ std::shared_ptr<AudioBuffer> nextBuffer = nullptr;
202
+
203
+ if (nextReadIndex >= buffer->getLength()) {
204
+ if (buffers_.size() > 1) {
205
+ auto tempQueue = buffers_;
206
+ tempQueue.pop();
207
+ nextBuffer = tempQueue.front().second;
208
+ nextReadIndex = 0;
209
+ crossBufferInterpolation = true;
210
+ } else {
211
+ nextReadIndex = readIndex;
212
+ }
213
+ }
214
+
215
+ for (int i = 0; i < processingBus->getNumberOfChannels(); i += 1) {
216
+ float *destination = processingBus->getChannel(i)->getData();
217
+ const float *currentSource = buffer->bus_->getChannel(i)->getData();
218
+
219
+ if (crossBufferInterpolation) {
220
+ const float *nextSource = nextBuffer->bus_->getChannel(i)->getData();
221
+ float currentSample = currentSource[readIndex];
222
+ float nextSample = nextSource[nextReadIndex];
223
+ destination[writeIndex] =
224
+ currentSample + factor * (nextSample - currentSample);
225
+ } else {
226
+ destination[writeIndex] = dsp::linearInterpolate(
227
+ currentSource, readIndex, nextReadIndex, factor);
228
+ }
229
+ }
230
+
231
+ writeIndex += 1;
232
+ // queue source node always use positive playbackRate
233
+ vReadIndex_ += std::abs(playbackRate);
234
+ framesLeft -= 1;
235
+
236
+ if (vReadIndex_ >= static_cast<double>(buffer->getLength())) {
237
+ playedBuffersDuration_ += buffer->getDuration();
238
+ buffers_.pop();
239
+
240
+ std::unordered_map<std::string, EventValue> body = {
241
+ {"bufferId", std::to_string(bufferId)}};
242
+ context_->audioEventHandlerRegistry_->invokeHandlerWithEventBody(
243
+ "ended", onEndedCallbackId_, body);
244
+
245
+ if (buffers_.empty()) {
246
+ processingBus->zero(writeIndex, framesLeft);
247
+ vReadIndex_ = 0.0;
248
+ break;
249
+ }
250
+
251
+ vReadIndex_ = vReadIndex_ - buffer->getLength();
252
+ data = buffers_.front();
253
+ bufferId = data.first;
254
+ buffer = data.second;
255
+ }
256
+ }
257
+ }
258
+
175
259
  } // namespace audioapi
@@ -17,19 +17,19 @@ class AudioParam;
17
17
 
18
18
  class AudioBufferQueueSourceNode : public AudioBufferBaseSourceNode {
19
19
  public:
20
- explicit AudioBufferQueueSourceNode(BaseAudioContext *context);
20
+ explicit AudioBufferQueueSourceNode(BaseAudioContext *context, bool pitchCorrection);
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(const size_t bufferId);
27
+ void dequeueBuffer(size_t bufferId);
28
28
  void clearBuffers();
29
29
  void disable() override;
30
30
 
31
31
  protected:
32
- void processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override;
32
+ std::shared_ptr<AudioBus> processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override;
33
33
  double getCurrentPosition() const override;
34
34
 
35
35
  private:
@@ -46,6 +46,12 @@ 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;
49
55
  };
50
56
 
51
57
  } // 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>
4
3
  #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,12 +13,11 @@ namespace audioapi {
13
13
  AudioBufferSourceNode::AudioBufferSourceNode(
14
14
  BaseAudioContext *context,
15
15
  bool pitchCorrection)
16
- : AudioBufferBaseSourceNode(context),
16
+ : AudioBufferBaseSourceNode(context, pitchCorrection),
17
17
  loop_(false),
18
18
  loopSkip_(false),
19
19
  loopStart_(0),
20
- loopEnd_(0),
21
- pitchCorrection_(pitchCorrection) {
20
+ loopEnd_(0) {
22
21
  buffer_ = std::shared_ptr<AudioBuffer>(nullptr);
23
22
  alignedBus_ = std::shared_ptr<AudioBus>(nullptr);
24
23
 
@@ -30,6 +29,8 @@ AudioBufferSourceNode::~AudioBufferSourceNode() {
30
29
 
31
30
  buffer_.reset();
32
31
  alignedBus_.reset();
32
+
33
+ clearOnLoopEndedCallback();
33
34
  }
34
35
 
35
36
  bool AudioBufferSourceNode::getLoop() const {
@@ -124,14 +125,29 @@ void AudioBufferSourceNode::disable() {
124
125
  alignedBus_.reset();
125
126
  }
126
127
 
127
- void AudioBufferSourceNode::processNode(
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
+ std::shared_ptr<AudioBus> AudioBufferSourceNode::processNode(
128
144
  const std::shared_ptr<AudioBus> &processingBus,
129
145
  int framesToProcess) {
130
146
  if (auto locker = Locker::tryLock(getBufferLock())) {
131
147
  // No audio data to fill, zero the output and return.
132
148
  if (!alignedBus_) {
133
149
  processingBus->zero();
134
- return;
150
+ return processingBus;
135
151
  }
136
152
 
137
153
  if (!pitchCorrection_) {
@@ -144,6 +160,8 @@ void AudioBufferSourceNode::processNode(
144
160
  } else {
145
161
  processingBus->zero();
146
162
  }
163
+
164
+ return processingBus;
147
165
  }
148
166
 
149
167
  double AudioBufferSourceNode::getCurrentPosition() const {
@@ -151,35 +169,19 @@ double AudioBufferSourceNode::getCurrentPosition() const {
151
169
  static_cast<int>(vReadIndex_), buffer_->getSampleRate());
152
170
  }
153
171
 
172
+ void AudioBufferSourceNode::sendOnLoopEndedEvent() {
173
+ auto onLoopEndedCallbackId =
174
+ onLoopEndedCallbackId_.load(std::memory_order_acquire);
175
+ if (onLoopEndedCallbackId != 0) {
176
+ context_->audioEventHandlerRegistry_->invokeHandlerWithEventBody(
177
+ "loopEnded", onLoopEndedCallbackId_, {});
178
+ }
179
+ }
180
+
154
181
  /**
155
182
  * Helper functions
156
183
  */
157
184
 
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
185
  void AudioBufferSourceNode::processWithoutInterpolation(
184
186
  const std::shared_ptr<AudioBus> &processingBus,
185
187
  size_t startOffset,
@@ -243,6 +245,8 @@ void AudioBufferSourceNode::processWithoutInterpolation(
243
245
  playbackState_ = PlaybackState::STOP_SCHEDULED;
244
246
  break;
245
247
  }
248
+
249
+ sendOnLoopEndedEvent();
246
250
  }
247
251
  }
248
252
 
@@ -304,23 +308,12 @@ void AudioBufferSourceNode::processWithInterpolation(
304
308
  playbackState_ = PlaybackState::STOP_SCHEDULED;
305
309
  break;
306
310
  }
311
+
312
+ sendOnLoopEndedEvent();
307
313
  }
308
314
  }
309
315
  }
310
316
 
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
-
324
317
  double AudioBufferSourceNode::getVirtualStartFrame() {
325
318
  auto loopStartFrame = loopStart_ * context_->getSampleRate();
326
319
 
@@ -34,8 +34,11 @@ 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
+
37
40
  protected:
38
- void processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override;
41
+ std::shared_ptr<AudioBus> processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override;
39
42
  double getCurrentPosition() const override;
40
43
 
41
44
  private:
@@ -45,15 +48,12 @@ class AudioBufferSourceNode : public AudioBufferBaseSourceNode {
45
48
  double loopStart_;
46
49
  double loopEnd_;
47
50
 
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
- void processWithoutPitchCorrection(const std::shared_ptr<AudioBus> &processingBus,
56
- int framesToProcess);
55
+ std::atomic<uint64_t> onLoopEndedCallbackId_ = 0; // 0 means no callback
56
+ void sendOnLoopEndedEvent();
57
57
 
58
58
  void processWithoutInterpolation(
59
59
  const std::shared_ptr<AudioBus>& processingBus,
@@ -65,9 +65,7 @@ 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);
69
-
70
- float getComputedPlaybackRateValue(int framesToProcess);
68
+ float playbackRate) override;
71
69
 
72
70
  double getVirtualStartFrame();
73
71
  double getVirtualEndFrame();
@@ -17,12 +17,7 @@ AudioScheduledSourceNode::AudioScheduledSourceNode(BaseAudioContext *context)
17
17
  }
18
18
 
19
19
  AudioScheduledSourceNode::~AudioScheduledSourceNode() {
20
- if (onEndedCallbackId_ != 0 &&
21
- context_->audioEventHandlerRegistry_ != nullptr) {
22
- context_->audioEventHandlerRegistry_->unregisterHandler(
23
- "ended", onEndedCallbackId_);
24
- onEndedCallbackId_ = 0;
25
- }
20
+ clearOnEndedCallback();
26
21
  }
27
22
 
28
23
  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
- virtual ~AudioScheduledSourceNode();
30
+ ~AudioScheduledSourceNode() override;
31
31
 
32
32
  void start(double when);
33
33
  virtual void stop(double when);
@@ -0,0 +1,53 @@
1
+ #include <audioapi/core/BaseAudioContext.h>
2
+ #include <audioapi/core/sources/ConstantSourceNode.h>
3
+ #include <audioapi/dsp/AudioUtils.h>
4
+ #include <audioapi/utils/AudioArray.h>
5
+ #include <audioapi/utils/AudioBus.h>
6
+
7
+ namespace audioapi {
8
+ ConstantSourceNode::ConstantSourceNode(BaseAudioContext *context)
9
+ : AudioScheduledSourceNode(context) {
10
+ offsetParam_ = std::make_shared<AudioParam>(
11
+ 1.0, MOST_NEGATIVE_SINGLE_FLOAT, MOST_POSITIVE_SINGLE_FLOAT, context);
12
+ isInitialized_ = true;
13
+ }
14
+
15
+ std::shared_ptr<AudioParam> ConstantSourceNode::getOffsetParam() const {
16
+ return offsetParam_;
17
+ }
18
+
19
+ std::shared_ptr<AudioBus> ConstantSourceNode::processNode(
20
+ const std::shared_ptr<AudioBus> &processingBus,
21
+ int framesToProcess) {
22
+ size_t startOffset = 0;
23
+ size_t offsetLength = 0;
24
+
25
+ updatePlaybackInfo(processingBus, framesToProcess, startOffset, offsetLength);
26
+
27
+ if (!isPlaying() && !isStopScheduled()) {
28
+ processingBus->zero();
29
+ return processingBus;
30
+ }
31
+
32
+ auto offsetBus = offsetParam_->processARateParam(
33
+ framesToProcess, context_->getCurrentTime());
34
+
35
+ auto offsetChannelData = offsetBus->getChannel(0)->getData();
36
+
37
+ for (int channel = 0; channel < processingBus->getNumberOfChannels();
38
+ ++channel) {
39
+ auto outputChannelData = processingBus->getChannel(channel)->getData();
40
+
41
+ std::copy(
42
+ offsetChannelData + startOffset,
43
+ offsetChannelData + startOffset + offsetLength,
44
+ outputChannelData + startOffset);
45
+ }
46
+
47
+ if (isStopScheduled()) {
48
+ handleStopScheduled();
49
+ }
50
+
51
+ return processingBus;
52
+ }
53
+ } // namespace audioapi
@@ -0,0 +1,26 @@
1
+ #pragma once
2
+
3
+ #include <audioapi/core/AudioParam.h>
4
+ #include <audioapi/core/sources/AudioScheduledSourceNode.h>
5
+
6
+ #include <cmath>
7
+ #include <memory>
8
+ #include <string>
9
+
10
+ namespace audioapi {
11
+
12
+ class AudioBus;
13
+
14
+ class ConstantSourceNode : public AudioScheduledSourceNode {
15
+ public:
16
+ explicit ConstantSourceNode(BaseAudioContext *context);
17
+
18
+ [[nodiscard]] std::shared_ptr<AudioParam> getOffsetParam() const;
19
+
20
+ protected:
21
+ std::shared_ptr<AudioBus> processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override;
22
+
23
+ private:
24
+ std::shared_ptr<AudioParam> offsetParam_;
25
+ };
26
+ } // namespace audioapi
@@ -21,6 +21,9 @@ OscillatorNode::OscillatorNode(BaseAudioContext *context)
21
21
  type_ = OscillatorType::SINE;
22
22
  periodicWave_ = context_->getBasicWaveForm(type_);
23
23
 
24
+ audioBus_ = std::make_shared<AudioBus>(
25
+ RENDER_QUANTUM_SIZE, 1, context_->getSampleRate());
26
+
24
27
  isInitialized_ = true;
25
28
  }
26
29
 
@@ -47,7 +50,7 @@ void OscillatorNode::setPeriodicWave(
47
50
  type_ = OscillatorType::CUSTOM;
48
51
  }
49
52
 
50
- void OscillatorNode::processNode(
53
+ std::shared_ptr<AudioBus> OscillatorNode::processNode(
51
54
  const std::shared_ptr<AudioBus> &processingBus,
52
55
  int framesToProcess) {
53
56
  size_t startOffset = 0;
@@ -57,7 +60,7 @@ void OscillatorNode::processNode(
57
60
 
58
61
  if (!isPlaying() && !isStopScheduled()) {
59
62
  processingBus->zero();
60
- return;
63
+ return processingBus;
61
64
  }
62
65
 
63
66
  auto time = context_->getCurrentTime() +
@@ -89,6 +92,8 @@ void OscillatorNode::processNode(
89
92
  }
90
93
 
91
94
  handleStopScheduled();
95
+
96
+ return processingBus;
92
97
  }
93
98
 
94
99
  } // namespace audioapi
@@ -24,7 +24,7 @@ class OscillatorNode : public AudioScheduledSourceNode {
24
24
  void setPeriodicWave(const std::shared_ptr<PeriodicWave> &periodicWave);
25
25
 
26
26
  protected:
27
- void processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override;
27
+ std::shared_ptr<AudioBus> processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override;
28
28
 
29
29
  private:
30
30
  std::shared_ptr<AudioParam> frequencyParam_;
@@ -23,7 +23,7 @@ void RecorderAdapterNode::init(size_t bufferSize) {
23
23
  buff_ = std::make_shared<CircularOverflowableAudioArray>(bufferSize);
24
24
  }
25
25
 
26
- void RecorderAdapterNode::processNode(
26
+ std::shared_ptr<AudioBus> RecorderAdapterNode::processNode(
27
27
  const std::shared_ptr<AudioBus> &processingBus,
28
28
  int framesToProcess) {
29
29
  float *outputChannel = processingBus->getChannel(0)->getData();
@@ -33,6 +33,8 @@ void RecorderAdapterNode::processNode(
33
33
  processingBus->getChannel(i)->copy(
34
34
  processingBus->getChannel(0), 0, framesToProcess);
35
35
  }
36
+
37
+ return processingBus;
36
38
  }
37
39
 
38
40
  void RecorderAdapterNode::readFrames(float *output, const size_t framesToRead) {
@@ -27,7 +27,7 @@ class RecorderAdapterNode : public AudioNode {
27
27
  void init(size_t bufferSize);
28
28
 
29
29
  protected:
30
- void processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override;
30
+ std::shared_ptr<AudioBus> processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override;
31
31
  std::shared_ptr<CircularOverflowableAudioArray> buff_;
32
32
 
33
33
  private:
@@ -147,12 +147,18 @@ void StreamerNode::streamAudio() {
147
147
  }
148
148
  }
149
149
 
150
- void StreamerNode::processNode(
150
+ std::shared_ptr<AudioBus> StreamerNode::processNode(
151
151
  const std::shared_ptr<AudioBus> &processingBus,
152
152
  int framesToProcess) {
153
153
  size_t startOffset = 0;
154
154
  size_t offsetLength = 0;
155
155
  updatePlaybackInfo(processingBus, framesToProcess, startOffset, offsetLength);
156
+
157
+ if (!isPlaying() && !isStopScheduled()) {
158
+ processingBus->zero();
159
+ return processingBus;
160
+ }
161
+
156
162
  // If we have enough buffered data, copy to output bus
157
163
  if (bufferedBusIndex_ >= framesToProcess) {
158
164
  Locker locker(mutex_);
@@ -169,6 +175,8 @@ void StreamerNode::processNode(
169
175
  }
170
176
  bufferedBusIndex_ -= offsetLength;
171
177
  }
178
+
179
+ return processingBus;
172
180
  }
173
181
 
174
182
  bool StreamerNode::processFrameWithResampler(AVFrame *frame) {
@@ -43,16 +43,8 @@ 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
-
54
46
  protected:
55
- void processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override;
47
+ std::shared_ptr<AudioBus> processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override;
56
48
 
57
49
  private:
58
50
  #ifndef AUDIO_API_TEST_SUITE