fix(fxrt): resume sau long stall phai fade-in (het click), khong hold khi da im lang
This commit is contained in:
@@ -38,6 +38,7 @@ class SfFxRealtimeProcessor extends AudioWorkletProcessor {
|
||||
this.holdPos = 0;
|
||||
this.holdLeft = 0;
|
||||
this.holdFadeLeft = 0; // mẫu còn lại của fade-out sau HOLD
|
||||
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);
|
||||
this.inR = new Float32Array(this.bufLen);
|
||||
@@ -111,9 +112,11 @@ class SfFxRealtimeProcessor extends AudioWorkletProcessor {
|
||||
}
|
||||
// Underrun giữa stream — chuyển hold (không cắt zero ngay → hết click).
|
||||
this.playing = false;
|
||||
this.holdPos = 0;
|
||||
this.holdLeft = this.HOLD * this.BLOCK;
|
||||
this.holdFadeLeft = this.HOLD_FADE * this.BLOCK;
|
||||
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;
|
||||
this.holdFadeLeft = this.HOLD_FADE * this.BLOCK;
|
||||
}
|
||||
}
|
||||
// Không phát: resume khi đủ block (lần đầu chờ FILL; sau đó chỉ cần 1
|
||||
// block — hold che khoảng chờ).
|
||||
@@ -123,11 +126,13 @@ class SfFxRealtimeProcessor extends AudioWorkletProcessor {
|
||||
const wasFading = this.holdFadeLeft > 0 && this.holdLeft <= 0;
|
||||
this.holdLeft = 0;
|
||||
this.holdFadeLeft = 0;
|
||||
if (wasFading && this.hasStarted) {
|
||||
// Resume giữa fade-out: gain đang <1 → fade-in nhanh tránh jump ~0→1
|
||||
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.silenced = false;
|
||||
if (!this.hasStarted) {
|
||||
this.hasStarted = true;
|
||||
this.outGain = 0;
|
||||
@@ -154,6 +159,7 @@ class SfFxRealtimeProcessor extends AudioWorkletProcessor {
|
||||
this.holdPos++;
|
||||
if (this.holdPos >= this.BLOCK) this.holdPos = 0;
|
||||
this.holdFadeLeft--;
|
||||
if (this.holdFadeLeft <= 0) this.silenced = true; // fade xong → im lặng thật
|
||||
continue;
|
||||
}
|
||||
outL[i] = 0;
|
||||
|
||||
Reference in New Issue
Block a user