react-native-audio-api 0.10.0-nightly-c815c40-20251026 → 0.11.0-alpha.0

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 (213) hide show
  1. package/RNAudioAPI.podspec +5 -9
  2. package/android/build.gradle +3 -33
  3. package/android/src/main/cpp/audioapi/android/AudioAPIModule.cpp +0 -5
  4. package/android/src/main/cpp/audioapi/android/AudioAPIModule.h +0 -1
  5. package/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.cpp +94 -28
  6. package/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.h +28 -14
  7. package/android/src/main/cpp/audioapi/android/core/AudioPlayer.cpp +2 -4
  8. package/android/src/main/cpp/audioapi/android/core/NativeAudioRecorder.hpp +9 -9
  9. package/android/src/main/cpp/audioapi/android/core/utils/AndroidFileWriterBackend.h +33 -0
  10. package/android/src/main/cpp/audioapi/android/core/utils/AudioDecoder.cpp +0 -6
  11. package/android/src/main/cpp/audioapi/android/core/utils/FileUtils.h +34 -0
  12. package/android/src/main/cpp/audioapi/android/core/utils/FileUtilts.cpp +133 -0
  13. package/android/src/main/cpp/audioapi/android/core/utils/MiniaudioImplementation.cpp +3 -0
  14. package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/FFmpegAudioFileOptions.cpp +154 -0
  15. package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/FFmpegAudioFileOptions.h +41 -0
  16. package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/FFmpegFileWriter.cpp +431 -0
  17. package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/FFmpegFileWriter.h +112 -0
  18. package/android/src/main/cpp/audioapi/android/core/utils/miniaudioBackend/MiniAudioFileOptions.cpp +47 -0
  19. package/android/src/main/cpp/audioapi/android/core/utils/miniaudioBackend/MiniAudioFileOptions.h +28 -0
  20. package/android/src/main/cpp/audioapi/android/core/utils/miniaudioBackend/MiniAudioFileWriter.cpp +237 -0
  21. package/android/src/main/cpp/audioapi/android/core/utils/miniaudioBackend/MiniAudioFileWriter.h +46 -0
  22. package/android/src/main/cpp/audioapi/android/system/NativeFileInfo.hpp +31 -0
  23. package/android/src/main/java/com/swmansion/audioapi/AudioAPIModule.kt +3 -29
  24. package/android/src/main/java/com/swmansion/audioapi/system/AudioFocusListener.kt +9 -21
  25. package/android/src/main/java/com/swmansion/audioapi/system/NativeFileInfo.kt +18 -0
  26. package/android/src/main/jniLibs/arm64-v8a/libavcodec.so +0 -0
  27. package/android/src/main/jniLibs/arm64-v8a/libavformat.so +0 -0
  28. package/android/src/main/jniLibs/arm64-v8a/libavutil.so +0 -0
  29. package/android/src/main/jniLibs/arm64-v8a/libswresample.so +0 -0
  30. package/android/src/main/jniLibs/armeabi-v7a/libavcodec.so +0 -0
  31. package/android/src/main/jniLibs/armeabi-v7a/libavformat.so +0 -0
  32. package/android/src/main/jniLibs/armeabi-v7a/libavutil.so +0 -0
  33. package/android/src/main/jniLibs/armeabi-v7a/libswresample.so +0 -0
  34. package/android/src/main/jniLibs/x86/libavcodec.so +0 -0
  35. package/android/src/main/jniLibs/x86/libavformat.so +0 -0
  36. package/android/src/main/jniLibs/x86/libavutil.so +0 -0
  37. package/android/src/main/jniLibs/x86/libswresample.so +0 -0
  38. package/android/src/main/jniLibs/x86_64/libavcodec.so +0 -0
  39. package/android/src/main/jniLibs/x86_64/libavformat.so +0 -0
  40. package/android/src/main/jniLibs/x86_64/libavutil.so +0 -0
  41. package/android/src/main/jniLibs/x86_64/libswresample.so +0 -0
  42. package/common/cpp/audioapi/AudioAPIModuleInstaller.h +2 -30
  43. package/common/cpp/audioapi/HostObjects/effects/BiquadFilterNodeHostObject.cpp +1 -1
  44. package/common/cpp/audioapi/HostObjects/inputs/AudioRecorderHostObject.cpp +80 -18
  45. package/common/cpp/audioapi/HostObjects/inputs/AudioRecorderHostObject.h +15 -6
  46. package/common/cpp/audioapi/core/AudioParam.cpp +2 -2
  47. package/common/cpp/audioapi/core/effects/BiquadFilterNode.cpp +32 -69
  48. package/common/cpp/audioapi/core/effects/BiquadFilterNode.h +1 -37
  49. package/common/cpp/audioapi/core/inputs/AudioRecorder.cpp +102 -49
  50. package/common/cpp/audioapi/core/inputs/AudioRecorder.h +46 -28
  51. package/common/cpp/audioapi/core/utils/Constants.h +1 -2
  52. package/common/cpp/audioapi/core/utils/worklets/SafeIncludes.h +10 -0
  53. package/common/cpp/audioapi/external/arm64-v8a/libcrypto.a +0 -0
  54. package/common/cpp/audioapi/external/arm64-v8a/libogg.a +0 -0
  55. package/common/cpp/audioapi/external/arm64-v8a/libopus.a +0 -0
  56. package/common/cpp/audioapi/external/arm64-v8a/libopusfile.a +0 -0
  57. package/common/cpp/audioapi/external/arm64-v8a/libssl.a +0 -0
  58. package/common/cpp/audioapi/external/arm64-v8a/libvorbis.a +0 -0
  59. package/common/cpp/audioapi/external/arm64-v8a/libvorbisenc.a +0 -0
  60. package/common/cpp/audioapi/external/arm64-v8a/libvorbisfile.a +0 -0
  61. package/common/cpp/audioapi/external/armeabi-v7a/libcrypto.a +0 -0
  62. package/common/cpp/audioapi/external/armeabi-v7a/libogg.a +0 -0
  63. package/common/cpp/audioapi/external/armeabi-v7a/libopus.a +0 -0
  64. package/common/cpp/audioapi/external/armeabi-v7a/libopusfile.a +0 -0
  65. package/common/cpp/audioapi/external/armeabi-v7a/libssl.a +0 -0
  66. package/common/cpp/audioapi/external/armeabi-v7a/libvorbis.a +0 -0
  67. package/common/cpp/audioapi/external/armeabi-v7a/libvorbisenc.a +0 -0
  68. package/common/cpp/audioapi/external/armeabi-v7a/libvorbisfile.a +0 -0
  69. package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/avcodec.h +2 -2
  70. package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/codec.h +1 -1
  71. package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/codec_desc.h +1 -1
  72. package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/codec_id.h +1 -1
  73. package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/codec_par.h +1 -1
  74. package/common/cpp/audioapi/external/ffmpeg_include/libavformat/avformat.h +2 -2
  75. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/avutil.h +2 -2
  76. package/common/cpp/audioapi/external/iphoneos/libcrypto.a +0 -0
  77. package/common/cpp/audioapi/external/iphoneos/libogg.a +0 -0
  78. package/common/cpp/audioapi/external/iphoneos/libopus.a +0 -0
  79. package/common/cpp/audioapi/external/iphoneos/libopusfile.a +0 -0
  80. package/common/cpp/audioapi/external/iphoneos/libssl.a +0 -0
  81. package/common/cpp/audioapi/external/iphoneos/libvorbis.a +0 -0
  82. package/common/cpp/audioapi/external/iphoneos/libvorbisenc.a +0 -0
  83. package/common/cpp/audioapi/external/iphoneos/libvorbisfile.a +0 -0
  84. package/common/cpp/audioapi/external/iphonesimulator/libcrypto.a +0 -0
  85. package/common/cpp/audioapi/external/iphonesimulator/libogg.a +0 -0
  86. package/common/cpp/audioapi/external/iphonesimulator/libopus.a +0 -0
  87. package/common/cpp/audioapi/external/iphonesimulator/libopusfile.a +0 -0
  88. package/common/cpp/audioapi/external/iphonesimulator/libssl.a +0 -0
  89. package/common/cpp/audioapi/external/iphonesimulator/libvorbis.a +0 -0
  90. package/common/cpp/audioapi/external/iphonesimulator/libvorbisenc.a +0 -0
  91. package/common/cpp/audioapi/external/iphonesimulator/libvorbisfile.a +0 -0
  92. package/common/cpp/audioapi/external/libavcodec.xcframework/Info.plist +44 -0
  93. package/common/cpp/audioapi/external/libavcodec.xcframework/ios-arm64/libavcodec.framework/Info.plist +1 -0
  94. package/common/cpp/audioapi/external/libavcodec.xcframework/ios-arm64/libavcodec.framework/libavcodec +0 -0
  95. package/common/cpp/audioapi/external/libavcodec.xcframework/ios-arm64_x86_64-simulator/libavcodec.framework/Info.plist +1 -0
  96. package/common/cpp/audioapi/external/libavcodec.xcframework/ios-arm64_x86_64-simulator/libavcodec.framework/libavcodec +0 -0
  97. package/common/cpp/audioapi/external/libavformat.xcframework/Info.plist +44 -0
  98. package/common/cpp/audioapi/external/libavformat.xcframework/ios-arm64/libavformat.framework/Info.plist +1 -0
  99. package/common/cpp/audioapi/external/libavformat.xcframework/ios-arm64/libavformat.framework/libavformat +0 -0
  100. package/common/cpp/audioapi/external/libavformat.xcframework/ios-arm64_x86_64-simulator/libavformat.framework/Info.plist +1 -0
  101. package/common/cpp/audioapi/external/libavformat.xcframework/ios-arm64_x86_64-simulator/libavformat.framework/libavformat +0 -0
  102. package/common/cpp/audioapi/external/libavutil.xcframework/Info.plist +44 -0
  103. package/common/cpp/audioapi/external/libavutil.xcframework/ios-arm64/libavutil.framework/Info.plist +1 -0
  104. package/common/cpp/audioapi/external/libavutil.xcframework/ios-arm64/libavutil.framework/libavutil +0 -0
  105. package/common/cpp/audioapi/external/libavutil.xcframework/ios-arm64_x86_64-simulator/libavutil.framework/Info.plist +1 -0
  106. package/common/cpp/audioapi/external/libavutil.xcframework/ios-arm64_x86_64-simulator/libavutil.framework/libavutil +0 -0
  107. package/common/cpp/audioapi/external/libswresample.xcframework/Info.plist +44 -0
  108. package/common/cpp/audioapi/external/libswresample.xcframework/ios-arm64/libswresample.framework/Info.plist +1 -0
  109. package/common/cpp/audioapi/external/libswresample.xcframework/ios-arm64/libswresample.framework/libswresample +0 -0
  110. package/common/cpp/audioapi/external/libswresample.xcframework/ios-arm64_x86_64-simulator/libswresample.framework/Info.plist +1 -0
  111. package/common/cpp/audioapi/external/libswresample.xcframework/ios-arm64_x86_64-simulator/libswresample.framework/libswresample +0 -0
  112. package/common/cpp/audioapi/external/x86/libcrypto.a +0 -0
  113. package/common/cpp/audioapi/external/x86/libogg.a +0 -0
  114. package/common/cpp/audioapi/external/x86/libopus.a +0 -0
  115. package/common/cpp/audioapi/external/x86/libopusfile.a +0 -0
  116. package/common/cpp/audioapi/external/x86/libssl.a +0 -0
  117. package/common/cpp/audioapi/external/x86/libvorbis.a +0 -0
  118. package/common/cpp/audioapi/external/x86/libvorbisenc.a +0 -0
  119. package/common/cpp/audioapi/external/x86/libvorbisfile.a +0 -0
  120. package/common/cpp/audioapi/external/x86_64/libcrypto.a +0 -0
  121. package/common/cpp/audioapi/external/x86_64/libogg.a +0 -0
  122. package/common/cpp/audioapi/external/x86_64/libopus.a +0 -0
  123. package/common/cpp/audioapi/external/x86_64/libopusfile.a +0 -0
  124. package/common/cpp/audioapi/external/x86_64/libssl.a +0 -0
  125. package/common/cpp/audioapi/external/x86_64/libvorbis.a +0 -0
  126. package/common/cpp/audioapi/external/x86_64/libvorbisenc.a +0 -0
  127. package/common/cpp/audioapi/external/x86_64/libvorbisfile.a +0 -0
  128. package/common/cpp/audioapi/libs/ffmpeg/FFmpegDecoding.cpp +3 -2
  129. package/common/cpp/audioapi/libs/ffmpeg/INSTRUCTIONS.md +32 -0
  130. package/common/cpp/audioapi/libs/ffmpeg/create_xcframework.sh +111 -0
  131. package/common/cpp/audioapi/libs/ffmpeg/ffmpeg_setup.sh +391 -0
  132. package/common/cpp/test/CMakeLists.txt +0 -3
  133. package/ios/audioapi/ios/AudioAPIModule.h +1 -2
  134. package/ios/audioapi/ios/AudioAPIModule.mm +0 -2
  135. package/ios/audioapi/ios/core/IOSAudioFileOptions.h +35 -0
  136. package/ios/audioapi/ios/core/IOSAudioFileOptions.mm +135 -0
  137. package/ios/audioapi/ios/core/IOSAudioFileWriter.h +38 -0
  138. package/ios/audioapi/ios/core/IOSAudioFileWriter.mm +187 -0
  139. package/ios/audioapi/ios/core/IOSAudioRecorder.h +18 -10
  140. package/ios/audioapi/ios/core/IOSAudioRecorder.mm +70 -28
  141. package/ios/audioapi/ios/core/NativeAudioRecorder.h +2 -6
  142. package/ios/audioapi/ios/core/NativeAudioRecorder.m +5 -73
  143. package/ios/audioapi/ios/system/AudioEngine.mm +3 -3
  144. package/ios/audioapi/ios/system/AudioSessionManager.mm +0 -9
  145. package/ios/audioapi/ios/system/LockScreenManager.h +1 -0
  146. package/ios/audioapi/ios/system/LockScreenManager.mm +19 -6
  147. package/lib/commonjs/api.js +76 -134
  148. package/lib/commonjs/api.js.map +1 -1
  149. package/lib/commonjs/core/AudioContext.js +1 -1
  150. package/lib/commonjs/core/AudioContext.js.map +1 -1
  151. package/lib/commonjs/core/AudioRecorder.js +157 -12
  152. package/lib/commonjs/core/AudioRecorder.js.map +1 -1
  153. package/lib/commonjs/core/BaseAudioContext.js +25 -16
  154. package/lib/commonjs/core/BaseAudioContext.js.map +1 -1
  155. package/lib/commonjs/core/OfflineAudioContext.js +1 -1
  156. package/lib/commonjs/core/OfflineAudioContext.js.map +1 -1
  157. package/lib/commonjs/types.js +50 -0
  158. package/lib/commonjs/types.js.map +1 -1
  159. package/lib/commonjs/utils/bitEnums.js +33 -0
  160. package/lib/commonjs/utils/bitEnums.js.map +1 -0
  161. package/lib/commonjs/utils/index.js +21 -19
  162. package/lib/commonjs/utils/index.js.map +1 -1
  163. package/lib/module/api.js +15 -15
  164. package/lib/module/api.js.map +1 -1
  165. package/lib/module/core/AudioContext.js +2 -2
  166. package/lib/module/core/AudioContext.js.map +1 -1
  167. package/lib/module/core/AudioRecorder.js +157 -12
  168. package/lib/module/core/AudioRecorder.js.map +1 -1
  169. package/lib/module/core/BaseAudioContext.js +26 -17
  170. package/lib/module/core/BaseAudioContext.js.map +1 -1
  171. package/lib/module/core/OfflineAudioContext.js +2 -2
  172. package/lib/module/core/OfflineAudioContext.js.map +1 -1
  173. package/lib/module/types.js +46 -0
  174. package/lib/module/types.js.map +1 -1
  175. package/lib/module/utils/bitEnums.js +27 -0
  176. package/lib/module/utils/bitEnums.js.map +1 -0
  177. package/lib/module/utils/index.js +2 -15
  178. package/lib/module/utils/index.js.map +1 -1
  179. package/lib/typescript/api.d.ts +17 -18
  180. package/lib/typescript/api.d.ts.map +1 -1
  181. package/lib/typescript/core/AudioContext.d.ts.map +1 -1
  182. package/lib/typescript/core/AudioRecorder.d.ts +58 -6
  183. package/lib/typescript/core/AudioRecorder.d.ts.map +1 -1
  184. package/lib/typescript/core/BaseAudioContext.d.ts.map +1 -1
  185. package/lib/typescript/events/types.d.ts +16 -0
  186. package/lib/typescript/events/types.d.ts.map +1 -1
  187. package/lib/typescript/interfaces.d.ts +39 -3
  188. package/lib/typescript/interfaces.d.ts.map +1 -1
  189. package/lib/typescript/types.d.ts +75 -4
  190. package/lib/typescript/types.d.ts.map +1 -1
  191. package/lib/typescript/utils/bitEnums.d.ts +4 -0
  192. package/lib/typescript/utils/bitEnums.d.ts.map +1 -0
  193. package/lib/typescript/utils/index.d.ts +2 -5
  194. package/lib/typescript/utils/index.d.ts.map +1 -1
  195. package/package.json +4 -7
  196. package/src/api.ts +18 -44
  197. package/src/core/AudioContext.ts +2 -3
  198. package/src/core/AudioRecorder.ts +190 -20
  199. package/src/core/BaseAudioContext.ts +60 -44
  200. package/src/core/OfflineAudioContext.ts +2 -2
  201. package/src/events/types.ts +18 -0
  202. package/src/interfaces.ts +47 -4
  203. package/src/types.ts +86 -4
  204. package/src/utils/bitEnums.ts +51 -0
  205. package/src/utils/index.ts +2 -22
  206. package/common/cpp/audioapi/libs/ffmpeg/relinking.md +0 -24
  207. package/common/cpp/test/src/biquad/BiquadFilterChromium.cpp +0 -389
  208. package/common/cpp/test/src/biquad/BiquadFilterChromium.h +0 -64
  209. package/common/cpp/test/src/biquad/BiquadFilterTest.cpp +0 -284
  210. package/common/cpp/test/src/biquad/BiquadFilterTest.h +0 -40
  211. package/scripts/download-prebuilt-binaries.sh +0 -52
  212. package/scripts/rnaa_utils.rb +0 -8
  213. package/scripts/validate-worklets-version.js +0 -28
