Skip to main content

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 inputs0
Number of outputs1
Channel count2
Channel count modemax
Channel interpretationspeakers

Constructor

BaseAudioContext.createOscillator(options)

Example

import React, { useEffect, useRef, FC } from 'react';
import {
AudioContext,
OscillatorNode,
} from 'react-native-audio-api';

export default MyComponent: FC = () => {
const audioContextRef = useRef<AudioContext | null>(null);

useEffect(() => {
if (!audioContextRef.current) {
audioContextRef.current = new AudioContext();
}
const oscillator = audioContextRef.current.createOscillator();
oscillator.connect(audioContextRef.current.destination);
oscillator.start(audioContextRef.current.currentTime);
}
)
}

Properties

NameTypeDefault valueDescription
detune
Read only
AudioParam0a-rate AudioParam representing detuning of oscillation in cents.
frequency
Read only
AudioParam440a-rate AudioParam representing frequency of wave in herzs.
typeOscillatorTypesineString value represening type of wave.

Methods

setPeriodicWave

The above allows user to set any periodic wave.

ParametersTypeDescription
wavePeriodicWaveData 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: -sampleRate/2 to sampleRate/2 (sampleRate value is taken from AudioContext)