kegel/web/fft.js

35 lines
847 B
JavaScript

// Analiza zvoka
let analiziramZvok = false
let analyser = null
const fftSize = 64
const bufferSize = 32
const stolpicki = new Uint8Array(bufferSize)
// Zacni audio analizo
function zacniAnalizo() {
if (!analiziramZvok) {
// Analiza zvoka
const audioCtx = new AudioContext()
const mikrofon = navigator.mediaDevices.getUserMedia({ audio: true }).then(
(stream) => {
const source = audioCtx.createMediaStreamSource(stream)
analyser = audioCtx.createAnalyser()
analyser.minDecibels = -90;
analyser.maxDecibels = -10;
analyser.smoothingTimeConstant = 0.85;
analyser.fftSize = fftSize
source.connect(analyser)
},
() => {
console.log('napaka nalaganja mikrofona', arguments)
analiziramZvok = false
}
)
analiziramZvok = true
}
}