react-native-audio-api 0.11.0-nightly-141c86f-20251118 → 0.11.0-nightly-4e6f25c-20251119

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 (167) hide show
  1. package/android/src/main/cpp/audioapi/android/AudioAPIModule.cpp +10 -16
  2. package/android/src/main/cpp/audioapi/android/OnLoad.cpp +1 -2
  3. package/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.cpp +4 -4
  4. package/android/src/main/cpp/audioapi/android/core/AudioPlayer.cpp +11 -20
  5. package/android/src/main/cpp/audioapi/android/core/utils/AudioDecoder.cpp +24 -46
  6. package/common/cpp/audioapi/AudioAPIModuleInstaller.h +48 -78
  7. package/common/cpp/audioapi/HostObjects/AudioContextHostObject.cpp +20 -21
  8. package/common/cpp/audioapi/HostObjects/AudioNodeHostObject.cpp +3 -4
  9. package/common/cpp/audioapi/HostObjects/AudioParamHostObject.cpp +6 -8
  10. package/common/cpp/audioapi/HostObjects/AudioParamHostObject.h +2 -2
  11. package/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.cpp +42 -78
  12. package/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.h +1 -1
  13. package/common/cpp/audioapi/HostObjects/OfflineAudioContextHostObject.cpp +14 -18
  14. package/common/cpp/audioapi/HostObjects/OfflineAudioContextHostObject.h +3 -3
  15. package/common/cpp/audioapi/HostObjects/WorkletNodeHostObject.h +1 -2
  16. package/common/cpp/audioapi/HostObjects/WorkletProcessingNodeHostObject.h +1 -2
  17. package/common/cpp/audioapi/HostObjects/analysis/AnalyserNodeHostObject.cpp +10 -18
  18. package/common/cpp/audioapi/HostObjects/destinations/AudioDestinationNodeHostObject.h +2 -3
  19. package/common/cpp/audioapi/HostObjects/effects/BiquadFilterNodeHostObject.cpp +16 -28
  20. package/common/cpp/audioapi/HostObjects/effects/BiquadFilterNodeHostObject.h +1 -2
  21. package/common/cpp/audioapi/HostObjects/effects/ConvolverNodeHostObject.cpp +4 -6
  22. package/common/cpp/audioapi/HostObjects/effects/GainNodeHostObject.cpp +2 -2
  23. package/common/cpp/audioapi/HostObjects/effects/PeriodicWaveHostObject.h +1 -2
  24. package/common/cpp/audioapi/HostObjects/effects/StereoPannerNodeHostObject.cpp +2 -2
  25. package/common/cpp/audioapi/HostObjects/effects/StereoPannerNodeHostObject.h +1 -2
  26. package/common/cpp/audioapi/HostObjects/events/AudioEventHandlerRegistryHostObject.cpp +6 -12
  27. package/common/cpp/audioapi/HostObjects/events/AudioEventHandlerRegistryHostObject.h +7 -7
  28. package/common/cpp/audioapi/HostObjects/inputs/AudioRecorderHostObject.cpp +8 -10
  29. package/common/cpp/audioapi/HostObjects/inputs/AudioRecorderHostObject.h +1 -1
  30. package/common/cpp/audioapi/HostObjects/sources/AudioBufferBaseSourceNodeHostObject.cpp +13 -27
  31. package/common/cpp/audioapi/HostObjects/sources/AudioBufferBaseSourceNodeHostObject.h +11 -12
  32. package/common/cpp/audioapi/HostObjects/sources/AudioBufferHostObject.cpp +15 -22
  33. package/common/cpp/audioapi/HostObjects/sources/AudioBufferHostObject.h +5 -7
  34. package/common/cpp/audioapi/HostObjects/sources/AudioBufferQueueSourceNodeHostObject.cpp +7 -12
  35. package/common/cpp/audioapi/HostObjects/sources/AudioBufferQueueSourceNodeHostObject.h +8 -9
  36. package/common/cpp/audioapi/HostObjects/sources/AudioBufferSourceNodeHostObject.cpp +16 -30
  37. package/common/cpp/audioapi/HostObjects/sources/AudioBufferSourceNodeHostObject.h +2 -4
  38. package/common/cpp/audioapi/HostObjects/sources/AudioScheduledSourceNodeHostObject.cpp +6 -10
  39. package/common/cpp/audioapi/HostObjects/sources/ConstantSourceNodeHostObject.cpp +2 -2
  40. package/common/cpp/audioapi/HostObjects/sources/ConstantSourceNodeHostObject.h +1 -2
  41. package/common/cpp/audioapi/HostObjects/sources/OscillatorNodeHostObject.cpp +6 -8
  42. package/common/cpp/audioapi/HostObjects/sources/OscillatorNodeHostObject.h +1 -2
  43. package/common/cpp/audioapi/HostObjects/sources/RecorderAdapterNodeHostObject.h +4 -5
  44. package/common/cpp/audioapi/HostObjects/sources/StreamerNodeHostObject.cpp +2 -2
  45. package/common/cpp/audioapi/HostObjects/sources/StreamerNodeHostObject.h +5 -6
  46. package/common/cpp/audioapi/HostObjects/sources/WorkletSourceNodeHostObject.h +1 -2
  47. package/common/cpp/audioapi/HostObjects/utils/AudioDecoderHostObject.cpp +39 -60
  48. package/common/cpp/audioapi/HostObjects/utils/AudioStretcherHostObject.cpp +4 -8
  49. package/common/cpp/audioapi/core/AudioContext.cpp +4 -4
  50. package/common/cpp/audioapi/core/AudioContext.h +5 -2
  51. package/common/cpp/audioapi/core/AudioNode.cpp +13 -19
  52. package/common/cpp/audioapi/core/AudioNode.h +14 -7
  53. package/common/cpp/audioapi/core/AudioParam.cpp +66 -98
  54. package/common/cpp/audioapi/core/AudioParam.h +20 -12
  55. package/common/cpp/audioapi/core/BaseAudioContext.cpp +22 -34
  56. package/common/cpp/audioapi/core/BaseAudioContext.h +19 -15
  57. package/common/cpp/audioapi/core/OfflineAudioContext.cpp +12 -17
  58. package/common/cpp/audioapi/core/OfflineAudioContext.h +10 -5
  59. package/common/cpp/audioapi/core/analysis/AnalyserNode.cpp +13 -21
  60. package/common/cpp/audioapi/core/analysis/AnalyserNode.h +8 -6
  61. package/common/cpp/audioapi/core/destinations/AudioDestinationNode.cpp +1 -0
  62. package/common/cpp/audioapi/core/destinations/AudioDestinationNode.h +5 -3
  63. package/common/cpp/audioapi/core/effects/BiquadFilterNode.cpp +17 -36
  64. package/common/cpp/audioapi/core/effects/BiquadFilterNode.h +2 -9
  65. package/common/cpp/audioapi/core/effects/ConvolverNode.cpp +18 -28
  66. package/common/cpp/audioapi/core/effects/ConvolverNode.h +19 -10
  67. package/common/cpp/audioapi/core/effects/GainNode.cpp +1 -0
  68. package/common/cpp/audioapi/core/effects/GainNode.h +3 -1
  69. package/common/cpp/audioapi/core/effects/PeriodicWave.cpp +22 -35
  70. package/common/cpp/audioapi/core/effects/PeriodicWave.h +4 -9
  71. package/common/cpp/audioapi/core/effects/StereoPannerNode.cpp +4 -5
  72. package/common/cpp/audioapi/core/effects/StereoPannerNode.h +4 -2
  73. package/common/cpp/audioapi/core/effects/WorkletNode.cpp +11 -13
  74. package/common/cpp/audioapi/core/effects/WorkletNode.h +15 -12
  75. package/common/cpp/audioapi/core/effects/WorkletProcessingNode.cpp +4 -4
  76. package/common/cpp/audioapi/core/effects/WorkletProcessingNode.h +15 -14
  77. package/common/cpp/audioapi/core/inputs/AudioRecorder.cpp +9 -8
  78. package/common/cpp/audioapi/core/inputs/AudioRecorder.h +4 -5
  79. package/common/cpp/audioapi/core/sources/AudioBuffer.cpp +4 -6
  80. package/common/cpp/audioapi/core/sources/AudioBuffer.h +4 -7
  81. package/common/cpp/audioapi/core/sources/AudioBufferBaseSourceNode.cpp +31 -53
  82. package/common/cpp/audioapi/core/sources/AudioBufferBaseSourceNode.h +35 -33
  83. package/common/cpp/audioapi/core/sources/AudioBufferQueueSourceNode.cpp +19 -20
  84. package/common/cpp/audioapi/core/sources/AudioBufferQueueSourceNode.h +38 -36
  85. package/common/cpp/audioapi/core/sources/AudioBufferSourceNode.cpp +25 -40
  86. package/common/cpp/audioapi/core/sources/AudioBufferSourceNode.h +3 -1
  87. package/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.cpp +9 -9
  88. package/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.h +3 -3
  89. package/common/cpp/audioapi/core/sources/ConstantSourceNode.cpp +3 -4
  90. package/common/cpp/audioapi/core/sources/ConstantSourceNode.h +3 -1
  91. package/common/cpp/audioapi/core/sources/OscillatorNode.cpp +12 -23
  92. package/common/cpp/audioapi/core/sources/OscillatorNode.h +6 -4
  93. package/common/cpp/audioapi/core/sources/RecorderAdapterNode.cpp +3 -4
  94. package/common/cpp/audioapi/core/sources/RecorderAdapterNode.h +18 -16
  95. package/common/cpp/audioapi/core/sources/StreamerNode.cpp +7 -4
  96. package/common/cpp/audioapi/core/sources/StreamerNode.h +38 -30
  97. package/common/cpp/audioapi/core/sources/WorkletSourceNode.cpp +5 -7
  98. package/common/cpp/audioapi/core/sources/WorkletSourceNode.h +15 -13
  99. package/common/cpp/audioapi/core/types/AudioFormat.h +1 -11
  100. package/common/cpp/audioapi/core/utils/AudioDecoder.h +15 -6
  101. package/common/cpp/audioapi/core/utils/AudioNodeDestructor.cpp +5 -6
  102. package/common/cpp/audioapi/core/utils/AudioNodeDestructor.h +7 -10
  103. package/common/cpp/audioapi/core/utils/AudioNodeManager.cpp +13 -22
  104. package/common/cpp/audioapi/core/utils/AudioNodeManager.h +8 -11
  105. package/common/cpp/audioapi/core/utils/AudioParamEventQueue.cpp +3 -3
  106. package/common/cpp/audioapi/core/utils/AudioParamEventQueue.h +5 -5
  107. package/common/cpp/audioapi/core/utils/AudioStretcher.cpp +6 -6
  108. package/common/cpp/audioapi/core/utils/Constants.h +5 -3
  109. package/common/cpp/audioapi/core/utils/ParamChangeEvent.cpp +1 -0
  110. package/common/cpp/audioapi/core/utils/ParamChangeEvent.h +9 -9
  111. package/common/cpp/audioapi/core/utils/worklets/SafeIncludes.h +29 -34
  112. package/common/cpp/audioapi/core/utils/worklets/WorkletsRunner.cpp +14 -16
  113. package/common/cpp/audioapi/core/utils/worklets/WorkletsRunner.h +23 -19
  114. package/common/cpp/audioapi/dsp/AudioUtils.cpp +3 -9
  115. package/common/cpp/audioapi/dsp/AudioUtils.h +1 -1
  116. package/common/cpp/audioapi/dsp/Convolver.cpp +13 -25
  117. package/common/cpp/audioapi/dsp/Convolver.h +26 -24
  118. package/common/cpp/audioapi/dsp/FFT.cpp +1 -1
  119. package/common/cpp/audioapi/dsp/FFT.h +5 -13
  120. package/common/cpp/audioapi/dsp/VectorMath.cpp +9 -43
  121. package/common/cpp/audioapi/dsp/VectorMath.h +35 -8
  122. package/common/cpp/audioapi/dsp/Windows.cpp +4 -9
  123. package/common/cpp/audioapi/dsp/Windows.h +24 -23
  124. package/common/cpp/audioapi/events/AudioEventHandlerRegistry.cpp +12 -17
  125. package/common/cpp/audioapi/events/AudioEventHandlerRegistry.h +44 -39
  126. package/common/cpp/audioapi/events/IAudioEventHandlerRegistry.h +15 -7
  127. package/common/cpp/audioapi/jsi/AudioArrayBuffer.h +4 -5
  128. package/common/cpp/audioapi/jsi/JsiHostObject.cpp +11 -13
  129. package/common/cpp/audioapi/jsi/JsiHostObject.h +26 -33
  130. package/common/cpp/audioapi/jsi/JsiPromise.cpp +11 -21
  131. package/common/cpp/audioapi/jsi/JsiPromise.h +55 -46
  132. package/common/cpp/audioapi/jsi/RuntimeLifecycleMonitor.cpp +7 -10
  133. package/common/cpp/audioapi/jsi/RuntimeLifecycleMonitor.h +1 -3
  134. package/common/cpp/audioapi/utils/AudioArray.cpp +3 -8
  135. package/common/cpp/audioapi/utils/AudioArray.h +3 -11
  136. package/common/cpp/audioapi/utils/AudioBus.cpp +51 -149
  137. package/common/cpp/audioapi/utils/AudioBus.h +15 -15
  138. package/common/cpp/audioapi/utils/CircularAudioArray.cpp +6 -18
  139. package/common/cpp/audioapi/utils/CircularOverflowableAudioArray.cpp +6 -10
  140. package/common/cpp/audioapi/utils/CircularOverflowableAudioArray.h +2 -2
  141. package/common/cpp/test/src/AudioParamTest.cpp +3 -2
  142. package/common/cpp/test/src/AudioScheduledSourceTest.cpp +14 -35
  143. package/common/cpp/test/src/ConstantSourceTest.cpp +4 -6
  144. package/common/cpp/test/src/GainTest.cpp +3 -4
  145. package/common/cpp/test/src/MockAudioEventHandlerRegistry.h +19 -11
  146. package/common/cpp/test/src/OscillatorTest.cpp +1 -0
  147. package/common/cpp/test/src/StereoPannerTest.cpp +5 -8
  148. package/common/cpp/test/src/biquad/BiquadFilterChromium.cpp +10 -27
  149. package/common/cpp/test/src/biquad/BiquadFilterChromium.h +7 -6
  150. package/common/cpp/test/src/biquad/BiquadFilterTest.cpp +16 -28
  151. package/common/cpp/test/src/biquad/BiquadFilterTest.h +13 -6
  152. package/ios/audioapi/ios/AudioAPIModule.h +4 -6
  153. package/ios/audioapi/ios/AudioAPIModule.mm +31 -46
  154. package/ios/audioapi/ios/core/IOSAudioPlayer.mm +24 -33
  155. package/ios/audioapi/ios/core/IOSAudioRecorder.h +1 -2
  156. package/ios/audioapi/ios/core/IOSAudioRecorder.mm +4 -6
  157. package/ios/audioapi/ios/core/NativeAudioPlayer.m +3 -5
  158. package/ios/audioapi/ios/core/NativeAudioRecorder.h +1 -2
  159. package/ios/audioapi/ios/core/NativeAudioRecorder.m +21 -33
  160. package/ios/audioapi/ios/core/utils/AudioDecoder.mm +17 -37
  161. package/ios/audioapi/ios/system/AudioEngine.h +2 -4
  162. package/ios/audioapi/ios/system/AudioEngine.mm +7 -19
  163. package/ios/audioapi/ios/system/AudioSessionManager.h +2 -4
  164. package/ios/audioapi/ios/system/AudioSessionManager.mm +17 -32
  165. package/ios/audioapi/ios/system/LockScreenManager.mm +73 -105
  166. package/ios/audioapi/ios/system/NotificationManager.mm +43 -68
  167. package/package.json +2 -2
