Skip to content

Commit 3b04bba

Browse files
authored
Merge pull request #460 from software-mansion/docs/connecting-node-to-param
docs: add mention about connecting node to param
2 parents 7af5caf + f99a6d2 commit 3b04bba

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

packages/audiodocs/docs/core/audio-node.mdx

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,52 @@ Based on them we can obtain output's number of channels and mixing strategy.
3535
| `channelCountMode` | [`ChannelCountMode`](/types/channel-count-mode) | Enumerated value that specifies the method by which channels are mixed between the node's inputs and outputs. | <ReadOnly /> |
3636
| `channelInterpretation` | [`ChannelInterpretation`](/types/channel-interpretation) | Enumerated value that specifies how input channels are mapped to output channels when number of them is different. | <ReadOnly /> |
3737

38+
## Examples
39+
40+
### Connecting node to node
41+
42+
```tsx
43+
import { OscillatorNode, GainNode, AudioContext } from 'react-native-audio-api';
44+
45+
function App() {
46+
const audioContext = new AudioContext();
47+
const oscillatorNode = audioContext.createOscillator();
48+
const gainNode = audioContext.createGain();
49+
50+
gainNode.gain.value = 0.5; //lower volume to 0.5
51+
oscillatorNode.connect(gainNode);
52+
gainNode.connect(audioContext.destination);
53+
oscillatorNode.start(audioContext.currentTime);
54+
}
55+
```
56+
57+
### Connecting node to audio param (LFO-controlled parameter)
58+
59+
```tsx
60+
import { OscillatorNode, GainNode, AudioContext } from 'react-native-audio-api';
61+
62+
function App() {
63+
const audioContext = new AudioContext();
64+
const oscillatorNode = audioContext.createOscillator();
65+
const lfo = audioContext.createOscillator();
66+
const gainNode = audioContext.createGain();
67+
68+
gainNode.gain.value = 0.5; //lower volume to 0.5
69+
lfo.frequency.value = 2; //low frequency oscillator with 2Hz
70+
71+
// by default oscillator wave values ranges from -1 to 1
72+
// connecting lfo to gain param will cause the gain param to oscillate at 2Hz and its value will range from 0.5 - 1 to 0.5 + 1
73+
// you can modulate amplitude by connecting lfo to another gain that would be responsible for this value
74+
lfo.connect(gainNode.gain)
75+
76+
oscillatorNode.connect(gainNode);
77+
gainNode.connect(audioContext.destination);
78+
oscillatorNode.start(audioContext.currentTime);
79+
lfo.start(audioContext.currentTime);
80+
}
81+
```
82+
83+
3884
## Methods
3985

4086
### `connect`
@@ -43,7 +89,7 @@ The above method lets you connect one of the node's outputs to a destination.
4389

4490
| Parameters | Type | Description |
4591
| :---: | :---: | :---- |
46-
| `destination` | [`AudioNode`](/core/audio-node) | `AudioNode` to which to connect. |
92+
| `destination` | [`AudioNode`](/core/audio-node) or [`AudioParam`](/core/audio-param) | `AudioNode` or `AudioParam` to which to connect. |
4793

4894
#### Errors:
4995

@@ -59,7 +105,7 @@ The above method lets you disconnect one or more nodes from the node.
59105

60106
| Parameters | Type | Description |
61107
| :---: | :---: | :---- |
62-
| `destination` <Optional /> | [`AudioNode`](/core/audio-node) | `AudioNode` to which to connect. |
108+
| `destination` <Optional /> | [`AudioNode`](/core/audio-node) or [`AudioParam`](/core/audio-param) | `AudioNode` or `AudioParam` from which to disconnect. |
63109

64110
If no arguments provided node disconnects from all outgoing connections.
65111

0 commit comments

Comments
 (0)