react-native-audio-api 0.4.1 → 0.4.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.
- package/android/src/main/cpp/core/AudioPlayer.cpp +4 -4
- package/android/src/main/cpp/core/AudioPlayer.h +4 -4
- package/common/cpp/HostObjects/AnalyserNodeHostObject.h +19 -6
- package/common/cpp/HostObjects/AudioAPIInstallerHostObject.h +1 -1
- package/common/cpp/HostObjects/AudioBufferHostObject.h +6 -5
- package/common/cpp/HostObjects/AudioParamHostObject.h +2 -1
- package/common/cpp/HostObjects/BaseAudioContextHostObject.h +4 -3
- package/common/cpp/core/AnalyserNode.cpp +56 -34
- package/common/cpp/core/AnalyserNode.h +51 -19
- package/common/cpp/core/AudioArray.cpp +14 -14
- package/common/cpp/core/AudioArray.h +16 -15
- package/common/cpp/core/AudioBuffer.cpp +12 -9
- package/common/cpp/core/AudioBuffer.h +9 -8
- package/common/cpp/core/AudioBufferSourceNode.cpp +25 -20
- package/common/cpp/core/AudioBufferSourceNode.h +1 -0
- package/common/cpp/core/AudioBus.cpp +22 -26
- package/common/cpp/core/AudioBus.h +24 -24
- package/common/cpp/core/AudioContext.cpp +1 -1
- package/common/cpp/core/AudioContext.h +1 -1
- package/common/cpp/core/AudioDecoder.h +2 -2
- package/common/cpp/core/AudioDestinationNode.cpp +1 -1
- package/common/cpp/core/AudioDestinationNode.h +2 -1
- package/common/cpp/core/AudioNode.cpp +7 -5
- package/common/cpp/core/AudioNode.h +9 -10
- package/common/cpp/core/AudioNodeManager.cpp +1 -3
- package/common/cpp/core/AudioNodeManager.h +1 -1
- package/common/cpp/core/AudioParam.cpp +6 -3
- package/common/cpp/core/AudioParam.h +2 -1
- package/common/cpp/core/AudioScheduledSourceNode.cpp +1 -1
- package/common/cpp/core/AudioScheduledSourceNode.h +1 -0
- package/common/cpp/core/BaseAudioContext.cpp +7 -3
- package/common/cpp/core/BaseAudioContext.h +6 -4
- package/common/cpp/core/BiquadFilterNode.cpp +13 -14
- package/common/cpp/core/Constants.h +25 -12
- package/common/cpp/core/GainNode.cpp +1 -1
- package/common/cpp/core/OscillatorNode.cpp +4 -3
- package/common/cpp/core/PeriodicWave.cpp +7 -6
- package/common/cpp/core/PeriodicWave.h +4 -4
- package/common/cpp/core/StereoPannerNode.cpp +4 -4
- package/common/cpp/utils/AudioUtils.cpp +2 -2
- package/common/cpp/utils/AudioUtils.h +2 -2
- package/common/cpp/utils/Locker.h +2 -2
- package/ios/core/AudioPlayer.h +3 -3
- package/ios/core/AudioPlayer.m +2 -2
- package/ios/core/IOSAudioPlayer.h +2 -2
- package/ios/core/IOSAudioPlayer.mm +2 -2
- package/lib/module/core/AnalyserNode.js +6 -0
- package/lib/module/core/AnalyserNode.js.map +1 -1
- package/lib/module/index.js +6 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/index.native.js +1 -1
- package/lib/module/index.native.js.map +1 -1
- package/lib/typescript/core/AnalyserNode.d.ts +3 -0
- package/lib/typescript/core/AnalyserNode.d.ts.map +1 -1
- package/lib/typescript/core/types.d.ts +1 -0
- package/lib/typescript/core/types.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +3 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/index.native.d.ts +1 -1
- package/lib/typescript/index.native.d.ts.map +1 -1
- package/lib/typescript/interfaces.d.ts +2 -1
- package/lib/typescript/interfaces.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/core/AnalyserNode.ts +9 -0
- package/src/core/types.ts +2 -0
- package/src/index.native.ts +1 -0
- package/src/index.ts +15 -1
- package/src/interfaces.ts +2 -0
|
@@ -4,7 +4,10 @@
|
|
|
4
4
|
|
|
5
5
|
namespace audioapi {
|
|
6
6
|
|
|
7
|
-
AudioBuffer::AudioBuffer(
|
|
7
|
+
AudioBuffer::AudioBuffer(
|
|
8
|
+
int numberOfChannels,
|
|
9
|
+
size_t length,
|
|
10
|
+
float sampleRate) {
|
|
8
11
|
bus_ = std::make_shared<AudioBus>(sampleRate, length, numberOfChannels);
|
|
9
12
|
}
|
|
10
13
|
|
|
@@ -12,7 +15,7 @@ AudioBuffer::AudioBuffer(AudioBus *bus) {
|
|
|
12
15
|
bus_ = std::shared_ptr<AudioBus>(bus);
|
|
13
16
|
}
|
|
14
17
|
|
|
15
|
-
|
|
18
|
+
size_t AudioBuffer::getLength() const {
|
|
16
19
|
return bus_->getSize();
|
|
17
20
|
}
|
|
18
21
|
|
|
@@ -20,12 +23,12 @@ int AudioBuffer::getNumberOfChannels() const {
|
|
|
20
23
|
return bus_->getNumberOfChannels();
|
|
21
24
|
}
|
|
22
25
|
|
|
23
|
-
|
|
26
|
+
float AudioBuffer::getSampleRate() const {
|
|
24
27
|
return bus_->getSampleRate();
|
|
25
28
|
}
|
|
26
29
|
|
|
27
|
-
|
|
28
|
-
return static_cast<
|
|
30
|
+
float AudioBuffer::getDuration() const {
|
|
31
|
+
return static_cast<float>(getLength()) / getSampleRate();
|
|
29
32
|
}
|
|
30
33
|
|
|
31
34
|
float *AudioBuffer::getChannelData(int channel) const {
|
|
@@ -34,9 +37,9 @@ float *AudioBuffer::getChannelData(int channel) const {
|
|
|
34
37
|
|
|
35
38
|
void AudioBuffer::copyFromChannel(
|
|
36
39
|
float *destination,
|
|
37
|
-
|
|
40
|
+
size_t destinationLength,
|
|
38
41
|
int channelNumber,
|
|
39
|
-
|
|
42
|
+
size_t startInChannel) const {
|
|
40
43
|
memcpy(
|
|
41
44
|
destination,
|
|
42
45
|
bus_->getChannel(channelNumber)->getData() + startInChannel,
|
|
@@ -46,9 +49,9 @@ void AudioBuffer::copyFromChannel(
|
|
|
46
49
|
|
|
47
50
|
void AudioBuffer::copyToChannel(
|
|
48
51
|
const float *source,
|
|
49
|
-
|
|
52
|
+
size_t sourceLength,
|
|
50
53
|
int channelNumber,
|
|
51
|
-
|
|
54
|
+
size_t startInChannel) {
|
|
52
55
|
memcpy(
|
|
53
56
|
bus_->getChannel(channelNumber)->getData() + startInChannel,
|
|
54
57
|
source,
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
#include <memory>
|
|
5
5
|
#include <string>
|
|
6
6
|
#include <vector>
|
|
7
|
+
#include <cstddef>
|
|
7
8
|
|
|
8
9
|
namespace audioapi {
|
|
9
10
|
|
|
@@ -11,26 +12,26 @@ class AudioBus;
|
|
|
11
12
|
|
|
12
13
|
class AudioBuffer : public std::enable_shared_from_this<AudioBuffer> {
|
|
13
14
|
public:
|
|
14
|
-
explicit AudioBuffer(int numberOfChannels,
|
|
15
|
+
explicit AudioBuffer(int numberOfChannels, size_t length, float sampleRate);
|
|
15
16
|
explicit AudioBuffer(AudioBus *bus);
|
|
16
17
|
|
|
17
|
-
[[nodiscard]]
|
|
18
|
-
[[nodiscard]]
|
|
19
|
-
[[nodiscard]]
|
|
18
|
+
[[nodiscard]] size_t getLength() const;
|
|
19
|
+
[[nodiscard]] float getSampleRate() const;
|
|
20
|
+
[[nodiscard]] float getDuration() const;
|
|
20
21
|
|
|
21
22
|
[[nodiscard]] int getNumberOfChannels() const;
|
|
22
23
|
[[nodiscard]] float *getChannelData(int channel) const;
|
|
23
24
|
|
|
24
25
|
void copyFromChannel(
|
|
25
26
|
float *destination,
|
|
26
|
-
|
|
27
|
+
size_t destinationLength,
|
|
27
28
|
int channelNumber,
|
|
28
|
-
|
|
29
|
+
size_t startInChannel) const;
|
|
29
30
|
void copyToChannel(
|
|
30
31
|
const float *source,
|
|
31
|
-
|
|
32
|
+
size_t sourceLength,
|
|
32
33
|
int channelNumber,
|
|
33
|
-
|
|
34
|
+
size_t startInChannel);
|
|
34
35
|
|
|
35
36
|
private:
|
|
36
37
|
std::shared_ptr<AudioBus> bus_;
|
|
@@ -16,10 +16,9 @@ AudioBufferSourceNode::AudioBufferSourceNode(BaseAudioContext *context)
|
|
|
16
16
|
loopStart_(0),
|
|
17
17
|
loopEnd_(0),
|
|
18
18
|
vReadIndex_(0.0) {
|
|
19
|
-
numberOfInputs_ = 0;
|
|
20
19
|
buffer_ = std::shared_ptr<AudioBuffer>(nullptr);
|
|
21
20
|
|
|
22
|
-
detuneParam_ = std::make_shared<AudioParam>(0.0,
|
|
21
|
+
detuneParam_ = std::make_shared<AudioParam>(0.0, MIN_DETUNE, MAX_DETUNE);
|
|
23
22
|
playbackRateParam_ = std::make_shared<AudioParam>(
|
|
24
23
|
1.0, MOST_NEGATIVE_SINGLE_FLOAT, MOST_POSITIVE_SINGLE_FLOAT);
|
|
25
24
|
|
|
@@ -73,7 +72,9 @@ void AudioBufferSourceNode::setBuffer(
|
|
|
73
72
|
|
|
74
73
|
buffer_ = buffer;
|
|
75
74
|
alignedBus_ = std::make_shared<AudioBus>(
|
|
76
|
-
context_->getSampleRate(),
|
|
75
|
+
context_->getSampleRate(),
|
|
76
|
+
buffer_->getLength(),
|
|
77
|
+
buffer_->getNumberOfChannels());
|
|
77
78
|
|
|
78
79
|
alignedBus_->zero();
|
|
79
80
|
alignedBus_->sum(buffer_->bus_.get());
|
|
@@ -90,7 +91,7 @@ void AudioBufferSourceNode::processNode(
|
|
|
90
91
|
|
|
91
92
|
// No audio data to fill, zero the output and return.
|
|
92
93
|
if (!isPlaying() || !alignedBus_ || alignedBus_->getSize() == 0 ||
|
|
93
|
-
|
|
94
|
+
playbackRate == 0.0f) {
|
|
94
95
|
processingBus->zero();
|
|
95
96
|
return;
|
|
96
97
|
}
|
|
@@ -115,7 +116,7 @@ void AudioBufferSourceNode::processWithoutInterpolation(
|
|
|
115
116
|
size_t startOffset,
|
|
116
117
|
size_t offsetLength,
|
|
117
118
|
float playbackRate) {
|
|
118
|
-
size_t direction = playbackRate < 0 ? -1 : 1;
|
|
119
|
+
size_t direction = playbackRate < 0.0f ? -1 : 1;
|
|
119
120
|
|
|
120
121
|
auto readIndex = static_cast<size_t>(vReadIndex_);
|
|
121
122
|
size_t writeIndex = startOffset;
|
|
@@ -165,7 +166,7 @@ void AudioBufferSourceNode::processWithoutInterpolation(
|
|
|
165
166
|
}
|
|
166
167
|
|
|
167
168
|
// update reading index for next render quantum
|
|
168
|
-
vReadIndex_ = readIndex;
|
|
169
|
+
vReadIndex_ = static_cast<double>(readIndex);
|
|
169
170
|
}
|
|
170
171
|
|
|
171
172
|
void AudioBufferSourceNode::processWithInterpolation(
|
|
@@ -173,13 +174,13 @@ void AudioBufferSourceNode::processWithInterpolation(
|
|
|
173
174
|
size_t startOffset,
|
|
174
175
|
size_t offsetLength,
|
|
175
176
|
float playbackRate) {
|
|
176
|
-
size_t direction = playbackRate < 0 ? -1 : 1;
|
|
177
|
+
size_t direction = playbackRate < 0.0f ? -1 : 1;
|
|
177
178
|
|
|
178
179
|
size_t writeIndex = startOffset;
|
|
179
180
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
181
|
+
auto vFrameStart = getVirtualStartFrame();
|
|
182
|
+
auto vFrameEnd = getVirtualEndFrame();
|
|
183
|
+
auto vFrameDelta = vFrameEnd - vFrameStart;
|
|
183
184
|
|
|
184
185
|
auto frameStart = static_cast<size_t>(vFrameStart);
|
|
185
186
|
auto frameEnd = static_cast<size_t>(vFrameEnd);
|
|
@@ -195,7 +196,8 @@ void AudioBufferSourceNode::processWithInterpolation(
|
|
|
195
196
|
while (framesLeft > 0) {
|
|
196
197
|
auto readIndex = static_cast<size_t>(vReadIndex_);
|
|
197
198
|
size_t nextReadIndex = readIndex + 1;
|
|
198
|
-
|
|
199
|
+
auto factor =
|
|
200
|
+
static_cast<float>(vReadIndex_ - static_cast<double>(readIndex));
|
|
199
201
|
|
|
200
202
|
if (nextReadIndex >= frameEnd) {
|
|
201
203
|
nextReadIndex = loop_ ? frameStart : readIndex;
|
|
@@ -210,11 +212,11 @@ void AudioBufferSourceNode::processWithInterpolation(
|
|
|
210
212
|
}
|
|
211
213
|
|
|
212
214
|
writeIndex += 1;
|
|
213
|
-
vReadIndex_ += playbackRate * direction;
|
|
215
|
+
vReadIndex_ += playbackRate * static_cast<double>(direction);
|
|
214
216
|
framesLeft -= 1;
|
|
215
217
|
|
|
216
218
|
if (vReadIndex_ < vFrameStart || vReadIndex_ >= vFrameEnd) {
|
|
217
|
-
vReadIndex_ -= direction * vFrameDelta;
|
|
219
|
+
vReadIndex_ -= static_cast<double>(direction) * vFrameDelta;
|
|
218
220
|
|
|
219
221
|
if (!loop_) {
|
|
220
222
|
processingBus->zero(writeIndex, framesLeft);
|
|
@@ -227,23 +229,26 @@ void AudioBufferSourceNode::processWithInterpolation(
|
|
|
227
229
|
}
|
|
228
230
|
|
|
229
231
|
float AudioBufferSourceNode::getPlaybackRateValue(size_t &startOffset) {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
+
auto time = context_->getCurrentTime() +
|
|
233
|
+
static_cast<double>(startOffset) / context_->getSampleRate();
|
|
232
234
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
+
auto sampleRateFactor = buffer_->getSampleRate() / context_->getSampleRate();
|
|
236
|
+
auto detune = std::pow(2.0f, detuneParam_->getValueAtTime(time) / 1200.0f);
|
|
237
|
+
auto playbackRate = playbackRateParam_->getValueAtTime(time);
|
|
238
|
+
|
|
239
|
+
return playbackRate * sampleRateFactor * detune;
|
|
235
240
|
}
|
|
236
241
|
|
|
237
242
|
double AudioBufferSourceNode::getVirtualStartFrame() {
|
|
238
|
-
|
|
243
|
+
auto loopStartFrame = loopStart_ * context_->getSampleRate();
|
|
239
244
|
|
|
240
245
|
return loop_ && loopStartFrame >= 0 && loopStart_ < loopEnd_ ? loopStartFrame
|
|
241
246
|
: 0.0;
|
|
242
247
|
}
|
|
243
248
|
|
|
244
249
|
double AudioBufferSourceNode::getVirtualEndFrame() {
|
|
245
|
-
|
|
246
|
-
|
|
250
|
+
auto inputBufferLength = static_cast<double>(alignedBus_->getSize());
|
|
251
|
+
auto loopEndFrame = loopEnd_ * context_->getSampleRate();
|
|
247
252
|
|
|
248
253
|
return loop_ && loopEndFrame > 0 && loopStart_ < loopEnd_
|
|
249
254
|
? std::min(loopEndFrame, inputBufferLength)
|
|
@@ -17,12 +17,8 @@ namespace audioapi {
|
|
|
17
17
|
/**
|
|
18
18
|
* Public interfaces - memory management
|
|
19
19
|
*/
|
|
20
|
-
AudioBus::AudioBus(int sampleRate, int size)
|
|
21
|
-
: numberOfChannels_(CHANNEL_COUNT), sampleRate_(sampleRate), size_(size) {
|
|
22
|
-
createChannels();
|
|
23
|
-
}
|
|
24
20
|
|
|
25
|
-
AudioBus::AudioBus(
|
|
21
|
+
AudioBus::AudioBus(float sampleRate, size_t size, int numberOfChannels)
|
|
26
22
|
: numberOfChannels_(numberOfChannels),
|
|
27
23
|
sampleRate_(sampleRate),
|
|
28
24
|
size_(size) {
|
|
@@ -41,11 +37,11 @@ int AudioBus::getNumberOfChannels() const {
|
|
|
41
37
|
return numberOfChannels_;
|
|
42
38
|
}
|
|
43
39
|
|
|
44
|
-
|
|
40
|
+
float AudioBus::getSampleRate() const {
|
|
45
41
|
return sampleRate_;
|
|
46
42
|
}
|
|
47
43
|
|
|
48
|
-
|
|
44
|
+
size_t AudioBus::getSize() const {
|
|
49
45
|
return size_;
|
|
50
46
|
}
|
|
51
47
|
|
|
@@ -56,7 +52,7 @@ AudioArray *AudioBus::getChannel(int index) const {
|
|
|
56
52
|
AudioArray *AudioBus::getChannelByType(int channelType) const {
|
|
57
53
|
switch (getNumberOfChannels()) {
|
|
58
54
|
case 1: // mono
|
|
59
|
-
if (channelType == ChannelMono
|
|
55
|
+
if (channelType == ChannelMono) {
|
|
60
56
|
return getChannel(0);
|
|
61
57
|
}
|
|
62
58
|
return nullptr;
|
|
@@ -131,7 +127,7 @@ void AudioBus::zero() {
|
|
|
131
127
|
zero(0, getSize());
|
|
132
128
|
}
|
|
133
129
|
|
|
134
|
-
void AudioBus::zero(
|
|
130
|
+
void AudioBus::zero(size_t start, size_t length) {
|
|
135
131
|
for (auto it = channels_.begin(); it != channels_.end(); it += 1) {
|
|
136
132
|
it->get()->zero(start, length);
|
|
137
133
|
}
|
|
@@ -169,15 +165,15 @@ void AudioBus::sum(const AudioBus *source) {
|
|
|
169
165
|
sum(source, 0, 0, getSize());
|
|
170
166
|
}
|
|
171
167
|
|
|
172
|
-
void AudioBus::sum(const AudioBus *source,
|
|
168
|
+
void AudioBus::sum(const AudioBus *source, size_t start, size_t length) {
|
|
173
169
|
sum(source, start, start, length);
|
|
174
170
|
}
|
|
175
171
|
|
|
176
172
|
void AudioBus::sum(
|
|
177
173
|
const AudioBus *source,
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
174
|
+
size_t sourceStart,
|
|
175
|
+
size_t destinationStart,
|
|
176
|
+
size_t length) {
|
|
181
177
|
if (source == this) {
|
|
182
178
|
return;
|
|
183
179
|
}
|
|
@@ -210,15 +206,15 @@ void AudioBus::copy(const AudioBus *source) {
|
|
|
210
206
|
copy(source, 0, 0, getSize());
|
|
211
207
|
}
|
|
212
208
|
|
|
213
|
-
void AudioBus::copy(const AudioBus *source,
|
|
209
|
+
void AudioBus::copy(const AudioBus *source, size_t start, size_t length) {
|
|
214
210
|
copy(source, start, start, length);
|
|
215
211
|
}
|
|
216
212
|
|
|
217
213
|
void AudioBus::copy(
|
|
218
214
|
const AudioBus *source,
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
215
|
+
size_t sourceStart,
|
|
216
|
+
size_t destinationStart,
|
|
217
|
+
size_t length) {
|
|
222
218
|
if (source == this) {
|
|
223
219
|
return;
|
|
224
220
|
}
|
|
@@ -255,9 +251,9 @@ void AudioBus::createChannels() {
|
|
|
255
251
|
|
|
256
252
|
void AudioBus::discreteSum(
|
|
257
253
|
const AudioBus *source,
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
254
|
+
size_t sourceStart,
|
|
255
|
+
size_t destinationStart,
|
|
256
|
+
size_t length) const {
|
|
261
257
|
int numberOfChannels =
|
|
262
258
|
std::min(getNumberOfChannels(), source->getNumberOfChannels());
|
|
263
259
|
|
|
@@ -272,9 +268,9 @@ void AudioBus::discreteSum(
|
|
|
272
268
|
|
|
273
269
|
void AudioBus::sumByUpMixing(
|
|
274
270
|
const AudioBus *source,
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
271
|
+
size_t sourceStart,
|
|
272
|
+
size_t destinationStart,
|
|
273
|
+
size_t length) {
|
|
278
274
|
int numberOfSourceChannels = source->getNumberOfChannels();
|
|
279
275
|
int numberOfChannels = getNumberOfChannels();
|
|
280
276
|
|
|
@@ -351,9 +347,9 @@ void AudioBus::sumByUpMixing(
|
|
|
351
347
|
|
|
352
348
|
void AudioBus::sumByDownMixing(
|
|
353
349
|
const AudioBus *source,
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
350
|
+
size_t sourceStart,
|
|
351
|
+
size_t destinationStart,
|
|
352
|
+
size_t length) {
|
|
357
353
|
int numberOfSourceChannels = source->getNumberOfChannels();
|
|
358
354
|
int numberOfChannels = getNumberOfChannels();
|
|
359
355
|
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
#include <algorithm>
|
|
4
4
|
#include <memory>
|
|
5
5
|
#include <vector>
|
|
6
|
+
#include <cstddef>
|
|
6
7
|
|
|
7
8
|
namespace audioapi {
|
|
8
9
|
|
|
@@ -21,14 +22,13 @@ class AudioBus {
|
|
|
21
22
|
ChannelSurroundRight = 5,
|
|
22
23
|
};
|
|
23
24
|
|
|
24
|
-
explicit AudioBus(
|
|
25
|
-
explicit AudioBus(int sampleRate, int size, int numberOfChannels);
|
|
25
|
+
explicit AudioBus(float sampleRate, size_t size, int numberOfChannels);
|
|
26
26
|
|
|
27
27
|
~AudioBus();
|
|
28
28
|
|
|
29
29
|
[[nodiscard]] int getNumberOfChannels() const;
|
|
30
|
-
[[nodiscard]]
|
|
31
|
-
[[nodiscard]]
|
|
30
|
+
[[nodiscard]] float getSampleRate() const;
|
|
31
|
+
[[nodiscard]] size_t getSize() const;
|
|
32
32
|
[[nodiscard]] AudioArray *getChannel(int index) const;
|
|
33
33
|
[[nodiscard]] AudioArray *getChannelByType(int channelType) const;
|
|
34
34
|
|
|
@@ -37,47 +37,47 @@ class AudioBus {
|
|
|
37
37
|
[[nodiscard]] float maxAbsValue() const;
|
|
38
38
|
|
|
39
39
|
void zero();
|
|
40
|
-
void zero(
|
|
40
|
+
void zero(size_t start, size_t length);
|
|
41
41
|
|
|
42
42
|
void sum(const AudioBus *source);
|
|
43
|
-
void sum(const AudioBus *source,
|
|
43
|
+
void sum(const AudioBus *source, size_t start, size_t length);
|
|
44
44
|
void sum(
|
|
45
45
|
const AudioBus *source,
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
size_t sourceStart,
|
|
47
|
+
size_t destinationStart,
|
|
48
|
+
size_t length);
|
|
49
49
|
|
|
50
50
|
void copy(const AudioBus *source);
|
|
51
|
-
void copy(const AudioBus *source,
|
|
51
|
+
void copy(const AudioBus *source, size_t start, size_t length);
|
|
52
52
|
void copy(
|
|
53
53
|
const AudioBus *source,
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
size_t sourceStart,
|
|
55
|
+
size_t destinationStart,
|
|
56
|
+
size_t length);
|
|
57
57
|
|
|
58
58
|
private:
|
|
59
59
|
std::vector<std::shared_ptr<AudioArray>> channels_;
|
|
60
60
|
|
|
61
61
|
int numberOfChannels_;
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
float sampleRate_;
|
|
63
|
+
size_t size_;
|
|
64
64
|
|
|
65
65
|
void createChannels();
|
|
66
66
|
void discreteSum(
|
|
67
67
|
const AudioBus *source,
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
size_t sourceStart,
|
|
69
|
+
size_t destinationStart,
|
|
70
|
+
size_t length) const;
|
|
71
71
|
void sumByUpMixing(
|
|
72
72
|
const AudioBus *source,
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
size_t sourceStart,
|
|
74
|
+
size_t destinationStart,
|
|
75
|
+
size_t length);
|
|
76
76
|
void sumByDownMixing(
|
|
77
77
|
const AudioBus *source,
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
size_t sourceStart,
|
|
79
|
+
size_t destinationStart,
|
|
80
|
+
size_t length);
|
|
81
81
|
};
|
|
82
82
|
|
|
83
83
|
} // namespace audioapi
|
|
@@ -21,7 +21,7 @@ AudioContext::AudioContext() : BaseAudioContext() {
|
|
|
21
21
|
audioPlayer_->start();
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
AudioContext::AudioContext(
|
|
24
|
+
AudioContext::AudioContext(float sampleRate) : BaseAudioContext() {
|
|
25
25
|
#ifdef ANDROID
|
|
26
26
|
audioPlayer_ = std::make_shared<AudioPlayer>(this->renderAudio(), sampleRate);
|
|
27
27
|
#else
|
|
@@ -8,12 +8,12 @@ class AudioBus;
|
|
|
8
8
|
|
|
9
9
|
class AudioDecoder {
|
|
10
10
|
public:
|
|
11
|
-
explicit AudioDecoder(
|
|
11
|
+
explicit AudioDecoder(float sampleRate) : sampleRate_(sampleRate) {}
|
|
12
12
|
|
|
13
13
|
[[nodiscard]] AudioBus *decodeWithFilePath(const std::string &path) const;
|
|
14
14
|
|
|
15
15
|
private:
|
|
16
|
-
|
|
16
|
+
float sampleRate_;
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
} // namespace audioapi
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
#include <algorithm>
|
|
4
4
|
#include <memory>
|
|
5
5
|
#include <vector>
|
|
6
|
+
#include <cstddef>
|
|
6
7
|
|
|
7
8
|
#include "AudioNode.h"
|
|
8
9
|
|
|
@@ -15,7 +16,7 @@ class AudioDestinationNode : public AudioNode {
|
|
|
15
16
|
public:
|
|
16
17
|
explicit AudioDestinationNode(BaseAudioContext *context);
|
|
17
18
|
|
|
18
|
-
void renderAudio(AudioBus *audioData,
|
|
19
|
+
void renderAudio(AudioBus *audioData, int numFrames);
|
|
19
20
|
|
|
20
21
|
std::size_t getCurrentSampleFrame() const;
|
|
21
22
|
double getCurrentTime() const;
|
|
@@ -75,16 +75,16 @@ bool AudioNode::isEnabled() const {
|
|
|
75
75
|
void AudioNode::enable() {
|
|
76
76
|
isEnabled_ = true;
|
|
77
77
|
|
|
78
|
-
for (auto
|
|
79
|
-
|
|
78
|
+
for (auto &outputNode : outputNodes_) {
|
|
79
|
+
outputNode->onInputEnabled();
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
void AudioNode::disable() {
|
|
84
84
|
isEnabled_ = false;
|
|
85
85
|
|
|
86
|
-
for (auto
|
|
87
|
-
|
|
86
|
+
for (auto &outputNode : outputNodes_) {
|
|
87
|
+
outputNode->onInputDisabled();
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
|
|
@@ -166,12 +166,14 @@ AudioBus *AudioNode::processAudio(AudioBus *outputBus, int framesToProcess) {
|
|
|
166
166
|
AudioBus *inputBus = (*it)->processAudio(processingBus, framesToProcess);
|
|
167
167
|
|
|
168
168
|
if (inputBus != processingBus) {
|
|
169
|
+
// add assert
|
|
169
170
|
processingBus->sum(inputBus);
|
|
170
171
|
}
|
|
171
172
|
} else {
|
|
172
173
|
// Enforce the summing to be done using the internal bus.
|
|
173
|
-
AudioBus *inputBus = (*it)->processAudio(
|
|
174
|
+
AudioBus *inputBus = (*it)->processAudio(nullptr, framesToProcess);
|
|
174
175
|
if (inputBus) {
|
|
176
|
+
// add assert
|
|
175
177
|
processingBus->sum(inputBus);
|
|
176
178
|
}
|
|
177
179
|
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
#include <memory>
|
|
4
4
|
#include <string>
|
|
5
5
|
#include <vector>
|
|
6
|
+
#include <cstddef>
|
|
6
7
|
|
|
7
8
|
#include "ChannelCountMode.h"
|
|
8
9
|
#include "ChannelInterpretation.h"
|
|
@@ -37,24 +38,22 @@ class AudioNode : public std::enable_shared_from_this<AudioNode> {
|
|
|
37
38
|
BaseAudioContext *context_;
|
|
38
39
|
std::shared_ptr<AudioBus> audioBus_;
|
|
39
40
|
|
|
40
|
-
int channelCount_ = CHANNEL_COUNT;
|
|
41
|
-
|
|
42
41
|
int numberOfInputs_ = 1;
|
|
43
42
|
int numberOfOutputs_ = 1;
|
|
44
|
-
int
|
|
43
|
+
int channelCount_ = 2;
|
|
44
|
+
ChannelCountMode channelCountMode_ = ChannelCountMode::MAX;
|
|
45
|
+
ChannelInterpretation channelInterpretation_ =
|
|
46
|
+
ChannelInterpretation::SPEAKERS;
|
|
47
|
+
|
|
48
|
+
std::vector<AudioNode *> inputNodes_ = {};
|
|
49
|
+
std::vector<std::shared_ptr<AudioNode>> outputNodes_ = {};
|
|
45
50
|
|
|
51
|
+
int numberOfEnabledInputNodes_ = 0;
|
|
46
52
|
bool isInitialized_ = false;
|
|
47
53
|
bool isEnabled_ = true;
|
|
48
54
|
|
|
49
55
|
std::size_t lastRenderedFrame_{SIZE_MAX};
|
|
50
56
|
|
|
51
|
-
ChannelCountMode channelCountMode_ = ChannelCountMode::MAX;
|
|
52
|
-
ChannelInterpretation channelInterpretation_ =
|
|
53
|
-
ChannelInterpretation::SPEAKERS;
|
|
54
|
-
|
|
55
|
-
std::vector<AudioNode *> inputNodes_ = {};
|
|
56
|
-
std::vector<std::shared_ptr<AudioNode>> outputNodes_ = {};
|
|
57
|
-
|
|
58
57
|
private:
|
|
59
58
|
static std::string toString(ChannelCountMode mode);
|
|
60
59
|
static std::string toString(ChannelInterpretation interpretation);
|
|
@@ -5,8 +5,6 @@
|
|
|
5
5
|
|
|
6
6
|
namespace audioapi {
|
|
7
7
|
|
|
8
|
-
AudioNodeManager::AudioNodeManager() {}
|
|
9
|
-
|
|
10
8
|
AudioNodeManager::~AudioNodeManager() {
|
|
11
9
|
audioNodesToConnect_.clear();
|
|
12
10
|
sourceNodes_.clear();
|
|
@@ -18,7 +16,7 @@ void AudioNodeManager::addPendingConnection(
|
|
|
18
16
|
ConnectionType type) {
|
|
19
17
|
Locker lock(getGraphLock());
|
|
20
18
|
|
|
21
|
-
audioNodesToConnect_.
|
|
19
|
+
audioNodesToConnect_.emplace_back(from, to, type);
|
|
22
20
|
}
|
|
23
21
|
|
|
24
22
|
void AudioNodeManager::addSourceNode(const std::shared_ptr<AudioNode> &node) {
|
|
@@ -181,7 +181,7 @@ void AudioParam::setTargetAtTime(
|
|
|
181
181
|
|
|
182
182
|
void AudioParam::setValueCurveAtTime(
|
|
183
183
|
const float *values,
|
|
184
|
-
|
|
184
|
+
size_t length,
|
|
185
185
|
double startTime,
|
|
186
186
|
double duration) {
|
|
187
187
|
if (startTime <= getQueueEndTime()) {
|
|
@@ -200,9 +200,12 @@ void AudioParam::setValueCurveAtTime(
|
|
|
200
200
|
|
|
201
201
|
if (time < endTime) {
|
|
202
202
|
auto k = static_cast<int>(std::floor(
|
|
203
|
-
(length - 1) / (endTime - startTime) *
|
|
203
|
+
static_cast<double>(length - 1) / (endTime - startTime) *
|
|
204
|
+
(time - startTime)));
|
|
204
205
|
auto factor = static_cast<float>(
|
|
205
|
-
k -
|
|
206
|
+
k -
|
|
207
|
+
(time - startTime) * static_cast<double>(length - 1) /
|
|
208
|
+
(endTime - startTime));
|
|
206
209
|
|
|
207
210
|
return AudioUtils::linearInterpolate(values, k, k + 1, factor);
|
|
208
211
|
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
#include <deque>
|
|
4
4
|
#include <memory>
|
|
5
5
|
#include <vector>
|
|
6
|
+
#include <cstddef>
|
|
6
7
|
|
|
7
8
|
#include "ParamChangeEvent.h"
|
|
8
9
|
#include "ParamChangeEventType.h"
|
|
@@ -27,7 +28,7 @@ class AudioParam {
|
|
|
27
28
|
void setTargetAtTime(float target, double startTime, double timeConstant);
|
|
28
29
|
void setValueCurveAtTime(
|
|
29
30
|
const float *values,
|
|
30
|
-
|
|
31
|
+
size_t length,
|
|
31
32
|
double startTime,
|
|
32
33
|
double duration);
|
|
33
34
|
void cancelScheduledValues(double cancelTime);
|
|
@@ -53,7 +53,7 @@ void AudioScheduledSourceNode::updatePlaybackInfo(
|
|
|
53
53
|
return;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
auto sampleRate = context_->getSampleRate();
|
|
57
57
|
|
|
58
58
|
size_t firstFrame = context_->getCurrentSampleFrame();
|
|
59
59
|
size_t lastFrame = firstFrame + framesToProcess;
|