V23: fix crackle master FX - underrun fade-out tu mau cuoi + crossfade 64 mau o cap-drop/resume
This commit is contained in:
@@ -1848,7 +1848,7 @@ async function fxRtStart() {
|
||||
fxRt.sessionId = st.session_id;
|
||||
fxRtGuiPushShm();
|
||||
try {
|
||||
await ctx.audioWorklet.addModule(`${API_BASE_URL}/static/js/sf-fx-realtime.js?v=202608242000`);
|
||||
await ctx.audioWorklet.addModule(`${API_BASE_URL}/static/js/sf-fx-realtime.js?v=202608312300`);
|
||||
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);
|
||||
@@ -24470,7 +24470,7 @@ const App = () => {
|
||||
fxRtTracks[key] = entry;
|
||||
fxRtGuiPushShm();
|
||||
try {
|
||||
await ctx.audioWorklet.addModule(`${API_BASE_URL}/static/js/sf-fx-realtime.js?v=202608242000`);
|
||||
await ctx.audioWorklet.addModule(`${API_BASE_URL}/static/js/sf-fx-realtime.js?v=202608312300`);
|
||||
const node = new AudioWorkletNode(ctx, 'sf-fx-realtime', { numberOfInputs: 1, numberOfOutputs: 1, outputChannelCount: [2] });
|
||||
entry.node = node;
|
||||
const u = new URL(API_BASE_URL);
|
||||
|
||||
@@ -328,7 +328,7 @@ else if(fxRt.chainKey!==ck){fxRtSetChain(chain);fxRt.chainKey=ck;return;}else re
|
||||
// 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=202608242000`);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://';const tok=localStorage.getItem('sonic_token')||'';const wsUrl=`${wsProto}${u.host}${st.ws_url}${tok?'?token='+encodeURIComponent(tok):''}`;const ws=new WebSocket(wsUrl);fxRt.ws=ws;ws.binaryType='arraybuffer';ws.onopen=()=>{if(token!==fxRt.startToken){try{ws.close();}catch(e){}fxRt.starting=false;return;}fxRt.active=true;fxRt.starting=false;fxRt.inQueue=[];// bỏ audio stale sản xuất trước khi WS open (~4s load VST) — hết lag khởi đầu
|
||||
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=202608312300`);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://';const tok=localStorage.getItem('sonic_token')||'';const wsUrl=`${wsProto}${u.host}${st.ws_url}${tok?'?token='+encodeURIComponent(tok):''}`;const ws=new WebSocket(wsUrl);fxRt.ws=ws;ws.binaryType='arraybuffer';ws.onopen=()=>{if(token!==fxRt.startToken){try{ws.close();}catch(e){}fxRt.starting=false;return;}fxRt.active=true;fxRt.starting=false;fxRt.inQueue=[];// bỏ audio stale sản xuất trước khi WS open (~4s load VST) — hết lag khởi đầu
|
||||
try{fxRtPushAllParams();}catch(e){}};ws.onmessage=ev=>{// Gap 8 (PDC realtime): text frame {cmd:'latency', total} tu server ->
|
||||
// cap nhat delay dry-bypass path (bu latency chain VST3 realtime).
|
||||
if(typeof ev.data==='string'){try{const d=JSON.parse(ev.data);if(d&&d.cmd==='latency'&&typeof d.total==='number'){fxRt.latencyTotal=d.total;// Chi delay dry path khi crossfade da xong (dry silent) — ap som
|
||||
@@ -1826,7 +1826,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};fxRtTracks[key]=entry;fxRtGuiPushShm();try{await ctx.audioWorklet.addModule(`${API_BASE_URL}/static/js/sf-fx-realtime.js?v=202608242000`);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://';const tok=localStorage.getItem('sonic_token')||'';const ws=new WebSocket(`${wsProto}${u.host}${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
|
||||
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};fxRtTracks[key]=entry;fxRtGuiPushShm();try{await ctx.audioWorklet.addModule(`${API_BASE_URL}/static/js/sf-fx-realtime.js?v=202608312300`);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://';const tok=localStorage.getItem('sonic_token')||'';const ws=new WebSocket(`${wsProto}${u.host}${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(!(ev.data instanceof ArrayBuffer)||!entry.node)return;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;i<half;i++){l[i]=f[i*2];r[i]=f[i*2+1];}entry.node.port.postMessage({type:'out',l,r});};ws.onclose=()=>fxRtTrackStop(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==='set_param'){try{entry.ws.send(JSON.stringify({cmd:'set_param',slot:d.slot,key:d.key,value:d.value}));}catch(e){}return;}if(d.type!=='in')return;// Burst 4 block (1024 mẫu) → tách 4 WS frame 512 floats → bridge batch 4.
|
||||
// Pace 1 burst/21ms (giống master) — tránh dồn frame sau stall làm tràn ring.
|
||||
entry.inQueue.push(d);const pump=()=>{if(!entry.inQueue.length)return;const now=Date.now();while(entry.inQueue.length&&now-entry.lastInSent>=FXRT_BURST_MS){entry.lastInSent=now;const dd=entry.inQueue.shift();if(entry.ws&&entry.ws.readyState===1){try{const f=new Float32Array(dd.data);if(f.length>512){for(let i=0;i<f.length;i+=512)entry.ws.send(f.slice(i,i+512).buffer);}else{entry.ws.send(dd.data);}}catch(e){}}}if(entry.inQueue.length){if(entry.pumpTimer)clearTimeout(entry.pumpTimer);entry.pumpTimer=setTimeout(pump,Math.max(1,FXRT_BURST_MS-(now-entry.lastInSent)));}else if(entry.pumpTimer){clearTimeout(entry.pumpTimer);entry.pumpTimer=null;}};pump();};}catch(e){console.warn('[FX RT track] setup fail',trackId,path,e);fxRtTrackStop(trackId,path,true);}};const fxRtTrackUnsplice=(trackId,path)=>{const entry=fxRtTracks[trackId+':'+path];if(!entry||!entry.spliced||!entry.node)return;try{entry.node.disconnect();try{entry.spliced.tail.connect(entry.spliced.dest);}catch(e){}entry.spliced=null;}catch(e){console.warn('[FX RT track] unsplice fail',trackId,path,e);}};// Chain đổi trên session ĐANG CHẠY — set_chain KHÔNG restart (bridge swap
|
||||
|
||||
@@ -16,15 +16,14 @@
|
||||
// realtime) → client tích lũy buffer an toàn; mọi jitter (bridge process VST
|
||||
// biến thiên, GC, WS, main thread rAF) bị hấp thụ bởi FILL thay vì queue ≈1
|
||||
// → cạn → ngắt quãng.
|
||||
// UNDERRUN (queue cạn khi đang phát): KHÔNG zero-fill/re-buffer im lặng — lặp
|
||||
// block cuối tối đa HOLD block (~11ms) giữ âm liên tục (hết click/ngắt), rồi
|
||||
// FADE-OUT HOLD_FADE block (~21ms) gain 1→0 trước khi im lặng nếu stall kéo
|
||||
// dài (hết click cắt cứng — engine không thể gửi fade tới kịp khi main-thread
|
||||
// stall chặn cả 2 hướng); resume NGAY khi có block mới (không đợi đủ FILL),
|
||||
// nếu đang giữa fade-out → fade-in nhanh (hết jump ~0→1) + không re-fade sau
|
||||
// lần đầu (tránh tụt volume).
|
||||
// UNDERRUN (queue cạn khi đang phát): V23 — KHÔNG lặp block cuối (lặp tạo
|
||||
// jump pha ở điểm vào hold + mỗi wrap → click), KHÔNG zero-fill: fade-out
|
||||
// tuyến tính từ mẫu output cuối (HOLD_FADE block ~21ms) tới im lặng; resume
|
||||
// NGAY khi có block mới (không đợi đủ FILL): đã im lặng → fade-in từ 0, đang
|
||||
// giữa fade → crossfade 64 mẫu từ mẫu hiện tại (hết jump). Cap-drop (queue
|
||||
// tràn sau stall) crossfade 64 mẫu (hết click) — giống bridgeAudioWorklet.
|
||||
// Cap 48 block (~256ms) chặn overflow khi bridge nhanh hơn realtime.
|
||||
// ponytail: thay hold bằng adaptive stretch khi cần chất lượng cao.
|
||||
// ponytail: thay fade-out bằng adaptive stretch khi cần chất lượng cao hơn.
|
||||
class SfFxRealtimeProcessor extends AudioWorkletProcessor {
|
||||
constructor() {
|
||||
super();
|
||||
@@ -32,12 +31,8 @@ class SfFxRealtimeProcessor extends AudioWorkletProcessor {
|
||||
this.BURST = 4; // số block gom 1 frame (bridge batch)
|
||||
this.FILL = 48; // 48 block ~256ms: buffer khởi đầu — hấp thụ jitter main-thread (GUI decode, rAF, VST panel)
|
||||
this.CAP = 64; // cap queue chặn overflow (~341ms)
|
||||
this.HOLD = 2; // 2 block ~11ms: lặp block cuối khi underrun (hết click) trước khi im lặng
|
||||
this.HOLD_FADE = 4; // 4 block ~21ms: fade 1→0 sau HOLD hết (hết click cắt cứng)
|
||||
this.lastBlock = null; // block cuối đã phát xong (hold khi underrun)
|
||||
this.holdPos = 0;
|
||||
this.holdLeft = 0;
|
||||
this.holdFadeLeft = 0; // mẫu còn lại của fade-out sau HOLD
|
||||
this.holdFadeLeft = 0; // mẫu còn lại của fade-out khi underrun
|
||||
this.silenced = false; // đã fade về 0 → im lặng; resume phải fade-in, không hold lại
|
||||
this.bufLen = this.BLOCK * this.BURST;
|
||||
this.inL = new Float32Array(this.bufLen);
|
||||
@@ -50,12 +45,31 @@ class SfFxRealtimeProcessor extends AudioWorkletProcessor {
|
||||
this.FADE = 512; // fade-in 512 mẫu (~11ms @48k) khi bắt đầu phát/resume — hết click
|
||||
this.outGain = 0; // gain phát hiện tại (0→1 trong fade)
|
||||
this.fadeLeft = 0; // số mẫu còn lại của fade
|
||||
this.skipFade = 0; // >0: crossfade 64 mẫu đang chạy sau jump (cap-drop/resume) — hết click
|
||||
this.skipFromL = 0.0; // mẫu output tại điểm jump — điểm bắt đầu crossfade
|
||||
this.skipFromR = 0.0;
|
||||
this.lastOutL = 0.0; // mẫu output cuối — nguồn crossfade + điểm bắt đầu fade-out
|
||||
this.lastOutR = 0.0;
|
||||
this.fadeFromL = 0.0; // mẫu cố định khi fade-out underrun (fade tuyến tính tới 0)
|
||||
this.fadeFromR = 0.0;
|
||||
this.port.onmessage = (e) => {
|
||||
const d = e.data;
|
||||
if (d && d.type === 'set_param') { this.port.postMessage(d); return; }
|
||||
if (!d || d.type !== 'out' || !d.l || !d.r) return;
|
||||
this.outQueue.push({ l: d.l, r: d.r });
|
||||
while (this.outQueue.length > this.CAP) { this.outQueue.shift(); this.statCapDrop++; }
|
||||
while (this.outQueue.length > this.CAP) {
|
||||
this.outQueue.shift();
|
||||
this.statCapDrop++;
|
||||
// V23: drop cứng = jump mẫu → click. Crossfade 64 mẫu từ mẫu output
|
||||
// cuối sang block mới; chỉ đặt 1 lần cho đợt drop liên tiếp. outPos=0:
|
||||
// block mới (front) phải phát từ đầu, không tiếp tục vị trí block cũ.
|
||||
if (this.skipFade <= 0) {
|
||||
this.skipFade = 64;
|
||||
this.skipFromL = this.lastOutL;
|
||||
this.skipFromR = this.lastOutR;
|
||||
}
|
||||
this.outPos = 0;
|
||||
}
|
||||
};
|
||||
// Telemetry (chẩn đoán crackle trên session thật): đếm sự kiện + báo main
|
||||
// thread mỗi ~2s. Nếu user bật master FX nghe crackle mà stats cho thấy
|
||||
@@ -95,9 +109,9 @@ class SfFxRealtimeProcessor extends AudioWorkletProcessor {
|
||||
}
|
||||
|
||||
// Phát output: chờ queue ≥ FILL trước khi phát lần đầu (hấp thụ jitter
|
||||
// engine/bridge/WS); underrun GIỮA stream → lặp block cuối tối đa HOLD
|
||||
// block (không zero-fill → hết click/ngắt) rồi mới im lặng; resume NGAY
|
||||
// khi có block mới (không đợi re-buffer FILL) + không re-fade sau lần đầu.
|
||||
// engine/bridge/WS); underrun GIỮA stream → fade-out 21ms từ mẫu cuối rồi
|
||||
// im lặng (V23); resume NGAY khi có block mới (không đợi re-buffer FILL),
|
||||
// đã im lặng → fade-in, giữa fade → crossfade 64 mẫu (hết jump).
|
||||
for (let i = 0; i < n; i++) {
|
||||
this.statCalls++;
|
||||
if (this.statCalls >= 1500) { // ~2s @48k/128
|
||||
@@ -114,22 +128,33 @@ class SfFxRealtimeProcessor extends AudioWorkletProcessor {
|
||||
this.outGain = Math.min(1, this.outGain + 1 / this.FADE);
|
||||
this.fadeLeft--;
|
||||
}
|
||||
outL[i] = blk.l[this.outPos] * this.outGain;
|
||||
if (outR) outR[i] = blk.r[this.outPos] * this.outGain;
|
||||
if (this.skipFade > 0) {
|
||||
const t = 1 - this.skipFade / 64;
|
||||
outL[i] = (this.skipFromL * (1 - t) + blk.l[this.outPos] * t) * this.outGain;
|
||||
if (outR) outR[i] = (this.skipFromR * (1 - t) + blk.r[this.outPos] * t) * this.outGain;
|
||||
this.skipFade--;
|
||||
} else {
|
||||
outL[i] = blk.l[this.outPos] * this.outGain;
|
||||
if (outR) outR[i] = blk.r[this.outPos] * this.outGain;
|
||||
}
|
||||
this.lastOutL = outL[i];
|
||||
this.lastOutR = outR ? outR[i] : outL[i];
|
||||
this.outPos++;
|
||||
if (this.outPos >= this.BLOCK) {
|
||||
this.lastBlock = blk;
|
||||
this.outQueue.shift();
|
||||
this.outPos = 0;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// Underrun giữa stream — chuyển hold (không cắt zero ngay → hết click).
|
||||
// Underrun giữa stream — V23: fade-out NGAY (không lặp block cuối:
|
||||
// lặp tạo jump pha ở điểm vào + mỗi wrap → click). Fade tuyến tính từ
|
||||
// mẫu output cuối tới 0 (21ms) — vào liền mạch (fadeFrom = lastOut),
|
||||
// hết click cắt cứng. Resume → crossfade/fade-in (xem dưới).
|
||||
this.playing = false;
|
||||
this.statUnderrun++;
|
||||
if (!this.silenced) { // đã im lặng (fade xong) → giữ im lặng, không hold lại block cũ
|
||||
this.holdPos = 0;
|
||||
this.holdLeft = this.HOLD * this.BLOCK;
|
||||
if (!this.silenced) { // đã im lặng (fade xong) → giữ im lặng
|
||||
this.fadeFromL = this.lastOutL;
|
||||
this.fadeFromR = this.lastOutR;
|
||||
this.holdFadeLeft = this.HOLD_FADE * this.BLOCK;
|
||||
this.statHold++;
|
||||
}
|
||||
@@ -139,15 +164,22 @@ class SfFxRealtimeProcessor extends AudioWorkletProcessor {
|
||||
if (this.outQueue.length >= (this.hasStarted ? 1 : this.FILL)) {
|
||||
this.playing = true;
|
||||
this.outPos = 0;
|
||||
const wasFading = this.holdFadeLeft > 0 && this.holdLeft <= 0;
|
||||
this.holdLeft = 0;
|
||||
const wasInterrupted = (this.holdFadeLeft > 0 || this.silenced) && this.hasStarted;
|
||||
this.holdFadeLeft = 0;
|
||||
if ((wasFading || this.silenced) && this.hasStarted) {
|
||||
// Resume giữa fade-out / sau im lặng: gain đang <1 (hoặc 0) →
|
||||
// fade-in nhanh tránh jump ~0→1 (click sau long stall).
|
||||
this.outGain = 0;
|
||||
this.fadeLeft = this.FADE;
|
||||
this.statFadeIn++;
|
||||
if (wasInterrupted) {
|
||||
if (this.silenced) {
|
||||
// Đã im lặng (fade xong) → fade-in từ 0 (hết jump ~0→1).
|
||||
// Dùng flag silenced (không đo lastOut: mẫu cuối fade ≈ fadeFrom/1024
|
||||
// ≈ 1e-3, ngưỡng số dễ sai).
|
||||
this.outGain = 0;
|
||||
this.fadeLeft = this.FADE;
|
||||
this.statFadeIn++;
|
||||
} else {
|
||||
// Giữa fade-out → crossfade ngắn từ mẫu hiện tại (không jump về 0).
|
||||
this.skipFade = 64;
|
||||
this.skipFromL = this.lastOutL;
|
||||
this.skipFromR = this.lastOutR;
|
||||
}
|
||||
}
|
||||
this.silenced = false;
|
||||
if (!this.hasStarted) {
|
||||
@@ -160,27 +192,21 @@ class SfFxRealtimeProcessor extends AudioWorkletProcessor {
|
||||
i--;
|
||||
continue;
|
||||
}
|
||||
if (this.holdLeft > 0 && this.lastBlock) {
|
||||
outL[i] = this.lastBlock.l[this.holdPos] * this.outGain;
|
||||
if (outR) outR[i] = this.lastBlock.r[this.holdPos] * this.outGain;
|
||||
this.holdPos++;
|
||||
if (this.holdPos >= this.BLOCK) this.holdPos = 0;
|
||||
this.holdLeft--;
|
||||
continue;
|
||||
}
|
||||
if (this.holdFadeLeft > 0 && this.lastBlock) {
|
||||
// Fade-out 1→0 sau HOLD: im lặng êm, hết click cắt cứng.
|
||||
if (this.holdFadeLeft > 0) {
|
||||
// Fade-out 1→0 (underrun): fade tuyến tính từ mẫu cuối, im lặng êm.
|
||||
const g = this.outGain * (this.holdFadeLeft / (this.HOLD_FADE * this.BLOCK));
|
||||
outL[i] = this.lastBlock.l[this.holdPos] * g;
|
||||
if (outR) outR[i] = this.lastBlock.r[this.holdPos] * g;
|
||||
this.holdPos++;
|
||||
if (this.holdPos >= this.BLOCK) this.holdPos = 0;
|
||||
outL[i] = this.fadeFromL * g;
|
||||
if (outR) outR[i] = this.fadeFromR * g;
|
||||
this.holdFadeLeft--;
|
||||
if (this.holdFadeLeft <= 0) { this.silenced = true; this.statFade++; this.statSilence++; } // fade xong → im lặng thật
|
||||
if (this.holdFadeLeft <= 0) { this.silenced = true; this.statFade++; this.statSilence++; }
|
||||
this.lastOutL = outL[i];
|
||||
this.lastOutR = outR ? outR[i] : outL[i];
|
||||
continue;
|
||||
}
|
||||
outL[i] = 0;
|
||||
if (outR) outR[i] = 0;
|
||||
this.lastOutL = 0;
|
||||
this.lastOutR = 0;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
<script src="/static/js/services/promptTemplateManager.js?v=202607281039"></script>
|
||||
<script src="/static/js/services/undoRedoEngine.js?v=202607290941"></script>
|
||||
<script src="/static/js/services/chordTheory.js?v=202608211300"></script>
|
||||
<script src="/static/js/app.precompiled.js?v=202608311200" defer></script>
|
||||
<script src="/static/js/app.precompiled.js?v=202608311300" defer></script>
|
||||
<link rel="stylesheet" href="/static/css/styles.css?v=202607271016">
|
||||
<style>
|
||||
:root {
|
||||
|
||||
Reference in New Issue
Block a user