Oscillator
The <Oscillator />
component generates audio signals at specified frequencies and waveforms.
"use client";
import { Oscillator } from "@clxrityy/react-audio";
import { useState } from "react";
export default function Example() {
const [isPlaying, setIsPlaying] = useState<boolean>(false);
return (
<Oscillator
frequency={440}
type="sine"
isPlaying={isPlaying}
onPlayChange={setIsPlaying}
/>
);
}
Props
Property | Type | Description | Required | Default Value |
---|---|---|---|---|
type | OscillatorType | The type of oscillator wave (e.g., sine, square, sawtooth, triangle). | ❌ | sine |
frequency | number | The frequency of the oscillator in Hz. | ❌ | 440 |
gain | number | The default gain (volume) of the oscillator. | ❌ | 0.5 |
onPlayChange | (playing: boolean) => void | Callback function to handle play/pause changes. | ❌ | undefined |
isPlaying | boolean | Whether the oscillator is currently playing sound. | ❌ | false |
onFrequencyChange | (frequency: number) => void | Callback function to handle frequency changes. | ❌ | undefined |
onGainChange | (gain: number) => void | Callback function to handle gain changes. | ❌ | undefined |
Last updated on