Revert "Smooth realtime display frame pacing"

This reverts commit a8e9729b3a.
This commit is contained in:
Mikei386
2026-08-05 20:54:33 +02:00
parent 96d323c32d
commit ab19798a2d
5 changed files with 20 additions and 59 deletions
+14 -17
View File
@@ -26,6 +26,7 @@ let lifecycleHandlersBound = false;
let recoverTimer = null;
let lastHardRecoverAt = 0;
let pendingPhoenixFrame = null;
let phoenixPacketRaf = 0;
let phoenixPacketBusy = false;
const RMS_RING = { L: new Float32Array(512), R: new Float32Array(512), i: 0, n: 0 };
@@ -124,6 +125,8 @@ function closePhoenixSocket() {
if (phoenixVisualsRaf) cancelAnimationFrame(phoenixVisualsRaf);
phoenixVisualsRaf = 0;
pendingPhoenixFrame = null;
if (phoenixPacketRaf) cancelAnimationFrame(phoenixPacketRaf);
phoenixPacketRaf = 0;
phoenixPacketBusy = false;
}
@@ -429,6 +432,7 @@ async function applyIncomingAudioPacket(env, packet, CONFIG, sampleTs = performa
const previousSeq = Number(env.audio.phoenixMetricsSeq || 0);
if (Number.isFinite(seq) && seq > 0 && previousSeq > 0 && seq <= previousSeq) return;
if (Number.isFinite(seq) && seq > 0) env.audio.phoenixMetricsSeq = seq;
env.requestRender?.('audio');
env.audio.lastSampleTs = sampleTs;
env.audio.alive = true;
if (Number.isFinite(Number(d.sampleRate)) && Number(d.sampleRate) > 0) {
@@ -483,10 +487,6 @@ async function applyIncomingAudioPacket(env, packet, CONFIG, sampleTs = performa
}
await updateActiveMeters(env, d, CONFIG);
// Publish the frame only after every active meter has consumed the packet.
// Otherwise the canvas loop can draw between the data update and the meter
// update, producing an old frame followed by a visible catch-up step.
env.requestRender?.('audio');
}
function buildPhoenixMeterPacket(frame) {
@@ -627,26 +627,23 @@ function mergePendingPhoenixFrame(previous, next) {
}
function schedulePhoenixPacketPump(env, CONFIG) {
if (phoenixPacketBusy || !pendingPhoenixFrame) return;
phoenixPacketBusy = true;
void (async () => {
if (phoenixPacketRaf || phoenixPacketBusy || !pendingPhoenixFrame) return;
phoenixPacketRaf = requestAnimationFrame(async () => {
phoenixPacketRaf = 0;
const frame = pendingPhoenixFrame;
pendingPhoenixFrame = null;
if (!frame) return;
phoenixPacketBusy = true;
try {
// Consume the newest packet immediately. Incoming packets are still
// coalesced while an asynchronous meter/config update is in progress,
// but they no longer wait for a second requestAnimationFrame loop.
while (pendingPhoenixFrame) {
const frame = pendingPhoenixFrame;
pendingPhoenixFrame = null;
const packet = buildPhoenixMeterPacket(frame);
await applyIncomingAudioPacket(env, packet, CONFIG, performance.now());
}
const packet = buildPhoenixMeterPacket(frame);
await applyIncomingAudioPacket(env, packet, CONFIG, performance.now());
} catch (err) {
console.warn('Phoenix packet error:', err);
} finally {
phoenixPacketBusy = false;
if (pendingPhoenixFrame) schedulePhoenixPacketPump(env, CONFIG);
}
})();
});
}
function enqueuePhoenixFrame(env, CONFIG, frame) {
+2 -8
View File
@@ -2698,20 +2698,14 @@ async function loop(now){
const currentAudioSeq = Math.max(currentMetricsSeq, currentVisualsSeq, currentXySeq);
const audioDirty = currentAudioSeq > lastRenderedAudioSeq;
const shouldRenderFrame =
audioOk ||
renderDirty ||
audioDirty ||
!audioOk ||
style === 'options-panel' ||
style === 'recorder' ||
renderStyle === 'clock';
// With live audio, requestAnimationFrame itself is the display clock. An
// additional exact 60 Hz comparison occasionally rejected a real 60 Hz
// frame because of fractional timestamp jitter, creating 33 ms pauses in
// otherwise smooth peak decay. Only throttle the disconnected state.
const frameDue = audioOk || elapsed >= target;
if (frameDue){
lastFrameTime = audioOk ? now : now - (elapsed % targetMs);
if (elapsed >= target){
lastFrameTime = now - (elapsed % targetMs);
try{
updateRect();
meterHitRects.length = 0;