From 41b24dabb29ec39a23314cc2138e0cd079faf9da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20B=C3=A4dorf?= Date: Fri, 7 Jun 2019 20:09:24 +0200 Subject: [PATCH] Added thresholds --- src/index.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/index.js b/src/index.js index bd48cca..faf77c0 100644 --- a/src/index.js +++ b/src/index.js @@ -2,6 +2,7 @@ import p5 from 'p5'; import './index.scss'; const FFT_SIZE = 256; +const VOLUME_THRESHOLD = 20; function getRMS(spectrum) { let rms = 0; @@ -85,12 +86,15 @@ async function main() { fresh = false; sketch.background(sketch.color(0, 0, 0)); - bars.push({ - x: getRandomX(), - volume, - pitch, - age: 1, - }); + if (volume > VOLUME_THRESHOLD) { + bars.push({ + x: getRandomX(), + volume, + pitch, + age: 1, + }); + } + const newBars = []; for (const bar of bars) { sketch.fill(sketch.color(0, (bar.volume / volumeThreshold) * 255, 255));