diff --git a/packages/audiodocs/docs/sources/audio-buffer.mdx b/packages/audiodocs/docs/sources/audio-buffer.mdx
index 26efefb1f..b935da889 100644
--- a/packages/audiodocs/docs/sources/audio-buffer.mdx
+++ b/packages/audiodocs/docs/sources/audio-buffer.mdx
@@ -18,15 +18,15 @@ Once you have data in `AudioBuffer`, audio can be played by passing it to [`Audi
## Constructor
```tsx
-constructor(context: BaseAudioContext, options: AudioBufferOptions)
+constructor(options: AudioBufferOptions)
```
### `AudioBufferOptions`
| Parameter | Type | Default | Description |
| :---: | :---: | :----: | :---- |
-| `numberOfChannels` | `number` | 1.0 | Number of [`channels`](/docs/sources/audio-buffer#properties) in buffer |
| `length` | `number` | - | [`Length`](/docs/sources/audio-buffer#properties) of the buffer |
+| `numberOfChannels` | `number` | 1.0 | Number of [`channels`](/docs/sources/audio-buffer#properties) in buffer |
| `sampleRate` | `number` | - | [`Sample rate`](/docs/sources/audio-buffer#properties) of the buffer in Hz |
Or by using `BaseAudioContext` factory method:
diff --git a/packages/custom-node-generator/templates/basic/shared/MyProcessorNode.cpp b/packages/custom-node-generator/templates/basic/shared/MyProcessorNode.cpp
index 3aa07f407..b69d3986c 100644
--- a/packages/custom-node-generator/templates/basic/shared/MyProcessorNode.cpp
+++ b/packages/custom-node-generator/templates/basic/shared/MyProcessorNode.cpp
@@ -2,7 +2,7 @@
#include
namespace audioapi {
-MyProcessorNode::MyProcessorNode(BaseAudioContext *context)
+MyProcessorNode::MyProcessorNode(std::shared_ptr context)
: AudioNode(context) {
isInitialized_ = true;
}
diff --git a/packages/custom-node-generator/templates/basic/shared/MyProcessorNode.h b/packages/custom-node-generator/templates/basic/shared/MyProcessorNode.h
index e065ff359..1f339aaa0 100644
--- a/packages/custom-node-generator/templates/basic/shared/MyProcessorNode.h
+++ b/packages/custom-node-generator/templates/basic/shared/MyProcessorNode.h
@@ -6,7 +6,7 @@ class AudioBus;
class MyProcessorNode : public AudioNode {
public:
- explicit MyProcessorNode(BaseAudioContext *context);
+ explicit MyProcessorNode(std::shared_ptr context);
protected:
std::shared_ptr processNode(const std::shared_ptr &bus,
diff --git a/packages/react-native-audio-api/common/cpp/audioapi/AudioAPIModuleInstaller.h b/packages/react-native-audio-api/common/cpp/audioapi/AudioAPIModuleInstaller.h
index 116673979..fb2543d4d 100644
--- a/packages/react-native-audio-api/common/cpp/audioapi/AudioAPIModuleInstaller.h
+++ b/packages/react-native-audio-api/common/cpp/audioapi/AudioAPIModuleInstaller.h
@@ -3,11 +3,13 @@
#include
#include
#include
+#include
#include
#include
#include
#include
#include
+#include
#include
#include
@@ -36,6 +38,7 @@ class AudioAPIModuleInstaller {
getCreateAudioRecorderFunction(jsiRuntime, audioEventHandlerRegistry);
auto createOfflineAudioContext = getCreateOfflineAudioContextFunction(
jsiRuntime, jsCallInvoker, audioEventHandlerRegistry, uiRuntime);
+ auto createAudioBuffer = getCrateAudioBufferFunction(jsiRuntime);
auto createAudioDecoder = getCreateAudioDecoderFunction(jsiRuntime, jsCallInvoker);
auto createAudioStretcher = getCreateAudioStretcherFunction(jsiRuntime, jsCallInvoker);
@@ -43,6 +46,7 @@ class AudioAPIModuleInstaller {
jsiRuntime->global().setProperty(*jsiRuntime, "createAudioRecorder", createAudioRecorder);
jsiRuntime->global().setProperty(
*jsiRuntime, "createOfflineAudioContext", createOfflineAudioContext);
+ jsiRuntime->global().setProperty(*jsiRuntime, "createAudioBuffer", createAudioBuffer);
jsiRuntime->global().setProperty(*jsiRuntime, "createAudioDecoder", createAudioDecoder);
jsiRuntime->global().setProperty(*jsiRuntime, "createAudioStretcher", createAudioStretcher);
@@ -63,7 +67,7 @@ class AudioAPIModuleInstaller {
return jsi::Function::createFromHostFunction(
*jsiRuntime,
jsi::PropNameID::forAscii(*jsiRuntime, "createAudioContext"),
- 0,
+ 1,
[jsCallInvoker, audioEventHandlerRegistry, uiRuntime](
jsi::Runtime &runtime,
const jsi::Value &thisValue,
@@ -94,7 +98,7 @@ class AudioAPIModuleInstaller {
return jsi::Function::createFromHostFunction(
*jsiRuntime,
jsi::PropNameID::forAscii(*jsiRuntime, "createOfflineAudioContext"),
- 0,
+ 3,
[jsCallInvoker, audioEventHandlerRegistry, uiRuntime](
jsi::Runtime &runtime,
const jsi::Value &thisValue,
@@ -181,6 +185,23 @@ class AudioAPIModuleInstaller {
return jsi::Object::createFromHostObject(runtime, audioStretcherHostObject);
});
}
+
+ static jsi::Function getCrateAudioBufferFunction(jsi::Runtime *jsiRuntime) {
+ return jsi::Function::createFromHostFunction(
+ *jsiRuntime,
+ jsi::PropNameID::forAscii(*jsiRuntime, "createAudioStretcher"),
+ 3,
+ [](jsi::Runtime &runtime, const jsi::Value &thisValue, const jsi::Value *args, size_t count)
+ -> jsi::Value {
+ auto numberOfChannels = static_cast(args[0].getNumber());
+ auto length = static_cast(args[1].getNumber());
+ auto sampleRate = static_cast(args[2].getNumber());
+
+ auto audioBuffer = std::make_shared(numberOfChannels, length, sampleRate);
+ auto audioBufferHostObject = std::make_shared(audioBuffer);
+ return jsi::Object::createFromHostObject(runtime, audioBufferHostObject);
+ });
+ }
};
} // namespace audioapi
diff --git a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/AudioNodeHostObject.cpp b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/AudioNodeHostObject.cpp
index 7fea3115e..8976e9398 100644
--- a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/AudioNodeHostObject.cpp
+++ b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/AudioNodeHostObject.cpp
@@ -7,7 +7,8 @@
namespace audioapi {
-AudioNodeHostObject::AudioNodeHostObject(const std::shared_ptr &node) : node_(node) {
+AudioNodeHostObject::AudioNodeHostObject(const std::shared_ptr &node,
+ const AudioNodeOptions &options) : node_(node) {
addGetters(
JSI_EXPORT_PROPERTY_GETTER(AudioNodeHostObject, numberOfInputs),
JSI_EXPORT_PROPERTY_GETTER(AudioNodeHostObject, numberOfOutputs),
diff --git a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/AudioNodeHostObject.h b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/AudioNodeHostObject.h
index dfea4ab46..423f84b6d 100644
--- a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/AudioNodeHostObject.h
+++ b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/AudioNodeHostObject.h
@@ -1,6 +1,7 @@
#pragma once
#include
+#include
#include
#include
@@ -13,7 +14,9 @@ class AudioNode;
class AudioNodeHostObject : public JsiHostObject {
public:
- explicit AudioNodeHostObject(const std::shared_ptr &node);
+ explicit AudioNodeHostObject(
+ const std::shared_ptr &node,
+ const AudioNodeOptions &options = AudioNodeOptions());
~AudioNodeHostObject() override;
JSI_PROPERTY_GETTER_DECL(numberOfInputs);
diff --git a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.cpp b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.cpp
index aa9978d2a..9cb1d072f 100644
--- a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.cpp
+++ b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.cpp
@@ -60,7 +60,6 @@ BaseAudioContextHostObject::BaseAudioContextHostObject(
JSI_EXPORT_FUNCTION(BaseAudioContextHostObject, createIIRFilter),
JSI_EXPORT_FUNCTION(BaseAudioContextHostObject, createBufferSource),
JSI_EXPORT_FUNCTION(BaseAudioContextHostObject, createBufferQueueSource),
- JSI_EXPORT_FUNCTION(BaseAudioContextHostObject, createBuffer),
JSI_EXPORT_FUNCTION(BaseAudioContextHostObject, createPeriodicWave),
JSI_EXPORT_FUNCTION(BaseAudioContextHostObject, createConvolver),
JSI_EXPORT_FUNCTION(BaseAudioContextHostObject, createAnalyser),
@@ -260,19 +259,6 @@ JSI_HOST_FUNCTION_IMPL(BaseAudioContextHostObject, createBufferQueueSource) {
return jsi::Object::createFromHostObject(runtime, bufferStreamSourceHostObject);
}
-JSI_HOST_FUNCTION_IMPL(BaseAudioContextHostObject, createBuffer) {
- const auto options = args[0].asObject(runtime);
- const auto audioBufferOptions =
- audioapi::option_parser::parseAudioBufferOptions(runtime, options);
- auto buffer = BaseAudioContext::createBuffer(audioBufferOptions);
- auto bufferHostObject = std::make_shared(buffer);
-
- auto jsiObject = jsi::Object::createFromHostObject(runtime, bufferHostObject);
- jsiObject.setExternalMemoryPressure(runtime, bufferHostObject->getSizeInBytes());
-
- return jsiObject;
-}
-
JSI_HOST_FUNCTION_IMPL(BaseAudioContextHostObject, createPeriodicWave) {
auto arrayBufferReal =
args[0].getObject(runtime).getPropertyAsObject(runtime, "buffer").getArrayBuffer(runtime);
diff --git a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.h b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.h
index dc0ec18a5..6ccd1dc3d 100644
--- a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.h
+++ b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.h
@@ -42,7 +42,6 @@ class BaseAudioContextHostObject : public JsiHostObject {
JSI_HOST_FUNCTION_DECL(createIIRFilter);
JSI_HOST_FUNCTION_DECL(createBufferSource);
JSI_HOST_FUNCTION_DECL(createBufferQueueSource);
- JSI_HOST_FUNCTION_DECL(createBuffer);
JSI_HOST_FUNCTION_DECL(createPeriodicWave);
JSI_HOST_FUNCTION_DECL(createAnalyser);
JSI_HOST_FUNCTION_DECL(createConvolver);
diff --git a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/analysis/AnalyserNodeHostObject.cpp b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/analysis/AnalyserNodeHostObject.cpp
index 45b9be3e2..3edfd86ce 100644
--- a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/analysis/AnalyserNodeHostObject.cpp
+++ b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/analysis/AnalyserNodeHostObject.cpp
@@ -1,5 +1,5 @@
#include
-#include
+#include
#include
#include
#include
@@ -9,7 +9,7 @@
namespace audioapi {
AnalyserNodeHostObject::AnalyserNodeHostObject(const std::shared_ptr& context, const AnalyserOptions &options)
- : AudioNodeHostObject(context->createAnalyser(options)) {
+ : AudioNodeHostObject(context->createAnalyser(options), options) {
addGetters(
JSI_EXPORT_PROPERTY_GETTER(AnalyserNodeHostObject, fftSize),
JSI_EXPORT_PROPERTY_GETTER(AnalyserNodeHostObject, frequencyBinCount),
diff --git a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/destinations/AudioDestinationNodeHostObject.h b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/destinations/AudioDestinationNodeHostObject.h
index b3e4211cc..03c985261 100644
--- a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/destinations/AudioDestinationNodeHostObject.h
+++ b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/destinations/AudioDestinationNodeHostObject.h
@@ -2,6 +2,7 @@
#include
#include
+#include
#include
#include
@@ -12,6 +13,6 @@ using namespace facebook;
class AudioDestinationNodeHostObject : public AudioNodeHostObject {
public:
explicit AudioDestinationNodeHostObject(const std::shared_ptr &node)
- : AudioNodeHostObject(node) {}
+ : AudioNodeHostObject(node, AudioDestinationOptions()) {}
};
} // namespace audioapi
diff --git a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/effects/BiquadFilterNodeHostObject.cpp b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/effects/BiquadFilterNodeHostObject.cpp
index ced78f8c0..b2e785530 100644
--- a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/effects/BiquadFilterNodeHostObject.cpp
+++ b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/effects/BiquadFilterNodeHostObject.cpp
@@ -1,7 +1,7 @@
#include
#include
#include
-#include
+#include
#include
#include
#include
@@ -12,7 +12,7 @@ namespace audioapi {
BiquadFilterNodeHostObject::BiquadFilterNodeHostObject(const std::shared_ptr& context,
const BiquadFilterOptions &options)
- : AudioNodeHostObject(context->createBiquadFilter(options)) {
+ : AudioNodeHostObject(context->createBiquadFilter(options), options) {
addGetters(
JSI_EXPORT_PROPERTY_GETTER(BiquadFilterNodeHostObject, frequency),
JSI_EXPORT_PROPERTY_GETTER(BiquadFilterNodeHostObject, detune),
diff --git a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/effects/ConvolverNodeHostObject.cpp b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/effects/ConvolverNodeHostObject.cpp
index 42d9fbf8d..d6f72a4c2 100644
--- a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/effects/ConvolverNodeHostObject.cpp
+++ b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/effects/ConvolverNodeHostObject.cpp
@@ -1,6 +1,6 @@
#include
#include
-#include
+#include
#include
#include
@@ -9,7 +9,7 @@
namespace audioapi {
ConvolverNodeHostObject::ConvolverNodeHostObject(const std::shared_ptr& context, const ConvolverOptions &options)
- : AudioNodeHostObject(context->createConvolver(options)) {
+ : AudioNodeHostObject(context->createConvolver(options), options) {
addGetters(
JSI_EXPORT_PROPERTY_GETTER(ConvolverNodeHostObject, normalize),
JSI_EXPORT_PROPERTY_GETTER(ConvolverNodeHostObject, buffer));
diff --git a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/effects/DelayNodeHostObject.cpp b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/effects/DelayNodeHostObject.cpp
index 9035caca3..17929e069 100644
--- a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/effects/DelayNodeHostObject.cpp
+++ b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/effects/DelayNodeHostObject.cpp
@@ -2,14 +2,14 @@
#include
#include
#include
-#include
+#include
#include
namespace audioapi {
DelayNodeHostObject::DelayNodeHostObject(const std::shared_ptr& context, const DelayOptions &options)
- : AudioNodeHostObject(context->createDelay(options)) {
+ : AudioNodeHostObject(context->createDelay(options), options) {
addGetters(JSI_EXPORT_PROPERTY_GETTER(DelayNodeHostObject, delayTime));
}
diff --git a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/effects/GainNodeHostObject.cpp b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/effects/GainNodeHostObject.cpp
index 98c89de37..4f9c040ed 100644
--- a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/effects/GainNodeHostObject.cpp
+++ b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/effects/GainNodeHostObject.cpp
@@ -1,7 +1,7 @@
#include
#include
-#include
+#include
#include
#include
#include
@@ -11,7 +11,7 @@ namespace audioapi {
GainNodeHostObject::GainNodeHostObject(
const std::shared_ptr &context,
const GainOptions &options)
- : AudioNodeHostObject(context->createGain(options)) {
+ : AudioNodeHostObject(context->createGain(options), options) {
addGetters(JSI_EXPORT_PROPERTY_GETTER(GainNodeHostObject, gain));
}
diff --git a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/effects/IIRFilterNodeHostObject.cpp b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/effects/IIRFilterNodeHostObject.cpp
index 592457c70..e77cdfebc 100644
--- a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/effects/IIRFilterNodeHostObject.cpp
+++ b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/effects/IIRFilterNodeHostObject.cpp
@@ -1,5 +1,5 @@
#include
-#include
+#include
#include
#include
#include
@@ -9,7 +9,7 @@ namespace audioapi {
IIRFilterNodeHostObject::IIRFilterNodeHostObject(
const std::shared_ptr &context,
const IIRFilterOptions &options)
- : AudioNodeHostObject(context->createIIRFilter(options)) {
+ : AudioNodeHostObject(context->createIIRFilter(options), options) {
addFunctions(JSI_EXPORT_FUNCTION(IIRFilterNodeHostObject, getFrequencyResponse));
}
diff --git a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/effects/StereoPannerNodeHostObject.cpp b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/effects/StereoPannerNodeHostObject.cpp
index 1fbd45f72..5170659ef 100644
--- a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/effects/StereoPannerNodeHostObject.cpp
+++ b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/effects/StereoPannerNodeHostObject.cpp
@@ -1,7 +1,7 @@
#include
#include
-#include
+#include
#include
#include
#include
@@ -11,7 +11,7 @@ namespace audioapi {
StereoPannerNodeHostObject::StereoPannerNodeHostObject(
const std::shared_ptr &context,
const StereoPannerOptions &options)
- : AudioNodeHostObject(context->createStereoPanner(options)) {
+ : AudioNodeHostObject(context->createStereoPanner(options), options) {
addGetters(JSI_EXPORT_PROPERTY_GETTER(StereoPannerNodeHostObject, pan));
}
diff --git a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/effects/WaveShaperNodeHostObject.cpp b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/effects/WaveShaperNodeHostObject.cpp
index 1550e9b72..f1351cdcf 100644
--- a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/effects/WaveShaperNodeHostObject.cpp
+++ b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/effects/WaveShaperNodeHostObject.cpp
@@ -1,6 +1,6 @@
#include
#include
-#include
+#include
#include
#include
#include
@@ -13,7 +13,7 @@ namespace audioapi {
WaveShaperNodeHostObject::WaveShaperNodeHostObject(
const std::shared_ptr &context,
const WaveShaperOptions &options)
- : AudioNodeHostObject(context->createWaveShaper(options)) {
+ : AudioNodeHostObject(context->createWaveShaper(options), options) {
addGetters(
JSI_EXPORT_PROPERTY_GETTER(WaveShaperNodeHostObject, oversample),
JSI_EXPORT_PROPERTY_GETTER(WaveShaperNodeHostObject, curve));
diff --git a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/AudioBufferBaseSourceNodeHostObject.cpp b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/AudioBufferBaseSourceNodeHostObject.cpp
index d7152ffa8..9f503d682 100644
--- a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/AudioBufferBaseSourceNodeHostObject.cpp
+++ b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/AudioBufferBaseSourceNodeHostObject.cpp
@@ -2,13 +2,15 @@
#include
#include
+#include
#include
namespace audioapi {
AudioBufferBaseSourceNodeHostObject::AudioBufferBaseSourceNodeHostObject(
- const std::shared_ptr &node)
- : AudioScheduledSourceNodeHostObject(node) {
+ const std::shared_ptr &node,
+ const BaseAudioBufferSourceOptions &options)
+ : AudioScheduledSourceNodeHostObject(node, options) {
addGetters(
JSI_EXPORT_PROPERTY_GETTER(AudioBufferBaseSourceNodeHostObject, detune),
JSI_EXPORT_PROPERTY_GETTER(AudioBufferBaseSourceNodeHostObject, playbackRate),
diff --git a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/AudioBufferBaseSourceNodeHostObject.h b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/AudioBufferBaseSourceNodeHostObject.h
index 60ee74d90..f65c39a14 100644
--- a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/AudioBufferBaseSourceNodeHostObject.h
+++ b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/AudioBufferBaseSourceNodeHostObject.h
@@ -9,11 +9,13 @@ namespace audioapi {
using namespace facebook;
class AudioBufferBaseSourceNode;
+struct BaseAudioBufferSourceOptions;
class AudioBufferBaseSourceNodeHostObject : public AudioScheduledSourceNodeHostObject {
public:
explicit AudioBufferBaseSourceNodeHostObject(
- const std::shared_ptr &node);
+ const std::shared_ptr &node,
+ const BaseAudioBufferSourceOptions &options);
~AudioBufferBaseSourceNodeHostObject() override;
diff --git a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/AudioBufferQueueSourceNodeHostObject.cpp b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/AudioBufferQueueSourceNodeHostObject.cpp
index 3705cb43b..f5996753c 100644
--- a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/AudioBufferQueueSourceNodeHostObject.cpp
+++ b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/AudioBufferQueueSourceNodeHostObject.cpp
@@ -1,7 +1,7 @@
#include
#include
-#include
+#include
#include
#include
#include
@@ -11,7 +11,7 @@ namespace audioapi {
AudioBufferQueueSourceNodeHostObject::AudioBufferQueueSourceNodeHostObject(
const std::shared_ptr &context,
const BaseAudioBufferSourceOptions &options)
- : AudioBufferBaseSourceNodeHostObject(context->createBufferQueueSource(options)) {
+ : AudioBufferBaseSourceNodeHostObject(context->createBufferQueueSource(options), options) {
functions_->erase("start");
addSetters(JSI_EXPORT_PROPERTY_SETTER(AudioBufferQueueSourceNodeHostObject, onBufferEnded));
diff --git a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/AudioBufferSourceNodeHostObject.cpp b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/AudioBufferSourceNodeHostObject.cpp
index faadb9da8..ac23adb1d 100644
--- a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/AudioBufferSourceNodeHostObject.cpp
+++ b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/AudioBufferSourceNodeHostObject.cpp
@@ -1,7 +1,7 @@
#include
#include
-#include
+#include
#include
#include
#include
@@ -11,7 +11,7 @@ namespace audioapi {
AudioBufferSourceNodeHostObject::AudioBufferSourceNodeHostObject(
const std::shared_ptr &context,
const AudioBufferSourceOptions &options)
- : AudioBufferBaseSourceNodeHostObject(context->createBufferSource(options)) {
+ : AudioBufferBaseSourceNodeHostObject(context->createBufferSource(options), options) {
addGetters(
JSI_EXPORT_PROPERTY_GETTER(AudioBufferSourceNodeHostObject, loop),
JSI_EXPORT_PROPERTY_GETTER(AudioBufferSourceNodeHostObject, loopSkip),
diff --git a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/AudioScheduledSourceNodeHostObject.cpp b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/AudioScheduledSourceNodeHostObject.cpp
index dc3542710..0f6c06c38 100644
--- a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/AudioScheduledSourceNodeHostObject.cpp
+++ b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/AudioScheduledSourceNodeHostObject.cpp
@@ -1,12 +1,14 @@
#include
-
#include
+#include
+
#include
namespace audioapi {
AudioScheduledSourceNodeHostObject::AudioScheduledSourceNodeHostObject(
- const std::shared_ptr &node)
+ const std::shared_ptr &node,
+ const AudioScheduledSourceNodeOptions &options)
: AudioNodeHostObject(node) {
addSetters(JSI_EXPORT_PROPERTY_SETTER(AudioScheduledSourceNodeHostObject, onEnded));
diff --git a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/AudioScheduledSourceNodeHostObject.h b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/AudioScheduledSourceNodeHostObject.h
index 8b9c3c101..f80caf5b6 100644
--- a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/AudioScheduledSourceNodeHostObject.h
+++ b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/AudioScheduledSourceNodeHostObject.h
@@ -1,6 +1,7 @@
#pragma once
#include
+#include
#include
#include
@@ -13,7 +14,8 @@ class AudioScheduledSourceNode;
class AudioScheduledSourceNodeHostObject : public AudioNodeHostObject {
public:
explicit AudioScheduledSourceNodeHostObject(
- const std::shared_ptr &node);
+ const std::shared_ptr &node,
+ const AudioScheduledSourceNodeOptions &options = AudioScheduledSourceNodeOptions());
~AudioScheduledSourceNodeHostObject() override;
diff --git a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/ConstantSourceNodeHostObject.cpp b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/ConstantSourceNodeHostObject.cpp
index d8d13cd4a..57ec5e828 100644
--- a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/ConstantSourceNodeHostObject.cpp
+++ b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/ConstantSourceNodeHostObject.cpp
@@ -1,6 +1,6 @@
#include
#include
-#include
+#include
#include
#include
#include
@@ -10,7 +10,7 @@ namespace audioapi {
ConstantSourceNodeHostObject::ConstantSourceNodeHostObject(
const std::shared_ptr &context,
const ConstantSourceOptions &options)
- : AudioScheduledSourceNodeHostObject(context->createConstantSource(options)) {
+ : AudioScheduledSourceNodeHostObject(context->createConstantSource(options), options) {
addGetters(JSI_EXPORT_PROPERTY_GETTER(ConstantSourceNodeHostObject, offset));
}
diff --git a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/OscillatorNodeHostObject.cpp b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/OscillatorNodeHostObject.cpp
index 85641fb33..0dfd11326 100644
--- a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/OscillatorNodeHostObject.cpp
+++ b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/OscillatorNodeHostObject.cpp
@@ -3,7 +3,7 @@
#include
#include
#include
-#include
+#include
#include
#include
#include
@@ -13,7 +13,7 @@ namespace audioapi {
OscillatorNodeHostObject::OscillatorNodeHostObject(
const std::shared_ptr &context,
const OscillatorOptions &options)
- : AudioScheduledSourceNodeHostObject(context->createOscillator(options)) {
+ : AudioScheduledSourceNodeHostObject(context->createOscillator(options), options) {
addGetters(
JSI_EXPORT_PROPERTY_GETTER(OscillatorNodeHostObject, frequency),
JSI_EXPORT_PROPERTY_GETTER(OscillatorNodeHostObject, detune),
diff --git a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/StreamerNodeHostObject.cpp b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/StreamerNodeHostObject.cpp
index f9dbef6f5..90ca56353 100644
--- a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/StreamerNodeHostObject.cpp
+++ b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/StreamerNodeHostObject.cpp
@@ -2,7 +2,7 @@
#include
#include
-#include
+#include
#include
#include
#include
@@ -12,7 +12,7 @@ namespace audioapi {
StreamerNodeHostObject::StreamerNodeHostObject(
const std::shared_ptr &context,
const StreamerOptions &options)
- : AudioScheduledSourceNodeHostObject(context->createStreamer(options)) {
+ : AudioScheduledSourceNodeHostObject(context->createStreamer(options), options) {
addFunctions(JSI_EXPORT_FUNCTION(StreamerNodeHostObject, initialize));
addGetters(JSI_EXPORT_PROPERTY_GETTER(StreamerNodeHostObject, streamPath));
}
diff --git a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/utils/NodeOptions.h b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/utils/NodeOptions.h
deleted file mode 100644
index b3fcd250c..000000000
--- a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/utils/NodeOptions.h
+++ /dev/null
@@ -1,111 +0,0 @@
-#pragma once
-
-#include
-#include
-#include
-#include
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-namespace audioapi {
-struct AudioNodeOptions {
- int channelCount = 2;
- ChannelCountMode channelCountMode;
- ChannelInterpretation channelInterpretation;
-};
-
-struct GainOptions : AudioNodeOptions {
- float gain;
-};
-
-struct StereoPannerOptions : AudioNodeOptions {
- float pan;
-};
-
-struct ConvolverOptions : AudioNodeOptions {
- std::shared_ptr bus;
- bool disableNormalization;
-};
-
-struct ConstantSourceOptions {
- float offset;
-};
-
-struct AnalyserOptions : AudioNodeOptions {
- int fftSize;
- float minDecibels;
- float maxDecibels;
- float smoothingTimeConstant;
-};
-
-struct BiquadFilterOptions : AudioNodeOptions {
- BiquadFilterType type;
- float frequency;
- float detune;
- float Q;
- float gain;
-};
-
-struct OscillatorOptions {
- std::shared_ptr periodicWave;
- float frequency;
- float detune;
- OscillatorType type;
-};
-
-struct BaseAudioBufferSourceOptions {
- float detune;
- bool pitchCorrection;
- float playbackRate;
-};
-
-struct AudioBufferSourceOptions : BaseAudioBufferSourceOptions {
- std::shared_ptr buffer;
- bool loop;
- float loopStart;
- float loopEnd;
-};
-
-struct StreamerOptions {
- std::string streamPath;
-};
-
-struct AudioBufferOptions {
- int numberOfChannels;
- size_t length;
- float sampleRate;
-};
-
-struct DelayOptions : AudioNodeOptions {
- float maxDelayTime;
- float delayTime;
-};
-
-struct IIRFilterOptions : AudioNodeOptions {
- std::vector feedforward;
- std::vector feedback;
-
- IIRFilterOptions() = default;
-
- explicit IIRFilterOptions(const AudioNodeOptions options) : AudioNodeOptions(options) {}
-
- IIRFilterOptions(const std::vector &ff, const std::vector &fb)
- : feedforward(ff), feedback(fb) {}
-
- IIRFilterOptions(std::vector &&ff, std::vector &&fb)
- : feedforward(std::move(ff)), feedback(std::move(fb)) {}
-};
-
-struct WaveShaperOptions : AudioNodeOptions {
- std::shared_ptr curve;
- OverSampleType oversample;
-};
-
-} // namespace audioapi
diff --git a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/utils/NodeOptionsParser.h b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/utils/NodeOptionsParser.h
index ede0e4a94..d98b386fe 100644
--- a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/utils/NodeOptionsParser.h
+++ b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/utils/NodeOptionsParser.h
@@ -9,33 +9,37 @@
#include
#include
-#include
+#include
namespace audioapi::option_parser {
AudioNodeOptions parseAudioNodeOptions(jsi::Runtime &runtime, const jsi::Object &optionsObject) {
AudioNodeOptions options;
- options.channelCount =
- static_cast(optionsObject.getProperty(runtime, "channelCount").getNumber());
-
- auto channelCountModeStr =
- optionsObject.getProperty(runtime, "channelCountMode").asString(runtime).utf8(runtime);
-
- if (channelCountModeStr == "max") {
- options.channelCountMode = ChannelCountMode::MAX;
- } else if (channelCountModeStr == "clamped-max") {
- options.channelCountMode = ChannelCountMode::CLAMPED_MAX;
- } else if (channelCountModeStr == "explicit") {
- options.channelCountMode = ChannelCountMode::EXPLICIT;
+ auto channelCountValue = optionsObject.getProperty(runtime, "channelCount");
+ if (channelCountValue.isNumber()) {
+ options.channelCount = static_cast(channelCountValue.getNumber());
}
- auto channelInterpretationStr =
- optionsObject.getProperty(runtime, "channelInterpretation").asString(runtime).utf8(runtime);
+ auto channelCountModeValue = optionsObject.getProperty(runtime, "channelCountMode");
+ if (channelCountModeValue.isString()) {
+ auto channelCountModeStr = channelCountModeValue.asString(runtime).utf8(runtime);
+ if (channelCountModeStr == "max") {
+ options.channelCountMode = ChannelCountMode::MAX;
+ } else if (channelCountModeStr == "clamped-max") {
+ options.channelCountMode = ChannelCountMode::CLAMPED_MAX;
+ } else if (channelCountModeStr == "explicit") {
+ options.channelCountMode = ChannelCountMode::EXPLICIT;
+ }
+ }
- if (channelInterpretationStr == "speakers") {
- options.channelInterpretation = ChannelInterpretation::SPEAKERS;
- } else if (channelInterpretationStr == "discrete") {
- options.channelInterpretation = ChannelInterpretation::DISCRETE;
+ auto channelInterpretationValue = optionsObject.getProperty(runtime, "channelInterpretation");
+ if (channelInterpretationValue.isString()) {
+ auto channelInterpretationStr = channelInterpretationValue.asString(runtime).utf8(runtime);
+ if (channelInterpretationStr == "speakers") {
+ options.channelInterpretation = ChannelInterpretation::SPEAKERS;
+ } else if (channelInterpretationStr == "discrete") {
+ options.channelInterpretation = ChannelInterpretation::DISCRETE;
+ }
}
return options;
@@ -43,7 +47,12 @@ AudioNodeOptions parseAudioNodeOptions(jsi::Runtime &runtime, const jsi::Object
GainOptions parseGainOptions(jsi::Runtime &runtime, const jsi::Object &optionsObject) {
GainOptions options(parseAudioNodeOptions(runtime, optionsObject));
- options.gain = static_cast(optionsObject.getProperty(runtime, "gain").getNumber());
+
+ auto gainValue = optionsObject.getProperty(runtime, "gain");
+ if (gainValue.isNumber()) {
+ options.gain = static_cast(gainValue.getNumber());
+ }
+
return options;
}
@@ -51,14 +60,23 @@ StereoPannerOptions parseStereoPannerOptions(
jsi::Runtime &runtime,
const jsi::Object &optionsObject) {
StereoPannerOptions options(parseAudioNodeOptions(runtime, optionsObject));
- options.pan = static_cast(optionsObject.getProperty(runtime, "pan").getNumber());
+
+ auto panValue = optionsObject.getProperty(runtime, "pan");
+ if (panValue.isNumber()) {
+ options.pan = static_cast(panValue.getNumber());
+ }
+
return options;
}
ConvolverOptions parseConvolverOptions(jsi::Runtime &runtime, const jsi::Object &optionsObject) {
ConvolverOptions options(parseAudioNodeOptions(runtime, optionsObject));
- options.disableNormalization =
- optionsObject.getProperty(runtime, "disableNormalization").getBool();
+
+ auto disableNormalizationValue = optionsObject.getProperty(runtime, "disableNormalization");
+ if (disableNormalizationValue.isBool()) {
+ options.disableNormalization = disableNormalizationValue.getBool();
+ }
+
if (optionsObject.hasProperty(runtime, "buffer")) {
auto bufferHostObject = optionsObject.getProperty(runtime, "buffer")
.getObject(runtime)
@@ -72,19 +90,38 @@ ConstantSourceOptions parseConstantSourceOptions(
jsi::Runtime &runtime,
const jsi::Object &optionsObject) {
ConstantSourceOptions options;
- options.offset = static_cast(optionsObject.getProperty(runtime, "offset").getNumber());
+
+ auto offsetValue = optionsObject.getProperty(runtime, "offset");
+ if (offsetValue.isNumber()) {
+ options.offset = static_cast(offsetValue.getNumber());
+ }
+
return options;
}
AnalyserOptions parseAnalyserOptions(jsi::Runtime &runtime, const jsi::Object &optionsObject) {
AnalyserOptions options(parseAudioNodeOptions(runtime, optionsObject));
- options.fftSize = static_cast(optionsObject.getProperty(runtime, "fftSize").getNumber());
- options.minDecibels =
- static_cast(optionsObject.getProperty(runtime, "minDecibels").getNumber());
- options.maxDecibels =
- static_cast(optionsObject.getProperty(runtime, "maxDecibels").getNumber());
- options.smoothingTimeConstant =
- static_cast(optionsObject.getProperty(runtime, "smoothingTimeConstant").getNumber());
+
+ auto fftSizeValue = optionsObject.getProperty(runtime, "fftSize");
+ if (fftSizeValue.isNumber()) {
+ options.fftSize = static_cast(fftSizeValue.getNumber());
+ }
+
+ auto minDecibelsValue = optionsObject.getProperty(runtime, "minDecibels");
+ if (minDecibelsValue.isNumber()) {
+ options.minDecibels = static_cast(minDecibelsValue.getNumber());
+ }
+
+ auto maxDecibelsValue = optionsObject.getProperty(runtime, "maxDecibels");
+ if (maxDecibelsValue.isNumber()) {
+ options.maxDecibels = static_cast(maxDecibelsValue.getNumber());
+ }
+
+ auto smoothingTimeConstantValue = optionsObject.getProperty(runtime, "smoothingTimeConstant");
+ if (smoothingTimeConstantValue.isNumber()) {
+ options.smoothingTimeConstant = static_cast(smoothingTimeConstantValue.getNumber());
+ }
+
return options;
}
@@ -93,31 +130,47 @@ BiquadFilterOptions parseBiquadFilterOptions(
const jsi::Object &optionsObject) {
BiquadFilterOptions options(parseAudioNodeOptions(runtime, optionsObject));
- auto typeStr = optionsObject.getProperty(runtime, "type").asString(runtime).utf8(runtime);
-
- if (typeStr == "lowpass") {
- options.type = BiquadFilterType::LOWPASS;
- } else if (typeStr == "highpass") {
- options.type = BiquadFilterType::HIGHPASS;
- } else if (typeStr == "bandpass") {
- options.type = BiquadFilterType::BANDPASS;
- } else if (typeStr == "lowshelf") {
- options.type = BiquadFilterType::LOWSHELF;
- } else if (typeStr == "highshelf") {
- options.type = BiquadFilterType::HIGHSHELF;
- } else if (typeStr == "peaking") {
- options.type = BiquadFilterType::PEAKING;
- } else if (typeStr == "notch") {
- options.type = BiquadFilterType::NOTCH;
- } else if (typeStr == "allpass") {
- options.type = BiquadFilterType::ALLPASS;
- }
-
- options.frequency =
- static_cast(optionsObject.getProperty(runtime, "frequency").getNumber());
- options.detune = static_cast(optionsObject.getProperty(runtime, "detune").getNumber());
- options.Q = static_cast(optionsObject.getProperty(runtime, "Q").getNumber());
- options.gain = static_cast(optionsObject.getProperty(runtime, "gain").getNumber());
+ auto typeValue = optionsObject.getProperty(runtime, "type");
+ if (typeValue.isString()) {
+ auto typeStr = typeValue.asString(runtime).utf8(runtime);
+ if (typeStr == "lowpass") {
+ options.type = BiquadFilterType::LOWPASS;
+ } else if (typeStr == "highpass") {
+ options.type = BiquadFilterType::HIGHPASS;
+ } else if (typeStr == "bandpass") {
+ options.type = BiquadFilterType::BANDPASS;
+ } else if (typeStr == "lowshelf") {
+ options.type = BiquadFilterType::LOWSHELF;
+ } else if (typeStr == "highshelf") {
+ options.type = BiquadFilterType::HIGHSHELF;
+ } else if (typeStr == "peaking") {
+ options.type = BiquadFilterType::PEAKING;
+ } else if (typeStr == "notch") {
+ options.type = BiquadFilterType::NOTCH;
+ } else if (typeStr == "allpass") {
+ options.type = BiquadFilterType::ALLPASS;
+ }
+ }
+
+ auto frequencyValue = optionsObject.getProperty(runtime, "frequency");
+ if (frequencyValue.isNumber()) {
+ options.frequency = static_cast(frequencyValue.getNumber());
+ }
+
+ auto detuneValue = optionsObject.getProperty(runtime, "detune");
+ if (detuneValue.isNumber()) {
+ options.detune = static_cast(detuneValue.getNumber());
+ }
+
+ auto QValue = optionsObject.getProperty(runtime, "Q");
+ if (QValue.isNumber()) {
+ options.Q = static_cast(QValue.getNumber());
+ }
+
+ auto gainValue = optionsObject.getProperty(runtime, "gain");
+ if (gainValue.isNumber()) {
+ options.gain = static_cast(gainValue.getNumber());
+ }
return options;
}
@@ -125,28 +178,36 @@ BiquadFilterOptions parseBiquadFilterOptions(
OscillatorOptions parseOscillatorOptions(jsi::Runtime &runtime, const jsi::Object &optionsObject) {
OscillatorOptions options;
- auto typeStr = optionsObject.getProperty(runtime, "type").asString(runtime).utf8(runtime);
+ auto typeValue = optionsObject.getProperty(runtime, "type");
+ if (typeValue.isString()) {
+ auto typeStr = typeValue.asString(runtime).utf8(runtime);
+ if (typeStr == "sine") {
+ options.type = OscillatorType::SINE;
+ } else if (typeStr == "square") {
+ options.type = OscillatorType::SQUARE;
+ } else if (typeStr == "sawtooth") {
+ options.type = OscillatorType::SAWTOOTH;
+ } else if (typeStr == "triangle") {
+ options.type = OscillatorType::TRIANGLE;
+ } else if (typeStr == "custom") {
+ options.type = OscillatorType::CUSTOM;
+ }
+ }
- if (typeStr == "sine") {
- options.type = OscillatorType::SINE;
- } else if (typeStr == "square") {
- options.type = OscillatorType::SQUARE;
- } else if (typeStr == "sawtooth") {
- options.type = OscillatorType::SAWTOOTH;
- } else if (typeStr == "triangle") {
- options.type = OscillatorType::TRIANGLE;
- } else if (typeStr == "custom") {
- options.type = OscillatorType::CUSTOM;
+ auto frequencyValue = optionsObject.getProperty(runtime, "frequency");
+ if (frequencyValue.isNumber()) {
+ options.frequency = static_cast(frequencyValue.getNumber());
}
- options.frequency =
- static_cast(optionsObject.getProperty(runtime, "frequency").getNumber());
- options.detune = static_cast(optionsObject.getProperty(runtime, "detune").getNumber());
+ auto detuneValue = optionsObject.getProperty(runtime, "detune");
+ if (detuneValue.isNumber()) {
+ options.detune = static_cast(detuneValue.getNumber());
+ }
- if (optionsObject.hasProperty(runtime, "periodicWave")) {
- auto periodicWaveHostObject = optionsObject.getProperty(runtime, "periodicWave")
- .getObject(runtime)
- .asHostObject(runtime);
+ auto periodicWaveValue = optionsObject.getProperty(runtime, "periodicWave");
+ if (periodicWaveValue.isObject()) {
+ auto periodicWaveHostObject =
+ periodicWaveValue.getObject(runtime).asHostObject(runtime);
options.periodicWave = periodicWaveHostObject->periodicWave_;
}
@@ -157,11 +218,22 @@ BaseAudioBufferSourceOptions parseBaseAudioBufferSourceOptions(
jsi::Runtime &runtime,
const jsi::Object &optionsObject) {
BaseAudioBufferSourceOptions options;
- options.detune = static_cast(optionsObject.getProperty(runtime, "detune").getNumber());
- options.playbackRate =
- static_cast(optionsObject.getProperty(runtime, "playbackRate").getNumber());
- options.pitchCorrection =
- static_cast(optionsObject.getProperty(runtime, "pitchCorrection").getBool());
+
+ auto detuneValue = optionsObject.getProperty(runtime, "detune");
+ if (detuneValue.isNumber()) {
+ options.detune = static_cast(detuneValue.getNumber());
+ }
+
+ auto playbackRateValue = optionsObject.getProperty(runtime, "playbackRate");
+ if (playbackRateValue.isNumber()) {
+ options.playbackRate = static_cast(playbackRateValue.getNumber());
+ }
+
+ auto pitchCorrectionValue = optionsObject.getProperty(runtime, "pitchCorrection");
+ if (pitchCorrectionValue.isBool()) {
+ options.pitchCorrection = static_cast(pitchCorrectionValue.getBool());
+ }
+
return options;
}
@@ -169,16 +241,29 @@ AudioBufferSourceOptions parseAudioBufferSourceOptions(
jsi::Runtime &runtime,
const jsi::Object &optionsObject) {
AudioBufferSourceOptions options(parseBaseAudioBufferSourceOptions(runtime, optionsObject));
+
if (optionsObject.hasProperty(runtime, "buffer")) {
auto bufferHostObject = optionsObject.getProperty(runtime, "buffer")
.getObject(runtime)
.asHostObject(runtime);
options.buffer = bufferHostObject->audioBuffer_;
}
- options.loop = static_cast(optionsObject.getProperty(runtime, "loop").getBool());
- options.loopStart =
- static_cast(optionsObject.getProperty(runtime, "loopStart").getNumber());
- options.loopEnd = static_cast(optionsObject.getProperty(runtime, "loopEnd").getNumber());
+
+ auto loopValue = optionsObject.getProperty(runtime, "loop");
+ if (loopValue.isBool()) {
+ options.loop = static_cast(loopValue.getBool());
+ }
+
+ auto loopStartValue = optionsObject.getProperty(runtime, "loopStart");
+ if (loopStartValue.isNumber()) {
+ options.loopStart = static_cast(loopStartValue.getNumber());
+ }
+
+ auto loopEndValue = optionsObject.getProperty(runtime, "loopEnd");
+ if (loopEndValue.isNumber()) {
+ options.loopEnd = static_cast(loopEndValue.getNumber());
+ }
+
return options;
}
@@ -191,46 +276,45 @@ StreamerOptions parseStreamerOptions(jsi::Runtime &runtime, const jsi::Object &o
return options;
}
-AudioBufferOptions parseAudioBufferOptions(
- jsi::Runtime &runtime,
- const jsi::Object &optionsObject) {
- AudioBufferOptions options;
- options.numberOfChannels =
- static_cast(optionsObject.getProperty(runtime, "numberOfChannels").getNumber());
- options.length = static_cast(optionsObject.getProperty(runtime, "length").getNumber());
- options.sampleRate =
- static_cast(optionsObject.getProperty(runtime, "sampleRate").getNumber());
- return options;
-}
-
DelayOptions parseDelayOptions(jsi::Runtime &runtime, const jsi::Object &optionsObject) {
DelayOptions options(parseAudioNodeOptions(runtime, optionsObject));
- options.maxDelayTime =
- static_cast(optionsObject.getProperty(runtime, "maxDelayTime").getNumber());
- options.delayTime =
- static_cast(optionsObject.getProperty(runtime, "delayTime").getNumber());
+
+ auto maxDelayTimeValue = optionsObject.getProperty(runtime, "maxDelayTime");
+ if (maxDelayTimeValue.isNumber()) {
+ options.maxDelayTime = static_cast(maxDelayTimeValue.getNumber());
+ }
+
+ auto delayTimeValue = optionsObject.getProperty(runtime, "delayTime");
+ if (delayTimeValue.isNumber()) {
+ options.delayTime = static_cast(delayTimeValue.getNumber());
+ }
+
return options;
}
IIRFilterOptions parseIIRFilterOptions(jsi::Runtime &runtime, const jsi::Object &optionsObject) {
IIRFilterOptions options(parseAudioNodeOptions(runtime, optionsObject));
- auto feedforwardArray =
- optionsObject.getProperty(runtime, "feedforward").asObject(runtime).asArray(runtime);
- size_t feedforwardLength = feedforwardArray.size(runtime);
- options.feedforward.reserve(feedforwardLength);
- for (size_t i = 0; i < feedforwardLength; ++i) {
- options.feedforward.push_back(
- static_cast(feedforwardArray.getValueAtIndex(runtime, i).getNumber()));
+ auto feedforwardValue = optionsObject.getProperty(runtime, "feedforward");
+ if (feedforwardValue.isObject()) {
+ auto feedforwardArray = feedforwardValue.asObject(runtime).asArray(runtime);
+ size_t feedforwardLength = feedforwardArray.size(runtime);
+ options.feedforward.reserve(feedforwardLength);
+ for (size_t i = 0; i < feedforwardLength; ++i) {
+ options.feedforward.push_back(
+ static_cast(feedforwardArray.getValueAtIndex(runtime, i).getNumber()));
+ }
}
- auto feedbackArray =
- optionsObject.getProperty(runtime, "feedback").asObject(runtime).asArray(runtime);
- size_t feedbackLength = feedbackArray.size(runtime);
- options.feedback.reserve(feedbackLength);
- for (size_t i = 0; i < feedbackLength; ++i) {
- options.feedback.push_back(
- static_cast(feedbackArray.getValueAtIndex(runtime, i).getNumber()));
+ auto feedbackValue = optionsObject.getProperty(runtime, "feedback");
+ if (feedbackValue.isObject()) {
+ auto feedbackArray = feedbackValue.asObject(runtime).asArray(runtime);
+ size_t feedbackLength = feedbackArray.size(runtime);
+ options.feedback.reserve(feedbackLength);
+ for (size_t i = 0; i < feedbackLength; ++i) {
+ options.feedback.push_back(
+ static_cast(feedbackArray.getValueAtIndex(runtime, i).getNumber()));
+ }
}
return options;
@@ -239,15 +323,16 @@ IIRFilterOptions parseIIRFilterOptions(jsi::Runtime &runtime, const jsi::Object
WaveShaperOptions parseWaveShaperOptions(jsi::Runtime &runtime, const jsi::Object &optionsObject) {
WaveShaperOptions options(parseAudioNodeOptions(runtime, optionsObject));
- auto oversampleStr =
- optionsObject.getProperty(runtime, "oversample").asString(runtime).utf8(runtime);
-
- if (oversampleStr == "none") {
- options.oversample = OverSampleType::OVERSAMPLE_NONE;
- } else if (oversampleStr == "2x") {
- options.oversample = OverSampleType::OVERSAMPLE_2X;
- } else if (oversampleStr == "4x") {
- options.oversample = OverSampleType::OVERSAMPLE_4X;
+ auto oversampleValue = optionsObject.getProperty(runtime, "oversample");
+ if (oversampleValue.isString()) {
+ auto oversampleStr = oversampleValue.asString(runtime).utf8(runtime);
+ if (oversampleStr == "none") {
+ options.oversample = OverSampleType::OVERSAMPLE_NONE;
+ } else if (oversampleStr == "2x") {
+ options.oversample = OverSampleType::OVERSAMPLE_2X;
+ } else if (oversampleStr == "4x") {
+ options.oversample = OverSampleType::OVERSAMPLE_4X;
+ }
}
if (optionsObject.hasProperty(runtime, "buffer")) {
diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/AudioNode.cpp b/packages/react-native-audio-api/common/cpp/audioapi/core/AudioNode.cpp
index e8cd1503e..7a7a8e7c9 100644
--- a/packages/react-native-audio-api/common/cpp/audioapi/core/AudioNode.cpp
+++ b/packages/react-native-audio-api/common/cpp/audioapi/core/AudioNode.cpp
@@ -1,4 +1,4 @@
-#include
+#include
#include
#include
#include
@@ -11,15 +11,13 @@
namespace audioapi {
-AudioNode::AudioNode(const std::shared_ptr& context) : context_(context) {
- audioBus_ =
- std::make_shared(RENDER_QUANTUM_SIZE, channelCount_, context->getSampleRate());
-}
-
AudioNode::AudioNode(
const std::shared_ptr &context,
const AudioNodeOptions &options)
: context_(context),
+ numberOfInputs_(options.numberOfInputs),
+ numberOfOutputs_(options.numberOfOutputs),
+ requiresTailProcessing_(options.requiresTailProcessing),
channelCount_(options.channelCount),
channelCountMode_(options.channelCountMode),
channelInterpretation_(options.channelInterpretation) {
diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/AudioNode.h b/packages/react-native-audio-api/common/cpp/audioapi/core/AudioNode.h
index 8a52f15c3..58cfe64d9 100644
--- a/packages/react-native-audio-api/common/cpp/audioapi/core/AudioNode.h
+++ b/packages/react-native-audio-api/common/cpp/audioapi/core/AudioNode.h
@@ -3,6 +3,7 @@
#include
#include
#include
+#include
#include
#include
@@ -16,14 +17,12 @@ namespace audioapi {
class AudioBus;
class BaseAudioContext;
class AudioParam;
-struct AudioNodeOptions;
class AudioNode : public std::enable_shared_from_this {
public:
- explicit AudioNode(const std::shared_ptr