Skip to content

Latest commit

 

History

History
51 lines (38 loc) · 1.06 KB

analyser.md

File metadata and controls

51 lines (38 loc) · 1.06 KB

Analyser

View source code

View example

Get real-time frequency and waveform information.

import analyser from 'sono/effects/analyser';

const analyse = sono.effects.add(analyser({
    useFloats: false,
    fftSize: 2048,
    smoothing: 0.9,
    maxDecibels: 0,
    minDecibels: 0
}));

function draw() {
	window.requestAnimationFrame(draw);

	const frequencies = analyse.getFrequencies();

	for (let i = 0; i < frequencies.length; i++) {
		const magnitude = frequencies[i];
		const normalised = magnitude / 256;
		// do something
	}

	const waveform = analyse.getWaveform();

	for (let i = 0; i < waveform.length; i++) {
		const magnitude = waveform[i];
		const normalised = magnitude / 256;
		// do something
	}

    analyse.getAmplitude(amplitude => {
        // returns normalised amplitude
    });

    analyse.getPitch(pitch => {
        const note = pitch.note; // e.g. C#
        const hertz = pitch.hertz; // e.g. C#
        // do something
    });
}
draw();