mirror of
https://codeberg.org/armin/noiz.git
synced 2026-09-01 05:50:52 +02:00
Refactor VU meter peak hold to use direct variable access
This commit is contained in:
parent
0fc4a746bf
commit
45bf10105b
1 changed files with 19 additions and 14 deletions
33
index.html
33
index.html
|
|
@ -583,15 +583,11 @@ function drawSpectrum() {
|
||||||
if (levelR > vuSmoothR) vuSmoothR = levelR; else vuSmoothR = vuSmoothR * vuSmooth + levelR * (1 - vuSmooth);
|
if (levelR > vuSmoothR) vuSmoothR = levelR; else vuSmoothR = vuSmoothR * vuSmooth + levelR * (1 - vuSmooth);
|
||||||
levelL = vuSmoothL;
|
levelL = vuSmoothL;
|
||||||
levelR = vuSmoothR;
|
levelR = vuSmoothR;
|
||||||
function drawVuRow(y, level, peak, hold) {
|
function drawVuRow(y, level) {
|
||||||
const lit = Math.round(level * segCount);
|
const lit = Math.round(level * segCount);
|
||||||
if (level > peak) { peak = level; hold = 0; }
|
|
||||||
else if (hold < vuPeakGrace) { hold++; }
|
|
||||||
else { peak *= 0.990; }
|
|
||||||
for (let i = 0; i < segCount; i++) {
|
for (let i = 0; i < segCount; i++) {
|
||||||
const sx = segLeft + i * (segW + segG);
|
const sx = segLeft + i * (segW + segG);
|
||||||
const on = i < lit;
|
const on = i < lit;
|
||||||
const pi = Math.round(peak * segCount);
|
|
||||||
vuctx.fillStyle = on ? '#84a0c6' : '#1e2132';
|
vuctx.fillStyle = on ? '#84a0c6' : '#1e2132';
|
||||||
vuctx.fillRect(sx, y, segW, rowH);
|
vuctx.fillRect(sx, y, segW, rowH);
|
||||||
if (on) {
|
if (on) {
|
||||||
|
|
@ -601,17 +597,26 @@ function drawSpectrum() {
|
||||||
vuctx.fillStyle = grd;
|
vuctx.fillStyle = grd;
|
||||||
vuctx.fillRect(sx, y, segW, 2);
|
vuctx.fillRect(sx, y, segW, 2);
|
||||||
}
|
}
|
||||||
if (i === pi && peak > 0.05) {
|
|
||||||
vuctx.fillStyle = '#e98989';
|
|
||||||
vuctx.fillRect(sx, y, segW, rowH);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return [peak, hold];
|
|
||||||
}
|
}
|
||||||
const rL = drawVuRow(0, levelL, vuPeakL, vuPeakHoldL);
|
if (levelL > vuPeakL) { vuPeakL = levelL; vuPeakHoldL = 0; }
|
||||||
vuPeakL = rL[0]; vuPeakHoldL = rL[1];
|
else if (vuPeakHoldL < vuPeakGrace) { vuPeakHoldL++; }
|
||||||
const rR = drawVuRow(gap + rowH, levelR, vuPeakR, vuPeakHoldR);
|
else { vuPeakL *= 0.990; }
|
||||||
vuPeakR = rR[0]; vuPeakHoldR = rR[1];
|
if (levelR > vuPeakR) { vuPeakR = levelR; vuPeakHoldR = 0; }
|
||||||
|
else if (vuPeakHoldR < vuPeakGrace) { vuPeakHoldR++; }
|
||||||
|
else { vuPeakR *= 0.990; }
|
||||||
|
drawVuRow(0, levelL);
|
||||||
|
drawVuRow(gap + rowH, levelR);
|
||||||
|
const piL = Math.round(vuPeakL * segCount);
|
||||||
|
const piR = Math.round(vuPeakR * segCount);
|
||||||
|
if (vuPeakL > 0.05) {
|
||||||
|
vuctx.fillStyle = '#e98989';
|
||||||
|
vuctx.fillRect(segLeft + piL * (segW + segG), 0, segW, rowH);
|
||||||
|
}
|
||||||
|
if (vuPeakR > 0.05) {
|
||||||
|
vuctx.fillStyle = '#e98989';
|
||||||
|
vuctx.fillRect(segLeft + piR * (segW + segG), gap + rowH, segW, rowH);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
animId = requestAnimationFrame(drawSpectrum);
|
animId = requestAnimationFrame(drawSpectrum);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue