UNPKG

@nafr/echo-ui

Version:

A UI library born for WAA

40 lines (39 loc) 1.79 kB
/// <reference types="react" /> import * as Tone from 'tone'; import { OscilloscopeDataPoint } from '../main'; export interface UseOscilloscopeProps { fftSize?: number; onReady?: () => void; onError?: () => void; } /** * `useOscilloscope` is a custom React hook that integrates with Tone.js to create an oscilloscope. * It is designed to capture and display real-time waveform data from an audio source. * * @param {UseOscilloscopeProps} props - The configuration properties for the oscilloscope. * @param {number} [props.fftSize=1024] - The FFT size, must be a power of 2. Default is 1024. * @param {Function} props.onReady - Callback executed when the oscilloscope is ready. * @param {Function} props.onError - Callback executed in case of an error. * * @returns {object} An object containing various properties and methods for the oscilloscope: * - init: Method to initialize the oscilloscope. * - analyser: The Tone.Analyser instance used by the oscilloscope. * - data: The current waveform data captured by the oscilloscope. * - getData: Method to retrieve the current waveform data. * - observe: Method to start the data observation. * - cancelObserve: Method to stop the data observation. * - error: Boolean indicating if an error has occurred. * - errorMessage: The error message in case of an error. * * This hook can be useful in audio analysis applications, allowing for real-time visualization of waveform data. */ export declare const useOscilloscope: (props?: UseOscilloscopeProps) => { init: () => void; analyser: import("react").MutableRefObject<Tone.Analyser | null>; data: OscilloscopeDataPoint[]; getData: () => void; observer: () => void; cancelObserve: () => void; error: boolean; errorMessage: string; };