Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="container"><canvas id="canvas"></canvas></div>
<audio id="audio" controls crossorigin></audio>
<input id="audioFileInput" type="file" accept="audio/*">
<script>
  function map(x, min, max, targetMin, targetMax) {
    return (x - min) / (max - min) * (targetMax - targetMin) + targetMin;
  }
  
  function clamp(x, min, max) {
    return Math.min(Math.max(x, min), max);
  }
  
  function idxWrapOver(x, length) {
    return (x % length + length) % length;
  }
  // Hz and FFT bin conversion
function hertzToFFTBin(x, y = 'round', bufferSize = 4096, sampleRate = 44100) {
  const bin = x * bufferSize / sampleRate;
  let func = y;
  
  if (!['floor','ceil','trunc'].includes(func))
    func = 'round'; // always use round if you specify an invalid/undefined value
  
  return Math[func](bin);
}

function fftBinToHertz(x, bufferSize = 4096, sampleRate = 44100) {
  return x * sampleRate / bufferSize;
}
  

// Calculate the FFT
function calcFFT(input) {
  let fft = input.map(x => x);
  let fft2 = input.map(x => x);
  transform(fft, fft2);
  let output = new Array(Math.round(fft.length/2)).fill(0);
  for (let i = 0; i < output.length; i++) {
    output[i] = Math.hypot(fft[i], fft2[i])/(fft.length);
  }
  return output;
}

function calcComplexFFT(input) {
  let fft = input.map(x => x);
  let fft2 = input.map(x => x);
  transform(fft, fft2);
  return input.map((_, i, arr) => {
    return {
      re: fft[i]/(arr.length/2),
      im: fft2[i]/(arr.length/2),
      magnitude: Math.hypot(fft[i], fft2[i])/(arr.length/2),
      phase: Math.atan2(fft2[i], fft[i])
    };
  });
}
  
function calcComplexInputFFT(real, imag) {
  if (real.length !== imag.length)
    return [];
  const fft1 = real.map(x => x),
        fft2 = imag.map(x => x);
  transform(fft1, fft2);
  return real.map((_, i, arr) => {
    return {
      re: fft1[i]/arr.length,
      im: fft2[i]/arr.length,
      magnitude: Math.hypot(fft1[i], fft2[i])/arr.length,
      phase: Math.atan2(fft2[i], fft1[i])
    }
  });
}
  
  /**
 * FFT and convolution (JavaScript)
 * 
 * Copyright (c) 2017 Project Nayuki. (MIT License)
 * https://www.nayuki.io/page/free-small-fft-in-multiple-languages
 */

/* 
 * Computes the discrete Fourier transform (DFT) of the given complex vector, storing the result back into the vector.
 * The vector can have any length. This is a wrapper function.
 */
function transform(real, imag) {
	const n = real.length;
	if (n != imag.length)
		throw "Mismatched lengths";
	if (n <= 0)
		return;
	else if ((2 ** Math.trunc(Math.log2(n))) === n)  // Is power of 2
		transformRadix2(real, imag);
	else  // More complicated algorithm for arbitrary sizes
		transformBluestein(real, imag);
}


/* 
 * Computes the inverse discrete Fourier transform (IDFT) of the given complex vector, storing the result back into the vector.
 * The vector can have any length. This is a wrapper function. This transform does not perform scaling, so the inverse is not a true inverse.
 */
function inverseTransform(real, imag) {
	transform(imag, real);
}


/* 
 * Computes the discrete Fourier transform (DFT) of the given complex vector, storing the result back into the vector.
 * The vector's length must be a power of 2. Uses the Cooley-Tukey decimation-in-time radix-2 algorithm.
 */