@@ -1,9 +1,9 @@
1
1
  #pragma once
2
2
 
3
- #include <audioapi/core/AudioParam.h>
4
3
  #include <audioapi/core/AudioNode.h>
5
- #include <audioapi/core/inputs/AudioRecorder.h>
4
+ #include <audioapi/core/AudioParam.h>
6
5
  #include <audioapi/core/BaseAudioContext.h>
6
+ #include <audioapi/core/inputs/AudioRecorder.h>
7
7
  #include <audioapi/utils/CircularOverflowableAudioArray.h>
8
8
  #include <memory>
9
9
 
@@ -18,26 +18,28 @@ class AudioBus;
18
18
  /// @note it will push silence if it is not connected to any Recorder
19
19
  class RecorderAdapterNode : public AudioNode {
20
20
  public:
21
- explicit RecorderAdapterNode(BaseAudioContext *context);
21
+ explicit RecorderAdapterNode(BaseAudioContext *context);
22
22
 
23
- /// @brief Initialize the RecorderAdapterNode with a buffer size.
24
- /// @note This method should be called ONLY ONCE when the buffer size is known.
25
- /// @throws std::runtime_error if the node is already initialized.
26
- /// @param bufferSize The size of the buffer to be used.
27
- void init(size_t bufferSize);
23
+ /// @brief Initialize the RecorderAdapterNode with a buffer size.
24
+ /// @note This method should be called ONLY ONCE when the buffer size is known.
25
+ /// @throws std::runtime_error if the node is already initialized.
26
+ /// @param bufferSize The size of the buffer to be used.
27
+ void init(size_t bufferSize);
28
28
 
29
29
  protected:
30
- std::shared_ptr<AudioBus> processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override;
31
- std::shared_ptr<CircularOverflowableAudioArray> buff_;
30
+ std::shared_ptr<AudioBus> processNode(
31
+ const std::shared_ptr<AudioBus> &processingBus,
32
+ int framesToProcess) override;
33
+ std::shared_ptr<CircularOverflowableAudioArray> buff_;
32
34
 
33
35
  private:
34
- /// @brief Read audio frames from the recorder's internal adapterBuffer.
35
- /// @note If `framesToRead` is greater than the number of available frames, it will fill empty space with silence.
36
- /// @param output Pointer to the output buffer.
37
- /// @param framesToRead Number of frames to read.
38
- void readFrames(float *output, size_t framesToRead);
36
+ /// @brief Read audio frames from the recorder's internal adapterBuffer.
37
+ /// @note If `framesToRead` is greater than the number of available frames, it will fill empty space with silence.
38
+ /// @param output Pointer to the output buffer.
39
+ /// @param framesToRead Number of frames to read.
40
+ void readFrames(float *output, size_t framesToRead);
39
41
 
40
- friend class AudioRecorder;
42
+ friend class AudioRecorder;
41
43
  };
