Skip to content

Commit

Permalink
feat: added AudioNode to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Maciej Makowski committed Jan 24, 2025
1 parent b1ae263 commit 9708526
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 21 deletions.
27 changes: 19 additions & 8 deletions packages/audiodocs/docs/core/audio-node.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,27 @@ Other cases are covered by `discrete`

The `connect` method lets you connect one of the node's outputs to a destination.

Arguments:
- `destination` - The [`AudioNode`](/core/audio-node) to which to connect.
#### Arguments:
- `destination`

Returns `undefined`.
The [`AudioNode`](/core/audio-node) to which to connect.

### `disconnect(destination: AudioNode)`
#### Returns `undefined`.

The `disconnect` method lets you disconnect from one of the node's outputs .
#### Exceptions:
- `InvalidAccessError: Error`

Arguments:
- `destination` - The [`AudioNode`](/core/audio-node) which to disconnect from.
Thrown if the `destination` node is not part of the same audio context as node.

Returns `undefined`.
### `disconnect(destination?: AudioNode)`

The `disconnect` method lets you disconnect one or more nodes from the node.

#### Arguments:
- `destination` <Optional />

The [`AudioNode`](/core/audio-node) which to disconnect from.

If no arguments provided node disconnects from all outgoing connections.

#### Returns `undefined`.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ class AudioNodeHostObject : public JsiHostObject {
}

JSI_HOST_FUNCTION(disconnect) {
if(args[0].isUndefined()) {
node_->disconnect();
return jsi::Value::undefined();
}

auto node =
args[0].getObject(runtime).getHostObject<AudioNodeHostObject>(runtime);
node_->disconnect(std::shared_ptr<AudioNodeHostObject>(node)->node_);
Expand Down
6 changes: 6 additions & 0 deletions packages/react-native-audio-api/common/cpp/core/AudioNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ void AudioNode::connectNode(const std::shared_ptr<AudioNode> &node) {
node->onInputConnected(this);
}

void AudioNode::disconnect() {
for (auto &outputNode : outputNodes_) {
disconnectNode(outputNode);
}
}

void AudioNode::disconnect(const std::shared_ptr<AudioNode> &node) {
context_->getNodeManager()->addPendingConnection(
shared_from_this(), node, AudioNodeManager::ConnectionType::DISCONNECT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class AudioNode : public std::enable_shared_from_this<AudioNode> {
std::string getChannelCountMode() const;
std::string getChannelInterpretation() const;
void connect(const std::shared_ptr<AudioNode> &node);
void disconnect();
void disconnect(const std::shared_ptr<AudioNode> &node);

bool isEnabled() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#define JSI_HOST_FUNCTION(NAME) \
jsi::Value NAME( \
jsi::Runtime &runtime, \
const jsi::Value &thisVal, \
const jsi::Value &thisValue, \
const jsi::Value *args, \
size_t count)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ void multiplyByScalarThenAddToOutput(

#endif

void VectorMath::linearToDecibels(
void linearToDecibels(
const float *inputVector,
float *outputVector,
size_t numberOfElementsToProcess) {
Expand Down
10 changes: 5 additions & 5 deletions packages/react-native-audio-api/src/core/AudioNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ export default class AudioNode {
this.channelInterpretation = this.node.channelInterpretation;
}

public connect(node: AudioNode): void {
if (this.context !== node.context) {
public connect(destination: AudioNode): void {
if (this.context !== destination.context) {
throw new InvalidAccessError(
'The AudioNodes are from different BaseAudioContexts'
);
}

this.node.connect(node.node);
this.node.connect(destination.node);
}

public disconnect(node: AudioNode): void {
this.node.disconnect(node.node);
public disconnect(destination?: AudioNode): void {
this.node.disconnect(destination?.node);
}
}
15 changes: 10 additions & 5 deletions packages/react-native-audio-api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,21 @@ export class AudioNode {
this.channelInterpretation = this.node.channelInterpretation;
}

public connect(node: AudioNode): void {
if (this.context !== node.context) {
public connect(destination: AudioNode): void {
if (this.context !== destination.context) {
throw new Error('The AudioNodes are from different BaseAudioContexts');
}

this.node.connect(node.node);
this.node.connect(destination.node);
}

public disconnect(node: AudioNode): void {
this.node.disconnect(node.node);
public disconnect(destination?: AudioNode): void {
if (destination === undefined) {
this.node.disconnect();
return;
}

this.node.disconnect(destination.node);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/react-native-audio-api/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export interface IAudioNode {
readonly channelInterpretation: ChannelInterpretation;

connect: (node: IAudioNode) => void;
disconnect: (node: IAudioNode) => void;
disconnect: (node?: IAudioNode) => void;
}

export interface IGainNode extends IAudioNode {
Expand Down

0 comments on commit 9708526

Please sign in to comment.