fix(vsti): crackle fix P1-P3 — SHM 8-slot ring + drain-delta pump + AudioWorklet sink

- SharedMemoryIPC.h/main.cpp: render into ring slot (idx & ringMask), 8 slots
- shm.rs: ring fields + read_ring_audio; lib.rs pump drains FULL delta, not just latest
- bridgeAudioNode.js: AudioWorklet primary (bridge-audio-sink), ScriptProcessor fallback
- bridgeAudioWorklet.js: ring 64 blocks, underrun fade, overrun drop + crossfade
- layout tests: sizeof 27560 (8-align via u64)
This commit is contained in:
2026-08-16 20:43:50 +07:00
parent ed26e1706d
commit cead8c8c71
8 changed files with 235 additions and 29 deletions
+12 -1
View File
@@ -65,7 +65,18 @@ int main() {
// 5. Layout stability — MUST match Rust src-tauri/src/shm.rs
assert(sizeof(SharedAudioBufferIPC::MidiEventIPC) == 12);
assert(sizeof(SharedAudioBufferIPC::ControlEventIPC) == 1040);
assert(sizeof(SharedAudioBufferIPC) == 11168); // G3.1: +4 heartbeat
// G4.5 ring: 11168 (G3.1 +heartbeat) + ringMask(4) + ringLeft(8192) + ringRight(8192)
// = 27556, rounded up to 8-byte struct alignment (u64 blockTimestamp) => 27560.
// Matches Rust size_of (src-tauri/src/shm.rs layout test).
assert(sizeof(SharedAudioBufferIPC) == 27560);
// 6. Audio ring round-trip (multi-slot, VSTi crackle fix)
ipc->ringMask = 7;
for (uint32_t i = 0; i < AUDIO_BLOCK_SIZE; ++i) ipc->ringLeft[3][i] = (float)i * 2.0f;
ipc->ringRight[3][0] = 42.0f;
assert(ipc->ringLeft[3][255] == 510.0f);
assert(ipc->ringRight[3][0] == 42.0f);
assert((ipc->bridgeWriteIndex & ipc->ringMask) < 8);
std::printf("SHM self-check OK (sizeof struct = %zu bytes)\n", sizeof(SharedAudioBufferIPC));
shm_close(h);