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
@@ -0,0 +1,219 @@
1
+ #include <audioapi/libs/dsp/common.h>
2
+
3
+ #ifndef SIGNALSMITH_DSP_WINDOWS_H
4
+ #define SIGNALSMITH_DSP_WINDOWS_H
5
+
6
+ #include <cmath>
7
+ #include <algorithm>
8
+
9
+ namespace signalsmith {
10
+ namespace windows {
11
+ /** @defgroup Windows Window functions
12
+ @brief Windows for spectral analysis
13
+
14
+ These are generally double-precision, because they are mostly calculated during setup/reconfiguring, not real-time code.
15
+
16
+ @{
17
+ @file
18
+ */
19
+
20
+ /** @brief The Kaiser window (almost) maximises the energy in the main-lobe compared to the side-lobes.
21
+
22
+ Kaiser windows can be constructing using the shape-parameter (beta) or using the static `with???()` methods.*/
23
+ class Kaiser {
24
+ // I_0(x)=\sum_{k=0}^{N}\frac{x^{2k}}{(k!)^2\cdot4^k}
25
+ inline static double bessel0(double x) {
26
+ const double significanceLimit = 1e-4;
27
+ double result = 0;
28
+ double term = 1;
29
+ double m = 0;
30
+ while (term > significanceLimit) {
31
+ result += term;
32
+ ++m;
33
+ term *= (x*x)/(4*m*m);
34
+ }
35
+
36
+ return result;
37
+ }
38
+ double beta;
39
+ double invB0;
40
+
41
+ static double heuristicBandwidth(double bandwidth) {
42
+ // Good peaks
43
+ //return bandwidth + 8/((bandwidth + 3)*(bandwidth + 3));
44
+ // Good average
45
+ //return bandwidth + 14/((bandwidth + 2.5)*(bandwidth + 2.5));
46
+ // Compromise
47
+ return bandwidth + 8/((bandwidth + 3)*(bandwidth + 3)) + 0.25*std::max(3 - bandwidth, 0.0);
48
+ }
49
+ public:
50
+ /// Set up a Kaiser window with a given shape. `beta` is `pi*alpha` (since there is ambiguity about shape parameters)
51
+ Kaiser(double beta) : beta(beta), invB0(1/bessel0(beta)) {}
52
+
53
+ /// @name Bandwidth methods
54
+ /// @{
55
+ static Kaiser withBandwidth(double bandwidth, bool heuristicOptimal=false) {
56
+ return Kaiser(bandwidthToBeta(bandwidth, heuristicOptimal));
57
+ }
58
+
59
+ /** Returns the Kaiser shape where the main lobe has the specified bandwidth (as a factor of 1/window-length).
60
+ \diagram{kaiser-windows.svg,You can see that the main lobe matches the specified bandwidth.}
61
+ If `heuristicOptimal` is enabled, the main lobe width is _slightly_ wider, improving both the peak and total energy - see `bandwidthToEnergyDb()` and `bandwidthToPeakDb()`.
62
+ \diagram{kaiser-windows-heuristic.svg, The main lobe extends to ±bandwidth/2.} */
63
+ static double bandwidthToBeta(double bandwidth, bool heuristicOptimal=false) {
64
+ if (heuristicOptimal) { // Heuristic based on numerical search
65
+ bandwidth = heuristicBandwidth(bandwidth);
66
+ }
67
+ bandwidth = std::max(bandwidth, 2.0);
68
+ double alpha = std::sqrt(bandwidth*bandwidth*0.25 - 1);
69
+ return alpha*M_PI;
70
+ }
71
+
72
+ static double betaToBandwidth(double beta) {
73
+ double alpha = beta*(1.0/M_PI);
74
+ return 2*std::sqrt(alpha*alpha + 1);
75
+ }
76
+ /// @}
77
+
78
+ /// @name Performance methods
79
+ /// @{
80
+ /** @brief Total energy ratio (in dB) between side-lobes and the main lobe.
81
+ \diagram{windows-kaiser-sidelobe-energy.svg,Measured main/side lobe energy ratio. You can see that the heuristic improves performance for all bandwidth values.}
82
+ This function uses an approximation which is accurate to ±0.5dB for 2 ⩽ bandwidth ≤ 10, or 1 ⩽ bandwidth ≤ 10 when `heuristicOptimal`is enabled.
83
+ */
84
+ static double bandwidthToEnergyDb(double bandwidth, bool heuristicOptimal=false) {
85
+ // Horrible heuristic fits
86
+ if (heuristicOptimal) {
87
+ if (bandwidth < 3) bandwidth += (3 - bandwidth)*0.5;
88
+ return 12.9 + -3/(bandwidth + 0.4) - 13.4*bandwidth + (bandwidth < 3)*-9.6*(bandwidth - 3);
89
+ }
90
+ return 10.5 + 15/(bandwidth + 0.4) - 13.25*bandwidth + (bandwidth < 2)*13*(bandwidth - 2);
91
+ }
92
+ static double energyDbToBandwidth(double energyDb, bool heuristicOptimal=false) {
93
+ double bw = 1;
94
+ while (bw < 20 && bandwidthToEnergyDb(bw, heuristicOptimal) > energyDb) {
95
+ bw *= 2;
96
+ }
97
+ double step = bw/2;
98
+ while (step > 0.0001) {
99
+ if (bandwidthToEnergyDb(bw, heuristicOptimal) > energyDb) {
100
+ bw += step;
101
+ } else {
102
+ bw -= step;
103
+ }
104
+ step *= 0.5;
105
+ }
106
+ return bw;
107
+ }
108
+ /** @brief Peak ratio (in dB) between side-lobes and the main lobe.
109
+ \diagram{windows-kaiser-sidelobe-peaks.svg,Measured main/side lobe peak ratio. You can see that the heuristic improves performance, except in the bandwidth range 1-2 where peak ratio was sacrificed to improve total energy ratio.}
110
+ This function uses an approximation which is accurate to ±0.5dB for 2 ⩽ bandwidth ≤ 9, or 0.5 ⩽ bandwidth ≤ 9 when `heuristicOptimal`is enabled.
111
+ */
112
+ static double bandwidthToPeakDb(double bandwidth, bool heuristicOptimal=false) {
113
+ // Horrible heuristic fits
114
+ if (heuristicOptimal) {
115
+ return 14.2 - 20/(bandwidth + 1) - 13*bandwidth + (bandwidth < 3)*-6*(bandwidth - 3) + (bandwidth < 2.25)*5.8*(bandwidth - 2.25);
116
+ }
117
+ return 10 + 8/(bandwidth + 2) - 12.75*bandwidth + (bandwidth < 2)*4*(bandwidth - 2);
118
+ }
119
+ static double peakDbToBandwidth(double peakDb, bool heuristicOptimal=false) {
120
+ double bw = 1;
121
+ while (bw < 20 && bandwidthToPeakDb(bw, heuristicOptimal) > peakDb) {
122
+ bw *= 2;
123
+ }
124
+ double step = bw/2;
125
+ while (step > 0.0001) {
126
+ if (bandwidthToPeakDb(bw, heuristicOptimal) > peakDb) {
127
+ bw += step;
128
+ } else {
129
+ bw -= step;
130
+ }
131
+ step *= 0.5;
132
+ }
133
+ return bw;
134
+ }
135
+ /** @} */
136
+
137
+ /** Equivalent noise bandwidth (ENBW), a measure of frequency resolution.
138
+ \diagram{windows-kaiser-enbw.svg,Measured ENBW\, with and without the heuristic bandwidth adjustment.}
139
+ This approximation is accurate to ±0.05 up to a bandwidth of 22.
140
+ */
141
+ static double bandwidthToEnbw(double bandwidth, bool heuristicOptimal=false) {
142
+ if (heuristicOptimal) bandwidth = heuristicBandwidth(bandwidth);
143
+ double b2 = std::max<double>(bandwidth - 2, 0);
144
+ return 1 + b2*(0.2 + b2*(-0.005 + b2*(-0.000005 + b2*0.0000022)));
145
+ }
146
+
147
+ /// Return the window's value for position in the range [0, 1]
148
+ double operator ()(double unit) {
149
+ double r = 2*unit - 1;
150
+ double arg = std::sqrt(1 - r*r);
151
+ return bessel0(beta*arg)*invB0;
152
+ }
153
+
154
+ /// Fills an arbitrary container with a Kaiser window
155
+ template<typename Data>
156
+ void fill(Data &&data, int size) const {
157
+ double invSize = 1.0/size;
158
+ for (int i = 0; i < size; ++i) {
159
+ double r = (2*i + 1)*invSize - 1;
160
+ double arg = std::sqrt(1 - r*r);
161
+ data[i] = bessel0(beta*arg)*invB0;
162
+ }
163
+ }
164
+ };
165
+
166
+ /** @brief The Approximate Confined Gaussian window is (almost) optimal
167
+
168
+ ACG windows can be constructing using the shape-parameter (sigma) or using the static `with???()` methods.*/
169
+ class ApproximateConfinedGaussian {
170
+ double gaussianFactor;
171
+
172
+ double gaussian(double x) const {
173
+ return std::exp(-x*x*gaussianFactor);
174
+ }
175
+ public:
176
+ /// Heuristic map from bandwidth to the appropriately-optimal sigma
177
+ static double bandwidthToSigma(double bandwidth) {
178
+ return 0.3/std::sqrt(bandwidth);
179
+ }
180
+ static ApproximateConfinedGaussian withBandwidth(double bandwidth) {
181
+ return ApproximateConfinedGaussian(bandwidthToSigma(bandwidth));
182
+ }
183
+
184
+ ApproximateConfinedGaussian(double sigma) : gaussianFactor(0.0625/(sigma*sigma)) {}
185
+
186
+ /// Fills an arbitrary container
187
+ template<typename Data>
188
+ void fill(Data &&data, int size) const {
189
+ double invSize = 1.0/size;
190
+ double offsetScale = gaussian(1)/(gaussian(3) + gaussian(-1));
191
+ double norm = 1/(gaussian(0) - 2*offsetScale*(gaussian(2)));
192
+ for (int i = 0; i < size; ++i) {
193
+ double r = (2*i + 1)*invSize - 1;
194
+ data[i] = norm*(gaussian(r) - offsetScale*(gaussian(r - 2) + gaussian(r + 2)));
195
+ }
196
+ }
197
+ };
198
+
199
+ /** Forces STFT perfect-reconstruction (WOLA) on an existing window, for a given STFT interval.
200
+ For example, here are perfect-reconstruction versions of the approximately-optimal @ref Kaiser windows:
201
+ \diagram{kaiser-windows-heuristic-pr.svg,Note the lower overall energy\, and the pointy top for 2x bandwidth. Spectral performance is about the same\, though.}
202
+ */
203
+ template<typename Data>
204
+ void forcePerfectReconstruction(Data &&data, int windowLength, int interval) {
205
+ for (int i = 0; i < interval; ++i) {
206
+ double sum2 = 0;
207
+ for (int index = i; index < windowLength; index += interval) {
208
+ sum2 += data[index]*data[index];
209
+ }
210
+ double factor = 1/std::sqrt(sum2);
211
+ for (int index = i; index < windowLength; index += interval) {
212
+ data[index] *= factor;
213
+ }
214
+ }
215
+ }
216
+
217
+ /** @} */
218
+ }} // signalsmith::windows
219
+ #endif // include guard