mirror of
https://codeberg.org/armin/noiz.git
synced 2026-09-01 05:50:52 +02:00
fix: use logarithmic frequency mapping for analyzer bars
This commit is contained in:
parent
9d82535024
commit
31aff8672d
1 changed files with 6 additions and 2 deletions
|
|
@ -455,9 +455,13 @@ function drawSpectrum() {
|
||||||
const maxBin = Math.min(binCount, Math.floor(19000 * fftSize / sampleRate));
|
const maxBin = Math.min(binCount, Math.floor(19000 * fftSize / sampleRate));
|
||||||
const NUM_BARS = 32;
|
const NUM_BARS = 32;
|
||||||
const barMags = new Float32Array(NUM_BARS);
|
const barMags = new Float32Array(NUM_BARS);
|
||||||
|
const minFreq = 20;
|
||||||
|
const maxFreq = 19000;
|
||||||
for (let b = 0; b < NUM_BARS; b++) {
|
for (let b = 0; b < NUM_BARS; b++) {
|
||||||
const start = 1 + Math.floor(b * (maxBin - 1) / NUM_BARS);
|
const lowFreq = minFreq * Math.pow(maxFreq / minFreq, b / NUM_BARS);
|
||||||
const end = 1 + Math.floor((b + 1) * (maxBin - 1) / NUM_BARS);
|
const highFreq = minFreq * Math.pow(maxFreq / minFreq, (b + 1) / NUM_BARS);
|
||||||
|
const start = 1 + Math.floor(lowFreq * fftSize / sampleRate);
|
||||||
|
const end = 1 + Math.min(maxBin, Math.ceil(highFreq * fftSize / sampleRate));
|
||||||
let sum = 0;
|
let sum = 0;
|
||||||
for (let j = start; j < end; j++) sum += mags[j];
|
for (let j = start; j < end; j++) sum += mags[j];
|
||||||
barMags[b] = sum / (end - start);
|
barMags[b] = sum / (end - start);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue