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
@@ -8,6 +8,13 @@
8
8
  #include <audioapi/utils/AudioArray.h>
9
9
  #include <audioapi/utils/AudioBus.h>
10
10
 
11
+ #include <algorithm>
12
+ #include <memory>
13
+ #include <queue>
14
+ #include <string>
15
+ #include <unordered_map>
16
+ #include <utility>
17
+
11
18
  namespace audioapi {
12
19
 
13
20
  AudioBufferQueueSourceNode::AudioBufferQueueSourceNode(
@@ -22,10 +29,9 @@ AudioBufferQueueSourceNode::AudioBufferQueueSourceNode(
22
29
  // to compensate for processing latency.
23
30
  addExtraTailFrames_ = true;
24
31
 
25
- int extraTailFrames =
26
- static_cast<int>(stretch_->inputLatency() + stretch_->outputLatency());
27
- tailBuffer_ = std::make_shared<AudioBuffer>(
28
- channelCount_, extraTailFrames, context_->getSampleRate());
32
+ int extraTailFrames = static_cast<int>(stretch_->inputLatency() + stretch_->outputLatency());
33
+ tailBuffer_ =
34
+ std::make_shared<AudioBuffer>(channelCount_, extraTailFrames, context_->getSampleRate());
29
35
 
30
36
  tailBuffer_->bus_->zero();
31
37
  }
@@ -54,8 +60,7 @@ void AudioBufferQueueSourceNode::start(double when, double offset) {
54
60
  }
55
61
 
56
62
  offset = std::min(offset, buffers_.front().second->getDuration());
57
- vReadIndex_ =
58
- static_cast<double>(buffers_.front().second->getSampleRate() * offset);
63
+ vReadIndex_ = static_cast<double>(buffers_.front().second->getSampleRate() * offset);
59
64
  }
60
65
 
61
66
  void AudioBufferQueueSourceNode::pause() {
@@ -63,8 +68,7 @@ void AudioBufferQueueSourceNode::pause() {
63
68
  isPaused_ = true;
64
69
  }
65
70
 
66
- std::string AudioBufferQueueSourceNode::enqueueBuffer(
67
- const std::shared_ptr<AudioBuffer> &buffer) {
71
+ std::string AudioBufferQueueSourceNode::enqueueBuffer(const std::shared_ptr<AudioBuffer> &buffer) {
68
72
  auto locker = Locker(getBufferLock());
69
73
  buffers_.emplace(bufferId_, buffer);
70
74
 
@@ -140,8 +144,7 @@ std::shared_ptr<AudioBus> AudioBufferQueueSourceNode::processNode(
140
144
  }
141
145
 
142
146
  double AudioBufferQueueSourceNode::getCurrentPosition() const {
143
- return dsp::sampleFrameToTime(
144
- static_cast<int>(vReadIndex_), context_->getSampleRate()) +
147
+ return dsp::sampleFrameToTime(static_cast<int>(vReadIndex_), context_->getSampleRate()) +
145
148
  playedBuffersDuration_;
146
149
  }
147
150
 
@@ -173,8 +176,7 @@ void AudioBufferQueueSourceNode::processWithoutInterpolation(
173
176
  assert(readIndex + framesToCopy <= buffer->getLength());
174
177
  assert(writeIndex + framesToCopy <= processingBus->getSize());
175
178
 
176
- processingBus->copy(
177
- buffer->bus_.get(), readIndex, writeIndex, framesToCopy);
179
+ processingBus->copy(buffer->bus_.get(), readIndex, writeIndex, framesToCopy);
178
180
 
179
181
  writeIndex += framesToCopy;
180
182
  readIndex += framesToCopy;
@@ -229,8 +231,7 @@ void AudioBufferQueueSourceNode::processWithInterpolation(
229
231
  while (framesLeft > 0) {
230
232
  auto readIndex = static_cast<size_t>(vReadIndex_);
231
233
  size_t nextReadIndex = readIndex + 1;
232
- auto factor =
233
- static_cast<float>(vReadIndex_ - static_cast<double>(readIndex));
234
+ auto factor = static_cast<float>(vReadIndex_ - static_cast<double>(readIndex));
234
235
 
235
236
  bool crossBufferInterpolation = false;
236
237
  std::shared_ptr<AudioBuffer> nextBuffer = nullptr;
@@ -255,11 +256,10 @@ void AudioBufferQueueSourceNode::processWithInterpolation(
255
256
  const float *nextSource = nextBuffer->bus_->getChannel(i)->getData();
256
257
  float currentSample = currentSource[readIndex];
257
258
  float nextSample = nextSource[nextReadIndex];
258
- destination[writeIndex] =
259
- currentSample + factor * (nextSample - currentSample);
259
+ destination[writeIndex] = currentSample + factor * (nextSample - currentSample);
260
260
  } else {
261
- destination[writeIndex] = dsp::linearInterpolate(
262
- currentSource, readIndex, nextReadIndex, factor);
261
+ destination[writeIndex] =
262
+ dsp::linearInterpolate(currentSource, readIndex, nextReadIndex, factor);
263
263
  }
264
264
  }
265
265
 
@@ -272,8 +272,7 @@ void AudioBufferQueueSourceNode::processWithInterpolation(
272
272
  playedBuffersDuration_ += buffer->getDuration();
273
273
  buffers_.pop();
274
274
 
275
- std::unordered_map<std::string, EventValue> body = {
276
- {"bufferId", std::to_string(bufferId)}};
275
+ std::unordered_map<std::string, EventValue> body = {{"bufferId", std::to_string(bufferId)}};
277
276
  context_->audioEventHandlerRegistry_->invokeHandlerWithEventBody(
278
277
  "ended", onEndedCallbackId_, body);
279
278
 
@@ -4,11 +4,11 @@
4
4
  #include <audioapi/core/sources/AudioBufferBaseSourceNode.h>
5
5
  #include <audioapi/libs/signalsmith-stretch/signalsmith-stretch.h>
6
6
 
7
- #include <memory>
8
- #include <cstddef>
9
7
  #include <algorithm>
10
- #include <string>
8
+ #include <cstddef>
9
+ #include <memory>
11
10
  #include <queue>
11
+ #include <string>
12
12
 
13
13
  namespace audioapi {
14
14
 
@@ -17,46 +17,48 @@ class AudioParam;
17
17
 
18
18
  class AudioBufferQueueSourceNode : public AudioBufferBaseSourceNode {
19
19
  public:
20
- explicit AudioBufferQueueSourceNode(BaseAudioContext *context, bool pitchCorrection);
21
- ~AudioBufferQueueSourceNode() override;
20
+ explicit AudioBufferQueueSourceNode(BaseAudioContext *context, bool pitchCorrection);
21
+ ~AudioBufferQueueSourceNode() override;
22
22
 
23
- void stop(double when) override;
23
+ void stop(double when) override;
24
24
 
25
- using AudioScheduledSourceNode::start;
26
- void start(double when, double offset);
27
- void pause();
25
+ using AudioScheduledSourceNode::start;
26
+ void start(double when, double offset);
27
+ void pause();
28
28
 
29
- std::string enqueueBuffer(const std::shared_ptr<AudioBuffer> &buffer);
30
- void dequeueBuffer(size_t bufferId);
31
- void clearBuffers();
32
- void disable() override;
29
+ std::string enqueueBuffer(const std::shared_ptr<AudioBuffer> &buffer);
30
+ void dequeueBuffer(size_t bufferId);
31
+ void clearBuffers();
32
+ void disable() override;
33
33
 
34
34
  protected:
35
- std::shared_ptr<AudioBus> processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override;
36
- double getCurrentPosition() const override;
35
+ std::shared_ptr<AudioBus> processNode(
36
+ const std::shared_ptr<AudioBus> &processingBus,
37
+ int framesToProcess) override;
38
+ double getCurrentPosition() const override;
37
39
 
38
40
  private:
39
- // User provided buffers
40
- std::queue<std::pair<size_t, std::shared_ptr<AudioBuffer>>> buffers_;
41
- size_t bufferId_ = 0;
42
-
43
- bool isPaused_ = false;
44
- bool addExtraTailFrames_ = false;
45
- std::shared_ptr<AudioBuffer> tailBuffer_;
46
-
47
- double playedBuffersDuration_ = 0;
48
-
49
- void processWithoutInterpolation(
50
- const std::shared_ptr<AudioBus>& processingBus,
51
- size_t startOffset,
52
- size_t offsetLength,
53
- float playbackRate) override;
54
-
55
- void processWithInterpolation(
56
- const std::shared_ptr<AudioBus>& processingBus,
57
- size_t startOffset,
58
- size_t offsetLength,
59
- float playbackRate) override;
41
+ // User provided buffers
42
+ std::queue<std::pair<size_t, std::shared_ptr<AudioBuffer>>> buffers_;
43
+ size_t bufferId_ = 0;
44
+
45
+ bool isPaused_ = false;
46
+ bool addExtraTailFrames_ = false;
47
+ std::shared_ptr<AudioBuffer> tailBuffer_;
48
+
49
+ double playedBuffersDuration_ = 0;
50
+
51
+ void processWithoutInterpolation(
52
+ const std::shared_ptr<AudioBus> &processingBus,
53
+ size_t startOffset,
54
+ size_t offsetLength,
55
+ float playbackRate) override;
56
+
57
+ void processWithInterpolation(
58
+ const std::shared_ptr<AudioBus> &processingBus,
59
+ size_t startOffset,
60
+ size_t offsetLength,
61
+ float playbackRate) override;
60
62
  };
61
63
 
62
64
  } // namespace audioapi
@@ -7,12 +7,12 @@
7
7
  #include <audioapi/events/AudioEventHandlerRegistry.h>
8
8
  #include <audioapi/utils/AudioArray.h>
9
9
  #include <audioapi/utils/AudioBus.h>
10
+ #include <algorithm>
11
+ #include <memory>
10
12
 
11
13
  namespace audioapi {
12
14
 
13
- AudioBufferSourceNode::AudioBufferSourceNode(
14
- BaseAudioContext *context,
15
- bool pitchCorrection)
15
+ AudioBufferSourceNode::AudioBufferSourceNode(BaseAudioContext *context, bool pitchCorrection)
16
16
  : AudioBufferBaseSourceNode(context, pitchCorrection),
17
17
  loop_(false),
18
18
  loopSkip_(false),
@@ -70,8 +70,7 @@ void AudioBufferSourceNode::setLoopEnd(double loopEnd) {
70
70
  loopEnd_ = loopEnd;
71
71
  }
72
72
 
73
- void AudioBufferSourceNode::setBuffer(
74
- const std::shared_ptr<AudioBuffer> &buffer) {
73
+ void AudioBufferSourceNode::setBuffer(const std::shared_ptr<AudioBuffer> &buffer) {
75
74
  Locker locker(getBufferLock());
76
75
 
77
76
  if (!buffer) {
@@ -87,12 +86,11 @@ void AudioBufferSourceNode::setBuffer(
87
86
  stretch_->presetDefault(channelCount_, buffer_->getSampleRate());
88
87
 
89
88
  if (pitchCorrection_) {
90
- int extraTailFrames = static_cast<int>(
91
- (getInputLatency() + getOutputLatency()) * context_->getSampleRate());
89
+ int extraTailFrames =
90
+ static_cast<int>((getInputLatency() + getOutputLatency()) * context_->getSampleRate());
92
91
  size_t totalSize = buffer_->getLength() + extraTailFrames;
93
92
 
94
- alignedBus_ = std::make_shared<AudioBus>(
95
- totalSize, channelCount_, buffer_->getSampleRate());
93
+ alignedBus_ = std::make_shared<AudioBus>(totalSize, channelCount_, buffer_->getSampleRate());
96
94
  alignedBus_->copy(buffer_->bus_.get(), 0, 0, buffer_->getLength());
97
95
 
98
96
  alignedBus_->zero(buffer_->getLength(), extraTailFrames);
@@ -100,10 +98,10 @@ void AudioBufferSourceNode::setBuffer(
100
98
  alignedBus_ = std::make_shared<AudioBus>(*buffer_->bus_);
101
99
  }
102
100
 
103
- audioBus_ = std::make_shared<AudioBus>(
104
- RENDER_QUANTUM_SIZE, channelCount_, context_->getSampleRate());
105
- playbackRateBus_ = std::make_shared<AudioBus>(
106
- RENDER_QUANTUM_SIZE * 3, channelCount_, context_->getSampleRate());
101
+ audioBus_ =
102
+ std::make_shared<AudioBus>(RENDER_QUANTUM_SIZE, channelCount_, context_->getSampleRate());
103
+ playbackRateBus_ =
104
+ std::make_shared<AudioBus>(RENDER_QUANTUM_SIZE * 3, channelCount_, context_->getSampleRate());
107
105
 
108
106
  loopEnd_ = buffer_->getDuration();
109
107
  }
@@ -119,10 +117,8 @@ void AudioBufferSourceNode::start(double when, double offset, double duration) {
119
117
  return;
120
118
  }
121
119
 
122
- offset = std::min(
123
- offset,
124
- static_cast<double>(alignedBus_->getSize()) /
125
- alignedBus_->getSampleRate());
120
+ offset =
121
+ std::min(offset, static_cast<double>(alignedBus_->getSize()) / alignedBus_->getSampleRate());
126
122
 
127
123
  if (loop_) {
128
124
  offset = std::min(offset, loopEnd_);
@@ -137,8 +133,7 @@ void AudioBufferSourceNode::disable() {
137
133
  }
138
134
 
139
135
  void AudioBufferSourceNode::setOnLoopEndedCallbackId(uint64_t callbackId) {
140
- auto oldCallbackId =
141
- onLoopEndedCallbackId_.exchange(callbackId, std::memory_order_acq_rel);
136
+ auto oldCallbackId = onLoopEndedCallbackId_.exchange(callbackId, std::memory_order_acq_rel);
142
137
 
143
138
  if (oldCallbackId != 0) {
144
139
  audioEventHandlerRegistry_->unregisterHandler("loopEnded", oldCallbackId);
@@ -170,16 +165,13 @@ std::shared_ptr<AudioBus> AudioBufferSourceNode::processNode(
170
165
  }
171
166
 
172
167
  double AudioBufferSourceNode::getCurrentPosition() const {
173
- return dsp::sampleFrameToTime(
174
- static_cast<int>(vReadIndex_), buffer_->getSampleRate());
168
+ return dsp::sampleFrameToTime(static_cast<int>(vReadIndex_), buffer_->getSampleRate());
175
169
  }
176
170
 
177
171
  void AudioBufferSourceNode::sendOnLoopEndedEvent() {
178
- auto onLoopEndedCallbackId =
179
- onLoopEndedCallbackId_.load(std::memory_order_acquire);
172
+ auto onLoopEndedCallbackId = onLoopEndedCallbackId_.load(std::memory_order_acquire);
180
173
  if (onLoopEndedCallbackId != 0) {
181
- audioEventHandlerRegistry_->invokeHandlerWithEventBody(
182
- "loopEnded", onLoopEndedCallbackId, {});
174
+ audioEventHandlerRegistry_->invokeHandlerWithEventBody("loopEnded", onLoopEndedCallbackId, {});
183
175
  }
184
176
  }
185
177
 
@@ -206,10 +198,9 @@ void AudioBufferSourceNode::processWithoutInterpolation(
206
198
  // if we are moving towards loop, we do nothing because we will achieve it
207
199
  // otherwise, we wrap to the start of the loop if necessary
208
200
  if (loop_ &&
209
- ((readIndex >= frameEnd && direction == 1) ||
210
- (readIndex < frameStart && direction == -1))) {
201
+ ((readIndex >= frameEnd && direction == 1) || (readIndex < frameStart && direction == -1))) {
211
202
  readIndex = frameStart +
212
- ((long long int)readIndex - (long long int)frameStart) % frameDelta;
203
+ (static_cast<int64_t>(readIndex) - static_cast<int64_t>(frameStart)) % frameDelta;
213
204
  }
214
205
 
215
206
  while (framesLeft > 0) {
@@ -224,8 +215,7 @@ void AudioBufferSourceNode::processWithoutInterpolation(
224
215
 
225
216
  // Direction is forward, we can normally copy the data
226
217
  if (direction == 1) {
227
- processingBus->copy(
228
- alignedBus_.get(), readIndex, writeIndex, framesToCopy);
218
+ processingBus->copy(alignedBus_.get(), readIndex, writeIndex, framesToCopy);
229
219
  } else {
230
220
  for (int i = 0; i < framesToCopy; i += 1) {
231
221
  for (int j = 0; j < processingBus->getNumberOfChannels(); j += 1) {
@@ -241,8 +231,7 @@ void AudioBufferSourceNode::processWithoutInterpolation(
241
231
 
242
232
  // if we are moving towards loop, we do nothing because we will achieve it
243
233
  // otherwise, we wrap to the start of the loop if necessary
244
- if ((readIndex >= frameEnd && direction == 1) ||
245
- (readIndex < frameStart && direction == -1)) {
234
+ if ((readIndex >= frameEnd && direction == 1) || (readIndex < frameStart && direction == -1)) {
246
235
  readIndex -= direction * frameDelta;
247
236
 
248
237
  if (!loop_) {
@@ -279,15 +268,13 @@ void AudioBufferSourceNode::processWithInterpolation(
279
268
 
280
269
  // Wrap to the start of the loop if necessary
281
270
  if (loop_ && (vReadIndex_ >= vFrameEnd || vReadIndex_ < vFrameStart)) {
282
- vReadIndex_ =
283
- vFrameStart + std::fmod(vReadIndex_ - vFrameStart, vFrameDelta);
271
+ vReadIndex_ = vFrameStart + std::fmod(vReadIndex_ - vFrameStart, vFrameDelta);
284
272
  }
285
273
 
286
274
  while (framesLeft > 0) {
287
275
  auto readIndex = static_cast<size_t>(vReadIndex_);
288
276
  size_t nextReadIndex = readIndex + 1;
289
- auto factor =
290
- static_cast<float>(vReadIndex_ - static_cast<double>(readIndex));
277
+ auto factor = static_cast<float>(vReadIndex_ - static_cast<double>(readIndex));
291
278
 
292
279
  if (nextReadIndex >= frameEnd) {
293
280
  nextReadIndex = loop_ ? frameStart : readIndex;
@@ -297,8 +284,7 @@ void AudioBufferSourceNode::processWithInterpolation(
297
284
  float *destination = processingBus->getChannel(i)->getData();
298
285
  const float *source = alignedBus_->getChannel(i)->getData();
299
286
 
300
- destination[writeIndex] =
301
- dsp::linearInterpolate(source, readIndex, nextReadIndex, factor);
287
+ destination[writeIndex] = dsp::linearInterpolate(source, readIndex, nextReadIndex, factor);
302
288
  }
303
289
 
304
290
  writeIndex += 1;
@@ -322,8 +308,7 @@ void AudioBufferSourceNode::processWithInterpolation(
322
308
  double AudioBufferSourceNode::getVirtualStartFrame() {
323
309
  auto loopStartFrame = loopStart_ * context_->getSampleRate();
324
310
 
325
- return loop_ && loopStartFrame >= 0 && loopStart_ < loopEnd_ ? loopStartFrame
326
- : 0.0;
311
+ return loop_ && loopStartFrame >= 0 && loopStart_ < loopEnd_ ? loopStartFrame : 0.0;
327
312
  }
328
313
 
329
314
  double AudioBufferSourceNode::getVirtualEndFrame() {
@@ -38,7 +38,9 @@ class AudioBufferSourceNode : public AudioBufferBaseSourceNode {
38
38
  void setOnLoopEndedCallbackId(uint64_t callbackId);
39
39
 
40
40
  protected:
41
- std::shared_ptr<AudioBus> processNode(const std::shared_ptr<AudioBus> &processingBus, int framesToProcess) override;
41
+ std::shared_ptr<AudioBus> processNode(
42
+ const std::shared_ptr<AudioBus> &processingBus,
43
+ int framesToProcess) override;
42
44
  double getCurrentPosition() const override;
43
45
 
44
46
  private:
@@ -10,6 +10,10 @@
10
10
  #include <audioapi/core/AudioContext.h>
11
11
  #endif
12
12
 
13
+ #include <algorithm>
14
+ #include <limits>
15
+ #include <memory>
16
+
13
17
  namespace audioapi {
14
18
 
15
19
  AudioScheduledSourceNode::AudioScheduledSourceNode(BaseAudioContext *context)
@@ -57,8 +61,7 @@ bool AudioScheduledSourceNode::isStopScheduled() {
57
61
  }
58
62
 
59
63
  void AudioScheduledSourceNode::setOnEndedCallbackId(const uint64_t callbackId) {
60
- auto oldCallbackId =
61
- onEndedCallbackId_.exchange(callbackId, std::memory_order_acq_rel);
64
+ auto oldCallbackId = onEndedCallbackId_.exchange(callbackId, std::memory_order_acq_rel);
62
65
 
63
66
  if (oldCallbackId != 0) {
64
67
  audioEventHandlerRegistry_->unregisterHandler("ended", oldCallbackId);
@@ -83,11 +86,9 @@ void AudioScheduledSourceNode::updatePlaybackInfo(
83
86
  size_t firstFrame = context_->getCurrentSampleFrame();
84
87
  size_t lastFrame = firstFrame + framesToProcess - 1;
85
88
 
86
- size_t startFrame =
87
- std::max(dsp::timeToSampleFrame(startTime_, sampleRate), firstFrame);
88
- size_t stopFrame = stopTime_ == -1.0
89
- ? std::numeric_limits<size_t>::max()
90
- : dsp::timeToSampleFrame(stopTime_, sampleRate);
89
+ size_t startFrame = std::max(dsp::timeToSampleFrame(startTime_, sampleRate), firstFrame);
90
+ size_t stopFrame = stopTime_ == -1.0 ? std::numeric_limits<size_t>::max()
91
+ : dsp::timeToSampleFrame(stopTime_, sampleRate);
91
92
  if (isFinished()) {
92
93
  startOffset = 0;
93
94
  nonSilentFramesToProcess = 0;
@@ -166,8 +167,7 @@ void AudioScheduledSourceNode::disable() {
166
167
 
167
168
  auto onEndedCallbackId = onEndedCallbackId_.load(std::memory_order_acquire);
168
169
  if (onEndedCallbackId != 0) {
169
- audioEventHandlerRegistry_->invokeHandlerWithEventBody(
170
- "ended", onEndedCallbackId, {});
170
+ audioEventHandlerRegistry_->invokeHandlerWithEventBody("ended", onEndedCallbackId, {});
171
171
  }
172
172
  }
173
173
 
@@ -4,14 +4,14 @@
4
4
 
5
5
  #include <algorithm>
6
6
  #include <atomic>
7
+ #include <cassert>
7
8
  #include <chrono>
9
+ #include <cstddef>
8
10
  #include <functional>
9
11
  #include <iostream>
10
12
  #include <limits>
11
13
  #include <memory>
12
14
  #include <thread>
13
- #include <cstddef>
14
- #include <cassert>
15
15
  #include <utility>
16
16
 
17
17
  namespace audioapi {
@@ -51,7 +51,7 @@ class AudioScheduledSourceNode : public AudioNode {
51
51
  std::shared_ptr<IAudioEventHandlerRegistry> audioEventHandlerRegistry_;
52
52
 
53
53
  void updatePlaybackInfo(
54
- const std::shared_ptr<AudioBus>& processingBus,
54
+ const std::shared_ptr<AudioBus> &processingBus,
55
55
  int framesToProcess,
56
56
  size_t &startOffset,
57
57
  size_t &nonSilentFramesToProcess);
@@ -3,6 +3,7 @@
3
3
  #include <audioapi/dsp/AudioUtils.h>
4
4
  #include <audioapi/utils/AudioArray.h>
5
5
  #include <audioapi/utils/AudioBus.h>
6
+ #include <memory>
6
7
 
7
8
  namespace audioapi {
8
9
  ConstantSourceNode::ConstantSourceNode(BaseAudioContext *context)
@@ -29,13 +30,11 @@ std::shared_ptr<AudioBus> ConstantSourceNode::processNode(
29
30
  return processingBus;
30
31
  }
31
32
 
32
- auto offsetBus = offsetParam_->processARateParam(
33
- framesToProcess, context_->getCurrentTime());
33
+ auto offsetBus = offsetParam_->processARateParam(framesToProcess, context_->getCurrentTime());
34
34
 
35
35
  auto offsetChannelData = offsetBus->getChannel(0)->getData();
36
36
 
37
- for (int channel = 0; channel < processingBus->getNumberOfChannels();
38
- ++channel) {
37
+ for (int channel = 0; channel < processingBus->getNumberOfChannels(); ++channel) {
39
38
  auto outputChannelData = processingBus->getChannel(channel)->getData();
40
39
 
41
40
  std::copy(
@@ -18,7 +18,9 @@ class ConstantSourceNode : public AudioScheduledSourceNode {
18
18
  [[nodiscard]] std::shared_ptr<AudioParam> getOffsetParam() const;
19
19
 
20
20
  protected:
21
- std::shared_ptr<AudioBus> processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override;
21
+ std::shared_ptr<AudioBus> processNode(
22
+ const std::shared_ptr<AudioBus> &processingBus,
23
+ int framesToProcess) override;
22
24
 
23
25
  private:
24
26
  std::shared_ptr<AudioParam> offsetParam_;
@@ -3,16 +3,14 @@
3
3
  #include <audioapi/dsp/AudioUtils.h>
4
4
  #include <audioapi/utils/AudioArray.h>
5
5
  #include <audioapi/utils/AudioBus.h>
6
+ #include <memory>
7
+ #include <string>
6
8
 
7
9
  namespace audioapi {
8
10
 
9
- OscillatorNode::OscillatorNode(BaseAudioContext *context)
10
- : AudioScheduledSourceNode(context) {
11
+ OscillatorNode::OscillatorNode(BaseAudioContext *context) : AudioScheduledSourceNode(context) {
11
12
  frequencyParam_ = std::make_shared<AudioParam>(
12
- 444.0,
13
- -context_->getNyquistFrequency(),
14
- context_->getNyquistFrequency(),
15
- context);
13
+ 444.0, -context_->getNyquistFrequency(), context_->getNyquistFrequency(), context);
16
14
  detuneParam_ = std::make_shared<AudioParam>(
17
15
  0.0,
18
16
  -1200 * LOG2_MOST_POSITIVE_SINGLE_FLOAT,
@@ -21,8 +19,7 @@ OscillatorNode::OscillatorNode(BaseAudioContext *context)
21
19
  type_ = OscillatorType::SINE;
22
20
  periodicWave_ = context_->getBasicWaveForm(type_);
23
21
 
24
- audioBus_ = std::make_shared<AudioBus>(
25
- RENDER_QUANTUM_SIZE, 1, context_->getSampleRate());
22
+ audioBus_ = std::make_shared<AudioBus>(RENDER_QUANTUM_SIZE, 1, context_->getSampleRate());
26
23
 
27
24
  isInitialized_ = true;
28
25
  }
@@ -44,8 +41,7 @@ void OscillatorNode::setType(const std::string &type) {
44
41
  periodicWave_ = context_->getBasicWaveForm(type_);
45
42
  }
46
43
 
47
- void OscillatorNode::setPeriodicWave(
48
- const std::shared_ptr<PeriodicWave> &periodicWave) {
44
+ void OscillatorNode::setPeriodicWave(const std::shared_ptr<PeriodicWave> &periodicWave) {
49
45
  periodicWave_ = periodicWave;
50
46
  type_ = OscillatorType::CUSTOM;
51
47
  }
@@ -65,29 +61,22 @@ std::shared_ptr<AudioBus> OscillatorNode::processNode(
65
61
 
66
62
  auto time = context_->getCurrentTime() +
67
63
  static_cast<double>(startOffset) * 1.0 / context_->getSampleRate();
68
- auto detuneParamValues =
69
- detuneParam_->processARateParam(framesToProcess, time);
70
- auto frequencyParamValues =
71
- frequencyParam_->processARateParam(framesToProcess, time);
64
+ auto detuneParamValues = detuneParam_->processARateParam(framesToProcess, time);
65
+ auto frequencyParamValues = frequencyParam_->processARateParam(framesToProcess, time);
72
66
 
73
67
  for (size_t i = startOffset; i < offsetLength; i += 1) {
74
- auto detuneRatio = std::pow(
75
- 2.0f, detuneParamValues->getChannel(0)->getData()[i] / 1200.0f);
76
- auto detunedFrequency =
77
- frequencyParamValues->getChannel(0)->getData()[i] * detuneRatio;
68
+ auto detuneRatio = std::pow(2.0f, detuneParamValues->getChannel(0)->getData()[i] / 1200.0f);
69
+ auto detunedFrequency = frequencyParamValues->getChannel(0)->getData()[i] * detuneRatio;
78
70
  auto phaseIncrement = detunedFrequency * periodicWave_->getScale();
79
71
 
80
- float sample =
81
- periodicWave_->getSample(detunedFrequency, phase_, phaseIncrement);
72
+ float sample = periodicWave_->getSample(detunedFrequency, phase_, phaseIncrement);
82
73
 
83
74
  for (int j = 0; j < processingBus->getNumberOfChannels(); j += 1) {
84
75
  (*processingBus->getChannel(j))[i] = sample;
85
76
  }
86
77
 
87
78
  phase_ += phaseIncrement;
88
- phase_ -=
89
- floor(
90
- phase_ / static_cast<float>(periodicWave_->getPeriodicWaveSize())) *
79
+ phase_ -= floor(phase_ / static_cast<float>(periodicWave_->getPeriodicWaveSize())) *
91
80
  static_cast<float>(periodicWave_->getPeriodicWaveSize());
92
81
  }
93
82
 
@@ -1,10 +1,11 @@
1
1
  #pragma once
2
2
 
3
3
  #include <audioapi/core/AudioParam.h>
4
+ #include <audioapi/core/effects/PeriodicWave.h>
4
5
  #include <audioapi/core/sources/AudioScheduledSourceNode.h>
5
6
  #include <audioapi/core/types/OscillatorType.h>
6
- #include <audioapi/core/effects/PeriodicWave.h>
7
7
 
8
+ #include <algorithm>
8
9
  #include <cmath>
9
10
  #include <memory>
10
11
  #include <string>
@@ -24,7 +25,9 @@ class OscillatorNode : public AudioScheduledSourceNode {
24
25
  void setPeriodicWave(const std::shared_ptr<PeriodicWave> &periodicWave);
25
26
 
26
27
  protected:
27
- std::shared_ptr<AudioBus> processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override;
28
+ std::shared_ptr<AudioBus> processNode(
29
+ const std::shared_ptr<AudioBus> &processingBus,
30
+ int framesToProcess) override;
28
31
 
29
32
  private:
30
33
  std::shared_ptr<AudioParam> frequencyParam_;
@@ -35,8 +38,7 @@ class OscillatorNode : public AudioScheduledSourceNode {
35
38
 
36
39
  static OscillatorType fromString(const std::string &type) {
37
40
  std::string lowerType = type;
38
- std::transform(
39
- lowerType.begin(), lowerType.end(), lowerType.begin(), ::tolower);
41
+ std::transform(lowerType.begin(), lowerType.end(), lowerType.begin(), ::tolower);
40
42
 
41
43
  if (lowerType == "sine")
42
44
  return OscillatorType::SINE;
@@ -2,6 +2,7 @@
2
2
  #include <audioapi/core/sources/RecorderAdapterNode.h>
3
3
  #include <audioapi/utils/AudioArray.h>
4
4
  #include <audioapi/utils/AudioBus.h>
5
+ #include <memory>
5
6
  #include <type_traits>
6
7
 
7
8
  namespace audioapi {
@@ -30,8 +31,7 @@ std::shared_ptr<AudioBus> RecorderAdapterNode::processNode(
30
31
  readFrames(outputChannel, framesToProcess);
31
32
 
32
33
  for (int i = 1; i < processingBus->getNumberOfChannels(); i++) {
33
- processingBus->getChannel(i)->copy(
34
- processingBus->getChannel(0), 0, framesToProcess);
34
+ processingBus->getChannel(i)->copy(processingBus->getChannel(0), 0, framesToProcess);
35
35
  }
36
36
 
37
37
  return processingBus;
@@ -42,8 +42,7 @@ void RecorderAdapterNode::readFrames(float *output, const size_t framesToRead) {
42
42
 
43
43
  if (readFrames < framesToRead) {
44
44
  // Fill the rest with silence
45
- std::memset(
46
- output + readFrames, 0, (framesToRead - readFrames) * sizeof(float));
45
+ std::memset(output + readFrames, 0, (framesToRead - readFrames) * sizeof(float));
47
46
  }
48
47
  }
49
48