// 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)
        analiziramZvok = true
      },
      () => {
        console.log('napaka nalaganja mikrofona', arguments)
        analiziramZvok = false
      }
    )
  }
}
