fix(bounce): offline render qua native bridge — bỏ gap realtime, thêm headroom, strip DIAG

This commit is contained in:
2026-08-25 09:11:29 +07:00
parent 4037dbf40d
commit dd17f87e4e
7 changed files with 66 additions and 107 deletions
+1 -12
View File
@@ -54,7 +54,6 @@
var self = this;
try {
window.__TAURI__.event.listen('bridge-audio', function (e) {
if (!self._evtDiagAt || Date.now() - self._evtDiagAt >= 1000) { self._evtDiagAt = Date.now(); if (window.__sfDiag) window.__sfDiag('BRIDGE_EVT_RX cb=' + (self._audioCb ? 'yes' : 'no') + ' len=' + (e.payload && e.payload.l ? e.payload.l.length : 0)); }
// Bridge recovered after bridge-down (or never bootstrapped):
// audio frames flow again -> re-establish routing (Fix C).
if (!self.isBridgeConnected) self._reconnectIfNeeded();
@@ -72,7 +71,6 @@
if (window.AudioRoutingEngine) window.AudioRoutingEngine.disconnect();
console.warn('[BridgeService] bridge-down event received.');
});
if (window.__sfDiag) window.__sfDiag('EVT_REG ok');
} catch (e) {
console.warn('[BridgeService] event listen failed:', e);
}
@@ -126,8 +124,6 @@
* data2/data3 (A12): CC value / program / PB LSB|MSB.
*/
dispatchMidiEvent: function (cmd, channel, pitch, velocity, sampleOffset, data2, data3, live) {
this._pushEnter = (this._pushEnter || 0) + 1;
if (this._pushEnter % 100 === 0 && window.__sfDiag) window.__sfDiag('PUSH_ENTER cmd=' + cmd + ' ch=' + channel + ' tauri=' + !!this._tauri());
if (!this._tauri()) return false;
var safeVelocity = Math.floor(Math.min(1.0, Math.max(0.0, velocity)) * 127);
var byteCmd;
@@ -137,8 +133,6 @@
case 'PITCH_BEND': byteCmd = 0xE; break;
default: byteCmd = cmd === 'NOTE_ON' ? 0x9 : 0x8; break;
}
this._pushSent = (this._pushSent || 0) + 1;
if (this._pushSent % 100 === 0 && window.__sfDiag) window.__sfDiag('PUSH_SENT ' + this._pushSent);
// DIAG: Promise.race 800ms — invoke gửi đi nhưng không settle -> timeout
// (phan biet main-thread block vs Rust hang).
Promise.race([
@@ -153,12 +147,7 @@
live: !!live
}),
new Promise(function (_, rej) { setTimeout(function () { rej(new Error('timeout-800ms')); }, 800); })
]).then(function () {
this._pushOk = (this._pushOk || 0) + 1;
if ((_pushOk + (_pushFail || 0)) % 100 === 0 && window.__sfDiag) window.__sfDiag('PUSH_MIDI ok=' + _pushOk + ' fail=' + (_pushFail || 0));
}).catch(function (e) {
this._pushFail = (this._pushFail || 0) + 1;
if (_lastPushFail !== String(e)) { _lastPushFail = String(e); if (window.__sfDiag) window.__sfDiag('PUSH_MIDI_FAIL ' + e); }
]).catch(function (e) {
console.warn('[BridgeService] push_midi_event:', e);
});
return true;