react-native-audio-api 0.2.0 → 0.3.0-rc2

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 (84) hide show
  1. package/android/CMakeLists.txt +2 -2
  2. package/android/build.gradle +1 -3
  3. package/android/libs/include/miniaudio.h +92621 -0
  4. package/android/src/main/cpp/AudioAPIInstaller/AudioAPIInstaller.cpp +8 -4
  5. package/android/src/main/cpp/AudioAPIInstaller/AudioAPIInstaller.h +16 -7
  6. package/android/src/main/cpp/AudioDecoder/AudioDecoder.cpp +64 -0
  7. package/android/src/main/cpp/AudioDecoder/AudioDecoder.h +21 -0
  8. package/android/src/main/cpp/AudioPlayer/AudioPlayer.cpp +16 -7
  9. package/android/src/main/cpp/AudioPlayer/AudioPlayer.h +5 -4
  10. package/android/src/main/java/com/swmansion/audioapi/module/AudioAPIInstaller.kt +14 -4
  11. package/android/src/main/java/com/swmansion/audioapi/nativemodules/AudioAPIModule.kt +2 -3
  12. package/common/cpp/AudioAPIInstaller/AudioAPIInstallerHostObject.cpp +9 -3
  13. package/common/cpp/AudioAPIInstaller/AudioAPIInstallerHostObject.h +13 -7
  14. package/common/cpp/HostObjects/AudioBufferHostObject.cpp +7 -0
  15. package/common/cpp/HostObjects/AudioContextHostObject.cpp +3 -2
  16. package/common/cpp/HostObjects/AudioContextHostObject.h +6 -3
  17. package/common/cpp/HostObjects/BaseAudioContextHostObject.cpp +38 -2
  18. package/common/cpp/HostObjects/BaseAudioContextHostObject.h +4 -1
  19. package/common/cpp/core/AudioArray.cpp +28 -14
  20. package/common/cpp/core/AudioArray.h +20 -14
  21. package/common/cpp/core/AudioBuffer.cpp +14 -11
  22. package/common/cpp/core/AudioBuffer.h +1 -0
  23. package/common/cpp/core/AudioBufferSourceNode.cpp +29 -19
  24. package/common/cpp/core/AudioBufferSourceNode.h +1 -1
  25. package/common/cpp/core/AudioBus.cpp +276 -115
  26. package/common/cpp/core/AudioBus.h +29 -9
  27. package/common/cpp/core/AudioContext.cpp +5 -9
  28. package/common/cpp/core/AudioDestinationNode.cpp +11 -8
  29. package/common/cpp/core/AudioDestinationNode.h +4 -4
  30. package/common/cpp/core/AudioNode.cpp +25 -17
  31. package/common/cpp/core/AudioNode.h +5 -5
  32. package/common/cpp/core/AudioNodeManager.cpp +10 -7
  33. package/common/cpp/core/AudioNodeManager.h +11 -4
  34. package/common/cpp/core/AudioScheduledSourceNode.cpp +2 -2
  35. package/common/cpp/core/BaseAudioContext.cpp +49 -12
  36. package/common/cpp/core/BaseAudioContext.h +16 -7
  37. package/common/cpp/core/BiquadFilterNode.cpp +5 -3
  38. package/common/cpp/core/GainNode.cpp +1 -1
  39. package/common/cpp/core/OscillatorNode.cpp +4 -4
  40. package/common/cpp/core/OscillatorNode.h +2 -2
  41. package/common/cpp/core/StereoPannerNode.cpp +10 -7
  42. package/common/cpp/core/StereoPannerNode.h +1 -1
  43. package/common/cpp/utils/FFTFrame.h +5 -1
  44. package/common/cpp/utils/JsiPromise.cpp +64 -0
  45. package/common/cpp/utils/JsiPromise.h +48 -0
  46. package/common/cpp/utils/Locker.h +8 -6
  47. package/common/cpp/utils/VectorMath.cpp +71 -55
  48. package/common/cpp/utils/android/FFTFrame.cpp +12 -11
  49. package/common/cpp/utils/ios/FFTFrame.cpp +6 -1
  50. package/common/cpp/wrappers/BaseAudioContextWrapper.cpp +7 -0
  51. package/common/cpp/wrappers/BaseAudioContextWrapper.h +2 -0
  52. package/ios/AudioAPIModule.mm +4 -1
  53. package/ios/AudioDecoder/AudioDecoder.h +17 -0
  54. package/ios/AudioDecoder/AudioDecoder.m +80 -0
  55. package/ios/AudioDecoder/IOSAudioDecoder.h +28 -0
  56. package/ios/AudioDecoder/IOSAudioDecoder.mm +46 -0
  57. package/ios/AudioPlayer/AudioPlayer.h +1 -1
  58. package/ios/AudioPlayer/AudioPlayer.m +2 -2
  59. package/ios/AudioPlayer/IOSAudioPlayer.h +5 -5
  60. package/ios/AudioPlayer/IOSAudioPlayer.mm +4 -3
  61. package/lib/module/core/BaseAudioContext.js +4 -0
  62. package/lib/module/core/BaseAudioContext.js.map +1 -1
  63. package/lib/module/index.js +232 -17
  64. package/lib/module/index.js.map +1 -1
  65. package/lib/module/index.native.js +18 -0
  66. package/lib/module/index.native.js.map +1 -0
  67. package/lib/typescript/core/BaseAudioContext.d.ts +1 -0
  68. package/lib/typescript/core/BaseAudioContext.d.ts.map +1 -1
  69. package/lib/typescript/index.d.ts +100 -13
  70. package/lib/typescript/index.d.ts.map +1 -1
  71. package/lib/typescript/index.native.d.ts +14 -0
  72. package/lib/typescript/index.native.d.ts.map +1 -0
  73. package/lib/typescript/interfaces.d.ts +1 -0
  74. package/lib/typescript/interfaces.d.ts.map +1 -1
  75. package/package.json +4 -2
  76. package/src/core/BaseAudioContext.ts +6 -0
  77. package/src/index.native.ts +25 -0
  78. package/src/index.ts +403 -19
  79. package/src/interfaces.ts +1 -0
  80. package/android/libs/fftw3/x86/libfftw3.a +0 -0
  81. package/android/libs/fftw3/x86_64/libfftw3.a +0 -0
  82. /package/android/libs/{fftw3/arm64-v8a → arm64-v8a}/libfftw3.a +0 -0
  83. /package/android/libs/{fftw3/armeabi-v7a → armeabi-v7a}/libfftw3.a +0 -0
  84. /package/android/libs/include/{fftw3/fftw3.h → fftw3.h} +0 -0