@@ -5,78 +5,131 @@
5
5
  #include <audioapi/events/AudioEventHandlerRegistry.h>
6
6
  #include <audioapi/utils/AudioBus.h>
7
7
  #include <audioapi/utils/CircularAudioArray.h>
8
- #include <audioapi/utils/CircularOverflowableAudioArray.h>
9
8
 
10
9
  namespace audioapi {
11
10
 
12
11
  AudioRecorder::AudioRecorder(
13
- float sampleRate,
14
- int bufferLength,
15
12
  const std::shared_ptr<AudioEventHandlerRegistry> &audioEventHandlerRegistry)
16
- : sampleRate_(sampleRate),
17
- bufferLength_(bufferLength),
18
- audioEventHandlerRegistry_(audioEventHandlerRegistry) {
19
- constexpr int minRingBufferSize = 8192;
20
- ringBufferSize_ = std::max(2 * bufferLength, minRingBufferSize);
21
- circularBuffer_ = std::make_shared<CircularAudioArray>(ringBufferSize_);
13
+ : audioEventHandlerRegistry_(audioEventHandlerRegistry) {
22
14
  isRunning_.store(false);
15
+ fileOutputEnabled_.store(false);
16
+ callbackOutputEnabled_.store(false);
17
+ isConnected_.store(false);
18
+ }
19
+
20
+ bool AudioRecorder::isRecording() {
21
+ return isRunning_.load();
22
+ }
23
+
24
+ void AudioRecorder::connect(const std::shared_ptr<RecorderAdapterNode> &node) {
25
+ // node->init();
26
+ // adapterNodeLock_.lock();
27
+ // adapterNode_ = node;
28
+ // adapterNodeLock_.unlock();
29
+ // isConnected_.store(true);
30
+ // node->init(ringBufferSize_);
31
+ // adapterNodeLock_.lock();
32
+ // adapterNode_ = node;
33
+ // adapterNodeLock_.unlock();
23
34
  }
24
35
 
25
- void AudioRecorder::setOnAudioReadyCallbackId(uint64_t callbackId) {
26
- onAudioReadyCallbackId_ = callbackId;
36
+ void AudioRecorder::disconnect() {
37
+ // adapterNodeLock_.lock();
38
+ // adapterNode_ = nullptr;
39
+ // adapterNodeLock_.unlock();
40
+ // isConnected_.store(false);
41
+ }
42
+
43
+ void AudioRecorder::setOnAudioReadyCallback(
44
+ float sampleRate,
45
+ size_t bufferLength,
46
+ size_t channelCount,
47
+ uint64_t callbackId) {
48
+ callbackProperties_.sampleRate = sampleRate;
49
+ callbackProperties_.bufferLength = bufferLength;
50
+ callbackProperties_.channelCount = channelCount;
51
+ callbackProperties_.callbackId = callbackId;
52
+
53
+ callbackOutputEnabled_.store(true);
54
+ }
55
+
56
+ void AudioRecorder::clearOnAudioReadyCallback() {
57
+ callbackOutputEnabled_.store(false);
58
+ callbackProperties_ = CallbackProperties{};
27
59
  }
28
60
 
29
61
  void AudioRecorder::invokeOnAudioReadyCallback(
30
62
  const std::shared_ptr<AudioBus> &bus,
31
63
  int numFrames) {
32
- auto audioBuffer = std::make_shared<AudioBuffer>(bus);
33
- auto audioBufferHostObject =
34
- std::make_shared<AudioBufferHostObject>(audioBuffer);
35
-
36
- std::unordered_map<std::string, EventValue> body = {};
37
- body.insert({"buffer", audioBufferHostObject});
38
- body.insert({"numFrames", numFrames});
39
-
40
- if (audioEventHandlerRegistry_ != nullptr) {
41
- audioEventHandlerRegistry_->invokeHandlerWithEventBody(
42
- "audioReady", onAudioReadyCallbackId_, body);
43
- }
64
+ // if (!hasCallback()) {
65
+ // return;
66
+ // }
67
+
68
+ // auto audioBuffer = std::make_shared<AudioBuffer>(bus);
69
+ // auto audioBufferHostObject =
70
+ // std::make_shared<AudioBufferHostObject>(audioBuffer);
71
+
72
+ // std::unordered_map<std::string, EventValue> body = {};
73
+ // body.insert({"buffer", audioBufferHostObject});
74
+ // body.insert({"numFrames", numFrames});
75
+
76
+ // if (audioEventHandlerRegistry_ != nullptr) {
77
+ // audioEventHandlerRegistry_->invokeHandlerWithEventBody(
78
+ // "audioReady", onAudioReadyCallbackId_, body);
79
+ // }
44
80
  }
45
81
 
46
- void AudioRecorder::sendRemainingData() {
47
- auto bus = std::make_shared<AudioBus>(
48
- circularBuffer_->getNumberOfAvailableFrames(), 1, sampleRate_);
49
- auto *outputChannel = bus->getChannel(0)->getData();
50
- auto availableFrames =
51
- static_cast<int>(circularBuffer_->getNumberOfAvailableFrames());
82
+ void AudioRecorder::sendRemainingCallbackData() {
83
+ // if (!hasCallback()) {
84
+ // return;
85
+ // }
86
+
87
+ // auto bus = std::make_shared<AudioBus>(
88
+ // circularBuffer_->getNumberOfAvailableFrames(), 1, sampleRate_);
89
+ // auto *outputChannel = bus->getChannel(0)->getData();
90
+ // auto availableFrames =
91
+ // static_cast<int>(circularBuffer_->getNumberOfAvailableFrames());
52
92
 
53
- circularBuffer_->pop_front(
54
- outputChannel, circularBuffer_->getNumberOfAvailableFrames());
93
+ // circularBuffer_->pop_front(
94
+ // outputChannel, circularBuffer_->getNumberOfAvailableFrames());
55
95
 
56
- invokeOnAudioReadyCallback(bus, availableFrames);
96
+ // invokeOnAudioReadyCallback(bus, availableFrames);
57
97
  }
58
98
 
59
- void AudioRecorder::connect(const std::shared_ptr<RecorderAdapterNode> &node) {
60
- node->init(ringBufferSize_);
61
- adapterNodeLock_.lock();
62
- adapterNode_ = node;
63
- adapterNodeLock_.unlock();
99
+ bool AudioRecorder::usesCallback() const {
100
+ return callbackOutputEnabled_.load();
64
101
  }
65
102
 
66
- void AudioRecorder::disconnect() {
67
- adapterNodeLock_.lock();
68
- adapterNode_ = nullptr;
69
- adapterNodeLock_.unlock();
103
+ bool AudioRecorder::usesFileOutput() const {
104
+ return fileOutputEnabled_.load();
70
105
  }
71
106
 
72
- void AudioRecorder::writeToBuffers(const float *data, int numFrames) {
73
- if (adapterNodeLock_.try_lock()) {
74
- if (adapterNode_ != nullptr) {
75
- adapterNode_->buff_->write(data, numFrames);
76
- }
77
- adapterNodeLock_.unlock();
78
- }
79
- circularBuffer_->push_back(data, numFrames);
107
+ bool AudioRecorder::isConnected() const {
108
+ return isConnected_.load();
80
109
  }
81
110
 
111
+ // AudioRecorder::AudioRecorder(
112
+ // const std::shared_ptr<AudioEventHandlerRegistry>
113
+ // &audioEventHandlerRegistry)
114
+ // audioEventHandlerRegistry_(audioEventHandlerRegistry) {
115
+ // constexpr int minRingBufferSize = 8192;
116
+ // ringBufferSize_ = std::max(2 * bufferLength, minRingBufferSize);
117
+
118
+ // circularBuffer_ = std::make_shared<CircularAudioArray>(ringBufferSize_);
119
+ // isRunning_.store(false);
120
+ // }
121
+
122
+ // void AudioRecorder::writeToBuffers(const float *data, int numFrames) {
123
+ // if (adapterNodeLock_.try_lock()) {
124
+ // if (adapterNode_ != nullptr) {
125
+ // adapterNode_->buff_->write(data, numFrames);
126
+ // }
127
+ // adapterNodeLock_.unlock();
128
+ // }
129
+
130
+ // if (hasCallback()) {
131
+ // circularBuffer_->push_back(data, numFrames);
132
+ // }
133
+ // }
134
+
82
135
  } // namespace audioapi
@@ -3,53 +3,71 @@
3
3
  #include <memory>
4
4
  #include <atomic>
5
5
  #include <mutex>
6
+ #include <string>
6
7
 
7
8
  namespace audioapi {
8
9
 
9
10
  class RecorderAdapterNode;
10
11
  class AudioBus;
11
12
  class CircularAudioArray;
12
- class CircularOverflowableAudioArray;
13
13
  class AudioEventHandlerRegistry;
14
14
 
15
15
  class AudioRecorder {
16
16
  public:
17
- explicit AudioRecorder(
18
- float sampleRate,
19
- int bufferLength,
20
- const std::shared_ptr<AudioEventHandlerRegistry> &audioEventHandlerRegistry
21
- );
22
-
17
+ explicit AudioRecorder(const std::shared_ptr<AudioEventHandlerRegistry> &audioEventHandlerRegistry);
23
18
  virtual ~AudioRecorder() = default;
24
19
 
25
- void setOnAudioReadyCallbackId(uint64_t callbackId);
26
- void invokeOnAudioReadyCallback(const std::shared_ptr<AudioBus> &bus, int numFrames);
27
- void sendRemainingData();
20
+ virtual void start() = 0;
21
+ virtual std::string stop() = 0;
28
22
 
29
- /// @brief
30
- /// # Connects the recorder to the adapter node.
31
- ///
32
- /// The adapter node will be used to read audio data from the recorder.
33
- /// @note Few frames of audio might not yet be written to the buffer when connecting.
34
- void connect(const std::shared_ptr<RecorderAdapterNode> &node);
23
+ bool isRecording();
24
+
25
+ virtual void enableFileOutput(
26
+ float sampleRate,
27
+ size_t channelCount,
28
+ size_t bitRate,
29
+ size_t iosFlags,
30
+ size_t androidFlags) = 0;
31
+ virtual void disableFileOutput() = 0;
32
+
33
+ virtual void pause() = 0;
34
+ virtual void resume() = 0;
35
35
 
36
- /// @brief
37
- /// # Disconnects the recorder from the adapter node.
38
- ///
39
- /// The adapter node will no longer be used to read audio data from the recorder.
40
- /// @note Last few frames of audio might be written to the buffer after disconnecting.
36
+ void connect(const std::shared_ptr<RecorderAdapterNode> &node);
41
37
  void disconnect();
42
38
 
43
- virtual void start() = 0;
44
- virtual void stop() = 0;
39
+ void setOnAudioReadyCallback(
40
+ float sampleRate,
41
+ size_t bufferLength,
42
+ size_t channelCount,
43
+ uint64_t callbackId);
44
+ void clearOnAudioReadyCallback();
45
+
46
+ void invokeOnAudioReadyCallback(
47
+ const std::shared_ptr<AudioBus> &bus,
48
+ int numFrames);
49
+ void sendRemainingCallbackData();
50
+
51
+ bool usesCallback() const;
52
+ bool usesFileOutput() const;
53
+ bool isConnected() const;
45
54
 
46
55
  protected:
47
- float sampleRate_;
48
- int bufferLength_;
49
- size_t ringBufferSize_;
56
+ struct CallbackProperties {
57
+ float sampleRate;
58
+ size_t bufferLength;
59
+ size_t channelCount;
60
+ uint64_t callbackId;
61
+ };
62
+
63
+ CallbackProperties callbackProperties_;
64
+ // size_t ringBufferSize_;
50
65
 
51
66
  std::atomic<bool> isRunning_;
52
- std::shared_ptr<CircularAudioArray> circularBuffer_;
67
+ std::atomic<bool> fileOutputEnabled_;
68
+ std::atomic<bool> callbackOutputEnabled_;
69
+ std::atomic<bool> isConnected_;
70
+ // std::shared_ptr<CircularAudioArray> circularBuffer_;
53
71
 
54
72
  mutable std::mutex adapterNodeLock_;
55
73
  std::shared_ptr<RecorderAdapterNode> adapterNode_ = nullptr;
@@ -57,7 +75,7 @@ class AudioRecorder {
57
75
  std::shared_ptr<AudioEventHandlerRegistry> audioEventHandlerRegistry_;
58
76
  uint64_t onAudioReadyCallbackId_ = 0;
59
77
 
60
- void writeToBuffers(const float *data, int numFrames);
78
+ // void writeToBuffers(const float *data, int numFrames);
61
79
  };
62
80
 
63
81
  } // namespace audioapi
@@ -1,6 +1,5 @@
1
1
  #pragma once
2
2
 
3
- #include <numbers>
4
3
  #include <cmath>
5
4
  #include <limits>
6
5
 
@@ -20,7 +19,7 @@ static constexpr float MOST_POSITIVE_SINGLE_FLOAT = static_cast<float>(std::nume
20
19
  static constexpr float MOST_NEGATIVE_SINGLE_FLOAT = static_cast<float>(std::numeric_limits<float>::lowest());
21
20
  static float LOG2_MOST_POSITIVE_SINGLE_FLOAT = std::log2(MOST_POSITIVE_SINGLE_FLOAT);
22
21
  static float LOG10_MOST_POSITIVE_SINGLE_FLOAT = std::log10(MOST_POSITIVE_SINGLE_FLOAT);
23
- static constexpr float PI = std::numbers::pi_v<float>;
22
+ static constexpr float PI = static_cast<float>(M_PI);
24
23
 
25
24
  // buffer sizes
26
25
  static constexpr size_t PROMISE_VENDOR_THREAD_POOL_WORKER_COUNT = 4;
@@ -5,6 +5,16 @@
5
5
  #include <string>
6
6
  #include <memory>
7
7
 
8
+ #ifdef __APPLE__
9
+ /// We cannot make any conditional logic inside podspec but it should automatically compile those files
10
+ /// they should be accessible if someone has react-native-worklets in node_modules
11
+ #if __has_include(<worklets/WorkletRuntime/WorkletRuntime.h>)
12
+ #define RN_AUDIO_API_ENABLE_WORKLETS 1
13
+ #else
14
+ #define RN_AUDIO_API_ENABLE_WORKLETS 0
15
+ #endif
16
+ #endif
17
+
8
18
  #ifndef RN_AUDIO_API_TEST
9
19
  #define RN_AUDIO_API_TEST 0
10
20
  #endif
@@ -436,7 +436,7 @@ typedef struct AVCodecContext {
436
436
  const AVClass *av_class;
437
437
  int log_level_offset;
438
438
 
439
- enum AVMediaTypeFFmpeg codec_type; /* see AVMEDIA_TYPE_xxx */
439
+ enum AVMediaTypeFFMPEG codec_type; /* see AVMEDIA_TYPE_xxx */
440
440
  const struct AVCodec *codec;
441
441
  enum AVCodecID codec_id; /* see AV_CODEC_ID_xxx */
442
442
 
@@ -1946,7 +1946,7 @@ typedef struct AVHWAccel {
1946
1946
  *
1947
1947
  * See AVMEDIA_TYPE_xxx
1948
1948
  */
1949
- enum AVMediaTypeFFmpeg type;
1949
+ enum AVMediaTypeFFMPEG type;
1950
1950
 
1951
1951
  /**
1952
1952
  * Codec implemented by the hardware accelerator.
@@ -182,7 +182,7 @@ typedef struct AVCodec {
182
182
  * You should use the NULL_IF_CONFIG_SMALL() macro to define it.
183
183
  */
184
184
  const char *long_name;
185
- enum AVMediaTypeFFmpeg type;
185
+ enum AVMediaTypeFFMPEG type;
186
186
  enum AVCodecID id;
187
187
  /**
188
188
  * Codec capabilities.
@@ -37,7 +37,7 @@
37
37
  */
38
38
  typedef struct AVCodecDescriptor {
39
39
  enum AVCodecID id;
40
- enum AVMediaTypeFFmpeg type;
40
+ enum AVMediaTypeFFMPEG type;
41
41
  /**
42
42
  * Name of the codec described by this descriptor. It is non-empty and
43
43
  * unique for each codec descriptor. It should contain alphanumeric
@@ -627,7 +627,7 @@ enum AVCodecID {
627
627
  /**
628
628
  * Get the type of the given codec.
629
629
  */
630
- enum AVMediaTypeFFmpeg avcodec_get_type(enum AVCodecID codec_id);
630
+ enum AVMediaTypeFFMPEG avcodec_get_type(enum AVCodecID codec_id);
631
631
 
632
632
  /**
633
633
  * Get the name of a codec.
@@ -48,7 +48,7 @@ typedef struct AVCodecParameters {
48
48
  /**
49
49
  * General type of the encoded data.
50
50
  */
51
- enum AVMediaTypeFFmpeg codec_type;
51
+ enum AVMediaTypeFFMPEG codec_type;
52
52
  /**
53
53
  * Specific type of the encoded data (the codec used).
54
54
  */
@@ -2253,7 +2253,7 @@ void av_program_add_stream_index(AVFormatContext *ac, int progid, unsigned int i
2253
2253
  * NULL, then *decoder_ret is guaranteed to be set to a valid AVCodec.
2254
2254
  */
2255
2255
  int av_find_best_stream(AVFormatContext *ic,
2256
- enum AVMediaTypeFFmpeg type,
2256
+ enum AVMediaTypeFFMPEG type,
2257
2257
  int wanted_stream_nb,
2258
2258
  int related_stream,
2259
2259
  const struct AVCodec **decoder_ret,
@@ -2593,7 +2593,7 @@ const AVOutputFormat *av_guess_format(const char *short_name,
2593
2593
  */
2594
2594
  enum AVCodecID av_guess_codec(const AVOutputFormat *fmt, const char *short_name,
2595
2595
  const char *filename, const char *mime_type,
2596
- enum AVMediaTypeFFmpeg type);
2596
+ enum AVMediaTypeFFMPEG type);
2597
2597
 
2598
2598
  /**
2599
2599
  * Get timing information for the data currently output.
@@ -195,7 +195,7 @@ const char *avutil_license(void);
195
195
  * @brief Media Type
196
196
  */
197
197
 
198
- enum AVMediaTypeFFmpeg {
198
+ enum AVMediaTypeFFMPEG {
199
199
  AVMEDIA_TYPE_UNKNOWN = -1, ///< Usually treated as AVMEDIA_TYPE_DATA
200
200
  AVMEDIA_TYPE_VIDEO,
201
201
  AVMEDIA_TYPE_AUDIO,
@@ -209,7 +209,7 @@ enum AVMediaTypeFFmpeg {
209
209
  * Return a string describing the media_type enum, NULL if media_type
210
210
  * is unknown.
211
211
  */
212
- const char *av_get_media_type_string(enum AVMediaTypeFFmpeg media_type);
212
+ const char *av_get_media_type_string(enum AVMediaTypeFFMPEG media_type);
213
213
 
214
214
  /**
215
215
  * @defgroup lavu_const Constants
@@ -0,0 +1,44 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>AvailableLibraries</key>
6
+ <array>
7
+ <dict>
8
+ <key>BinaryPath</key>
9
+ <string>libavcodec.framework/libavcodec</string>
10
+ <key>LibraryIdentifier</key>
11
+ <string>ios-arm64_x86_64-simulator</string>
12
+ <key>LibraryPath</key>
13
+ <string>libavcodec.framework</string>
14
+ <key>SupportedArchitectures</key>
15
+ <array>
16
+ <string>arm64</string>
17
+ <string>x86_64</string>
18
+ </array>
19
+ <key>SupportedPlatform</key>
20
+ <string>ios</string>
21
+ <key>SupportedPlatformVariant</key>
22
+ <string>simulator</string>
23
+ </dict>
24
+ <dict>
25
+ <key>BinaryPath</key>
26
+ <string>libavcodec.framework/libavcodec</string>
27
+ <key>LibraryIdentifier</key>
28
+ <string>ios-arm64</string>
29
+ <key>LibraryPath</key>
30
+ <string>libavcodec.framework</string>
31
+ <key>SupportedArchitectures</key>
32
+ <array>
33
+ <string>arm64</string>
34
+ </array>
35
+ <key>SupportedPlatform</key>
36
+ <string>ios</string>
37
+ </dict>
38
+ </array>
39
+ <key>CFBundlePackageType</key>
40
+ <string>XFWK</string>
41
+ <key>XCFrameworkFormatVersion</key>
42
+ <string>1.0</string>
43
+ </dict>
44
+ </plist>
@@ -0,0 +1 @@
1
+ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>CFBundleDevelopmentRegion</key> <string>en</string> <key>CFBundleExecutable</key> <string>libavcodec</string> <key>CFBundleIdentifier</key> <string>io.qt.ffmpegkit.libavcodec</string> <key>CFBundleInfoDictionaryVersion</key> <string>6.0</string> <key>CFBundleName</key> <string>libavcodec</string> <key>CFBundlePackageType</key> <string>FMWK</string> <key>CFBundleShortVersionString</key> <string>7.0.2</string> <key>CFBundleVersion</key> <string>7.0.2</string> <key>CFBundleSignature</key> <string>????</string> <key>MinimumOSVersion</key> <string>16.0</string> <key>CFBundleSupportedPlatforms</key> <array> <string>iPhoneOS</string> </array> <key>NSPrincipalClass</key> <string></string> </dict> </plist>
@@ -0,0 +1 @@
1
+ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>CFBundleDevelopmentRegion</key> <string>en</string> <key>CFBundleExecutable</key> <string>libavcodec</string> <key>CFBundleIdentifier</key> <string>io.qt.ffmpegkit.libavcodec</string> <key>CFBundleInfoDictionaryVersion</key> <string>6.0</string> <key>CFBundleName</key> <string>libavcodec</string> <key>CFBundlePackageType</key> <string>FMWK</string> <key>CFBundleShortVersionString</key> <string>7.0.2</string> <key>CFBundleVersion</key> <string>7.0.2</string> <key>CFBundleSignature</key> <string>????</string> <key>MinimumOSVersion</key> <string>16.0</string> <key>CFBundleSupportedPlatforms</key> <array> <string>iPhoneOS</string> </array> <key>NSPrincipalClass</key> <string></string> </dict> </plist>
@@ -0,0 +1,44 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>AvailableLibraries</key>
6
+ <array>
7
+ <dict>
8
+ <key>BinaryPath</key>
9
+ <string>libavformat.framework/libavformat</string>
10
+ <key>LibraryIdentifier</key>
11
+ <string>ios-arm64</string>
12
+ <key>LibraryPath</key>
13
+ <string>libavformat.framework</string>
14
+ <key>SupportedArchitectures</key>
15
+ <array>
16
+ <string>arm64</string>
17
+ </array>
18
+ <key>SupportedPlatform</key>
19
+ <string>ios</string>
20
+ </dict>
21
+ <dict>
22
+ <key>BinaryPath</key>
23
+ <string>libavformat.framework/libavformat</string>
24
+ <key>LibraryIdentifier</key>
25
+ <string>ios-arm64_x86_64-simulator</string>
26
+ <key>LibraryPath</key>
27
+ <string>libavformat.framework</string>
28
+ <key>SupportedArchitectures</key>
29
+ <array>
30
+ <string>arm64</string>
31
+ <string>x86_64</string>
32
+ </array>
33
+ <key>SupportedPlatform</key>
34
+ <string>ios</string>
35
+ <key>SupportedPlatformVariant</key>
36
+ <string>simulator</string>
37
+ </dict>
38
+ </array>
39
+ <key>CFBundlePackageType</key>
40
+ <string>XFWK</string>
41
+ <key>XCFrameworkFormatVersion</key>
42
+ <string>1.0</string>
43
+ </dict>
44
+ </plist>
@@ -0,0 +1 @@
1
+ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>CFBundleDevelopmentRegion</key> <string>en</string> <key>CFBundleExecutable</key> <string>libavformat</string> <key>CFBundleIdentifier</key> <string>io.qt.ffmpegkit.libavformat</string> <key>CFBundleInfoDictionaryVersion</key> <string>6.0</string> <key>CFBundleName</key> <string>libavformat</string> <key>CFBundlePackageType</key> <string>FMWK</string> <key>CFBundleShortVersionString</key> <string>7.0.2</string> <key>CFBundleVersion</key> <string>7.0.2</string> <key>CFBundleSignature</key> <string>????</string> <key>MinimumOSVersion</key> <string>16.0</string> <key>CFBundleSupportedPlatforms</key> <array> <string>iPhoneOS</string> </array> <key>NSPrincipalClass</key> <string></string> </dict> </plist>
@@ -0,0 +1 @@
1
+ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>CFBundleDevelopmentRegion</key> <string>en</string> <key>CFBundleExecutable</key> <string>libavformat</string> <key>CFBundleIdentifier</key> <string>io.qt.ffmpegkit.libavformat</string> <key>CFBundleInfoDictionaryVersion</key> <string>6.0</string> <key>CFBundleName</key> <string>libavformat</string> <key>CFBundlePackageType</key> <string>FMWK</string> <key>CFBundleShortVersionString</key> <string>7.0.2</string> <key>CFBundleVersion</key> <string>7.0.2</string> <key>CFBundleSignature</key> <string>????</string> <key>MinimumOSVersion</key> <string>16.0</string> <key>CFBundleSupportedPlatforms</key> <array> <string>iPhoneOS</string> </array> <key>NSPrincipalClass</key> <string></string> </dict> </plist>