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
|
@@ -18,8 +18,7 @@ class IOSAudioRecorder : public AudioRecorder {
|
|
|
18
18
|
IOSAudioRecorder(
|
|
19
19
|
float sampleRate,
|
|
20
20
|
int bufferLength,
|
|
21
|
-
const std::shared_ptr<AudioEventHandlerRegistry>
|
|
22
|
-
&audioEventHandlerRegistry);
|
|
21
|
+
const std::shared_ptr<AudioEventHandlerRegistry> &audioEventHandlerRegistry);
|
|
23
22
|
|
|
24
23
|
~IOSAudioRecorder() override;
|
|
25
24
|
|
|
@@ -18,8 +18,7 @@ IOSAudioRecorder::IOSAudioRecorder(
|
|
|
18
18
|
const std::shared_ptr<AudioEventHandlerRegistry> &audioEventHandlerRegistry)
|
|
19
19
|
: AudioRecorder(sampleRate, bufferLength, audioEventHandlerRegistry)
|
|
20
20
|
{
|
|
21
|
-
AudioReceiverBlock audioReceiverBlock = ^(
|
|
22
|
-
const AudioBufferList *inputBuffer, int numFrames) {
|
|
21
|
+
AudioReceiverBlock audioReceiverBlock = ^(const AudioBufferList *inputBuffer, int numFrames) {
|
|
23
22
|
if (isRunning_.load()) {
|
|
24
23
|
auto *inputChannel = static_cast<float *>(inputBuffer->mBuffers[0].mData);
|
|
25
24
|
writeToBuffers(inputChannel, numFrames);
|
|
@@ -35,10 +34,9 @@ IOSAudioRecorder::IOSAudioRecorder(
|
|
|
35
34
|
}
|
|
36
35
|
};
|
|
37
36
|
|
|
38
|
-
audioRecorder_ =
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
sampleRate:sampleRate];
|
|
37
|
+
audioRecorder_ = [[NativeAudioRecorder alloc] initWithReceiverBlock:audioReceiverBlock
|
|
38
|
+
bufferLength:bufferLength
|
|
39
|
+
sampleRate:sampleRate];
|
|
42
40
|
}
|
|
43
41
|
|
|
44
42
|
IOSAudioRecorder::~IOSAudioRecorder()
|
|
@@ -28,9 +28,8 @@
|
|
|
28
28
|
return kAudioServicesNoError;
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
-
_format = [[AVAudioFormat alloc]
|
|
32
|
-
|
|
33
|
-
channels:self.channelCount];
|
|
31
|
+
_format = [[AVAudioFormat alloc] initStandardFormatWithSampleRate:self.sampleRate
|
|
32
|
+
channels:self.channelCount];
|
|
34
33
|
_sourceNode = [[AVAudioSourceNode alloc] initWithFormat:self.format
|
|
35
34
|
renderBlock:self.renderBlock];
|
|
36
35
|
}
|
|
@@ -55,8 +54,7 @@
|
|
|
55
54
|
// performance issue and case when you will need to start and stop player very
|
|
56
55
|
// frequently
|
|
57
56
|
[audioEngine stopEngine];
|
|
58
|
-
self.sourceNodeId = [audioEngine attachSourceNode:self.sourceNode
|
|
59
|
-
format:self.format];
|
|
57
|
+
self.sourceNodeId = [audioEngine attachSourceNode:self.sourceNode format:self.format];
|
|
60
58
|
return [audioEngine startIfNecessary];
|
|
61
59
|
}
|
|
62
60
|
|
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
#import <AVFoundation/AVFoundation.h>
|
|
4
4
|
#import <Foundation/Foundation.h>
|
|
5
5
|
|
|
6
|
-
typedef void (
|
|
7
|
-
^AudioReceiverBlock)(const AudioBufferList *inputBuffer, int numFrames);
|
|
6
|
+
typedef void (^AudioReceiverBlock)(const AudioBufferList *inputBuffer, int numFrames);
|
|
8
7
|
|
|
9
8
|
@interface NativeAudioRecorder : NSObject
|
|
10
9
|
|
|
@@ -14,43 +14,35 @@
|
|
|
14
14
|
|
|
15
15
|
self.receiverBlock = [receiverBlock copy];
|
|
16
16
|
|
|
17
|
-
float devicePrefferedSampleRate =
|
|
18
|
-
[[AVAudioSession sharedInstance] sampleRate];
|
|
17
|
+
float devicePrefferedSampleRate = [[AVAudioSession sharedInstance] sampleRate];
|
|
19
18
|
|
|
20
19
|
if (!devicePrefferedSampleRate) {
|
|
21
20
|
NSError *error;
|
|
22
21
|
devicePrefferedSampleRate = sampleRate;
|
|
23
22
|
|
|
24
|
-
[[AVAudioSession sharedInstance] setPreferredSampleRate:sampleRate
|
|
25
|
-
error:&error];
|
|
23
|
+
[[AVAudioSession sharedInstance] setPreferredSampleRate:sampleRate error:&error];
|
|
26
24
|
}
|
|
27
25
|
|
|
28
|
-
self.inputFormat =
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
self.audioConverter =
|
|
39
|
-
[[AVAudioConverter alloc] initFromFormat:self.inputFormat
|
|
40
|
-
toFormat:self.outputFormat];
|
|
26
|
+
self.inputFormat = [[AVAudioFormat alloc] initWithCommonFormat:AVAudioPCMFormatFloat32
|
|
27
|
+
sampleRate:devicePrefferedSampleRate
|
|
28
|
+
channels:1
|
|
29
|
+
interleaved:NO];
|
|
30
|
+
self.outputFormat = [[AVAudioFormat alloc] initWithCommonFormat:AVAudioPCMFormatFloat32
|
|
31
|
+
sampleRate:sampleRate
|
|
32
|
+
channels:1
|
|
33
|
+
interleaved:NO];
|
|
34
|
+
self.audioConverter = [[AVAudioConverter alloc] initFromFormat:self.inputFormat
|
|
35
|
+
toFormat:self.outputFormat];
|
|
41
36
|
|
|
42
37
|
__weak typeof(self) weakSelf = self;
|
|
43
38
|
self.receiverSinkBlock = ^OSStatus(
|
|
44
39
|
const AudioTimeStamp *_Nonnull timestamp,
|
|
45
40
|
AVAudioFrameCount frameCount,
|
|
46
41
|
const AudioBufferList *_Nonnull inputData) {
|
|
47
|
-
return [weakSelf processAudioInput:inputData
|
|
48
|
-
withFrameCount:frameCount
|
|
49
|
-
atTimestamp:timestamp];
|
|
42
|
+
return [weakSelf processAudioInput:inputData withFrameCount:frameCount atTimestamp:timestamp];
|
|
50
43
|
};
|
|
51
44
|
|
|
52
|
-
self.sinkNode =
|
|
53
|
-
[[AVAudioSinkNode alloc] initWithReceiverBlock:self.receiverSinkBlock];
|
|
45
|
+
self.sinkNode = [[AVAudioSinkNode alloc] initWithReceiverBlock:self.receiverSinkBlock];
|
|
54
46
|
}
|
|
55
47
|
|
|
56
48
|
return self;
|
|
@@ -64,9 +56,8 @@
|
|
|
64
56
|
float outputSampleRate = self.outputFormat.sampleRate;
|
|
65
57
|
|
|
66
58
|
if (inputSampleRate != outputSampleRate) {
|
|
67
|
-
AVAudioPCMBuffer *inputBuffer =
|
|
68
|
-
|
|
69
|
-
frameCapacity:frameCount];
|
|
59
|
+
AVAudioPCMBuffer *inputBuffer = [[AVAudioPCMBuffer alloc] initWithPCMFormat:self.inputFormat
|
|
60
|
+
frameCapacity:frameCount];
|
|
70
61
|
memcpy(
|
|
71
62
|
inputBuffer.mutableAudioBufferList->mBuffers[0].mData,
|
|
72
63
|
inputData->mBuffers[0].mData,
|
|
@@ -75,14 +66,13 @@
|
|
|
75
66
|
|
|
76
67
|
int outputFrameCount = frameCount * outputSampleRate / inputSampleRate;
|
|
77
68
|
|
|
78
|
-
AVAudioPCMBuffer *outputBuffer =
|
|
79
|
-
initWithPCMFormat:self.audioConverter.outputFormat
|
|
80
|
-
|
|
69
|
+
AVAudioPCMBuffer *outputBuffer =
|
|
70
|
+
[[AVAudioPCMBuffer alloc] initWithPCMFormat:self.audioConverter.outputFormat
|
|
71
|
+
frameCapacity:outputFrameCount];
|
|
81
72
|
|
|
82
73
|
NSError *error = nil;
|
|
83
74
|
AVAudioConverterInputBlock inputBlock = ^AVAudioBuffer *_Nullable(
|
|
84
|
-
AVAudioPacketCount inNumberOfPackets,
|
|
85
|
-
AVAudioConverterInputStatus *outStatus)
|
|
75
|
+
AVAudioPacketCount inNumberOfPackets, AVAudioConverterInputStatus *outStatus)
|
|
86
76
|
{
|
|
87
77
|
*outStatus = AVAudioConverterInputStatus_HaveData;
|
|
88
78
|
return inputBuffer;
|
|
@@ -94,9 +84,7 @@
|
|
|
94
84
|
/// we can try to remove it in the future or refactor to reuse buffers to
|
|
95
85
|
/// minimize allocations
|
|
96
86
|
@autoreleasepool {
|
|
97
|
-
[self.audioConverter convertToBuffer:outputBuffer
|
|
98
|
-
error:&error
|
|
99
|
-
withInputFromBlock:inputBlock];
|
|
87
|
+
[self.audioConverter convertToBuffer:outputBuffer error:&error withInputFromBlock:inputBlock];
|
|
100
88
|
}
|
|
101
89
|
|
|
102
90
|
if (error) {
|
|
@@ -18,9 +18,7 @@ namespace audioapi {
|
|
|
18
18
|
// Decoding audio in fixed-size chunks because total frame count can't be
|
|
19
19
|
// determined in advance. Note: ma_decoder_get_length_in_pcm_frames() always
|
|
20
20
|
// returns 0 for Vorbis decoders.
|
|
21
|
-
std::vector<float> AudioDecoder::readAllPcmFrames(
|
|
22
|
-
ma_decoder &decoder,
|
|
23
|
-
int outputChannels)
|
|
21
|
+
std::vector<float> AudioDecoder::readAllPcmFrames(ma_decoder &decoder, int outputChannels)
|
|
24
22
|
{
|
|
25
23
|
std::vector<float> buffer;
|
|
26
24
|
std::vector<float> temp(CHUNK_SIZE * outputChannels);
|
|
@@ -28,16 +26,12 @@ std::vector<float> AudioDecoder::readAllPcmFrames(
|
|
|
28
26
|
|
|
29
27
|
while (true) {
|
|
30
28
|
ma_uint64 tempFramesDecoded = 0;
|
|
31
|
-
ma_decoder_read_pcm_frames(
|
|
32
|
-
&decoder, temp.data(), CHUNK_SIZE, &tempFramesDecoded);
|
|
29
|
+
ma_decoder_read_pcm_frames(&decoder, temp.data(), CHUNK_SIZE, &tempFramesDecoded);
|
|
33
30
|
if (tempFramesDecoded == 0) {
|
|
34
31
|
break;
|
|
35
32
|
}
|
|
36
33
|
|
|
37
|
-
buffer.insert(
|
|
38
|
-
buffer.end(),
|
|
39
|
-
temp.data(),
|
|
40
|
-
temp.data() + tempFramesDecoded * outputChannels);
|
|
34
|
+
buffer.insert(buffer.end(), temp.data(), temp.data() + tempFramesDecoded * outputChannels);
|
|
41
35
|
outFramesRead += tempFramesDecoded;
|
|
42
36
|
}
|
|
43
37
|
|
|
@@ -57,8 +51,7 @@ std::shared_ptr<AudioBuffer> AudioDecoder::makeAudioBufferFromFloatBuffer(
|
|
|
57
51
|
}
|
|
58
52
|
|
|
59
53
|
auto outputFrames = buffer.size() / outputChannels;
|
|
60
|
-
auto audioBus = std::make_shared<AudioBus>(
|
|
61
|
-
outputFrames, outputChannels, outputSampleRate);
|
|
54
|
+
auto audioBus = std::make_shared<AudioBus>(outputFrames, outputChannels, outputSampleRate);
|
|
62
55
|
|
|
63
56
|
for (int ch = 0; ch < outputChannels; ++ch) {
|
|
64
57
|
auto channelData = audioBus->getChannel(ch)->getData();
|
|
@@ -74,8 +67,7 @@ std::shared_ptr<AudioBuffer> AudioDecoder::decodeWithFilePath(
|
|
|
74
67
|
float sampleRate)
|
|
75
68
|
{
|
|
76
69
|
if (AudioDecoder::pathHasExtension(path, {".mp4", ".m4a", ".aac"})) {
|
|
77
|
-
auto buffer =
|
|
78
|
-
ffmpegdecoder::decodeWithFilePath(path, static_cast<int>(sampleRate));
|
|
70
|
+
auto buffer = ffmpegdecoder::decodeWithFilePath(path, static_cast<int>(sampleRate));
|
|
79
71
|
if (buffer == nullptr) {
|
|
80
72
|
NSLog(@"Failed to decode with FFmpeg: %s", path.c_str());
|
|
81
73
|
return nullptr;
|
|
@@ -83,14 +75,12 @@ std::shared_ptr<AudioBuffer> AudioDecoder::decodeWithFilePath(
|
|
|
83
75
|
return buffer;
|
|
84
76
|
}
|
|
85
77
|
ma_decoder decoder;
|
|
86
|
-
ma_decoder_config config =
|
|
87
|
-
ma_decoder_config_init(ma_format_f32, 0, static_cast<int>(sampleRate));
|
|
78
|
+
ma_decoder_config config = ma_decoder_config_init(ma_format_f32, 0, static_cast<int>(sampleRate));
|
|
88
79
|
ma_decoding_backend_vtable *customBackends[] = {
|
|
89
80
|
ma_decoding_backend_libvorbis, ma_decoding_backend_libopus};
|
|
90
81
|
|
|
91
82
|
config.ppCustomBackendVTables = customBackends;
|
|
92
|
-
config.customBackendCount =
|
|
93
|
-
sizeof(customBackends) / sizeof(customBackends[0]);
|
|
83
|
+
config.customBackendCount = sizeof(customBackends) / sizeof(customBackends[0]);
|
|
94
84
|
|
|
95
85
|
if (ma_decoder_init_file(path.c_str(), &config, &decoder) != MA_SUCCESS) {
|
|
96
86
|
NSLog(@"Failed to initialize decoder for file: %s", path.c_str());
|
|
@@ -103,20 +93,15 @@ std::shared_ptr<AudioBuffer> AudioDecoder::decodeWithFilePath(
|
|
|
103
93
|
|
|
104
94
|
std::vector<float> buffer = readAllPcmFrames(decoder, outputChannels);
|
|
105
95
|
ma_decoder_uninit(&decoder);
|
|
106
|
-
return makeAudioBufferFromFloatBuffer(
|
|
107
|
-
buffer, outputSampleRate, outputChannels);
|
|
96
|
+
return makeAudioBufferFromFloatBuffer(buffer, outputSampleRate, outputChannels);
|
|
108
97
|
}
|
|
109
98
|
|
|
110
|
-
std::shared_ptr<AudioBuffer>
|
|
111
|
-
|
|
112
|
-
size_t size,
|
|
113
|
-
float sampleRate)
|
|
99
|
+
std::shared_ptr<AudioBuffer>
|
|
100
|
+
AudioDecoder::decodeWithMemoryBlock(const void *data, size_t size, float sampleRate)
|
|
114
101
|
{
|
|
115
102
|
const AudioFormat format = AudioDecoder::detectAudioFormat(data, size);
|
|
116
|
-
if (format == AudioFormat::MP4 || format == AudioFormat::M4A ||
|
|
117
|
-
|
|
118
|
-
auto buffer = ffmpegdecoder::decodeWithMemoryBlock(
|
|
119
|
-
data, size, static_cast<int>(sampleRate));
|
|
103
|
+
if (format == AudioFormat::MP4 || format == AudioFormat::M4A || format == AudioFormat::AAC) {
|
|
104
|
+
auto buffer = ffmpegdecoder::decodeWithMemoryBlock(data, size, static_cast<int>(sampleRate));
|
|
120
105
|
if (buffer == nullptr) {
|
|
121
106
|
NSLog(@"Failed to decode with FFmpeg");
|
|
122
107
|
return nullptr;
|
|
@@ -124,15 +109,13 @@ std::shared_ptr<AudioBuffer> AudioDecoder::decodeWithMemoryBlock(
|
|
|
124
109
|
return buffer;
|
|
125
110
|
}
|
|
126
111
|
ma_decoder decoder;
|
|
127
|
-
ma_decoder_config config =
|
|
128
|
-
ma_decoder_config_init(ma_format_f32, 0, static_cast<int>(sampleRate));
|
|
112
|
+
ma_decoder_config config = ma_decoder_config_init(ma_format_f32, 0, static_cast<int>(sampleRate));
|
|
129
113
|
|
|
130
114
|
ma_decoding_backend_vtable *customBackends[] = {
|
|
131
115
|
ma_decoding_backend_libvorbis, ma_decoding_backend_libopus};
|
|
132
116
|
|
|
133
117
|
config.ppCustomBackendVTables = customBackends;
|
|
134
|
-
config.customBackendCount =
|
|
135
|
-
sizeof(customBackends) / sizeof(customBackends[0]);
|
|
118
|
+
config.customBackendCount = sizeof(customBackends) / sizeof(customBackends[0]);
|
|
136
119
|
|
|
137
120
|
if (ma_decoder_init_memory(data, size, &config, &decoder) != MA_SUCCESS) {
|
|
138
121
|
NSLog(@"Failed to initialize decoder for memory block");
|
|
@@ -145,8 +128,7 @@ std::shared_ptr<AudioBuffer> AudioDecoder::decodeWithMemoryBlock(
|
|
|
145
128
|
|
|
146
129
|
std::vector<float> buffer = readAllPcmFrames(decoder, outputChannels);
|
|
147
130
|
ma_decoder_uninit(&decoder);
|
|
148
|
-
return makeAudioBufferFromFloatBuffer(
|
|
149
|
-
buffer, outputSampleRate, outputChannels);
|
|
131
|
+
return makeAudioBufferFromFloatBuffer(buffer, outputSampleRate, outputChannels);
|
|
150
132
|
}
|
|
151
133
|
|
|
152
134
|
std::shared_ptr<AudioBuffer> AudioDecoder::decodeWithPCMInBase64(
|
|
@@ -157,11 +139,9 @@ std::shared_ptr<AudioBuffer> AudioDecoder::decodeWithPCMInBase64(
|
|
|
157
139
|
{
|
|
158
140
|
auto decodedData = base64_decode(data, false);
|
|
159
141
|
const auto uint8Data = reinterpret_cast<uint8_t *>(decodedData.data());
|
|
160
|
-
size_t numFramesDecoded =
|
|
161
|
-
decodedData.size() / (inputChannelCount * sizeof(int16_t));
|
|
142
|
+
size_t numFramesDecoded = decodedData.size() / (inputChannelCount * sizeof(int16_t));
|
|
162
143
|
|
|
163
|
-
auto audioBus = std::make_shared<AudioBus>(
|
|
164
|
-
numFramesDecoded, inputChannelCount, inputSampleRate);
|
|
144
|
+
auto audioBus = std::make_shared<AudioBus>(numFramesDecoded, inputChannelCount, inputSampleRate);
|
|
165
145
|
|
|
166
146
|
for (int ch = 0; ch < inputChannelCount; ++ch) {
|
|
167
147
|
auto channelData = audioBus->getChannel(ch)->getData();
|
|
@@ -16,8 +16,7 @@
|
|
|
16
16
|
@property (nonatomic, strong) AVAudioSinkNode *inputNode;
|
|
17
17
|
@property (nonatomic, weak) AudioSessionManager *sessionManager;
|
|
18
18
|
|
|
19
|
-
- (instancetype)initWithAudioSessionManager:
|
|
20
|
-
(AudioSessionManager *)sessionManager;
|
|
19
|
+
- (instancetype)initWithAudioSessionManager:(AudioSessionManager *)sessionManager;
|
|
21
20
|
|
|
22
21
|
+ (instancetype)sharedInstance;
|
|
23
22
|
- (void)cleanup;
|
|
@@ -31,8 +30,7 @@
|
|
|
31
30
|
- (void)unmarkAsInterrupted;
|
|
32
31
|
- (bool)isSupposedToRun;
|
|
33
32
|
|
|
34
|
-
- (NSString *)attachSourceNode:(AVAudioSourceNode *)sourceNode
|
|
35
|
-
format:(AVAudioFormat *)format;
|
|
33
|
+
- (NSString *)attachSourceNode:(AVAudioSourceNode *)sourceNode format:(AVAudioFormat *)format;
|
|
36
34
|
- (void)detachSourceNodeWithId:(NSString *)sourceNodeId;
|
|
37
35
|
|
|
38
36
|
- (void)attachInputNode:(AVAudioSinkNode *)inputNode;
|
|
@@ -10,8 +10,7 @@ static AudioEngine *_sharedInstance = nil;
|
|
|
10
10
|
return _sharedInstance;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
- (instancetype)initWithAudioSessionManager:
|
|
14
|
-
(AudioSessionManager *)sessionManager
|
|
13
|
+
- (instancetype)initWithAudioSessionManager:(AudioSessionManager *)sessionManager
|
|
15
14
|
{
|
|
16
15
|
if (self = [super init]) {
|
|
17
16
|
self.isInterrupted = false;
|
|
@@ -55,16 +54,12 @@ static AudioEngine *_sharedInstance = nil;
|
|
|
55
54
|
AVAudioFormat *format = [self.sourceFormats valueForKey:sourceNodeId];
|
|
56
55
|
|
|
57
56
|
[self.audioEngine attachNode:sourceNode];
|
|
58
|
-
[self.audioEngine connect:sourceNode
|
|
59
|
-
to:self.audioEngine.mainMixerNode
|
|
60
|
-
format:format];
|
|
57
|
+
[self.audioEngine connect:sourceNode to:self.audioEngine.mainMixerNode format:format];
|
|
61
58
|
}
|
|
62
59
|
|
|
63
60
|
if (self.inputNode) {
|
|
64
61
|
[self.audioEngine attachNode:self.inputNode];
|
|
65
|
-
[self.audioEngine connect:self.audioEngine.inputNode
|
|
66
|
-
to:self.inputNode
|
|
67
|
-
format:nil];
|
|
62
|
+
[self.audioEngine connect:self.audioEngine.inputNode to:self.inputNode format:nil];
|
|
68
63
|
}
|
|
69
64
|
}
|
|
70
65
|
|
|
@@ -113,8 +108,7 @@ static AudioEngine *_sharedInstance = nil;
|
|
|
113
108
|
[self.audioEngine startAndReturnError:&error];
|
|
114
109
|
|
|
115
110
|
if (error != nil) {
|
|
116
|
-
NSLog(
|
|
117
|
-
@"Error while starting the audio engine: %@", [error debugDescription]);
|
|
111
|
+
NSLog(@"Error while starting the audio engine: %@", [error debugDescription]);
|
|
118
112
|
return false;
|
|
119
113
|
}
|
|
120
114
|
|
|
@@ -161,8 +155,7 @@ static AudioEngine *_sharedInstance = nil;
|
|
|
161
155
|
self.isInterrupted = false;
|
|
162
156
|
}
|
|
163
157
|
|
|
164
|
-
- (NSString *)attachSourceNode:(AVAudioSourceNode *)sourceNode
|
|
165
|
-
format:(AVAudioFormat *)format
|
|
158
|
+
- (NSString *)attachSourceNode:(AVAudioSourceNode *)sourceNode format:(AVAudioFormat *)format
|
|
166
159
|
{
|
|
167
160
|
NSString *sourceNodeId = [[NSUUID UUID] UUIDString];
|
|
168
161
|
NSLog(@"[AudioEngine] attaching new source node with ID: %@", sourceNodeId);
|
|
@@ -172,9 +165,7 @@ static AudioEngine *_sharedInstance = nil;
|
|
|
172
165
|
[self.sourceStates setValue:@true forKey:sourceNodeId];
|
|
173
166
|
|
|
174
167
|
[self.audioEngine attachNode:sourceNode];
|
|
175
|
-
[self.audioEngine connect:sourceNode
|
|
176
|
-
to:self.audioEngine.mainMixerNode
|
|
177
|
-
format:format];
|
|
168
|
+
[self.audioEngine connect:sourceNode to:self.audioEngine.mainMixerNode format:format];
|
|
178
169
|
|
|
179
170
|
return sourceNodeId;
|
|
180
171
|
}
|
|
@@ -290,10 +281,7 @@ static AudioEngine *_sharedInstance = nil;
|
|
|
290
281
|
|
|
291
282
|
// Output node format
|
|
292
283
|
AVAudioFormat *format = [self.audioEngine.outputNode inputFormatForBus:0];
|
|
293
|
-
NSLog(
|
|
294
|
-
@"📐 Engine output format: %.0f Hz, %u channels",
|
|
295
|
-
format.sampleRate,
|
|
296
|
-
format.channelCount);
|
|
284
|
+
NSLog(@"📐 Engine output format: %.0f Hz, %u channels", format.sampleRate, format.channelCount);
|
|
297
285
|
|
|
298
286
|
NSLog(@"=======================================================");
|
|
299
287
|
}
|
|
@@ -35,9 +35,7 @@
|
|
|
35
35
|
- (void)checkRecordingPermissions:(RCTPromiseResolveBlock)resolve
|
|
36
36
|
reject:(RCTPromiseRejectBlock)reject;
|
|
37
37
|
|
|
38
|
-
- (void)getDevicesInfo:(RCTPromiseResolveBlock)resolve
|
|
39
|
-
|
|
40
|
-
- (NSArray<NSDictionary *> *)parseDeviceList:
|
|
41
|
-
(NSArray<AVAudioSessionPortDescription *> *)devices;
|
|
38
|
+
- (void)getDevicesInfo:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject;
|
|
39
|
+
- (NSArray<NSDictionary *> *)parseDeviceList:(NSArray<AVAudioSessionPortDescription *> *)devices;
|
|
42
40
|
|
|
43
41
|
@end
|
|
@@ -101,13 +101,11 @@
|
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
if ([option isEqualToString:@"overrideMutedMicrophoneInterruption"]) {
|
|
104
|
-
sessionOptions |=
|
|
105
|
-
AVAudioSessionCategoryOptionOverrideMutedMicrophoneInterruption;
|
|
104
|
+
sessionOptions |= AVAudioSessionCategoryOptionOverrideMutedMicrophoneInterruption;
|
|
106
105
|
}
|
|
107
106
|
|
|
108
107
|
if ([option isEqualToString:@"interruptSpokenAudioAndMixWithOthers"]) {
|
|
109
|
-
sessionOptions |=
|
|
110
|
-
AVAudioSessionCategoryOptionInterruptSpokenAudioAndMixWithOthers;
|
|
108
|
+
sessionOptions |= AVAudioSessionCategoryOptionInterruptSpokenAudioAndMixWithOthers;
|
|
111
109
|
}
|
|
112
110
|
}
|
|
113
111
|
|
|
@@ -129,8 +127,7 @@
|
|
|
129
127
|
if (self.allowHapticsAndSystemSoundsDuringRecording !=
|
|
130
128
|
allowHapticsAndSystemSoundsDuringRecording) {
|
|
131
129
|
self.hasDirtySettings = true;
|
|
132
|
-
self.allowHapticsAndSystemSoundsDuringRecording =
|
|
133
|
-
allowHapticsAndSystemSoundsDuringRecording;
|
|
130
|
+
self.allowHapticsAndSystemSoundsDuringRecording = allowHapticsAndSystemSoundsDuringRecording;
|
|
134
131
|
}
|
|
135
132
|
|
|
136
133
|
if (self.isActive) {
|
|
@@ -160,13 +157,9 @@
|
|
|
160
157
|
}
|
|
161
158
|
|
|
162
159
|
if (error != nil) {
|
|
163
|
-
NSLog(
|
|
164
|
-
@"[AudioSessionManager] setting session as %@ failed",
|
|
165
|
-
active ? @"ACTIVE" : @"INACTIVE");
|
|
160
|
+
NSLog(@"[AudioSessionManager] setting session as %@ failed", active ? @"ACTIVE" : @"INACTIVE");
|
|
166
161
|
} else {
|
|
167
|
-
NSLog(
|
|
168
|
-
@"[AudioSessionManager] session is %@",
|
|
169
|
-
active ? @"ACTIVE" : @"INACTIVE");
|
|
162
|
+
NSLog(@"[AudioSessionManager] session is %@", active ? @"ACTIVE" : @"INACTIVE");
|
|
170
163
|
}
|
|
171
164
|
|
|
172
165
|
return success;
|
|
@@ -199,8 +192,7 @@
|
|
|
199
192
|
error:&error];
|
|
200
193
|
|
|
201
194
|
if (error != nil) {
|
|
202
|
-
NSLog(
|
|
203
|
-
@"Error while configuring audio session: %@", [error debugDescription]);
|
|
195
|
+
NSLog(@"Error while configuring audio session: %@", [error debugDescription]);
|
|
204
196
|
return false;
|
|
205
197
|
}
|
|
206
198
|
|
|
@@ -245,8 +237,7 @@
|
|
|
245
237
|
- (void)requestRecordingPermissions:(RCTPromiseResolveBlock)resolve
|
|
246
238
|
reject:(RCTPromiseRejectBlock)reject
|
|
247
239
|
{
|
|
248
|
-
id value = [[NSBundle mainBundle]
|
|
249
|
-
objectForInfoDictionaryKey:@"NSMicrophoneUsageDescription"];
|
|
240
|
+
id value = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSMicrophoneUsageDescription"];
|
|
250
241
|
// if there is no entry NSMicrophoneUsageDescription calling
|
|
251
242
|
// requestRecordPermission will quit an app
|
|
252
243
|
if (value == nil) {
|
|
@@ -342,29 +333,23 @@
|
|
|
342
333
|
}
|
|
343
334
|
}
|
|
344
335
|
|
|
345
|
-
- (void)getDevicesInfo:(RCTPromiseResolveBlock)resolve
|
|
346
|
-
reject:(RCTPromiseRejectBlock)reject
|
|
336
|
+
- (void)getDevicesInfo:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject
|
|
347
337
|
{
|
|
348
338
|
NSMutableDictionary *devicesInfo = [[NSMutableDictionary alloc] init];
|
|
349
339
|
|
|
350
|
-
[devicesInfo
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
[devicesInfo
|
|
357
|
-
|
|
358
|
-
forKey:@"availableOutputs"];
|
|
359
|
-
[devicesInfo
|
|
360
|
-
setValue:[self parseDeviceList:[[self.audioSession currentRoute] outputs]]
|
|
361
|
-
forKey:@"currentOutputs"];
|
|
340
|
+
[devicesInfo setValue:[self parseDeviceList:[self.audioSession availableInputs]]
|
|
341
|
+
forKey:@"availableInputs"];
|
|
342
|
+
[devicesInfo setValue:[self parseDeviceList:[[self.audioSession currentRoute] inputs]]
|
|
343
|
+
forKey:@"currentInputs"];
|
|
344
|
+
[devicesInfo setValue:[self parseDeviceList:[[self.audioSession currentRoute] outputs]]
|
|
345
|
+
forKey:@"availableOutputs"];
|
|
346
|
+
[devicesInfo setValue:[self parseDeviceList:[[self.audioSession currentRoute] outputs]]
|
|
347
|
+
forKey:@"currentOutputs"];
|
|
362
348
|
|
|
363
349
|
resolve(devicesInfo);
|
|
364
350
|
}
|
|
365
351
|
|
|
366
|
-
- (NSArray<NSDictionary *> *)parseDeviceList:
|
|
367
|
-
(NSArray<AVAudioSessionPortDescription *> *)devices
|
|
352
|
+
- (NSArray<NSDictionary *> *)parseDeviceList:(NSArray<AVAudioSessionPortDescription *> *)devices
|
|
368
353
|
{
|
|
369
354
|
NSMutableArray<NSDictionary *> *deviceList = [[NSMutableArray alloc] init];
|
|
370
355
|
|