The Fast Fourrier Transform analysis.
let m = maximilian(); let fftSize = 1024; let magMult = 6; let wave = 0; let playAudio = () => { let myOsc = new m.maxiOsc(); let myOsc2 = new m.maxiOsc(); let maxiAudio = new m.maxiAudio(); let samplePlayer = new m.maxiSample(); let fft = new m.maxiFFT(); let magnitudes = new m.VectorFloat(); let mags = new Float32Array(); maxiAudio.init(); maxiAudio.loadSample("audio/beat2.wav", samplePlayer); fft.setup(fftSize, 512, 256); maxiAudio.play = function () { wave = samplePlayer.play(); if (fft.process(wave, 0)) { magnitudes = fft.getMagnitudesDB(); console.log(magnitudes); for (let i = 0; i < fftSize / 2; i++){ mags[i] = magnitudes.get(i); } console.log(mags); } return wave; } } function draw() { context.clearRect(0, 0, 700, 700); context.fillStyle = "#FF0000"; context.font = "30px Arial"; context.fillText("FFT", 70, 200); for (let i = 0; i < fftSize / 2; i++) { context.beginPath(); context.rect( fftDraw.barsLeft + i, fftDraw.barsBottom, fftDraw.barsSize, -(fft.getMagnitude(i) * fftDraw.magMult)); context.fill(); context.closePath(); } } const playButton = document.getElementById('playButton'); playButton.addEventListener("click", () => playAudio()); window.onload = function setup() { let canvas = document.getElementById("myCanvas"); context = canvas.getContext("2d"); // return setInterval(draw, 40); }