Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
d74dee6
feat: gain impl
mdydek Nov 13, 2025
62ae75f
feat: better consistency
mdydek Nov 13, 2025
5790ce5
docs: docs proposition
mdydek Nov 14, 2025
4fd5487
feat: stereo panner options
mdydek Nov 16, 2025
5d7cc69
feat: added web
mdydek Nov 16, 2025
add1958
feat: convolver options
mdydek Nov 16, 2025
022683b
test: tests
mdydek Nov 17, 2025
0a539d1
feat: constant source options
mdydek Nov 17, 2025
a90f428
Merge branch 'main' into feat/audio-node-options-in-ctor
mdydek Nov 18, 2025
a052c45
feat: web for convolver
mdydek Nov 18, 2025
a47447b
feat: periodic wave
mdydek Nov 19, 2025
1aa6443
feat: analyser node
mdydek Nov 19, 2025
3b0b1b7
feat: biquad filter
mdydek Nov 19, 2025
1dcdaa6
feat: oscillator
mdydek Nov 20, 2025
1f62ba8
feat: mobile audio buffer sources
mdydek Nov 24, 2025
f80292a
feat: streamer node options
mdydek Nov 26, 2025
67df87d
feat: recorder adapter
mdydek Nov 26, 2025
617188a
feat: worklets
mdydek Dec 2, 2025
0a6f8d8
feat: audiobuffer
mdydek Dec 2, 2025
f074c12
feat: audiobuffer on web
mdydek Dec 2, 2025
4617720
docs: documentation for new constructors
mdydek Dec 2, 2025
002b5c3
feat: absn on web
mdydek Dec 3, 2025
25c9327
Merge branch 'main' into feat/audio-node-options-in-ctor
mdydek Dec 3, 2025
829c019
feat: delay node
mdydek Dec 3, 2025
2c6a512
feat: iirfilter
mdydek Dec 3, 2025
e487709
test: test fix
mdydek Dec 3, 2025
bf1ad3d
feat: better absn for web
mdydek Dec 3, 2025
5632d68
feat: reverted pitch correction option in factory method for absn
mdydek Dec 3, 2025
97eb239
feat: slowly removing shared ptr in options
mdydek Dec 4, 2025
7a99505
feat: removed options as shared ptr
mdydek Dec 4, 2025
b19e1fd
test: test fix
mdydek Dec 4, 2025
e12c3da
feat: changes after review
mdydek Dec 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <audioapi/HostObjects/sources/WorkletSourceNodeHostObject.h>
#include <audioapi/core/BaseAudioContext.h>

#include <audioapi/HostObjects/utils/NodeOptionsParser.h>