42
44
 
43
45
  } // namespace audioapi
@@ -15,6 +15,10 @@
15
15
  #include <audioapi/utils/AudioArray.h>
16
16
  #include <audioapi/utils/AudioBus.h>
17
17
  #include <chrono>
18
+ #include <cstdio>
19
+ #include <memory>
20
+ #include <string>
21
+ #include <utility>
18
22
 
19
23
  namespace audioapi {
20
24
  StreamerNode::StreamerNode(BaseAudioContext *context)
@@ -65,8 +69,8 @@ bool StreamerNode::initialize(const std::string &input_url) {
65
69
  }
66
70
 
67
71
  channelCount_ = codecpar_->ch_layout.nb_channels;
68
- audioBus_ = std::make_shared<AudioBus>(
69
- RENDER_QUANTUM_SIZE, channelCount_, context_->getSampleRate());
72
+ audioBus_ =
73
+ std::make_shared<AudioBus>(RENDER_QUANTUM_SIZE, channelCount_, context_->getSampleRate());
70
74
 
71
75
  auto [sender, receiver] = channels::spsc::channel<
72
76
  StreamingData,
@@ -134,8 +138,7 @@ void StreamerNode::streamAudio() {
134
138
  av_packet_unref(pkt_);
135
139
  }
136
140
  StreamingData dummy;
137
- while (receiver_.try_receive(dummy) ==
138
- channels::spsc::ResponseStatus::SUCCESS)
141
+ while (receiver_.try_receive(dummy) == channels::spsc::ResponseStatus::SUCCESS)
139
142
  ; // clear the receiver
140
143
  }
