react-native-audio-api 0.11.0-nightly-141c86f-20251118 → 0.11.0-nightly-4e6f25c-20251119
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/audioapi/android/AudioAPIModule.cpp +10 -16
- package/android/src/main/cpp/audioapi/android/OnLoad.cpp +1 -2
- package/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.cpp +4 -4
- package/android/src/main/cpp/audioapi/android/core/AudioPlayer.cpp +11 -20
- package/android/src/main/cpp/audioapi/android/core/utils/AudioDecoder.cpp +24 -46
- package/common/cpp/audioapi/AudioAPIModuleInstaller.h +48 -78
- package/common/cpp/audioapi/HostObjects/AudioContextHostObject.cpp +20 -21
- package/common/cpp/audioapi/HostObjects/AudioNodeHostObject.cpp +3 -4
- package/common/cpp/audioapi/HostObjects/AudioParamHostObject.cpp +6 -8
- package/common/cpp/audioapi/HostObjects/AudioParamHostObject.h +2 -2
- package/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.cpp +42 -78
- package/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.h +1 -1
- package/common/cpp/audioapi/HostObjects/OfflineAudioContextHostObject.cpp +14 -18
- package/common/cpp/audioapi/HostObjects/OfflineAudioContextHostObject.h +3 -3
- package/common/cpp/audioapi/HostObjects/WorkletNodeHostObject.h +1 -2
- package/common/cpp/audioapi/HostObjects/WorkletProcessingNodeHostObject.h +1 -2
- package/common/cpp/audioapi/HostObjects/analysis/AnalyserNodeHostObject.cpp +10 -18
- package/common/cpp/audioapi/HostObjects/destinations/AudioDestinationNodeHostObject.h +2 -3
- package/common/cpp/audioapi/HostObjects/effects/BiquadFilterNodeHostObject.cpp +16 -28
- package/common/cpp/audioapi/HostObjects/effects/BiquadFilterNodeHostObject.h +1 -2
- package/common/cpp/audioapi/HostObjects/effects/ConvolverNodeHostObject.cpp +4 -6
- package/common/cpp/audioapi/HostObjects/effects/GainNodeHostObject.cpp +2 -2
- package/common/cpp/audioapi/HostObjects/effects/PeriodicWaveHostObject.h +1 -2
- package/common/cpp/audioapi/HostObjects/effects/StereoPannerNodeHostObject.cpp +2 -2
- package/common/cpp/audioapi/HostObjects/effects/StereoPannerNodeHostObject.h +1 -2
- package/common/cpp/audioapi/HostObjects/events/AudioEventHandlerRegistryHostObject.cpp +6 -12
- package/common/cpp/audioapi/HostObjects/events/AudioEventHandlerRegistryHostObject.h +7 -7
- package/common/cpp/audioapi/HostObjects/inputs/AudioRecorderHostObject.cpp +8 -10
- package/common/cpp/audioapi/HostObjects/inputs/AudioRecorderHostObject.h +1 -1
- package/common/cpp/audioapi/HostObjects/sources/AudioBufferBaseSourceNodeHostObject.cpp +13 -27
- package/common/cpp/audioapi/HostObjects/sources/AudioBufferBaseSourceNodeHostObject.h +11 -12
- package/common/cpp/audioapi/HostObjects/sources/AudioBufferHostObject.cpp +15 -22
- package/common/cpp/audioapi/HostObjects/sources/AudioBufferHostObject.h +5 -7
- package/common/cpp/audioapi/HostObjects/sources/AudioBufferQueueSourceNodeHostObject.cpp +7 -12
- package/common/cpp/audioapi/HostObjects/sources/AudioBufferQueueSourceNodeHostObject.h +8 -9
- package/common/cpp/audioapi/HostObjects/sources/AudioBufferSourceNodeHostObject.cpp +16 -30
- package/common/cpp/audioapi/HostObjects/sources/AudioBufferSourceNodeHostObject.h +2 -4
- package/common/cpp/audioapi/HostObjects/sources/AudioScheduledSourceNodeHostObject.cpp +6 -10
- package/common/cpp/audioapi/HostObjects/sources/ConstantSourceNodeHostObject.cpp +2 -2
- package/common/cpp/audioapi/HostObjects/sources/ConstantSourceNodeHostObject.h +1 -2
- package/common/cpp/audioapi/HostObjects/sources/OscillatorNodeHostObject.cpp +6 -8
- package/common/cpp/audioapi/HostObjects/sources/OscillatorNodeHostObject.h +1 -2
- package/common/cpp/audioapi/HostObjects/sources/RecorderAdapterNodeHostObject.h +4 -5
- package/common/cpp/audioapi/HostObjects/sources/StreamerNodeHostObject.cpp +2 -2
- package/common/cpp/audioapi/HostObjects/sources/StreamerNodeHostObject.h +5 -6
- package/common/cpp/audioapi/HostObjects/sources/WorkletSourceNodeHostObject.h +1 -2
- package/common/cpp/audioapi/HostObjects/utils/AudioDecoderHostObject.cpp +39 -60
- package/common/cpp/audioapi/HostObjects/utils/AudioStretcherHostObject.cpp +4 -8
- package/common/cpp/audioapi/core/AudioContext.cpp +4 -4
- package/common/cpp/audioapi/core/AudioContext.h +5 -2
- package/common/cpp/audioapi/core/AudioNode.cpp +13 -19
- package/common/cpp/audioapi/core/AudioNode.h +14 -7
- package/common/cpp/audioapi/core/AudioParam.cpp +66 -98
- package/common/cpp/audioapi/core/AudioParam.h +20 -12
- package/common/cpp/audioapi/core/BaseAudioContext.cpp +22 -34
- package/common/cpp/audioapi/core/BaseAudioContext.h +19 -15
- package/common/cpp/audioapi/core/OfflineAudioContext.cpp +12 -17
- package/common/cpp/audioapi/core/OfflineAudioContext.h +10 -5
- package/common/cpp/audioapi/core/analysis/AnalyserNode.cpp +13 -21
- package/common/cpp/audioapi/core/analysis/AnalyserNode.h +8 -6
- package/common/cpp/audioapi/core/destinations/AudioDestinationNode.cpp +1 -0
- package/common/cpp/audioapi/core/destinations/AudioDestinationNode.h +5 -3
- package/common/cpp/audioapi/core/effects/BiquadFilterNode.cpp +17 -36
- package/common/cpp/audioapi/core/effects/BiquadFilterNode.h +2 -9
- package/common/cpp/audioapi/core/effects/ConvolverNode.cpp +18 -28
- package/common/cpp/audioapi/core/effects/ConvolverNode.h +19 -10
- package/common/cpp/audioapi/core/effects/GainNode.cpp +1 -0
- package/common/cpp/audioapi/core/effects/GainNode.h +3 -1
- package/common/cpp/audioapi/core/effects/PeriodicWave.cpp +22 -35
- package/common/cpp/audioapi/core/effects/PeriodicWave.h +4 -9
- package/common/cpp/audioapi/core/effects/StereoPannerNode.cpp +4 -5
- package/common/cpp/audioapi/core/effects/StereoPannerNode.h +4 -2
- package/common/cpp/audioapi/core/effects/WorkletNode.cpp +11 -13
- package/common/cpp/audioapi/core/effects/WorkletNode.h +15 -12
- package/common/cpp/audioapi/core/effects/WorkletProcessingNode.cpp +4 -4
- package/common/cpp/audioapi/core/effects/WorkletProcessingNode.h +15 -14
- package/common/cpp/audioapi/core/inputs/AudioRecorder.cpp +9 -8
- package/common/cpp/audioapi/core/inputs/AudioRecorder.h +4 -5
- package/common/cpp/audioapi/core/sources/AudioBuffer.cpp +4 -6
- package/common/cpp/audioapi/core/sources/AudioBuffer.h +4 -7
- package/common/cpp/audioapi/core/sources/AudioBufferBaseSourceNode.cpp +31 -53
- package/common/cpp/audioapi/core/sources/AudioBufferBaseSourceNode.h +35 -33
- package/common/cpp/audioapi/core/sources/AudioBufferQueueSourceNode.cpp +19 -20
- package/common/cpp/audioapi/core/sources/AudioBufferQueueSourceNode.h +38 -36
- package/common/cpp/audioapi/core/sources/AudioBufferSourceNode.cpp +25 -40
- package/common/cpp/audioapi/core/sources/AudioBufferSourceNode.h +3 -1
- package/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.cpp +9 -9
- package/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.h +3 -3
- package/common/cpp/audioapi/core/sources/ConstantSourceNode.cpp +3 -4
- package/common/cpp/audioapi/core/sources/ConstantSourceNode.h +3 -1
- package/common/cpp/audioapi/core/sources/OscillatorNode.cpp +12 -23
- package/common/cpp/audioapi/core/sources/OscillatorNode.h +6 -4
- package/common/cpp/audioapi/core/sources/RecorderAdapterNode.cpp +3 -4
- package/common/cpp/audioapi/core/sources/RecorderAdapterNode.h +18 -16
- package/common/cpp/audioapi/core/sources/StreamerNode.cpp +7 -4
- package/common/cpp/audioapi/core/sources/StreamerNode.h +38 -30
- package/common/cpp/audioapi/core/sources/WorkletSourceNode.cpp +5 -7
- package/common/cpp/audioapi/core/sources/WorkletSourceNode.h +15 -13
- package/common/cpp/audioapi/core/types/AudioFormat.h +1 -11
- package/common/cpp/audioapi/core/utils/AudioDecoder.h +15 -6
- package/common/cpp/audioapi/core/utils/AudioNodeDestructor.cpp +5 -6
- package/common/cpp/audioapi/core/utils/AudioNodeDestructor.h +7 -10
- package/common/cpp/audioapi/core/utils/AudioNodeManager.cpp +13 -22
- package/common/cpp/audioapi/core/utils/AudioNodeManager.h +8 -11
- package/common/cpp/audioapi/core/utils/AudioParamEventQueue.cpp +3 -3
- package/common/cpp/audioapi/core/utils/AudioParamEventQueue.h +5 -5
- package/common/cpp/audioapi/core/utils/AudioStretcher.cpp +6 -6
- package/common/cpp/audioapi/core/utils/Constants.h +5 -3
- package/common/cpp/audioapi/core/utils/ParamChangeEvent.cpp +1 -0
- package/common/cpp/audioapi/core/utils/ParamChangeEvent.h +9 -9
- package/common/cpp/audioapi/core/utils/worklets/SafeIncludes.h +29 -34
- package/common/cpp/audioapi/core/utils/worklets/WorkletsRunner.cpp +14 -16
- package/common/cpp/audioapi/core/utils/worklets/WorkletsRunner.h +23 -19
- package/common/cpp/audioapi/dsp/AudioUtils.cpp +3 -9
- package/common/cpp/audioapi/dsp/AudioUtils.h +1 -1
- package/common/cpp/audioapi/dsp/Convolver.cpp +13 -25
- package/common/cpp/audioapi/dsp/Convolver.h +26 -24
- package/common/cpp/audioapi/dsp/FFT.cpp +1 -1
- package/common/cpp/audioapi/dsp/FFT.h +5 -13
- package/common/cpp/audioapi/dsp/VectorMath.cpp +9 -43
- package/common/cpp/audioapi/dsp/VectorMath.h +35 -8
- package/common/cpp/audioapi/dsp/Windows.cpp +4 -9
- package/common/cpp/audioapi/dsp/Windows.h +24 -23
- package/common/cpp/audioapi/events/AudioEventHandlerRegistry.cpp +12 -17
- package/common/cpp/audioapi/events/AudioEventHandlerRegistry.h +44 -39
- package/common/cpp/audioapi/events/IAudioEventHandlerRegistry.h +15 -7
- package/common/cpp/audioapi/jsi/AudioArrayBuffer.h +4 -5
- package/common/cpp/audioapi/jsi/JsiHostObject.cpp +11 -13
- package/common/cpp/audioapi/jsi/JsiHostObject.h +26 -33
- package/common/cpp/audioapi/jsi/JsiPromise.cpp +11 -21
- package/common/cpp/audioapi/jsi/JsiPromise.h +55 -46
- package/common/cpp/audioapi/jsi/RuntimeLifecycleMonitor.cpp +7 -10
- package/common/cpp/audioapi/jsi/RuntimeLifecycleMonitor.h +1 -3
- package/common/cpp/audioapi/utils/AudioArray.cpp +3 -8
- package/common/cpp/audioapi/utils/AudioArray.h +3 -11
- package/common/cpp/audioapi/utils/AudioBus.cpp +51 -149
- package/common/cpp/audioapi/utils/AudioBus.h +15 -15
- package/common/cpp/audioapi/utils/CircularAudioArray.cpp +6 -18
- package/common/cpp/audioapi/utils/CircularOverflowableAudioArray.cpp +6 -10
- package/common/cpp/audioapi/utils/CircularOverflowableAudioArray.h +2 -2
- package/common/cpp/test/src/AudioParamTest.cpp +3 -2
- package/common/cpp/test/src/AudioScheduledSourceTest.cpp +14 -35
- package/common/cpp/test/src/ConstantSourceTest.cpp +4 -6
- package/common/cpp/test/src/GainTest.cpp +3 -4
- package/common/cpp/test/src/MockAudioEventHandlerRegistry.h +19 -11
- package/common/cpp/test/src/OscillatorTest.cpp +1 -0
- package/common/cpp/test/src/StereoPannerTest.cpp +5 -8
- package/common/cpp/test/src/biquad/BiquadFilterChromium.cpp +10 -27
- package/common/cpp/test/src/biquad/BiquadFilterChromium.h +7 -6
- package/common/cpp/test/src/biquad/BiquadFilterTest.cpp +16 -28
- package/common/cpp/test/src/biquad/BiquadFilterTest.h +13 -6
- package/ios/audioapi/ios/AudioAPIModule.h +4 -6
- package/ios/audioapi/ios/AudioAPIModule.mm +31 -46
- package/ios/audioapi/ios/core/IOSAudioPlayer.mm +24 -33
- package/ios/audioapi/ios/core/IOSAudioRecorder.h +1 -2
- package/ios/audioapi/ios/core/IOSAudioRecorder.mm +4 -6
- package/ios/audioapi/ios/core/NativeAudioPlayer.m +3 -5
- package/ios/audioapi/ios/core/NativeAudioRecorder.h +1 -2
- package/ios/audioapi/ios/core/NativeAudioRecorder.m +21 -33
- package/ios/audioapi/ios/core/utils/AudioDecoder.mm +17 -37
- package/ios/audioapi/ios/system/AudioEngine.h +2 -4
- package/ios/audioapi/ios/system/AudioEngine.mm +7 -19
- package/ios/audioapi/ios/system/AudioSessionManager.h +2 -4
- package/ios/audioapi/ios/system/AudioSessionManager.mm +17 -32
- package/ios/audioapi/ios/system/LockScreenManager.mm +73 -105
- package/ios/audioapi/ios/system/NotificationManager.mm +43 -68
- package/package.json +2 -2
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
#include <audioapi/dsp/VectorMath.h>
|
|
3
3
|
#include <audioapi/utils/AudioArray.h>
|
|
4
4
|
#include <audioapi/utils/AudioBus.h>
|
|
5
|
+
#include <algorithm>
|
|
6
|
+
#include <memory>
|
|
7
|
+
#include <utility>
|
|
8
|
+
#include <vector>
|
|
5
9
|
|
|
6
10
|
// Implementation of channel summing/mixing is based on the WebKit approach,
|
|
7
11
|
// source:
|
|
@@ -16,9 +20,7 @@ namespace audioapi {
|
|
|
16
20
|
*/
|
|
17
21
|
|
|
18
22
|
AudioBus::AudioBus(size_t size, int numberOfChannels, float sampleRate)
|
|
19
|
-
: numberOfChannels_(numberOfChannels),
|
|
20
|
-
sampleRate_(sampleRate),
|
|
21
|
-
size_(size) {
|
|
23
|
+
: numberOfChannels_(numberOfChannels), sampleRate_(sampleRate), size_(size) {
|
|
22
24
|
createChannels();
|
|
23
25
|
}
|
|
24
26
|
|
|
@@ -210,9 +212,7 @@ float AudioBus::maxAbsValue() const {
|
|
|
210
212
|
return maxAbsValue;
|
|
211
213
|
}
|
|
212
214
|
|
|
213
|
-
void AudioBus::sum(
|
|
214
|
-
const AudioBus *source,
|
|
215
|
-
ChannelInterpretation interpretation) {
|
|
215
|
+
void AudioBus::sum(const AudioBus *source, ChannelInterpretation interpretation) {
|
|
216
216
|
sum(source, 0, 0, getSize(), interpretation);
|
|
217
217
|
}
|
|
218
218
|
|
|
@@ -256,8 +256,7 @@ void AudioBus::sum(
|
|
|
256
256
|
|
|
257
257
|
// Source and destination channel counts are the same. Just sum the channels.
|
|
258
258
|
for (int i = 0; i < numberOfChannels_; i += 1) {
|
|
259
|
-
getChannel(i)->sum(
|
|
260
|
-
source->getChannel(i), sourceStart, destinationStart, length);
|
|
259
|
+
getChannel(i)->sum(source->getChannel(i), sourceStart, destinationStart, length);
|
|
261
260
|
}
|
|
262
261
|
}
|
|
263
262
|
|
|
@@ -280,8 +279,7 @@ void AudioBus::copy(
|
|
|
280
279
|
|
|
281
280
|
if (source->getNumberOfChannels() == getNumberOfChannels()) {
|
|
282
281
|
for (int i = 0; i < getNumberOfChannels(); i += 1) {
|
|
283
|
-
getChannel(i)->copy(
|
|
284
|
-
source->getChannel(i), sourceStart, destinationStart, length);
|
|
282
|
+
getChannel(i)->copy(source->getChannel(i), sourceStart, destinationStart, length);
|
|
285
283
|
}
|
|
286
284
|
|
|
287
285
|
return;
|
|
@@ -313,15 +311,13 @@ void AudioBus::discreteSum(
|
|
|
313
311
|
size_t sourceStart,
|
|
314
312
|
size_t destinationStart,
|
|
315
313
|
size_t length) const {
|
|
316
|
-
int numberOfChannels =
|
|
317
|
-
std::min(getNumberOfChannels(), source->getNumberOfChannels());
|
|
314
|
+
int numberOfChannels = std::min(getNumberOfChannels(), source->getNumberOfChannels());
|
|
318
315
|
|
|
319
316
|
// In case of source > destination, we "down-mix" and drop the extra channels.
|
|
320
317
|
// In case of source < destination, we "up-mix" as many channels as we have,
|
|
321
318
|
// leaving the remaining channels untouched.
|
|
322
319
|
for (int i = 0; i < numberOfChannels; i++) {
|
|
323
|
-
getChannel(i)->sum(
|
|
324
|
-
source->getChannel(i), sourceStart, destinationStart, length);
|
|
320
|
+
getChannel(i)->sum(source->getChannel(i), sourceStart, destinationStart, length);
|
|
325
321
|
}
|
|
326
322
|
}
|
|
327
323
|
|
|
@@ -334,14 +330,11 @@ void AudioBus::sumByUpMixing(
|
|
|
334
330
|
int numberOfChannels = getNumberOfChannels();
|
|
335
331
|
|
|
336
332
|
// Mono to stereo (1 -> 2, 4)
|
|
337
|
-
if (numberOfSourceChannels == 1 &&
|
|
338
|
-
(numberOfChannels == 2 || numberOfChannels == 4)) {
|
|
333
|
+
if (numberOfSourceChannels == 1 && (numberOfChannels == 2 || numberOfChannels == 4)) {
|
|
339
334
|
AudioArray *sourceChannel = source->getChannelByType(ChannelMono);
|
|
340
335
|
|
|
341
|
-
getChannelByType(ChannelLeft)
|
|
342
|
-
|
|
343
|
-
getChannelByType(ChannelRight)
|
|
344
|
-
->sum(sourceChannel, sourceStart, destinationStart, length);
|
|
336
|
+
getChannelByType(ChannelLeft)->sum(sourceChannel, sourceStart, destinationStart, length);
|
|
337
|
+
getChannelByType(ChannelRight)->sum(sourceChannel, sourceStart, destinationStart, length);
|
|
345
338
|
return;
|
|
346
339
|
}
|
|
347
340
|
|
|
@@ -349,55 +342,30 @@ void AudioBus::sumByUpMixing(
|
|
|
349
342
|
if (numberOfSourceChannels == 1 && numberOfChannels == 6) {
|
|
350
343
|
AudioArray *sourceChannel = source->getChannel(0);
|
|
351
344
|
|
|
352
|
-
getChannelByType(ChannelCenter)
|
|
353
|
-
->sum(sourceChannel, sourceStart, destinationStart, length);
|
|
345
|
+
getChannelByType(ChannelCenter)->sum(sourceChannel, sourceStart, destinationStart, length);
|
|
354
346
|
return;
|
|
355
347
|
}
|
|
356
348
|
|
|
357
349
|
// Stereo 2 to stereo 4 or 5.1 (2 -> 4, 6)
|
|
358
|
-
if (numberOfSourceChannels == 2 &&
|
|
359
|
-
(numberOfChannels == 4 || numberOfChannels == 6)) {
|
|
350
|
+
if (numberOfSourceChannels == 2 && (numberOfChannels == 4 || numberOfChannels == 6)) {
|
|
360
351
|
getChannelByType(ChannelLeft)
|
|
361
|
-
->sum(
|
|
362
|
-
source->getChannelByType(ChannelLeft),
|
|
363
|
-
sourceStart,
|
|
364
|
-
destinationStart,
|
|
365
|
-
length);
|
|
352
|
+
->sum(source->getChannelByType(ChannelLeft), sourceStart, destinationStart, length);
|
|
366
353
|
getChannelByType(ChannelRight)
|
|
367
|
-
->sum(
|
|
368
|
-
source->getChannelByType(ChannelRight),
|
|
369
|
-
sourceStart,
|
|
370
|
-
destinationStart,
|
|
371
|
-
length);
|
|
354
|
+
->sum(source->getChannelByType(ChannelRight), sourceStart, destinationStart, length);
|
|
372
355
|
return;
|
|
373
356
|
}
|
|
374
357
|
|
|
375
358
|
// Stereo 4 to 5.1 (4 -> 6)
|
|
376
359
|
if (numberOfSourceChannels == 4 && numberOfChannels == 6) {
|
|
377
360
|
getChannelByType(ChannelLeft)
|
|
378
|
-
->sum(
|
|
379
|
-
source->getChannelByType(ChannelLeft),
|
|
380
|
-
sourceStart,
|
|
381
|
-
destinationStart,
|
|
382
|
-
length);
|
|
361
|
+
->sum(source->getChannelByType(ChannelLeft), sourceStart, destinationStart, length);
|
|
383
362
|
getChannelByType(ChannelRight)
|
|
384
|
-
->sum(
|
|
385
|
-
source->getChannelByType(ChannelRight),
|
|
386
|
-
sourceStart,
|
|
387
|
-
destinationStart,
|
|
388
|
-
length);
|
|
363
|
+
->sum(source->getChannelByType(ChannelRight), sourceStart, destinationStart, length);
|
|
389
364
|
getChannelByType(ChannelSurroundLeft)
|
|
390
|
-
->sum(
|
|
391
|
-
source->getChannelByType(ChannelSurroundLeft),
|
|
392
|
-
sourceStart,
|
|
393
|
-
destinationStart,
|
|
394
|
-
length);
|
|
365
|
+
->sum(source->getChannelByType(ChannelSurroundLeft), sourceStart, destinationStart, length);
|
|
395
366
|
getChannelByType(ChannelSurroundRight)
|
|
396
367
|
->sum(
|
|
397
|
-
source->getChannelByType(ChannelSurroundRight),
|
|
398
|
-
sourceStart,
|
|
399
|
-
destinationStart,
|
|
400
|
-
length);
|
|
368
|
+
source->getChannelByType(ChannelSurroundRight), sourceStart, destinationStart, length);
|
|
401
369
|
return;
|
|
402
370
|
}
|
|
403
371
|
|
|
@@ -420,15 +388,9 @@ void AudioBus::sumByDownMixing(
|
|
|
420
388
|
float *destinationData = getChannelByType(ChannelMono)->getData();
|
|
421
389
|
|
|
422
390
|
dsp::multiplyByScalarThenAddToOutput(
|
|
423
|
-
sourceLeft + sourceStart,
|
|
424
|
-
0.5f,
|
|
425
|
-
destinationData + destinationStart,
|
|
426
|
-
length);
|
|
391
|
+
sourceLeft + sourceStart, 0.5f, destinationData + destinationStart, length);
|
|
427
392
|
dsp::multiplyByScalarThenAddToOutput(
|
|
428
|
-
sourceRight + sourceStart,
|
|
429
|
-
0.5f,
|
|
430
|
-
destinationData + destinationStart,
|
|
431
|
-
length);
|
|
393
|
+
sourceRight + sourceStart, 0.5f, destinationData + destinationStart, length);
|
|
432
394
|
return;
|
|
433
395
|
}
|
|
434
396
|
|
|
@@ -438,33 +400,19 @@ void AudioBus::sumByDownMixing(
|
|
|
438
400
|
if (numberOfSourceChannels == 4 && numberOfChannels == 1) {
|
|
439
401
|
float *sourceLeft = source->getChannelByType(ChannelLeft)->getData();
|
|
440
402
|
float *sourceRight = source->getChannelByType(ChannelRight)->getData();
|
|
441
|
-
float *sourceSurroundLeft =
|
|
442
|
-
|
|
443
|
-
float *sourceSurroundRight =
|
|
444
|
-
source->getChannelByType(ChannelSurroundRight)->getData();
|
|
403
|
+
float *sourceSurroundLeft = source->getChannelByType(ChannelSurroundLeft)->getData();
|
|
404
|
+
float *sourceSurroundRight = source->getChannelByType(ChannelSurroundRight)->getData();
|
|
445
405
|
|
|
446
406
|
float *destinationData = getChannelByType(ChannelMono)->getData();
|
|
447
407
|
|
|
448
408
|
dsp::multiplyByScalarThenAddToOutput(
|
|
449
|
-
sourceLeft + sourceStart,
|
|
450
|
-
0.25f,
|
|
451
|
-
destinationData + destinationStart,
|
|
452
|
-
length);
|
|
409
|
+
sourceLeft + sourceStart, 0.25f, destinationData + destinationStart, length);
|
|
453
410
|
dsp::multiplyByScalarThenAddToOutput(
|
|
454
|
-
sourceRight + sourceStart,
|
|
455
|
-
0.25f,
|
|
456
|
-
destinationData + destinationStart,
|
|
457
|
-
length);
|
|
411
|
+
sourceRight + sourceStart, 0.25f, destinationData + destinationStart, length);
|
|
458
412
|
dsp::multiplyByScalarThenAddToOutput(
|
|
459
|
-
sourceSurroundLeft + sourceStart,
|
|
460
|
-
0.25f,
|
|
461
|
-
destinationData + destinationStart,
|
|
462
|
-
length);
|
|
413
|
+
sourceSurroundLeft + sourceStart, 0.25f, destinationData + destinationStart, length);
|
|
463
414
|
dsp::multiplyByScalarThenAddToOutput(
|
|
464
|
-
sourceSurroundRight + sourceStart,
|
|
465
|
-
0.25f,
|
|
466
|
-
destinationData + destinationStart,
|
|
467
|
-
length);
|
|
415
|
+
sourceSurroundRight + sourceStart, 0.25f, destinationData + destinationStart, length);
|
|
468
416
|
return;
|
|
469
417
|
}
|
|
470
418
|
|
|
@@ -475,38 +423,24 @@ void AudioBus::sumByDownMixing(
|
|
|
475
423
|
float *sourceLeft = source->getChannelByType(ChannelLeft)->getData();
|
|
476
424
|
float *sourceRight = source->getChannelByType(ChannelRight)->getData();
|
|
477
425
|
float *sourceCenter = source->getChannelByType(ChannelCenter)->getData();
|
|
478
|
-
float *sourceSurroundLeft =
|
|
479
|
-
|
|
480
|
-
float *sourceSurroundRight =
|
|
481
|
-
source->getChannelByType(ChannelSurroundRight)->getData();
|
|
426
|
+
float *sourceSurroundLeft = source->getChannelByType(ChannelSurroundLeft)->getData();
|
|
427
|
+
float *sourceSurroundRight = source->getChannelByType(ChannelSurroundRight)->getData();
|
|
482
428
|
|
|
483
429
|
float *destinationData = getChannelByType(ChannelMono)->getData();
|
|
484
430
|
|
|
485
431
|
dsp::multiplyByScalarThenAddToOutput(
|
|
486
|
-
sourceLeft + sourceStart,
|
|
487
|
-
SQRT_HALF,
|
|
488
|
-
destinationData + destinationStart,
|
|
489
|
-
length);
|
|
432
|
+
sourceLeft + sourceStart, SQRT_HALF, destinationData + destinationStart, length);
|
|
490
433
|
dsp::multiplyByScalarThenAddToOutput(
|
|
491
|
-
sourceRight + sourceStart,
|
|
492
|
-
SQRT_HALF,
|
|
493
|
-
destinationData + destinationStart,
|
|
494
|
-
length);
|
|
434
|
+
sourceRight + sourceStart, SQRT_HALF, destinationData + destinationStart, length);
|
|
495
435
|
dsp::add(
|
|
496
436
|
sourceCenter + sourceStart,
|
|
497
437
|
destinationData + destinationStart,
|
|
498
438
|
destinationData + destinationStart,
|
|
499
439
|
length);
|
|
500
440
|
dsp::multiplyByScalarThenAddToOutput(
|
|
501
|
-
sourceSurroundLeft + sourceStart,
|
|
502
|
-
0.5f,
|
|
503
|
-
destinationData + destinationStart,
|
|
504
|
-
length);
|
|
441
|
+
sourceSurroundLeft + sourceStart, 0.5f, destinationData + destinationStart, length);
|
|
505
442
|
dsp::multiplyByScalarThenAddToOutput(
|
|
506
|
-
sourceSurroundRight + sourceStart,
|
|
507
|
-
0.5f,
|
|
508
|
-
destinationData + destinationStart,
|
|
509
|
-
length);
|
|
443
|
+
sourceSurroundRight + sourceStart, 0.5f, destinationData + destinationStart, length);
|
|
510
444
|
|
|
511
445
|
return;
|
|
512
446
|
}
|
|
@@ -517,35 +451,21 @@ void AudioBus::sumByDownMixing(
|
|
|
517
451
|
if (numberOfSourceChannels == 4 && numberOfChannels == 2) {
|
|
518
452
|
float *sourceLeft = source->getChannelByType(ChannelLeft)->getData();
|
|
519
453
|
float *sourceRight = source->getChannelByType(ChannelRight)->getData();
|
|
520
|
-
float *sourceSurroundLeft =
|
|
521
|
-
|
|
522
|
-
float *sourceSurroundRight =
|
|
523
|
-
source->getChannelByType(ChannelSurroundRight)->getData();
|
|
454
|
+
float *sourceSurroundLeft = source->getChannelByType(ChannelSurroundLeft)->getData();
|
|
455
|
+
float *sourceSurroundRight = source->getChannelByType(ChannelSurroundRight)->getData();
|
|
524
456
|
|
|
525
457
|
float *destinationLeft = getChannelByType(ChannelLeft)->getData();
|
|
526
458
|
float *destinationRight = getChannelByType(ChannelRight)->getData();
|
|
527
459
|
|
|
528
460
|
dsp::multiplyByScalarThenAddToOutput(
|
|
529
|
-
sourceLeft + sourceStart,
|
|
530
|
-
0.5f,
|
|
531
|
-
destinationLeft + destinationStart,
|
|
532
|
-
length);
|
|
461
|
+
sourceLeft + sourceStart, 0.5f, destinationLeft + destinationStart, length);
|
|
533
462
|
dsp::multiplyByScalarThenAddToOutput(
|
|
534
|
-
sourceSurroundLeft + sourceStart,
|
|
535
|
-
0.5f,
|
|
536
|
-
destinationLeft + destinationStart,
|
|
537
|
-
length);
|
|
463
|
+
sourceSurroundLeft + sourceStart, 0.5f, destinationLeft + destinationStart, length);
|
|
538
464
|
|
|
539
465
|
dsp::multiplyByScalarThenAddToOutput(
|
|
540
|
-
sourceRight + sourceStart,
|
|
541
|
-
0.5f,
|
|
542
|
-
destinationRight + destinationStart,
|
|
543
|
-
length);
|
|
466
|
+
sourceRight + sourceStart, 0.5f, destinationRight + destinationStart, length);
|
|
544
467
|
dsp::multiplyByScalarThenAddToOutput(
|
|
545
|
-
sourceSurroundRight + sourceStart,
|
|
546
|
-
0.5f,
|
|
547
|
-
destinationRight + destinationStart,
|
|
548
|
-
length);
|
|
468
|
+
sourceSurroundRight + sourceStart, 0.5f, destinationRight + destinationStart, length);
|
|
549
469
|
return;
|
|
550
470
|
}
|
|
551
471
|
|
|
@@ -557,10 +477,8 @@ void AudioBus::sumByDownMixing(
|
|
|
557
477
|
float *sourceLeft = source->getChannelByType(ChannelLeft)->getData();
|
|
558
478
|
float *sourceRight = source->getChannelByType(ChannelRight)->getData();
|
|
559
479
|
float *sourceCenter = source->getChannelByType(ChannelCenter)->getData();
|
|
560
|
-
float *sourceSurroundLeft =
|
|
561
|
-
|
|
562
|
-
float *sourceSurroundRight =
|
|
563
|
-
source->getChannelByType(ChannelSurroundRight)->getData();
|
|
480
|
+
float *sourceSurroundLeft = source->getChannelByType(ChannelSurroundLeft)->getData();
|
|
481
|
+
float *sourceSurroundRight = source->getChannelByType(ChannelSurroundRight)->getData();
|
|
564
482
|
|
|
565
483
|
float *destinationLeft = getChannelByType(ChannelLeft)->getData();
|
|
566
484
|
float *destinationRight = getChannelByType(ChannelRight)->getData();
|
|
@@ -571,15 +489,9 @@ void AudioBus::sumByDownMixing(
|
|
|
571
489
|
destinationLeft + destinationStart,
|
|
572
490
|
length);
|
|
573
491
|
dsp::multiplyByScalarThenAddToOutput(
|
|
574
|
-
sourceCenter + sourceStart,
|
|
575
|
-
SQRT_HALF,
|
|
576
|
-
destinationLeft + destinationStart,
|
|
577
|
-
length);
|
|
492
|
+
sourceCenter + sourceStart, SQRT_HALF, destinationLeft + destinationStart, length);
|
|
578
493
|
dsp::multiplyByScalarThenAddToOutput(
|
|
579
|
-
sourceSurroundLeft + sourceStart,
|
|
580
|
-
SQRT_HALF,
|
|
581
|
-
destinationLeft + destinationStart,
|
|
582
|
-
length);
|
|
494
|
+
sourceSurroundLeft + sourceStart, SQRT_HALF, destinationLeft + destinationStart, length);
|
|
583
495
|
|
|
584
496
|
dsp::add(
|
|
585
497
|
sourceRight + sourceStart,
|
|
@@ -587,15 +499,9 @@ void AudioBus::sumByDownMixing(
|
|
|
587
499
|
destinationRight + destinationStart,
|
|
588
500
|
length);
|
|
589
501
|
dsp::multiplyByScalarThenAddToOutput(
|
|
590
|
-
sourceCenter + sourceStart,
|
|
591
|
-
SQRT_HALF,
|
|
592
|
-
destinationRight + destinationStart,
|
|
593
|
-
length);
|
|
502
|
+
sourceCenter + sourceStart, SQRT_HALF, destinationRight + destinationStart, length);
|
|
594
503
|
dsp::multiplyByScalarThenAddToOutput(
|
|
595
|
-
sourceSurroundRight + sourceStart,
|
|
596
|
-
SQRT_HALF,
|
|
597
|
-
destinationRight + destinationStart,
|
|
598
|
-
length);
|
|
504
|
+
sourceSurroundRight + sourceStart, SQRT_HALF, destinationRight + destinationStart, length);
|
|
599
505
|
return;
|
|
600
506
|
}
|
|
601
507
|
|
|
@@ -608,17 +514,13 @@ void AudioBus::sumByDownMixing(
|
|
|
608
514
|
float *sourceLeft = source->getChannelByType(ChannelLeft)->getData();
|
|
609
515
|
float *sourceRight = source->getChannelByType(ChannelRight)->getData();
|
|
610
516
|
float *sourceCenter = source->getChannelByType(ChannelCenter)->getData();
|
|
611
|
-
float *sourceSurroundLeft =
|
|
612
|
-
|
|
613
|
-
float *sourceSurroundRight =
|
|
614
|
-
source->getChannelByType(ChannelSurroundRight)->getData();
|
|
517
|
+
float *sourceSurroundLeft = source->getChannelByType(ChannelSurroundLeft)->getData();
|
|
518
|
+
float *sourceSurroundRight = source->getChannelByType(ChannelSurroundRight)->getData();
|
|
615
519
|
|
|
616
520
|
float *destinationLeft = getChannelByType(ChannelLeft)->getData();
|
|
617
521
|
float *destinationRight = getChannelByType(ChannelRight)->getData();
|
|
618
|
-
float *destinationSurroundLeft =
|
|
619
|
-
|
|
620
|
-
float *destinationSurroundRight =
|
|
621
|
-
getChannelByType(ChannelSurroundRight)->getData();
|
|
522
|
+
float *destinationSurroundLeft = getChannelByType(ChannelSurroundLeft)->getData();
|
|
523
|
+
float *destinationSurroundRight = getChannelByType(ChannelSurroundRight)->getData();
|
|
622
524
|
|
|
623
525
|
dsp::add(
|
|
624
526
|
sourceLeft + sourceStart,
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
#include <audioapi/core/types/ChannelInterpretation.h>
|
|
4
4
|
|
|
5
5
|
#include <algorithm>
|
|
6
|
+
#include <cstddef>
|
|
6
7
|
#include <memory>
|
|
7
8
|
#include <vector>
|
|
8
|
-
#include <cstddef>
|
|
9
9
|
|
|
10
10
|
namespace audioapi {
|
|
11
11
|
|
|
@@ -28,7 +28,7 @@ class AudioBus {
|
|
|
28
28
|
explicit AudioBus(size_t size, int numberOfChannels, float sampleRate);
|
|
29
29
|
AudioBus(const AudioBus &other);
|
|
30
30
|
AudioBus(AudioBus &&other) noexcept;
|
|
31
|
-
AudioBus&
|
|
31
|
+
AudioBus &operator=(const AudioBus &other);
|
|
32
32
|
|
|
33
33
|
~AudioBus();
|
|
34
34
|
|
|
@@ -49,21 +49,24 @@ class AudioBus {
|
|
|
49
49
|
void zero();
|
|
50
50
|
void zero(size_t start, size_t length);
|
|
51
51
|
|
|
52
|
-
void sum(
|
|
53
|
-
|
|
52
|
+
void sum(
|
|
53
|
+
const AudioBus *source,
|
|
54
|
+
ChannelInterpretation interpretation = ChannelInterpretation::SPEAKERS);
|
|
55
|
+
void sum(
|
|
56
|
+
const AudioBus *source,
|
|
57
|
+
size_t start,
|
|
58
|
+
size_t length,
|
|
59
|
+
ChannelInterpretation interpretation = ChannelInterpretation::SPEAKERS);
|
|
54
60
|
void sum(
|
|
55
61
|
const AudioBus *source,
|
|
56
62
|
size_t sourceStart,
|
|
57
63
|
size_t destinationStart,
|
|
58
|
-
size_t length,
|
|
64
|
+
size_t length,
|
|
65
|
+
ChannelInterpretation interpretation = ChannelInterpretation::SPEAKERS);
|
|
59
66
|
|
|
60
67
|
void copy(const AudioBus *source);
|
|
61
68
|
void copy(const AudioBus *source, size_t start, size_t length);
|
|
62
|
-
void copy(
|
|
63
|
-
const AudioBus *source,
|
|
64
|
-
size_t sourceStart,
|
|
65
|
-
size_t destinationStart,
|
|
66
|
-
size_t length);
|
|
69
|
+
void copy(const AudioBus *source, size_t sourceStart, size_t destinationStart, size_t length);
|
|
67
70
|
|
|
68
71
|
private:
|
|
69
72
|
std::vector<std::shared_ptr<AudioArray>> channels_;
|
|
@@ -78,11 +81,8 @@ class AudioBus {
|
|
|
78
81
|
size_t sourceStart,
|
|
79
82
|
size_t destinationStart,
|
|
80
83
|
size_t length) const;
|
|
81
|
-
void
|
|
82
|
-
|
|
83
|
-
size_t sourceStart,
|
|
84
|
-
size_t destinationStart,
|
|
85
|
-
size_t length);
|
|
84
|
+
void
|
|
85
|
+
sumByUpMixing(const AudioBus *source, size_t sourceStart, size_t destinationStart, size_t length);
|
|
86
86
|
void sumByDownMixing(
|
|
87
87
|
const AudioBus *source,
|
|
88
88
|
size_t sourceStart,
|
|
@@ -4,10 +4,7 @@ namespace audioapi {
|
|
|
4
4
|
|
|
5
5
|
CircularAudioArray::CircularAudioArray(size_t size) : AudioArray(size) {}
|
|
6
6
|
|
|
7
|
-
void CircularAudioArray::push_back(
|
|
8
|
-
const float *data,
|
|
9
|
-
size_t size,
|
|
10
|
-
bool skipAvailableSpaceCheck) {
|
|
7
|
+
void CircularAudioArray::push_back(const float *data, size_t size, bool skipAvailableSpaceCheck) {
|
|
11
8
|
if (size > size_) {
|
|
12
9
|
throw std::overflow_error("size exceeds CircularAudioArray size_");
|
|
13
10
|
}
|
|
@@ -24,14 +21,10 @@ void CircularAudioArray::push_back(
|
|
|
24
21
|
memcpy(data_ + vWriteIndex_, data, size * sizeof(float));
|
|
25
22
|
}
|
|
26
23
|
|
|
27
|
-
vWriteIndex_ = vWriteIndex_ + size > size_ ? vWriteIndex_ + size - size_
|
|
28
|
-
: vWriteIndex_ + size;
|
|
24
|
+
vWriteIndex_ = vWriteIndex_ + size > size_ ? vWriteIndex_ + size - size_ : vWriteIndex_ + size;
|
|
29
25
|
}
|
|
30
26
|
|
|
31
|
-
void CircularAudioArray::pop_front(
|
|
32
|
-
float *data,
|
|
33
|
-
size_t size,
|
|
34
|
-
bool skipAvailableDataCheck) {
|
|
27
|
+
void CircularAudioArray::pop_front(float *data, size_t size, bool skipAvailableDataCheck) {
|
|
35
28
|
if (size > size_) {
|
|
36
29
|
throw std::overflow_error("size exceeds CircularAudioArray size_");
|
|
37
30
|
}
|
|
@@ -48,8 +41,7 @@ void CircularAudioArray::pop_front(
|
|
|
48
41
|
memcpy(data, data_ + vReadIndex_, size * sizeof(float));
|
|
49
42
|
}
|
|
50
43
|
|
|
51
|
-
vReadIndex_ = vReadIndex_ + size > size_ ? vReadIndex_ + size - size_
|
|
52
|
-
: vReadIndex_ + size;
|
|
44
|
+
vReadIndex_ = vReadIndex_ + size > size_ ? vReadIndex_ + size - size_ : vReadIndex_ + size;
|
|
53
45
|
}
|
|
54
46
|
|
|
55
47
|
void CircularAudioArray::pop_back(
|
|
@@ -66,10 +58,7 @@ void CircularAudioArray::pop_back(
|
|
|
66
58
|
}
|
|
67
59
|
|
|
68
60
|
if (vWriteIndex_ <= offset) {
|
|
69
|
-
memcpy(
|
|
70
|
-
data,
|
|
71
|
-
data_ + size_ - (offset - vWriteIndex_) - size,
|
|
72
|
-
size * sizeof(float));
|
|
61
|
+
memcpy(data, data_ + size_ - (offset - vWriteIndex_) - size, size * sizeof(float));
|
|
73
62
|
} else if (vWriteIndex_ <= size + offset) {
|
|
74
63
|
auto partSize = size + offset - vWriteIndex_;
|
|
75
64
|
memcpy(data, data_ + size_ - partSize, partSize * sizeof(float));
|
|
@@ -78,8 +67,7 @@ void CircularAudioArray::pop_back(
|
|
|
78
67
|
memcpy(data, data_ + vWriteIndex_ - size - offset, size * sizeof(float));
|
|
79
68
|
}
|
|
80
69
|
|
|
81
|
-
vReadIndex_ = vWriteIndex_ - offset < 0 ? size + vWriteIndex_ - offset
|
|
82
|
-
: vWriteIndex_ - offset;
|
|
70
|
+
vReadIndex_ = vWriteIndex_ - offset < 0 ? size + vWriteIndex_ - offset : vWriteIndex_ - offset;
|
|
83
71
|
}
|
|
84
72
|
|
|
85
73
|
size_t CircularAudioArray::getNumberOfAvailableFrames() const {
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
#include <audioapi/utils/CircularOverflowableAudioArray.h>
|
|
2
|
+
#include <algorithm>
|
|
2
3
|
#include <type_traits>
|
|
3
4
|
|
|
4
5
|
namespace audioapi {
|
|
5
6
|
|
|
6
|
-
CircularOverflowableAudioArray::CircularOverflowableAudioArray(
|
|
7
|
-
size_t
|
|
8
|
-
size) noexcept(std::is_nothrow_constructible<AudioArray, size_t>::value)
|
|
7
|
+
CircularOverflowableAudioArray::CircularOverflowableAudioArray(size_t size) noexcept(
|
|
8
|
+
std::is_nothrow_constructible<AudioArray, size_t>::value)
|
|
9
9
|
: AudioArray(size) {}
|
|
10
10
|
|
|
11
|
-
void CircularOverflowableAudioArray::write(
|
|
12
|
-
const float *data,
|
|
13
|
-
const size_t size) {
|
|
11
|
+
void CircularOverflowableAudioArray::write(const float *data, const size_t size) {
|
|
14
12
|
size_t writeIndex = vWriteIndex_.load(std::memory_order_relaxed);
|
|
15
13
|
|
|
16
14
|
if (size > size_) {
|
|
@@ -43,8 +41,7 @@ size_t CircularOverflowableAudioArray::read(float *output, size_t size) const {
|
|
|
43
41
|
size_t partSize = size_ - vReadIndex_;
|
|
44
42
|
if (readSize > partSize) {
|
|
45
43
|
std::memcpy(output, data_ + vReadIndex_, partSize * sizeof(float));
|
|
46
|
-
std::memcpy(
|
|
47
|
-
output + partSize, data_, (readSize - partSize) * sizeof(float));
|
|
44
|
+
std::memcpy(output + partSize, data_, (readSize - partSize) * sizeof(float));
|
|
48
45
|
} else {
|
|
49
46
|
std::memcpy(output, data_ + vReadIndex_, readSize * sizeof(float));
|
|
50
47
|
}
|
|
@@ -54,8 +51,7 @@ size_t CircularOverflowableAudioArray::read(float *output, size_t size) const {
|
|
|
54
51
|
}
|
|
55
52
|
|
|
56
53
|
size_t CircularOverflowableAudioArray::getAvailableSpace() const {
|
|
57
|
-
return (size_ + vWriteIndex_.load(std::memory_order_relaxed) - vReadIndex_) %
|
|
58
|
-
size_;
|
|
54
|
+
return (size_ + vWriteIndex_.load(std::memory_order_relaxed) - vReadIndex_) % size_;
|
|
59
55
|
}
|
|
60
56
|
|
|
61
57
|
} // namespace audioapi
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
#pragma once
|
|
3
3
|
|
|
4
4
|
#include <audioapi/utils/AudioArray.h>
|
|
5
|
-
#include <stdexcept>
|
|
6
5
|
#include <atomic>
|
|
7
6
|
#include <mutex>
|
|
7
|
+
#include <stdexcept>
|
|
8
8
|
|
|
9
9
|
namespace audioapi {
|
|
10
10
|
|
|
@@ -32,7 +32,7 @@ class CircularOverflowableAudioArray : public AudioArray {
|
|
|
32
32
|
size_t read(float *output, size_t size) const;
|
|
33
33
|
|
|
34
34
|
private:
|
|
35
|
-
std::atomic<size_t> vWriteIndex_ = {
|
|
35
|
+
std::atomic<size_t> vWriteIndex_ = {0};
|
|
36
36
|
mutable size_t vReadIndex_ = 0; // it is only used after acquiring readLock_
|
|
37
37
|
mutable std::mutex readLock_;
|
|
38
38
|
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
#include <audioapi/core/utils/worklets/SafeIncludes.h>
|
|
4
4
|
#include <gtest/gtest.h>
|
|
5
5
|
#include <test/src/MockAudioEventHandlerRegistry.h>
|
|
6
|
+
#include <memory>
|
|
7
|
+
#include <vector>
|
|
6
8
|
|
|
7
9
|
using namespace audioapi;
|
|
8
10
|
|
|
@@ -119,8 +121,7 @@ TEST_F(AudioParamTest, SetTargetAtTime) {
|
|
|
119
121
|
TEST_F(AudioParamTest, SetValueCurveAtTime) {
|
|
120
122
|
AudioParam param = AudioParam(0.0, 0.0, 1.0, context.get());
|
|
121
123
|
param.setValue(0.5);
|
|
122
|
-
auto curve = std::make_shared<std::vector<float>>(
|
|
123
|
-
std::vector<float>{0.1, 0.4, 0.2, 0.8, 0.5});
|
|
124
|
+
auto curve = std::make_shared<std::vector<float>>(std::vector<float>{0.1, 0.4, 0.2, 0.8, 0.5});
|
|
124
125
|
param.setValueCurveAtTime(curve, curve->size(), 0.1, 0.2);
|
|
125
126
|
// 5 elements over 0.2s => each element is 0.04s apart
|
|
126
127
|
|
|
@@ -5,12 +5,12 @@
|
|
|
5
5
|
#include <audioapi/utils/AudioBus.h>
|
|
6
6
|
#include <gtest/gtest.h>
|
|
7
7
|
#include <test/src/MockAudioEventHandlerRegistry.h>
|
|
8
|
+
#include <memory>
|
|
8
9
|
|
|
9
10
|
using namespace audioapi;
|
|
10
11
|
static constexpr int SAMPLE_RATE = 44100;
|
|
11
12
|
static constexpr int RENDER_QUANTUM = 128;
|
|
12
|
-
static constexpr double RENDER_QUANTUM_TIME =
|
|
13
|
-
static_cast<double>(RENDER_QUANTUM) / SAMPLE_RATE;
|
|
13
|
+
static constexpr double RENDER_QUANTUM_TIME = static_cast<double>(RENDER_QUANTUM) / SAMPLE_RATE;
|
|
14
14
|
|
|
15
15
|
class AudioScheduledSourceTest : public ::testing::Test {
|
|
16
16
|
protected:
|
|
@@ -40,8 +40,7 @@ class TestableAudioScheduledSourceNode : public AudioScheduledSourceNode {
|
|
|
40
40
|
processingBus, framesToProcess, startOffset, nonSilentFramesToProcess);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
std::shared_ptr<AudioBus> processNode(const std::shared_ptr<AudioBus> &, int)
|
|
44
|
-
override {
|
|
43
|
+
std::shared_ptr<AudioBus> processNode(const std::shared_ptr<AudioBus> &, int) override {
|
|
45
44
|
return nullptr;
|
|
46
45
|
}
|
|
47
46
|
|
|
@@ -52,42 +51,30 @@ class TestableAudioScheduledSourceNode : public AudioScheduledSourceNode {
|
|
|
52
51
|
void playFrames(int frames) {
|
|
53
52
|
size_t startOffset = 0;
|
|
54
53
|
size_t nonSilentFramesToProcess = 0;
|
|
55
|
-
auto processingBus =
|
|
56
|
-
|
|
57
|
-
updatePlaybackInfo(
|
|
58
|
-
processingBus, frames, startOffset, nonSilentFramesToProcess);
|
|
54
|
+
auto processingBus = std::make_shared<AudioBus>(128, 2, static_cast<float>(SAMPLE_RATE));
|
|
55
|
+
updatePlaybackInfo(processingBus, frames, startOffset, nonSilentFramesToProcess);
|
|
59
56
|
context_->getDestination()->renderAudio(processingBus, frames);
|
|
60
57
|
}
|
|
61
58
|
};
|
|
62
59
|
|
|
63
60
|
TEST_F(AudioScheduledSourceTest, IsUnscheduledStateSetCorrectly) {
|
|
64
61
|
auto sourceNode = TestableAudioScheduledSourceNode(context.get());
|
|
65
|
-
EXPECT_EQ(
|
|
66
|
-
sourceNode.getPlaybackState(),
|
|
67
|
-
AudioScheduledSourceNode::PlaybackState::UNSCHEDULED);
|
|
62
|
+
EXPECT_EQ(sourceNode.getPlaybackState(), AudioScheduledSourceNode::PlaybackState::UNSCHEDULED);
|
|
68
63
|
|
|
69
64
|
sourceNode.start(RENDER_QUANTUM_TIME);
|
|
70
|
-
EXPECT_NE(
|
|
71
|
-
sourceNode.getPlaybackState(),
|
|
72
|
-
AudioScheduledSourceNode::PlaybackState::UNSCHEDULED);
|
|
65
|
+
EXPECT_NE(sourceNode.getPlaybackState(), AudioScheduledSourceNode::PlaybackState::UNSCHEDULED);
|
|
73
66
|
}
|
|
74
67
|
|
|
75
68
|
TEST_F(AudioScheduledSourceTest, IsScheduledStateSetCorrectly) {
|
|
76
69
|
auto sourceNode = TestableAudioScheduledSourceNode(context.get());
|
|
77
70
|
sourceNode.start(RENDER_QUANTUM_TIME);
|
|
78
|
-
EXPECT_EQ(
|
|
79
|
-
sourceNode.getPlaybackState(),
|
|
80
|
-
AudioScheduledSourceNode::PlaybackState::SCHEDULED);
|
|
71
|
+
EXPECT_EQ(sourceNode.getPlaybackState(), AudioScheduledSourceNode::PlaybackState::SCHEDULED);
|
|
81
72
|
|
|
82
73
|
sourceNode.playFrames(RENDER_QUANTUM);
|
|
83
|
-
EXPECT_EQ(
|
|
84
|
-
sourceNode.getPlaybackState(),
|
|
85
|
-
AudioScheduledSourceNode::PlaybackState::SCHEDULED);
|
|
74
|
+
EXPECT_EQ(sourceNode.getPlaybackState(), AudioScheduledSourceNode::PlaybackState::SCHEDULED);
|
|
86
75
|
|
|
87
76
|
sourceNode.playFrames(1);
|
|
88
|
-
EXPECT_NE(
|
|
89
|
-
sourceNode.getPlaybackState(),
|
|
90
|
-
AudioScheduledSourceNode::PlaybackState::SCHEDULED);
|
|
77
|
+
EXPECT_NE(sourceNode.getPlaybackState(), AudioScheduledSourceNode::PlaybackState::SCHEDULED);
|
|
91
78
|
}
|
|
92
79
|
|
|
93
80
|
TEST_F(AudioScheduledSourceTest, IsPlayingStateSetCorrectly) {
|
|
@@ -96,14 +83,10 @@ TEST_F(AudioScheduledSourceTest, IsPlayingStateSetCorrectly) {
|
|
|
96
83
|
sourceNode.stop(RENDER_QUANTUM_TIME);
|
|
97
84
|
|
|
98
85
|
sourceNode.playFrames(RENDER_QUANTUM);
|
|
99
|
-
EXPECT_EQ(
|
|
100
|
-
sourceNode.getPlaybackState(),
|
|
101
|
-
AudioScheduledSourceNode::PlaybackState::PLAYING);
|
|
86
|
+
EXPECT_EQ(sourceNode.getPlaybackState(), AudioScheduledSourceNode::PlaybackState::PLAYING);
|
|
102
87
|
|
|
103
88
|
sourceNode.playFrames(1);
|
|
104
|
-
EXPECT_NE(
|
|
105
|
-
sourceNode.getPlaybackState(),
|
|
106
|
-
AudioScheduledSourceNode::PlaybackState::PLAYING);
|
|
89
|
+
EXPECT_NE(sourceNode.getPlaybackState(), AudioScheduledSourceNode::PlaybackState::PLAYING);
|
|
107
90
|
}
|
|
108
91
|
|
|
109
92
|
TEST_F(AudioScheduledSourceTest, IsStopScheduledStateSetCorrectly) {
|
|
@@ -112,14 +95,10 @@ TEST_F(AudioScheduledSourceTest, IsStopScheduledStateSetCorrectly) {
|
|
|
112
95
|
sourceNode.stop(RENDER_QUANTUM_TIME);
|
|
113
96
|
sourceNode.playFrames(1); // start playing
|
|
114
97
|
sourceNode.playFrames(RENDER_QUANTUM);
|
|
115
|
-
EXPECT_EQ(
|
|
116
|
-
sourceNode.getPlaybackState(),
|
|
117
|
-
AudioScheduledSourceNode::PlaybackState::STOP_SCHEDULED);
|
|
98
|
+
EXPECT_EQ(sourceNode.getPlaybackState(), AudioScheduledSourceNode::PlaybackState::STOP_SCHEDULED);
|
|
118
99
|
|
|
119
100
|
sourceNode.playFrames(1);
|
|
120
|
-
EXPECT_NE(
|
|
121
|
-
sourceNode.getPlaybackState(),
|
|
122
|
-
AudioScheduledSourceNode::PlaybackState::STOP_SCHEDULED);
|
|
101
|
+
EXPECT_NE(sourceNode.getPlaybackState(), AudioScheduledSourceNode::PlaybackState::STOP_SCHEDULED);
|
|
123
102
|
}
|
|
124
103
|
|
|
125
104
|
TEST_F(AudioScheduledSourceTest, IsFinishedStateSetCorrectly) {
|