namespace audioapi {

BaseAudioContextHostObject::BaseAudioContextHostObject(
Expand Down Expand Up @@ -184,7 +186,10 @@ JSI_HOST_FUNCTION_IMPL(BaseAudioContextHostObject, createConstantSource) {
}

JSI_HOST_FUNCTION_IMPL(BaseAudioContextHostObject, createGain) {
auto gain = context_->createGain();
auto object = args[0].asObject(runtime);
GainOptions options =
audioapi::option_parser::parseGainOptions(runtime, object);
auto gain = context_->createGain(std::make_shared<GainOptions>(options));
auto gainHostObject = std::make_shared<GainNodeHostObject>(gain);
return jsi::Object::createFromHostObject(runtime, gainHostObject);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include <audioapi/core/types/ChannelCountMode.h>
#include <audioapi/core/types/ChannelInterpretation.h>

namespace audioapi {
struct AudioNodeOptions {
int channelCount;
ChannelCountMode channelCountMode;
ChannelInterpretation channelInterpretation;
};

struct GainOptions : AudioNodeOptions {
float gain;
explicit GainOptions(AudioNodeOptions nodeOptions)
: AudioNodeOptions(nodeOptions) {}
};
} // namespace audioapi
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#pragma once

#include <audioapi/jsi/RuntimeLifecycleMonitor.h>
#include <jsi/jsi.h>
#include <memory>
#include <utility>
#include <vector>
#include <cstddef>

#include <audioapi/HostObjects/utils/NodeOptions.h>

namespace audioapi::option_parser {
std::shared_ptr<AudioNodeOptions> parseAudioNodeOptions(
jsi::Runtime &runtime,
const jsi::Object &optionsObject
) {
AudioNodeOptions options;

options.channelCount =
static_cast<int>(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 channelInterpretationStr = optionsObject
.getProperty(runtime, "channelInterpretation")
.asString(runtime)
.utf8(runtime);

if (channelInterpretationStr == "speakers") {
options.channelInterpretation = ChannelInterpretation::SPEAKERS;
} else if (channelInterpretationStr == "discrete") {
options.channelInterpretation = ChannelInterpretation::DISCRETE;
}

return std::make_shared<AudioNodeOptions>(options);
}

GainOptions parseGainOptions(
jsi::Runtime &runtime,
const jsi::Object &optionsObject) {
std::shared_ptr<AudioNodeOptions> nodeOptions = parseAudioNodeOptions(runtime, optionsObject);
GainOptions options(*nodeOptions.get());
options.gain = static_cast<float>(optionsObject
.getProperty(runtime, "gain")
.getNumber());
return options;
}
} // namespace audioapi::option_parser


Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <audioapi/HostObjects/utils/NodeOptions.h>
#include <audioapi/core/AudioNode.h>
#include <audioapi/core/AudioParam.h>
#include <audioapi/core/BaseAudioContext.h>
Expand All @@ -7,7 +8,15 @@

namespace audioapi {

AudioNode::AudioNode(BaseAudioContext *context) : context_(context) {
AudioNode::AudioNode(
BaseAudioContext *context,
std::shared_ptr<AudioNodeOptions> options)
: context_(context) {
if (options != nullptr) {
channelCount_ = options->channelCount;
channelCountMode_ = options->channelCountMode;
channelInterpretation_ = options->channelInterpretation;
}
audioBus_ = std::make_shared<AudioBus>(
RENDER_QUANTUM_SIZE, channelCount_, context->getSampleRate());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ namespace audioapi {
class AudioBus;
class BaseAudioContext;
class AudioParam;
class AudioNodeOptions;

class AudioNode : public std::enable_shared_from_this<AudioNode> {
public:
explicit AudioNode(BaseAudioContext *context);
explicit AudioNode(BaseAudioContext *context, std::shared_ptr<AudioNodeOptions> options = nullptr);
virtual ~AudioNode();

int getNumberOfInputs() const;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <audioapi/HostObjects/utils/NodeOptions.h>
#include <audioapi/core/BaseAudioContext.h>
#include <audioapi/core/analysis/AnalyserNode.h>
#include <audioapi/core/destinations/AudioDestinationNode.h>
Expand Down Expand Up @@ -128,8 +129,9 @@ std::shared_ptr<StreamerNode> BaseAudioContext::createStreamer() {
}
#endif

std::shared_ptr<GainNode> BaseAudioContext::createGain() {
auto gain = std::make_shared<GainNode>(this);
std::shared_ptr<GainNode> BaseAudioContext::createGain(
std::shared_ptr<GainOptions> options) {
auto gain = std::make_shared<GainNode>(this, options);
nodeManager_->addProcessingNode(gain);
return gain;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class WorkletSourceNode;
class WorkletNode;
class WorkletProcessingNode;
class StreamerNode;
class GainOptions;

class BaseAudioContext {
public:
Expand Down Expand Up @@ -65,7 +66,7 @@ class BaseAudioContext {
std::shared_ptr<OscillatorNode> createOscillator();
std::shared_ptr<ConstantSourceNode> createConstantSource();
std::shared_ptr<StreamerNode> createStreamer();
std::shared_ptr<GainNode> createGain();
std::shared_ptr<GainNode> createGain(std::shared_ptr<GainOptions> options);
std::shared_ptr<StereoPannerNode> createStereoPanner();
std::shared_ptr<BiquadFilterNode> createBiquadFilter();
std::shared_ptr<AudioBufferSourceNode> createBufferSource(bool pitchCorrection);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <audioapi/HostObjects/utils/NodeOptions.h>
#include <audioapi/core/BaseAudioContext.h>
#include <audioapi/core/effects/GainNode.h>
#include <audioapi/dsp/VectorMath.h>
Expand All @@ -6,9 +7,15 @@

namespace audioapi {

GainNode::GainNode(BaseAudioContext *context) : AudioNode(context) {
GainNode::GainNode(
BaseAudioContext *context,
std::shared_ptr<GainOptions> options)
: AudioNode(context, std::static_pointer_cast<AudioNodeOptions>(options)) {
gainParam_ = std::make_shared<AudioParam>(
1.0, MOST_NEGATIVE_SINGLE_FLOAT, MOST_POSITIVE_SINGLE_FLOAT, context);
options->gain,
MOST_NEGATIVE_SINGLE_FLOAT,
MOST_POSITIVE_SINGLE_FLOAT,
context);
isInitialized_ = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
namespace audioapi {

class AudioBus;
class GainOptions;

class GainNode : public AudioNode {
public:
explicit GainNode(BaseAudioContext *context);
explicit GainNode(BaseAudioContext *context, std::shared_ptr<GainOptions> options);

[[nodiscard]] std::shared_ptr<AudioParam> getGainParam() const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export default class BaseAudioContext {
}

createGain(): GainNode {
return new GainNode(this, this.context.createGain());
return new GainNode(this);
}

createStereoPanner(): StereoPannerNode {
Expand Down
13 changes: 10 additions & 3 deletions packages/react-native-audio-api/src/core/GainNode.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import { IGainNode } from '../interfaces';
import { GainOptions } from '../defaults';
import { TGainOptions } from '../types';
import AudioNode from './AudioNode';
import AudioParam from './AudioParam';
import BaseAudioContext from './BaseAudioContext';

export default class GainNode extends AudioNode {
readonly gain: AudioParam;

constructor(context: BaseAudioContext, gain: IGainNode) {
super(context, gain);
this.gain = new AudioParam(gain.gain, context);
constructor(context: BaseAudioContext, gainOptions?: TGainOptions) {
const finalOptions: TGainOptions = {
...GainOptions,
...gainOptions,
};
const gainNode: IGainNode = context.context.createGain(finalOptions);
super(context, gainNode);
this.gain = new AudioParam(gainNode.gain, context);
}
}
12 changes: 12 additions & 0 deletions packages/react-native-audio-api/src/defaults.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { TAudioNodeOptions, TGainOptions } from './types';

export const AudioNodeOptions: TAudioNodeOptions = {
channelCount: 2,
channelCountMode: 'max',
channelInterpretation: 'speakers',
};

export const GainOptions: TGainOptions = {
...AudioNodeOptions,
gain: 1,
};
3 changes: 2 additions & 1 deletion packages/react-native-audio-api/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
ContextState,
OscillatorType,
WindowType,
TGainOptions,
} from './types';

// IMPORTANT: use only IClass, because it is a part of contract between cpp host object and js layer
Expand Down Expand Up @@ -59,7 +60,7 @@ export interface IBaseAudioContext {
): IWorkletProcessingNode;
createOscillator(): IOscillatorNode;
createConstantSource(): IConstantSourceNode;
createGain(): IGainNode;
createGain(gainOptions: TGainOptions): IGainNode;
createStereoPanner(): IStereoPannerNode;
createBiquadFilter: () => IBiquadFilterNode;
createBufferSource: (pitchCorrection: boolean) => IAudioBufferSourceNode;
Expand Down
10 changes: 10 additions & 0 deletions packages/react-native-audio-api/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,13 @@ export interface ConvolverNodeOptions {
buffer?: AudioBuffer | null;
disableNormalization?: boolean;
}

export type TAudioNodeOptions = {
channelCount?: number;
channelCountMode?: ChannelCountMode;
channelInterpretation?: ChannelInterpretation;
};

export type TGainOptions = TAudioNodeOptions & {
gain?: number;
};
Loading