| sidebar_position | 6 |
|---|
import AudioNodePropsTable from "@site/src/components/AudioNodePropsTable" import { Optional, ReadOnly } from '@site/src/components/Badges';
import InteractivePlayground from '@site/src/components/InteractivePlayground'; import { useOscillatorPlayground } from '@site/src/components/InteractivePlayground/OscillatorExample/useOscilatorPlayground';
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.
constructor(context: BaseAudioContext, options?: OscillatorOptions)Inherits all properties from AudioNodeOptions
| Parameter | Type | Default | |
|---|---|---|---|
type |
OscillatorType |
sine |
Initial value for type. |
frequency |
number |
440 | Initial value for frequency. |
detune |
number |
0 | Initial value for detune. |
Or by using BaseAudioContext factory method:
BaseAudioContext.createOscillator()
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);
}It inherits all properties from AudioScheduledSourceNode.
| Name | Type | Default value | Description |
|---|---|---|---|
detune |
AudioParam |
0 | a-rate AudioParam representing detuning of oscillation in cents. |
frequency |
AudioParam |
440 | a-rate AudioParam representing frequency of wave in herzs. |
type |
OscillatorType |
sine |
String value represening type of wave. |
It inherits all methods from AudioScheduledSourceNode.
Sets any periodic wave.
| Parameter | Type | Description |
|---|---|---|
wave |
PeriodicWave |
Data representing custom wave. See for reference |
- Nominal range is: -∞ to ∞.
- For example value of 100 detune the source up by one semitone, whereas -1200 down by one octave.
- 440 Hz is equivalent to piano note A4.
- Nominal range is:
$-\frac{\text{sampleRate}}{2}$ to$\frac{\text{sampleRate}}{2}$ (sampleRatevalue is taken fromAudioContext)