M20: diag Bug B — log meter dB master OUT (load/fx_click/panel_open + hist 8s + post 1/2/4/8s)

This commit is contained in:
2026-09-07 09:03:23 +07:00
parent e4c678aabd
commit fa6d09ee83
3 changed files with 79 additions and 8 deletions
+65 -1
View File
@@ -272,6 +272,67 @@ const _dbgLog = (tag, extra) => {
}; };
// V29: expose dbg hook cho BridgeAudioNode (worklet state) + helpers. // V29: expose dbg hook cho BridgeAudioNode (worklet state) + helpers.
window.__dbgLog = _dbgLog; window.__dbgLog = _dbgLog;
// M20 Bug B diag: log dB meter master OUT (masterBus.analyser — cùng nguồn
// outPeakText MASTERING PANEL, SAU chain FX) + fader gain state. Hist vòng ~8s
// @250ms (chỉ giữ RAM, không log cho tới khi có event); marker: load (initMasterBus),
// fx_click (nút FX master), panel_open + post 1/2/4/8s (MASTERING PANEL mở) →
// so dB trước/sau để tìm cơ chế Bug B (âm lượng giảm khi mở panel).
let _mdiagHist = [];
let _mdiagTimer = null;
let _mdiagBuf = null;
function _mdiagDb() {
try {
const b = window.masterBus;
if (!b || !b.analyser) return null;
const an = b.analyser;
const len = an.fftSize || 2048;
if (!_mdiagBuf || _mdiagBuf.length < len) _mdiagBuf = new Float32Array(len);
an.getFloatTimeDomainData(_mdiagBuf);
let pk = 0;
for (let i = 0; i < len; i++) { const v = _mdiagBuf[i]; const a = v < 0 ? -v : v; if (a > pk) pk = a; }
return pk < 0.00003 ? -120 : 20 * Math.log10(pk);
} catch (e) { return null; }
}
function _mdiagFader() {
try {
const b = window.masterBus; if (!b) return 'na';
const f = (x) => { try { const n = x && x.gain ? x.gain.value : null; return n === null ? 'na' : n.toFixed(4); } catch (e) { return 'na'; } };
return 'out=' + f(b.output) + ' mute=' + f(b.muteGain) + ' volL=' + f(b.volLGain) + ' volR=' + f(b.volRGain);
} catch (e) { return 'na'; }
}
function _mdiagSample(tag) {
const db = _mdiagDb();
try { _dbgLog('mdiag_' + tag, 'db=' + (db === null ? 'na' : db.toFixed(1)) + ' ' + _mdiagFader()); } catch (e) {}
}
function _mdiagStart() {
if (_mdiagTimer) return;
_mdiagTimer = setInterval(() => {
try {
if (!window.masterBus) return;
_mdiagHist.push(_mdiagDb());
if (_mdiagHist.length > 32) _mdiagHist.shift(); // ~8s @250ms
} catch (e) {}
}, 250);
}
function _mdiagDump() {
try {
for (let i = 0; i < _mdiagHist.length; i++) {
const v = _mdiagHist[i];
_dbgLog('mdiag_hist', 'db=' + (v === null ? 'na' : v.toFixed(1)));
}
} catch (e) {}
}
let _mdiagPostTimer = null;
function _mdiagSchedulePost() {
if (_mdiagPostTimer) clearTimeout(_mdiagPostTimer);
const del = [1000, 2000, 4000, 8000];
let k = 0;
const tick = () => {
if (k >= del.length) return;
_mdiagPostTimer = setTimeout(() => { _mdiagSample('post' + del[k]); k++; tick(); }, del[k]);
};
tick();
}
if (window.PerformanceObserver) { try { new PerformanceObserver((list) => { for (const e of list.getEntries()) _dbgLog('longtask', 'd=' + Math.round(e.duration) + ' s=' + Math.round(e.startTime)); }).observe({ entryTypes: ['longtask'] }); } catch (e) {} } if (window.PerformanceObserver) { try { new PerformanceObserver((list) => { for (const e of list.getEntries()) _dbgLog('longtask', 'd=' + Math.round(e.duration) + ' s=' + Math.round(e.startTime)); }).observe({ entryTypes: ['longtask'] }); } catch (e) {} }
const _dbgBridgeGain = () => { const _dbgBridgeGain = () => {
try { try {
@@ -1324,6 +1385,7 @@ function initMasterBus(ctx) {
masterBus.analyser.connect(ctx.destination); masterBus.analyser.connect(ctx.destination);
window.masterBus = masterBus; window.masterBus = masterBus;
try { _mdiagStart(); setTimeout(() => _mdiagSample('load1'), 1000); setTimeout(() => _mdiagSample('load5'), 5000); } catch (e) {}
// Apply mastering once when the chain is first created (and on the // Apply mastering once when the chain is first created (and on the
// masteringSettings effect for subsequent changes — see useEffect). // masteringSettings effect for subsequent changes — see useEffect).
if (window.currentMasteringSettings) { if (window.currentMasteringSettings) {
@@ -3610,7 +3672,7 @@ const MasterStripConsole = ({ masterVolume, setMasterVolume, masterVolL, setMast
React.createElement("button", { React.createElement("button", {
id: "fxBtn", id: "fxBtn",
className: "btn-daw h-[18px] rounded font-extrabold text-[10px] transition-all", className: "btn-daw h-[18px] rounded font-extrabold text-[10px] transition-all",
onClick: function() { setShowMasteringModal(true); }, onClick: function() { try { _mdiagSample('fx_click'); } catch (e) {} setShowMasteringModal(true); },
title: "Mở MASTER FX CHAIN để chỉnh sửa" title: "Mở MASTER FX CHAIN để chỉnh sửa"
}, "FX"), }, "FX"),
React.createElement("button", { React.createElement("button", {
@@ -14801,6 +14863,8 @@ const MasteringModal = ({ isOpen, onClose, masteringSettings, setMasteringSettin
}, []); }, []);
React.useEffect(() => { React.useEffect(() => {
if (!isOpen) { _autoOpenRef.current.attempt = 0; return; } if (!isOpen) { _autoOpenRef.current.attempt = 0; return; }
// M20 Bug B diag: giá trị meter đúng lúc mở MASTERING PANEL + hist 8s trước + post 1/2/4/8s
try { _mdiagSample('panel_open'); _mdiagDump(); _mdiagSchedulePost(); } catch (e) {}
if (_autoOpenRef.current.timer) { clearTimeout(_autoOpenRef.current.timer); _autoOpenRef.current.timer = null; } if (_autoOpenRef.current.timer) { clearTimeout(_autoOpenRef.current.timer); _autoOpenRef.current.timer = null; }
_autoTryOpen(); _autoTryOpen();
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -51,7 +51,7 @@
<script src="/static/js/services/promptTemplateManager.js?v=202608290945"></script> <script src="/static/js/services/promptTemplateManager.js?v=202608290945"></script>
<script src="/static/js/services/undoRedoEngine.js?v=202608290945"></script> <script src="/static/js/services/undoRedoEngine.js?v=202608290945"></script>
<script src="/static/js/services/chordTheory.js?v=202608290945"></script> <script src="/static/js/services/chordTheory.js?v=202608290945"></script>
<script src="/static/js/app.precompiled.js?v=202609070853202609070713" defer></script> <script src="/static/js/app.precompiled.js?v=202609070903202609070853202609070713" defer></script>
<link rel="stylesheet" href="/static/css/styles.css?v=202608290945"> <link rel="stylesheet" href="/static/css/styles.css?v=202608290945">
<style> <style>
:root { :root {