@@ -1,6 +1,6 @@
1
- #include "AudioBus.h"
2
- #include "AudioArray.h"
3
1
  #include "AudioBuffer.h"
2
+ #include "AudioArray.h"
3
+ #include "AudioBus.h"
4
4
 
5
5
  namespace audioapi {
6
6
 
@@ -8,6 +8,10 @@ AudioBuffer::AudioBuffer(int numberOfChannels, int length, int sampleRate) {
8
8
  bus_ = std::make_shared<AudioBus>(sampleRate, length, numberOfChannels);
9
9
  }
10
10
 
11
+ AudioBuffer::AudioBuffer(AudioBus *bus) {
12
+ bus_ = std::shared_ptr<AudioBus>(bus);
13
+ }
14
+
11
15
  int AudioBuffer::getLength() const {
12
16
  return bus_->getSize();
13
17
  }
@@ -24,7 +28,7 @@ double AudioBuffer::getDuration() const {
24
28
  return static_cast<double>(getLength()) / getSampleRate();
25
29
  }
26
30
 
27
- float* AudioBuffer::getChannelData(int channel) const {
31
+ float *AudioBuffer::getChannelData(int channel) const {
28
32
  return bus_->getChannel(channel)->getData();
29
33
  }
30
34
 
@@ -34,10 +38,10 @@ void AudioBuffer::copyFromChannel(
34
38
  int channelNumber,
35
39
  int startInChannel) const {
36
40
  memcpy(
37
- destination,
38
- bus_->getChannel(channelNumber)->getData() + startInChannel,
39
- std::min(destinationLength, getLength() - startInChannel) * sizeof(float)
40
- );
41
+ destination,
42
+ bus_->getChannel(channelNumber)->getData() + startInChannel,
43
+ std::min(destinationLength, getLength() - startInChannel) *
44
+ sizeof(float));
41
45
  }
42
46
 
43
47
  void AudioBuffer::copyToChannel(
@@ -46,10 +50,9 @@ void AudioBuffer::copyToChannel(
46
50
  int channelNumber,
47
51
  int startInChannel) {
48
52
  memcpy(
49
- bus_->getChannel(channelNumber)->getData() + startInChannel,
50
- source,
51
- std::min(sourceLength, getLength() - startInChannel) * sizeof(float)
52
- );
53
+ bus_->getChannel(channelNumber)->getData() + startInChannel,
54
+ source,
55
+ std::min(sourceLength, getLength() - startInChannel) * sizeof(float));
53
56
  }
54
57
 
55
58
  } // namespace audioapi