function transformRadix2(real, imag) {
	// Length variables
	const n = real.length;
	if (n != imag.length)
		throw "Mismatched lengths";
	if (n <= 1)  // Trivial transform
		return;
	const logN = Math.log2(n);
	if ((2 ** Math.trunc(logN)) !== n)
		throw "Length is not a power of 2";
	
	// Trigonometric tables
	let cosTable = new Array(n / 2);
	let sinTable = new Array(n / 2);
	for (let i = 0; i < n / 2; i++) {
		cosTable[i] = Math.cos(2 * Math.PI * i / n);
		sinTable[i] = Math.sin(2 * Math.PI * i / n);
	}
	
	// Bit-reversed addressing permutation
	for (let i = 0; i < n; i++) {
		let j = reverseBits(i, logN);
		if (j > i) {
			let temp = real[i];
			real[i] = real[j];
			real[j] = temp;
			temp = imag[i];
			imag[i] = imag[j];
			imag[j] = temp;
		}
	}
	
	// Cooley-Tukey decimation-in-time radix-2 FFT
	for (let size = 2; size <= n; size *= 2) {
		let halfsize = size / 2;
		let tablestep = n / size;
		for (let i = 0; i < n; i += size) {
			for (let j = i, k = 0; j < i + halfsize; j++, k += tablestep) {
				const l = j + halfsize;
				const tpre =  real[l] * cosTable[k] + imag[l] * sinTable[k];
				const tpim = -real[l] * sinTable[k] + imag[l] * cosTable[k];
				real[l] = real[j] - tpre;
				imag[l] = imag[j] - tpim;
				real[j] += tpre;
				imag[j] += tpim;
			}
		}
	}
	
	// Returns the integer whose value is the reverse of the lowest 'bits' bits of the integer 'x'.
	function reverseBits(x, bits) {
		let y = 0;
		for (let i = 0; i < bits; i++) {
			y = (y << 1) | (x & 1);
			x >>>= 1;
		}
		return y;
	}
}


/* 
 * Computes the discrete Fourier transform (DFT) of the given complex vector, storing the result back into the vector.
 * The vector can have any length. This requires the convolution function, which in turn requires the radix-2 FFT function.
 * Uses Bluestein's chirp z-transform algorithm.
 */
function transformBluestein(real, imag) {
	// Find a power-of-2 convolution length m such that m >= n * 2 + 1
	const n = real.length;
	if (n != imag.length)
		throw "Mismatched lengths";
	const m = 2 ** Math.trunc(Math.log2(n*2)+1);
	
	// Trignometric tables
	let cosTable = new Array(n);
	let sinTable = new Array(n);
	for (let i = 0; i < n; i++) {
		let j = i * i % (n * 2);  // This is more accurate than j = i * i
		cosTable[i] = Math.cos(Math.PI * j / n);
		sinTable[i] = Math.sin(Math.PI * j / n);
	}
	
	// Temporary vectors and preprocessing
	let areal = newArrayOfZeros(m);
	let aimag = newArrayOfZeros(m);
	for (let i = 0; i < n; i++) {
		areal[i] =  real[i] * cosTable[i] + imag[i] * sinTable[i];
		aimag[i] = -real[i] * sinTable[i] + imag[i] * cosTable[i];
	}
	let breal = newArrayOfZeros(m);
	let bimag = newArrayOfZeros(m);
	breal[0] = cosTable[0];
	bimag[0] = sinTable[0];
	for (let i = 1; i < n; i++) {
		breal[i] = breal[m - i] = cosTable[i];
		bimag[i] = bimag[m - i] = sinTable[i];
	}
	
	// Convolution
	let creal = new Array(m);
	let cimag = new Array(m);
	convolveComplex(areal, aimag, breal, bimag, creal, cimag);
	
	// Postprocessing
	for (let i = 0; i < n; i++) {
		real[i] =  creal[i] * cosTable[i] + cimag[i] * sinTable[i];
		imag[i] = -creal[i] * sinTable[i] + cimag[i] * cosTable[i];
	}
}


/* 
 * Computes the circular convolution of the given real vectors. Each vector's length must be the same.
 */
function convolveReal(x, y, out) {
	const n = x.length;
	if (n != y.length || n != out.length)
		throw "Mismatched lengths";
	convolveComplex(x, newArrayOfZeros(n), y, newArrayOfZeros(n), out, newArrayOfZeros(n));
}


/* 
 * Computes the circular convolution of the given complex vectors. Each vector's length must be the same.
 */
function convolveComplex(xreal, ximag, yreal, yimag, outreal, outimag) {
	const n = xreal.length;
	if (n != ximag.length || n != yreal.length || n != yimag.length
			|| n != outreal.length || n != outimag.length)
		throw "Mismatched lengths";
	
	xreal = xreal.slice();
	ximag = ximag.slice();
	yreal = yreal.slice();
	yimag = yimag.slice();
	transform(xreal, ximag);
	transform(yreal, yimag);
	
	for (let i = 0; i < n; i++) {
		const temp = xreal[i] * yreal[i] - ximag[i] * yimag[i];
		ximag[i] = ximag[i] * yreal[i] + xreal[i] * yimag[i];
		xreal[i] = temp;
	}
	inverseTransform(xreal, ximag);
	
	for (let i = 0; i < n; i++) {  // Scaling (because this FFT implementation omits it)
		outreal[i] = xreal[i] / n;
		outimag[i] = ximag[i] / n;
	}
}


