Add RTA hold and fall mode

This commit is contained in:
Mikei386
2026-07-22 09:09:04 +02:00
parent 3a0bdbb5ad
commit fbcafd43f9
10 changed files with 83 additions and 20 deletions
+7 -1
View File
@@ -21,6 +21,7 @@ const STATIC_STROKE_PAD = 2;
const PEAK_HOLD_MAP = new Map(Object.entries({
off: 0,
auto: null,
fall: null,
'1s': 1,
'2s': 2,
'4s': 4,
@@ -290,6 +291,7 @@ function buildConfigSignature(CONFIG, nyq, binCount) {
CONFIG.RTA_INTEGRATION,
CONFIG.RTA_PEAK_HOLD_MODE,
CONFIG.RTA_PEAK_HOLD_SEC,
CONFIG.RTA_PEAK_DECAY_DB_PER_S,
CONFIG.RTA_PEAK_RESET_TOKEN,
CONFIG.RTA_DISPLAY_HOLD_SEC,
CONFIG.REALTIME_RENDER_STYLE,
@@ -413,13 +415,15 @@ function applyIntegration(state, levels, CONFIG, range) {
}
function applyPeakHold(state, levels, CONFIG, range) {
const mode = CONFIG.RTA_PEAK_HOLD_MODE || 'auto';
const mode = CONFIG.RTA_PEAK_HOLD_MODE || 'fall';
const len = levels.length;
const mapped = PEAK_HOLD_MAP.get(mode);
const holdSec = Number.isFinite(mapped)
? Math.max(0, mapped)
: Math.max(0, Number(CONFIG.RTA_PEAK_HOLD_SEC) || 0);
const decayRate = Math.max(0, Number(CONFIG.RTA_PEAK_DECAY_DB_PER_S) || 20);
const now = performance.now();
const dt = Math.max(0, (now - (state.holdSampleTs || now)) / 1000);
state.holdSampleTs = now;
if (!state.peakHold || state.peakHold.length !== len) {
@@ -445,6 +449,8 @@ function applyPeakHold(state, levels, CONFIG, range) {
if (mode === 'auto' && (now - (state.lastPeakTime[i] || 0)) >= holdSec * 1000) {
buffer[i] = current;
state.lastPeakTime[i] = now;
} else if (mode === 'fall' && (now - (state.lastPeakTime[i] || 0)) >= holdSec * 1000) {
buffer[i] = Math.max(current, buffer[i] - decayRate * dt);
}
buffer[i] = clamp(buffer[i], range.bottom, range.top);
}