diff --git a/app/static/js/app.jsx b/app/static/js/app.jsx index 5063a67..4346977 100644 --- a/app/static/js/app.jsx +++ b/app/static/js/app.jsx @@ -20988,8 +20988,9 @@ const App = () => { // M23 Bug C: PWR OFF giua play — giu PDC (dry = content, khong // jump/scratch) + rebase display ve content de warm display lien // tuc (khong nhay +lat nhu M22). + let _plNow = false; try { - const _plNow = !!(isPlayingRef && isPlayingRef.current) || !!(subTabsRef && subTabsRef.current && subTabsRef.current.some(s => s && s.isPlaying)); + _plNow = !!(isPlayingRef && isPlayingRef.current) || !!(subTabsRef && subTabsRef.current && subTabsRef.current.some(s => s && s.isPlaying)); if (_plNow) { fxRtWarmPlayHold = true; const _c2 = getAudioContext(); @@ -21009,6 +21010,38 @@ const App = () => { } } catch (e) { try { _dbgLog('ph_offhold', 'err ' + String(e)); } catch (e2) {} } fxRtWarmBypass(); + // M26 diag: PWR OFF mid-play — snap pdcDelay/gains + hoi worklet + // state tai t0/+180/+400/+800ms de do: pdc thuc te khi dry mo, + // wet tail song bao lau, gains ramp ra sao. Bo diag o build fix. + if (_plNow) { + const _busB = masterBus; + const _ctxB = getAudioContext(); + const _snapB = (k) => { + let _pdB = 'na', _gdB = 'na', _gwB = 'na', _psB = 'na', _paB = 'na'; + try { if (_busB && _busB.pdcDelay) _pdB = (_busB.pdcDelay.delayTime.value * 1000).toFixed(1); } catch (e) {} + try { if (_busB && _busB.masterFxDryGain) _gdB = _busB.masterFxDryGain.gain.value.toFixed(4); } catch (e) {} + try { if (_busB && _busB.masterFxGain) _gwB = _busB.masterFxGain.gain.value.toFixed(4); } catch (e) {} + try { _psB = typeof fxRt.processedSamples === 'number' ? fxRt.processedSamples : 'na'; } catch (e) {} + try { _paB = typeof fxRt.processedAnchor === 'number' ? fxRt.processedAnchor : 'na'; } catch (e) {} + const _oB = startOffsetTimeRef.current || 0; + const _aB = startAudioTimeRef.current || 0; + const _tB = _ctxB ? _ctxB.currentTime : 0; + _dbgLog('ph_echo' + k, 'pdcMs=' + _pdB + ' gDry=' + _gdB + ' gWet=' + _gwB + ' lat=' + (fxRt.latencyTotal || 0) + ' ps=' + _psB + ' pa=' + _paB + ' cur=' + (currentTimeRef.current == null ? 'na' : currentTimeRef.current.toFixed(3)) + ' off=' + _oB.toFixed(3) + ' wall=' + (_oB + _tB - _aB).toFixed(3) + ' ctx=' + _tB.toFixed(3)); + try { if (fxRt.node && fxRt.node.port) fxRt.node.port.postMessage({ type: 'dbg_state', k: k }); } catch (e) {} + }; + const _wlB = (ev) => { + try { + const d = ev.data; + if (d && d.type === 'dbg_state_r') { + _dbgLog('ph_echo_wl', 'k=' + d.k + ' t=' + d.t + ' q=' + d.q + ' play=' + d.playing + ' hs=' + d.hasStarted + ' sil=' + d.silenced + ' fp=' + d.flushPending + ' stp=' + d.stopped + ' wm=' + d.wrapMode + ' wfb=' + d.wrapFadeBlocks + ' lat=' + d.latencySamples + ' rfill=' + d.resumeFill + ' inC=' + d.inCount + ' outPos=' + d.outPos + ' fadeL=' + d.fadeLeft + ' holdL=' + d.holdFadeLeft); + } + } catch (e) {} + }; + try { if (fxRt.node && fxRt.node.port) fxRt.node.port.addEventListener('message', _wlB); } catch (e) {} + _snapB(0); + [180, 400, 800].forEach((_msB, _iB) => setTimeout(() => _snapB(_iB + 1), _msB)); + setTimeout(() => { try { if (fxRt.node && fxRt.node.port) fxRt.node.port.removeEventListener('message', _wlB); } catch (e) {} }, 1600); + } } } else { fxRtStop(); diff --git a/app/static/js/app.precompiled.js b/app/static/js/app.precompiled.js index 1cb717f..e32a32b 100644 --- a/app/static/js/app.precompiled.js +++ b/app/static/js/app.precompiled.js @@ -390,7 +390,7 @@ else if(data instanceof ArrayBuffer)this._worker.postMessage({kind:'send',buf:da // SecurityError -> fxRtStart chet -> master FX khong hoat dong (M24 dung // new WebSocket, khong bi same-origin). Fetch text qua engine (CORS * da bat) // -> Blob URL same-origin -> worker chay duoc ca Tauri lan http dev. -try{if(!fxRtWorkerUrl){const _r=await fetch(`${API_BASE_URL}/static/js/fx-rt-worker.js?v=202609071534`,{cache:'no-store'});if(!_r.ok)throw new Error('fx-rt-worker load '+_r.status);fxRtWorkerUrl=URL.createObjectURL(new Blob([await _r.text()],{type:'text/javascript'}));}shim._worker=new Worker(fxRtWorkerUrl);}catch(e){throw e;}// giong ws constructor that -> caller catch cu giu nguyen +try{if(!fxRtWorkerUrl){const _r=await fetch(`${API_BASE_URL}/static/js/fx-rt-worker.js?v=202609060930`,{cache:'no-store'});if(!_r.ok)throw new Error('fx-rt-worker load '+_r.status);fxRtWorkerUrl=URL.createObjectURL(new Blob([await _r.text()],{type:'text/javascript'}));}shim._worker=new Worker(fxRtWorkerUrl);}catch(e){throw e;}// giong ws constructor that -> caller catch cu giu nguyen shim._worker.onmessage=ev=>{const d=ev.data;if(!d||shim._closed)return;if(d.kind==='open'){shim.readyState=1;if(shim.onopen){try{shim.onopen();}catch(e){}}return;}if(d.kind==='close'){_fireClose(shim);return;}if(d.kind==='text'){if(shim.onmessage){try{shim.onmessage({data:d.text});}catch(e){}}}};shim._worker.onerror=()=>_fireClose(shim);try{shim._worker.postMessage({kind:'init',wsUrl,port:directPort||undefined},directPort?[directPort]:[]);}catch(e){}return shim;}async function fxRtStart(){// V21: mọi play/chain-change gọi đây — hủy idle timer của lần stop trước // (không để session warm bị teardown giữa lúc đang chơi). if(fxRtWarmIdleTimer){clearTimeout(fxRtWarmIdleTimer);fxRtWarmIdleTimer=null;}const chain=fxRtChain();const ck=fxRtChainKey(chain);const ckStruct=fxRtChainStructKey(chain);if(fxRt.active){// masterBus bị rebuild (recovery/export) → node thuộc graph cũ → restart. @@ -438,7 +438,7 @@ if(fxRt.warm)fxRtStop(true);// Token chống race bypass: user bấm PWR/Bypass // node → bypass vô hiệu. Mỗi fxRtStop() bump startToken → mọi checkpoint // dưới đây thấy mismatch → hủy session vừa tạo, không nối node. const token=++fxRt.startToken;fxRt.starting=true;const ctx=getAudioContext();if(!ctx||!ctx.audioWorklet||!masterBus||!masterBus.output||!masterBus.analyser||!masterBus.masterFxGain||!masterBus.masterFxDryGain)return;const chainPayload=chain.map(s=>s.type==='vst3'?{type:'vst3',path:s.path,name:s.name||s.path,preset_b64:s.preset_b64||'',bypass:!!s.bypass||!!(window.currentMasteringSettings||{}).vstBypass}:{type:'builtin',id:s.type,params:s.params&&Object.keys(s.params).length?s.params:{},bypass:!!s.bypass});let st;try{st=await window.SonicAPI.fxRealtimeStart({fx_chain:chainPayload,sample_rate:ctx.sampleRate||44100});}catch(e){console.warn('[FX RT] start fail:',e);showToast('Không khởi động VST FX realtime: '+(e.message||e),'warning');fxRt.starting=false;return;}if(token!==fxRt.startToken){// Bypass/stop giữa lúc engine đang load chain — hủy session vừa tạo. -console.warn('[FX RT] start cancelled mid-flight — session stopped');try{window.SonicAPI.fxRealtimeStop({session_id:st.session_id}).catch(()=>{});}catch(e2){}fxRt.starting=false;return;}fxRt.sessionId=st.session_id;fxRtGuiPushShm();try{await ctx.audioWorklet.addModule(`${API_BASE_URL}/static/js/sf-fx-realtime.js?v=202609071534`);if(token!==fxRt.startToken){fxRt.starting=false;return;}fxRt.node=new AudioWorkletNode(ctx,'sf-fx-realtime',{numberOfInputs:1,numberOfOutputs:1,outputChannelCount:[2]});const u=new URL(API_BASE_URL);const wsProto=u.protocol==='https:'?'wss://':'ws://';// WS to 'localhost' bi tre ~300ms: Chromium thu ::1 truoc (Windows khong +console.warn('[FX RT] start cancelled mid-flight — session stopped');try{window.SonicAPI.fxRealtimeStop({session_id:st.session_id}).catch(()=>{});}catch(e2){}fxRt.starting=false;return;}fxRt.sessionId=st.session_id;fxRtGuiPushShm();try{await ctx.audioWorklet.addModule(`${API_BASE_URL}/static/js/sf-fx-realtime.js?v=202609060930`);if(token!==fxRt.startToken){fxRt.starting=false;return;}fxRt.node=new AudioWorkletNode(ctx,'sf-fx-realtime',{numberOfInputs:1,numberOfOutputs:1,outputChannelCount:[2]});const u=new URL(API_BASE_URL);const wsProto=u.protocol==='https:'?'wss://':'ws://';// WS to 'localhost' bi tre ~300ms: Chromium thu ::1 truoc (Windows khong // co listener IPv6 -> SYN hang ~2s) roi moi fallback 127.0.0.1. Dung // thang 127.0.0.1 (loopback) -> WS open ~5ms. Server chap nhan loopback. const wsHost=u.hostname==='localhost'||u.hostname==='::1'?'127.0.0.1'+(u.port?':'+u.port:''):u.host;const tok=localStorage.getItem('sonic_token')||'';const wsUrl=`${wsProto}${wsHost}${st.ws_url}${tok?'?token='+encodeURIComponent(tok):''}`;// M25: WS chay tren Web Worker - binary output/input di THANG @@ -1737,7 +1737,10 @@ const _guiVst=masteringSettings.gui_open_path&&(masteringSettings.chain||[]).som const _hasVst=!!(masteringSettings.gui_open_path&&(masteringSettings.chain||[]).some(x=>x&&x.type==='vst3'&&x.path===masteringSettings.gui_open_path&&x.active!==false));if(fxRt.active||fxRt.starting||fxRt.warm){if(_hasVst&&fxRt.sessionId&&(fxRt.active||fxRt.warm)){if(fxRt.active){// M23 Bug C: PWR OFF giua play — giu PDC (dry = content, khong // jump/scratch) + rebase display ve content de warm display lien // tuc (khong nhay +lat nhu M22). -try{const _plNow=!!(isPlayingRef&&isPlayingRef.current)||!!(subTabsRef&&subTabsRef.current&&subTabsRef.current.some(s=>s&&s.isPlaying));if(_plNow){fxRtWarmPlayHold=true;const _c2=getAudioContext();const _sr2=_c2.sampleRate||44100;const _off2=startOffsetTimeRef.current||0;const _at2=startAudioTimeRef.current||_c2.currentTime;const _eng2=typeof fxRt.processedSamples==='number'&&fxRt.processedAnchor!=null?Math.max(_off2,_off2+(fxRt.processedSamples-fxRt.processedAnchor-(fxRt.latencyTotal||0))/_sr2):null;const _wall2=_off2+(_c2.currentTime-_at2);const _content2=_eng2!==null?_eng2:_wall2-(fxRt.latencyTotal||0)/_sr2;startOffsetTimeRef.current=_content2;startAudioTimeRef.current=_c2.currentTime;_dbgLog('ph_offhold','cur='+(currentTimeRef.current==null?'na':currentTimeRef.current.toFixed(3))+' wall='+_wall2.toFixed(3)+' content='+_content2.toFixed(3)+' off='+startOffsetTimeRef.current.toFixed(3)+' at='+startAudioTimeRef.current.toFixed(3)+' ctx='+_c2.currentTime.toFixed(3)+' lat='+(fxRt.latencyTotal||0)+' hold=1');}else{_dbgLog('ph_offhold','cur='+(currentTimeRef.current==null?'na':currentTimeRef.current.toFixed(3))+' hold=0');}}catch(e){try{_dbgLog('ph_offhold','err '+String(e));}catch(e2){}}fxRtWarmBypass();}}else{fxRtStop();}}}}catch(e){console.warn('[FX RT] resync fail:',e);}// Re-sync live track routes: mastering ON → mọi track qua chain (♪ bị +let _plNow=false;try{_plNow=!!(isPlayingRef&&isPlayingRef.current)||!!(subTabsRef&&subTabsRef.current&&subTabsRef.current.some(s=>s&&s.isPlaying));if(_plNow){fxRtWarmPlayHold=true;const _c2=getAudioContext();const _sr2=_c2.sampleRate||44100;const _off2=startOffsetTimeRef.current||0;const _at2=startAudioTimeRef.current||_c2.currentTime;const _eng2=typeof fxRt.processedSamples==='number'&&fxRt.processedAnchor!=null?Math.max(_off2,_off2+(fxRt.processedSamples-fxRt.processedAnchor-(fxRt.latencyTotal||0))/_sr2):null;const _wall2=_off2+(_c2.currentTime-_at2);const _content2=_eng2!==null?_eng2:_wall2-(fxRt.latencyTotal||0)/_sr2;startOffsetTimeRef.current=_content2;startAudioTimeRef.current=_c2.currentTime;_dbgLog('ph_offhold','cur='+(currentTimeRef.current==null?'na':currentTimeRef.current.toFixed(3))+' wall='+_wall2.toFixed(3)+' content='+_content2.toFixed(3)+' off='+startOffsetTimeRef.current.toFixed(3)+' at='+startAudioTimeRef.current.toFixed(3)+' ctx='+_c2.currentTime.toFixed(3)+' lat='+(fxRt.latencyTotal||0)+' hold=1');}else{_dbgLog('ph_offhold','cur='+(currentTimeRef.current==null?'na':currentTimeRef.current.toFixed(3))+' hold=0');}}catch(e){try{_dbgLog('ph_offhold','err '+String(e));}catch(e2){}}fxRtWarmBypass();// M26 diag: PWR OFF mid-play — snap pdcDelay/gains + hoi worklet +// state tai t0/+180/+400/+800ms de do: pdc thuc te khi dry mo, +// wet tail song bao lau, gains ramp ra sao. Bo diag o build fix. +if(_plNow){const _busB=masterBus;const _ctxB=getAudioContext();const _snapB=k=>{let _pdB='na',_gdB='na',_gwB='na',_psB='na',_paB='na';try{if(_busB&&_busB.pdcDelay)_pdB=(_busB.pdcDelay.delayTime.value*1000).toFixed(1);}catch(e){}try{if(_busB&&_busB.masterFxDryGain)_gdB=_busB.masterFxDryGain.gain.value.toFixed(4);}catch(e){}try{if(_busB&&_busB.masterFxGain)_gwB=_busB.masterFxGain.gain.value.toFixed(4);}catch(e){}try{_psB=typeof fxRt.processedSamples==='number'?fxRt.processedSamples:'na';}catch(e){}try{_paB=typeof fxRt.processedAnchor==='number'?fxRt.processedAnchor:'na';}catch(e){}const _oB=startOffsetTimeRef.current||0;const _aB=startAudioTimeRef.current||0;const _tB=_ctxB?_ctxB.currentTime:0;_dbgLog('ph_echo'+k,'pdcMs='+_pdB+' gDry='+_gdB+' gWet='+_gwB+' lat='+(fxRt.latencyTotal||0)+' ps='+_psB+' pa='+_paB+' cur='+(currentTimeRef.current==null?'na':currentTimeRef.current.toFixed(3))+' off='+_oB.toFixed(3)+' wall='+(_oB+_tB-_aB).toFixed(3)+' ctx='+_tB.toFixed(3));try{if(fxRt.node&&fxRt.node.port)fxRt.node.port.postMessage({type:'dbg_state',k:k});}catch(e){}};const _wlB=ev=>{try{const d=ev.data;if(d&&d.type==='dbg_state_r'){_dbgLog('ph_echo_wl','k='+d.k+' t='+d.t+' q='+d.q+' play='+d.playing+' hs='+d.hasStarted+' sil='+d.silenced+' fp='+d.flushPending+' stp='+d.stopped+' wm='+d.wrapMode+' wfb='+d.wrapFadeBlocks+' lat='+d.latencySamples+' rfill='+d.resumeFill+' inC='+d.inCount+' outPos='+d.outPos+' fadeL='+d.fadeLeft+' holdL='+d.holdFadeLeft);}}catch(e){}};try{if(fxRt.node&&fxRt.node.port)fxRt.node.port.addEventListener('message',_wlB);}catch(e){}_snapB(0);[180,400,800].forEach((_msB,_iB)=>setTimeout(()=>_snapB(_iB+1),_msB));setTimeout(()=>{try{if(fxRt.node&&fxRt.node.port)fxRt.node.port.removeEventListener('message',_wlB);}catch(e){}},1600);}}}else{fxRtStop();}}}}catch(e){console.warn('[FX RT] resync fail:',e);}// Re-sync live track routes: mastering ON → mọi track qua chain (♪ bị // override bởi effMidiBypass/effAudioBypass) — nút PWR bật/tắt phải áp // ngay lên node đang phát (không chờ tracks effect). try{const _list=activeTracksRef.current&&activeTracksRef.current.length?activeTracksRef.current:tracks;_list.forEach(_t=>{const _n=activeTrackNodesRef.current[_t.id];if(_n){if(_n.sfRouteGain&&_n.sfDryGain){const _b=effMidiBypass(_t);_n.sfRouteGain.gain.value=_b?0:1;_n.sfDryGain.gain.value=_b?1:0;}if(_n.route&&_n.route.routeGain&&_n.route.dryGain){const _ab=routeBypassFor(_t);_n.route.routeGain.gain.value=_ab?0:1;_n.route.dryGain.gain.value=_ab?1:0;}}});// Sub-nodes (section tabs, key '_sub_'): PWR master ON → @@ -2245,7 +2248,7 @@ fxRtTrackReconcile(trackId,node,track);}catch(e){console.warn('rebuildTrackFxGra // Cần activeTrackNodesRef/isPlayingRef. Session giống master (fxRtStart): // fetch start → AudioWorkletNode 'sf-fx-realtime' → WS; WS open → splice // worklet vào chain hiện tại (đọc mods MỚI NHẤT — an toàn với rebuild). -const fxRtTrackStart=async(trackId,track,path)=>{const key=trackId+':'+path;const chain=fxRtTrackChain(track);if(!chain.length)return;if(fxRtTracks[key]){if(!fxRtTracks[key].node||fxRtTracks[key].node.context!==getAudioContext())fxRtTrackStop(trackId,path,true);else return;}const ctx=getAudioContext();if(!ctx||!ctx.audioWorklet)return;const chainPayload=chain.map(s=>s.type==='vst3'?{type:'vst3',path:s.path,name:s.name||s.path,preset_b64:s.preset_b64||'',bypass:!!s.bypass||!!(track&&track.vstFxBypass)}:{type:'builtin',id:s.type,params:s.params&&Object.keys(s.params).length?s.params:{},bypass:!!s.bypass});let st;try{st=await window.SonicAPI.fxRealtimeStart({fx_chain:chainPayload,sample_rate:ctx.sampleRate||44100});}catch(e){console.warn('[FX RT track] start fail',trackId,path,e);return;}const entry={sessionId:st.session_id,ws:null,node:null,ready:false,path,spliced:null,chainKey:fxRtTrackChainKey(chain)+'|vb:'+(track&&track.vstFxBypass?'1':'0'),paramsBySlot:chain.map(s=>fxRtEntryParams(s,null)),inQueue:[],pumpTimer:null,lastInSent:0,flushing:false,flushTimer:null};fxRtTracks[key]=entry;fxRtGuiPushShm();try{await ctx.audioWorklet.addModule(`${API_BASE_URL}/static/js/sf-fx-realtime.js?v=202609071534`);const node=new AudioWorkletNode(ctx,'sf-fx-realtime',{numberOfInputs:1,numberOfOutputs:1,outputChannelCount:[2]});entry.node=node;const u=new URL(API_BASE_URL);const wsProto=u.protocol==='https:'?'wss://':'ws://';// WS to 'localhost' bi tre ~300ms (Chromium thu ::1 truoc roi fallback) - dung 127.0.0.1 +const fxRtTrackStart=async(trackId,track,path)=>{const key=trackId+':'+path;const chain=fxRtTrackChain(track);if(!chain.length)return;if(fxRtTracks[key]){if(!fxRtTracks[key].node||fxRtTracks[key].node.context!==getAudioContext())fxRtTrackStop(trackId,path,true);else return;}const ctx=getAudioContext();if(!ctx||!ctx.audioWorklet)return;const chainPayload=chain.map(s=>s.type==='vst3'?{type:'vst3',path:s.path,name:s.name||s.path,preset_b64:s.preset_b64||'',bypass:!!s.bypass||!!(track&&track.vstFxBypass)}:{type:'builtin',id:s.type,params:s.params&&Object.keys(s.params).length?s.params:{},bypass:!!s.bypass});let st;try{st=await window.SonicAPI.fxRealtimeStart({fx_chain:chainPayload,sample_rate:ctx.sampleRate||44100});}catch(e){console.warn('[FX RT track] start fail',trackId,path,e);return;}const entry={sessionId:st.session_id,ws:null,node:null,ready:false,path,spliced:null,chainKey:fxRtTrackChainKey(chain)+'|vb:'+(track&&track.vstFxBypass?'1':'0'),paramsBySlot:chain.map(s=>fxRtEntryParams(s,null)),inQueue:[],pumpTimer:null,lastInSent:0,flushing:false,flushTimer:null};fxRtTracks[key]=entry;fxRtGuiPushShm();try{await ctx.audioWorklet.addModule(`${API_BASE_URL}/static/js/sf-fx-realtime.js?v=202609060930`);const node=new AudioWorkletNode(ctx,'sf-fx-realtime',{numberOfInputs:1,numberOfOutputs:1,outputChannelCount:[2]});entry.node=node;const u=new URL(API_BASE_URL);const wsProto=u.protocol==='https:'?'wss://':'ws://';// WS to 'localhost' bi tre ~300ms (Chromium thu ::1 truoc roi fallback) - dung 127.0.0.1 const wsHost=u.hostname==='localhost'||u.hostname==='::1'?'127.0.0.1'+(u.port?':'+u.port:''):u.host;const tok=localStorage.getItem('sonic_token')||'';const ws=new WebSocket(`${wsProto}${wsHost}${st.ws_url}${tok?'?token='+encodeURIComponent(tok):''}`);entry.ws=ws;ws.binaryType='arraybuffer';ws.onopen=()=>{entry.ready=true;entry.inQueue=[];// bỏ audio stale trước khi WS open — hết lag khởi đầu fxRtTrackSplice(trackId,path);try{(entry.paramsBySlot||[]).forEach((pl,slot)=>pl.forEach(p=>ws.send(JSON.stringify({cmd:'set_param',slot,key:p.key,value:p.value}))));}catch(e){}};ws.onmessage=ev=>{if(typeof ev.data==='string'){try{const d=JSON.parse(ev.data);if(d&&d.cmd==='flush_done'){entry.flushing=false;if(entry.flushTimer){clearTimeout(entry.flushTimer);entry.flushTimer=null;}if(entry.node)entry.node.port.postMessage({type:'flush_done'});}}catch(e){}return;}if(!(ev.data instanceof ArrayBuffer)||!entry.node)return;if(entry.flushing)return;// V24: output stale trong luc flush — drop const f=new Float32Array(ev.data);const half=f.length/2;const l=new Float32Array(half);const r=new Float32Array(half);for(let i=0;ifxRtTrackStop(trackId,path,true);ws.onerror=()=>{try{ws.close();}catch(e){}};entry.node.port.onmessage=ev=>{const d=ev.data;if(!d||!entry.ws)return;if(d.type==='flush'){// V24: nhu master — worklet underrun-resume → flush engine ring diff --git a/app/static/js/sf-fx-realtime.js b/app/static/js/sf-fx-realtime.js index eae363c..2a5ea37 100644 --- a/app/static/js/sf-fx-realtime.js +++ b/app/static/js/sf-fx-realtime.js @@ -84,6 +84,12 @@ class SfFxRealtimeProcessor extends AudioWorkletProcessor { if (d && d.type === 'set_param') { this.port.postMessage(d); return; } if (d && d.type === 'flush_done') { this.flushPending = false; return; } if (d && d.type === 'latency') { this.latencySamples = (d.samples || 0); return; } + if (d && d.type === 'dbg_state') { + // M26 diag: main thread hoi state worklet quanh PWR OFF mid-play — + // do wet tail (queue/playing) + state sau khi cat 2 canh. + this.port.postMessage({ type: 'dbg_state_r', k: (d.k !== undefined ? d.k : -1), t: Math.round(currentTime * 1000), q: this.outQueue.length, playing: this.playing ? 1 : 0, hasStarted: this.hasStarted ? 1 : 0, silenced: this.silenced ? 1 : 0, flushPending: this.flushPending ? 1 : 0, stopped: this.stopped ? 1 : 0, wrapMode: this.wrapMode ? 1 : 0, wrapFadeBlocks: this.wrapFadeBlocks, latencySamples: this.latencySamples || 0, resumeFill: this.resumeFill, inCount: this.inCount, outPos: this.outPos, fadeLeft: this.fadeLeft, holdFadeLeft: this.holdFadeLeft }); + return; + } if (d && d.type === 'flush_for_stop') { // V26: user stop — main thread báo xóa audio tail trong queue (audio đã // xử lí còn phát ~0.3-0.5s sau stop = tiếng "ding"). Fade-out 21ms từ