function newArrayOfZeros(n) {
	let result = new Array(n).fill(0);
	return result;
}
</script>
              
            
!

CSS

              
                body {
  margin: 0;
  overflow: hidden;
}

audio {
  display: inline-block;
  width: 100%;
  height: 40px;
}

canvas {
  display: block;
  width: 100%;
}

#container {
  height: calc( 100vh - 40px );
}

#upload {
  display: none;
}
              
            
!

JS

              
                // necessary parts for audio context and audio elements respectively
const audioCtx = new AudioContext();
const audioPlayer = document.getElementById('audio');
const localAudioElement = document.getElementById('audioFileInput');
localAudioElement.addEventListener('change', loadLocalFile);
// canvas is for displaying visuals
const canvas = document.getElementById('canvas'),
      ctx = canvas.getContext('2d'),
      container = document.getElementById('container');
const audioSource = audioCtx.createMediaElementSource(audioPlayer);
const analyser = audioCtx.createAnalyser();
analyser.fftSize = 32768; // maxes out FFT size
const dataArray = new Float32Array(analyser.fftSize);
// variables
const fifoBuffers = [],
      smoothed = [],
      peaks = [],
      holds = [];
let fifoIdx = 0;
/*
const currentSpectrum = [],
      peaks = [],
      peakHolds = [],
      peakAccels = [];
*/
const delay = audioCtx.createDelay();
audioSource.connect(delay);
delay.connect(audioCtx.destination);
//audioSource.connect(audioCtx.destination);
audioSource.connect(analyser);

const visualizerSettings = {
  fftSize: 16384,
  fifoLength: 30,
  fifoDomain: 'linear',
  calibrationDomain: 'linear',
  smoothingTimeConstant: 95,
  peakDecayTimeConstant: 99,
  holdTime: 180,
  resetAverage: resetFIFO,
  showCrest: true,
  showPeaks: true,
  showAverage: true,
  showCurrent: true,
  showCalibration: true,
  freeze: false,
  darkMode: true,
  compensateDelay: true
},
      placeholderListData = {
        'Option 1': 'one',
        'Option 2': 'two'
      }, // useful for multiple options sharing dropdown menu options
      averagingDomains = {
        'Linear': 'linear',
        'Squared': 'rms',
        'Logarithmic': 'log'
      },
      loader = {
        url: '',
        load: function() {
          audioPlayer.src = this.url;
          audioPlayer.play();
        },
        loadLocal: function() {
          localAudioElement.click();
        },
        toggleFullscreen: _ => {
          if (document.fullscreenElement === canvas)
            document.exitFullscreen();
          else
            canvas.requestFullscreen();
        }
      };
// dat.GUI for quick customization
let gui = new dat.GUI();
gui.add(loader, 'url').name('URL');
gui.add(loader, 'load').name('Load');
gui.add(loader, 'loadLocal').name('Load from local device');
let settings = gui.addFolder('Visualization settings');
// FFT size can be non-power of 2 because we use the FFT library that supports non-power of two data length
settings.add(visualizerSettings, 'fftSize', 32, 32768, 1).name('FFT size').onChange(resetFIFO);
// The additional parameters goes here
settings.add(visualizerSettings, 'fifoLength', 1, 240, 1).name('FIFO averaging length').onChange(resetFIFO);
settings.add(visualizerSettings, 'fifoDomain', averagingDomains).name('FIFO averaging domain');
settings.add(visualizerSettings, 'smoothingTimeConstant', 0, 100).name('Main spectrum decay rate');
settings.add(visualizerSettings, 'peakDecayTimeConstant', 0, 100).name('Peak decay rate');
settings.add(visualizerSettings, 'holdTime', 0, 240).name('Peak hold (frames)');
settings.add(visualizerSettings, 'resetAverage').name('Reset FIFO averaging');
settings.add(visualizerSettings, 'showPeaks').name('Show peak spectrum');
settings.add(visualizerSettings, 'showAverage').name('Show average spectrum');
settings.add(visualizerSettings, 'showCurrent').name('Show current spectrum');
settings.add(visualizerSettings, 'showCrest').name('Show crest spectrum');
settings.add(visualizerSettings, 'showCalibration').name('Show calibration line');
settings.add(visualizerSettings, 'calibrationDomain', averagingDomains).name('Calibration line calculation domain');
// another parameters at the end
settings.add(visualizerSettings, 'freeze').name('Freeze analyzer');
settings.add(visualizerSettings, 'darkMode').name('Dark mode');
settings.add(visualizerSettings, 'compensateDelay').name('Compensate for delay');
gui.add(loader, 'toggleFullscreen').name('Toggle fullscreen mode');

