Skip to content

Commit 5dde976

Browse files
authored
Merge pull request #442 from software-mansion/docs/oscillator-node
docs: add docs for oscillator node
2 parents c276c9d + 542ccfa commit 5dde976

File tree

7 files changed

+102
-5
lines changed

7 files changed

+102
-5
lines changed

packages/audiodocs/docs/core/base-audio-context.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ The above method lets you create [`GainNode`](/effects/gain-node).
9696

9797
### `createOscillator`
9898

99-
The above method lets you create `OscillatorNode`.
99+
The above method lets you create [`OscillatorNode`](/sources/oscillator-node).
100100

101101
#### Returns `OscillatorNode`.
102102

packages/audiodocs/docs/sources/audio-buffer-source-node.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import { Optional, Overridden } from '@site/src/components/Badges';
1010
The `AudioBufferSourceNode` is an [`AudioScheduledSourceNode`](/sources/audio-scheduled-source-node) which represents audio source with in-memory audio data, stored in `AudioBuffer`.
1111
You can use it for audio playback, including standard pause and resume functionalities.
1212

13-
An `AudioBufferSourceNode` can be started only once, so if you want to play the same sound again you have to created new one.
14-
However this node is very inexpensive to create, and what is crucial you can reuse same [`AudioBuffer`](/sources/audio-buffer).
13+
An `AudioBufferSourceNode` can be started only once, so if you want to play the same sound again you have to create a new one.
14+
However, this node is very inexpensive to create, and what is crucial you can reuse same [`AudioBuffer`](/sources/audio-buffer).
1515

1616
#### [`AudioNode`](/core/audio-node#read-only-properties) properties
1717

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
---
2+
sidebar_position: 4
3+
---
4+
5+
import AudioNodePropsTable from "@site/src/components/AudioNodePropsTable"
6+
import { Optional, ReadOnly } from '@site/src/components/Badges';
7+
8+
# OscillatorNode
9+
10+
The `OscillatorNode` is an [`AudioScheduledSourceNode`](/sources/audio-scheduled-source-node) which represents a simple periodic wave signal.
11+
Similar to all of `AudioScheduledSourceNodes`, it can be started only once. If you want to play the same sound again you have to create a new one.
12+
13+
#### [`AudioNode`](/core/audio-node#read-only-properties) properties
14+
15+
<AudioNodePropsTable numberOfInputs={0} numberOfOutputs={1} channelCount={"defined by associated buffer"} channelCountMode={"max"} channelInterpretation={"speakers"} />
16+
17+
## Constructor
18+
19+
[`BaseAudioContext.createOscillator(options)`](/core/base-audio-context#createoscillator)
20+
21+
## Example
22+
23+
```tsx
24+
import React, { useEffect, useRef, FC } from 'react';
25+
import {
26+
AudioContext,
27+
OscillatorNode,
28+
} from 'react-native-audio-api';
29+
30+
export default MyComponent: FC = () => {
31+
const audioContextRef = useRef<AudioContext | null>(null);
32+
33+
useEffect(() => {
34+
if (!audioContextRef.current) {
35+
audioContextRef.current = new AudioContext();
36+
}
37+
const oscillator = audioContextRef.current.createOscillator();
38+
oscillator.connect(audioContextRef.current.destination);
39+
oscillator.start(audioContextRef.current.currentTime);
40+
}
41+
)
42+
}
43+
```
44+
45+
## Properties
46+
47+
| Name | Type | Default value | Description |
48+
| :----: | :----: | :-------- | :------- |
49+
| `detune` <ReadOnly /> | [`AudioParam`](/core/audio-param) | 0 |[`a-rate`](/core/audio-param#a-rate-vs-k-rate) `AudioParam` representing detuning of oscillation in cents. |
50+
| `frequency` <ReadOnly /> | [`AudioParam`](/core/audio-param) | 440 | [`a-rate`](/core/audio-param#a-rate-vs-k-rate) `AudioParam` representing frequency of wave in herzs. |
51+
| `type` | [`OscillatorType`](/types/oscillator-type)| `sine` | String value represening type of wave. |
52+
53+
## Methods
54+
55+
### `setPeriodicWave`
56+
57+
The above allows user to set any periodic wave.
58+
59+
| Parameters | Type | Description |
60+
| :---: | :---: | :---- |
61+
| `wave` | `PeriodicWave` | Data representing custom wave. [`See for reference`](/core/base-audio-context#createperiodicwave) |
62+
63+
#### Returns `undefined`.
64+
65+
## Remarks
66+
67+
#### `detune`
68+
- Nominal range is: -∞ to ∞.
69+
- For example value of 100 detune the source up by one semitone, whereas -1200 down by one octave.
70+
71+
#### `frequency`
72+
- 440 Hz is equivalent to piano note A4.
73+
- Nominal range is: -sampleRate/2 to sampleRate/2 (`sampleRate` value is taken from [`AudioContext`](/core/base-audio-context#properties))
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
sidebar_position: 6
3+
---
4+
5+
# OscillatorType
6+
7+
`OscillatorType` is a string that specifies shape of an oscillator wave
8+
9+
```jsx
10+
type OscillatorType =
11+
| 'sine'
12+
| 'square'
13+
| 'sawtooth'
14+
| 'triangle'
15+
| 'custom';
16+
```
17+
18+
Below you can see possible names with shapes corresponding to them.
19+
![](/img/oscillator-waves.png)
20+
21+
## `custom`
22+
23+
This value can't be set explicitly, but it allows user to set any shape. See [`setPeriodicWave`](/sources/oscillator-node#setperiodicwave) for reference.
24+

packages/audiodocs/docs/types/periodic-wave-constraints.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 6
2+
sidebar_position: 7
33
---
44

55
# PeriodicWaveConstraints

packages/audiodocs/docs/types/window-type.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 7
2+
sidebar_position: 8
33
---
44

55
# WindowType
Loading

0 commit comments

Comments
 (0)