react-native-audio-api 0.1.0 → 0.3.0-rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -8
- package/RNAudioAPI.podspec +5 -0
- package/android/CMakeLists.txt +21 -10
- package/android/libs/fftw3/arm64-v8a/libfftw3.a +0 -0
- package/android/libs/fftw3/armeabi-v7a/libfftw3.a +0 -0
- package/android/libs/fftw3/x86/libfftw3.a +0 -0
- package/android/libs/fftw3/x86_64/libfftw3.a +0 -0
- package/android/libs/include/fftw3/fftw3.h +413 -0
- package/android/src/main/cpp/AudioPlayer/AudioPlayer.cpp +32 -2
- package/android/src/main/cpp/AudioPlayer/AudioPlayer.h +6 -2
- package/common/cpp/AudioAPIInstaller/AudioAPIInstallerHostObject.cpp +5 -3
- package/common/cpp/AudioAPIInstaller/AudioAPIInstallerHostObject.h +5 -1
- package/common/cpp/HostObjects/AudioBufferHostObject.cpp +6 -0
- package/common/cpp/HostObjects/AudioBufferSourceNodeHostObject.cpp +13 -1
- package/common/cpp/HostObjects/AudioContextHostObject.cpp +12 -149
- package/common/cpp/HostObjects/AudioContextHostObject.h +8 -14
- package/common/cpp/HostObjects/AudioNodeHostObject.cpp +0 -6
- package/common/cpp/HostObjects/BaseAudioContextHostObject.cpp +240 -0
- package/common/cpp/HostObjects/BaseAudioContextHostObject.h +41 -0
- package/common/cpp/HostObjects/BiquadFilterNodeHostObject.cpp +44 -0
- package/common/cpp/HostObjects/OscillatorNodeHostObject.cpp +21 -0
- package/common/cpp/HostObjects/OscillatorNodeHostObject.h +1 -0
- package/common/cpp/HostObjects/PeriodicWaveHostObject.cpp +33 -0
- package/common/cpp/HostObjects/PeriodicWaveHostObject.h +33 -0
- package/common/cpp/core/AudioArray.cpp +117 -0
- package/common/cpp/core/AudioArray.h +48 -0
- package/common/cpp/core/AudioBuffer.cpp +23 -80
- package/common/cpp/core/AudioBuffer.h +12 -13
- package/common/cpp/core/AudioBufferSourceNode.cpp +112 -25
- package/common/cpp/core/AudioBufferSourceNode.h +10 -6
- package/common/cpp/core/AudioBus.cpp +518 -0
- package/common/cpp/core/AudioBus.h +83 -0
- package/common/cpp/core/AudioContext.cpp +7 -77
- package/common/cpp/core/AudioContext.h +3 -60
- package/common/cpp/core/AudioDestinationNode.cpp +27 -15
- package/common/cpp/core/AudioDestinationNode.h +13 -5
- package/common/cpp/core/AudioNode.cpp +184 -22
- package/common/cpp/core/AudioNode.h +37 -37
- package/common/cpp/core/AudioNodeManager.cpp +75 -0
- package/common/cpp/core/AudioNodeManager.h +42 -0
- package/common/cpp/core/AudioParam.cpp +8 -11
- package/common/cpp/core/AudioParam.h +8 -8
- package/common/cpp/core/AudioScheduledSourceNode.cpp +19 -5
- package/common/cpp/core/AudioScheduledSourceNode.h +6 -2
- package/common/cpp/core/BaseAudioContext.cpp +191 -0
- package/common/cpp/core/BaseAudioContext.h +87 -0
- package/common/cpp/core/BiquadFilterNode.cpp +92 -69
- package/common/cpp/core/BiquadFilterNode.h +53 -57
- package/common/cpp/core/GainNode.cpp +12 -12
- package/common/cpp/core/GainNode.h +5 -3
- package/common/cpp/core/OscillatorNode.cpp +38 -29
- package/common/cpp/core/OscillatorNode.h +29 -69
- package/common/cpp/core/ParamChange.h +6 -6
- package/common/cpp/core/PeriodicWave.cpp +362 -0
- package/common/cpp/core/PeriodicWave.h +119 -0
- package/common/cpp/core/StereoPannerNode.cpp +31 -30
- package/common/cpp/core/StereoPannerNode.h +6 -6
- package/common/cpp/types/BiquadFilterType.h +19 -0
- package/common/cpp/types/ChannelCountMode.h +10 -0
- package/common/cpp/types/ChannelInterpretation.h +10 -0
- package/common/cpp/types/ContextState.h +10 -0
- package/common/cpp/types/OscillatorType.h +11 -0
- package/common/cpp/utils/FFTFrame.h +67 -0
- package/common/cpp/utils/JsiPromise.cpp +59 -0
- package/common/cpp/utils/JsiPromise.h +42 -0
- package/common/cpp/utils/Locker.h +49 -0
- package/common/cpp/utils/VectorMath.cpp +88 -3
- package/common/cpp/utils/VectorMath.h +7 -1
- package/common/cpp/utils/android/FFTFrame.cpp +23 -0
- package/common/cpp/utils/ios/FFTFrame.cpp +29 -0
- package/common/cpp/wrappers/AudioBufferSourceNodeWrapper.cpp +10 -0
- package/common/cpp/wrappers/AudioBufferSourceNodeWrapper.h +3 -2
- package/common/cpp/wrappers/AudioBufferWrapper.h +5 -5
- package/common/cpp/wrappers/AudioContextWrapper.cpp +7 -60
- package/common/cpp/wrappers/AudioContextWrapper.h +5 -26
- package/common/cpp/wrappers/AudioNodeWrapper.h +5 -5
- package/common/cpp/wrappers/AudioParamWrapper.h +4 -4
- package/common/cpp/wrappers/BaseAudioContextWrapper.cpp +83 -0
- package/common/cpp/wrappers/BaseAudioContextWrapper.h +50 -0
- package/common/cpp/wrappers/BiquadFilterNodeWrapper.cpp +9 -0
- package/common/cpp/wrappers/BiquadFilterNodeWrapper.h +9 -4
- package/common/cpp/wrappers/GainNodeWrapper.h +1 -1
- package/common/cpp/wrappers/OscillatorNodeWrapper.cpp +6 -0
- package/common/cpp/wrappers/OscillatorNodeWrapper.h +5 -2
- package/common/cpp/wrappers/PeriodicWaveWrapper.h +17 -0
- package/common/cpp/wrappers/StereoPannerNodeWrapper.h +1 -1
- package/ios/AudioAPIModule.h +20 -1
- package/ios/AudioAPIModule.mm +6 -4
- package/ios/AudioDecoder/AudioDecoder.h +17 -0
- package/ios/AudioDecoder/AudioDecoder.m +167 -0
- package/ios/AudioDecoder/IOSAudioDecoder.h +26 -0
- package/ios/AudioDecoder/IOSAudioDecoder.mm +40 -0
- package/ios/AudioPlayer/AudioPlayer.h +3 -2
- package/ios/AudioPlayer/AudioPlayer.m +14 -17
- package/ios/AudioPlayer/IOSAudioPlayer.h +7 -3
- package/ios/AudioPlayer/IOSAudioPlayer.mm +31 -7
- package/lib/module/core/AudioBuffer.js +37 -0
- package/lib/module/core/AudioBuffer.js.map +1 -0
- package/lib/module/core/AudioBufferSourceNode.js +28 -0
- package/lib/module/core/AudioBufferSourceNode.js.map +1 -0
- package/lib/module/core/AudioContext.js +10 -0
- package/lib/module/core/AudioContext.js.map +1 -0
- package/lib/module/core/AudioDestinationNode.js +7 -0
- package/lib/module/core/AudioDestinationNode.js.map +1 -0
- package/lib/module/core/AudioNode.js +22 -0
- package/lib/module/core/AudioNode.js.map +1 -0
- package/lib/module/core/AudioParam.js +35 -0
- package/lib/module/core/AudioParam.js.map +1 -0
- package/lib/module/core/AudioScheduledSourceNode.js +28 -0
- package/lib/module/core/AudioScheduledSourceNode.js.map +1 -0
- package/lib/module/core/BaseAudioContext.js +62 -0
- package/lib/module/core/BaseAudioContext.js.map +1 -0
- package/lib/module/core/BiquadFilterNode.js +25 -0
- package/lib/module/core/BiquadFilterNode.js.map +1 -0
- package/lib/module/core/GainNode.js +9 -0
- package/lib/module/core/GainNode.js.map +1 -0
- package/lib/module/core/OscillatorNode.js +24 -0
- package/lib/module/core/OscillatorNode.js.map +1 -0
- package/lib/module/core/PeriodicWave.js +8 -0
- package/lib/module/core/PeriodicWave.js.map +1 -0
- package/lib/module/core/StereoPannerNode.js +9 -0
- package/lib/module/core/StereoPannerNode.js.map +1 -0
- package/lib/module/core/types.js.map +1 -0
- package/lib/module/errors/IndexSizeError.js +8 -0
- package/lib/module/errors/IndexSizeError.js.map +1 -0
- package/lib/module/errors/InvalidAccessError.js +8 -0
- package/lib/module/errors/InvalidAccessError.js.map +1 -0
- package/lib/module/errors/InvalidStateError.js +8 -0
- package/lib/module/errors/InvalidStateError.js.map +1 -0
- package/lib/module/errors/RangeError.js +8 -0
- package/lib/module/errors/RangeError.js.map +1 -0
- package/lib/module/errors/index.js +5 -0
- package/lib/module/errors/index.js.map +1 -0
- package/lib/module/index.js +212 -15
- package/lib/module/index.js.map +1 -1
- package/lib/module/index.native.js +18 -0
- package/lib/module/index.native.js.map +1 -0
- package/lib/module/interfaces.js +2 -0
- package/lib/module/interfaces.js.map +1 -0
- package/lib/module/utils/resolveAudioSource.js +10 -0
- package/lib/module/utils/resolveAudioSource.js.map +1 -0
- package/lib/typescript/core/AudioBuffer.d.ts +12 -0
- package/lib/typescript/core/AudioBuffer.d.ts.map +1 -0
- package/lib/typescript/core/AudioBufferSourceNode.d.ts +12 -0
- package/lib/typescript/core/AudioBufferSourceNode.d.ts.map +1 -0
- package/lib/typescript/core/AudioContext.d.ts +6 -0
- package/lib/typescript/core/AudioContext.d.ts.map +1 -0
- package/lib/typescript/core/AudioDestinationNode.d.ts +7 -0
- package/lib/typescript/core/AudioDestinationNode.d.ts.map +1 -0
- package/lib/typescript/core/AudioNode.d.ts +16 -0
- package/lib/typescript/core/AudioNode.d.ts.map +1 -0
- package/lib/typescript/core/AudioParam.d.ts +14 -0
- package/lib/typescript/core/AudioParam.d.ts.map +1 -0
- package/lib/typescript/core/AudioScheduledSourceNode.d.ts +10 -0
- package/lib/typescript/core/AudioScheduledSourceNode.d.ts.map +1 -0
- package/lib/typescript/core/BaseAudioContext.d.ts +27 -0
- package/lib/typescript/core/BaseAudioContext.d.ts.map +1 -0
- package/lib/typescript/core/BiquadFilterNode.d.ts +16 -0
- package/lib/typescript/core/BiquadFilterNode.d.ts.map +1 -0
- package/lib/typescript/core/GainNode.d.ts +9 -0
- package/lib/typescript/core/GainNode.d.ts.map +1 -0
- package/lib/typescript/core/OscillatorNode.d.ts +15 -0
- package/lib/typescript/core/OscillatorNode.d.ts.map +1 -0
- package/lib/typescript/core/PeriodicWave.d.ts +5 -0
- package/lib/typescript/core/PeriodicWave.d.ts.map +1 -0
- package/lib/typescript/core/StereoPannerNode.d.ts +9 -0
- package/lib/typescript/core/StereoPannerNode.d.ts.map +1 -0
- package/lib/typescript/core/types.d.ts +15 -0
- package/lib/typescript/core/types.d.ts.map +1 -0
- package/lib/typescript/errors/IndexSizeError.d.ts +5 -0
- package/lib/typescript/errors/IndexSizeError.d.ts.map +1 -0
- package/lib/typescript/errors/InvalidAccessError.d.ts +5 -0
- package/lib/typescript/errors/InvalidAccessError.d.ts.map +1 -0
- package/lib/typescript/errors/InvalidStateError.d.ts +5 -0
- package/lib/typescript/errors/InvalidStateError.d.ts.map +1 -0
- package/lib/typescript/errors/RangeError.d.ts +5 -0
- package/lib/typescript/errors/RangeError.d.ts.map +1 -0
- package/lib/typescript/errors/index.d.ts +5 -0
- package/lib/typescript/errors/index.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +88 -5
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/index.native.d.ts +14 -0
- package/lib/typescript/index.native.d.ts.map +1 -0
- package/lib/typescript/interfaces.d.ts +79 -0
- package/lib/typescript/interfaces.d.ts.map +1 -0
- package/lib/typescript/utils/resolveAudioSource.d.ts +3 -0
- package/lib/typescript/utils/resolveAudioSource.d.ts.map +1 -0
- package/package.json +4 -2
- package/src/core/AudioBuffer.ts +68 -0
- package/src/core/AudioBufferSourceNode.ts +35 -0
- package/src/core/AudioContext.ts +12 -0
- package/src/core/AudioDestinationNode.ts +9 -0
- package/src/core/AudioNode.ts +38 -0
- package/src/core/AudioParam.ts +55 -0
- package/src/core/AudioScheduledSourceNode.ts +43 -0
- package/src/core/BaseAudioContext.ts +108 -0
- package/src/core/BiquadFilterNode.ts +49 -0
- package/src/core/GainNode.ts +13 -0
- package/src/core/OscillatorNode.ts +37 -0
- package/src/core/PeriodicWave.ts +10 -0
- package/src/core/StereoPannerNode.ts +13 -0
- package/src/core/types.ts +33 -0
- package/src/errors/IndexSizeError.ts +8 -0
- package/src/errors/InvalidAccessError.ts +8 -0
- package/src/errors/InvalidStateError.ts +8 -0
- package/src/errors/RangeError.ts +8 -0
- package/src/errors/index.ts +4 -0
- package/src/index.native.ts +25 -0
- package/src/index.ts +380 -40
- package/src/interfaces.ts +121 -0
- package/src/modules/global.d.ts +3 -3
- package/src/utils/resolveAudioSource.ts +14 -0
- package/lib/module/types.js.map +0 -1
- package/lib/typescript/types.d.ts +0 -76
- package/lib/typescript/types.d.ts.map +0 -1
- package/src/types.ts +0 -108
- /package/lib/module/{types.js → core/types.js} +0 -0
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
|
+
#include <ReactCommon/CallInvoker.h>
|
|
3
4
|
#include <jsi/jsi.h>
|
|
4
5
|
#include <memory>
|
|
5
6
|
#include <utility>
|
|
6
7
|
#include <vector>
|
|
7
8
|
|
|
9
|
+
|
|
8
10
|
#include "AudioAPIInstallerWrapper.h"
|
|
9
11
|
#include "AudioContextHostObject.h"
|
|
12
|
+
#include "JsiPromise.h"
|
|
10
13
|
|
|
11
14
|
namespace audioapi {
|
|
12
15
|
using namespace facebook;
|
|
@@ -16,7 +19,7 @@ class AudioAPIInstallerWrapper;
|
|
|
16
19
|
class AudioAPIInstallerHostObject : public jsi::HostObject {
|
|
17
20
|
public:
|
|
18
21
|
explicit AudioAPIInstallerHostObject(
|
|
19
|
-
const std::shared_ptr<AudioAPIInstallerWrapper> &wrapper);
|
|
22
|
+
const std::shared_ptr<AudioAPIInstallerWrapper> &wrapper, jsi::Runtime* runtime, const std::shared_ptr<react::CallInvoker> &jsInvoker);
|
|
20
23
|
|
|
21
24
|
#ifdef ANDROID
|
|
22
25
|
static void createAndInstallFromWrapper(
|
|
@@ -41,5 +44,6 @@ class AudioAPIInstallerHostObject : public jsi::HostObject {
|
|
|
41
44
|
|
|
42
45
|
private:
|
|
43
46
|
std::shared_ptr<AudioAPIInstallerWrapper> wrapper_;
|
|
47
|
+
std::shared_ptr<JsiPromise::PromiseVendor> promiseVendor_;
|
|
44
48
|
};
|
|
45
49
|
} // namespace audioapi
|
|
@@ -128,6 +128,12 @@ jsi::Value AudioBufferHostObject::get(
|
|
|
128
128
|
});
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
+
// `decodeAudioData` is a method that returns a promise to AudioBufferHostObject
|
|
132
|
+
// It seems that async/await checks for the presence of `then` method on the object
|
|
133
|
+
if (propName == "then") {
|
|
134
|
+
return jsi::Value::undefined();
|
|
135
|
+
}
|
|
136
|
+
|
|
131
137
|
throw std::runtime_error("Not yet implemented!");
|
|
132
138
|
}
|
|
133
139
|
|
|
@@ -18,6 +18,7 @@ std::vector<jsi::PropNameID> AudioBufferSourceNodeHostObject::getPropertyNames(
|
|
|
18
18
|
AudioScheduledSourceNodeHostObject::getPropertyNames(runtime);
|
|
19
19
|
propertyNames.push_back(jsi::PropNameID::forAscii(runtime, "loop"));
|
|
20
20
|
propertyNames.push_back(jsi::PropNameID::forAscii(runtime, "buffer"));
|
|
21
|
+
propertyNames.push_back(jsi::PropNameID::forAscii(runtime, "resetBuffer"));
|
|
21
22
|
return propertyNames;
|
|
22
23
|
}
|
|
23
24
|
|
|
@@ -35,6 +36,11 @@ jsi::Value AudioBufferSourceNodeHostObject::get(
|
|
|
35
36
|
if (propName == "buffer") {
|
|
36
37
|
auto wrapper = getAudioBufferSourceNodeWrapperFromAudioNodeWrapper();
|
|
37
38
|
auto buffer = wrapper->getBuffer();
|
|
39
|
+
|
|
40
|
+
if (!buffer) {
|
|
41
|
+
return jsi::Value::null();
|
|
42
|
+
}
|
|
43
|
+
|
|
38
44
|
auto bufferHostObject = AudioBufferHostObject::createFromWrapper(buffer);
|
|
39
45
|
return jsi::Object::createFromHostObject(runtime, bufferHostObject);
|
|
40
46
|
}
|
|
@@ -55,9 +61,15 @@ void AudioBufferSourceNodeHostObject::set(
|
|
|
55
61
|
}
|
|
56
62
|
|
|
57
63
|
if (propName == "buffer") {
|
|
64
|
+
auto wrapper = getAudioBufferSourceNodeWrapperFromAudioNodeWrapper();
|
|
65
|
+
|
|
66
|
+
if (value.isNull()) {
|
|
67
|
+
wrapper->setBuffer(std::shared_ptr<AudioBufferWrapper>(nullptr));
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
58
71
|
auto bufferHostObject =
|
|
59
72
|
value.getObject(runtime).asHostObject<AudioBufferHostObject>(runtime);
|
|
60
|
-
auto wrapper = getAudioBufferSourceNodeWrapperFromAudioNodeWrapper();
|
|
61
73
|
wrapper->setBuffer(bufferHostObject->wrapper_);
|
|
62
74
|
return;
|
|
63
75
|
}
|
|
@@ -4,30 +4,13 @@ namespace audioapi {
|
|
|
4
4
|
using namespace facebook;
|
|
5
5
|
|
|
6
6
|
AudioContextHostObject::AudioContextHostObject(
|
|
7
|
-
const std::shared_ptr<AudioContextWrapper> &wrapper)
|
|
8
|
-
:
|
|
9
|
-
auto destinationNodeWrapper = wrapper_->getDestination();
|
|
10
|
-
destination_ =
|
|
11
|
-
AudioDestinationNodeHostObject::createFromWrapper(destinationNodeWrapper);
|
|
12
|
-
}
|
|
7
|
+
const std::shared_ptr<AudioContextWrapper> &wrapper, std::shared_ptr<JsiPromise::PromiseVendor> promiseVendor)
|
|
8
|
+
: BaseAudioContextHostObject(wrapper, promiseVendor) {}
|
|
13
9
|
|
|
14
10
|
std::vector<jsi::PropNameID> AudioContextHostObject::getPropertyNames(
|
|
15
11
|
jsi::Runtime &runtime) {
|
|
16
|
-
std::vector<jsi::PropNameID> propertyNames
|
|
17
|
-
|
|
18
|
-
propertyNames.push_back(jsi::PropNameID::forUtf8(runtime, "state"));
|
|
19
|
-
propertyNames.push_back(jsi::PropNameID::forUtf8(runtime, "sampleRate"));
|
|
20
|
-
propertyNames.push_back(jsi::PropNameID::forUtf8(runtime, "currentTime"));
|
|
21
|
-
propertyNames.push_back(
|
|
22
|
-
jsi::PropNameID::forUtf8(runtime, "createOscillator"));
|
|
23
|
-
propertyNames.push_back(jsi::PropNameID::forUtf8(runtime, "createGain"));
|
|
24
|
-
propertyNames.push_back(
|
|
25
|
-
jsi::PropNameID::forUtf8(runtime, "createStereoPanner"));
|
|
26
|
-
propertyNames.push_back(
|
|
27
|
-
jsi::PropNameID::forUtf8(runtime, "createBiquadFilter"));
|
|
28
|
-
propertyNames.push_back(
|
|
29
|
-
jsi::PropNameID::forUtf8(runtime, "createBufferSource"));
|
|
30
|
-
propertyNames.push_back(jsi::PropNameID::forUtf8(runtime, "createBuffer"));
|
|
12
|
+
std::vector<jsi::PropNameID> propertyNames =
|
|
13
|
+
BaseAudioContextHostObject::getPropertyNames(runtime);
|
|
31
14
|
propertyNames.push_back(jsi::PropNameID::forUtf8(runtime, "close"));
|
|
32
15
|
return propertyNames;
|
|
33
16
|
}
|
|
@@ -37,131 +20,6 @@ jsi::Value AudioContextHostObject::get(
|
|
|
37
20
|
const jsi::PropNameID &propNameId) {
|
|
38
21
|
auto propName = propNameId.utf8(runtime);
|
|
39
22
|
|
|
40
|
-
if (propName == "destination") {
|
|
41
|
-
return jsi::Object::createFromHostObject(runtime, destination_);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (propName == "state") {
|
|
45
|
-
return jsi::String::createFromUtf8(runtime, wrapper_->getState());
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (propName == "sampleRate") {
|
|
49
|
-
return {wrapper_->getSampleRate()};
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (propName == "currentTime") {
|
|
53
|
-
return {wrapper_->getCurrentTime()};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (propName == "createOscillator") {
|
|
57
|
-
return jsi::Function::createFromHostFunction(
|
|
58
|
-
runtime,
|
|
59
|
-
propNameId,
|
|
60
|
-
0,
|
|
61
|
-
[this](
|
|
62
|
-
jsi::Runtime &runtime,
|
|
63
|
-
const jsi::Value &thisValue,
|
|
64
|
-
const jsi::Value *arguments,
|
|
65
|
-
size_t count) -> jsi::Value {
|
|
66
|
-
auto oscillator = wrapper_->createOscillator();
|
|
67
|
-
auto oscillatorHostObject =
|
|
68
|
-
OscillatorNodeHostObject::createFromWrapper(oscillator);
|
|
69
|
-
return jsi::Object::createFromHostObject(
|
|
70
|
-
runtime, oscillatorHostObject);
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (propName == "createGain") {
|
|
75
|
-
return jsi::Function::createFromHostFunction(
|
|
76
|
-
runtime,
|
|
77
|
-
propNameId,
|
|
78
|
-
0,
|
|
79
|
-
[this](
|
|
80
|
-
jsi::Runtime &runtime,
|
|
81
|
-
const jsi::Value &thisValue,
|
|
82
|
-
const jsi::Value *arguments,
|
|
83
|
-
size_t count) -> jsi::Value {
|
|
84
|
-
auto gain = wrapper_->createGain();
|
|
85
|
-
auto gainHostObject = GainNodeHostObject::createFromWrapper(gain);
|
|
86
|
-
return jsi::Object::createFromHostObject(runtime, gainHostObject);
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (propName == "createStereoPanner") {
|
|
91
|
-
return jsi::Function::createFromHostFunction(
|
|
92
|
-
runtime,
|
|
93
|
-
propNameId,
|
|
94
|
-
0,
|
|
95
|
-
[this](
|
|
96
|
-
jsi::Runtime &runtime,
|
|
97
|
-
const jsi::Value &thisValue,
|
|
98
|
-
const jsi::Value *arguments,
|
|
99
|
-
size_t count) -> jsi::Value {
|
|
100
|
-
auto stereoPanner = wrapper_->createStereoPanner();
|
|
101
|
-
auto stereoPannerHostObject =
|
|
102
|
-
StereoPannerNodeHostObject::createFromWrapper(stereoPanner);
|
|
103
|
-
return jsi::Object::createFromHostObject(
|
|
104
|
-
runtime, stereoPannerHostObject);
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (propName == "createBiquadFilter") {
|
|
109
|
-
return jsi::Function::createFromHostFunction(
|
|
110
|
-
runtime,
|
|
111
|
-
propNameId,
|
|
112
|
-
0,
|
|
113
|
-
[this](
|
|
114
|
-
jsi::Runtime &runtime,
|
|
115
|
-
const jsi::Value &thisValue,
|
|
116
|
-
const jsi::Value *arguments,
|
|
117
|
-
size_t count) -> jsi::Value {
|
|
118
|
-
auto biquadFilter = wrapper_->createBiquadFilter();
|
|
119
|
-
auto biquadFilterHostObject =
|
|
120
|
-
BiquadFilterNodeHostObject::createFromWrapper(biquadFilter);
|
|
121
|
-
return jsi::Object::createFromHostObject(
|
|
122
|
-
runtime, biquadFilterHostObject);
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if (propName == "createBufferSource") {
|
|
127
|
-
return jsi::Function::createFromHostFunction(
|
|
128
|
-
runtime,
|
|
129
|
-
propNameId,
|
|
130
|
-
0,
|
|
131
|
-
[this](
|
|
132
|
-
jsi::Runtime &runtime,
|
|
133
|
-
const jsi::Value &thisValue,
|
|
134
|
-
const jsi::Value *arguments,
|
|
135
|
-
size_t count) -> jsi::Value {
|
|
136
|
-
auto bufferSource = wrapper_->createBufferSource();
|
|
137
|
-
auto bufferSourceHostObject =
|
|
138
|
-
AudioBufferSourceNodeHostObject::createFromWrapper(bufferSource);
|
|
139
|
-
return jsi::Object::createFromHostObject(
|
|
140
|
-
runtime, bufferSourceHostObject);
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
if (propName == "createBuffer") {
|
|
145
|
-
return jsi::Function::createFromHostFunction(
|
|
146
|
-
runtime,
|
|
147
|
-
propNameId,
|
|
148
|
-
3,
|
|
149
|
-
[this](
|
|
150
|
-
jsi::Runtime &runtime,
|
|
151
|
-
const jsi::Value &thisValue,
|
|
152
|
-
const jsi::Value *arguments,
|
|
153
|
-
size_t count) -> jsi::Value {
|
|
154
|
-
auto numberOfChannels = static_cast<int>(arguments[0].getNumber());
|
|
155
|
-
auto length = static_cast<int>(arguments[1].getNumber());
|
|
156
|
-
auto sampleRate = static_cast<int>(arguments[2].getNumber());
|
|
157
|
-
auto buffer =
|
|
158
|
-
wrapper_->createBuffer(numberOfChannels, length, sampleRate);
|
|
159
|
-
auto bufferHostObject =
|
|
160
|
-
AudioBufferHostObject::createFromWrapper(buffer);
|
|
161
|
-
return jsi::Object::createFromHostObject(runtime, bufferHostObject);
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
|
|
165
23
|
if (propName == "close") {
|
|
166
24
|
return jsi::Function::createFromHostFunction(
|
|
167
25
|
runtime,
|
|
@@ -172,12 +30,12 @@ jsi::Value AudioContextHostObject::get(
|
|
|
172
30
|
const jsi::Value &thisValue,
|
|
173
31
|
const jsi::Value *arguments,
|
|
174
32
|
size_t count) -> jsi::Value {
|
|
175
|
-
|
|
33
|
+
getAudioContextWrapperFromBaseAudioContextWrapper()->close();
|
|
176
34
|
return jsi::Value::undefined();
|
|
177
35
|
});
|
|
178
36
|
}
|
|
179
37
|
|
|
180
|
-
|
|
38
|
+
return BaseAudioContextHostObject::get(runtime, propNameId);
|
|
181
39
|
}
|
|
182
40
|
|
|
183
41
|
void AudioContextHostObject::set(
|
|
@@ -186,6 +44,11 @@ void AudioContextHostObject::set(
|
|
|
186
44
|
const jsi::Value &value) {
|
|
187
45
|
auto propName = propNameId.utf8(runtime);
|
|
188
46
|
|
|
189
|
-
|
|
47
|
+
return BaseAudioContextHostObject::set(runtime, propNameId, value);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
std::shared_ptr<AudioContextWrapper>
|
|
51
|
+
AudioContextHostObject::getAudioContextWrapperFromBaseAudioContextWrapper() {
|
|
52
|
+
return std::static_pointer_cast<AudioContextWrapper>(wrapper_);
|
|
190
53
|
}
|
|
191
54
|
} // namespace audioapi
|
|
@@ -2,25 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
#include <jsi/jsi.h>
|
|
4
4
|
#include <memory>
|
|
5
|
-
#include <utility>
|
|
6
5
|
#include <vector>
|
|
7
6
|
|
|
8
|
-
#include
|
|
9
|
-
#include "AudioBufferSourceNodeHostObject.h"
|
|
7
|
+
#include"JsiPromise.h"
|
|
10
8
|
#include "AudioContextWrapper.h"
|
|
11
|
-
#include "
|
|
12
|
-
#include "BiquadFilterNodeHostObject.h"
|
|
13
|
-
#include "GainNodeHostObject.h"
|
|
14
|
-
#include "OscillatorNodeHostObject.h"
|
|
15
|
-
#include "StereoPannerNodeHostObject.h"
|
|
9
|
+
#include "BaseAudioContextHostObject.h"
|
|
16
10
|
|
|
17
11
|
namespace audioapi {
|
|
18
12
|
using namespace facebook;
|
|
19
13
|
|
|
20
|
-
class AudioContextHostObject : public
|
|
14
|
+
class AudioContextHostObject : public BaseAudioContextHostObject {
|
|
21
15
|
public:
|
|
22
16
|
explicit AudioContextHostObject(
|
|
23
|
-
const std::shared_ptr<AudioContextWrapper> &wrapper);
|
|
17
|
+
const std::shared_ptr<AudioContextWrapper> &wrapper, std::shared_ptr<JsiPromise::PromiseVendor> promiseVendor);
|
|
24
18
|
|
|
25
19
|
jsi::Value get(jsi::Runtime &runtime, const jsi::PropNameID &name) override;
|
|
26
20
|
|
|
@@ -32,12 +26,12 @@ class AudioContextHostObject : public jsi::HostObject {
|
|
|
32
26
|
std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt) override;
|
|
33
27
|
|
|
34
28
|
static std::shared_ptr<AudioContextHostObject> createFromWrapper(
|
|
35
|
-
const std::shared_ptr<AudioContextWrapper> &wrapper) {
|
|
36
|
-
return std::make_shared<AudioContextHostObject>(wrapper);
|
|
29
|
+
const std::shared_ptr<AudioContextWrapper> &wrapper, std::shared_ptr<JsiPromise::PromiseVendor> promiseVendor) {
|
|
30
|
+
return std::make_shared<AudioContextHostObject>(wrapper, promiseVendor);
|
|
37
31
|
}
|
|
38
32
|
|
|
39
33
|
private:
|
|
40
|
-
std::shared_ptr<AudioContextWrapper>
|
|
41
|
-
|
|
34
|
+
std::shared_ptr<AudioContextWrapper>
|
|
35
|
+
getAudioContextWrapperFromBaseAudioContextWrapper();
|
|
42
36
|
};
|
|
43
37
|
} // namespace audioapi
|
|
@@ -21,7 +21,6 @@ std::vector<jsi::PropNameID> AudioNodeHostObject::getPropertyNames(
|
|
|
21
21
|
jsi::PropNameID::forAscii(runtime, "channelCountMode"));
|
|
22
22
|
propertyNames.push_back(
|
|
23
23
|
jsi::PropNameID::forAscii(runtime, "channelInterpretation"));
|
|
24
|
-
propertyNames.push_back(jsi::PropNameID::forAscii(runtime, "context"));
|
|
25
24
|
return propertyNames;
|
|
26
25
|
}
|
|
27
26
|
|
|
@@ -88,11 +87,6 @@ jsi::Value AudioNodeHostObject::get(
|
|
|
88
87
|
runtime, wrapper_->getChannelInterpretation());
|
|
89
88
|
}
|
|
90
89
|
|
|
91
|
-
if (propName == "context") {
|
|
92
|
-
// TODO fix this
|
|
93
|
-
return jsi::Value::undefined();
|
|
94
|
-
}
|
|
95
|
-
|
|
96
90
|
throw std::runtime_error("Not yet implemented!");
|
|
97
91
|
}
|
|
98
92
|
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
#include <thread>
|
|
2
|
+
|
|
3
|
+
#include "BaseAudioContextHostObject.h"
|
|
4
|
+
|
|
5
|
+
namespace audioapi {
|
|
6
|
+
using namespace facebook;
|
|
7
|
+
|
|
8
|
+
BaseAudioContextHostObject::BaseAudioContextHostObject(
|
|
9
|
+
const std::shared_ptr<BaseAudioContextWrapper> &wrapper, std::shared_ptr<JsiPromise::PromiseVendor> promiseVendor)
|
|
10
|
+
: wrapper_(wrapper), promiseVendor_(promiseVendor) {
|
|
11
|
+
auto destinationNodeWrapper = wrapper_->getDestination();
|
|
12
|
+
destination_ =
|
|
13
|
+
AudioDestinationNodeHostObject::createFromWrapper(destinationNodeWrapper);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
std::vector<jsi::PropNameID> BaseAudioContextHostObject::getPropertyNames(
|
|
17
|
+
jsi::Runtime &runtime) {
|
|
18
|
+
std::vector<jsi::PropNameID> propertyNames;
|
|
19
|
+
propertyNames.push_back(jsi::PropNameID::forUtf8(runtime, "destination"));
|
|
20
|
+
propertyNames.push_back(jsi::PropNameID::forUtf8(runtime, "state"));
|
|
21
|
+
propertyNames.push_back(jsi::PropNameID::forUtf8(runtime, "sampleRate"));
|
|
22
|
+
propertyNames.push_back(jsi::PropNameID::forUtf8(runtime, "currentTime"));
|
|
23
|
+
propertyNames.push_back(
|
|
24
|
+
jsi::PropNameID::forUtf8(runtime, "createOscillator"));
|
|
25
|
+
propertyNames.push_back(jsi::PropNameID::forUtf8(runtime, "createGain"));
|
|
26
|
+
propertyNames.push_back(
|
|
27
|
+
jsi::PropNameID::forUtf8(runtime, "createStereoPanner"));
|
|
28
|
+
propertyNames.push_back(
|
|
29
|
+
jsi::PropNameID::forUtf8(runtime, "createBiquadFilter"));
|
|
30
|
+
propertyNames.push_back(
|
|
31
|
+
jsi::PropNameID::forUtf8(runtime, "createBufferSource"));
|
|
32
|
+
propertyNames.push_back(jsi::PropNameID::forUtf8(runtime, "createBuffer"));
|
|
33
|
+
propertyNames.push_back(
|
|
34
|
+
jsi::PropNameID::forUtf8(runtime, "createPeriodicWave"));
|
|
35
|
+
propertyNames.push_back(
|
|
36
|
+
jsi::PropNameID::forUtf8(runtime, "decodeAudioDataSource"));
|
|
37
|
+
return propertyNames;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
jsi::Value BaseAudioContextHostObject::get(
|
|
41
|
+
jsi::Runtime &runtime,
|
|
42
|
+
const jsi::PropNameID &propNameId) {
|
|
43
|
+
auto propName = propNameId.utf8(runtime);
|
|
44
|
+
|
|
45
|
+
if (propName == "destination") {
|
|
46
|
+
return jsi::Object::createFromHostObject(runtime, destination_);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (propName == "state") {
|
|
50
|
+
return jsi::String::createFromUtf8(runtime, wrapper_->getState());
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (propName == "sampleRate") {
|
|
54
|
+
return {wrapper_->getSampleRate()};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (propName == "currentTime") {
|
|
58
|
+
return {wrapper_->getCurrentTime()};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (propName == "createOscillator") {
|
|
62
|
+
return jsi::Function::createFromHostFunction(
|
|
63
|
+
runtime,
|
|
64
|
+
propNameId,
|
|
65
|
+
0,
|
|
66
|
+
[this](
|
|
67
|
+
jsi::Runtime &runtime,
|
|
68
|
+
const jsi::Value &thisValue,
|
|
69
|
+
const jsi::Value *arguments,
|
|
70
|
+
size_t count) -> jsi::Value {
|
|
71
|
+
auto oscillator = wrapper_->createOscillator();
|
|
72
|
+
auto oscillatorHostObject =
|
|
73
|
+
OscillatorNodeHostObject::createFromWrapper(oscillator);
|
|
74
|
+
return jsi::Object::createFromHostObject(
|
|
75
|
+
runtime, oscillatorHostObject);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (propName == "createGain") {
|
|
80
|
+
return jsi::Function::createFromHostFunction(
|
|
81
|
+
runtime,
|
|
82
|
+
propNameId,
|
|
83
|
+
0,
|
|
84
|
+
[this](
|
|
85
|
+
jsi::Runtime &runtime,
|
|
86
|
+
const jsi::Value &thisValue,
|
|
87
|
+
const jsi::Value *arguments,
|
|
88
|
+
size_t count) -> jsi::Value {
|
|
89
|
+
auto gain = wrapper_->createGain();
|
|
90
|
+
auto gainHostObject = GainNodeHostObject::createFromWrapper(gain);
|
|
91
|
+
return jsi::Object::createFromHostObject(runtime, gainHostObject);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (propName == "createStereoPanner") {
|
|
96
|
+
return jsi::Function::createFromHostFunction(
|
|
97
|
+
runtime,
|
|
98
|
+
propNameId,
|
|
99
|
+
0,
|
|
100
|
+
[this](
|
|
101
|
+
jsi::Runtime &runtime,
|
|
102
|
+
const jsi::Value &thisValue,
|
|
103
|
+
const jsi::Value *arguments,
|
|
104
|
+
size_t count) -> jsi::Value {
|
|
105
|
+
auto stereoPanner = wrapper_->createStereoPanner();
|
|
106
|
+
auto stereoPannerHostObject =
|
|
107
|
+
StereoPannerNodeHostObject::createFromWrapper(stereoPanner);
|
|
108
|
+
return jsi::Object::createFromHostObject(
|
|
109
|
+
runtime, stereoPannerHostObject);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (propName == "createBiquadFilter") {
|
|
114
|
+
return jsi::Function::createFromHostFunction(
|
|
115
|
+
runtime,
|
|
116
|
+
propNameId,
|
|
117
|
+
0,
|
|
118
|
+
[this](
|
|
119
|
+
jsi::Runtime &runtime,
|
|
120
|
+
const jsi::Value &thisValue,
|
|
121
|
+
const jsi::Value *arguments,
|
|
122
|
+
size_t count) -> jsi::Value {
|
|
123
|
+
auto biquadFilter = wrapper_->createBiquadFilter();
|
|
124
|
+
auto biquadFilterHostObject =
|
|
125
|
+
BiquadFilterNodeHostObject::createFromWrapper(biquadFilter);
|
|
126
|
+
return jsi::Object::createFromHostObject(
|
|
127
|
+
runtime, biquadFilterHostObject);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (propName == "createBufferSource") {
|
|
132
|
+
return jsi::Function::createFromHostFunction(
|
|
133
|
+
runtime,
|
|
134
|
+
propNameId,
|
|
135
|
+
0,
|
|
136
|
+
[this](
|
|
137
|
+
jsi::Runtime &runtime,
|
|
138
|
+
const jsi::Value &thisValue,
|
|
139
|
+
const jsi::Value *arguments,
|
|
140
|
+
size_t count) -> jsi::Value {
|
|
141
|
+
auto bufferSource = wrapper_->createBufferSource();
|
|
142
|
+
auto bufferSourceHostObject =
|
|
143
|
+
AudioBufferSourceNodeHostObject::createFromWrapper(bufferSource);
|
|
144
|
+
return jsi::Object::createFromHostObject(
|
|
145
|
+
runtime, bufferSourceHostObject);
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (propName == "createBuffer") {
|
|
150
|
+
return jsi::Function::createFromHostFunction(
|
|
151
|
+
runtime,
|
|
152
|
+
propNameId,
|
|
153
|
+
3,
|
|
154
|
+
[this](
|
|
155
|
+
jsi::Runtime &runtime,
|
|
156
|
+
const jsi::Value &thisValue,
|
|
157
|
+
const jsi::Value *arguments,
|
|
158
|
+
size_t count) -> jsi::Value {
|
|
159
|
+
auto numberOfChannels = static_cast<int>(arguments[0].getNumber());
|
|
160
|
+
auto length = static_cast<int>(arguments[1].getNumber());
|
|
161
|
+
auto sampleRate = static_cast<int>(arguments[2].getNumber());
|
|
162
|
+
auto buffer =
|
|
163
|
+
wrapper_->createBuffer(numberOfChannels, length, sampleRate);
|
|
164
|
+
auto bufferHostObject =
|
|
165
|
+
AudioBufferHostObject::createFromWrapper(buffer);
|
|
166
|
+
return jsi::Object::createFromHostObject(runtime, bufferHostObject);
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (propName == "createPeriodicWave") {
|
|
171
|
+
return jsi::Function::createFromHostFunction(
|
|
172
|
+
runtime,
|
|
173
|
+
propNameId,
|
|
174
|
+
3,
|
|
175
|
+
[this](
|
|
176
|
+
jsi::Runtime &runtime,
|
|
177
|
+
const jsi::Value &thisValue,
|
|
178
|
+
const jsi::Value *arguments,
|
|
179
|
+
size_t count) -> jsi::Value {
|
|
180
|
+
auto real = arguments[0].getObject(runtime).getArray(runtime);
|
|
181
|
+
auto imag = arguments[1].getObject(runtime).getArray(runtime);
|
|
182
|
+
auto disableNormalization = arguments[2].getBool();
|
|
183
|
+
auto length =
|
|
184
|
+
static_cast<int>(real.getProperty(runtime, "length").asNumber());
|
|
185
|
+
|
|
186
|
+
auto *realData = new float[length];
|
|
187
|
+
auto *imagData = new float[length];
|
|
188
|
+
|
|
189
|
+
for (size_t i = 0; i < real.length(runtime); i++) {
|
|
190
|
+
realData[i] = static_cast<float>(
|
|
191
|
+
real.getValueAtIndex(runtime, i).getNumber());
|
|
192
|
+
}
|
|
193
|
+
for (size_t i = 0; i < imag.length(runtime); i++) {
|
|
194
|
+
realData[i] = static_cast<float>(
|
|
195
|
+
imag.getValueAtIndex(runtime, i).getNumber());
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
auto periodicWave = wrapper_->createPeriodicWave(
|
|
199
|
+
realData, imagData, disableNormalization, length);
|
|
200
|
+
auto periodicWaveHostObject =
|
|
201
|
+
PeriodicWaveHostObject::createFromWrapper(periodicWave);
|
|
202
|
+
return jsi::Object::createFromHostObject(
|
|
203
|
+
runtime, periodicWaveHostObject);
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (propName == "decodeAudioDataSource") {
|
|
208
|
+
auto decode = [this](jsi::Runtime& runtime,
|
|
209
|
+
const jsi::Value&,
|
|
210
|
+
const jsi::Value* arguments,
|
|
211
|
+
size_t count) -> jsi::Value {
|
|
212
|
+
auto sourcePath = arguments[0].getString(runtime).utf8(runtime);
|
|
213
|
+
|
|
214
|
+
auto promise = promiseVendor_->createPromise([this, &runtime, sourcePath](std::shared_ptr<JsiPromise::Promise> promise) {
|
|
215
|
+
std::thread([this, &runtime, sourcePath, promise = std::move(promise)]() {
|
|
216
|
+
auto results = wrapper_->decodeAudioDataSource(sourcePath);
|
|
217
|
+
auto audioBufferHostObject = AudioBufferHostObject::createFromWrapper(results);
|
|
218
|
+
|
|
219
|
+
promise->resolve(jsi::Object::createFromHostObject(runtime, audioBufferHostObject));
|
|
220
|
+
}).detach();
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
return promise;
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
return jsi::Function::createFromHostFunction(runtime, propNameId, 1, decode);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
throw std::runtime_error("Not yet implemented!");
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
void BaseAudioContextHostObject::set(
|
|
233
|
+
jsi::Runtime &runtime,
|
|
234
|
+
const jsi::PropNameID &propNameId,
|
|
235
|
+
const jsi::Value &value) {
|
|
236
|
+
auto propName = propNameId.utf8(runtime);
|
|
237
|
+
|
|
238
|
+
throw std::runtime_error("Not yet implemented!");
|
|
239
|
+
}
|
|
240
|
+
} // namespace audioapi
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <jsi/jsi.h>
|
|
4
|
+
#include <memory>
|
|
5
|
+
#include <utility>
|
|
6
|
+
#include <vector>
|
|
7
|
+
|
|
8
|
+
#include "JsiPromise.h"
|
|
9
|
+
#include "AudioBufferHostObject.h"
|
|
10
|
+
#include "AudioBufferSourceNodeHostObject.h"
|
|
11
|
+
#include "AudioDestinationNodeHostObject.h"
|
|
12
|
+
#include "BaseAudioContextWrapper.h"
|
|
13
|
+
#include "BiquadFilterNodeHostObject.h"
|
|
14
|
+
#include "GainNodeHostObject.h"
|
|
15
|
+
#include "OscillatorNodeHostObject.h"
|
|
16
|
+
#include "PeriodicWaveHostObject.h"
|
|
17
|
+
#include "StereoPannerNodeHostObject.h"
|
|
18
|
+
|
|
19
|
+
namespace audioapi {
|
|
20
|
+
using namespace facebook;
|
|
21
|
+
|
|
22
|
+
class BaseAudioContextHostObject : public jsi::HostObject {
|
|
23
|
+
public:
|
|
24
|
+
explicit BaseAudioContextHostObject(
|
|
25
|
+
const std::shared_ptr<BaseAudioContextWrapper> &wrapper, std::shared_ptr<JsiPromise::PromiseVendor> promiseVendor);
|
|
26
|
+
|
|
27
|
+
jsi::Value get(jsi::Runtime &runtime, const jsi::PropNameID &name) override;
|
|
28
|
+
|
|
29
|
+
void set(
|
|
30
|
+
jsi::Runtime &runtime,
|
|
31
|
+
const jsi::PropNameID &name,
|
|
32
|
+
const jsi::Value &value) override;
|
|
33
|
+
|
|
34
|
+
std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt) override;
|
|
35
|
+
|
|
36
|
+
protected:
|
|
37
|
+
std::shared_ptr<BaseAudioContextWrapper> wrapper_;
|
|
38
|
+
std::shared_ptr<AudioDestinationNodeHostObject> destination_;
|
|
39
|
+
std::shared_ptr<JsiPromise::PromiseVendor> promiseVendor_;
|
|
40
|
+
};
|
|
41
|
+
} // namespace audioapi
|
|
@@ -30,6 +30,8 @@ std::vector<jsi::PropNameID> BiquadFilterNodeHostObject::getPropertyNames(
|
|
|
30
30
|
propertyNames.push_back(jsi::PropNameID::forAscii(runtime, "Q"));
|
|
31
31
|
propertyNames.push_back(jsi::PropNameID::forAscii(runtime, "gain"));
|
|
32
32
|
propertyNames.push_back(jsi::PropNameID::forAscii(runtime, "type"));
|
|
33
|
+
propertyNames.push_back(
|
|
34
|
+
jsi::PropNameID::forAscii(runtime, "getFrequencyResponse"));
|
|
33
35
|
return propertyNames;
|
|
34
36
|
}
|
|
35
37
|
|
|
@@ -60,6 +62,48 @@ jsi::Value BiquadFilterNodeHostObject::get(
|
|
|
60
62
|
return jsi::String::createFromUtf8(runtime, waveType);
|
|
61
63
|
}
|
|
62
64
|
|
|
65
|
+
if (propName == "getFrequencyResponse") {
|
|
66
|
+
return jsi::Function::createFromHostFunction(
|
|
67
|
+
runtime,
|
|
68
|
+
propNameId,
|
|
69
|
+
3,
|
|
70
|
+
[this](
|
|
71
|
+
jsi::Runtime &rt,
|
|
72
|
+
const jsi::Value &thisVal,
|
|
73
|
+
const jsi::Value *args,
|
|
74
|
+
size_t count) -> jsi::Value {
|
|
75
|
+
auto frequencyArray = args[0].getObject(rt).asArray(rt);
|
|
76
|
+
auto magResponseOut = args[1].getObject(rt).asArray(rt);
|
|
77
|
+
auto phaseResponseOut = args[2].getObject(rt).asArray(rt);
|
|
78
|
+
|
|
79
|
+
std::vector<float> frequencyArrayVector(frequencyArray.length(rt));
|
|
80
|
+
for (size_t i = 0; i < frequencyArray.length(rt); i++) {
|
|
81
|
+
frequencyArrayVector[i] = static_cast<float>(
|
|
82
|
+
frequencyArray.getValueAtIndex(rt, i).getNumber());
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
std::vector<float> magResponseOutVector(magResponseOut.length(rt));
|
|
86
|
+
std::vector<float> phaseResponseOutVector(
|
|
87
|
+
phaseResponseOut.length(rt));
|
|
88
|
+
|
|
89
|
+
auto wrapper = getBiquadFilterNodeWrapperFromAudioNodeWrapper();
|
|
90
|
+
wrapper->getFrequencyResponse(
|
|
91
|
+
frequencyArrayVector,
|
|
92
|
+
magResponseOutVector,
|
|
93
|
+
phaseResponseOutVector);
|
|
94
|
+
|
|
95
|
+
for (size_t i = 0; i < magResponseOutVector.size(); i++) {
|
|
96
|
+
magResponseOut.setValueAtIndex(rt, i, magResponseOutVector[i]);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
for (size_t i = 0; i < phaseResponseOutVector.size(); i++) {
|
|
100
|
+
phaseResponseOut.setValueAtIndex(rt, i, phaseResponseOutVector[i]);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return jsi::Value::undefined();
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
63
107
|
return AudioNodeHostObject::get(runtime, propNameId);
|
|
64
108
|
}
|
|
65
109
|
|