react-native-audio-api 0.6.0-rc.5 → 0.6.0
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 +35 -2
- package/android/src/main/cpp/audioapi/android/AudioAPIModule.h +4 -0
- package/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.cpp +31 -17
- package/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.h +1 -3
- package/android/src/main/java/com/swmansion/audioapi/AudioAPIModule.kt +56 -2
- package/android/src/main/java/com/swmansion/audioapi/AudioAPIPackage.kt +0 -12
- package/android/src/main/java/com/swmansion/audioapi/system/AudioFocusListener.kt +35 -12
- package/android/src/main/java/com/swmansion/audioapi/system/LockScreenManager.kt +30 -29
- package/android/src/main/java/com/swmansion/audioapi/system/MediaNotificationManager.kt +20 -22
- package/android/src/main/java/com/swmansion/audioapi/system/MediaReceiver.kt +19 -9
- package/android/src/main/java/com/swmansion/audioapi/system/MediaSessionCallback.kt +30 -11
- package/android/src/main/java/com/swmansion/audioapi/system/MediaSessionManager.kt +34 -27
- package/android/src/main/java/com/swmansion/audioapi/system/VolumeChangeListener.kt +10 -5
- package/android/src/oldarch/NativeAudioAPIModuleSpec.java +39 -0
- package/common/cpp/audioapi/AudioAPIModuleInstaller.h +20 -14
- package/common/cpp/audioapi/HostObjects/AudioBufferSourceNodeHostObject.h +2 -3
- package/common/cpp/audioapi/HostObjects/AudioNodeHostObject.h +24 -11
- package/common/cpp/audioapi/HostObjects/AudioParamHostObject.h +1 -0
- package/common/cpp/audioapi/HostObjects/AudioRecorderHostObject.h +10 -89
- package/common/cpp/audioapi/HostObjects/AudioScheduledSourceNodeHostObject.h +3 -24
- package/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.h +2 -2
- package/common/cpp/audioapi/HostObjects/OscillatorNodeHostObject.h +2 -3
- package/common/cpp/audioapi/core/AudioContext.cpp +4 -1
- package/common/cpp/audioapi/core/AudioContext.h +1 -1
- package/common/cpp/audioapi/core/AudioNode.cpp +31 -2
- package/common/cpp/audioapi/core/AudioNode.h +7 -1
- package/common/cpp/audioapi/core/AudioParam.cpp +84 -2
- package/common/cpp/audioapi/core/AudioParam.h +14 -1
- package/common/cpp/audioapi/core/BaseAudioContext.cpp +6 -1
- package/common/cpp/audioapi/core/BaseAudioContext.h +7 -1
- package/common/cpp/audioapi/core/OfflineAudioContext.cpp +3 -2
- package/common/cpp/audioapi/core/OfflineAudioContext.h +1 -1
- package/common/cpp/audioapi/core/effects/BiquadFilterNode.cpp +28 -26
- package/common/cpp/audioapi/core/effects/GainNode.cpp +9 -9
- package/common/cpp/audioapi/core/effects/StereoPannerNode.cpp +5 -2
- package/common/cpp/audioapi/core/inputs/AudioRecorder.cpp +56 -0
- package/common/cpp/audioapi/core/inputs/AudioRecorder.h +13 -13
- package/common/cpp/audioapi/core/sources/AudioBufferSourceNode.cpp +14 -10
- package/common/cpp/audioapi/core/sources/AudioBufferSourceNode.h +1 -1
- package/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.cpp +7 -6
- package/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.h +5 -3
- package/common/cpp/audioapi/core/sources/OscillatorNode.cpp +15 -10
- package/common/cpp/audioapi/core/utils/AudioNodeManager.cpp +35 -1
- package/common/cpp/audioapi/core/utils/AudioNodeManager.h +15 -1
- package/common/cpp/audioapi/events/AudioEventHandlerRegistry.cpp +108 -0
- package/common/cpp/audioapi/events/AudioEventHandlerRegistry.h +62 -0
- package/common/cpp/audioapi/events/AudioEventHandlerRegistryHostObject.h +48 -0
- package/common/cpp/audioapi/jsi/JsiPromise.cpp +3 -4
- package/ios/audioapi/ios/AudioAPIModule.h +13 -0
- package/ios/audioapi/ios/AudioAPIModule.mm +115 -6
- package/ios/audioapi/ios/core/IOSAudioRecorder.h +2 -10
- package/ios/audioapi/ios/core/IOSAudioRecorder.mm +6 -17
- package/ios/audioapi/ios/core/NativeAudioPlayer.m +2 -0
- package/ios/audioapi/ios/core/NativeAudioRecorder.m +7 -3
- package/ios/audioapi/ios/events/IOSAudioEventHandlerRegistry.h +7 -0
- package/ios/audioapi/ios/events/IOSAudioEventHandlerRegistry.mm +12 -0
- package/ios/audioapi/ios/system/AudioEngine.h +5 -0
- package/ios/audioapi/ios/system/AudioEngine.mm +7 -15
- package/ios/audioapi/ios/system/AudioSessionManager.h +1 -1
- package/ios/audioapi/ios/system/AudioSessionManager.mm +2 -18
- package/ios/audioapi/ios/system/LockScreenManager.h +3 -3
- package/ios/audioapi/ios/system/LockScreenManager.mm +36 -48
- package/ios/audioapi/ios/system/NotificationManager.h +3 -3
- package/ios/audioapi/ios/system/NotificationManager.mm +21 -29
- package/lib/commonjs/api.js +4 -4
- package/lib/commonjs/api.js.map +1 -1
- package/lib/commonjs/core/AudioBufferSourceNode.js +2 -2
- package/lib/commonjs/core/AudioBufferSourceNode.js.map +1 -1
- package/lib/commonjs/core/AudioNode.js +8 -2
- package/lib/commonjs/core/AudioNode.js.map +1 -1
- package/lib/commonjs/core/AudioParam.js +2 -1
- package/lib/commonjs/core/AudioParam.js.map +1 -1
- package/lib/commonjs/core/AudioRecorder.js +11 -28
- package/lib/commonjs/core/AudioRecorder.js.map +1 -1
- package/lib/commonjs/core/AudioScheduledSourceNode.js +4 -1
- package/lib/commonjs/core/AudioScheduledSourceNode.js.map +1 -1
- package/lib/commonjs/core/BiquadFilterNode.js +4 -4
- package/lib/commonjs/core/BiquadFilterNode.js.map +1 -1
- package/lib/commonjs/core/GainNode.js +1 -1
- package/lib/commonjs/core/GainNode.js.map +1 -1
- package/lib/commonjs/core/OscillatorNode.js +2 -2
- package/lib/commonjs/core/OscillatorNode.js.map +1 -1
- package/lib/commonjs/core/StereoPannerNode.js +1 -1
- package/lib/commonjs/core/StereoPannerNode.js.map +1 -1
- package/lib/commonjs/events/AudioEventEmitter.js +22 -0
- package/lib/commonjs/events/AudioEventEmitter.js.map +1 -0
- package/lib/commonjs/events/AudioEventSubscription.js +20 -0
- package/lib/commonjs/events/AudioEventSubscription.js.map +1 -0
- package/lib/commonjs/events/index.js +21 -0
- package/lib/commonjs/events/index.js.map +1 -0
- package/lib/commonjs/events/types.js +6 -0
- package/lib/commonjs/events/types.js.map +1 -0
- package/lib/commonjs/hooks/useSytemVolume.js +1 -1
- package/lib/commonjs/hooks/useSytemVolume.js.map +1 -1
- package/lib/commonjs/specs/NativeAudioAPIModule.js +3 -3
- package/lib/commonjs/specs/NativeAudioAPIModule.js.map +1 -1
- package/lib/commonjs/specs/index.js +2 -16
- package/lib/commonjs/specs/index.js.map +1 -1
- package/lib/commonjs/system/AudioManager.js +22 -28
- package/lib/commonjs/system/AudioManager.js.map +1 -1
- package/lib/module/api.js +2 -2
- package/lib/module/api.js.map +1 -1
- package/lib/module/core/AudioBufferSourceNode.js +2 -2
- package/lib/module/core/AudioBufferSourceNode.js.map +1 -1
- package/lib/module/core/AudioNode.js +7 -2
- package/lib/module/core/AudioNode.js.map +1 -1
- package/lib/module/core/AudioParam.js +2 -1
- package/lib/module/core/AudioParam.js.map +1 -1
- package/lib/module/core/AudioRecorder.js +11 -28
- package/lib/module/core/AudioRecorder.js.map +1 -1
- package/lib/module/core/AudioScheduledSourceNode.js +4 -1
- package/lib/module/core/AudioScheduledSourceNode.js.map +1 -1
- package/lib/module/core/BiquadFilterNode.js +4 -4
- package/lib/module/core/BiquadFilterNode.js.map +1 -1
- package/lib/module/core/GainNode.js +1 -1
- package/lib/module/core/GainNode.js.map +1 -1
- package/lib/module/core/OscillatorNode.js +2 -2
- package/lib/module/core/OscillatorNode.js.map +1 -1
- package/lib/module/core/StereoPannerNode.js +1 -1
- package/lib/module/core/StereoPannerNode.js.map +1 -1
- package/lib/module/events/AudioEventEmitter.js +16 -0
- package/lib/module/events/AudioEventEmitter.js.map +1 -0
- package/lib/module/events/AudioEventSubscription.js +15 -0
- package/lib/module/events/AudioEventSubscription.js.map +1 -0
- package/lib/module/events/index.js +6 -0
- package/lib/module/events/index.js.map +1 -0
- package/lib/module/events/types.js +4 -0
- package/lib/module/events/types.js.map +1 -0
- package/lib/module/hooks/useSytemVolume.js +1 -1
- package/lib/module/hooks/useSytemVolume.js.map +1 -1
- package/lib/module/specs/NativeAudioAPIModule.js +3 -2
- package/lib/module/specs/NativeAudioAPIModule.js.map +1 -1
- package/lib/module/specs/index.js +2 -3
- package/lib/module/specs/index.js.map +1 -1
- package/lib/module/system/AudioManager.js +23 -29
- package/lib/module/system/AudioManager.js.map +1 -1
- package/lib/typescript/api.d.ts +2 -1
- package/lib/typescript/api.d.ts.map +1 -1
- package/lib/typescript/core/AudioNode.d.ts +2 -1
- package/lib/typescript/core/AudioNode.d.ts.map +1 -1
- package/lib/typescript/core/AudioParam.d.ts +4 -2
- package/lib/typescript/core/AudioParam.d.ts.map +1 -1
- package/lib/typescript/core/AudioRecorder.d.ts +4 -14
- package/lib/typescript/core/AudioRecorder.d.ts.map +1 -1
- package/lib/typescript/core/AudioScheduledSourceNode.d.ts +3 -1
- package/lib/typescript/core/AudioScheduledSourceNode.d.ts.map +1 -1
- package/lib/typescript/events/AudioEventEmitter.d.ts +10 -0
- package/lib/typescript/events/AudioEventEmitter.d.ts.map +1 -0
- package/lib/typescript/events/AudioEventSubscription.d.ts +11 -0
- package/lib/typescript/events/AudioEventSubscription.d.ts.map +1 -0
- package/lib/typescript/events/index.d.ts +4 -0
- package/lib/typescript/events/index.d.ts.map +1 -0
- package/lib/typescript/events/types.d.ts +50 -0
- package/lib/typescript/events/types.d.ts.map +1 -0
- package/lib/typescript/hooks/useSytemVolume.d.ts.map +1 -1
- package/lib/typescript/interfaces.d.ts +10 -10
- package/lib/typescript/interfaces.d.ts.map +1 -1
- package/lib/typescript/specs/NativeAudioAPIModule.d.ts +15 -3
- package/lib/typescript/specs/NativeAudioAPIModule.d.ts.map +1 -1
- package/lib/typescript/specs/index.d.ts +2 -3
- package/lib/typescript/specs/index.d.ts.map +1 -1
- package/lib/typescript/system/AudioManager.d.ts +6 -4
- package/lib/typescript/system/AudioManager.d.ts.map +1 -1
- package/lib/typescript/system/types.d.ts +0 -34
- package/lib/typescript/system/types.d.ts.map +1 -1
- package/lib/typescript/types.d.ts +0 -1
- package/lib/typescript/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/api.ts +6 -3
- package/src/core/AudioBufferSourceNode.ts +2 -2
- package/src/core/AudioNode.ts +8 -3
- package/src/core/AudioParam.ts +5 -2
- package/src/core/AudioRecorder.ts +22 -62
- package/src/core/AudioScheduledSourceNode.ts +13 -2
- package/src/core/BiquadFilterNode.ts +4 -4
- package/src/core/GainNode.ts +1 -1
- package/src/core/OscillatorNode.ts +2 -2
- package/src/core/StereoPannerNode.ts +1 -1
- package/src/events/AudioEventEmitter.ts +29 -0
- package/src/events/AudioEventSubscription.ts +26 -0
- package/src/events/index.ts +4 -0
- package/src/events/types.ts +64 -0
- package/src/hooks/useSytemVolume.ts +2 -1
- package/src/interfaces.ts +19 -20
- package/src/specs/NativeAudioAPIModule.ts +23 -2
- package/src/specs/index.ts +2 -4
- package/src/system/AudioManager.ts +35 -43
- package/src/system/types.ts +0 -42
- package/src/types.ts +0 -8
- package/android/src/main/java/com/swmansion/audioapi/AudioManagerModule.kt +0 -77
- package/android/src/main/java/com/swmansion/audioapi/system/MediaSessionEventEmitter.kt +0 -88
- package/android/src/oldarch/NativeAudioManagerModuleSpec.java +0 -99
- package/ios/audioapi/ios/AudioManagerModule.h +0 -18
- package/ios/audioapi/ios/AudioManagerModule.mm +0 -108
- package/lib/commonjs/specs/NativeAudioManagerModule.js +0 -42
- package/lib/commonjs/specs/NativeAudioManagerModule.js.map +0 -1
- package/lib/module/specs/NativeAudioManagerModule.js +0 -39
- package/lib/module/specs/NativeAudioManagerModule.js.map +0 -1
- package/lib/typescript/specs/NativeAudioManagerModule.d.ts +0 -18
- package/lib/typescript/specs/NativeAudioManagerModule.d.ts.map +0 -1
- package/src/specs/NativeAudioManagerModule.ts +0 -53
|
@@ -12,9 +12,8 @@ using namespace facebook;
|
|
|
12
12
|
class AudioScheduledSourceNodeHostObject : public AudioNodeHostObject {
|
|
13
13
|
public:
|
|
14
14
|
explicit AudioScheduledSourceNodeHostObject(
|
|
15
|
-
const std::shared_ptr<AudioScheduledSourceNode> &node
|
|
16
|
-
|
|
17
|
-
: AudioNodeHostObject(node), callInvoker_(callInvoker) {
|
|
15
|
+
const std::shared_ptr<AudioScheduledSourceNode> &node)
|
|
16
|
+
: AudioNodeHostObject(node) {
|
|
18
17
|
addSetters(
|
|
19
18
|
JSI_EXPORT_PROPERTY_SETTER(AudioScheduledSourceNodeHostObject, onended));
|
|
20
19
|
addFunctions(
|
|
@@ -22,27 +21,11 @@ class AudioScheduledSourceNodeHostObject : public AudioNodeHostObject {
|
|
|
22
21
|
JSI_EXPORT_FUNCTION(AudioScheduledSourceNodeHostObject, stop));
|
|
23
22
|
}
|
|
24
23
|
|
|
25
|
-
~AudioScheduledSourceNodeHostObject() override {
|
|
26
|
-
// https://github.com/software-mansion/react-native-reanimated/blob/2b669b069bd70ba876d97a9e19daa509808a1b3a/packages/react-native-worklets/Common/cpp/worklets/SharedItems/Shareables.h#L39-L63
|
|
27
|
-
auto audioScheduleSourceNode =
|
|
28
|
-
std::static_pointer_cast<AudioScheduledSourceNode>(node_);
|
|
29
|
-
audioScheduleSourceNode->setOnendedCallback(nullptr);
|
|
30
|
-
|
|
31
|
-
onendedCallback_ = nullptr;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
24
|
JSI_PROPERTY_SETTER(onended) {
|
|
35
|
-
onendedCallback_ = std::make_unique<jsi::Function>(value.getObject(runtime).getFunction(runtime));
|
|
36
25
|
auto audioScheduleSourceNode =
|
|
37
26
|
std::static_pointer_cast<AudioScheduledSourceNode>(node_);
|
|
38
27
|
|
|
39
|
-
|
|
40
|
-
callInvoker_->invokeAsync([this, &runtime, stopTime] () {
|
|
41
|
-
onendedCallback_->call(runtime, stopTime);
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
audioScheduleSourceNode->setOnendedCallback(lambda);
|
|
28
|
+
audioScheduleSourceNode->setOnEndedCallbackId(std::stoull(value.getString(runtime).utf8(runtime)));
|
|
46
29
|
}
|
|
47
30
|
|
|
48
31
|
JSI_HOST_FUNCTION(start) {
|
|
@@ -60,9 +43,5 @@ class AudioScheduledSourceNodeHostObject : public AudioNodeHostObject {
|
|
|
60
43
|
audioScheduleSourceNode->stop(time);
|
|
61
44
|
return jsi::Value::undefined();
|
|
62
45
|
}
|
|
63
|
-
|
|
64
|
-
private:
|
|
65
|
-
std::shared_ptr<react::CallInvoker> callInvoker_;
|
|
66
|
-
std::unique_ptr<jsi::Function> onendedCallback_;
|
|
67
46
|
};
|
|
68
47
|
} // namespace audioapi
|
|
@@ -71,7 +71,7 @@ class BaseAudioContextHostObject : public JsiHostObject {
|
|
|
71
71
|
JSI_HOST_FUNCTION(createOscillator) {
|
|
72
72
|
auto oscillator = context_->createOscillator();
|
|
73
73
|
auto oscillatorHostObject =
|
|
74
|
-
std::make_shared<OscillatorNodeHostObject>(oscillator
|
|
74
|
+
std::make_shared<OscillatorNodeHostObject>(oscillator);
|
|
75
75
|
return jsi::Object::createFromHostObject(runtime, oscillatorHostObject);
|
|
76
76
|
}
|
|
77
77
|
|
|
@@ -99,7 +99,7 @@ class BaseAudioContextHostObject : public JsiHostObject {
|
|
|
99
99
|
auto pitchCorrection = args[0].asBool();
|
|
100
100
|
auto bufferSource = context_->createBufferSource(pitchCorrection);
|
|
101
101
|
auto bufferSourceHostObject =
|
|
102
|
-
std::make_shared<AudioBufferSourceNodeHostObject>(bufferSource
|
|
102
|
+
std::make_shared<AudioBufferSourceNodeHostObject>(bufferSource);
|
|
103
103
|
return jsi::Object::createFromHostObject(runtime, bufferSourceHostObject);
|
|
104
104
|
}
|
|
105
105
|
|
|
@@ -15,9 +15,8 @@ using namespace facebook;
|
|
|
15
15
|
class OscillatorNodeHostObject : public AudioScheduledSourceNodeHostObject {
|
|
16
16
|
public:
|
|
17
17
|
explicit OscillatorNodeHostObject(
|
|
18
|
-
const std::shared_ptr<OscillatorNode> &node
|
|
19
|
-
|
|
20
|
-
: AudioScheduledSourceNodeHostObject(node, callInvoker) {
|
|
18
|
+
const std::shared_ptr<OscillatorNode> &node)
|
|
19
|
+
: AudioScheduledSourceNodeHostObject(node) {
|
|
21
20
|
addGetters(
|
|
22
21
|
JSI_EXPORT_PROPERTY_GETTER(OscillatorNodeHostObject, frequency),
|
|
23
22
|
JSI_EXPORT_PROPERTY_GETTER(OscillatorNodeHostObject, detune),
|
|
@@ -10,7 +10,10 @@
|
|
|
10
10
|
#include <audioapi/core/utils/AudioNodeManager.h>
|
|
11
11
|
|
|
12
12
|
namespace audioapi {
|
|
13
|
-
AudioContext::AudioContext(
|
|
13
|
+
AudioContext::AudioContext(
|
|
14
|
+
float sampleRate,
|
|
15
|
+
const std::shared_ptr<AudioEventHandlerRegistry> &audioEventHandlerRegistry)
|
|
16
|
+
: BaseAudioContext(audioEventHandlerRegistry) {
|
|
14
17
|
#ifdef ANDROID
|
|
15
18
|
audioPlayer_ = std::make_shared<AudioPlayer>(this->renderAudio(), sampleRate);
|
|
16
19
|
#else
|
|
@@ -14,7 +14,7 @@ class IOSAudioPlayer;
|
|
|
14
14
|
|
|
15
15
|
class AudioContext : public BaseAudioContext {
|
|
16
16
|
public:
|
|
17
|
-
explicit AudioContext(float sampleRate);
|
|
17
|
+
explicit AudioContext(float sampleRate, const std::shared_ptr<AudioEventHandlerRegistry> &audioEventHandlerRegistry);
|
|
18
18
|
~AudioContext() override;
|
|
19
19
|
|
|
20
20
|
void close();
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#include <audioapi/core/AudioNode.h>
|
|
2
|
+
#include <audioapi/core/AudioParam.h>
|
|
2
3
|
#include <audioapi/core/BaseAudioContext.h>
|
|
3
4
|
#include <audioapi/core/utils/AudioNodeManager.h>
|
|
4
5
|
#include <audioapi/utils/AudioArray.h>
|
|
@@ -38,10 +39,15 @@ std::string AudioNode::getChannelInterpretation() const {
|
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
void AudioNode::connect(const std::shared_ptr<AudioNode> &node) {
|
|
41
|
-
context_->getNodeManager()->
|
|
42
|
+
context_->getNodeManager()->addPendingNodeConnection(
|
|
42
43
|
shared_from_this(), node, AudioNodeManager::ConnectionType::CONNECT);
|
|
43
44
|
}
|
|
44
45
|
|
|
46
|
+
void AudioNode::connect(const std::shared_ptr<AudioParam> ¶m) {
|
|
47
|
+
context_->getNodeManager()->addPendingParamConnection(
|
|
48
|
+
shared_from_this(), param, AudioNodeManager::ConnectionType::CONNECT);
|
|
49
|
+
}
|
|
50
|
+
|
|
45
51
|
void AudioNode::disconnect() {
|
|
46
52
|
for (auto it = outputNodes_.begin(), end = outputNodes_.end(); it != end;
|
|
47
53
|
++it) {
|
|
@@ -50,10 +56,15 @@ void AudioNode::disconnect() {
|
|
|
50
56
|
}
|
|
51
57
|
|
|
52
58
|
void AudioNode::disconnect(const std::shared_ptr<AudioNode> &node) {
|
|
53
|
-
context_->getNodeManager()->
|
|
59
|
+
context_->getNodeManager()->addPendingNodeConnection(
|
|
54
60
|
shared_from_this(), node, AudioNodeManager::ConnectionType::DISCONNECT);
|
|
55
61
|
}
|
|
56
62
|
|
|
63
|
+
void AudioNode::disconnect(const std::shared_ptr<AudioParam> ¶m) {
|
|
64
|
+
context_->getNodeManager()->addPendingParamConnection(
|
|
65
|
+
shared_from_this(), param, AudioNodeManager::ConnectionType::DISCONNECT);
|
|
66
|
+
}
|
|
67
|
+
|
|
57
68
|
bool AudioNode::isEnabled() const {
|
|
58
69
|
return isEnabled_;
|
|
59
70
|
}
|
|
@@ -221,6 +232,15 @@ void AudioNode::connectNode(const std::shared_ptr<AudioNode> &node) {
|
|
|
221
232
|
}
|
|
222
233
|
}
|
|
223
234
|
|
|
235
|
+
void AudioNode::connectParam(const std::shared_ptr<AudioParam> ¶m) {
|
|
236
|
+
auto position = outputParams_.find(param);
|
|
237
|
+
|
|
238
|
+
if (position == outputParams_.end()) {
|
|
239
|
+
outputParams_.insert(param);
|
|
240
|
+
param->addInputNode(this);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
224
244
|
void AudioNode::disconnectNode(const std::shared_ptr<AudioNode> &node) {
|
|
225
245
|
auto position = outputNodes_.find(node);
|
|
226
246
|
|
|
@@ -230,6 +250,15 @@ void AudioNode::disconnectNode(const std::shared_ptr<AudioNode> &node) {
|
|
|
230
250
|
}
|
|
231
251
|
}
|
|
232
252
|
|
|
253
|
+
void AudioNode::disconnectParam(const std::shared_ptr<AudioParam> ¶m) {
|
|
254
|
+
auto position = outputParams_.find(param);
|
|
255
|
+
|
|
256
|
+
if (position != outputParams_.end()) {
|
|
257
|
+
param->removeInputNode(this);
|
|
258
|
+
outputParams_.erase(param);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
233
262
|
void AudioNode::onInputEnabled() {
|
|
234
263
|
numberOfEnabledInputNodes_ += 1;
|
|
235
264
|
|
|
@@ -15,6 +15,7 @@ namespace audioapi {
|
|
|
15
15
|
|
|
16
16
|
class AudioBus;
|
|
17
17
|
class BaseAudioContext;
|
|
18
|
+
class AudioParam;
|
|
18
19
|
|
|
19
20
|
class AudioNode : public std::enable_shared_from_this<AudioNode> {
|
|
20
21
|
public:
|
|
@@ -27,8 +28,11 @@ class AudioNode : public std::enable_shared_from_this<AudioNode> {
|
|
|
27
28
|
std::string getChannelCountMode() const;
|
|
28
29
|
std::string getChannelInterpretation() const;
|
|
29
30
|
void connect(const std::shared_ptr<AudioNode> &node);
|
|
31
|
+
void connect(const std::shared_ptr<AudioParam> ¶m);
|
|
30
32
|
void disconnect();
|
|
31
33
|
void disconnect(const std::shared_ptr<AudioNode> &node);
|
|
34
|
+
void disconnect(const std::shared_ptr<AudioParam> ¶m);
|
|
35
|
+
virtual std::shared_ptr<AudioBus> processAudio(const std::shared_ptr<AudioBus> &outputBus, int framesToProcess, bool checkIsAlreadyProcessed);
|
|
32
36
|
|
|
33
37
|
bool isEnabled() const;
|
|
34
38
|
void enable();
|
|
@@ -50,6 +54,7 @@ class AudioNode : public std::enable_shared_from_this<AudioNode> {
|
|
|
50
54
|
|
|
51
55
|
std::unordered_set<AudioNode *> inputNodes_ = {};
|
|
52
56
|
std::unordered_set<std::shared_ptr<AudioNode>> outputNodes_ = {};
|
|
57
|
+
std::unordered_set<std::shared_ptr<AudioParam>> outputParams_ = {};
|
|
53
58
|
|
|
54
59
|
int numberOfEnabledInputNodes_ = 0;
|
|
55
60
|
bool isInitialized_ = false;
|
|
@@ -63,7 +68,6 @@ class AudioNode : public std::enable_shared_from_this<AudioNode> {
|
|
|
63
68
|
static std::string toString(ChannelCountMode mode);
|
|
64
69
|
static std::string toString(ChannelInterpretation interpretation);
|
|
65
70
|
|
|
66
|
-
virtual std::shared_ptr<AudioBus> processAudio(const std::shared_ptr<AudioBus> &outputBus, int framesToProcess, bool checkIsAlreadyProcessed);
|
|
67
71
|
virtual void processNode(const std::shared_ptr<AudioBus>&, int) = 0;
|
|
68
72
|
|
|
69
73
|
bool isAlreadyProcessed();
|
|
@@ -73,6 +77,8 @@ class AudioNode : public std::enable_shared_from_this<AudioNode> {
|
|
|
73
77
|
|
|
74
78
|
void connectNode(const std::shared_ptr<AudioNode> &node);
|
|
75
79
|
void disconnectNode(const std::shared_ptr<AudioNode> &node);
|
|
80
|
+
void connectParam(const std::shared_ptr<AudioParam> ¶m);
|
|
81
|
+
void disconnectParam(const std::shared_ptr<AudioParam> ¶m);
|
|
76
82
|
|
|
77
83
|
void onInputEnabled();
|
|
78
84
|
void onInputDisabled();
|
|
@@ -1,14 +1,27 @@
|
|
|
1
1
|
#include <audioapi/core/AudioParam.h>
|
|
2
2
|
#include <audioapi/core/BaseAudioContext.h>
|
|
3
3
|
#include <audioapi/dsp/AudioUtils.h>
|
|
4
|
+
#include <audioapi/dsp/VectorMath.h>
|
|
5
|
+
#include <audioapi/utils/AudioArray.h>
|
|
6
|
+
#include <iostream>
|
|
4
7
|
|
|
5
8
|
namespace audioapi {
|
|
6
9
|
|
|
7
|
-
AudioParam::AudioParam(
|
|
10
|
+
AudioParam::AudioParam(
|
|
11
|
+
float defaultValue,
|
|
12
|
+
float minValue,
|
|
13
|
+
float maxValue,
|
|
14
|
+
BaseAudioContext *context)
|
|
8
15
|
: value_(defaultValue),
|
|
9
16
|
defaultValue_(defaultValue),
|
|
10
17
|
minValue_(minValue),
|
|
11
|
-
maxValue_(maxValue)
|
|
18
|
+
maxValue_(maxValue),
|
|
19
|
+
context_(context),
|
|
20
|
+
audioBus_(
|
|
21
|
+
std::make_shared<AudioBus>(
|
|
22
|
+
RENDER_QUANTUM_SIZE,
|
|
23
|
+
1,
|
|
24
|
+
context->getSampleRate())) {
|
|
12
25
|
startTime_ = 0;
|
|
13
26
|
endTime_ = 0;
|
|
14
27
|
startValue_ = value_;
|
|
@@ -256,6 +269,44 @@ void AudioParam::cancelAndHoldAtTime(double cancelTime) {
|
|
|
256
269
|
}
|
|
257
270
|
}
|
|
258
271
|
|
|
272
|
+
void AudioParam::addInputNode(AudioNode *node) {
|
|
273
|
+
auto position = inputNodes_.find(node);
|
|
274
|
+
if (position == inputNodes_.end()) {
|
|
275
|
+
inputNodes_.insert(node);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
void AudioParam::removeInputNode(AudioNode *node) {
|
|
280
|
+
auto position = inputNodes_.find(node);
|
|
281
|
+
|
|
282
|
+
if (position != inputNodes_.end()) {
|
|
283
|
+
inputNodes_.erase(position);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
std::shared_ptr<AudioBus> AudioParam::processARateParam(
|
|
288
|
+
int framesToProcess,
|
|
289
|
+
double time) {
|
|
290
|
+
auto processingBus = audioBus_;
|
|
291
|
+
processingBus->zero();
|
|
292
|
+
if (!inputNodes_.empty()) {
|
|
293
|
+
processInputs(processingBus, framesToProcess, true);
|
|
294
|
+
mixInputsBuses(processingBus);
|
|
295
|
+
}
|
|
296
|
+
for (size_t i = 0; i < framesToProcess; i++) {
|
|
297
|
+
auto sample = getValueAtTime(time + i / context_->getSampleRate());
|
|
298
|
+
processingBus->getChannel(0)->getData()[i] += sample;
|
|
299
|
+
}
|
|
300
|
+
// processingBus is a mono bus
|
|
301
|
+
return processingBus;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
float AudioParam::processKRateParam(int framesToProcess, double time) {
|
|
305
|
+
auto processingBus = processARateParam(framesToProcess, time);
|
|
306
|
+
// processingBus is a mono bus
|
|
307
|
+
return processingBus->getChannel(0)->getData()[0];
|
|
308
|
+
}
|
|
309
|
+
|
|
259
310
|
double AudioParam::getQueueEndTime() {
|
|
260
311
|
if (eventsQueue_.empty()) {
|
|
261
312
|
return endTime_;
|
|
@@ -292,4 +343,35 @@ void AudioParam::updateQueue(ParamChangeEvent &event) {
|
|
|
292
343
|
eventsQueue_.push_back(event);
|
|
293
344
|
}
|
|
294
345
|
|
|
346
|
+
void AudioParam::processInputs(
|
|
347
|
+
const std::shared_ptr<AudioBus> &outputBus,
|
|
348
|
+
int framesToProcess,
|
|
349
|
+
bool checkIsAlreadyProcessed) {
|
|
350
|
+
for (auto it = inputNodes_.begin(), end = inputNodes_.end(); it != end;
|
|
351
|
+
++it) {
|
|
352
|
+
auto inputNode = *it;
|
|
353
|
+
assert(inputNode != nullptr);
|
|
354
|
+
|
|
355
|
+
if (!inputNode->isEnabled()) {
|
|
356
|
+
continue;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
auto inputBus = inputNode->processAudio(
|
|
360
|
+
outputBus, framesToProcess, checkIsAlreadyProcessed);
|
|
361
|
+
inputBuses_.push_back(inputBus);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
void AudioParam::mixInputsBuses(
|
|
366
|
+
const std::shared_ptr<AudioBus> &processingBus) {
|
|
367
|
+
assert(processingBus != nullptr);
|
|
368
|
+
|
|
369
|
+
for (auto it = inputBuses_.begin(), end = inputBuses_.end(); it != end;
|
|
370
|
+
++it) {
|
|
371
|
+
processingBus->sum(it->get(), ChannelInterpretation::SPEAKERS);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
inputBuses_.clear();
|
|
375
|
+
}
|
|
376
|
+
|
|
295
377
|
} // namespace audioapi
|
|
@@ -2,17 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
#include <audioapi/core/utils/ParamChangeEvent.h>
|
|
4
4
|
#include <audioapi/core/types/ParamChangeEventType.h>
|
|
5
|
+
#include <audioapi/utils/AudioBus.h>
|
|
6
|
+
#include <audioapi/core/AudioNode.h>
|
|
5
7
|
|
|
6
8
|
#include <deque>
|
|
7
9
|
#include <memory>
|
|
8
10
|
#include <vector>
|
|
11
|
+
#include <unordered_set>
|
|
9
12
|
#include <cstddef>
|
|
10
13
|
|
|
11
14
|
namespace audioapi {
|
|
12
15
|
|
|
13
16
|
class AudioParam {
|
|
14
17
|
public:
|
|
15
|
-
explicit AudioParam(float defaultValue, float minValue, float maxValue);
|
|
18
|
+
explicit AudioParam(float defaultValue, float minValue, float maxValue, BaseAudioContext *context);
|
|
16
19
|
|
|
17
20
|
[[nodiscard]] float getValue() const;
|
|
18
21
|
float getValueAtTime(double time);
|
|
@@ -33,23 +36,33 @@ class AudioParam {
|
|
|
33
36
|
double duration);
|
|
34
37
|
void cancelScheduledValues(double cancelTime);
|
|
35
38
|
void cancelAndHoldAtTime(double cancelTime);
|
|
39
|
+
void addInputNode(AudioNode* node);
|
|
40
|
+
void removeInputNode(AudioNode* node);
|
|
41
|
+
std::shared_ptr<AudioBus> processARateParam(int framesToProcess, double time);
|
|
42
|
+
float processKRateParam(int framesToProcess, double time);
|
|
36
43
|
|
|
37
44
|
private:
|
|
38
45
|
float value_;
|
|
39
46
|
float defaultValue_;
|
|
40
47
|
float minValue_;
|
|
41
48
|
float maxValue_;
|
|
49
|
+
BaseAudioContext *context_;
|
|
42
50
|
std::deque<ParamChangeEvent> eventsQueue_;
|
|
51
|
+
std::unordered_set<AudioNode *> inputNodes_;
|
|
52
|
+
std::shared_ptr<AudioBus> audioBus_;
|
|
43
53
|
|
|
44
54
|
double startTime_;
|
|
45
55
|
double endTime_;
|
|
46
56
|
float startValue_;
|
|
47
57
|
float endValue_;
|
|
48
58
|
std::function<float(double, double, float, float, double)> calculateValue_;
|
|
59
|
+
std::vector<std::shared_ptr<AudioBus>> inputBuses_ = {};
|
|
49
60
|
|
|
50
61
|
double getQueueEndTime();
|
|
51
62
|
float getQueueEndValue();
|
|
52
63
|
void updateQueue(ParamChangeEvent &event);
|
|
64
|
+
void processInputs(const std::shared_ptr<AudioBus>& outputBus, int framesToProcess, bool checkIsAlreadyProcessed);
|
|
65
|
+
void mixInputsBuses(const std::shared_ptr<AudioBus>& processingBus);
|
|
53
66
|
};
|
|
54
67
|
|
|
55
68
|
} // namespace audioapi
|
|
@@ -9,15 +9,20 @@
|
|
|
9
9
|
#include <audioapi/core/sources/OscillatorNode.h>
|
|
10
10
|
#include <audioapi/core/utils/AudioDecoder.h>
|
|
11
11
|
#include <audioapi/core/utils/AudioNodeManager.h>
|
|
12
|
+
#include <audioapi/events/AudioEventHandlerRegistry.h>
|
|
12
13
|
#include <audioapi/utils/AudioArray.h>
|
|
13
14
|
#include <audioapi/utils/AudioBus.h>
|
|
14
15
|
#include <audioapi/utils/CircularAudioArray.h>
|
|
15
16
|
|
|
16
17
|
namespace audioapi {
|
|
17
18
|
|
|
18
|
-
BaseAudioContext::BaseAudioContext(
|
|
19
|
+
BaseAudioContext::BaseAudioContext(
|
|
20
|
+
const std::shared_ptr<AudioEventHandlerRegistry>
|
|
21
|
+
&audioEventHandlerRegistry) {
|
|
19
22
|
nodeManager_ = std::make_shared<AudioNodeManager>();
|
|
20
23
|
destination_ = std::make_shared<AudioDestinationNode>(this);
|
|
24
|
+
|
|
25
|
+
audioEventHandlerRegistry_ = audioEventHandlerRegistry;
|
|
21
26
|
}
|
|
22
27
|
|
|
23
28
|
std::string BaseAudioContext::getState() {
|
|
@@ -26,10 +26,11 @@ class AudioDestinationNode;
|
|
|
26
26
|
class AudioBufferSourceNode;
|
|
27
27
|
class AudioDecoder;
|
|
28
28
|
class AnalyserNode;
|
|
29
|
+
class AudioEventHandlerRegistry;
|
|
29
30
|
|
|
30
31
|
class BaseAudioContext {
|
|
31
32
|
public:
|
|
32
|
-
BaseAudioContext();
|
|
33
|
+
explicit BaseAudioContext(const std::shared_ptr<AudioEventHandlerRegistry> &audioEventHandlerRegistry);
|
|
33
34
|
virtual ~BaseAudioContext() = default;
|
|
34
35
|
|
|
35
36
|
std::string getState();
|
|
@@ -77,6 +78,11 @@ class BaseAudioContext {
|
|
|
77
78
|
std::shared_ptr<PeriodicWave> cachedSquareWave_ = nullptr;
|
|
78
79
|
std::shared_ptr<PeriodicWave> cachedSawtoothWave_ = nullptr;
|
|
79
80
|
std::shared_ptr<PeriodicWave> cachedTriangleWave_ = nullptr;
|
|
81
|
+
|
|
82
|
+
protected:
|
|
83
|
+
friend class AudioScheduledSourceNode;
|
|
84
|
+
|
|
85
|
+
std::shared_ptr<AudioEventHandlerRegistry> audioEventHandlerRegistry_;
|
|
80
86
|
};
|
|
81
87
|
|
|
82
88
|
} // namespace audioapi
|
|
@@ -21,8 +21,9 @@ namespace audioapi {
|
|
|
21
21
|
OfflineAudioContext::OfflineAudioContext(
|
|
22
22
|
int numberOfChannels,
|
|
23
23
|
size_t length,
|
|
24
|
-
float sampleRate
|
|
25
|
-
|
|
24
|
+
float sampleRate,
|
|
25
|
+
const std::shared_ptr<AudioEventHandlerRegistry> &audioEventHandlerRegistry)
|
|
26
|
+
: BaseAudioContext(audioEventHandlerRegistry),
|
|
26
27
|
length_(length),
|
|
27
28
|
numberOfChannels_(numberOfChannels),
|
|
28
29
|
currentSampleFrame_(0) {
|
|
@@ -14,7 +14,7 @@ using OfflineAudioContextResultCallback = std::function<void(std::shared_ptr<Aud
|
|
|
14
14
|
|
|
15
15
|
class OfflineAudioContext : public BaseAudioContext {
|
|
16
16
|
public:
|
|
17
|
-
explicit OfflineAudioContext(int numberOfChannels, size_t length, float sampleRate);
|
|
17
|
+
explicit OfflineAudioContext(int numberOfChannels, size_t length, float sampleRate, const std::shared_ptr<AudioEventHandlerRegistry> &audioEventHandlerRegistry);
|
|
18
18
|
~OfflineAudioContext() override;
|
|
19
19
|
|
|
20
20
|
void resume();
|
|
@@ -10,16 +10,20 @@ namespace audioapi {
|
|
|
10
10
|
|
|
11
11
|
BiquadFilterNode::BiquadFilterNode(BaseAudioContext *context)
|
|
12
12
|
: AudioNode(context) {
|
|
13
|
-
frequencyParam_ =
|
|
14
|
-
|
|
13
|
+
frequencyParam_ = std::make_shared<AudioParam>(
|
|
14
|
+
350.0, 0.0f, context->getNyquistFrequency(), context);
|
|
15
15
|
detuneParam_ = std::make_shared<AudioParam>(
|
|
16
16
|
0.0,
|
|
17
17
|
-1200 * LOG2_MOST_POSITIVE_SINGLE_FLOAT,
|
|
18
|
-
1200 * LOG2_MOST_POSITIVE_SINGLE_FLOAT
|
|
18
|
+
1200 * LOG2_MOST_POSITIVE_SINGLE_FLOAT,
|
|
19
|
+
context);
|
|
19
20
|
QParam_ = std::make_shared<AudioParam>(
|
|
20
|
-
1.0, MOST_NEGATIVE_SINGLE_FLOAT, MOST_POSITIVE_SINGLE_FLOAT);
|
|
21
|
+
1.0, MOST_NEGATIVE_SINGLE_FLOAT, MOST_POSITIVE_SINGLE_FLOAT, context);
|
|
21
22
|
gainParam_ = std::make_shared<AudioParam>(
|
|
22
|
-
0.0,
|
|
23
|
+
0.0,
|
|
24
|
+
MOST_NEGATIVE_SINGLE_FLOAT,
|
|
25
|
+
40 * LOG10_MOST_POSITIVE_SINGLE_FLOAT,
|
|
26
|
+
context);
|
|
23
27
|
type_ = BiquadFilterType::LOWPASS;
|
|
24
28
|
isInitialized_ = true;
|
|
25
29
|
}
|
|
@@ -304,48 +308,46 @@ void BiquadFilterNode::setAllpassCoefficients(float frequency, float Q) {
|
|
|
304
308
|
void BiquadFilterNode::applyFilter() {
|
|
305
309
|
double currentTime = context_->getCurrentTime();
|
|
306
310
|
|
|
307
|
-
float
|
|
308
|
-
|
|
309
|
-
float
|
|
311
|
+
float frequencyParamValue =
|
|
312
|
+
frequencyParam_->processKRateParam(RENDER_QUANTUM_SIZE, currentTime);
|
|
313
|
+
float normalizedFrequency =
|
|
314
|
+
frequencyParamValue / context_->getNyquistFrequency();
|
|
315
|
+
|
|
316
|
+
float detuneValue =
|
|
317
|
+
detuneParam_->processKRateParam(RENDER_QUANTUM_SIZE, currentTime);
|
|
310
318
|
|
|
311
319
|
if (detuneValue != 0.0) {
|
|
312
320
|
normalizedFrequency *= std::pow(2.0f, detuneValue / 1200.0f);
|
|
313
321
|
}
|
|
314
322
|
|
|
323
|
+
auto qparamValue =
|
|
324
|
+
QParam_->processKRateParam(RENDER_QUANTUM_SIZE, currentTime);
|
|
325
|
+
auto gainParamValue =
|
|
326
|
+
gainParam_->processKRateParam(RENDER_QUANTUM_SIZE, currentTime);
|
|
315
327
|
switch (type_) {
|
|
316
328
|
case BiquadFilterType::LOWPASS:
|
|
317
|
-
setLowpassCoefficients(
|
|
318
|
-
normalizedFrequency, QParam_->getValueAtTime(currentTime));
|
|
329
|
+
setLowpassCoefficients(normalizedFrequency, qparamValue);
|
|
319
330
|
break;
|
|
320
331
|
case BiquadFilterType::HIGHPASS:
|
|
321
|
-
setHighpassCoefficients(
|
|
322
|
-
normalizedFrequency, QParam_->getValueAtTime(currentTime));
|
|
332
|
+
setHighpassCoefficients(normalizedFrequency, qparamValue);
|
|
323
333
|
break;
|
|
324
334
|
case BiquadFilterType::BANDPASS:
|
|
325
|
-
setBandpassCoefficients(
|
|
326
|
-
normalizedFrequency, QParam_->getValueAtTime(currentTime));
|
|
335
|
+
setBandpassCoefficients(normalizedFrequency, qparamValue);
|
|
327
336
|
break;
|
|
328
337
|
case BiquadFilterType::LOWSHELF:
|
|
329
|
-
setLowshelfCoefficients(
|
|
330
|
-
normalizedFrequency, gainParam_->getValueAtTime(currentTime));
|
|
338
|
+
setLowshelfCoefficients(normalizedFrequency, gainParamValue);
|
|
331
339
|
break;
|
|
332
340
|
case BiquadFilterType::HIGHSHELF:
|
|
333
|
-
setHighshelfCoefficients(
|
|
334
|
-
normalizedFrequency, gainParam_->getValueAtTime(currentTime));
|
|
341
|
+
setHighshelfCoefficients(normalizedFrequency, gainParamValue);
|
|
335
342
|
break;
|
|
336
343
|
case BiquadFilterType::PEAKING:
|
|
337
|
-
setPeakingCoefficients(
|
|
338
|
-
normalizedFrequency,
|
|
339
|
-
QParam_->getValueAtTime(currentTime),
|
|
340
|
-
gainParam_->getValueAtTime(currentTime));
|
|
344
|
+
setPeakingCoefficients(normalizedFrequency, qparamValue, gainParamValue);
|
|
341
345
|
break;
|
|
342
346
|
case BiquadFilterType::NOTCH:
|
|
343
|
-
setNotchCoefficients(
|
|
344
|
-
normalizedFrequency, QParam_->getValueAtTime(currentTime));
|
|
347
|
+
setNotchCoefficients(normalizedFrequency, qparamValue);
|
|
345
348
|
break;
|
|
346
349
|
case BiquadFilterType::ALLPASS:
|
|
347
|
-
setAllpassCoefficients(
|
|
348
|
-
normalizedFrequency, QParam_->getValueAtTime(currentTime));
|
|
350
|
+
setAllpassCoefficients(normalizedFrequency, qparamValue);
|
|
349
351
|
break;
|
|
350
352
|
default:
|
|
351
353
|
break;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#include <audioapi/core/BaseAudioContext.h>
|
|
2
2
|
#include <audioapi/core/effects/GainNode.h>
|
|
3
|
+
#include <audioapi/dsp/VectorMath.h>
|
|
3
4
|
#include <audioapi/utils/AudioArray.h>
|
|
4
5
|
#include <audioapi/utils/AudioBus.h>
|
|
5
6
|
|
|
@@ -7,7 +8,7 @@ namespace audioapi {
|
|
|
7
8
|
|
|
8
9
|
GainNode::GainNode(BaseAudioContext *context) : AudioNode(context) {
|
|
9
10
|
gainParam_ = std::make_shared<AudioParam>(
|
|
10
|
-
1.0, MOST_NEGATIVE_SINGLE_FLOAT, MOST_POSITIVE_SINGLE_FLOAT);
|
|
11
|
+
1.0, MOST_NEGATIVE_SINGLE_FLOAT, MOST_POSITIVE_SINGLE_FLOAT, context);
|
|
11
12
|
isInitialized_ = true;
|
|
12
13
|
}
|
|
13
14
|
|
|
@@ -19,14 +20,13 @@ void GainNode::processNode(
|
|
|
19
20
|
const std::shared_ptr<AudioBus> &processingBus,
|
|
20
21
|
int framesToProcess) {
|
|
21
22
|
double time = context_->getCurrentTime();
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
time += deltaTime;
|
|
23
|
+
auto gainParamValues = gainParam_->processARateParam(framesToProcess, time);
|
|
24
|
+
for (int i = 0; i < processingBus->getNumberOfChannels(); i += 1) {
|
|
25
|
+
dsp::multiply(
|
|
26
|
+
processingBus->getChannel(i)->getData(),
|
|
27
|
+
gainParamValues->getChannel(0)->getData(),
|
|
28
|
+
processingBus->getChannel(i)->getData(),
|
|
29
|
+
framesToProcess);
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -11,7 +11,7 @@ namespace audioapi {
|
|
|
11
11
|
StereoPannerNode::StereoPannerNode(BaseAudioContext *context)
|
|
12
12
|
: AudioNode(context) {
|
|
13
13
|
channelCountMode_ = ChannelCountMode::EXPLICIT;
|
|
14
|
-
panParam_ = std::make_shared<AudioParam>(0.0, -1.0f, 1.0f);
|
|
14
|
+
panParam_ = std::make_shared<AudioParam>(0.0, -1.0f, 1.0f, context);
|
|
15
15
|
isInitialized_ = true;
|
|
16
16
|
}
|
|
17
17
|
|
|
@@ -27,9 +27,12 @@ void StereoPannerNode::processNode(
|
|
|
27
27
|
|
|
28
28
|
AudioArray *left = processingBus->getChannelByType(AudioBus::ChannelLeft);
|
|
29
29
|
AudioArray *right = processingBus->getChannelByType(AudioBus::ChannelRight);
|
|
30
|
+
auto panParamValues = panParam_->processARateParam(framesToProcess, time)
|
|
31
|
+
->getChannel(0)
|
|
32
|
+
->getData();
|
|
30
33
|
|
|
31
34
|
for (int i = 0; i < framesToProcess; i += 1) {
|
|
32
|
-
auto pan =
|
|
35
|
+
auto pan = panParamValues[i];
|
|
33
36
|
|
|
34
37
|
auto x = (pan <= 0 ? pan + 1 : pan);
|
|
35
38
|
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
#include <audioapi/HostObjects/AudioBufferHostObject.h>
|
|
2
|
+
#include <audioapi/core/inputs/AudioRecorder.h>
|
|
3
|
+
#include <audioapi/core/sources/AudioBuffer.h>
|
|
4
|
+
#include <audioapi/events/AudioEventHandlerRegistry.h>
|
|
5
|
+
#include <audioapi/utils/AudioBus.h>
|
|
6
|
+
#include <audioapi/utils/CircularAudioArray.h>
|
|
7
|
+
|
|
8
|
+
namespace audioapi {
|
|
9
|
+
|
|
10
|
+
AudioRecorder::AudioRecorder(
|
|
11
|
+
float sampleRate,
|
|
12
|
+
int bufferLength,
|
|
13
|
+
const std::shared_ptr<AudioEventHandlerRegistry> &audioEventHandlerRegistry)
|
|
14
|
+
: sampleRate_(sampleRate),
|
|
15
|
+
bufferLength_(bufferLength),
|
|
16
|
+
audioEventHandlerRegistry_(audioEventHandlerRegistry) {
|
|
17
|
+
circularBuffer_ =
|
|
18
|
+
std::make_shared<CircularAudioArray>(std::max(2 * bufferLength, 2048));
|
|
19
|
+
isRunning_.store(false);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
void AudioRecorder::setOnAudioReadyCallbackId(uint64_t callbackId) {
|
|
23
|
+
onAudioReadyCallbackId_ = callbackId;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
void AudioRecorder::invokeOnAudioReadyCallback(
|
|
27
|
+
const std::shared_ptr<AudioBus> &bus,
|
|
28
|
+
int numFrames,
|
|
29
|
+
double when) {
|
|
30
|
+
auto audioBuffer = std::make_shared<AudioBuffer>(bus);
|
|
31
|
+
auto audioBufferHostObject =
|
|
32
|
+
std::make_shared<AudioBufferHostObject>(audioBuffer);
|
|
33
|
+
|
|
34
|
+
std::unordered_map<std::string, EventValue> body = {};
|
|
35
|
+
body.insert({"buffer", audioBufferHostObject});
|
|
36
|
+
body.insert({"numFrames", numFrames});
|
|
37
|
+
body.insert({"when", when});
|
|
38
|
+
|
|
39
|
+
audioEventHandlerRegistry_->invokeHandlerWithEventBody(
|
|
40
|
+
"audioReady", onAudioReadyCallbackId_, body);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
void AudioRecorder::sendRemainingData() {
|
|
44
|
+
auto bus = std::make_shared<AudioBus>(
|
|
45
|
+
circularBuffer_->getNumberOfAvailableFrames(), 1, sampleRate_);
|
|
46
|
+
auto *outputChannel = bus->getChannel(0)->getData();
|
|
47
|
+
auto availableFrames =
|
|
48
|
+
static_cast<int>(circularBuffer_->getNumberOfAvailableFrames());
|
|
49
|
+
|
|
50
|
+
circularBuffer_->pop_front(
|
|
51
|
+
outputChannel, circularBuffer_->getNumberOfAvailableFrames());
|
|
52
|
+
|
|
53
|
+
invokeOnAudioReadyCallback(bus, availableFrames, 0);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
} // namespace audioapi
|