@@ -12,6 +12,7 @@ class AudioBus;
12
12
  class AudioBuffer : public std::enable_shared_from_this<AudioBuffer> {
13
13
  public:
14
14
  explicit AudioBuffer(int numberOfChannels, int length, int sampleRate);
15
+ explicit AudioBuffer(AudioBus *bus);
15
16
 
16
17
  [[nodiscard]] int getLength() const;
17
18
  [[nodiscard]] int getSampleRate() const;
@@ -1,9 +1,9 @@
1
1
  #include <algorithm>
2
2
 
3
- #include "AudioBus.h"
4
3
  #include "AudioArray.h"
5
- #include "BaseAudioContext.h"
6
4
  #include "AudioBufferSourceNode.h"
5
+ #include "AudioBus.h"
6
+ #include "BaseAudioContext.h"
7
7
 
8
8
  namespace audioapi {
9
9
 
@@ -28,7 +28,6 @@ void AudioBufferSourceNode::setLoop(bool loop) {
28
28
 
29
29
  void AudioBufferSourceNode::setBuffer(
30
30
  const std::shared_ptr<AudioBuffer> &buffer) {
31
-
32
31
  if (!buffer) {
33
32
  buffer_ = std::shared_ptr<AudioBuffer>(nullptr);
34
33
  return;
@@ -37,16 +36,20 @@ void AudioBufferSourceNode::setBuffer(
37
36
  buffer_ = buffer;
38
37
  }
39
38
 
40
- // Note: AudioBus copy method will use memcpy if the source buffer and system processing bus have same channel count,
41
- // otherwise it will use the summing function taking care of up/down mixing.
42
- void AudioBufferSourceNode::processNode(AudioBus* processingBus, int framesToProcess) {
39
+ // Note: AudioBus copy method will use memcpy if the source buffer and system
40
+ // processing bus have same channel count, otherwise it will use the summing
41
+ // function taking care of up/down mixing.
42
+ void AudioBufferSourceNode::processNode(
43
+ AudioBus *processingBus,
44
+ int framesToProcess) {
43
45
  // No audio data to fill, zero the output and return.
44
46
  if (!isPlaying() || !buffer_ || buffer_->getLength() == 0) {
45
47
  processingBus->zero();
46
48
  return;
47
49
  }
48
50
 
49
- // Easiest case, the buffer is the same length as the number of frames to process, just copy the data.
51
+ // Easiest case, the buffer is the same length as the number of frames to
52
+ // process, just copy the data.
50
53
  if (framesToProcess == buffer_->getLength()) {
51
54
  processingBus->copy(buffer_->bus_.get());
52
55
 
@@ -65,9 +68,12 @@ void AudioBufferSourceNode::processNode(AudioBus* processingBus, int framesToPro
65
68
  int framesToCopy = 0;
66
69
 
67
70
  while (framesToProcess - outputBusIndex > 0) {
68
- framesToCopy = std::min(framesToProcess - outputBusIndex, buffer_->getLength() - bufferIndex_);
71
+ framesToCopy = std::min(
72
+ framesToProcess - outputBusIndex,
73
+ buffer_->getLength() - bufferIndex_);
69
74
 
70
- processingBus->copy(buffer_->bus_.get(), bufferIndex_, outputBusIndex, framesToCopy);
75
+ processingBus->copy(
76
+ buffer_->bus_.get(), bufferIndex_, outputBusIndex, framesToCopy);
71
77
 
72
78
  bufferIndex_ += framesToCopy;
73
79
  outputBusIndex += framesToCopy;
@@ -76,12 +82,11 @@ void AudioBufferSourceNode::processNode(AudioBus* processingBus, int framesToPro
76
82
  continue;
77
83
  }
78
84
 
79
-
80
85
  bufferIndex_ %= buffer_->getLength();
81
86
 
82
87
  if (!loop_) {
83
- playbackState_ = PlaybackState::FINISHED;
84
- disable();
88
+ playbackState_ = PlaybackState::FINISHED;
89
+ disable();
85
90
 
86
91
  if (framesToProcess - outputBusIndex > 0) {
87
92
  processingBus->zero(outputBusIndex, framesToProcess - outputBusIndex);
@@ -94,9 +99,11 @@ void AudioBufferSourceNode::processNode(AudioBus* processingBus, int framesToPro
94
99
 
95
100
  // processing bus is longer than the source buffer
96
101
  if (!loop_) {
97
- // If we don't loop the buffer, copy it once and zero the remaining processing bus frames.
102
+ // If we don't loop the buffer, copy it once and zero the remaining
103
+ // processing bus frames.
98
104
  processingBus->copy(buffer_->bus_.get());
99
- processingBus->zero(buffer_->getLength(), framesToProcess - buffer_->getLength());
105
+ processingBus->zero(
106
+ buffer_->getLength(), framesToProcess - buffer_->getLength());
100
107
 
101
108
  playbackState_ = PlaybackState::FINISHED;
102
109
  disable();
@@ -104,9 +111,10 @@ void AudioBufferSourceNode::processNode(AudioBus* processingBus, int framesToPro
104
111
  return;
105
112
  }
106
113
 
107
- // If we loop the buffer, we need to loop the buffer framesToProcess / bufferSize times
108
- // There might also be a remainder of frames to copy after the loop,
109
- // which will also carry over some buffer frames to the next render quantum.
114
+ // If we loop the buffer, we need to loop the buffer framesToProcess /
115
+ // bufferSize times There might also be a remainder of frames to copy after
116
+ // the loop, which will also carry over some buffer frames to the next render
117
+ // quantum.
110
118
  int processingBusPosition = 0;
111
119
  int bufferSize = buffer_->getLength();
112
120
  int remainingFrames = framesToProcess - framesToProcess / bufferSize;
@@ -125,9 +133,11 @@ void AudioBufferSourceNode::processNode(AudioBus* processingBus, int framesToPro
125
133
  processingBusPosition += bufferSize;
126
134
  }
127
135
 
128
- // Fill in the remaining frames from the processing buffer and update buffer index for next render quantum.
136
+ // Fill in the remaining frames from the processing buffer and update buffer
137
+ // index for next render quantum.
129
138
  if (remainingFrames > 0) {
130
- processingBus->copy(buffer_->bus_.get(), 0, processingBusPosition, remainingFrames);
139
+ processingBus->copy(
140
+ buffer_->bus_.get(), 0, processingBusPosition, remainingFrames);
131
141
  bufferIndex_ = remainingFrames;
132
142
  }
133
143
  }
@@ -19,7 +19,7 @@ class AudioBufferSourceNode : public AudioScheduledSourceNode {
19
19
  void setBuffer(const std::shared_ptr<AudioBuffer> &buffer);
20
20
 
21
21
  protected:
22
- void processNode(AudioBus* processingBus, int framesToProcess) override;
22
+ void processNode(AudioBus *processingBus, int framesToProcess) override;
23
23
 
24
24
  private:
25
25
  bool loop_;