Repository navigation
Fix the audio pop on game start / exit and Genesis save-state sound - #137
Conversation
- BoxEmu::audio_sample_rate(): skip a switch to the current rate, and hold the speaker amplifier off across a real switch (the I2S clocks stop and the ES8311 dividers are reprogrammed, which popped every time a core set its rate and again when it restored 48 kHz) - gwenesis: rebuild the YM2612 operator routing / detune pointers and keep this build's audio rates after loading a save state; a save from another build left the FM output silent and wrote to stray memory Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SFCMzomCZ5wRHJN4sxwkvY
|
✅Static analysis result - no issues found! ✅ |
There was a problem hiding this comment.
🟡 Changes recommended
The audio changes call methods unavailable in the declared espp/esp-box 1.3.8 dependency, causing compilation to fail with that supported release.
1 open issue
What changed in this PR
The reviewed changes address audio pops when emulators start or exit by centralizing sample-rate switching in BoxEmu.
Changes:
- Skip invalid rates and switches to the current rate.
- Disable the speaker amplifier, clear queued audio, and wait 50 ms after switching before re-enabling it.
- Move the implementation out of the header and document its behavior.
| File | Description |
|---|---|
components/box-emu/src/box-emu.cpp |
Implements guarded sample-rate switching with amplifier control and a settling delay. |
components/box-emu/include/box-emu.hpp |
Replaces the inline setter with a documented declaration. |
Review effort: Balanced
| bsp.enable_audio(false); | ||
| bsp.clear_audio(); | ||
| bsp.audio_sample_rate(rate); | ||
| std::this_thread::sleep_for(settle_time); | ||
| bsp.enable_audio(true); |
There was a problem hiding this comment.
Good catch on the requirement: enable_audio() / clear_audio() came with the espp::Audio move (espp #889, first in v1.4.1), so f63fc69 raises it to espp/esp-box >=1.4.1 instead of switching back to the deprecated enable_sound().
ESP-IDF Size Report for 'Esp Box Emu'
FLASH uses app .bin size or json2 flash sum. RAM sums DRAM+IRAM via idf_size. Percentages shown when totals are available. |
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SFCMzomCZ5wRHJN4sxwkvY
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SFCMzomCZ5wRHJN4sxwkvY

Audio pop when a game starts or exits
Every core sets its own sample rate on start and restores 48 kHz on exit. Each switch stops the I2S clocks and reprograms the ES8311's clock dividers under a live DAC, which the speaker played as a pop.
BoxEmu::audio_sample_rate()now:Genesis: silent Sonic 2 after resuming a save, and heap corruption
Bumps
components/genesis/gwenesisto esp-cpp/gwenesis#1. A save state from another firmware build restored stale YM2612 pointers, so the FM output was silent (even after an emulator reset) and stray writes corrupted the heap. This was the intermittent TLSF assert / MMU fault seen while testing #133 and the follow-ups.The submodule points at the gwenesis PR branch commit (
d984bd5). If that PR is squash-merged, re-pin it to the merge commit onesp32before merging this one.Testing (ESP32-S3-BOX-3)
🤖 Generated with Claude Code
https://claude.ai/code/session_01SFCMzomCZ5wRHJN4sxwkvY