react-native-audio-api 0.4.11 → 0.4.12-beta.2

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 (128) hide show
  1. package/RNAudioAPI.podspec +11 -1
  2. package/android/CMakeLists.txt +9 -48
  3. package/android/src/main/cpp/audioapi/CMakeLists.txt +44 -0
  4. package/android/src/main/cpp/{AudioAPIModule.cpp → audioapi/android/AudioAPIModule.cpp} +1 -4
  5. package/android/src/main/cpp/{AudioAPIModule.h → audioapi/android/AudioAPIModule.h} +2 -1
  6. package/android/src/main/cpp/{OnLoad.cpp → audioapi/android/OnLoad.cpp} +2 -1
  7. package/android/src/main/cpp/{core → audioapi/android/core}/AudioDecoder.cpp +5 -5
  8. package/android/src/main/cpp/{core → audioapi/android/core}/AudioPlayer.cpp +5 -7
  9. package/android/src/main/cpp/{core → audioapi/android/core}/AudioPlayer.h +1 -0
  10. package/android/src/main/cpp/{libs → audioapi/android/libs}/pffft.c +2 -2
  11. package/android/src/main/java/com/swmansion/audioapi/AudioAPIPackage.kt +1 -0
  12. package/common/cpp/{installer → audioapi}/AudioAPIModuleInstaller.h +9 -7
  13. package/common/cpp/{HostObjects → audioapi/HostObjects}/AnalyserNodeHostObject.h +3 -3
  14. package/common/cpp/{HostObjects → audioapi/HostObjects}/AudioBufferHostObject.h +3 -3
  15. package/common/cpp/{HostObjects → audioapi/HostObjects}/AudioBufferSourceNodeHostObject.h +6 -7
  16. package/common/cpp/{HostObjects → audioapi/HostObjects}/AudioContextHostObject.h +3 -3
  17. package/common/cpp/{HostObjects → audioapi/HostObjects}/AudioDestinationNodeHostObject.h +3 -3
  18. package/common/cpp/{HostObjects → audioapi/HostObjects}/AudioNodeHostObject.h +3 -3
  19. package/common/cpp/{HostObjects → audioapi/HostObjects}/AudioParamHostObject.h +3 -3
  20. package/common/cpp/{HostObjects → audioapi/HostObjects}/AudioScheduledSourceNodeHostObject.h +3 -3
  21. package/common/cpp/{HostObjects → audioapi/HostObjects}/BaseAudioContextHostObject.h +21 -14
  22. package/common/cpp/{HostObjects → audioapi/HostObjects}/BiquadFilterNodeHostObject.h +4 -4
  23. package/common/cpp/{HostObjects → audioapi/HostObjects}/GainNodeHostObject.h +6 -6
  24. package/common/cpp/{HostObjects → audioapi/HostObjects}/OscillatorNodeHostObject.h +5 -5
  25. package/common/cpp/{HostObjects → audioapi/HostObjects}/PeriodicWaveHostObject.h +2 -2
  26. package/common/cpp/{HostObjects → audioapi/HostObjects}/StereoPannerNodeHostObject.h +4 -4
  27. package/common/cpp/audioapi/HostObjects/StretcherNodeHostObject.h +35 -0
  28. package/common/cpp/{core → audioapi/core}/AudioContext.cpp +6 -6
  29. package/common/cpp/{core → audioapi/core}/AudioContext.h +2 -2
  30. package/common/cpp/{core → audioapi/core}/AudioNode.cpp +14 -12
  31. package/common/cpp/{core → audioapi/core}/AudioNode.h +9 -6
  32. package/common/cpp/{core → audioapi/core}/AudioParam.cpp +3 -4
  33. package/common/cpp/{core → audioapi/core}/AudioParam.h +3 -3
  34. package/common/cpp/{core → audioapi/core}/BaseAudioContext.cpp +20 -16
  35. package/common/cpp/{core → audioapi/core}/BaseAudioContext.h +6 -3
  36. package/common/cpp/{core → audioapi/core/analysis}/AnalyserNode.cpp +6 -10
  37. package/common/cpp/{core → audioapi/core/analysis}/AnalyserNode.h +4 -3
  38. package/common/cpp/{core → audioapi/core/destinations}/AudioDestinationNode.cpp +6 -6
  39. package/common/cpp/{core → audioapi/core/destinations}/AudioDestinationNode.h +2 -2
  40. package/common/cpp/{core → audioapi/core/effects}/BiquadFilterNode.cpp +4 -4
  41. package/common/cpp/{core → audioapi/core/effects}/BiquadFilterNode.h +4 -4
  42. package/common/cpp/{core → audioapi/core/effects}/GainNode.cpp +4 -4
  43. package/common/cpp/{core → audioapi/core/effects}/GainNode.h +3 -3
  44. package/common/cpp/{core → audioapi/core/effects}/PeriodicWave.cpp +4 -2
  45. package/common/cpp/{core → audioapi/core/effects}/PeriodicWave.h +2 -4
  46. package/common/cpp/{core → audioapi/core/effects}/StereoPannerNode.cpp +5 -7
  47. package/common/cpp/{core → audioapi/core/effects}/StereoPannerNode.h +4 -3
  48. package/common/cpp/audioapi/core/effects/StretcherNode.cpp +94 -0
  49. package/common/cpp/audioapi/core/effects/StretcherNode.h +35 -0
  50. package/common/cpp/{core → audioapi/core/sources}/AudioBuffer.cpp +3 -3
  51. package/common/cpp/{core → audioapi/core/sources}/AudioBufferSourceNode.cpp +8 -11
  52. package/common/cpp/{core → audioapi/core/sources}/AudioBufferSourceNode.h +5 -3
  53. package/common/cpp/{core → audioapi/core/sources}/AudioScheduledSourceNode.cpp +6 -8
  54. package/common/cpp/{core → audioapi/core/sources}/AudioScheduledSourceNode.h +3 -2
  55. package/common/cpp/{core → audioapi/core/sources}/OscillatorNode.cpp +4 -4
  56. package/common/cpp/{core → audioapi/core/sources}/OscillatorNode.h +5 -5
  57. package/common/cpp/{core → audioapi/core/utils}/AudioArray.cpp +2 -4
  58. package/common/cpp/{core → audioapi/core/utils}/AudioBus.cpp +12 -7
  59. package/common/cpp/{core → audioapi/core/utils}/AudioBus.h +5 -2
  60. package/common/cpp/{core → audioapi/core/utils}/AudioNodeManager.cpp +3 -4
  61. package/common/cpp/{core → audioapi/core/utils}/ParamChangeEvent.cpp +1 -3
  62. package/common/cpp/{core → audioapi/core/utils}/ParamChangeEvent.h +3 -1
  63. package/common/cpp/{utils → audioapi/dsp}/AudioUtils.cpp +1 -1
  64. package/common/cpp/{utils → audioapi/dsp}/FFTFrame.cpp +1 -10
  65. package/common/cpp/{utils → audioapi/dsp}/FFTFrame.h +4 -3
  66. package/common/cpp/{utils → audioapi/dsp}/VectorMath.cpp +2 -5
  67. package/common/cpp/{utils → audioapi/dsp}/VectorMath.h +2 -0
  68. package/common/cpp/{jsi → audioapi/jsi}/JsiHostObject.cpp +1 -1
  69. package/common/cpp/{jsi → audioapi/jsi}/JsiHostObject.h +2 -2
  70. package/common/cpp/{jsi → audioapi/jsi}/JsiPromise.cpp +2 -6
  71. package/common/cpp/{jsi → audioapi/jsi}/RuntimeAwareCache.h +2 -3
  72. package/common/cpp/{jsi → audioapi/jsi}/RuntimeLifecycleMonitor.cpp +1 -5
  73. package/common/cpp/{jsi → audioapi/jsi}/RuntimeLifecycleMonitor.h +3 -0
  74. package/common/cpp/audioapi/libs/dsp/common.h +47 -0
  75. package/common/cpp/audioapi/libs/dsp/delay.h +717 -0
  76. package/common/cpp/audioapi/libs/dsp/fft.h +523 -0
  77. package/common/cpp/audioapi/libs/dsp/perf.h +84 -0
  78. package/common/cpp/audioapi/libs/dsp/spectral.h +496 -0
  79. package/common/cpp/audioapi/libs/dsp/windows.h +219 -0
  80. package/common/cpp/audioapi/libs/signalsmith-stretch.h +637 -0
  81. package/ios/{AudioAPIModule.mm → audioapi/ios/AudioAPIModule.mm} +1 -1
  82. package/ios/{core → audioapi/ios/core}/AudioDecoder.mm +4 -4
  83. package/ios/{core → audioapi/ios/core}/AudioPlayer.m +3 -3
  84. package/ios/{core → audioapi/ios/core}/IOSAudioPlayer.mm +4 -4
  85. package/lib/module/core/BaseAudioContext.js +4 -0
  86. package/lib/module/core/BaseAudioContext.js.map +1 -1
  87. package/lib/module/core/StretcherNode.js +12 -0
  88. package/lib/module/core/StretcherNode.js.map +1 -0
  89. package/lib/module/index.js +1 -0
  90. package/lib/module/index.js.map +1 -1
  91. package/lib/module/index.web.js +1 -1
  92. package/lib/module/index.web.js.map +1 -1
  93. package/lib/typescript/core/BaseAudioContext.d.ts +2 -0
  94. package/lib/typescript/core/BaseAudioContext.d.ts.map +1 -1
  95. package/lib/typescript/core/StretcherNode.d.ts +10 -0
  96. package/lib/typescript/core/StretcherNode.d.ts.map +1 -0
  97. package/lib/typescript/index.d.ts +1 -0
  98. package/lib/typescript/index.d.ts.map +1 -1
  99. package/lib/typescript/index.web.d.ts +1 -1
  100. package/lib/typescript/index.web.d.ts.map +1 -1
  101. package/lib/typescript/interfaces.d.ts +5 -0
  102. package/lib/typescript/interfaces.d.ts.map +1 -1
  103. package/package.json +6 -6
  104. package/src/core/BaseAudioContext.ts +5 -0
  105. package/src/core/StretcherNode.ts +15 -0
  106. package/src/index.ts +1 -0
  107. package/src/index.web.ts +1 -0
  108. package/src/interfaces.ts +6 -0
  109. package/common/cpp/installer/AudioAPIModuleInstaller.cpp +0 -49
  110. /package/android/src/main/cpp/{libs → audioapi/android/libs}/pffft.h +0 -0
  111. /package/common/cpp/{core → audioapi/core}/Constants.h +0 -0
  112. /package/common/cpp/{core → audioapi/core/sources}/AudioBuffer.h +0 -0
  113. /package/common/cpp/{types → audioapi/core/types}/BiquadFilterType.h +0 -0
  114. /package/common/cpp/{types → audioapi/core/types}/ChannelCountMode.h +0 -0
  115. /package/common/cpp/{types → audioapi/core/types}/ChannelInterpretation.h +0 -0
  116. /package/common/cpp/{types → audioapi/core/types}/ContextState.h +0 -0
  117. /package/common/cpp/{types → audioapi/core/types}/OscillatorType.h +0 -0
  118. /package/common/cpp/{types → audioapi/core/types}/ParamChangeEventType.h +0 -0
  119. /package/common/cpp/{core → audioapi/core/utils}/AudioArray.h +0 -0
  120. /package/common/cpp/{core → audioapi/core/utils}/AudioDecoder.h +0 -0
  121. /package/common/cpp/{core → audioapi/core/utils}/AudioNodeManager.h +0 -0
  122. /package/common/cpp/{utils → audioapi/core/utils}/Locker.h +0 -0
  123. /package/common/cpp/{utils → audioapi/dsp}/AudioUtils.h +0 -0
  124. /package/common/cpp/{jsi → audioapi/jsi}/JsiPromise.h +0 -0
  125. /package/common/cpp/{libs → audioapi/libs}/miniaudio.h +0 -0
  126. /package/ios/{AudioAPIModule.h → audioapi/ios/AudioAPIModule.h} +0 -0
  127. /package/ios/{core → audioapi/ios/core}/AudioPlayer.h +0 -0
  128. /package/ios/{core → audioapi/ios/core}/IOSAudioPlayer.h +0 -0
@@ -1,10 +1,8 @@
1
- #include <cassert>
2
- #include <memory>
3
-
4
- #include "AudioBus.h"
5
- #include "AudioNode.h"
6
- #include "AudioNodeManager.h"
7
- #include "BaseAudioContext.h"
1
+ #include <audioapi/core/AudioNode.h>
2
+ #include <audioapi/core/BaseAudioContext.h>
3
+ #include <audioapi/core/utils/AudioArray.h>
4
+ #include <audioapi/core/utils/AudioBus.h>
5
+ #include <audioapi/core/utils/AudioNodeManager.h>
8
6
 
9
7
  namespace audioapi {
10
8
 
@@ -99,17 +97,19 @@ std::string AudioNode::toString(ChannelInterpretation interpretation) {
99
97
 
100
98
  std::shared_ptr<AudioBus> AudioNode::processAudio(
101
99
  std::shared_ptr<AudioBus> outputBus,
102
- int framesToProcess) {
100
+ int framesToProcess,
101
+ bool checkIsAlreadyProcessed) {
103
102
  if (!isInitialized_) {
104
103
  return outputBus;
105
104
  }
106
105
 
107
- if (isAlreadyProcessed()) {
106
+ if (checkIsAlreadyProcessed && isAlreadyProcessed()) {
108
107
  return audioBus_;
109
108
  }
110
109
 
111
110
  // Process inputs and return the bus with the most channels.
112
- auto processingBus = processInputs(outputBus, framesToProcess);
111
+ auto processingBus =
112
+ processInputs(outputBus, framesToProcess, checkIsAlreadyProcessed);
113
113
 
114
114
  // Apply channel count mode.
115
115
  processingBus = applyChannelCountMode(processingBus);
@@ -142,7 +142,8 @@ bool AudioNode::isAlreadyProcessed() {
142
142
 
143
143
  std::shared_ptr<AudioBus> AudioNode::processInputs(
144
144
  const std::shared_ptr<AudioBus> &outputBus,
145
- int framesToProcess) {
145
+ int framesToProcess,
146
+ bool checkIsAlreadyProcessed) {
146
147
  auto processingBus = audioBus_;
147
148
  processingBus->zero();
148
149
 
@@ -154,7 +155,8 @@ std::shared_ptr<AudioBus> AudioNode::processInputs(
154
155
  continue;
155
156
  }
156
157
 
157
- auto inputBus = inputNode->processAudio(outputBus, framesToProcess);
158
+ auto inputBus = inputNode->processAudio(
159
+ outputBus, framesToProcess, checkIsAlreadyProcessed);
158
160
  inputBuses_.push_back(inputBus);
159
161
 
160
162
  if (maxNumberOfChannels < inputBus->getNumberOfChannels()) {
@@ -1,14 +1,15 @@
1
1
  #pragma once
2
2
 
3
+ #include <audioapi/core/types/ChannelCountMode.h>
4
+ #include <audioapi/core/types/ChannelInterpretation.h>
5
+ #include <audioapi/core/Constants.h>
6
+
3
7
  #include <memory>
4
8
  #include <string>
5
9
  #include <unordered_set>
6
10
  #include <cstddef>
7
11
  #include <vector>
8
-
9
- #include "ChannelCountMode.h"
10
- #include "ChannelInterpretation.h"
11
- #include "Constants.h"
12
+ #include <cassert>
12
13
 
13
14
  namespace audioapi {
14
15
 
@@ -57,16 +58,18 @@ class AudioNode : public std::enable_shared_from_this<AudioNode> {
57
58
  std::size_t lastRenderedFrame_{SIZE_MAX};
58
59
 
59
60
  private:
61
+ friend class StretcherNode;
62
+
60
63
  std::vector<std::shared_ptr<AudioBus>> inputBuses_ = {};
61
64
 
62
65
  static std::string toString(ChannelCountMode mode);
63
66
  static std::string toString(ChannelInterpretation interpretation);
64
67
 
65
- std::shared_ptr<AudioBus> processAudio(std::shared_ptr<AudioBus> outputBus, int framesToProcess);
68
+ virtual std::shared_ptr<AudioBus> processAudio(std::shared_ptr<AudioBus> outputBus, int framesToProcess, bool checkIsAlreadyProcessed);
66
69
  virtual void processNode(const std::shared_ptr<AudioBus>&, int) = 0;
67
70
 
68
71
  bool isAlreadyProcessed();
69
- std::shared_ptr<AudioBus> processInputs(const std::shared_ptr<AudioBus>& outputBus, int framesToProcess);
72
+ std::shared_ptr<AudioBus> processInputs(const std::shared_ptr<AudioBus>& outputBus, int framesToProcess, bool checkIsAlreadyProcessed);
70
73
  std::shared_ptr<AudioBus> applyChannelCountMode(std::shared_ptr<AudioBus> processingBus);
71
74
  void mixInputsBuses(const std::shared_ptr<AudioBus>& processingBus);
72
75
 
@@ -1,7 +1,6 @@
1
- #include "AudioParam.h"
2
-
3
- #include "AudioUtils.h"
4
- #include "BaseAudioContext.h"
1
+ #include <audioapi/core/AudioParam.h>
2
+ #include <audioapi/core/BaseAudioContext.h>
3
+ #include <audioapi/dsp/AudioUtils.h>
5
4
 
6
5
  namespace audioapi {
7
6
 
@@ -1,13 +1,13 @@
1
1
  #pragma once
2
2
 
3
+ #include <audioapi/core/utils/ParamChangeEvent.h>
4
+ #include <audioapi/core/types/ParamChangeEventType.h>
5
+
3
6
  #include <deque>
4
7
  #include <memory>
5
8
  #include <vector>
6
9
  #include <cstddef>
7
10
 
8
- #include "ParamChangeEvent.h"
9
- #include "ParamChangeEventType.h"
10
-
11
11
  namespace audioapi {
12
12
 
13
13
  class AudioParam {
@@ -1,19 +1,17 @@
1
- #include <cassert>
2
-
3
- #include "AnalyserNode.h"
4
- #include "AudioArray.h"
5
- #include "AudioBuffer.h"
6
- #include "AudioBufferSourceNode.h"
7
- #include "AudioBus.h"
8
- #include "AudioDecoder.h"
9
- #include "AudioDestinationNode.h"
10
- #include "AudioNodeManager.h"
11
- #include "BaseAudioContext.h"
12
- #include "BiquadFilterNode.h"
13
- #include "ContextState.h"
14
- #include "GainNode.h"
15
- #include "OscillatorNode.h"
16
- #include "StereoPannerNode.h"
1
+ #include <audioapi/core/BaseAudioContext.h>
2
+ #include <audioapi/core/analysis/AnalyserNode.h>
3
+ #include <audioapi/core/destinations/AudioDestinationNode.h>
4
+ #include <audioapi/core/effects/BiquadFilterNode.h>
5
+ #include <audioapi/core/effects/GainNode.h>
6
+ #include <audioapi/core/effects/StereoPannerNode.h>
7
+ #include <audioapi/core/effects/StretcherNode.h>
8
+ #include <audioapi/core/sources/AudioBuffer.h>
9
+ #include <audioapi/core/sources/AudioBufferSourceNode.h>
10
+ #include <audioapi/core/sources/OscillatorNode.h>
11
+ #include <audioapi/core/utils/AudioArray.h>
12
+ #include <audioapi/core/utils/AudioBus.h>
13
+ #include <audioapi/core/utils/AudioDecoder.h>
14
+ #include <audioapi/core/utils/AudioNodeManager.h>
17
15
 
18
16
  namespace audioapi {
19
17
 
@@ -96,6 +94,12 @@ std::shared_ptr<AnalyserNode> BaseAudioContext::createAnalyser() {
96
94
  return analyser;
97
95
  }
98
96
 
97
+ std::shared_ptr<StretcherNode> BaseAudioContext::createStretcher() {
98
+ auto node = std::make_shared<StretcherNode>(this);
99
+ nodeManager_->addNode(node);
100
+ return node;
101
+ }
102
+
99
103
  std::shared_ptr<AudioBuffer> BaseAudioContext::decodeAudioDataSource(
100
104
  const std::string &path) {
101
105
  auto audioBus = audioDecoder_->decodeWithFilePath(path);
@@ -1,14 +1,15 @@
1
1
  #pragma once
2
2
 
3
+ #include <audioapi/core/types/ContextState.h>
4
+ #include <audioapi/core/types/OscillatorType.h>
5
+
3
6
  #include <functional>
4
7
  #include <memory>
5
8
  #include <string>
6
9
  #include <utility>
7
10
  #include <vector>
8
11
  #include <cstddef>
9
-
10
- #include "ContextState.h"
11
- #include "OscillatorType.h"
12
+ #include <cassert>
12
13
 
13
14
  namespace audioapi {
14
15
 
@@ -24,6 +25,7 @@ class AudioDestinationNode;
24
25
  class AudioBufferSourceNode;
25
26
  class AudioDecoder;
26
27
  class AnalyserNode;
28
+ class StretcherNode;
27
29
 
28
30
  class BaseAudioContext {
29
31
  public:
@@ -49,6 +51,7 @@ class BaseAudioContext {
49
51
  bool disableNormalization,
50
52
  int length);
51
53
  std::shared_ptr<AnalyserNode> createAnalyser();
54
+ std::shared_ptr<StretcherNode> createStretcher();
52
55
 
53
56
  std::shared_ptr<AudioBuffer> decodeAudioDataSource(const std::string &path);
54
57
 
@@ -1,13 +1,9 @@
1
- #include "AnalyserNode.h"
2
-
3
- #include <complex>
4
-
5
- #include "AudioArray.h"
6
- #include "AudioBus.h"
7
- #include "AudioUtils.h"
8
- #include "BaseAudioContext.h"
9
- #include "FFTFrame.h"
10
- #include "VectorMath.h"
1
+ #include <audioapi/core/BaseAudioContext.h>
2
+ #include <audioapi/core/analysis/AnalyserNode.h>
3
+ #include <audioapi/core/utils/AudioArray.h>
4
+ #include <audioapi/core/utils/AudioBus.h>
5
+ #include <audioapi/dsp/AudioUtils.h>
6
+ #include <audioapi/dsp/VectorMath.h>
11
7
 
12
8
  namespace audioapi {
13
9
  AnalyserNode::AnalyserNode(audioapi::BaseAudioContext *context)
@@ -1,16 +1,17 @@
1
1
  #pragma once
2
2
 
3
+ #include <audioapi/core/AudioNode.h>
4
+ #include <audioapi/dsp/FFTFrame.h>
5
+
3
6
  #include <memory>
4
7
  #include <cstddef>
5
8
  #include <string>
6
-
7
- #include "AudioNode.h"
9
+ #include <complex>
8
10
 
9
11
  namespace audioapi {
10
12
 
11
13
  class AudioBus;
12
14
  class AudioArray;
13
- class FFTFrame;
14
15
 
15
16
  class AnalyserNode : public AudioNode {
16
17
  public:
@@ -1,8 +1,8 @@
1
- #include "AudioDestinationNode.h"
2
- #include "AudioBus.h"
3
- #include "AudioNode.h"
4
- #include "AudioNodeManager.h"
5
- #include "BaseAudioContext.h"
1
+ #include <audioapi/core/AudioNode.h>
2
+ #include <audioapi/core/BaseAudioContext.h>
3
+ #include <audioapi/core/destinations/AudioDestinationNode.h>
4
+ #include <audioapi/core/utils/AudioBus.h>
5
+ #include <audioapi/core/utils/AudioNodeManager.h>
6
6
 
7
7
  namespace audioapi {
8
8
 
@@ -33,7 +33,7 @@ void AudioDestinationNode::renderAudio(
33
33
 
34
34
  destinationBus->zero();
35
35
 
36
- auto processedBus = processAudio(destinationBus, numFrames);
36
+ auto processedBus = processAudio(destinationBus, numFrames, true);
37
37
 
38
38
  if (processedBus && processedBus != destinationBus) {
39
39
  destinationBus->copy(processedBus.get());
@@ -1,12 +1,12 @@
1
1
  #pragma once
2
2
 
3
+ #include <audioapi/core/AudioNode.h>
4
+
3
5
  #include <algorithm>
4
6
  #include <memory>
5
7
  #include <vector>
6
8
  #include <cstddef>
7
9
 
8
- #include "AudioNode.h"
9
-
10
10
  namespace audioapi {
11
11
 
12
12
  class AudioBus;
@@ -1,7 +1,7 @@
1
- #include "BiquadFilterNode.h"
2
- #include "AudioArray.h"
3
- #include "AudioBus.h"
4
- #include "BaseAudioContext.h"
1
+ #include <audioapi/core/BaseAudioContext.h>
2
+ #include <audioapi/core/effects/BiquadFilterNode.h>
3
+ #include <audioapi/core/utils/AudioArray.h>
4
+ #include <audioapi/core/utils/AudioBus.h>
5
5
 
6
6
  // https://webaudio.github.io/Audio-EQ-Cookbook/audio-eq-cookbook.html - math
7
7
  // formulas for filters
@@ -1,5 +1,9 @@
1
1
  #pragma once
2
2
 
3
+ #include <audioapi/core/AudioNode.h>
4
+ #include <audioapi/core/AudioParam.h>
5
+ #include <audioapi/core/types/BiquadFilterType.h>
6
+
3
7
  #include <algorithm>
4
8
  #include <cmath>
5
9
  #include <complex>
@@ -8,10 +12,6 @@
8
12
  #include <string>
9
13
  #include <vector>
10
14
 
11
- #include "AudioNode.h"
12
- #include "AudioParam.h"
13
- #include "BiquadFilterType.h"
14
-
15
15
  namespace audioapi {
16
16
 
17
17
  class AudioBus;
@@ -1,7 +1,7 @@
1
- #include "GainNode.h"
2
- #include "AudioArray.h"
3
- #include "AudioBus.h"
4
- #include "BaseAudioContext.h"
1
+ #include <audioapi/core/BaseAudioContext.h>
2
+ #include <audioapi/core/effects/GainNode.h>
3
+ #include <audioapi/core/utils/AudioArray.h>
4
+ #include <audioapi/core/utils/AudioBus.h>
5
5
 
6
6
  namespace audioapi {
7
7
 
@@ -1,9 +1,9 @@
1
1
  #pragma once
2
2
 
3
- #include <memory>
3
+ #include <audioapi/core/AudioNode.h>
4
+ #include <audioapi/core/AudioParam.h>
4
5
 
5
- #include "AudioNode.h"
6
- #include "AudioParam.h"
6
+ #include <memory>
7
7
 
8
8
  namespace audioapi {
9
9
 
@@ -26,8 +26,10 @@
26
26
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
27
  */
28
28
 
29
- #include "PeriodicWave.h"
30
- #include "Constants.h"
29
+ #include <audioapi/core/Constants.h>
30
+ #include <audioapi/core/effects/PeriodicWave.h>
31
+ #include <audioapi/dsp/FFTFrame.h>
32
+ #include <audioapi/dsp/VectorMath.h>
31
33
 
32
34
  constexpr unsigned NumberOfOctaveBands = 3;
33
35
  constexpr float CentsPerRange = 1200.0f / NumberOfOctaveBands;
@@ -28,14 +28,12 @@
28
28
 
29
29
  #pragma once
30
30
 
31
+ #include <audioapi/core/types/OscillatorType.h>
32
+
31
33
  #include <algorithm>
32
34
  #include <cmath>
33
35
  #include <memory>
34
36
 
35
- #include "FFTFrame.h"
36
- #include "OscillatorType.h"
37
- #include "VectorMath.h"
38
-
39
37
  namespace audioapi {
40
38
  class PeriodicWave {
41
39
  public:
@@ -1,10 +1,8 @@
1
- #include <cassert>
2
-
3
- #include "AudioArray.h"
4
- #include "AudioBus.h"
5
- #include "BaseAudioContext.h"
6
- #include "Constants.h"
7
- #include "StereoPannerNode.h"
1
+ #include <audioapi/core/BaseAudioContext.h>
2
+ #include <audioapi/core/Constants.h>
3
+ #include <audioapi/core/effects/StereoPannerNode.h>
4
+ #include <audioapi/core/utils/AudioArray.h>
5
+ #include <audioapi/core/utils/AudioBus.h>
8
6
 
9
7
  // https://webaudio.github.io/web-audio-api/#stereopanner-algorithm
10
8
 
@@ -1,10 +1,11 @@
1
1
  #pragma once
2
2
 
3
+ #include <audioapi/core/AudioNode.h>
4
+ #include <audioapi/core/AudioParam.h>
5
+
3
6
  #include <algorithm>
4
7
  #include <memory>
5
-
6
- #include "AudioNode.h"
7
- #include "AudioParam.h"
8
+ #include <cassert>
8
9
 
9
10
  namespace audioapi {
10
11
 
@@ -0,0 +1,94 @@
1
+ #include <audioapi/core/BaseAudioContext.h>
2
+ #include <audioapi/core/effects/StretcherNode.h>
3
+ #include <audioapi/core/utils/AudioArray.h>
4
+ #include <audioapi/core/utils/AudioBus.h>
5
+
6
+ namespace audioapi {
7
+
8
+ StretcherNode::StretcherNode(BaseAudioContext *context) : AudioNode(context) {
9
+ channelCountMode_ = ChannelCountMode::EXPLICIT;
10
+ rate_ = std::make_shared<AudioParam>(1.0, 0.0, 3.0);
11
+ semitones_ = std::make_shared<AudioParam>(0.0, -12.0, 12.0);
12
+
13
+ stretch_ =
14
+ std::make_shared<signalsmith::stretch::SignalsmithStretch<float>>();
15
+ stretch_->presetDefault(channelCount_, context->getSampleRate());
16
+ playbackRateBus_ = std::make_shared<AudioBus>(
17
+ RENDER_QUANTUM_SIZE * 3, channelCount_, context_->getSampleRate());
18
+
19
+ isInitialized_ = true;
20
+ }
21
+
22
+ std::shared_ptr<AudioParam> StretcherNode::getRateParam() const {
23
+ return rate_;
24
+ }
25
+
26
+ std::shared_ptr<AudioParam> StretcherNode::getSemitonesParam() const {
27
+ return semitones_;
28
+ }
29
+
30
+ void StretcherNode::processNode(
31
+ const std::shared_ptr<AudioBus> &processingBus,
32
+ int framesToProcess) {
33
+ auto time = context_->getCurrentTime();
34
+ auto semitones = semitones_->getValueAtTime(time);
35
+
36
+ stretch_->setTransposeSemitones(semitones);
37
+ stretch_->process(
38
+ playbackRateBus_.get()[0],
39
+ framesNeededToStretch_,
40
+ audioBus_.get()[0],
41
+ framesToProcess);
42
+ }
43
+
44
+ std::shared_ptr<AudioBus> StretcherNode::processAudio(
45
+ std::shared_ptr<AudioBus> outputBus,
46
+ int framesToProcess,
47
+ bool checkIsAlreadyProcessed) {
48
+ if (!isInitialized_) {
49
+ return outputBus;
50
+ }
51
+
52
+ if (isAlreadyProcessed()) {
53
+ return audioBus_;
54
+ }
55
+
56
+ auto time = context_->getCurrentTime();
57
+
58
+ auto rate = rate_->getValueAtTime(time);
59
+ framesNeededToStretch_ =
60
+ static_cast<int>(rate * static_cast<float>(framesToProcess));
61
+
62
+ playbackRateBus_->zero();
63
+ auto writeIndex = 0;
64
+ auto framesNeededToStretch = framesNeededToStretch_;
65
+
66
+ // Collecting frames needed to stretch
67
+ while (framesNeededToStretch > 0) {
68
+ auto framesToCopy = std::min(framesNeededToStretch, framesToProcess);
69
+
70
+ // Process inputs and return the bus with the most channels. We must not
71
+ // check if the node has already been processed, cause we need to process it
72
+ // multiple times in this case.
73
+ auto processingBus = processInputs(outputBus, framesToCopy, false);
74
+
75
+ // Apply channel count mode.
76
+ processingBus = applyChannelCountMode(processingBus);
77
+
78
+ // Mix all input buses into the processing bus.
79
+ mixInputsBuses(processingBus);
80
+
81
+ assert(processingBus != nullptr);
82
+
83
+ playbackRateBus_->copy(processingBus.get(), 0, writeIndex, framesToCopy);
84
+
85
+ writeIndex += framesToCopy;
86
+ framesNeededToStretch -= framesToCopy;
87
+ }
88
+
89
+ processNode(audioBus_, framesToProcess);
90
+
91
+ return audioBus_;
92
+ }
93
+
94
+ } // namespace audioapi
@@ -0,0 +1,35 @@
1
+ #pragma once
2
+
3
+ #include <audioapi/libs/signalsmith-stretch.h>
4
+ #include <audioapi/core/AudioNode.h>
5
+ #include <audioapi/core/AudioParam.h>
6
+
7
+ #include <memory>
8
+ #include <string>
9
+ #include <cassert>
10
+
11
+ namespace audioapi {
12
+ class AudioBus;
13
+
14
+ class StretcherNode : public AudioNode {
15
+ public:
16
+ explicit StretcherNode(BaseAudioContext *context);
17
+
18
+ [[nodiscard]] std::shared_ptr<AudioParam> getRateParam() const;
19
+ [[nodiscard]] std::shared_ptr<AudioParam> getSemitonesParam() const;
20
+
21
+ protected:
22
+ void processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override;
23
+ std::shared_ptr<AudioBus> processAudio(std::shared_ptr<AudioBus> outputBus, int framesToProcess, bool checkIsAlreadyProcessed) override;
24
+
25
+ private:
26
+ // k-rate params
27
+ std::shared_ptr<AudioParam> rate_;
28
+ std::shared_ptr<AudioParam> semitones_;
29
+
30
+ std::shared_ptr<signalsmith::stretch::SignalsmithStretch<float>> stretch_;
31
+ std::shared_ptr<AudioBus> playbackRateBus_;
32
+ int framesNeededToStretch_ = RENDER_QUANTUM_SIZE;
33
+ };
34
+
35
+ } // namespace audioapi
@@ -1,8 +1,8 @@
1
- #include "AudioBuffer.h"
1
+ #include <audioapi/core/sources/AudioBuffer.h>
2
+ #include <audioapi/core/utils/AudioArray.h>
3
+ #include <audioapi/core/utils/AudioBus.h>
2
4
 
3
5
  #include <utility>
4
- #include "AudioArray.h"
5
- #include "AudioBus.h"
6
6
 
7
7
  namespace audioapi {
8
8
 
@@ -1,14 +1,11 @@
1
- #include <algorithm>
2
- #include <cassert>
3
-
4
- #include "AudioArray.h"
5
- #include "AudioBufferSourceNode.h"
6
- #include "AudioBus.h"
7
- #include "AudioParam.h"
8
- #include "AudioUtils.h"
9
- #include "BaseAudioContext.h"
10
- #include "Constants.h"
11
- #include "Locker.h"
1
+ #include <audioapi/core/AudioParam.h>
2
+ #include <audioapi/core/BaseAudioContext.h>
3
+ #include <audioapi/core/Constants.h>
4
+ #include <audioapi/core/sources/AudioBufferSourceNode.h>
5
+ #include <audioapi/core/utils/AudioArray.h>
6
+ #include <audioapi/core/utils/AudioBus.h>
7
+ #include <audioapi/core/utils/Locker.h>
8
+ #include <audioapi/dsp/AudioUtils.h>
12
9
 
13
10
  namespace audioapi {
14
11
 
@@ -1,10 +1,12 @@
1
1
  #pragma once
2
2
 
3
+ #include <audioapi/core/sources/AudioBuffer.h>
4
+ #include <audioapi/core/sources/AudioScheduledSourceNode.h>
5
+
3
6
  #include <memory>
4
7
  #include <cstddef>
5
-
6
- #include "AudioBuffer.h"
7
- #include "AudioScheduledSourceNode.h"
8
+ #include <algorithm>
9
+ #include <cassert>
8
10
 
9
11
  namespace audioapi {
10
12
 
@@ -1,11 +1,9 @@
1
- #include <cassert>
2
-
3
- #include "AudioArray.h"
4
- #include "AudioBus.h"
5
- #include "AudioNodeManager.h"
6
- #include "AudioScheduledSourceNode.h"
7
- #include "AudioUtils.h"
8
- #include "BaseAudioContext.h"
1
+ #include <audioapi/core/BaseAudioContext.h>
2
+ #include <audioapi/core/sources/AudioScheduledSourceNode.h>
3
+ #include <audioapi/core/utils/AudioArray.h>
4
+ #include <audioapi/core/utils/AudioBus.h>
5
+ #include <audioapi/core/utils/AudioNodeManager.h>
6
+ #include <audioapi/dsp/AudioUtils.h>
9
7
 
10
8
  namespace audioapi {
11
9
 
@@ -1,5 +1,7 @@
1
1
  #pragma once
2
2
 
3
+ #include <audioapi/core/AudioNode.h>
4
+
3
5
  #include <algorithm>
4
6
  #include <atomic>
5
7
  #include <chrono>
@@ -9,8 +11,7 @@
9
11
  #include <memory>
10
12
  #include <thread>
11
13
  #include <cstddef>
12
-
13
- #include "AudioNode.h"
14
+ #include <cassert>
14
15
 
15
16
  namespace audioapi {
16
17
 
@@ -1,7 +1,7 @@
1
- #include "OscillatorNode.h"
2
- #include "AudioArray.h"
3
- #include "AudioBus.h"
4
- #include "BaseAudioContext.h"
1
+ #include <audioapi/core/BaseAudioContext.h>
2
+ #include <audioapi/core/sources/OscillatorNode.h>
3
+ #include <audioapi/core/utils/AudioArray.h>
4
+ #include <audioapi/core/utils/AudioBus.h>
5
5
 
6
6
  namespace audioapi {
7
7