react-native-audio-api 0.12.0-nightly-3254662-20260127 → 0.12.0-nightly-1a3c43b-20260128
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/CMakeLists.txt +0 -6
- package/android/src/main/cpp/audioapi/android/AudioAPIModule.cpp +3 -2
- package/android/src/main/cpp/audioapi/android/AudioAPIModule.h +1 -1
- package/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.cpp +1 -1
- package/android/src/main/java/com/swmansion/audioapi/AudioAPIModule.kt +5 -1
- package/android/src/main/java/com/swmansion/audioapi/system/AudioEvent.kt +28 -0
- package/android/src/main/java/com/swmansion/audioapi/system/AudioFocusListener.kt +4 -4
- package/android/src/main/java/com/swmansion/audioapi/system/VolumeChangeListener.kt +1 -1
- package/android/src/main/java/com/swmansion/audioapi/system/notification/PlaybackNotification.kt +27 -18
- package/android/src/main/java/com/swmansion/audioapi/system/notification/PlaybackNotificationReceiver.kt +13 -8
- package/android/src/main/java/com/swmansion/audioapi/system/notification/RecordingNotificationReceiver.kt +3 -2
- package/android/src/oldarch/NativeAudioAPIModuleSpec.java +2 -2
- package/common/cpp/audioapi/AudioAPIModuleInstaller.h +9 -12
- package/common/cpp/audioapi/HostObjects/AudioContextHostObject.cpp +4 -2
- package/common/cpp/audioapi/HostObjects/AudioContextHostObject.h +5 -1
- package/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.cpp +38 -38
- package/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.h +4 -2
- package/common/cpp/audioapi/HostObjects/OfflineAudioContextHostObject.cpp +8 -4
- package/common/cpp/audioapi/HostObjects/OfflineAudioContextHostObject.h +7 -1
- package/common/cpp/audioapi/HostObjects/analysis/AnalyserNodeHostObject.cpp +6 -4
- package/common/cpp/audioapi/HostObjects/analysis/AnalyserNodeHostObject.h +6 -2
- package/common/cpp/audioapi/HostObjects/effects/BiquadFilterNodeHostObject.cpp +8 -5
- package/common/cpp/audioapi/HostObjects/effects/BiquadFilterNodeHostObject.h +5 -3
- package/common/cpp/audioapi/HostObjects/effects/ConvolverNodeHostObject.cpp +5 -3
- package/common/cpp/audioapi/HostObjects/effects/ConvolverNodeHostObject.h +5 -2
- package/common/cpp/audioapi/HostObjects/effects/DelayNodeHostObject.cpp +4 -3
- package/common/cpp/audioapi/HostObjects/effects/DelayNodeHostObject.h +5 -2
- package/common/cpp/audioapi/HostObjects/effects/GainNodeHostObject.cpp +6 -2
- package/common/cpp/audioapi/HostObjects/effects/GainNodeHostObject.h +5 -2
- package/common/cpp/audioapi/HostObjects/effects/IIRFilterNodeHostObject.cpp +6 -2
- package/common/cpp/audioapi/HostObjects/effects/IIRFilterNodeHostObject.h +5 -2
- package/common/cpp/audioapi/HostObjects/effects/StereoPannerNodeHostObject.cpp +5 -2
- package/common/cpp/audioapi/HostObjects/effects/StereoPannerNodeHostObject.h +5 -2
- package/common/cpp/audioapi/HostObjects/effects/WaveShaperNodeHostObject.cpp +9 -4
- package/common/cpp/audioapi/HostObjects/effects/WaveShaperNodeHostObject.h +5 -2
- package/common/cpp/audioapi/HostObjects/events/AudioEventHandlerRegistryHostObject.cpp +3 -2
- package/common/cpp/audioapi/HostObjects/sources/AudioBufferQueueSourceNodeHostObject.cpp +9 -6
- package/common/cpp/audioapi/HostObjects/sources/AudioBufferQueueSourceNodeHostObject.h +4 -2
- package/common/cpp/audioapi/HostObjects/sources/AudioBufferSourceNodeHostObject.cpp +5 -2
- package/common/cpp/audioapi/HostObjects/sources/AudioBufferSourceNodeHostObject.h +5 -2
- package/common/cpp/audioapi/HostObjects/sources/ConstantSourceNodeHostObject.cpp +5 -2
- package/common/cpp/audioapi/HostObjects/sources/ConstantSourceNodeHostObject.h +5 -2
- package/common/cpp/audioapi/HostObjects/sources/OscillatorNodeHostObject.cpp +7 -3
- package/common/cpp/audioapi/HostObjects/sources/OscillatorNodeHostObject.h +5 -2
- package/common/cpp/audioapi/HostObjects/sources/StreamerNodeHostObject.cpp +6 -2
- package/common/cpp/audioapi/HostObjects/sources/StreamerNodeHostObject.h +5 -2
- package/common/cpp/audioapi/HostObjects/utils/JsEnumParser.cpp +63 -0
- package/common/cpp/audioapi/HostObjects/utils/JsEnumParser.h +5 -0
- package/common/cpp/audioapi/core/AudioContext.cpp +2 -4
- package/common/cpp/audioapi/core/AudioNode.cpp +2 -2
- package/common/cpp/audioapi/core/AudioNode.h +6 -6
- package/common/cpp/audioapi/core/BaseAudioContext.cpp +7 -22
- package/common/cpp/audioapi/core/BaseAudioContext.h +20 -22
- package/common/cpp/audioapi/core/OfflineAudioContext.cpp +3 -6
- package/common/cpp/audioapi/core/analysis/AnalyserNode.cpp +5 -2
- package/common/cpp/audioapi/core/analysis/AnalyserNode.h +4 -2
- package/common/cpp/audioapi/core/destinations/AudioDestinationNode.cpp +1 -1
- package/common/cpp/audioapi/core/destinations/AudioDestinationNode.h +1 -1
- package/common/cpp/audioapi/core/effects/BiquadFilterNode.cpp +6 -6
- package/common/cpp/audioapi/core/effects/BiquadFilterNode.h +2 -2
- package/common/cpp/audioapi/core/effects/ConvolverNode.cpp +1 -1
- package/common/cpp/audioapi/core/effects/ConvolverNode.h +2 -2
- package/common/cpp/audioapi/core/effects/DelayNode.cpp +1 -1
- package/common/cpp/audioapi/core/effects/DelayNode.h +2 -2
- package/common/cpp/audioapi/core/effects/GainNode.cpp +1 -1
- package/common/cpp/audioapi/core/effects/GainNode.h +2 -2
- package/common/cpp/audioapi/core/effects/IIRFilterNode.cpp +5 -3
- package/common/cpp/audioapi/core/effects/IIRFilterNode.h +2 -2
- package/common/cpp/audioapi/core/effects/StereoPannerNode.cpp +5 -2
- package/common/cpp/audioapi/core/effects/StereoPannerNode.h +2 -2
- package/common/cpp/audioapi/core/effects/WaveShaperNode.cpp +4 -2
- package/common/cpp/audioapi/core/effects/WaveShaperNode.h +2 -2
- package/common/cpp/audioapi/core/sources/AudioBuffer.h +1 -1
- package/common/cpp/audioapi/core/sources/AudioBufferBaseSourceNode.cpp +10 -4
- package/common/cpp/audioapi/core/sources/AudioBufferBaseSourceNode.h +2 -2
- package/common/cpp/audioapi/core/sources/AudioBufferQueueSourceNode.cpp +13 -13
- package/common/cpp/audioapi/core/sources/AudioBufferQueueSourceNode.h +2 -2
- package/common/cpp/audioapi/core/sources/AudioBufferSourceNode.cpp +6 -5
- package/common/cpp/audioapi/core/sources/AudioBufferSourceNode.h +2 -2
- package/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.cpp +2 -2
- package/common/cpp/audioapi/core/sources/ConstantSourceNode.cpp +10 -2
- package/common/cpp/audioapi/core/sources/ConstantSourceNode.h +2 -2
- package/common/cpp/audioapi/core/sources/OscillatorNode.cpp +11 -6
- package/common/cpp/audioapi/core/sources/OscillatorNode.h +2 -2
- package/common/cpp/audioapi/core/sources/StreamerNode.cpp +17 -4
- package/common/cpp/audioapi/core/sources/StreamerNode.h +4 -2
- package/common/cpp/audioapi/core/utils/AudioFileWriter.cpp +1 -1
- package/common/cpp/audioapi/core/utils/AudioRecorderCallback.cpp +2 -2
- package/common/cpp/audioapi/events/AudioEvent.h +30 -0
- package/common/cpp/audioapi/events/AudioEventHandlerRegistry.cpp +9 -20
- package/common/cpp/audioapi/events/AudioEventHandlerRegistry.h +7 -34
- package/common/cpp/audioapi/events/IAudioEventHandlerRegistry.h +5 -4
- package/common/cpp/test/src/MockAudioEventHandlerRegistry.h +5 -10
- package/ios/audioapi/ios/AudioAPIModule.h +3 -1
- package/ios/audioapi/ios/AudioAPIModule.mm +7 -6
- package/ios/audioapi/ios/system/AudioSessionManager.h +3 -1
- package/ios/audioapi/ios/system/AudioSessionManager.mm +8 -1
- package/ios/audioapi/ios/system/SystemNotificationManager.mm +17 -8
- package/ios/audioapi/ios/system/notification/PlaybackNotification.mm +36 -33
- package/lib/commonjs/core/AudioDecoder.js +2 -2
- package/lib/commonjs/core/AudioDecoder.js.map +1 -1
- package/lib/commonjs/specs/NativeAudioAPIModule.js.map +1 -1
- package/lib/commonjs/specs/NativeAudioAPIModule.web.js.map +1 -1
- package/lib/commonjs/system/AudioManager.js +1 -1
- package/lib/commonjs/system/AudioManager.js.map +1 -1
- package/lib/module/core/AudioDecoder.js +2 -2
- package/lib/module/core/AudioDecoder.js.map +1 -1
- package/lib/module/specs/NativeAudioAPIModule.js.map +1 -1
- package/lib/module/specs/NativeAudioAPIModule.web.js.map +1 -1
- package/lib/module/system/AudioManager.js +1 -1
- package/lib/module/system/AudioManager.js.map +1 -1
- package/lib/typescript/core/AudioDecoder.d.ts.map +1 -1
- package/lib/typescript/events/types.d.ts +1 -17
- package/lib/typescript/events/types.d.ts.map +1 -1
- package/lib/typescript/specs/NativeAudioAPIModule.d.ts +1 -1
- package/lib/typescript/specs/NativeAudioAPIModule.d.ts.map +1 -1
- package/lib/typescript/specs/NativeAudioAPIModule.web.d.ts +1 -1
- package/lib/typescript/specs/NativeAudioAPIModule.web.d.ts.map +1 -1
- package/lib/typescript/system/AudioManager.d.ts.map +1 -1
- package/lib/typescript/system/notification/types.d.ts +4 -3
- package/lib/typescript/system/notification/types.d.ts.map +1 -1
- package/lib/typescript/system/types.d.ts +8 -0
- package/lib/typescript/system/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/core/AudioDecoder.ts +2 -2
- package/src/events/types.ts +1 -18
- package/src/specs/NativeAudioAPIModule.ts +3 -2
- package/src/specs/NativeAudioAPIModule.web.ts +2 -1
- package/src/system/AudioManager.ts +2 -1
- package/src/system/notification/types.ts +6 -4
- package/src/system/types.ts +8 -0
|
@@ -124,4 +124,67 @@ namespace audioapi::js_enum_parser {
|
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
+
AudioEvent audioEventFromString(const std::string &event) {
|
|
128
|
+
if (event == "playbackNotificationPlay")
|
|
129
|
+
return AudioEvent::PLAYBACK_NOTIFICATION_PLAY;
|
|
130
|
+
if (event == "playbackNotificationPause")
|
|
131
|
+
return AudioEvent::PLAYBACK_NOTIFICATION_PAUSE;
|
|
132
|
+
if (event == "playbackNotificationStop")
|
|
133
|
+
return AudioEvent::PLAYBACK_NOTIFICATION_STOP;
|
|
134
|
+
if (event == "playbackNotificationNextTrack")
|
|
135
|
+
return AudioEvent::PLAYBACK_NOTIFICATION_NEXT_TRACK;
|
|
136
|
+
if (event == "playbackNotificationPreviousTrack")
|
|
137
|
+
return AudioEvent::PLAYBACK_NOTIFICATION_PREVIOUS_TRACK;
|
|
138
|
+
if (event == "playbackNotificationSkipForward")
|
|
139
|
+
return AudioEvent::PLAYBACK_NOTIFICATION_SKIP_FORWARD;
|
|
140
|
+
if (event == "playbackNotificationSkipBackward")
|
|
141
|
+
return AudioEvent::PLAYBACK_NOTIFICATION_SKIP_BACKWARD;
|
|
142
|
+
if (event == "playbackNotificationSeekForward")
|
|
143
|
+
return AudioEvent::PLAYBACK_NOTIFICATION_SEEK_FORWARD;
|
|
144
|
+
if (event == "playbackNotificationSeekBackward")
|
|
145
|
+
return AudioEvent::PLAYBACK_NOTIFICATION_SEEK_BACKWARD;
|
|
146
|
+
if (event == "playbackNotificationSeekTo")
|
|
147
|
+
return AudioEvent::PLAYBACK_NOTIFICATION_SEEK_TO;
|
|
148
|
+
if (event == "playbackNotificationDismissed")
|
|
149
|
+
return AudioEvent::PLAYBACK_NOTIFICATION_DISMISSED;
|
|
150
|
+
if (event == "recordingNotificationResume")
|
|
151
|
+
return AudioEvent::RECORDING_NOTIFICATION_RESUME;
|
|
152
|
+
if (event == "recordingNotificationPause")
|
|
153
|
+
return AudioEvent::RECORDING_NOTIFICATION_PAUSE;
|
|
154
|
+
if (event == "routeChange")
|
|
155
|
+
return AudioEvent::ROUTE_CHANGE;
|
|
156
|
+
if (event == "interruption")
|
|
157
|
+
return AudioEvent::INTERRUPTION;
|
|
158
|
+
if (event == "volumeChange")
|
|
159
|
+
return AudioEvent::VOLUME_CHANGE;
|
|
160
|
+
if (event == "duck")
|
|
161
|
+
return AudioEvent::DUCK;
|
|
162
|
+
if (event == "ended")
|
|
163
|
+
return AudioEvent::ENDED;
|
|
164
|
+
if (event == "loopEnded")
|
|
165
|
+
return AudioEvent::LOOP_ENDED;
|
|
166
|
+
if (event == "audioReady")
|
|
167
|
+
return AudioEvent::AUDIO_READY;
|
|
168
|
+
if (event == "positionChanged")
|
|
169
|
+
return AudioEvent::POSITION_CHANGED;
|
|
170
|
+
if (event == "bufferEnded")
|
|
171
|
+
return AudioEvent::BUFFER_ENDED;
|
|
172
|
+
if (event == "recorderError")
|
|
173
|
+
return AudioEvent::RECORDER_ERROR;
|
|
174
|
+
|
|
175
|
+
throw std::invalid_argument("Unknown audio event: " + event);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
std::string contextStateToString(ContextState state) {
|
|
179
|
+
switch (state) {
|
|
180
|
+
case ContextState::SUSPENDED:
|
|
181
|
+
return "suspended";
|
|
182
|
+
case ContextState::RUNNING:
|
|
183
|
+
return "running";
|
|
184
|
+
case ContextState::CLOSED:
|
|
185
|
+
return "closed";
|
|
186
|
+
default:
|
|
187
|
+
throw std::invalid_argument("Unknown context state");
|
|
188
|
+
}
|
|
189
|
+
}
|
|
127
190
|
} // namespace audioapi::js_enum_parser
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
#pragma once
|
|
2
|
+
|
|
2
3
|
#include <audioapi/core/analysis/AnalyserNode.h>
|
|
3
4
|
#include <audioapi/core/types/BiquadFilterType.h>
|
|
5
|
+
#include <audioapi/core/types/ContextState.h>
|
|
4
6
|
#include <audioapi/core/types/OscillatorType.h>
|
|
5
7
|
#include <audioapi/core/types/OverSampleType.h>
|
|
8
|
+
#include <audioapi/events/AudioEvent.h>
|
|
6
9
|
#include <string>
|
|
7
10
|
|
|
8
11
|
namespace audioapi::js_enum_parser {
|
|
@@ -14,4 +17,6 @@ std::string oscillatorTypeToString(OscillatorType type);
|
|
|
14
17
|
OscillatorType oscillatorTypeFromString(const std::string &type);
|
|
15
18
|
std::string filterTypeToString(BiquadFilterType type);
|
|
16
19
|
BiquadFilterType filterTypeFromString(const std::string &type);
|
|
20
|
+
AudioEvent audioEventFromString(const std::string &event);
|
|
21
|
+
std::string contextStateToString(ContextState state);
|
|
17
22
|
} // namespace audioapi::js_enum_parser
|
|
@@ -15,10 +15,8 @@ AudioContext::AudioContext(
|
|
|
15
15
|
float sampleRate,
|
|
16
16
|
const std::shared_ptr<IAudioEventHandlerRegistry> &audioEventHandlerRegistry,
|
|
17
17
|
const RuntimeRegistry &runtimeRegistry)
|
|
18
|
-
: BaseAudioContext(audioEventHandlerRegistry, runtimeRegistry),
|
|
19
|
-
|
|
20
|
-
state_ = ContextState::SUSPENDED;
|
|
21
|
-
}
|
|
18
|
+
: BaseAudioContext(sampleRate, audioEventHandlerRegistry, runtimeRegistry),
|
|
19
|
+
isInitialized_(false) {}
|
|
22
20
|
|
|
23
21
|
AudioContext::~AudioContext() {
|
|
24
22
|
if (!isClosed()) {
|
|
@@ -11,12 +11,12 @@
|
|
|
11
11
|
|
|
12
12
|
namespace audioapi {
|
|
13
13
|
|
|
14
|
-
AudioNode::AudioNode(std::shared_ptr<BaseAudioContext
|
|
14
|
+
AudioNode::AudioNode(const std::shared_ptr<BaseAudioContext>& context) : context_(context) {
|
|
15
15
|
audioBus_ =
|
|
16
16
|
std::make_shared<AudioBus>(RENDER_QUANTUM_SIZE, channelCount_, context->getSampleRate());
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
AudioNode::AudioNode(std::shared_ptr<BaseAudioContext
|
|
19
|
+
AudioNode::AudioNode(const std::shared_ptr<BaseAudioContext>& context, const AudioNodeOptions &options)
|
|
20
20
|
: channelCount_(options.channelCount),
|
|
21
21
|
context_(context),
|
|
22
22
|
channelCountMode_(options.channelCountMode),
|
|
@@ -16,12 +16,14 @@ namespace audioapi {
|
|
|
16
16
|
class AudioBus;
|
|
17
17
|
class BaseAudioContext;
|
|
18
18
|
class AudioParam;
|
|
19
|
-
|
|
19
|
+
struct AudioNodeOptions;
|
|
20
20
|
|
|
21
21
|
class AudioNode : public std::enable_shared_from_this<AudioNode> {
|
|
22
22
|
public:
|
|
23
|
-
explicit AudioNode(std::shared_ptr<BaseAudioContext> context);
|
|
24
|
-
explicit AudioNode(
|
|
23
|
+
explicit AudioNode(const std::shared_ptr<BaseAudioContext> &context);
|
|
24
|
+
explicit AudioNode(
|
|
25
|
+
const std::shared_ptr<BaseAudioContext> &context,
|
|
26
|
+
const AudioNodeOptions &options);
|
|
25
27
|
virtual ~AudioNode();
|
|
26
28
|
|
|
27
29
|
int getNumberOfInputs() const;
|
|
@@ -57,9 +59,7 @@ class AudioNode : public std::enable_shared_from_this<AudioNode> {
|
|
|
57
59
|
int numberOfInputs_ = 1;
|
|
58
60
|
int numberOfOutputs_ = 1;
|
|
59
61
|
ChannelCountMode channelCountMode_ = ChannelCountMode::MAX;
|
|
60
|
-
ChannelInterpretation channelInterpretation_ =
|
|
61
|
-
|
|
62
|
-
ChannelInterpretation::SPEAKERS;
|
|
62
|
+
ChannelInterpretation channelInterpretation_ = ChannelInterpretation::SPEAKERS;
|
|
63
63
|
|
|
64
64
|
std::unordered_set<AudioNode *> inputNodes_ = {};
|
|
65
65
|
std::unordered_set<std::shared_ptr<AudioNode>> outputNodes_ = {};
|
|
@@ -36,9 +36,11 @@
|
|
|
36
36
|
namespace audioapi {
|
|
37
37
|
|
|
38
38
|
BaseAudioContext::BaseAudioContext(
|
|
39
|
+
float sampleRate,
|
|
39
40
|
const std::shared_ptr<IAudioEventHandlerRegistry> &audioEventHandlerRegistry,
|
|
40
41
|
const RuntimeRegistry &runtimeRegistry)
|
|
41
|
-
:
|
|
42
|
+
: sampleRate_(sampleRate),
|
|
43
|
+
nodeManager_(std::make_shared<AudioNodeManager>()),
|
|
42
44
|
audioEventHandlerRegistry_(audioEventHandlerRegistry),
|
|
43
45
|
runtimeRegistry_(runtimeRegistry) {}
|
|
44
46
|
|
|
@@ -46,16 +48,12 @@ void BaseAudioContext::initialize() {
|
|
|
46
48
|
destination_ = std::make_shared<AudioDestinationNode>(shared_from_this());
|
|
47
49
|
}
|
|
48
50
|
|
|
49
|
-
|
|
50
|
-
if (isDriverRunning()) {
|
|
51
|
-
return
|
|
51
|
+
ContextState BaseAudioContext::getState() {
|
|
52
|
+
if (isDriverRunning() || state_ == ContextState::CLOSED) {
|
|
53
|
+
return state_;
|
|
52
54
|
}
|
|
53
55
|
|
|
54
|
-
|
|
55
|
-
return BaseAudioContext::toString(ContextState::CLOSED);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return BaseAudioContext::toString(ContextState::SUSPENDED);
|
|
56
|
+
return ContextState::SUSPENDED;
|
|
59
57
|
}
|
|
60
58
|
|
|
61
59
|
float BaseAudioContext::getSampleRate() const {
|
|
@@ -235,19 +233,6 @@ float BaseAudioContext::getNyquistFrequency() const {
|
|
|
235
233
|
return sampleRate_ / 2.0f;
|
|
236
234
|
}
|
|
237
235
|
|
|
238
|
-
std::string BaseAudioContext::toString(ContextState state) {
|
|
239
|
-
switch (state) {
|
|
240
|
-
case ContextState::SUSPENDED:
|
|
241
|
-
return "suspended";
|
|
242
|
-
case ContextState::RUNNING:
|
|
243
|
-
return "running";
|
|
244
|
-
case ContextState::CLOSED:
|
|
245
|
-
return "closed";
|
|
246
|
-
default:
|
|
247
|
-
throw std::invalid_argument("Unknown context state");
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
236
|
std::shared_ptr<PeriodicWave> BaseAudioContext::getBasicWaveForm(OscillatorType type) {
|
|
252
237
|
switch (type) {
|
|
253
238
|
case OscillatorType::SINE:
|
|
@@ -38,31 +38,30 @@ class WorkletSourceNode;
|
|
|
38
38
|
class WorkletNode;
|
|
39
39
|
class WorkletProcessingNode;
|
|
40
40
|
class StreamerNode;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
41
|
+
struct GainOptions;
|
|
42
|
+
struct StereoPannerOptions;
|
|
43
|
+
struct ConvolverOptions;
|
|
44
|
+
struct ConstantSourceOptions;
|
|
45
|
+
struct AnalyserOptions;
|
|
46
|
+
struct BiquadFilterOptions;
|
|
47
|
+
struct OscillatorOptions;
|
|
48
|
+
struct BaseAudioBufferSourceOptions;
|
|
49
|
+
struct AudioBufferSourceOptions;
|
|
50
|
+
struct StreamerOptions;
|
|
51
|
+
struct AudioBufferOptions;
|
|
52
|
+
struct DelayOptions;
|
|
53
|
+
struct IIRFilterOptions;
|
|
54
|
+
struct WaveShaperOptions;
|
|
55
55
|
|
|
56
56
|
class BaseAudioContext : public std::enable_shared_from_this<BaseAudioContext> {
|
|
57
57
|
public:
|
|
58
58
|
explicit BaseAudioContext(
|
|
59
|
+
float sampleRate,
|
|
59
60
|
const std::shared_ptr<IAudioEventHandlerRegistry> &audioEventHandlerRegistry,
|
|
60
61
|
const RuntimeRegistry &runtimeRegistry);
|
|
61
62
|
virtual ~BaseAudioContext() = default;
|
|
62
63
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
std::string getState();
|
|
64
|
+
ContextState getState();
|
|
66
65
|
[[nodiscard]] float getSampleRate() const;
|
|
67
66
|
[[nodiscard]] double getCurrentTime() const;
|
|
68
67
|
[[nodiscard]] std::size_t getCurrentSampleFrame() const;
|
|
@@ -112,13 +111,12 @@ class BaseAudioContext : public std::enable_shared_from_this<BaseAudioContext> {
|
|
|
112
111
|
[[nodiscard]] bool isSuspended() const;
|
|
113
112
|
[[nodiscard]] bool isClosed() const;
|
|
114
113
|
|
|
115
|
-
|
|
116
|
-
static std::string toString(ContextState state);
|
|
114
|
+
virtual void initialize();
|
|
117
115
|
|
|
116
|
+
protected:
|
|
118
117
|
std::shared_ptr<AudioDestinationNode> destination_;
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
ContextState state_ = ContextState::RUNNING;
|
|
118
|
+
float sampleRate_;
|
|
119
|
+
ContextState state_ = ContextState::SUSPENDED;
|
|
122
120
|
std::shared_ptr<AudioNodeManager> nodeManager_;
|
|
123
121
|
|
|
124
122
|
private:
|
|
@@ -24,14 +24,11 @@ OfflineAudioContext::OfflineAudioContext(
|
|
|
24
24
|
float sampleRate,
|
|
25
25
|
const std::shared_ptr<IAudioEventHandlerRegistry> &audioEventHandlerRegistry,
|
|
26
26
|
const RuntimeRegistry &runtimeRegistry)
|
|
27
|
-
: BaseAudioContext(audioEventHandlerRegistry, runtimeRegistry),
|
|
27
|
+
: BaseAudioContext(sampleRate, audioEventHandlerRegistry, runtimeRegistry),
|
|
28
28
|
length_(length),
|
|
29
29
|
numberOfChannels_(numberOfChannels),
|
|
30
|
-
currentSampleFrame_(0)
|
|
31
|
-
|
|
32
|
-
resultBus_ =
|
|
33
|
-
std::make_shared<AudioBus>(static_cast<int>(length_), numberOfChannels_, sampleRate_);
|
|
34
|
-
}
|
|
30
|
+
currentSampleFrame_(0),
|
|
31
|
+
resultBus_(std::make_shared<AudioBus>(length, numberOfChannels, sampleRate)) {}
|
|
35
32
|
|
|
36
33
|
OfflineAudioContext::~OfflineAudioContext() {
|
|
37
34
|
nodeManager_->cleanup();
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
#include <audioapi/utils/AudioArray.h>
|
|
8
8
|
#include <audioapi/utils/AudioBus.h>
|
|
9
9
|
#include <audioapi/utils/CircularAudioArray.h>
|
|
10
|
+
|
|
10
11
|
#include <algorithm>
|
|
11
12
|
#include <memory>
|
|
12
13
|
#include <string>
|
|
@@ -14,7 +15,9 @@
|
|
|
14
15
|
|
|
15
16
|
namespace audioapi {
|
|
16
17
|
|
|
17
|
-
AnalyserNode::AnalyserNode(
|
|
18
|
+
AnalyserNode::AnalyserNode(
|
|
19
|
+
const std::shared_ptr<BaseAudioContext> &context,
|
|
20
|
+
const AnalyserOptions &options)
|
|
18
21
|
: AudioNode(context, options),
|
|
19
22
|
fftSize_(options.fftSize),
|
|
20
23
|
minDecibels_(options.minDecibels),
|
|
@@ -194,7 +197,7 @@ void AnalyserNode::setWindowData(AnalyserNode::WindowType type, int size) {
|
|
|
194
197
|
}
|
|
195
198
|
|
|
196
199
|
windowType_ = type;
|
|
197
|
-
if (windowData_ == nullptr|| windowData_->getSize() != size) {
|
|
200
|
+
if (windowData_ == nullptr || windowData_->getSize() != size) {
|
|
198
201
|
windowData_ = std::make_shared<AudioArray>(size);
|
|
199
202
|
}
|
|
200
203
|
|
|
@@ -15,12 +15,14 @@ namespace audioapi {
|
|
|
15
15
|
class AudioBus;
|
|
16
16
|
class AudioArray;
|
|
17
17
|
class CircularAudioArray;
|
|
18
|
-
|
|
18
|
+
struct AnalyserOptions;
|
|
19
19
|
|
|
20
20
|
class AnalyserNode : public AudioNode {
|
|
21
21
|
public:
|
|
22
22
|
enum class WindowType { BLACKMAN, HANN };
|
|
23
|
-
explicit AnalyserNode(
|
|
23
|
+
explicit AnalyserNode(
|
|
24
|
+
const std::shared_ptr<BaseAudioContext> &context,
|
|
25
|
+
const AnalyserOptions &options);
|
|
24
26
|
|
|
25
27
|
int getFftSize() const;
|
|
26
28
|
int getFrequencyBinCount() const;
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
namespace audioapi {
|
|
9
9
|
|
|
10
|
-
AudioDestinationNode::AudioDestinationNode(std::shared_ptr<BaseAudioContext> context)
|
|
10
|
+
AudioDestinationNode::AudioDestinationNode(const std::shared_ptr<BaseAudioContext> &context)
|
|
11
11
|
: AudioNode(context), currentSampleFrame_(0) {
|
|
12
12
|
numberOfOutputs_ = 0;
|
|
13
13
|
numberOfInputs_ = 1;
|
|
@@ -14,7 +14,7 @@ class BaseAudioContext;
|
|
|
14
14
|
|
|
15
15
|
class AudioDestinationNode : public AudioNode {
|
|
16
16
|
public:
|
|
17
|
-
explicit AudioDestinationNode(std::shared_ptr<BaseAudioContext> context);
|
|
17
|
+
explicit AudioDestinationNode(const std::shared_ptr<BaseAudioContext> &context);
|
|
18
18
|
|
|
19
19
|
std::size_t getCurrentSampleFrame() const;
|
|
20
20
|
double getCurrentTime() const;
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
|
|
40
40
|
namespace audioapi {
|
|
41
41
|
|
|
42
|
-
BiquadFilterNode::BiquadFilterNode(std::shared_ptr<BaseAudioContext
|
|
42
|
+
BiquadFilterNode::BiquadFilterNode(const std::shared_ptr<BaseAudioContext>& context, const BiquadFilterOptions &options) : AudioNode(context, options) {
|
|
43
43
|
frequencyParam_ =
|
|
44
44
|
std::make_shared<AudioParam>(options.frequency, 0.0f, context->getNyquistFrequency(), context);
|
|
45
45
|
detuneParam_ = std::make_shared<AudioParam>(
|
|
@@ -112,11 +112,11 @@ void BiquadFilterNode::getFrequencyResponse(
|
|
|
112
112
|
#endif
|
|
113
113
|
|
|
114
114
|
// Use double precision for later calculations
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
115
|
+
auto b0 = static_cast<double>(b0_);
|
|
116
|
+
auto b1 = static_cast<double>(b1_);
|
|
117
|
+
auto b2 = static_cast<double>(b2_);
|
|
118
|
+
auto a1 = static_cast<double>(a1_);
|
|
119
|
+
auto a2 = static_cast<double>(a2_);
|
|
120
120
|
|
|
121
121
|
std::shared_ptr<BaseAudioContext> context = context_.lock();
|
|
122
122
|
if (!context)
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
namespace audioapi {
|
|
47
47
|
|
|
48
48
|
class AudioBus;
|
|
49
|
-
|
|
49
|
+
struct BiquadFilterOptions;
|
|
50
50
|
|
|
51
51
|
class BiquadFilterNode : public AudioNode {
|
|
52
52
|
#if RN_AUDIO_API_TEST
|
|
@@ -56,7 +56,7 @@ class BiquadFilterNode : public AudioNode {
|
|
|
56
56
|
|
|
57
57
|
public:
|
|
58
58
|
explicit BiquadFilterNode(
|
|
59
|
-
std::shared_ptr<BaseAudioContext> context,
|
|
59
|
+
const std::shared_ptr<BaseAudioContext> &context,
|
|
60
60
|
const BiquadFilterOptions &options);
|
|
61
61
|
|
|
62
62
|
[[nodiscard]] BiquadFilterType getType();
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
#include <vector>
|
|
13
13
|
|
|
14
14
|
namespace audioapi {
|
|
15
|
-
ConvolverNode::ConvolverNode(std::shared_ptr<BaseAudioContext
|
|
15
|
+
ConvolverNode::ConvolverNode(const std::shared_ptr<BaseAudioContext>& context, const ConvolverOptions &options)
|
|
16
16
|
: AudioNode(context, options),
|
|
17
17
|
gainCalibrationSampleRate_(context->getSampleRate()),
|
|
18
18
|
remainingSegments_(0),
|
|
@@ -17,12 +17,12 @@ namespace audioapi {
|
|
|
17
17
|
|
|
18
18
|
class AudioBus;
|
|
19
19
|
class AudioBuffer;
|
|
20
|
-
|
|
20
|
+
struct ConvolverOptions;
|
|
21
21
|
|
|
22
22
|
class ConvolverNode : public AudioNode {
|
|
23
23
|
public:
|
|
24
24
|
explicit ConvolverNode(
|
|
25
|
-
std::shared_ptr<BaseAudioContext> context,
|
|
25
|
+
const std::shared_ptr<BaseAudioContext> &context,
|
|
26
26
|
const ConvolverOptions &options);
|
|
27
27
|
|
|
28
28
|
[[nodiscard]] bool getNormalize_() const;
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
namespace audioapi {
|
|
10
10
|
|
|
11
|
-
DelayNode::DelayNode(std::shared_ptr<BaseAudioContext
|
|
11
|
+
DelayNode::DelayNode(const std::shared_ptr<BaseAudioContext>& context, const DelayOptions &options)
|
|
12
12
|
: AudioNode(context, options),
|
|
13
13
|
delayTimeParam_(std::make_shared<AudioParam>(options.delayTime, 0, options.maxDelayTime, context)),
|
|
14
14
|
delayBuffer_(
|
|
@@ -9,11 +9,11 @@
|
|
|
9
9
|
namespace audioapi {
|
|
10
10
|
|
|
11
11
|
class AudioBus;
|
|
12
|
-
|
|
12
|
+
struct DelayOptions;
|
|
13
13
|
|
|
14
14
|
class DelayNode : public AudioNode {
|
|
15
15
|
public:
|
|
16
|
-
explicit DelayNode(std::shared_ptr<BaseAudioContext> context, const DelayOptions &options);
|
|
16
|
+
explicit DelayNode(const std::shared_ptr<BaseAudioContext> &context, const DelayOptions &options);
|
|
17
17
|
|
|
18
18
|
[[nodiscard]] std::shared_ptr<AudioParam> getDelayTimeParam() const;
|
|
19
19
|
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
namespace audioapi {
|
|
10
10
|
|
|
11
|
-
GainNode::GainNode(std::shared_ptr<BaseAudioContext> context, const GainOptions &options)
|
|
11
|
+
GainNode::GainNode(const std::shared_ptr<BaseAudioContext> &context, const GainOptions &options)
|
|
12
12
|
: AudioNode(context, options),
|
|
13
13
|
gainParam_(
|
|
14
14
|
std::make_shared<AudioParam>(
|
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
namespace audioapi {
|
|
9
9
|
|
|
10
10
|
class AudioBus;
|
|
11
|
-
|
|
11
|
+
struct GainOptions;
|
|
12
12
|
|
|
13
13
|
class GainNode : public AudioNode {
|
|
14
14
|
public:
|
|
15
|
-
explicit GainNode(std::shared_ptr<BaseAudioContext> context, const GainOptions &options);
|
|
15
|
+
explicit GainNode(const std::shared_ptr<BaseAudioContext> &context, const GainOptions &options);
|
|
16
16
|
|
|
17
17
|
[[nodiscard]] std::shared_ptr<AudioParam> getGainParam() const;
|
|
18
18
|
|
|
@@ -36,10 +36,12 @@
|
|
|
36
36
|
|
|
37
37
|
namespace audioapi {
|
|
38
38
|
|
|
39
|
-
IIRFilterNode::IIRFilterNode(
|
|
39
|
+
IIRFilterNode::IIRFilterNode(
|
|
40
|
+
const std::shared_ptr<BaseAudioContext> &context,
|
|
41
|
+
const IIRFilterOptions &options)
|
|
40
42
|
: AudioNode(context, options),
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
feedforward_(std::move(options.feedforward)),
|
|
44
|
+
feedback_(std::move(options.feedback)) {
|
|
43
45
|
|
|
44
46
|
int maxChannels = MAX_CHANNEL_COUNT;
|
|
45
47
|
xBuffers_.resize(maxChannels);
|
|
@@ -33,13 +33,13 @@
|
|
|
33
33
|
|
|
34
34
|
namespace audioapi {
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
struct IIRFilterOptions;
|
|
37
37
|
|
|
38
38
|
class IIRFilterNode : public AudioNode {
|
|
39
39
|
|
|
40
40
|
public:
|
|
41
41
|
explicit IIRFilterNode(
|
|
42
|
-
std::shared_ptr<BaseAudioContext> context,
|
|
42
|
+
const std::shared_ptr<BaseAudioContext> &context,
|
|
43
43
|
const IIRFilterOptions &options);
|
|
44
44
|
|
|
45
45
|
void getFrequencyResponse(
|
|
@@ -10,8 +10,11 @@
|
|
|
10
10
|
|
|
11
11
|
namespace audioapi {
|
|
12
12
|
|
|
13
|
-
StereoPannerNode::StereoPannerNode(
|
|
14
|
-
|
|
13
|
+
StereoPannerNode::StereoPannerNode(
|
|
14
|
+
const std::shared_ptr<BaseAudioContext> &context,
|
|
15
|
+
const StereoPannerOptions &options)
|
|
16
|
+
: AudioNode(context, options),
|
|
17
|
+
panParam_(std::make_shared<AudioParam>(options.pan, -1.0f, 1.0f, context)) {
|
|
15
18
|
isInitialized_ = true;
|
|
16
19
|
}
|
|
17
20
|
|
|
@@ -10,12 +10,12 @@
|
|
|
10
10
|
namespace audioapi {
|
|
11
11
|
|
|
12
12
|
class AudioBus;
|
|
13
|
-
|
|
13
|
+
struct StereoPannerOptions;
|
|
14
14
|
|
|
15
15
|
class StereoPannerNode : public AudioNode {
|
|
16
16
|
public:
|
|
17
17
|
explicit StereoPannerNode(
|
|
18
|
-
std::shared_ptr<BaseAudioContext> context,
|
|
18
|
+
const std::shared_ptr<BaseAudioContext> &context,
|
|
19
19
|
const StereoPannerOptions &options);
|
|
20
20
|
|
|
21
21
|
[[nodiscard]] std::shared_ptr<AudioParam> getPanParam() const;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
#include <audioapi/HostObjects/utils/NodeOptions.h>
|
|
1
2
|
#include <audioapi/core/BaseAudioContext.h>
|
|
2
3
|
#include <audioapi/core/effects/WaveShaperNode.h>
|
|
3
4
|
#include <audioapi/dsp/VectorMath.h>
|
|
4
5
|
#include <audioapi/utils/AudioArray.h>
|
|
5
6
|
#include <audioapi/utils/AudioBus.h>
|
|
6
|
-
#include <audioapi/HostObjects/utils/NodeOptions.h>
|
|
7
7
|
|
|
8
8
|
#include <algorithm>
|
|
9
9
|
#include <memory>
|
|
@@ -11,7 +11,9 @@
|
|
|
11
11
|
|
|
12
12
|
namespace audioapi {
|
|
13
13
|
|
|
14
|
-
WaveShaperNode::WaveShaperNode(
|
|
14
|
+
WaveShaperNode::WaveShaperNode(
|
|
15
|
+
const std::shared_ptr<BaseAudioContext> &context,
|
|
16
|
+
const WaveShaperOptions &options)
|
|
15
17
|
: AudioNode(context, options), oversample_(options.oversample) {
|
|
16
18
|
|
|
17
19
|
waveShapers_.reserve(6);
|
|
@@ -16,12 +16,12 @@ namespace audioapi {
|
|
|
16
16
|
|
|
17
17
|
class AudioBus;
|
|
18
18
|
class AudioArray;
|
|
19
|
-
|
|
19
|
+
struct WaveShaperOptions;
|
|
20
20
|
|
|
21
21
|
class WaveShaperNode : public AudioNode {
|
|
22
22
|
public:
|
|
23
23
|
explicit WaveShaperNode(
|
|
24
|
-
std::shared_ptr<BaseAudioContext> context,
|
|
24
|
+
const std::shared_ptr<BaseAudioContext> &context,
|
|
25
25
|
const WaveShaperOptions &options);
|
|
26
26
|
|
|
27
27
|
[[nodiscard]] OverSampleType getOversample() const;
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
namespace audioapi {
|
|
14
14
|
AudioBufferBaseSourceNode::AudioBufferBaseSourceNode(
|
|
15
|
-
std::shared_ptr<BaseAudioContext> context,
|
|
15
|
+
const std::shared_ptr<BaseAudioContext> &context,
|
|
16
16
|
const BaseAudioBufferSourceOptions &options)
|
|
17
17
|
: AudioScheduledSourceNode(context),
|
|
18
18
|
pitchCorrection_(options.pitchCorrection),
|
|
@@ -42,7 +42,7 @@ void AudioBufferBaseSourceNode::setOnPositionChangedCallbackId(uint64_t callback
|
|
|
42
42
|
auto oldCallbackId = onPositionChangedCallbackId_.exchange(callbackId, std::memory_order_acq_rel);
|
|
43
43
|
|
|
44
44
|
if (oldCallbackId != 0) {
|
|
45
|
-
audioEventHandlerRegistry_->unregisterHandler(
|
|
45
|
+
audioEventHandlerRegistry_->unregisterHandler(AudioEvent::POSITION_CHANGED, oldCallbackId);
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
|
|
@@ -90,7 +90,7 @@ void AudioBufferBaseSourceNode::sendOnPositionChangedEvent() {
|
|
|
90
90
|
std::unordered_map<std::string, EventValue> body = {{"value", getCurrentPosition()}};
|
|
91
91
|
|
|
92
92
|
audioEventHandlerRegistry_->invokeHandlerWithEventBody(
|
|
93
|
-
|
|
93
|
+
AudioEvent::POSITION_CHANGED, onPositionChangedCallbackId, body);
|
|
94
94
|
|
|
95
95
|
onPositionChangedTime_ = 0;
|
|
96
96
|
}
|
|
@@ -157,7 +157,13 @@ void AudioBufferBaseSourceNode::processWithoutPitchCorrection(
|
|
|
157
157
|
}
|
|
158
158
|
auto computedPlaybackRate =
|
|
159
159
|
getComputedPlaybackRateValue(framesToProcess, context->getCurrentTime());
|
|
160
|
-
updatePlaybackInfo(
|
|
160
|
+
updatePlaybackInfo(
|
|
161
|
+
processingBus,
|
|
162
|
+
framesToProcess,
|
|
163
|
+
startOffset,
|
|
164
|
+
offsetLength,
|
|
165
|
+
context->getSampleRate(),
|
|
166
|
+
context->getCurrentSampleFrame());
|
|
161
167
|
|
|
162
168
|
if (computedPlaybackRate == 0.0f || (!isPlaying() && !isStopScheduled())) {
|
|
163
169
|
processingBus->zero();
|
|
@@ -11,12 +11,12 @@ namespace audioapi {
|
|
|
11
11
|
|
|
12
12
|
class AudioBus;
|
|
13
13
|
class AudioParam;
|
|
14
|
-
|
|
14
|
+
struct BaseAudioBufferSourceOptions;
|
|
15
15
|
|
|
16
16
|
class AudioBufferBaseSourceNode : public AudioScheduledSourceNode {
|
|
17
17
|
public:
|
|
18
18
|
explicit AudioBufferBaseSourceNode(
|
|
19
|
-
std::shared_ptr<BaseAudioContext> context,
|
|
19
|
+
const std::shared_ptr<BaseAudioContext> &context,
|
|
20
20
|
const BaseAudioBufferSourceOptions &options);
|
|
21
21
|
|
|
22
22
|
[[nodiscard]] std::shared_ptr<AudioParam> getDetuneParam() const;
|