react-native-audio-api 0.11.0-nightly-9f40b78-20251109 → 0.11.0-nightly-c8d92af-20251111

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 (73) hide show
  1. package/common/cpp/audioapi/AudioAPIModuleInstaller.h +1 -3
  2. package/common/cpp/audioapi/HostObjects/AudioContextHostObject.cpp +6 -2
  3. package/common/cpp/audioapi/HostObjects/OfflineAudioContextHostObject.cpp +3 -1
  4. package/common/cpp/audioapi/HostObjects/sources/AudioBufferBaseSourceNodeHostObject.cpp +19 -0
  5. package/common/cpp/audioapi/HostObjects/sources/AudioBufferBaseSourceNodeHostObject.h +3 -0
  6. package/common/cpp/audioapi/HostObjects/sources/AudioBufferQueueSourceNodeHostObject.cpp +16 -1
  7. package/common/cpp/audioapi/HostObjects/sources/AudioBufferQueueSourceNodeHostObject.h +1 -0
  8. package/common/cpp/audioapi/core/AudioContext.cpp +19 -24
  9. package/common/cpp/audioapi/core/AudioContext.h +2 -2
  10. package/common/cpp/audioapi/core/sources/AudioBufferBaseSourceNode.cpp +16 -0
  11. package/common/cpp/audioapi/core/sources/AudioBufferBaseSourceNode.h +2 -0
  12. package/common/cpp/audioapi/core/sources/AudioBufferQueueSourceNode.cpp +32 -4
  13. package/common/cpp/audioapi/core/sources/AudioBufferQueueSourceNode.h +5 -1
  14. package/common/cpp/audioapi/core/sources/AudioBufferSourceNode.cpp +16 -3
  15. package/common/cpp/audioapi/core/sources/AudioBufferSourceNode.h +6 -5
  16. package/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.cpp +10 -0
  17. package/common/cpp/audioapi/dsp/VectorMath.cpp +15 -15
  18. package/common/cpp/test/src/biquad/BiquadFilterTest.cpp +5 -5
  19. package/ios/audioapi/ios/AudioAPIModule.h +6 -4
  20. package/ios/audioapi/ios/AudioAPIModule.mm +62 -41
  21. package/ios/audioapi/ios/core/IOSAudioPlayer.h +1 -1
  22. package/ios/audioapi/ios/core/IOSAudioPlayer.mm +33 -24
  23. package/ios/audioapi/ios/core/IOSAudioRecorder.h +3 -2
  24. package/ios/audioapi/ios/core/IOSAudioRecorder.mm +6 -4
  25. package/ios/audioapi/ios/core/NativeAudioPlayer.m +18 -9
  26. package/ios/audioapi/ios/core/NativeAudioRecorder.h +2 -1
  27. package/ios/audioapi/ios/core/NativeAudioRecorder.m +45 -27
  28. package/ios/audioapi/ios/core/utils/AudioDecoder.mm +44 -19
  29. package/ios/audioapi/ios/system/AudioEngine.h +4 -2
  30. package/ios/audioapi/ios/system/AudioEngine.mm +22 -8
  31. package/ios/audioapi/ios/system/AudioSessionManager.h +9 -5
  32. package/ios/audioapi/ios/system/AudioSessionManager.mm +51 -21
  33. package/ios/audioapi/ios/system/LockScreenManager.mm +137 -88
  34. package/ios/audioapi/ios/system/NotificationManager.mm +79 -48
  35. package/lib/commonjs/api.js.map +1 -1
  36. package/lib/commonjs/core/AudioBufferBaseSourceNode.js +3 -0
  37. package/lib/commonjs/core/AudioBufferBaseSourceNode.js.map +1 -1
  38. package/lib/commonjs/core/AudioBufferQueueSourceNode.js +5 -2
  39. package/lib/commonjs/core/AudioBufferQueueSourceNode.js.map +1 -1
  40. package/lib/commonjs/core/AudioContext.js +1 -1
  41. package/lib/commonjs/core/AudioContext.js.map +1 -1
  42. package/lib/commonjs/web-core/AudioContext.js +1 -1
  43. package/lib/commonjs/web-core/AudioContext.js.map +1 -1
  44. package/lib/module/api.js.map +1 -1
  45. package/lib/module/core/AudioBufferBaseSourceNode.js +3 -0
  46. package/lib/module/core/AudioBufferBaseSourceNode.js.map +1 -1
  47. package/lib/module/core/AudioBufferQueueSourceNode.js +5 -2
  48. package/lib/module/core/AudioBufferQueueSourceNode.js.map +1 -1
  49. package/lib/module/core/AudioContext.js +1 -1
  50. package/lib/module/core/AudioContext.js.map +1 -1
  51. package/lib/module/web-core/AudioContext.js +1 -1
  52. package/lib/module/web-core/AudioContext.js.map +1 -1
  53. package/lib/typescript/api.d.ts +1 -1
  54. package/lib/typescript/api.d.ts.map +1 -1
  55. package/lib/typescript/core/AudioBufferBaseSourceNode.d.ts +1 -0
  56. package/lib/typescript/core/AudioBufferBaseSourceNode.d.ts.map +1 -1
  57. package/lib/typescript/core/AudioBufferQueueSourceNode.d.ts +1 -1
  58. package/lib/typescript/core/AudioBufferQueueSourceNode.d.ts.map +1 -1
  59. package/lib/typescript/core/AudioContext.d.ts.map +1 -1
  60. package/lib/typescript/interfaces.d.ts +3 -0
  61. package/lib/typescript/interfaces.d.ts.map +1 -1
  62. package/lib/typescript/types.d.ts +0 -1
  63. package/lib/typescript/types.d.ts.map +1 -1
  64. package/lib/typescript/web-core/AudioContext.d.ts +1 -1
  65. package/lib/typescript/web-core/AudioContext.d.ts.map +1 -1
  66. package/package.json +1 -1
  67. package/src/api.ts +0 -1
  68. package/src/core/AudioBufferBaseSourceNode.ts +8 -0
  69. package/src/core/AudioBufferQueueSourceNode.ts +8 -2
  70. package/src/core/AudioContext.ts +0 -1
  71. package/src/interfaces.ts +4 -0
  72. package/src/types.ts +0 -1
  73. package/src/web-core/AudioContext.tsx +1 -1
