Add correlation marker modes
This commit is contained in:
@@ -24,6 +24,7 @@ const BASE_ZOOM = 1.0;
|
||||
const BASE_GONIO_SCALE = (BASE_TARGET / ALIGN_PEAK) * Math.pow(10, -BASE_HEADROOM_DB / 20) * BASE_ZOOM;
|
||||
const AGC_TARGET_DB = linearToDb(ALIGN_PEAK);
|
||||
const CORR_SILENCE_THRESHOLD_DEFAULT = -75;
|
||||
const CORR_HOLD_MS = 4000;
|
||||
const MAX_TRAIL_FRAMES = 48;
|
||||
|
||||
function computePanelSlotWidth(canvasWidth, slotCount = METER_SLOTS, slotGap = 12) {
|
||||
@@ -48,6 +49,10 @@ export function init() {
|
||||
staticLayerCanvas: null,
|
||||
staticLayerCtx: null,
|
||||
staticLayerKey: '',
|
||||
corrNegativeMarkerMode: 'memory',
|
||||
corrHoldPeak: 0,
|
||||
corrHoldUntil: 0,
|
||||
corrResetToken: 0,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -99,9 +104,16 @@ export async function render(env, state) {
|
||||
// Correlation is measured continuously in the audio DSP. Do not add a
|
||||
// second, frame-rate-dependent browser integration here.
|
||||
const corrVisual = Number.isFinite(audio?.correlation) ? clamp1(audio.correlation) : 0;
|
||||
const corrNegativePeak = Number.isFinite(audio?.correlationNegativePeak)
|
||||
const corrMemoryPeak = Number.isFinite(audio?.correlationNegativePeak)
|
||||
? clamp1(audio.correlationNegativePeak)
|
||||
: 0;
|
||||
const corrNegativeMarker = resolveCorrelationNegativeMarker(
|
||||
state,
|
||||
CONFIG,
|
||||
corrVisual,
|
||||
corrMemoryPeak,
|
||||
frameNow,
|
||||
);
|
||||
drawCorrelationBar(
|
||||
g,
|
||||
layout.plot.x + layout.plot.w / 2,
|
||||
@@ -109,7 +121,7 @@ export async function render(env, state) {
|
||||
Math.round(Math.min(layout.scope.w * 0.75, layout.plot.w - 50)),
|
||||
18,
|
||||
corrVisual,
|
||||
corrNegativePeak,
|
||||
corrNegativeMarker,
|
||||
);
|
||||
|
||||
if (slots.length) {
|
||||
@@ -123,6 +135,34 @@ export async function render(env, state) {
|
||||
}
|
||||
}
|
||||
|
||||
export function resolveCorrelationNegativeMarker(state, CONFIG = {}, current = 0, memoryPeak = 0, nowMs = 0) {
|
||||
const requestedMode = String(CONFIG.CORR_NEGATIVE_MARKER_MODE || 'memory').toLowerCase();
|
||||
const mode = ['memory', 'hold', 'off'].includes(requestedMode) ? requestedMode : 'memory';
|
||||
const resetToken = Math.max(0, Math.floor(Number(CONFIG.CORR_RESET_TOKEN) || 0));
|
||||
|
||||
if (state.corrResetToken !== resetToken || state.corrNegativeMarkerMode !== mode) {
|
||||
state.corrResetToken = resetToken;
|
||||
state.corrNegativeMarkerMode = mode;
|
||||
state.corrHoldPeak = 0;
|
||||
state.corrHoldUntil = 0;
|
||||
}
|
||||
|
||||
if (mode === 'off') return 0;
|
||||
if (mode === 'memory') return Math.max(-1, Math.min(1, Number(memoryPeak) || 0));
|
||||
|
||||
const now = Number.isFinite(nowMs) ? nowMs : 0;
|
||||
const currentNegative = Math.min(0, Math.max(-1, Math.min(1, Number(current) || 0)));
|
||||
const holdActive = Number.isFinite(state.corrHoldUntil) && now < state.corrHoldUntil;
|
||||
if (!holdActive) {
|
||||
state.corrHoldPeak = currentNegative;
|
||||
state.corrHoldUntil = currentNegative < -0.001 ? now + CORR_HOLD_MS : 0;
|
||||
} else if (currentNegative < state.corrHoldPeak) {
|
||||
state.corrHoldPeak = currentNegative;
|
||||
state.corrHoldUntil = now + CORR_HOLD_MS;
|
||||
}
|
||||
return Number.isFinite(state.corrHoldPeak) ? state.corrHoldPeak : 0;
|
||||
}
|
||||
|
||||
function drawStaticLayer(g, state, rect, layout, CONFIG, slotCount) {
|
||||
const layer = ensureStaticLayer(state, rect, layout, CONFIG, slotCount);
|
||||
if (!layer) {
|
||||
|
||||
Reference in New Issue
Block a user