react-native-audio-api 0.2.0 → 0.3.0-rc1
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/AudioPlayer/AudioPlayer.cpp +16 -7
- package/android/src/main/cpp/AudioPlayer/AudioPlayer.h +3 -2
- package/common/cpp/AudioAPIInstaller/AudioAPIInstallerHostObject.cpp +5 -3
- package/common/cpp/AudioAPIInstaller/AudioAPIInstallerHostObject.h +5 -1
- package/common/cpp/HostObjects/AudioBufferHostObject.cpp +6 -0
- package/common/cpp/HostObjects/AudioContextHostObject.cpp +2 -2
- package/common/cpp/HostObjects/AudioContextHostObject.h +4 -3
- package/common/cpp/HostObjects/BaseAudioContextHostObject.cpp +28 -2
- package/common/cpp/HostObjects/BaseAudioContextHostObject.h +3 -1
- package/common/cpp/core/AudioArray.cpp +28 -14
- package/common/cpp/core/AudioArray.h +20 -14
- package/common/cpp/core/AudioBuffer.cpp +14 -11
- package/common/cpp/core/AudioBuffer.h +1 -0
- package/common/cpp/core/AudioBufferSourceNode.cpp +29 -19
- package/common/cpp/core/AudioBufferSourceNode.h +1 -1
- package/common/cpp/core/AudioBus.cpp +276 -115
- package/common/cpp/core/AudioBus.h +29 -9
- package/common/cpp/core/AudioContext.cpp +5 -9
- package/common/cpp/core/AudioDestinationNode.cpp +10 -8
- package/common/cpp/core/AudioDestinationNode.h +4 -4
- package/common/cpp/core/AudioNode.cpp +25 -17
- package/common/cpp/core/AudioNode.h +5 -5
- package/common/cpp/core/AudioNodeManager.cpp +10 -7
- package/common/cpp/core/AudioNodeManager.h +11 -4
- package/common/cpp/core/AudioScheduledSourceNode.cpp +2 -2
- package/common/cpp/core/BaseAudioContext.cpp +46 -12
- package/common/cpp/core/BaseAudioContext.h +12 -5
- package/common/cpp/core/BiquadFilterNode.cpp +5 -3
- package/common/cpp/core/GainNode.cpp +1 -1
- package/common/cpp/core/OscillatorNode.cpp +4 -4
- package/common/cpp/core/OscillatorNode.h +2 -2
- package/common/cpp/core/StereoPannerNode.cpp +10 -7
- package/common/cpp/core/StereoPannerNode.h +1 -1
- package/common/cpp/utils/FFTFrame.h +5 -1
- package/common/cpp/utils/JsiPromise.cpp +59 -0
- package/common/cpp/utils/JsiPromise.h +42 -0
- package/common/cpp/utils/Locker.h +8 -6
- package/common/cpp/utils/VectorMath.cpp +71 -55
- package/common/cpp/utils/android/FFTFrame.cpp +12 -11
- package/common/cpp/utils/ios/FFTFrame.cpp +6 -1
- package/common/cpp/wrappers/BaseAudioContextWrapper.cpp +7 -0
- package/common/cpp/wrappers/BaseAudioContextWrapper.h +1 -0
- package/ios/AudioAPIModule.mm +3 -1
- package/ios/AudioDecoder/AudioDecoder.h +17 -0
- package/ios/AudioDecoder/AudioDecoder.m +167 -0
- package/ios/AudioDecoder/IOSAudioDecoder.h +26 -0
- package/ios/AudioDecoder/IOSAudioDecoder.mm +40 -0
- package/ios/AudioPlayer/AudioPlayer.h +1 -1
- package/ios/AudioPlayer/AudioPlayer.m +0 -1
- package/ios/AudioPlayer/IOSAudioPlayer.h +5 -5
- package/ios/AudioPlayer/IOSAudioPlayer.mm +4 -3
- package/lib/module/core/BaseAudioContext.js +5 -0
- package/lib/module/core/BaseAudioContext.js.map +1 -1
- package/lib/module/index.js +235 -17
- package/lib/module/index.js.map +1 -1
- package/lib/module/index.native.js +18 -0
- package/lib/module/index.native.js.map +1 -0
- package/lib/module/utils/resolveAudioSource.js +10 -0
- package/lib/module/utils/resolveAudioSource.js.map +1 -0
- package/lib/typescript/core/BaseAudioContext.d.ts +2 -1
- package/lib/typescript/core/BaseAudioContext.d.ts.map +1 -1
- package/lib/typescript/core/types.d.ts +6 -0
- package/lib/typescript/core/types.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +100 -13
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/index.native.d.ts +14 -0
- package/lib/typescript/index.native.d.ts.map +1 -0
- package/lib/typescript/interfaces.d.ts +1 -0
- package/lib/typescript/interfaces.d.ts.map +1 -1
- package/lib/typescript/utils/resolveAudioSource.d.ts +3 -0
- package/lib/typescript/utils/resolveAudioSource.d.ts.map +1 -0
- package/package.json +4 -2
- package/src/core/BaseAudioContext.ts +12 -1
- package/src/core/types.ts +7 -0
- package/src/index.native.ts +25 -0
- package/src/index.ts +413 -19
- package/src/interfaces.ts +1 -0
- package/src/utils/resolveAudioSource.ts +14 -0
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
#include <algorithm>
|
|
2
2
|
|
|
3
|
+
#include "AudioArray.h"
|
|
3
4
|
#include "AudioBus.h"
|
|
5
|
+
#include "BaseAudioContext.h"
|
|
4
6
|
#include "Constants.h"
|
|
5
|
-
#include "AudioArray.h"
|
|
6
7
|
#include "VectorMath.h"
|
|
7
|
-
#include "BaseAudioContext.h"
|
|
8
8
|
|
|
9
|
-
// Implementation of channel summing/mixing is based on the WebKit approach,
|
|
9
|
+
// Implementation of channel summing/mixing is based on the WebKit approach,
|
|
10
|
+
// source:
|
|
10
11
|
// https://github.com/WebKit/WebKit/blob/main/Source/WebCore/platform/audio/AudioBus.cpp
|
|
11
12
|
|
|
12
13
|
const float SQRT_HALF = sqrtf(0.5f);
|
|
@@ -17,12 +18,14 @@ namespace audioapi {
|
|
|
17
18
|
* Public interfaces - memory management
|
|
18
19
|
*/
|
|
19
20
|
AudioBus::AudioBus(int sampleRate, int size)
|
|
20
|
-
: sampleRate_(sampleRate), size_(size)
|
|
21
|
+
: numberOfChannels_(CHANNEL_COUNT), sampleRate_(sampleRate), size_(size) {
|
|
21
22
|
createChannels();
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
AudioBus::AudioBus(int sampleRate, int size, int numberOfChannels)
|
|
25
|
-
:
|
|
26
|
+
: numberOfChannels_(numberOfChannels),
|
|
27
|
+
sampleRate_(sampleRate),
|
|
28
|
+
size_(size) {
|
|
26
29
|
createChannels();
|
|
27
30
|
}
|
|
28
31
|
|
|
@@ -46,56 +49,77 @@ int AudioBus::getSize() const {
|
|
|
46
49
|
return size_;
|
|
47
50
|
}
|
|
48
51
|
|
|
49
|
-
AudioArray*
|
|
52
|
+
AudioArray *AudioBus::getChannel(int index) const {
|
|
50
53
|
return channels_[index].get();
|
|
51
54
|
}
|
|
52
55
|
|
|
53
|
-
AudioArray*
|
|
56
|
+
AudioArray *AudioBus::getChannelByType(int channelType) const {
|
|
54
57
|
switch (getNumberOfChannels()) {
|
|
55
58
|
case 1: // mono
|
|
56
59
|
if (channelType == ChannelMono || channelType == ChannelLeft) {
|
|
57
60
|
return getChannel(0);
|
|
58
61
|
}
|
|
59
|
-
return
|
|
62
|
+
return nullptr;
|
|
60
63
|
|
|
61
64
|
case 2: // stereo
|
|
62
65
|
switch (channelType) {
|
|
63
|
-
case ChannelLeft:
|
|
64
|
-
|
|
65
|
-
|
|
66
|
+
case ChannelLeft:
|
|
67
|
+
return getChannel(0);
|
|
68
|
+
case ChannelRight:
|
|
69
|
+
return getChannel(1);
|
|
70
|
+
default:
|
|
71
|
+
return nullptr;
|
|
66
72
|
}
|
|
67
73
|
|
|
68
74
|
case 4: // quad
|
|
69
75
|
switch (channelType) {
|
|
70
|
-
case ChannelLeft:
|
|
71
|
-
|
|
72
|
-
case
|
|
73
|
-
|
|
74
|
-
|
|
76
|
+
case ChannelLeft:
|
|
77
|
+
return getChannel(0);
|
|
78
|
+
case ChannelRight:
|
|
79
|
+
return getChannel(1);
|
|
80
|
+
case ChannelSurroundLeft:
|
|
81
|
+
return getChannel(2);
|
|
82
|
+
case ChannelSurroundRight:
|
|
83
|
+
return getChannel(3);
|
|
84
|
+
default:
|
|
85
|
+
return nullptr;
|
|
75
86
|
}
|
|
76
87
|
|
|
77
88
|
case 5: // 5.0
|
|
78
89
|
switch (channelType) {
|
|
79
|
-
case ChannelLeft:
|
|
80
|
-
|
|
81
|
-
case
|
|
82
|
-
|
|
83
|
-
case
|
|
84
|
-
|
|
90
|
+
case ChannelLeft:
|
|
91
|
+
return getChannel(0);
|
|
92
|
+
case ChannelRight:
|
|
93
|
+
return getChannel(1);
|
|
94
|
+
case ChannelCenter:
|
|
95
|
+
return getChannel(2);
|
|
96
|
+
case ChannelSurroundLeft:
|
|
97
|
+
return getChannel(3);
|
|
98
|
+
case ChannelSurroundRight:
|
|
99
|
+
return getChannel(4);
|
|
100
|
+
default:
|
|
101
|
+
return nullptr;
|
|
85
102
|
}
|
|
86
103
|
|
|
87
104
|
case 6: // 5.1
|
|
88
105
|
switch (channelType) {
|
|
89
|
-
case ChannelLeft:
|
|
90
|
-
|
|
91
|
-
case
|
|
92
|
-
|
|
93
|
-
case
|
|
94
|
-
|
|
95
|
-
|
|
106
|
+
case ChannelLeft:
|
|
107
|
+
return getChannel(0);
|
|
108
|
+
case ChannelRight:
|
|
109
|
+
return getChannel(1);
|
|
110
|
+
case ChannelCenter:
|
|
111
|
+
return getChannel(2);
|
|
112
|
+
case ChannelLFE:
|
|
113
|
+
return getChannel(3);
|
|
114
|
+
case ChannelSurroundLeft:
|
|
115
|
+
return getChannel(4);
|
|
116
|
+
case ChannelSurroundRight:
|
|
117
|
+
return getChannel(5);
|
|
118
|
+
default:
|
|
119
|
+
return nullptr;
|
|
96
120
|
}
|
|
97
121
|
default:
|
|
98
|
-
return
|
|
122
|
+
return nullptr;
|
|
99
123
|
}
|
|
100
124
|
}
|
|
101
125
|
|
|
@@ -125,16 +149,16 @@ void AudioBus::normalize() {
|
|
|
125
149
|
}
|
|
126
150
|
|
|
127
151
|
void AudioBus::scale(float value) {
|
|
128
|
-
for (auto
|
|
129
|
-
|
|
152
|
+
for (auto &channel : channels_) {
|
|
153
|
+
channel->scale(value);
|
|
130
154
|
}
|
|
131
155
|
}
|
|
132
156
|
|
|
133
157
|
float AudioBus::maxAbsValue() const {
|
|
134
158
|
float maxAbsValue = 1.0f;
|
|
135
159
|
|
|
136
|
-
for (auto
|
|
137
|
-
float channelMaxAbsValue =
|
|
160
|
+
for (const auto &channel : channels_) {
|
|
161
|
+
float channelMaxAbsValue = channel->getMaxAbsValue();
|
|
138
162
|
maxAbsValue = std::max(maxAbsValue, channelMaxAbsValue);
|
|
139
163
|
}
|
|
140
164
|
|
|
@@ -149,7 +173,11 @@ void AudioBus::sum(const AudioBus *source, int start, int length) {
|
|
|
149
173
|
sum(source, start, start, length);
|
|
150
174
|
}
|
|
151
175
|
|
|
152
|
-
void AudioBus::sum(
|
|
176
|
+
void AudioBus::sum(
|
|
177
|
+
const AudioBus *source,
|
|
178
|
+
int sourceStart,
|
|
179
|
+
int destinationStart,
|
|
180
|
+
int length) {
|
|
153
181
|
if (source == this) {
|
|
154
182
|
return;
|
|
155
183
|
}
|
|
@@ -157,8 +185,9 @@ void AudioBus::sum(const AudioBus *source, int sourceStart, int destinationStart
|
|
|
157
185
|
int numberOfSourceChannels = source->getNumberOfChannels();
|
|
158
186
|
int numberOfChannels = getNumberOfChannels();
|
|
159
187
|
|
|
160
|
-
// TODO: consider adding ability to enforce discrete summing (if/when it will
|
|
161
|
-
// Source channel count is smaller than current bus, we need to
|
|
188
|
+
// TODO: consider adding ability to enforce discrete summing (if/when it will
|
|
189
|
+
// be useful). Source channel count is smaller than current bus, we need to
|
|
190
|
+
// up-mix.
|
|
162
191
|
if (numberOfSourceChannels < numberOfChannels) {
|
|
163
192
|
sumByUpMixing(source, sourceStart, destinationStart, length);
|
|
164
193
|
return;
|
|
@@ -172,7 +201,8 @@ void AudioBus::sum(const AudioBus *source, int sourceStart, int destinationStart
|
|
|
172
201
|
|
|
173
202
|
// Source and destination channel counts are the same. Just sum the channels.
|
|
174
203
|
for (int i = 0; i < numberOfChannels_; i += 1) {
|
|
175
|
-
getChannel(i)->sum(
|
|
204
|
+
getChannel(i)->sum(
|
|
205
|
+
source->getChannel(i), sourceStart, destinationStart, length);
|
|
176
206
|
}
|
|
177
207
|
}
|
|
178
208
|
|
|
@@ -184,14 +214,19 @@ void AudioBus::copy(const AudioBus *source, int start, int length) {
|
|
|
184
214
|
copy(source, start, start, length);
|
|
185
215
|
}
|
|
186
216
|
|
|
187
|
-
void AudioBus::copy(
|
|
217
|
+
void AudioBus::copy(
|
|
218
|
+
const AudioBus *source,
|
|
219
|
+
int sourceStart,
|
|
220
|
+
int destinationStart,
|
|
221
|
+
int length) {
|
|
188
222
|
if (source == this) {
|
|
189
223
|
return;
|
|
190
224
|
}
|
|
191
225
|
|
|
192
226
|
if (source->getNumberOfChannels() == getNumberOfChannels()) {
|
|
193
227
|
for (int i = 0; i < getNumberOfChannels(); i += 1) {
|
|
194
|
-
getChannel(i)->copy(
|
|
228
|
+
getChannel(i)->copy(
|
|
229
|
+
source->getChannel(i), sourceStart, destinationStart, length);
|
|
195
230
|
}
|
|
196
231
|
|
|
197
232
|
return;
|
|
@@ -218,108 +253,212 @@ void AudioBus::createChannels() {
|
|
|
218
253
|
* Internal tooling - channel summing
|
|
219
254
|
*/
|
|
220
255
|
|
|
221
|
-
void AudioBus::discreteSum(
|
|
222
|
-
|
|
256
|
+
void AudioBus::discreteSum(
|
|
257
|
+
const AudioBus *source,
|
|
258
|
+
int sourceStart,
|
|
259
|
+
int destinationStart,
|
|
260
|
+
int length) const {
|
|
261
|
+
int numberOfChannels =
|
|
262
|
+
std::min(getNumberOfChannels(), source->getNumberOfChannels());
|
|
223
263
|
|
|
224
264
|
// In case of source > destination, we "down-mix" and drop the extra channels.
|
|
225
|
-
// In case of source < destination, we "up-mix" as many channels as we have,
|
|
265
|
+
// In case of source < destination, we "up-mix" as many channels as we have,
|
|
266
|
+
// leaving the remaining channels untouched.
|
|
226
267
|
for (int i = 0; i < numberOfChannels; i++) {
|
|
227
|
-
getChannel(i)->sum(
|
|
268
|
+
getChannel(i)->sum(
|
|
269
|
+
source->getChannel(i), sourceStart, destinationStart, length);
|
|
228
270
|
}
|
|
229
271
|
}
|
|
230
272
|
|
|
231
|
-
void AudioBus::sumByUpMixing(
|
|
273
|
+
void AudioBus::sumByUpMixing(
|
|
274
|
+
const AudioBus *source,
|
|
275
|
+
int sourceStart,
|
|
276
|
+
int destinationStart,
|
|
277
|
+
int length) {
|
|
232
278
|
int numberOfSourceChannels = source->getNumberOfChannels();
|
|
233
279
|
int numberOfChannels = getNumberOfChannels();
|
|
234
280
|
|
|
235
281
|
// Mono to stereo (1 -> 2, 4)
|
|
236
|
-
if (numberOfSourceChannels == 1 &&
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
getChannelByType(
|
|
282
|
+
if (numberOfSourceChannels == 1 &&
|
|
283
|
+
(numberOfChannels == 2 || numberOfChannels == 4)) {
|
|
284
|
+
AudioArray *sourceChannel = source->getChannelByType(ChannelMono);
|
|
285
|
+
|
|
286
|
+
getChannelByType(ChannelLeft)
|
|
287
|
+
->sum(sourceChannel, sourceStart, destinationStart, length);
|
|
288
|
+
getChannelByType(ChannelRight)
|
|
289
|
+
->sum(sourceChannel, sourceStart, destinationStart, length);
|
|
241
290
|
return;
|
|
242
291
|
}
|
|
243
292
|
|
|
244
293
|
// Mono to 5.1 (1 -> 6)
|
|
245
294
|
if (numberOfSourceChannels == 1 && numberOfChannels == 6) {
|
|
246
|
-
AudioArray*
|
|
295
|
+
AudioArray *sourceChannel = source->getChannel(0);
|
|
247
296
|
|
|
248
|
-
getChannelByType(ChannelCenter)
|
|
297
|
+
getChannelByType(ChannelCenter)
|
|
298
|
+
->sum(sourceChannel, sourceStart, destinationStart, length);
|
|
249
299
|
return;
|
|
250
300
|
}
|
|
251
301
|
|
|
252
302
|
// Stereo 2 to stereo 4 or 5.1 (2 -> 4, 6)
|
|
253
|
-
if (numberOfSourceChannels == 2 &&
|
|
254
|
-
|
|
255
|
-
getChannelByType(
|
|
303
|
+
if (numberOfSourceChannels == 2 &&
|
|
304
|
+
(numberOfChannels == 4 || numberOfChannels == 6)) {
|
|
305
|
+
getChannelByType(ChannelLeft)
|
|
306
|
+
->sum(
|
|
307
|
+
source->getChannelByType(ChannelLeft),
|
|
308
|
+
sourceStart,
|
|
309
|
+
destinationStart,
|
|
310
|
+
length);
|
|
311
|
+
getChannelByType(ChannelRight)
|
|
312
|
+
->sum(
|
|
313
|
+
source->getChannelByType(ChannelRight),
|
|
314
|
+
sourceStart,
|
|
315
|
+
destinationStart,
|
|
316
|
+
length);
|
|
256
317
|
return;
|
|
257
318
|
}
|
|
258
319
|
|
|
259
320
|
// Stereo 4 to 5.1 (4 -> 6)
|
|
260
321
|
if (numberOfSourceChannels == 4 && numberOfChannels == 6) {
|
|
261
|
-
getChannelByType(ChannelLeft)
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
322
|
+
getChannelByType(ChannelLeft)
|
|
323
|
+
->sum(
|
|
324
|
+
source->getChannelByType(ChannelLeft),
|
|
325
|
+
sourceStart,
|
|
326
|
+
destinationStart,
|
|
327
|
+
length);
|
|
328
|
+
getChannelByType(ChannelRight)
|
|
329
|
+
->sum(
|
|
330
|
+
source->getChannelByType(ChannelRight),
|
|
331
|
+
sourceStart,
|
|
332
|
+
destinationStart,
|
|
333
|
+
length);
|
|
334
|
+
getChannelByType(ChannelSurroundLeft)
|
|
335
|
+
->sum(
|
|
336
|
+
source->getChannelByType(ChannelSurroundLeft),
|
|
337
|
+
sourceStart,
|
|
338
|
+
destinationStart,
|
|
339
|
+
length);
|
|
340
|
+
getChannelByType(ChannelSurroundRight)
|
|
341
|
+
->sum(
|
|
342
|
+
source->getChannelByType(ChannelSurroundRight),
|
|
343
|
+
sourceStart,
|
|
344
|
+
destinationStart,
|
|
345
|
+
length);
|
|
265
346
|
return;
|
|
266
347
|
}
|
|
267
348
|
|
|
268
349
|
discreteSum(source, sourceStart, destinationStart, length);
|
|
269
350
|
}
|
|
270
351
|
|
|
271
|
-
void AudioBus::sumByDownMixing(
|
|
352
|
+
void AudioBus::sumByDownMixing(
|
|
353
|
+
const AudioBus *source,
|
|
354
|
+
int sourceStart,
|
|
355
|
+
int destinationStart,
|
|
356
|
+
int length) {
|
|
272
357
|
int numberOfSourceChannels = source->getNumberOfChannels();
|
|
273
358
|
int numberOfChannels = getNumberOfChannels();
|
|
274
359
|
|
|
275
360
|
// Stereo to mono (2 -> 1): output += 0.5 * (input.left + input.right).
|
|
276
361
|
if (numberOfSourceChannels == 2 && numberOfChannels == 1) {
|
|
277
|
-
float*
|
|
278
|
-
float*
|
|
279
|
-
|
|
280
|
-
float*
|
|
281
|
-
|
|
282
|
-
VectorMath::multiplyByScalarThenAddToOutput(
|
|
283
|
-
|
|
362
|
+
float *sourceLeft = source->getChannelByType(ChannelLeft)->getData();
|
|
363
|
+
float *sourceRight = source->getChannelByType(ChannelRight)->getData();
|
|
364
|
+
|
|
365
|
+
float *destinationData = getChannelByType(ChannelMono)->getData();
|
|
366
|
+
|
|
367
|
+
VectorMath::multiplyByScalarThenAddToOutput(
|
|
368
|
+
sourceLeft + sourceStart,
|
|
369
|
+
0.5f,
|
|
370
|
+
destinationData + destinationStart,
|
|
371
|
+
length);
|
|
372
|
+
VectorMath::multiplyByScalarThenAddToOutput(
|
|
373
|
+
sourceRight + sourceStart,
|
|
374
|
+
0.5f,
|
|
375
|
+
destinationData + destinationStart,
|
|
376
|
+
length);
|
|
284
377
|
return;
|
|
285
378
|
}
|
|
286
379
|
|
|
287
|
-
// Stereo 4 to mono: output += 0.25 * (input.left + input.right +
|
|
380
|
+
// Stereo 4 to mono: output += 0.25 * (input.left + input.right +
|
|
381
|
+
// input.surroundLeft + input.surroundRight)
|
|
288
382
|
if (numberOfSourceChannels == 4 && numberOfChannels == 1) {
|
|
289
|
-
float*
|
|
290
|
-
float*
|
|
291
|
-
float*
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
VectorMath::multiplyByScalarThenAddToOutput(
|
|
299
|
-
|
|
383
|
+
float *sourceLeft = source->getChannelByType(ChannelLeft)->getData();
|
|
384
|
+
float *sourceRight = source->getChannelByType(ChannelRight)->getData();
|
|
385
|
+
float *sourceSurroundLeft =
|
|
386
|
+
source->getChannelByType(ChannelSurroundLeft)->getData();
|
|
387
|
+
float *sourceSurroundRight =
|
|
388
|
+
source->getChannelByType(ChannelSurroundRight)->getData();
|
|
389
|
+
|
|
390
|
+
float *destinationData = getChannelByType(ChannelMono)->getData();
|
|
391
|
+
|
|
392
|
+
VectorMath::multiplyByScalarThenAddToOutput(
|
|
393
|
+
sourceLeft + sourceStart,
|
|
394
|
+
0.25f,
|
|
395
|
+
destinationData + destinationStart,
|
|
396
|
+
length);
|
|
397
|
+
VectorMath::multiplyByScalarThenAddToOutput(
|
|
398
|
+
sourceRight + sourceStart,
|
|
399
|
+
0.25f,
|
|
400
|
+
destinationData + destinationStart,
|
|
401
|
+
length);
|
|
402
|
+
VectorMath::multiplyByScalarThenAddToOutput(
|
|
403
|
+
sourceSurroundLeft + sourceStart,
|
|
404
|
+
0.25f,
|
|
405
|
+
destinationData + destinationStart,
|
|
406
|
+
length);
|
|
407
|
+
VectorMath::multiplyByScalarThenAddToOutput(
|
|
408
|
+
sourceSurroundRight + sourceStart,
|
|
409
|
+
0.25f,
|
|
410
|
+
destinationData + destinationStart,
|
|
411
|
+
length);
|
|
300
412
|
return;
|
|
301
413
|
}
|
|
302
414
|
|
|
303
415
|
// 5.1 to stereo:
|
|
304
416
|
// output.left += input.left + sqrt(1/2) * (input.center + input.surroundLeft)
|
|
305
|
-
// output.right += input.right + sqrt(1/2) * (input.center +
|
|
417
|
+
// output.right += input.right + sqrt(1/2) * (input.center +
|
|
418
|
+
// input.surroundRight)
|
|
306
419
|
if (numberOfSourceChannels == 6 && numberOfChannels == 2) {
|
|
307
|
-
float*
|
|
308
|
-
float*
|
|
309
|
-
float*
|
|
310
|
-
float*
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
VectorMath::
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
420
|
+
float *sourceLeft = source->getChannelByType(ChannelLeft)->getData();
|
|
421
|
+
float *sourceRight = source->getChannelByType(ChannelRight)->getData();
|
|
422
|
+
float *sourceCenter = source->getChannelByType(ChannelCenter)->getData();
|
|
423
|
+
float *sourceSurroundLeft =
|
|
424
|
+
source->getChannelByType(ChannelSurroundLeft)->getData();
|
|
425
|
+
float *sourceSurroundRight =
|
|
426
|
+
source->getChannelByType(ChannelSurroundRight)->getData();
|
|
427
|
+
|
|
428
|
+
float *destinationLeft = getChannelByType(ChannelLeft)->getData();
|
|
429
|
+
float *destinationRight = getChannelByType(ChannelRight)->getData();
|
|
430
|
+
|
|
431
|
+
VectorMath::add(
|
|
432
|
+
sourceLeft + sourceStart,
|
|
433
|
+
destinationLeft + destinationStart,
|
|
434
|
+
destinationLeft + destinationStart,
|
|
435
|
+
length);
|
|
436
|
+
VectorMath::multiplyByScalarThenAddToOutput(
|
|
437
|
+
sourceCenter + sourceStart,
|
|
438
|
+
SQRT_HALF,
|
|
439
|
+
destinationLeft + destinationStart,
|
|
440
|
+
length);
|
|
441
|
+
VectorMath::multiplyByScalarThenAddToOutput(
|
|
442
|
+
sourceSurroundLeft + sourceStart,
|
|
443
|
+
SQRT_HALF,
|
|
444
|
+
destinationLeft + destinationStart,
|
|
445
|
+
length);
|
|
446
|
+
|
|
447
|
+
VectorMath::add(
|
|
448
|
+
sourceRight + sourceStart,
|
|
449
|
+
destinationRight + destinationStart,
|
|
450
|
+
destinationRight + destinationStart,
|
|
451
|
+
length);
|
|
452
|
+
VectorMath::multiplyByScalarThenAddToOutput(
|
|
453
|
+
sourceCenter + sourceStart,
|
|
454
|
+
SQRT_HALF,
|
|
455
|
+
destinationRight + destinationStart,
|
|
456
|
+
length);
|
|
457
|
+
VectorMath::multiplyByScalarThenAddToOutput(
|
|
458
|
+
sourceSurroundRight + sourceStart,
|
|
459
|
+
SQRT_HALF,
|
|
460
|
+
destinationRight + destinationStart,
|
|
461
|
+
length);
|
|
323
462
|
return;
|
|
324
463
|
}
|
|
325
464
|
|
|
@@ -329,25 +468,47 @@ void AudioBus::sumByDownMixing(const AudioBus *source, int sourceStart, int dest
|
|
|
329
468
|
// output.surroundLeft += input.surroundLeft
|
|
330
469
|
// output.surroundRight += input.surroundRight
|
|
331
470
|
if (numberOfSourceChannels == 6 && numberOfChannels == 4) {
|
|
332
|
-
float*
|
|
333
|
-
float*
|
|
334
|
-
float*
|
|
335
|
-
float*
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
float*
|
|
341
|
-
float*
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
VectorMath::
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
471
|
+
float *sourceLeft = source->getChannelByType(ChannelLeft)->getData();
|
|
472
|
+
float *sourceRight = source->getChannelByType(ChannelRight)->getData();
|
|
473
|
+
float *sourceCenter = source->getChannelByType(ChannelCenter)->getData();
|
|
474
|
+
float *sourceSurroundLeft =
|
|
475
|
+
source->getChannelByType(ChannelSurroundLeft)->getData();
|
|
476
|
+
float *sourceSurroundRight =
|
|
477
|
+
source->getChannelByType(ChannelSurroundRight)->getData();
|
|
478
|
+
|
|
479
|
+
float *destinationLeft = getChannelByType(ChannelLeft)->getData();
|
|
480
|
+
float *destinationRight = getChannelByType(ChannelRight)->getData();
|
|
481
|
+
float *destinationSurroundLeft =
|
|
482
|
+
getChannelByType(ChannelSurroundLeft)->getData();
|
|
483
|
+
float *destinationSurroundRight =
|
|
484
|
+
getChannelByType(ChannelSurroundRight)->getData();
|
|
485
|
+
|
|
486
|
+
VectorMath::add(
|
|
487
|
+
sourceLeft + sourceStart,
|
|
488
|
+
destinationLeft + destinationStart,
|
|
489
|
+
destinationLeft + destinationStart,
|
|
490
|
+
length);
|
|
491
|
+
VectorMath::multiplyByScalarThenAddToOutput(
|
|
492
|
+
sourceCenter, SQRT_HALF, destinationLeft + destinationStart, length);
|
|
493
|
+
|
|
494
|
+
VectorMath::add(
|
|
495
|
+
sourceRight + sourceStart,
|
|
496
|
+
destinationRight + destinationStart,
|
|
497
|
+
destinationRight + destinationStart,
|
|
498
|
+
length);
|
|
499
|
+
VectorMath::multiplyByScalarThenAddToOutput(
|
|
500
|
+
sourceCenter, SQRT_HALF, destinationRight + destinationStart, length);
|
|
501
|
+
|
|
502
|
+
VectorMath::add(
|
|
503
|
+
sourceSurroundLeft + sourceStart,
|
|
504
|
+
destinationSurroundLeft + destinationStart,
|
|
505
|
+
destinationSurroundLeft + destinationStart,
|
|
506
|
+
length);
|
|
507
|
+
VectorMath::add(
|
|
508
|
+
sourceSurroundRight + sourceStart,
|
|
509
|
+
destinationSurroundRight + destinationStart,
|
|
510
|
+
destinationSurroundRight + destinationStart,
|
|
511
|
+
length);
|
|
351
512
|
return;
|
|
352
513
|
}
|
|
353
514
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
|
+
#include <algorithm>
|
|
3
4
|
#include <memory>
|
|
4
5
|
#include <vector>
|
|
5
|
-
#include <algorithm>
|
|
6
6
|
|
|
7
7
|
namespace audioapi {
|
|
8
8
|
|
|
@@ -29,23 +29,31 @@ class AudioBus {
|
|
|
29
29
|
[[nodiscard]] int getNumberOfChannels() const;
|
|
30
30
|
[[nodiscard]] int getSampleRate() const;
|
|
31
31
|
[[nodiscard]] int getSize() const;
|
|
32
|
-
AudioArray*
|
|
33
|
-
AudioArray*
|
|
32
|
+
[[nodiscard]] AudioArray *getChannel(int index) const;
|
|
33
|
+
[[nodiscard]] AudioArray *getChannelByType(int channelType) const;
|
|
34
34
|
|
|
35
35
|
void normalize();
|
|
36
36
|
void scale(float value);
|
|
37
|
-
float maxAbsValue() const;
|
|
37
|
+
[[nodiscard]] float maxAbsValue() const;
|
|
38
38
|
|
|
39
39
|
void zero();
|
|
40
40
|
void zero(int start, int length);
|
|
41
41
|
|
|
42
42
|
void sum(const AudioBus *source);
|
|
43
43
|
void sum(const AudioBus *source, int start, int length);
|
|
44
|
-
void sum(
|
|
44
|
+
void sum(
|
|
45
|
+
const AudioBus *source,
|
|
46
|
+
int sourceStart,
|
|
47
|
+
int destinationStart,
|
|
48
|
+
int length);
|
|
45
49
|
|
|
46
50
|
void copy(const AudioBus *source);
|
|
47
51
|
void copy(const AudioBus *source, int start, int length);
|
|
48
|
-
void copy(
|
|
52
|
+
void copy(
|
|
53
|
+
const AudioBus *source,
|
|
54
|
+
int sourceStart,
|
|
55
|
+
int destinationStart,
|
|
56
|
+
int length);
|
|
49
57
|
|
|
50
58
|
private:
|
|
51
59
|
std::vector<std::shared_ptr<AudioArray>> channels_;
|
|
@@ -55,9 +63,21 @@ class AudioBus {
|
|
|
55
63
|
int size_;
|
|
56
64
|
|
|
57
65
|
void createChannels();
|
|
58
|
-
void discreteSum(
|
|
59
|
-
|
|
60
|
-
|
|
66
|
+
void discreteSum(
|
|
67
|
+
const AudioBus *source,
|
|
68
|
+
int sourceStart,
|
|
69
|
+
int destinationStart,
|
|
70
|
+
int length) const;
|
|
71
|
+
void sumByUpMixing(
|
|
72
|
+
const AudioBus *source,
|
|
73
|
+
int sourceStart,
|
|
74
|
+
int destinationStart,
|
|
75
|
+
int length);
|
|
76
|
+
void sumByDownMixing(
|
|
77
|
+
const AudioBus *source,
|
|
78
|
+
int sourceStart,
|
|
79
|
+
int destinationStart,
|
|
80
|
+
int length);
|
|
61
81
|
};
|
|
62
82
|
|
|
63
83
|
} // namespace audioapi
|
|
@@ -6,19 +6,15 @@
|
|
|
6
6
|
|
|
7
7
|
#include "AudioContext.h"
|
|
8
8
|
|
|
9
|
-
|
|
10
9
|
namespace audioapi {
|
|
11
10
|
|
|
12
|
-
AudioContext::AudioContext() : BaseAudioContext() {
|
|
11
|
+
AudioContext::AudioContext() : BaseAudioContext() {
|
|
12
|
+
audioPlayer_->start();
|
|
13
|
+
}
|
|
13
14
|
|
|
14
15
|
void AudioContext::close() {
|
|
15
16
|
state_ = ContextState::CLOSED;
|
|
16
|
-
|
|
17
|
-
if (audioPlayer_) {
|
|
18
|
-
audioPlayer_->stop();
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
audioPlayer_.reset();
|
|
22
|
-
destination_.reset();
|
|
17
|
+
audioPlayer_->stop();
|
|
23
18
|
}
|
|
19
|
+
|
|
24
20
|
} // namespace audioapi
|