OscillatorNode
The OscillatorNode
is an AudioScheduledSourceNode
which represents a simple periodic wave signal.
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.
AudioNode
properties
Number of inputs | 0 |
Number of outputs | 1 |
Channel count | 2 |
Channel count mode | max |
Channel interpretation | speakers |
Constructor
BaseAudioContext.createOscillator(options)
Example
import React, { useRef } from 'react';
import {
AudioContext,
OscillatorNode,
} from 'react-native-audio-api';
function App() {
const audioContextRef = useRef<AudioContext | null>(null);
if (!audioContextRef.current) {
audioContextRef.current = new AudioContext();
}
const oscillator = audioContextRef.current.createOscillator();
oscillator.connect(audioContextRef.current.destination);
oscillator.start(audioContextRef.current.currentTime);
}
OscillatorNode Playground
This is an interactive example demonstrating the OscillatorNode. You can adjust the parameters in real-time to hear and see how they affect the generated sound wave.
OscillatorNode
interactive playground
Oscillator Node
Sine
Frequency: 440 Hz
Detune: 0 cents
Volume: 0.50
import { AudioContext } from 'react-native-audio-api';
const ctx = new AudioContext();
const oscillator = ctx.createOscillator();
const gain = ctx.createGain();
oscillator.type = 'sine';
oscillator.frequency.value = 440;
oscillator.detune.value = 0;
gain.gain.value = 0.50;
oscillator.connect(gain);
gain.connect(ctx.destination);
oscillator.start();
Properties
It inherits all properties from AudioScheduledSourceNode
.
Name | Type | Default value | Description |
---|---|---|---|
detune Read only | AudioParam | 0 | a-rate AudioParam representing detuning of oscillation in cents. |
frequency Read only | AudioParam | 440 | a-rate AudioParam representing frequency of wave in herzs. |
type | OscillatorType | sine | String value represening type of wave. |
Methods
It inherits all methods from AudioScheduledSourceNode
.
setPeriodicWave
The above allows user to set any periodic wave.
Parameters | Type | Description |
---|---|---|
wave | PeriodicWave | Data representing custom wave. See for reference |
Returns undefined
.
Remarks
detune
- Nominal range is: -∞ to ∞.
- For example value of 100 detune the source up by one semitone, whereas -1200 down by one octave.
frequency
- 440 Hz is equivalent to piano note A4.
- Nominal range is: to
(
sampleRate
value is taken fromAudioContext
)