Skip to main content
Version: Next

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.

Loading...

Constructor

constructor(context: BaseAudioContext, options?: OscillatorOptions)

OscillatorOptions

Inherits all properties from AudioNodeOptions.

ParameterTypeDefault
type
Optional
OscillatorTypesineInitial value for type.
frequency
Optional
number440.0Initial value for frequency.
detune
Optional
number0.0Initial value for detune.
info

You can also create an OscillatorNode via BaseAudioContext.createOscillator(), which uses default values.

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);
}

Properties

Inherits all properties from AudioScheduledSourceNode.

AudioNodeproperties
NameTypeDefault valueDescription
detune
Read only
AudioParam0.0a-rate AudioParam representing detuning of oscillation in cents.
frequency
Read only
AudioParam440.0a-rate AudioParam representing frequency of wave in herzs.
typeOscillatorTypesineString value represening type of wave.

Methods

Inherits all methods from AudioScheduledSourceNode.

setPeriodicWave

Sets any periodic wave.

ParameterTypeDescription
wavePeriodicWaveData representing custom wave (see for reference).

Returns undefined.

Remarks

detune

  • Nominal range is: -∞ to ∞.
  • For example value of 100.0 detune the source up by one semitone, whereas -1200.0 down by one octave.

frequency

  • 440.0 Hz is equivalent to piano note A4.
  • Nominal range is: sampleRate2-\frac{\text{sampleRate}}{2} to sampleRate2\frac{\text{sampleRate}}{2} (sampleRate value is taken from AudioContext)