141
144
 
@@ -15,19 +15,19 @@
15
15
 
16
16
  #ifndef AUDIO_API_TEST_SUITE
17
17
  extern "C" {
18
- #include <libavformat/avformat.h>
19
- #include <libavcodec/avcodec.h>
20
- #include <libavutil/samplefmt.h>
21
- #include <libavutil/channel_layout.h>
22
- #include <libavutil/opt.h>
23
- #include <libswresample/swresample.h>
18
+ #include <libavcodec/avcodec.h>
19
+ #include <libavformat/avformat.h>
20
+ #include <libavutil/channel_layout.h>
21
+ #include <libavutil/opt.h>
22
+ #include <libavutil/samplefmt.h>
23
+ #include <libswresample/swresample.h>
24
24
  }
25
25
  #endif
26
26
 
27
+ #include <atomic>
27
28
  #include <cmath>
28
29
  #include <memory>
29
30
  #include <string>
30
- #include <atomic>
31
31
  #include <utility>
32
32
  #ifndef AUDIO_API_TEST_SUITE
33
33
  #include <audioapi/utils/SpscChannel.hpp>
@@ -41,14 +41,14 @@ static constexpr audioapi::channels::spsc::WaitStrategy STREAMER_NODE_SPSC_WAIT_
41
41
  static constexpr bool VERBOSE = false;
42
42
  static constexpr int CHANNEL_CAPACITY = 32;
43
43
 
