A-Tractor - v2.3.1
    Preparing search index...

    Class WaveformGraph

    Waveform graphic draw widget.

    Example 1: Just draw the waveform.

    const audioElement = document.getElementById('audio');
    const viewElement = document.getElementById('div-analyzer');

    const waveFormGraph = new WaveformGraph(audioElement, viewElement, { colorPositive: '#00daff', colorNegative: '#00b6d5' });

    // We can start only after user starts interact with our page.
    // This is because of HTML Web Audio API restriction.
    document.body.onclick = () => {
    waveFormGraph.render();
    }

    Example 2: Draw the waveform and set the data to the other graph.

    const audioElement = document.getElementById('audio');
    const viewElement1 = document.getElementById('div-analyzer-1');
    const viewElement2 = document.getElementById('div-analyzer-2');

    const waveFormGraph1 = new WaveformGraph(audioElement, viewElement1, { colorPositive: '#00daff', colorNegative: '#00b6d5' });
    const waveFormGraph2 = new WaveformGraph(new Audio(), viewElement2, { colorPositive: '#00daff', colorNegative: '#00b6d5' });

    // We can start only after user starts interact with our page.
    // This is because of HTML Web Audio API restriction.
    document.body.onclick = () => {
    // Draw the first graph.
    waveFormGraph1.render().then(() => {
    // Get a simplified data samples for drawing.
    // 2000 values are more than enough to draw fast and correct on full HD screen.
    const data = waveFormGraph1.getDataSampling(2000);

    // Set obtained the data to the new waveform graph and draw it.
    waveFormGraph2.setDataSampling(data).render();

    // Obtained "data" - You can save and use for fast render.
    });
    }

    See more options at interface definition: IWaveFormGraphOptions

    Index

    Constructors

    • Constructor.

      Parameters

      • audioElement: HTMLMediaElement

        Input HTML element with source audio (HTML audio tag).

      • viewElement: HTMLElement

        The HTML element to render the widget.

      • Optionaloptions: IWaveFormGraphOptions

        The widget options.

      Returns WaveformGraph

    Methods

    • Returns the current audio buffer.

      Returns AudioBuffer

    • Returns an array of a specified number of data samples, taken at regular intervals. The minimum amount of data to construct a wave form graphic of a given width (defined by number of samples).

      Parameters

      • sampleCount: number

        Number of samples.

      • OptionalsourceChannel: number

        Optional source channel (0 - Left or 1 - Right). If omitted the max of both channels for stereo audio will be taken.

      • OptionalsourceAudioBuffer: AudioBuffer

        Optional instance of a source audio buffer. If omitted the current audio buffer will be taken.

      Returns number[]

    • Loads audio from source URL and sets current audio buffer.

      Parameters

      • Optionalsrc: string

        Source URL of audio.

      Returns Promise<AudioBuffer>

      Promise that resolves the current audio buffer.

    • Draws waveform graphic.

      Returns Promise<number[]>

      Promise that resolves an array of data samples used to construct a wave form graphic.

    • Resets the graphic.

      Returns void

    • Updates the canvas size depended on element size.

      Returns void