function resizeCanvas() {
  const scale = devicePixelRatio,
        isFullscreen = document.fullscreenElement === canvas;
  canvas.width = (isFullscreen ? innerWidth : container.clientWidth)*scale;
  canvas.height = (isFullscreen ? innerHeight : container.clientHeight)*scale;
}
// additional function used by settings with onChange property
function resetFIFO() {
  smoothed.length = 0;
  fifoBuffers.length = 0;
  peaks.length = 0;
  holds.length = 0;
  fifoIdx = 0;
}

addEventListener('click', () => {
  if (audioCtx.state == 'suspended')
    audioCtx.resume();
});
addEventListener('resize', resizeCanvas);
resizeCanvas();

function loadLocalFile(event) {
  const file = event.target.files[0],
        reader = new FileReader();
  reader.onload = (e) => {
    audioPlayer.src = e.target.result;
    audioPlayer.play();
  };

  reader.readAsDataURL(file);
}

visualize();
function visualize() {
  delay.delayTime.value = (visualizerSettings.fftSize / audioCtx.sampleRate) * visualizerSettings.compensateDelay;
  if (!visualizerSettings.freeze) {
    // we use getFloatTimeDomainData (which is PCM data that is gathered, just like vis_stream::get_chunk_absolute() in foobar2000 SDK)
    analyser.getFloatTimeDomainData(dataArray);
  }
  const fftData = new Array(visualizerSettings.fftSize);
  let norm = 0; // we can use a variable called norm to compensate for gain changes incurred by a window function
  for (let i = 0; i < visualizerSettings.fftSize; i++) {
    const magnitude = dataArray[i+analyser.fftSize-visualizerSettings.fftSize],
          w = applyWindow(map(i, 0, visualizerSettings.fftSize, -1, 1), 'hann', 1, true, 0);
    fftData[i] = magnitude * w;
    norm += w;
  }
  const spectrumData = calcComplexFFT(fftData.map(x => x*fftData.length/norm/Math.SQRT2));
  const fgColor = visualizerSettings.darkMode ? '#fff' : '#000',
        bgColor = visualizerSettings.darkMode ? '#000' : '#fff';
  ctx.fillStyle = bgColor;
  ctx.fillRect(0, 0, canvas.width, canvas.height);
  //ctx.fillStyle = fgColor;
  //ctx.strokeStyle = fgColor;
  // fifo (first-in, first-out) averaging
  const fifoLength = visualizerSettings.fifoLength,
        crestSpectrum = new Array(spectrumData.length);
  let calibrationValue = 0;
  fifoBuffers.length = spectrumData.length;
  smoothed.length = spectrumData.length;
  peaks.length = spectrumData.length;
  holds.length = spectrumData.length;
  for (let i = 0; i < spectrumData.length; i++) {
    if (fifoBuffers[i] === undefined)
      fifoBuffers[i] = new Array(fifoLength);
    else
      fifoBuffers[i].length = fifoLength;
    fifoBuffers[i][fifoIdx] = spectrumData[i].magnitude;
    smoothed[i] = isFinite(smoothed[i]) ? Math.max(smoothed[i]*visualizerSettings.smoothingTimeConstant/100, spectrumData[i].magnitude) : spectrumData[i].magnitude;
    if (spectrumData[i].magnitude >= peaks[i] || !isFinite(peaks[i])) {
      peaks[i] = spectrumData[i].magnitude;
      holds[i] = visualizerSettings.holdTime;
    }
    else if (holds[i] > 0)
      holds[i]--;
    else
      peaks[i] *= visualizerSettings.peakDecayTimeConstant / 100;
  }
  fifoIdx = idxWrapOver(fifoIdx+1, fifoLength);
  ctx.lineWidth = 1;
  ctx.fillStyle = '#00f';
  ctx.strokeStyle = ctx.fillStyle;
  if (visualizerSettings.showPeaks) {
    ctx.beginPath();
    for (let i = 0; i < peaks.length; i++) {
      const x = peaks[i];
      // log frequency scale
      ctx.lineTo(map(Math.log2(fftBinToHertz(i, visualizerSettings.fftSize, audioCtx.sampleRate)), Math.log2(20), Math.log2(20000), 0, canvas.width), map(20*Math.log10(x), -100, 0, canvas.height, 0));
    }
    ctx.stroke();
  }
  ctx.fillStyle = fgColor;
  ctx.strokeStyle = fgColor;
  if (visualizerSettings.showCurrent) {
    ctx.beginPath();
    for (let i = 0; i < smoothed.length; i++) {
      const x = smoothed[i];
      // log frequency scale
      ctx.lineTo(map(Math.log2(fftBinToHertz(i, visualizerSettings.fftSize, audioCtx.sampleRate)), Math.log2(20), Math.log2(20000), 0, canvas.width), map(20*Math.log10(x), -100, 0, canvas.height, 0));
    }
    ctx.stroke();
  }
  ctx.lineWidth = 1;
  ctx.fillStyle = '#569CFF'//'#569CD6';
  ctx.strokeStyle = ctx.fillStyle;
  ctx.beginPath();
  for (let i = 0; i < fifoBuffers.length; i++) {
    const avg = fifoBuffers[i].reduce((acc, curr) => {
      const current = isFinite(curr) ? curr : 0;
      switch (visualizerSettings.fifoDomain) {
        case 'rms':
          return acc + current ** 2;
        case 'log':
          return acc + 20*Math.log10(current);
        default:
          return acc + current;
      }
    }, 0),
          smoothedPeak = fifoBuffers[i].reduce((acc, curr) => Math.max(acc, isFinite(curr) ? curr : 0), 0); // needed for calculating crest spectrum
    let x = avg;
    switch (visualizerSettings.fifoDomain) {
      case 'rms':
        x = Math.sqrt(avg/fifoLength);
        break;
      case 'log':
        x = 10 ** (avg/fifoLength/20);
        break;
      default:
        x /= fifoLength;
    }
    crestSpectrum[i] = smoothedPeak/x;
    // log frequency scale
    if (visualizerSettings.showAverage)
      ctx.lineTo(map(Math.log2(fftBinToHertz(i, visualizerSettings.fftSize, audioCtx.sampleRate)), Math.log2(20), Math.log2(20000), 0, canvas.width), map(20*Math.log10(x), -100, 0, canvas.height, 0));
    // calculating a calibration line
    switch (visualizerSettings.calibrationDomain) {
      case 'rms':
        calibrationValue += x ** 2;
        break;
      case 'log':
        calibrationValue += 20*Math.log10(x);
        break;
      default:
        calibrationValue += x;
    }
  }
  ctx.stroke();
  switch (visualizerSettings.calibrationDomain) {
    case 'rms':
      calibrationValue = Math.sqrt(calibrationValue/fifoBuffers.length);
      break;
    case 'log':
      calibrationValue = 10 ** (calibrationValue/fifoBuffers.length/20);
      break;
    default:
      calibrationValue /= fifoBuffers.length;
  }
  if (visualizerSettings.showCrest) {
    ctx.fillStyle = '#f00';
    ctx.strokeStyle = ctx.fillStyle;
    ctx.beginPath();
    for (let i = 0; i < crestSpectrum.length; i++) {
      const x = crestSpectrum[i];
      // log frequency scale
      ctx.lineTo(map(Math.log2(fftBinToHertz(i, visualizerSettings.fftSize, audioCtx.sampleRate)), Math.log2(20), Math.log2(20000), 0, canvas.width), map(20*Math.log10(x), 0, 100, canvas.height, 0));
    }
    ctx.stroke();
  }
  ctx.fillStyle = '#0f0';
  ctx.strokeStyle = ctx.fillStyle;
  if (visualizerSettings.showCalibration) {
    ctx.beginPath();
    ctx.lineTo(0, map(20*Math.log10(calibrationValue), -100, 0, canvas.height, 0));
    ctx.lineTo(canvas.width, map(20*Math.log10(calibrationValue), -100, 0, canvas.height, 0));
    ctx.stroke();
  }
  requestAnimationFrame(visualize);
}
// and here's the additional functions that we can need for this visualization
function applyWindow(posX, windowType = 'Hann', windowParameter = 1, truncate = true, windowSkew = 0) {
  let x = windowSkew > 0 ? ((posX/2-0.5)/(1-(posX/2-0.5)*10*(windowSkew ** 2)))/(1/(1+10*(windowSkew ** 2)))*2+1 :
                           ((posX/2+0.5)/(1+(posX/2+0.5)*10*(windowSkew ** 2)))/(1/(1+10*(windowSkew ** 2)))*2-1;
  
  if (truncate && Math.abs(x) > 1)
    return 0;
  
  switch (windowType.toLowerCase()) {
    default:
      return 1;
    case 'hanning':
    case 'cosine squared':
    case 'hann':
      return Math.cos(x*Math.PI/2) ** 2;
    case 'raised cosine':
    case 'hamming':
      return 0.54 + 0.46 * Math.cos(x*Math.PI);
    case 'power of sine':
      return Math.cos(x*Math.PI/2) ** windowParameter;
    case 'circle':
    case 'power of circle':
      return Math.sqrt(1 - (x ** 2)) ** windowParameter;
    case 'tapered cosine':
    case 'tukey':
      return Math.abs(x) <= 1-windowParameter ? 1 : 
      (x > 0 ? 
       (-Math.sin((x-1)*Math.PI/windowParameter/2)) ** 2 :
       Math.sin((x+1)*Math.PI/windowParameter/2) ** 2);
    case 'blackman':
      return 0.42 + 0.5 * Math.cos(x*Math.PI) + 0.08 * Math.cos(x*Math.PI*2);
    case 'nuttall':
      return 0.355768 + 0.487396 * Math.cos(x*Math.PI) + 0.144232 * Math.cos(2*x*Math.PI) + 0.012604 * Math.cos(3*x*Math.PI);
    case 'flat top':
    case 'flattop':
      return 0.21557895 + 0.41663158 * Math.cos(x*Math.PI) + 0.277263158 * Math.cos(2*x*Math.PI) + 0.083578947 * Math.cos(3*x*Math.PI) + 0.006947368 * Math.cos(4*x*Math.PI);
    case 'kaiser':
      return Math.cosh(Math.sqrt(1-(x ** 2))*(windowParameter ** 2))/Math.cosh(windowParameter ** 2);
    case 'gauss':
    case 'gaussian':
      return Math.exp(-(windowParameter ** 2)*(x ** 2));
    case 'cosh':
    case 'hyperbolic cosine':
      return Math.E ** (-(windowParameter ** 2)*(Math.cosh(x)-1));
    case 'bartlett':
    case 'triangle':
    case 'triangular':
      return 1 - Math.abs(x);
    case 'poisson':
    case 'exponential':
      return Math.exp(-Math.abs(x * (windowParameter ** 2)));
    case 'hyperbolic secant':
    case 'sech':
      return 1/Math.cosh(x * (windowParameter ** 2));
    case 'quadratic spline':
      return Math.abs(x) <= 0.5 ? -((x*Math.sqrt(2)) ** 2)+1 : (Math.abs(x*Math.sqrt(2))-Math.sqrt(2)) ** 2;
    case 'parzen':
      return Math.abs(x) > 0.5 ? -2 * ((-1 + Math.abs(x)) ** 3) : 1 - 24 * (Math.abs(x/2) ** 2) + 48 * (Math.abs(x/2) ** 3);
    case 'welch':
      return 1 - (x ** 2);
    case 'ogg':
    case 'vorbis':
      return Math.sin(Math.PI/2 * Math.cos(x*Math.PI/2) ** 2);
    case 'cascaded sine':
    case 'cascaded cosine':
    case 'cascaded sin':
    case 'cascaded cos':
      return 1 - Math.sin(Math.PI/2 * Math.sin(x*Math.PI/2) ** 2);
  }
}

/*navigator.mediaDevices.getUserMedia({
  audio: {
    noiseCancellation: false,
    echoCancellation: false,
    autoGainControl: false
  },
  video: false
}).then((stream) => {
  const audioStream = audioCtx.createMediaStreamSource(stream);
  //audioStream.connect(splitter);
  audioStream.connect(analyser);
}).catch((err) => {
  console.log(err);
});*/
              
            
!
999px

Console