44
- struct StreamingData{
44
+ struct StreamingData {
45
45
  audioapi::AudioBus bus;
46
46
  size_t size;
47
47
  StreamingData() = default;
48
48
  StreamingData(audioapi::AudioBus b, size_t s) : bus(b), size(s) {}
49
- StreamingData(const StreamingData& data) : bus(data.bus), size(data.size) {}
50
- StreamingData(StreamingData&& data) noexcept : bus(std::move(data.bus)), size(data.size) {}
51
- StreamingData& operator=(const StreamingData& data) {
49
+ StreamingData(const StreamingData &data) : bus(data.bus), size(data.size) {}
50
+ StreamingData(StreamingData &&data) noexcept : bus(std::move(data.bus)), size(data.size) {}
51
+ StreamingData &operator=(const StreamingData &data) {
52
52
  if (this == &data) {
53
53
  return *this;
54
54
  }
@@ -70,33 +70,41 @@ class StreamerNode : public AudioScheduledSourceNode {
70
70
  /**
71
71
  * @brief Initialize all necessary ffmpeg components for streaming audio
72
72
  */
73
- bool initialize(const std::string& inputUrl);
73
+ bool initialize(const std::string &inputUrl);
74
74
 
75
75
  protected:
76
- std::shared_ptr<AudioBus> processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override;
76
+ std::shared_ptr<AudioBus> processNode(
77
+ const std::shared_ptr<AudioBus> &processingBus,
78
+ int framesToProcess) override;
77
79
 
78
80
  private:
79
- #ifndef AUDIO_API_TEST_SUITE
80
- AVFormatContext* fmtCtx_;
81
- AVCodecContext* codecCtx_;
82
- const AVCodec* decoder_;
83
- AVCodecParameters* codecpar_;
84
- AVPacket* pkt_;
85
- AVFrame* frame_; // Frame that is currently being processed
86
- SwrContext* swrCtx_;
87
- uint8_t** resampledData_; // weird ffmpeg way of using raw byte pointers for resampled data
81
+ #ifndef AUDIO_API_TEST_SUITE
82
+ AVFormatContext *fmtCtx_;
83
+ AVCodecContext *codecCtx_;
84
+ const AVCodec *decoder_;
85
+ AVCodecParameters *codecpar_;
86
+ AVPacket *pkt_;
87
+ AVFrame *frame_; // Frame that is currently being processed
88
+ SwrContext *swrCtx_;
89
+ uint8_t **resampledData_; // weird ffmpeg way of using raw byte pointers for resampled data
88
90
 
89
91
  std::shared_ptr<AudioBus> bufferedBus_; // audio bus for buffering hls frames
90
- size_t bufferedBusSize_; // size of currently buffered bus
91
- int audio_stream_index_; // index of the audio stream channel in the input
92
+ size_t bufferedBusSize_; // size of currently buffered bus
93
+ int audio_stream_index_; // index of the audio stream channel in the input
92
94
  int maxResampledSamples_;
93
95
  size_t processedSamples_;
94
96
 
95
97
  std::thread streamingThread_;
96
- std::atomic<bool> isNodeFinished_; // Flag to control the streaming thread
98
+ std::atomic<bool> isNodeFinished_; // Flag to control the streaming thread
97
99
  static constexpr int INITIAL_MAX_RESAMPLED_SAMPLES = 8192; // Initial size for resampled data
98
- channels::spsc::Sender<StreamingData, STREAMER_NODE_SPSC_OVERFLOW_STRATEGY, STREAMER_NODE_SPSC_WAIT_STRATEGY> sender_;
99
- channels::spsc::Receiver<StreamingData, STREAMER_NODE_SPSC_OVERFLOW_STRATEGY, STREAMER_NODE_SPSC_WAIT_STRATEGY> receiver_;
100
+ channels::spsc::
101
+ Sender<StreamingData, STREAMER_NODE_SPSC_OVERFLOW_STRATEGY, STREAMER_NODE_SPSC_WAIT_STRATEGY>
102
+ sender_;
103
+ channels::spsc::Receiver<
104
+ StreamingData,
105
+ STREAMER_NODE_SPSC_OVERFLOW_STRATEGY,
106
+ STREAMER_NODE_SPSC_WAIT_STRATEGY>
107
+ receiver_;
100
108
 
101
109
  /**
102
110
  * @brief Setting up the resampler
@@ -109,7 +117,7 @@ class StreamerNode : public AudioScheduledSourceNode {
109
117
  * @param frame The AVFrame to resample
110
118
  * @return true if successful, false otherwise
111
119
  */
112
- bool processFrameWithResampler(AVFrame* frame);
120
+ bool processFrameWithResampler(AVFrame *frame);
113
121
 
114
122
  /**
115
123
  * @brief Thread function to continuously read and process audio frames
@@ -128,7 +136,7 @@ class StreamerNode : public AudioScheduledSourceNode {
128
136
  * @return true if successful, false otherwise
129
137
  * @note This function initializes the FFmpeg libraries and opens the input stream
130
138
  */
131
- bool openInput(const std::string& inputUrl);
139
+ bool openInput(const std::string &inputUrl);
132
140
 
133
141
  /**
134
142
  * @brief Find the audio stream channel in the input
@@ -141,6 +149,6 @@ class StreamerNode : public AudioScheduledSourceNode {
141
149
  * @return true if successful, false otherwise
142
150
  */
143
151
  bool setupDecoder();
144
- #endif // AUDIO_API_TEST_SUITE
152
+ #endif // AUDIO_API_TEST_SUITE
145
153
  };
146
154
  } // namespace audioapi
@@ -1,13 +1,12 @@
1
1
  #include <audioapi/core/sources/WorkletSourceNode.h>
2
2
  #include <audioapi/core/utils/Constants.h>
3
+ #include <memory>
4
+ #include <utility>
3
5
 
4
6
  namespace audioapi {
5
7
 
6
- WorkletSourceNode::WorkletSourceNode(
7
- BaseAudioContext *context,
8
- WorkletsRunner &&workletRunner)
9
- : AudioScheduledSourceNode(context),
10
- workletRunner_(std::move(workletRunner)) {
8
+ WorkletSourceNode::WorkletSourceNode(BaseAudioContext *context, WorkletsRunner &&workletRunner)
9
+ : AudioScheduledSourceNode(context), workletRunner_(std::move(workletRunner)) {
11
10
  isInitialized_ = true;
12
11
 
13
12
  // Prepare buffers for audio processing
@@ -30,8 +29,7 @@ std::shared_ptr<AudioBus> WorkletSourceNode::processNode(
30
29
  size_t startOffset = 0;
31
30
  size_t nonSilentFramesToProcess = framesToProcess;
32
31
 
33
- updatePlaybackInfo(
34
- processingBus, framesToProcess, startOffset, nonSilentFramesToProcess);
32
+ updatePlaybackInfo(processingBus, framesToProcess, startOffset, nonSilentFramesToProcess);
35
33
 
36
34
  if (nonSilentFramesToProcess == 0) {
37
35
  processingBus->zero();
@@ -1,40 +1,42 @@
1
1
  #pragma once
2
- #include <jsi/jsi.h>
3
2
  #include <audioapi/core/BaseAudioContext.h>
4
- #include <audioapi/utils/AudioBus.h>
5
3
  #include <audioapi/core/sources/AudioScheduledSourceNode.h>
6
4
  #include <audioapi/core/utils/worklets/SafeIncludes.h>
7
5
  #include <audioapi/core/utils/worklets/WorkletsRunner.h>
8
6
  #include <audioapi/jsi/AudioArrayBuffer.h>
9
7
  #include <audioapi/utils/AudioArray.h>
8
+ #include <audioapi/utils/AudioBus.h>
9
+ #include <jsi/jsi.h>
10
10
 
11
- #include <vector>
12
11
  #include <memory>
12
+ #include <vector>
13
13
 
14
14
  namespace audioapi {
15
15
 
16
16
  #if RN_AUDIO_API_TEST
17
17
  class WorkletSourceNode : public AudioScheduledSourceNode {
18
18
  public:
19
- explicit WorkletSourceNode(
20
- BaseAudioContext *context,
21
- WorkletsRunner &&workletRunner
22
- ) : AudioScheduledSourceNode(context) {}
19
+ explicit WorkletSourceNode(BaseAudioContext *context, WorkletsRunner &&workletRunner)
20
+ : AudioScheduledSourceNode(context) {}
23
21
 
24
22
  protected:
25
- std::shared_ptr<AudioBus> processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override { return processingBus; }
23
+ std::shared_ptr<AudioBus> processNode(
24
+ const std::shared_ptr<AudioBus> &processingBus,
25
+ int framesToProcess) override {
26
+ return processingBus;
27
+ }
26
28
  };
27
29
  #else
28
30
 
29
31
  class WorkletSourceNode : public AudioScheduledSourceNode {
30
32
  public:
31
- explicit WorkletSourceNode(
32
- BaseAudioContext *context,
33
- WorkletsRunner &&workletRunner
34
- );
33
+ explicit WorkletSourceNode(BaseAudioContext *context, WorkletsRunner &&workletRunner);
35
34
 
36
35
  protected:
37
- std::shared_ptr<AudioBus> processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override;
36
+ std::shared_ptr<AudioBus> processNode(
37
+ const std::shared_ptr<AudioBus> &processingBus,
38
+ int framesToProcess) override;
39
+
38
40
  private:
39
41
  WorkletsRunner workletRunner_;
40
42
  std::vector<std::shared_ptr<AudioArrayBuffer>> outputBuffsHandles_;
@@ -2,15 +2,5 @@
2
2
 
3
3
  namespace audioapi {
4
4
 
5
- enum class AudioFormat {
6
- UNKNOWN,
7
- WAV,
8
- OGG,
9
- FLAC,
10
- AAC,
11
- MP3,
12
- M4A,
13
- MP4,
14
- MOV
15
- };
5
+ enum class AudioFormat { UNKNOWN, WAV, OGG, FLAC, AAC, MP3, M4A, MP4, MOV };
16
6
  } // namespace audioapi
@@ -18,16 +18,23 @@ class AudioDecoder {
18
18
  public:
19
19
  AudioDecoder() = delete;
20
20
 
21
- [[nodiscard]] static std::shared_ptr<AudioBuffer> decodeWithFilePath(const std::string &path, float sampleRate);
21
+ [[nodiscard]] static std::shared_ptr<AudioBuffer> decodeWithFilePath(
22
+ const std::string &path,
23
+ float sampleRate);
22
24
  [[nodiscard]] static std::shared_ptr<AudioBuffer>
23
25
  decodeWithMemoryBlock(const void *data, size_t size, float sampleRate);
24
- [[nodiscard]] static std::shared_ptr<AudioBuffer>
25
- decodeWithPCMInBase64(const std::string &data, float inputSampleRate, int inputChannelCount, bool interleaved);
26
+ [[nodiscard]] static std::shared_ptr<AudioBuffer> decodeWithPCMInBase64(
27
+ const std::string &data,
28
+ float inputSampleRate,
29
+ int inputChannelCount,
30
+ bool interleaved);
26
31
 
27
32
  private:
28
33
  static std::vector<float> readAllPcmFrames(ma_decoder &decoder, int outputChannels);
29
- static std::shared_ptr<AudioBuffer>
30
- makeAudioBufferFromFloatBuffer(const std::vector<float> &buffer, float outputSampleRate, int outputChannels);
34
+ static std::shared_ptr<AudioBuffer> makeAudioBufferFromFloatBuffer(
35
+ const std::vector<float> &buffer,
36
+ float outputSampleRate,
37
+ int outputChannels);
31
38
 
32
39
  static AudioFormat detectAudioFormat(const void *data, size_t size) {
33
40
  if (size < 12)
@@ -66,7 +73,9 @@ class AudioDecoder {
66
73
  return AudioFormat::UNKNOWN;
67
74
  }
68
75
 
69
- static inline bool pathHasExtension(const std::string &path, const std::vector<std::string> &extensions) {
76
+ static inline bool pathHasExtension(
77
+ const std::string &path,
78
+ const std::vector<std::string> &extensions) {
70
79
  std::string pathLower = path;
71
80
  std::transform(pathLower.begin(), pathLower.end(), pathLower.begin(), ::tolower);
72
81
  for (const auto &ext : extensions) {
@@ -1,6 +1,8 @@
1
1
  #include <audioapi/core/AudioNode.h>
2
2
  #include <audioapi/core/utils/AudioNodeDestructor.h>
3
3
  #include <audioapi/core/utils/Locker.h>
4
+ #include <memory>
5
+ #include <utility>
4
6
 
5
7
  namespace audioapi {
6
8
 
@@ -11,8 +13,7 @@ AudioNodeDestructor::AudioNodeDestructor() {
11
13
  channels::spsc::OverflowStrategy::WAIT_ON_FULL,
12
14
  channels::spsc::WaitStrategy::ATOMIC_WAIT>(kChannelCapacity);
13
15
  sender_ = std::move(sender);
14
- workerHandle_ =
15
- std::thread(&AudioNodeDestructor::process, this, std::move(receiver));
16
+ workerHandle_ = std::thread(&AudioNodeDestructor::process, this, std::move(receiver));
16
17
  }
17
18
 
18
19
  AudioNodeDestructor::~AudioNodeDestructor() {
@@ -25,10 +26,8 @@ AudioNodeDestructor::~AudioNodeDestructor() {
25
26
  }
26
27
  }
27
28
 
28
- bool AudioNodeDestructor::tryAddNodeForDeconstruction(
29
- std::shared_ptr<AudioNode> &&node) {
30
- return sender_.try_send(std::move(node)) ==
31
- channels::spsc::ResponseStatus::SUCCESS;
29
+ bool AudioNodeDestructor::tryAddNodeForDeconstruction(std::shared_ptr<AudioNode> &&node) {
30
+ return sender_.try_send(std::move(node)) == channels::spsc::ResponseStatus::SUCCESS;
32
31
  }
33
32
 
34
33
  void AudioNodeDestructor::process(
@@ -1,19 +1,18 @@
1
1
  #pragma once
2
2
 
3
- #include <thread>
3
+ #include <audioapi/utils/SpscChannel.hpp>
4
4
  #include <atomic>
5
- #include <vector>
6
5
  #include <memory>
7
- #include <audioapi/utils/SpscChannel.hpp>
6
+ #include <thread>
7
+ #include <vector>
8
8
 
9
9
  namespace audioapi {
10
10
 
11
11
  class AudioNode;
12
12
 
13
13
  #define AUDIO_NODE_DESTRUCTOR_SPSC_OPTIONS \
14
- std::shared_ptr<AudioNode>, \
15
- channels::spsc::OverflowStrategy::WAIT_ON_FULL, \
16
- channels::spsc::WaitStrategy::ATOMIC_WAIT
14
+ std::shared_ptr<AudioNode>, channels::spsc::OverflowStrategy::WAIT_ON_FULL, \
15
+ channels::spsc::WaitStrategy::ATOMIC_WAIT
17
16
 
18
17
  class AudioNodeDestructor {
19
18
  public:
@@ -32,13 +31,11 @@ class AudioNodeDestructor {
32
31
  std::thread workerHandle_;
33
32
  std::atomic<bool> isExiting_;
34
33
 
35
- channels::spsc::Sender<
36
- AUDIO_NODE_DESTRUCTOR_SPSC_OPTIONS> sender_;
34
+ channels::spsc::Sender<AUDIO_NODE_DESTRUCTOR_SPSC_OPTIONS> sender_;
37
35
 
38
36
  /// @brief Processes audio nodes for deconstruction.
39
37
  /// @param receiver The receiver channel for incoming audio nodes.
40
- void process(channels::spsc::Receiver<
41
- AUDIO_NODE_DESTRUCTOR_SPSC_OPTIONS> &&receiver);
38
+ void process(channels::spsc::Receiver<AUDIO_NODE_DESTRUCTOR_SPSC_OPTIONS> &&receiver);
42
39
  };
43
40
 
44
41
  #undef AUDIO_NODE_DESTRUCTOR_SPSC_OPTIONS
@@ -4,6 +4,9 @@
4
4
  #include <audioapi/core/sources/AudioScheduledSourceNode.h>
5
5
  #include <audioapi/core/utils/AudioNodeManager.h>
6
6
  #include <audioapi/core/utils/Locker.h>
7
+ #include <memory>
8
+ #include <utility>
9
+ #include <vector>
7
10
 
8
11
  namespace audioapi {
9
12
 
@@ -117,8 +120,7 @@ void AudioNodeManager::preProcessGraph() {
117
120
  prepareNodesForDestruction(processingNodes_);
118
121
  }
119
122
 
120
- void AudioNodeManager::addProcessingNode(
121
- const std::shared_ptr<AudioNode> &node) {
123
+ void AudioNodeManager::addProcessingNode(const std::shared_ptr<AudioNode> &node) {
122
124
  auto event = std::make_unique<Event>();
123
125
  event->type = ConnectionType::ADD;
124
126
  event->payloadType = EventPayloadType::NODE;
@@ -127,8 +129,7 @@ void AudioNodeManager::addProcessingNode(
127
129
  sender_.send(std::move(event));
128
130
  }
129
131
 
130
- void AudioNodeManager::addSourceNode(
131
- const std::shared_ptr<AudioScheduledSourceNode> &node) {
132
+ void AudioNodeManager::addSourceNode(const std::shared_ptr<AudioScheduledSourceNode> &node) {
132
133
  auto event = std::make_unique<Event>();
133
134
  event->type = ConnectionType::ADD;
134
135
  event->payloadType = EventPayloadType::SOURCE_NODE;
@@ -148,8 +149,7 @@ void AudioNodeManager::addAudioParam(const std::shared_ptr<AudioParam> &param) {
148
149
 
149
150
  void AudioNodeManager::settlePendingConnections() {
150
151
  std::unique_ptr<Event> value;
151
- while (receiver_.try_receive(value) !=
152
- channels::spsc::ResponseStatus::CHANNEL_EMPTY) {
152
+ while (receiver_.try_receive(value) != channels::spsc::ResponseStatus::CHANNEL_EMPTY) {
153
153
  switch (value->type) {
154
154
  case ConnectionType::CONNECT:
155
155
  handleConnectEvent(std::move(value));
@@ -197,8 +197,7 @@ void AudioNodeManager::handleDisconnectAllEvent(std::unique_ptr<Event> event) {
197
197
  }
198
198
  }
199
199
 
200
- void AudioNodeManager::handleAddToDeconstructionEvent(
201
- std::unique_ptr<Event> event) {
200
+ void AudioNodeManager::handleAddToDeconstructionEvent(std::unique_ptr<Event> event) {
202
201
  switch (event->payloadType) {
203
202
  case EventPayloadType::NODE:
204
203
  processingNodes_.push_back(event->payload.node);
@@ -215,24 +214,19 @@ void AudioNodeManager::handleAddToDeconstructionEvent(
215
214
  }
216
215
 
217
216
  template <typename U>
218
- inline bool AudioNodeManager::nodeCanBeDestructed(
219
- std::shared_ptr<U> const &node) {
217
+ inline bool AudioNodeManager::nodeCanBeDestructed(std::shared_ptr<U> const &node) {
220
218
  // If the node is an AudioScheduledSourceNode, we need to check if it is
221
219
  // playing
222
220
  if constexpr (std::is_base_of_v<AudioScheduledSourceNode, U>) {
223
- return node.use_count() == 1 &&
224
- (node->isUnscheduled() || node->isFinished());
225
- } else if constexpr (std::is_base_of_v<
226
- ConvolverNode,
227
- U>) { // convolver overrides disabling behavior
221
+ return node.use_count() == 1 && (node->isUnscheduled() || node->isFinished());
222
+ } else if constexpr (std::is_base_of_v<ConvolverNode, U>) {
228
223
  return node.use_count() == 1 && !node->isEnabled();
229
224
  }
230
225
  return node.use_count() == 1;
231
226
  }
232
227
 
233
228
  template <typename U>
234
- void AudioNodeManager::prepareNodesForDestruction(
235
- std::vector<std::shared_ptr<U>> &vec) {
229
+ void AudioNodeManager::prepareNodesForDestruction(std::vector<std::shared_ptr<U>> &vec) {
236
230
  if (vec.empty()) {
237
231
  return;
238
232
  }
@@ -284,14 +278,11 @@ void AudioNodeManager::prepareNodesForDestruction(
284
278
  }
285
279
 
286
280
  void AudioNodeManager::cleanup() {
287
- for (auto it = sourceNodes_.begin(), end = sourceNodes_.end(); it != end;
288
- ++it) {
281
+ for (auto it = sourceNodes_.begin(), end = sourceNodes_.end(); it != end; ++it) {
289
282
  it->get()->cleanup();
290
283
  }
291
284
 
292
- for (auto it = processingNodes_.begin(), end = processingNodes_.end();
293
- it != end;
294
- ++it) {
285
+ for (auto it = processingNodes_.begin(), end = processingNodes_.end(); it != end; ++it) {
295
286
  it->get()->cleanup();
296
287
  }
297
288
 
@@ -16,9 +16,8 @@ class AudioScheduledSourceNode;
16
16
  class AudioParam;
17
17
 
18
18
  #define AUDIO_NODE_MANAGER_SPSC_OPTIONS \
19
- std::unique_ptr<Event>, \
20
- channels::spsc::OverflowStrategy::WAIT_ON_FULL, \
21
- channels::spsc::WaitStrategy::BUSY_LOOP
19
+ std::unique_ptr<Event>, channels::spsc::OverflowStrategy::WAIT_ON_FULL, \
20
+ channels::spsc::WaitStrategy::BUSY_LOOP
22
21
 
23
22
  class AudioNodeManager {
24
23
  public:
@@ -49,8 +48,8 @@ class AudioNodeManager {
49
48
  EventPayloadType payloadType;
50
49
  EventPayload payload;
51
50
 
52
- Event(Event&& other);
53
- Event& operator=(Event&& other);
51
+ Event(Event &&other);
52
+ Event &operator=(Event &&other);
54
53
  Event() : type(ConnectionType::CONNECT), payloadType(EventPayloadType::NODES), payload() {}
55
54
  ~Event();
56
55
  };
@@ -78,7 +77,7 @@ class AudioNodeManager {
78
77
  void addPendingParamConnection(
79
78
  const std::shared_ptr<AudioNode> &from,
80
79
  const std::shared_ptr<AudioParam> &to,
81
- ConnectionType type);
80
+ ConnectionType type);
82
81
 
83
82
  /// @brief Adds a processing node to the manager.
84
83
  /// @param node The processing node to add.
@@ -112,11 +111,9 @@ class AudioNodeManager {
112
111
  std::vector<std::shared_ptr<AudioNode>> processingNodes_;
113
112
  std::vector<std::shared_ptr<AudioParam>> audioParams_;
114
113
 
115
- channels::spsc::Receiver<
116
- AUDIO_NODE_MANAGER_SPSC_OPTIONS> receiver_;
114
+ channels::spsc::Receiver<AUDIO_NODE_MANAGER_SPSC_OPTIONS> receiver_;
117
115
 
118
- channels::spsc::Sender<
119
- AUDIO_NODE_MANAGER_SPSC_OPTIONS> sender_;
116
+ channels::spsc::Sender<AUDIO_NODE_MANAGER_SPSC_OPTIONS> sender_;
120
117
 
121
118
  void settlePendingConnections();
122
119
  void handleConnectEvent(std::unique_ptr<Event> event);
@@ -128,7 +125,7 @@ class AudioNodeManager {
128
125
  void prepareNodesForDestruction(std::vector<std::shared_ptr<U>> &vec);
129
126
 
130
127
  template <typename U>
131
- inline static bool nodeCanBeDestructed(std::shared_ptr<U> const& node);
128
+ inline static bool nodeCanBeDestructed(std::shared_ptr<U> const &node);
132
129
  };
133
130
 
134
131
  #undef AUDIO_NODE_MANAGER_SPSC_OPTIONS
@@ -1,4 +1,6 @@
1
1
  #include <audioapi/core/utils/AudioParamEventQueue.h>
2
+ #include <algorithm>
3
+ #include <utility>
2
4
 
3
5
  namespace audioapi {
4
6
 
@@ -42,9 +44,7 @@ void AudioParamEventQueue::cancelScheduledValues(double cancelTime) {
42
44
  }
43
45
  }
44
46
 
45
- void AudioParamEventQueue::cancelAndHoldAtTime(
46
- double cancelTime,
47
- double &endTimeCache) {
47
+ void AudioParamEventQueue::cancelAndHoldAtTime(double cancelTime, double &endTimeCache) {
48
48
  while (!eventQueue_.isEmpty()) {
49
49
  auto &back = eventQueue_.peekBack();
50
50
  if (back.getEndTime() < cancelTime || back.getStartTime() <= cancelTime) {
@@ -1,7 +1,7 @@
1
1
  #pragma once
2
2
 
3
- #include <audioapi/core/utils/ParamChangeEvent.h>
4
3
  #include <audioapi/core/types/ParamChangeEventType.h>
4
+ #include <audioapi/core/utils/ParamChangeEvent.h>
5
5
  #include <audioapi/utils/RingBiDirectionalBuffer.hpp>
6
6
 
7
7
  namespace audioapi {
@@ -16,7 +16,7 @@ class AudioParamEventQueue {
16
16
 
17
17
  /// @brief Push a new event to the back of the queue.
18
18
  /// @note Handles connecting the start value of the new event to the end value of the last event in the queue.
19
- void pushBack(ParamChangeEvent&& event);
19
+ void pushBack(ParamChangeEvent &&event);
20
20
 
21
21
  /// @brief Pop the front event from the queue.
22
22
  /// @return The front event in the queue.
@@ -28,17 +28,17 @@ class AudioParamEventQueue {
28
28
 
29
29
  /// @brief Cancel scheduled parameter changes and hold the current value at the given time.
30
30
  /// @param cancelTime The time at which to cancel scheduled changes.
31
- void cancelAndHoldAtTime(double cancelTime, double& endTimeCache);
31
+ void cancelAndHoldAtTime(double cancelTime, double &endTimeCache);
32
32
 
33
33
  /// @brief Get the first event in the queue.
34
34
  /// @return The first event in the queue.
35
- inline const ParamChangeEvent& front() const noexcept {
35
+ inline const ParamChangeEvent &front() const noexcept {
36
36
  return eventQueue_.peekFront();
37
37
  }
38
38
 
39
39
  /// @brief Get the last event in the queue.
40
40
  /// @return The last event in the queue.
41
- inline const ParamChangeEvent& back() const noexcept {
41
+ inline const ParamChangeEvent &back() const noexcept {
42
42
  return eventQueue_.peekBack();
43
43
  }
44
44