@@ -96,12 +96,11 @@ class AudioAPIModuleInstaller {
96
96
  size_t count) -> jsi::Value {
97
97
  std::shared_ptr<AudioContext> audioContext;
98
98
  auto sampleRate = static_cast<float>(args[0].getNumber());
99
- auto initSuspended = args[1].getBool();
100
99
 
101
100
  #if RN_AUDIO_API_ENABLE_WORKLETS
102
101
  auto runtimeRegistry = RuntimeRegistry{
103
102
  .uiRuntime = uiRuntime,
104
- .audioRuntime = worklets::extractWorkletRuntime(runtime, args[2])
103
+ .audioRuntime = worklets::extractWorkletRuntime(runtime, args[1])
105
104
  };
106
105
  #else
107
106
  auto runtimeRegistry = RuntimeRegistry{};
@@ -109,7 +108,6 @@ class AudioAPIModuleInstaller {
109
108
 
110
109
  audioContext = std::make_shared<AudioContext>(
111
110
  sampleRate,
112
- initSuspended,
113
111
  audioEventHandlerRegistry,
114
112
  runtimeRegistry);
115
113
  AudioAPIModuleInstaller::contexts_.push_back(audioContext);
@@ -33,7 +33,9 @@ JSI_HOST_FUNCTION_IMPL(AudioContextHostObject, resume) {
33
33
  auto promise = promiseVendor_->createAsyncPromise(
34
34
  [audioContext = std::move(audioContext)]() {
35
35
  auto result = audioContext->resume();
36
- return [result](jsi::Runtime &runtime) { return jsi::Value(result); };
36
+ return [result](jsi::Runtime &runtime) {
37
+ return jsi::Value(result);
38
+ };
37
39
  });
38
40
  return promise;
39
41
  }
@@ -43,7 +45,9 @@ JSI_HOST_FUNCTION_IMPL(AudioContextHostObject, suspend) {
43
45
  auto promise = promiseVendor_->createAsyncPromise(
44
46
  [audioContext = std::move(audioContext)]() {
45
47
  auto result = audioContext->suspend();
46
- return [result](jsi::Runtime &runtime) { return jsi::Value(result); };
48
+ return [result](jsi::Runtime &runtime) {
49
+ return jsi::Value(result);
50
+ };
47
51
  });
48
52
 
49
53
  return promise;
@@ -20,7 +20,9 @@ JSI_HOST_FUNCTION_IMPL(OfflineAudioContextHostObject, resume) {
20
20
  auto audioContext = std::static_pointer_cast<OfflineAudioContext>(context_);
21
21
  auto promise = promiseVendor_->createAsyncPromise([audioContext]() {
22
22
  audioContext->resume();
23
- return [](jsi::Runtime &runtime) { return jsi::Value::undefined(); };
23
+ return [](jsi::Runtime &runtime) {
24
+ return jsi::Value::undefined();
25
+ };
24
26
  });
25
27
 
26
28
  return promise;
@@ -20,6 +20,11 @@ AudioBufferBaseSourceNodeHostObject::AudioBufferBaseSourceNodeHostObject(
20
20
  AudioBufferBaseSourceNodeHostObject, onPositionChanged),
21
21
  JSI_EXPORT_PROPERTY_SETTER(
22
22
  AudioBufferBaseSourceNodeHostObject, onPositionChangedInterval));
23
+
24
+ addFunctions(
25
+ JSI_EXPORT_FUNCTION(AudioBufferBaseSourceNodeHostObject, getInputLatency),
26
+ JSI_EXPORT_FUNCTION(
27
+ AudioBufferBaseSourceNodeHostObject, getOutputLatency));
23
28
  }
24
29
 
25
30
  AudioBufferBaseSourceNodeHostObject::~AudioBufferBaseSourceNodeHostObject() {
@@ -70,4 +75,18 @@ JSI_PROPERTY_SETTER_IMPL(
70
75
  sourceNode->setOnPositionChangedInterval(static_cast<int>(value.getNumber()));
71
76
  }
72
77
 
78
+ JSI_HOST_FUNCTION_IMPL(AudioBufferBaseSourceNodeHostObject, getInputLatency) {
79
+ auto audioBufferBaseSourceNode =
80
+ std::static_pointer_cast<AudioBufferBaseSourceNode>(node_);
81
+
82
+ return audioBufferBaseSourceNode->getInputLatency();
83
+ }
84
+
85
+ JSI_HOST_FUNCTION_IMPL(AudioBufferBaseSourceNodeHostObject, getOutputLatency) {
86
+ auto audioBufferBaseSourceNode =
87
+ std::static_pointer_cast<AudioBufferBaseSourceNode>(node_);
88
+
89
+ return audioBufferBaseSourceNode->getOutputLatency();
90
+ }
91
+
73
92
  } // namespace audioapi
@@ -24,6 +24,9 @@ class AudioBufferBaseSourceNodeHostObject
24
24
 
25
25
  JSI_PROPERTY_SETTER_DECL(onPositionChanged);
26
26
  JSI_PROPERTY_SETTER_DECL(onPositionChangedInterval);
27
+
28
+ JSI_HOST_FUNCTION_DECL(getInputLatency);
29
+ JSI_HOST_FUNCTION_DECL(getOutputLatency);
27
30
  };
28
31
 
29
32
  } // namespace audioapi
