mirror of
https://codeberg.org/armin/noiz.git
synced 2026-09-01 14:00:54 +02:00
fix: blend linear/log frequency mapping with blend=0.4
This commit is contained in:
parent
31aff8672d
commit
ae3943aab0
1 changed files with 7 additions and 2 deletions
|
|
@ -457,11 +457,16 @@ function drawSpectrum() {
|
|||
const barMags = new Float32Array(NUM_BARS);
|
||||
const minFreq = 20;
|
||||
const maxFreq = 19000;
|
||||
const blend = 0.4;
|
||||
for (let b = 0; b < NUM_BARS; b++) {
|
||||
const lowFreq = minFreq * Math.pow(maxFreq / minFreq, b / 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));
|
||||
const logStart = 1 + Math.floor(lowFreq * fftSize / sampleRate);
|
||||
const logEnd = 1 + Math.min(maxBin, Math.ceil(highFreq * fftSize / sampleRate));
|
||||
const linStart = 1 + Math.floor(b * (maxBin - 1) / NUM_BARS);
|
||||
const linEnd = 1 + Math.floor((b + 1) * (maxBin - 1) / NUM_BARS);
|
||||
const start = Math.round(linStart + (logStart - linStart) * blend);
|
||||
const end = Math.round(linEnd + (logEnd - linEnd) * blend);
|
||||
let sum = 0;
|
||||
for (let j = start; j < end; j++) sum += mags[j];
|
||||
barMags[b] = sum / (end - start);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue