Commit Graph

93 Commits

Author SHA1 Message Date
3dtours 6018263044 fix: Lỗi không có âm thanh - quay lại ScriptProcessor vĩnh viễn (worklet push-model bị nghẽn main thread -> câm) 2026-08-03 12:13:26 +07:00
3dtours 36edc9daca fix: bật AudioWorklet hết deprecation ScriptProcessor + signature guard applyMasteringSettings hết BiquadFilterNode state is bad 2026-08-03 12:11:11 +07:00
3dtours 71278f2aba fix: mất soundfont khi ARM - clamp tham số master chain chặn NaN làm biquad state bad, toggleMasteringOnMaster idempotent, loadSoundFont retry khi lỗi thoáng qua 2026-08-03 11:44:13 +07:00
3dtours 71c3bafdb5 fix: không có âm thanh khi play MIDI item - quay lại ScriptProcessor làm renderer mặc định (worklet gây lỗi thiết bị), giữ worklet mono-safe + cache-busting 2026-08-03 11:24:59 +07:00
3dtours 34ad02dd6b fix: crash AudioWorklet khi output mono - xử lý mọi số channel trong fluidsynth-bridge + ép stereo outputChannelCount=2 2026-08-03 11:20:30 +07:00
3dtours 47b1633bd3 fix: ReferenceError assignTrackMidiChannel - chuyển allocator channel lên module-level cho PianoRollTabEditor + bật AudioWorklet thay ScriptProcessor 2026-08-03 11:17:19 +07:00
3dtours 9b6de7f857 fix: sfload reset_presets=0 giữ nguyên instrument các track khác; preloadTrackInstruments module-level (sửa ReferenceError reload); truyền props cho ProfileModal; lọc warning No preset found channel 9 2026-08-03 11:00:08 +07:00
3dtours 25471e6ea5 fix: lag khi ARM sau reload + câm sau vài lần nhấn MIDI - dedup loadSoundFont (1 font=1 sfload, tránh cạn heap 256MB) + preload instrument khi mở/khôi phục dự án 2026-08-03 10:43:26 +07:00
3dtours 0dc95386f2 fix: ARM nhiều track phát sai instrument - synth_engine của track là nguồn quyết định thay vì channel state (bỏ che mask khi channel giữ instrument cũ/trùng) 2026-08-03 10:33:40 +07:00
3dtours d8227904b6 fix: MIDI ARM không phát âm thanh sau khi load instrument - lazy-load soundfont trong playNote + giữ channel khi selectInstrument truyền channel tường minh 2026-08-03 10:23:32 +07:00
3dtours 73025fc387 fix: instrument SF3/Sonatina không phát âm thanh - chuyển SF3->SF2, bỏ convert SF2->SF3, sửa converter 2026-08-02 21:44:49 +07:00
3dtours 7e5f406226 fix: crackling - time-based render buffer, no voice stacking, lower synth gain/verbose 2026-07-31 10:52:22 +07:00
3dtours ad5cda5a40 fix: reduce MIDI playback crackling (no per-note prog reload, underrun-proof render loop, gentle stopAll) 2026-07-31 10:49:31 +07:00
3dtours 1790f743d6 fix: add 400ms decay to MIDI noteoff for natural release 2026-07-31 08:26:06 +07:00
3dtours 64f43cd5ad IMPROVE: cho phép thay đổi instrument realtime khi đang playback 2026-07-30 17:32:57 +07:00
3dtours 6e1f116658 FIX: sửa MASTERING PANEL có tác dụng với mainout 2026-07-30 11:06:31 +07:00
3dtours 2c55db372a FIX: sửa volume main out 2026-07-30 10:05:11 +07:00
3dtours 32b61553f9 fix: program_change at call time overrides subsequent notes
_playNoteFluid called program_change synchronously at
call time, not at scheduled note time. startTrackPlayback
processes all MIDI items first, then all sections -> each
note's program_change overwritten by the last type processed.
All notes played with section instrument regardless of
actual time position. Moved program_change into doNote
(setTimeout callback) so it fires at correct time.
2026-07-28 09:48:54 +07:00
3dtours 6fa6578dd1 feat: silent fallback when no instrument — no oscillator default
_playNoteFluid no-instrument branch previously called
_playNoteFallback (sine wave oscillator). Changed to
silent return. User explicitly requested no default sound.
2026-07-28 09:28:21 +07:00
3dtours 6dec171af7 fix: _playNoteFluid else branch leaked other track's SF program 0
When a track has no instrument configured, _playNoteFluid called
program_change(ch, 0). FluidSynth searches ALL loaded SoundFonts
to resolve program 0 — if only another track's SoundFont is loaded,
that SF's program 0 gets applied to the wrong track.

Fix: use oscillator fallback directly instead of program_change.
2026-07-27 21:26:52 +07:00
3dtours b5344e41f7 fix: default instrument for tracks without instrument set
_playNoteFluid: when no synthEngine and no program, fallback to
program 0 on channel (default piano) so unconfigured tracks still
produce sound via FluidSynth
2026-07-27 20:09:49 +07:00
3dtours 4a9cbcdef1 fix: per-track instrument + ghost note visibility
soundfontPlayer.js:
- selectInstrument: respect passed channel (don't allocate new one)
- _playNoteFluid: only use _engineChMap when channel is undefined

ghostNoteExtractor.js:
- Include ALL notes from overlapping items (not clipped)
- relative_start_beat can be negative (notes before window)
- Keep original duration instead of clamping
2026-07-27 20:04:56 +07:00
3dtours 2b04b32ea8 fix: dùng fluid_synth_program_select thay vì bank_select+program_change
Khi load SF2, preset lookup của program_change dùng search order
(lần lượt qua các SF đã load). Track 1 load SF2→SF2 presets override
SF1 trên tất cả channel, track 2 chọn nhầm preset của SF2.
Fix: program_select(synth, ch, sfHandle, bank, prog) chỉ định rõ
SoundFont ID, không phụ thuộc search order.
2026-07-27 16:08:54 +07:00
3dtours 8965643450 cleanup: bỏ dead code stopNote + debug log _playNoteFluid 2026-07-27 16:00:33 +07:00
3dtours 16e33b2e6a fix: _activeNotes lưu array channel cho mỗi key
Cùng MIDI pitch 60, track 1→ch0, track 2→ch1 cùng key '0:60'
→ single value bị overwrite, stopNote chỉ stop 1 channel.
Fix: _activeNotes[key] = [ch1, ch2, ...], stopNote iterate all.
2026-07-27 16:00:11 +07:00
3dtours 838e173dd7 debug: log _playNoteFluid params + stopNote activeNotes keys 2026-07-27 15:56:28 +07:00
3dtours ce7d23c351 fix: _origChannel tránh channel bị ghi đè bởi mappedCh
Line 378: 'if (channel===undefined) channel=ch' gán channel = FluidSynth
channel (2), sau đó _activeNotes key dùng channel (2) thay vì MIDI
channel (0). stopNote lookup bằng 0 → key mismatch.
Fix: _origChannel = channel ngay đầu hàm, dùng _origChannel cho key.
2026-07-27 15:54:06 +07:00
3dtours 987ecffc6c fix: activeNotes key dùng MIDI channel gốc, không phải FluidSynth channel
Key _activeNotes[ch:midiPitch] dùng ch đã remap (FluidSynth channel),
stopNote lookup bằng MIDI channel (0) → không tìm thấy.
Fix: key = (channel ?? 0) + ':' + midiPitch (MIDI channel gốc).
2026-07-27 15:50:28 +07:00
3dtours cb23d36bc8 fix: multi-track ARM + activeNotes map cho stopNote
1. precompiled: find(t=>isArmed) → filter(t=>isArmed) loop all tracks
2. soundfontPlayer: _activeNotes[ch:pitch] = mappedCh lưu khi noteOn
3. stopNote lookup mappedCh từ _activeNotes thay vì dùng MIDI ch 0
→ Fix: đổi SF track → channel mới → noteOff vẫn tìm đúng voice
2026-07-27 15:48:34 +07:00
3dtours 638d56ce63 fix: engine->channel map cho multi-track ARM
_engineChMap: key=sfId:bank:prog → allocated MIDI channel.
Mỗi track ARM riêng biệt có engKey khác nhau → allocated channel
riêng (0-8 round-robin). _playNoteFluid lookup channel từ map
thay vì dùng MIDI channel gốc (luôn 0).
2026-07-27 15:40:45 +07:00
3dtours 3d7bae94f2 fix: schedule noteOff even cho immediate notes (durationMs < 60000)
Trước đây chỉ schedule noteOff khi delay > 0 (notes scheduled).
Virtual piano keyboard play note immediate (delay===0) với duration=500ms
nhưng không có noteOff → âm thanh play mãi không tắt.
Fix: schedule noteOff khi 0 < durationMs < 60000, không phụ thuộc delay.
2026-07-27 15:36:03 +07:00
3dtours 00566e8ea6 fix: stopNote dùng noteoff+noteon(vel0) thay vì all_sounds_off
- Bỏ _fluid_synth_all_sounds_off (kill cả chord)
- Thử noteoff + noteon(vel=0) - MIDI noteOff alternate
- Log cả 2 return code
2026-07-27 15:27:53 +07:00
3dtours 5c7f922eb0 fix: _fluid_synth_all_sounds_off + log noteoff return code
- Dùng _fluid_synth_all_sounds_off thay vì CC120
- Log return value của _fluid_synth_noteoff (0=OK, -1=fail)
- Log ch+pitch trong stopNote
- Sửa printErr filter (bỏ check 'stderr')
2026-07-27 15:21:50 +07:00
3dtours ae6abc3ea5 fix: thêm CC120 (All Sound Off) vào stopNote
_fluid_synth_noteoff chưa đủ để tắt âm với instrument loop.
Thêm CC120 kill tất cả voices trên channel để note tắt ngay.
2026-07-27 15:20:01 +07:00
3dtours cdfe88ba76 fix: force ScriptProcessorNode (bypass AudioWorklet) để debug no-audio 2026-07-27 15:15:20 +07:00
3dtours 05113e17f3 fix: gain 2.0 + zero buffer trước render + log get_gain thực tế
- synth.gain=2.0 (thay vì 0.5 + set_gain 1.0) để tăng volume
- Pre-zero HEAPF32 buffer trước khi gọi write_float
- Log peak, avg, và value từ _fluid_synth_get_gain để debug
2026-07-27 15:14:49 +07:00
3dtours 4d2da5a272 fix: ScriptProcessorNode fallback + worklet process() logging
- ScriptProcessorNode fallback khi AudioWorkletNode fails
- Render trực tiếp trong onaudioprocess callback, không cần setInterval
- Worklet log peak + queue depth mỗi 50 process() calls
- Log audioCtx state + sampleRate khi init
2026-07-27 15:09:47 +07:00
3dtours 4ca6e7c6ad fix: thêm logging debug cho noteOn + render + gain explicit
- _fluid_synth_set_gain(1.0) sau khi tạo synth (đảm bảo gain > 0)
- Log noteOn(ch, pitch, vel) mỗi lần play
- Log peak frame đầu tiên khi render > 0.001
- Error log trong catch pushFrame
- Sửa _playNoteFluid: dùng usedBank để xác định ch khi undefined
2026-07-27 15:02:27 +07:00
3dtours a887db587f fix: clean sfload with _allocCStr helper + printErr debug + verbose FluidSynth
- Thay MEMFS path từ /soundfonts/ → root / (tránh lỗi thư mục)
- Helper _allocCStr + _tryLoadSFL: unique filename, manual C string alloc, cleanup
- Thêm printErr callback để capture FluidSynth C stderr log
- Bật synth.verbose=1, synth.ladspa.active=0
- Loại bỏ _fluid_synth_get_sfont_count (không export)
- Log buffer magic bytes (RIFF/sfbk) để verify file valid
2026-07-27 14:56:07 +07:00
3dtours 6fe0cd8d61 fix: bắt lỗi _fluid_synth_sfload + fallback SF2 + tăng WASM memory
- Gọi _fluid_synth_error để lấy error message từ C engine
- Fallback từ .sf3 → .sf2 nếu sfload thất bại
- TOTAL_MEMORY=256MB cho SoundFont 11MB
- unlink file cũ trước writeFile tránh MEMFS conflict
- Log MEMFS stat để debug
2026-07-27 14:51:39 +07:00
3dtours e801023beb fix: locateFile cho FluidSynth WASM module (dùng self-host/CDN)
Module script (type=module) có document.currentScript === null,
nên libfluidsynth không thể tự locate .wasm file. Fix: pass
locateFile() trả về URL .wasm tương ứng với URL .js đã load.

fluidsynthLoader.js: expose __FluidSynthLocateWasm() trả về
FLUIDSYNTH_JS_URL.replace('.js', '.wasm'). Dùng polling
setInterval thay vì resolve callback cho đáng tin cậy hơn.
soundfontPlayer.js: pass locateFile factory khi gọi factory.
2026-07-27 14:48:58 +07:00
3dtours ef1238b87d feat: migrate SpessaSynth → FluidSynth WASM (SF3 native, loop Gen 54 fix)
Replace SpessaSynth JS/AudioWorklet with FluidSynth C++ WASM
(@enikey87/fluidsynth-emscripten@0.1.1). CDN for dev, self-host
for prod. Fixes stuck Tremolo/Saxophone notes via compliant
Gen 44 loop mode processing. 100% audio parity with server
pyfluidsynth render (same C++ core).

- soundfontPlayer.js: FluidSynth WASM engine, preserve SonicSF API
- fluidsynthLoader.js: auto-select CDN (dev) vs self-host (prod)
- fluidsynth-bridge.js: PCM bridge AudioWorklet processor
- index.html: remove SpessaSynth importmap + module, add loader
- vendor/: libfluidsynth-2.3.0-sf3.js + .wasm (1.8MB self-host)
2026-07-27 12:48:30 +07:00
3dtours 18d2503cb9 fix: bypass SpessaSynth AudioWorklet MIDI pipeline for looped voice release
SpessaSynth 4.3.1 bug: looped voices (Tremolo Strings, Trumpet) ignore
release envelope + CC 120 when processed through MIDI message pipeline
(processMessage). Fix: send stopAll directly to worklet via
handleMessage post() bypass, plus noteOn(vel=0) as alternate note-off.
2026-07-27 12:27:51 +07:00
3dtours fa4a38bf3e fix: stopNote/stoplAll uses CC120 (All Sound Off) instead of CC123 (All Notes Off) to kill sustained instrument voices immediately
Root cause: SpessaSynth's CC123 (All Notes Off) calls stopAllNotes(false)
which enters the SoundFont release envelope. Tremolo Strings (GM#44) and
similar sustained instruments have 2-5s release tails, causing notes to
continue playing after MIDI key release.

Fix: Replace CC 123 with CC 120 (All Sound Off) in stopNote() and
stopAll(). CC 120 calls stopAllNotes(true) which sets voice.isActive=false
instantly, bypassing the release envelope entirely.

Removed redundant noteOff(ch,pitch,0) and resetAllControllers(CC121)
which unnecessarily reset volume/pan/expression on the channel.
2026-07-27 12:11:37 +07:00
3dtours 4def86168b fix: send CC64=0 + CC121=0 before noteOff (reset sustain + all controllers) 2026-07-27 12:02:50 +07:00
3dtours f7a46e0baa fix: lazyInit in playNote, oscillator fallback 2s instead of 60s 2026-07-27 11:43:32 +07:00
3dtours 1829b61472 fix: stopNote fires noteOff(3 variants) + allNotesOff + CC123 for redundancy 2026-07-27 11:39:16 +07:00
3dtours 8aeac14e4b fix: only send All Notes Off (CC123) when sustain pedal is not active
- Track sustain state per channel via _sustainStates[]
- sustainActive(channel) returns boolean
- MIDI NoteOn: only send CC123 if !sustainActive(ch)
- Preserves sustained notes when playing new notes
2026-07-27 11:30:35 +07:00
3dtours 48e4047a84 revert: remove 100ms delay from stopNote, keep instant noteOff 2026-07-27 11:27:39 +07:00
3dtours 0e051297b0 fix: stopNote delays noteOff by 100ms for natural release 2026-07-27 11:25:03 +07:00