@@ -8,13 +8,28 @@ namespace audioapi {
8
8
  AudioBufferQueueSourceNodeHostObject::AudioBufferQueueSourceNodeHostObject(
9
9
  const std::shared_ptr<AudioBufferQueueSourceNode> &node)
10
10
  : AudioBufferBaseSourceNodeHostObject(node) {
11
+ functions_->erase("start");
12
+
11
13
  addFunctions(
14
+ JSI_EXPORT_FUNCTION(AudioBufferQueueSourceNodeHostObject, start),
12
15
  JSI_EXPORT_FUNCTION(AudioBufferQueueSourceNodeHostObject, enqueueBuffer),
13
16
  JSI_EXPORT_FUNCTION(AudioBufferQueueSourceNodeHostObject, dequeueBuffer),
14
17
  JSI_EXPORT_FUNCTION(AudioBufferQueueSourceNodeHostObject, clearBuffers),
15
18
  JSI_EXPORT_FUNCTION(AudioBufferQueueSourceNodeHostObject, pause));
16
19
  }
17
20
 
21
+ JSI_HOST_FUNCTION_IMPL(AudioBufferQueueSourceNodeHostObject, start) {
22
+ auto when = args[0].getNumber();
23
+ auto offset = args[1].getNumber();
24
+
25
+ auto audioBufferQueueSourceNode =
26
+ std::static_pointer_cast<AudioBufferQueueSourceNode>(node_);
27
+
28
+ audioBufferQueueSourceNode->start(when, offset);
29
+
30
+ return jsi::Value::undefined();
31
+ }
32
+
18
33
  JSI_HOST_FUNCTION_IMPL(AudioBufferQueueSourceNodeHostObject, pause) {
19
34
  auto audioBufferQueueSourceNode =
20
35
  std::static_pointer_cast<AudioBufferQueueSourceNode>(node_);
@@ -41,7 +56,7 @@ JSI_HOST_FUNCTION_IMPL(AudioBufferQueueSourceNodeHostObject, dequeueBuffer) {
41
56
  auto audioBufferQueueSourceNode =
42
57
  std::static_pointer_cast<AudioBufferQueueSourceNode>(node_);
43
58
 
44
- auto bufferId = args[0].getNumber();
59
+ auto bufferId = static_cast<size_t>(args[0].getNumber());
45
60
 
46
61
  audioBufferQueueSourceNode->dequeueBuffer(bufferId);
47
62
 
@@ -16,6 +16,7 @@ class AudioBufferQueueSourceNodeHostObject
16
16
  explicit AudioBufferQueueSourceNodeHostObject(
17
17
  const std::shared_ptr<AudioBufferQueueSourceNode> &node);
18
18
 
19
+ JSI_HOST_FUNCTION_DECL(start);
19
20
  JSI_HOST_FUNCTION_DECL(pause);
20
21
  JSI_HOST_FUNCTION_DECL(enqueueBuffer);
21
22
  JSI_HOST_FUNCTION_DECL(dequeueBuffer);
@@ -11,7 +11,6 @@
11
11
  namespace audioapi {
12
12
  AudioContext::AudioContext(
13
13
  float sampleRate,
14
- bool initSuspended,
15
14
  const std::shared_ptr<IAudioEventHandlerRegistry>
16
15
  &audioEventHandlerRegistry,
17
16
  const RuntimeRegistry &runtimeRegistry)
@@ -25,17 +24,8 @@ AudioContext::AudioContext(
25
24
  #endif
26
25
 
27
26
  sampleRate_ = sampleRate;
28
-
29
- if (initSuspended) {
30
- playerHasBeenStarted_ = false;
31
- state_ = ContextState::SUSPENDED;
32
-
33
- return;
34
- }
35
-
36
- playerHasBeenStarted_ = true;
37
- audioPlayer_->start();
38
- state_ = ContextState::RUNNING;
27
+ playerHasBeenStarted_ = false;
28
+ state_ = ContextState::SUSPENDED;
39
29
  }
40
30
 
41
31
  AudioContext::~AudioContext() {
@@ -61,22 +51,12 @@ bool AudioContext::resume() {
61
51
  return true;
62
52
  }
63
53
 
64
- if (!playerHasBeenStarted_) {
65
- if (audioPlayer_->start()) {
66
- playerHasBeenStarted_ = true;
67
- state_ = ContextState::RUNNING;
68
- return true;
69
- }
70
-
71
- return false;
72
- }
73
-
74
- if (audioPlayer_->resume()) {
54
+ if (playerHasBeenStarted_ && audioPlayer_->resume()) {
75
55
  state_ = ContextState::RUNNING;
76
56
  return true;
77
57
  }
78
58
 
79
- return false;
59
+ return start();
80
60
  }
81
61
 
82
62
  bool AudioContext::suspend() {
@@ -94,6 +74,21 @@ bool AudioContext::suspend() {
94
74
  return true;
95
75
  }
96
76
 
77
+ bool AudioContext::start() {
78
+ if (isClosed()) {
79
+ return false;
80
+ }
81
+
82
+ if (!playerHasBeenStarted_ && audioPlayer_->start()) {
83
+ playerHasBeenStarted_ = true;
84
+ state_ = ContextState::RUNNING;
85
+
86
+ return true;
87
+ }
88
+
89
+ return false;
90
+ }
91
+
97
92
  std::function<void(std::shared_ptr<AudioBus>, int)>
98
93
  AudioContext::renderAudio() {
99
94
  return [this](const std::shared_ptr<AudioBus> &data, int frames) {
@@ -15,13 +15,13 @@ class IOSAudioPlayer;
15
15
 
16
16
  class AudioContext : public BaseAudioContext {
17
17
  public:
18
- explicit AudioContext(float sampleRate, bool initSuspended, const std::shared_ptr<IAudioEventHandlerRegistry> &audioEventHandlerRegistry, const RuntimeRegistry &runtimeRegistry);
18
+ explicit AudioContext(float sampleRate, const std::shared_ptr<IAudioEventHandlerRegistry> &audioEventHandlerRegistry, const RuntimeRegistry &runtimeRegistry);
19
19
  ~AudioContext() override;
20
20
 
21
21
  void close();
22
22
  bool resume();
23
23
  bool suspend();
24
-
24
+ bool start();
25
25
 
26
26
  private:
27
27
  #ifdef ANDROID
@@ -60,6 +60,22 @@ std::mutex &AudioBufferBaseSourceNode::getBufferLock() {
60
60
  return bufferLock_;
61
61
  }
62
62
 
63
+ double AudioBufferBaseSourceNode::getInputLatency() const {
64
+ if (pitchCorrection_) {
65
+ return static_cast<double>(stretch_->inputLatency()) /
66
+ context_->getSampleRate();
67
+ }
68
+ return 0;
69
+ }
70
+
71
+ double AudioBufferBaseSourceNode::getOutputLatency() const {
72
+ if (pitchCorrection_) {
73
+ return static_cast<double>(stretch_->outputLatency()) /
74
+ context_->getSampleRate();
75
+ }
76
+ return 0;
77
+ }
78
+
63
79
  void AudioBufferBaseSourceNode::sendOnPositionChangedEvent() {
64
80
  auto onPositionChangedCallbackId =
65
81
  onPositionChangedCallbackId_.load(std::memory_order_acquire);
@@ -22,6 +22,8 @@ class AudioBufferBaseSourceNode : public AudioScheduledSourceNode {
22
22
  void setOnPositionChangedCallbackId(uint64_t callbackId);
23
23
  void setOnPositionChangedInterval(int interval);
24
24
  [[nodiscard]] int getOnPositionChangedInterval() const;
25
+ [[nodiscard]] double getInputLatency() const;
26
+ [[nodiscard]] double getOutputLatency() const;
25
27
 
26
28
  protected:
27
29
  // pitch correction
@@ -17,6 +17,19 @@ AudioBufferQueueSourceNode::AudioBufferQueueSourceNode(
17
17
  buffers_ = {};
18
18
  stretch_->presetDefault(channelCount_, context_->getSampleRate());
19
19
 
20
+ if (pitchCorrection) {
21
+ // If pitch correction is enabled, add extra frames at the end
22
+ // to compensate for processing latency.
23
+ addExtraTailFrames_ = true;
24
+
25
+ int extraTailFrames =
26
+ static_cast<int>(stretch_->inputLatency() + stretch_->outputLatency());
27
+ tailBuffer_ = std::make_shared<AudioBuffer>(
28
+ channelCount_, extraTailFrames, context_->getSampleRate());
29
+
30
+ tailBuffer_->bus_->zero();
31
+ }
32
+
20
33
  isInitialized_ = true;
21
34
  }
22
35
 
@@ -31,10 +44,18 @@ void AudioBufferQueueSourceNode::stop(double when) {
31
44
  isPaused_ = false;
32
45
  }
33
46
 
34
- void AudioBufferQueueSourceNode::start(double when) {
47
+ void AudioBufferQueueSourceNode::start(double when, double offset) {
35
48
  isPaused_ = false;
36
49
  stopTime_ = -1.0;
37
50
  AudioScheduledSourceNode::start(when);
51
+
52
+ if (buffers_.empty()) {
53
+ return;
54
+ }
55
+
56
+ offset = std::min(offset, buffers_.front().second->getDuration());
57
+ vReadIndex_ =
58
+ static_cast<double>(buffers_.front().second->getSampleRate() * offset);
38
59
  }
39
60
 
40
61
  void AudioBufferQueueSourceNode::pause() {
@@ -169,10 +190,17 @@ void AudioBufferQueueSourceNode::processWithoutInterpolation(
169
190
  "ended", onEndedCallbackId_, body);
170
191
 
171
192
  if (buffers_.empty()) {
172
- processingBus->zero(writeIndex, framesLeft);
173
- readIndex = 0;
193
+ if (addExtraTailFrames_) {
194
+ buffers_.emplace(bufferId_, tailBuffer_);
195
+ bufferId_++;
174
196
 
175
- break;
197
+ addExtraTailFrames_ = false;
198
+ } else if (buffers_.empty()) {
199
+ processingBus->zero(writeIndex, framesLeft);
200
+ readIndex = 0;
201
+
202
+ break;
203
+ }
176
204
  }
177
205
 
178
206
  data = buffers_.front();
@@ -21,7 +21,9 @@ class AudioBufferQueueSourceNode : public AudioBufferBaseSourceNode {
21
21
  ~AudioBufferQueueSourceNode() override;
22
22
 
23
23
  void stop(double when) override;
24
- void start(double when) override;
24
+
25
+ using AudioScheduledSourceNode::start;
26
+ void start(double when, double offset);
25
27
  void pause();
26
28
 
27
29
  std::string enqueueBuffer(const std::shared_ptr<AudioBuffer> &buffer);
@@ -39,6 +41,8 @@ class AudioBufferQueueSourceNode : public AudioBufferBaseSourceNode {
39
41
  size_t bufferId_ = 0;
40
42
 
41
43
  bool isPaused_ = false;
44
+ bool addExtraTailFrames_ = false;
45
+ std::shared_ptr<AudioBuffer> tailBuffer_;
42
46
 
43
47
  double playedBuffersDuration_ = 0;
44
48
 
@@ -82,17 +82,30 @@ void AudioBufferSourceNode::setBuffer(
82
82
  }
83
83
 
84
84
  buffer_ = buffer;
85
- alignedBus_ = std::make_shared<AudioBus>(*buffer_->bus_);
86
85
  channelCount_ = buffer_->getNumberOfChannels();
87
86
 
87
+ stretch_->presetDefault(channelCount_, buffer_->getSampleRate());
88
+
89
+ if (pitchCorrection_) {
90
+ int extraTailFrames = static_cast<int>(
91
+ (getInputLatency() + getOutputLatency()) * context_->getSampleRate());
92
+ size_t totalSize = buffer_->getLength() + extraTailFrames;
93
+
94
+ alignedBus_ = std::make_shared<AudioBus>(
95
+ totalSize, channelCount_, buffer_->getSampleRate());
96
+ alignedBus_->copy(buffer_->bus_.get(), 0, 0, buffer_->getLength());
97
+
98
+ alignedBus_->zero(buffer_->getLength(), extraTailFrames);
99
+ } else {
100
+ alignedBus_ = std::make_shared<AudioBus>(*buffer_->bus_);
101
+ }
102
+
88
103
  audioBus_ = std::make_shared<AudioBus>(
89
104
  RENDER_QUANTUM_SIZE, channelCount_, context_->getSampleRate());
90
105
  playbackRateBus_ = std::make_shared<AudioBus>(
91
106
  RENDER_QUANTUM_SIZE * 3, channelCount_, context_->getSampleRate());
92
107
 
93
108
  loopEnd_ = buffer_->getDuration();
94
-
95
- stretch_->presetDefault(channelCount_, buffer_->getSampleRate());
96
109
  }
97
110
 
98
111
  void AudioBufferSourceNode::start(double when, double offset, double duration) {
@@ -4,9 +4,9 @@
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>
8
+ #include <cstddef>
9
+ #include <memory>
10
10
  #include <string>
11
11
 
12
12
  namespace audioapi {
@@ -31,13 +31,14 @@ class AudioBufferSourceNode : public AudioBufferBaseSourceNode {
31
31
  void setLoopEnd(double loopEnd);
32
32
  void setBuffer(const std::shared_ptr<AudioBuffer> &buffer);
33
33
 
34
+ using AudioScheduledSourceNode::start;
34
35
  void start(double when, double offset, double duration = -1);
35
36
  void disable() override;
36
37
 
37
38
  void setOnLoopEndedCallbackId(uint64_t callbackId);
38
39
 
39
40
  protected:
40
- std::shared_ptr<AudioBus> processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override;
41
+ std::shared_ptr<AudioBus> processNode(const std::shared_ptr<AudioBus> &processingBus, int framesToProcess) override;
41
42
  double getCurrentPosition() const override;
42
43
 
43
44
  private:
@@ -55,13 +56,13 @@ class AudioBufferSourceNode : public AudioBufferBaseSourceNode {
55
56
  void sendOnLoopEndedEvent();
56
57
 
57
58
  void processWithoutInterpolation(
58
- const std::shared_ptr<AudioBus>& processingBus,
59
+ const std::shared_ptr<AudioBus> &processingBus,
59
60
  size_t startOffset,
60
61
  size_t offsetLength,
61
62
  float playbackRate) override;
62
63
 
63
64
  void processWithInterpolation(
64
- const std::shared_ptr<AudioBus>& processingBus,
65
+ const std::shared_ptr<AudioBus> &processingBus,
65
66
  size_t startOffset,
66
67
  size_t offsetLength,
67
68
  float playbackRate) override;
@@ -6,6 +6,10 @@
6
6
  #include <audioapi/utils/AudioArray.h>
7
7
  #include <audioapi/utils/AudioBus.h>
8
8
 
9
+ #if !RN_AUDIO_API_TEST
10
+ #include <audioapi/core/AudioContext.h>
11
+ #endif
12
+
9
13
  namespace audioapi {
10
14
 
11
15
  AudioScheduledSourceNode::AudioScheduledSourceNode(BaseAudioContext *context)
@@ -18,6 +22,12 @@ AudioScheduledSourceNode::AudioScheduledSourceNode(BaseAudioContext *context)
18
22
  }
19
23
 
20
24
  void AudioScheduledSourceNode::start(double when) {
25
+ #if !RN_AUDIO_API_TEST
26
+ if (auto context = dynamic_cast<AudioContext *>(context_)) {
27
+ context->start();
28
+ }
29
+ #endif
30
+
21
31
  playbackState_ = PlaybackState::SCHEDULED;
22
32
  startTime_ = when;
23
33
  }
@@ -508,15 +508,15 @@ void multiply(
508
508
  bool source2Aligned = is16ByteAligned(inputVector2);
509
509
  bool destAligned = is16ByteAligned(outputVector);
510
510
 
511
- #define SSE2_MULT(loadInstr, storeInstr) \
512
- while (outputVector < endP) { \
513
- pSource1 = _mm_load_ps(inputVector1); \
511
+ #define SSE2_MULT(loadInstr, storeInstr) \
512
+ while (outputVector < endP) { \
513
+ pSource1 = _mm_load_ps(inputVector1); \
514
514
  pSource2 = _mm_##loadInstr##_ps(inputVector2); \
515
- dest = _mm_mul_ps(pSource1, pSource2); \
516
- _mm_##storeInstr##_ps(outputVector, dest); \
517
- inputVector1 += 4; \
518
- inputVector2 += 4; \
519
- outputVector += 4; \
515
+ dest = _mm_mul_ps(pSource1, pSource2); \
516
+ _mm_##storeInstr##_ps(outputVector, dest); \
517
+ inputVector1 += 4; \
518
+ inputVector2 += 4; \
519
+ outputVector += 4; \
520
520
  }
521
521
 
522
522
  if (source2Aligned && destAligned) // Both aligned.
@@ -647,15 +647,15 @@ void multiplyByScalarThenAddToOutput(
647
647
 
648
648
  bool destAligned = is16ByteAligned(outputVector);
649
649
 
650
- #define SSE2_MULT_ADD(loadInstr, storeInstr) \
651
- while (outputVector < endP) { \
652
- pSource = _mm_load_ps(inputVector); \
653
- temp = _mm_mul_ps(pSource, mScale); \
650
+ #define SSE2_MULT_ADD(loadInstr, storeInstr) \
651
+ while (outputVector < endP) { \
652
+ pSource = _mm_load_ps(inputVector); \
653
+ temp = _mm_mul_ps(pSource, mScale); \
654
654
  dest = _mm_##loadInstr##_ps(outputVector); \
655
- dest = _mm_add_ps(dest, temp); \
655
+ dest = _mm_add_ps(dest, temp); \
656
656
  _mm_##storeInstr##_ps(outputVector, dest); \
657
- inputVector += 4; \
658
- outputVector += 4; \
657
+ inputVector += 4; \
658
+ outputVector += 4; \
659
659
  }
660
660
 
661
661
  if (destAligned)
@@ -89,18 +89,18 @@ INSTANTIATE_TEST_SUITE_P(
89
89
  Frequencies,
90
90
  BiquadFilterFrequencyTest,
91
91
  ::testing::Values(
92
- 0.0f, // 0 Hz - the filter should block all input signal
93
- 10.0f, // very low frequency
92
+ 0.0f, // 0 Hz - the filter should block all input signal
93
+ 10.0f, // very low frequency
94
94
  350.0f, // default
95
95
  nyquistFrequency - 0.0001f, // frequency near Nyquist
96
- nyquistFrequency)); // maximal frequency
96
+ nyquistFrequency)); // maximal frequency
97
97
 
98
98
  INSTANTIATE_TEST_SUITE_P(
99
99
  QEdgeCases,
100
100
  BiquadFilterQTestLowpassHighpass,
101
101
  ::testing::Values(
102
- -770.63678f, // min value for lowpass and highpass
103
- 0.0f, // default
102
+ -770.63678f, // min value for lowpass and highpass
103
+ 0.0f, // default
104
104
  770.63678f)); // max value for lowpass and highpass
105
105
 
106
106
  INSTANTIATE_TEST_SUITE_P(
@@ -13,11 +13,12 @@
13
13
  @class AudioSessionManager;
14
14
  @class LockScreenManager;
15
15
 
16
- @interface AudioAPIModule : RCTEventEmitter
16
+ @interface AudioAPIModule
17
+ : RCTEventEmitter
17
18
  #ifdef RCT_NEW_ARCH_ENABLED
18
- <NativeAudioAPIModuleSpec, RCTCallInvokerModule, RCTInvalidating>
19
+ <NativeAudioAPIModuleSpec, RCTCallInvokerModule, RCTInvalidating>
19
20
  #else
20
- <RCTBridgeModule>
21
+ <RCTBridgeModule>
21
22
  #endif // RCT_NEW_ARCH_ENABLED
22
23
 
23
24
  @property (nonatomic, strong) AudioEngine *audioEngine;
@@ -25,6 +26,7 @@
25
26
  @property (nonatomic, strong) AudioSessionManager *audioSessionManager;
26
27
  @property (nonatomic, strong) LockScreenManager *lockScreenManager;
27
28
 
28
- - (void)invokeHandlerWithEventName:(NSString *)eventName eventBody:(NSDictionary *)eventBody;
29
+ - (void)invokeHandlerWithEventName:(NSString *)eventName
30
+ eventBody:(NSDictionary *)eventBody;
29
31
 
30
32
  @end