diff --git a/.github/workflows/voice-user-check.yml b/.github/workflows/voice-user-check.yml index d87fb231..60c7e79c 100644 --- a/.github/workflows/voice-user-check.yml +++ b/.github/workflows/voice-user-check.yml @@ -267,6 +267,10 @@ jobs: node-version: '22' - name: Build and compare emulator audio with native firmware run: | + set -euo pipefail + mkdir -p build/emu + cc -O1 -w -Wno-implicit-function-declaration -Ibuild/gen -Ifirmware/src tests/web_polyphony_test.c -lm -o build/emu/web-polyphony + build/emu/web-polyphony sh web/emu/build.sh cc -O2 -ffp-contract=off -w -Wno-implicit-function-declaration -Wno-incompatible-pointer-types -Ibuild/gen -Ifirmware/src web/emu/native_check.c -lm -o build/emu/native-check build/emu/native-check build/emu/native.f32 diff --git a/docs/performance/v51-two-track-recovery.md b/docs/performance/v51-two-track-recovery.md index 718d5e60..b3856e1d 100644 --- a/docs/performance/v51-two-track-recovery.md +++ b/docs/performance/v51-two-track-recovery.md @@ -51,3 +51,13 @@ No synth preset's intentional voice mode is changed by this patch. Target build: image 583,416/584,336 bytes; RAM data 97,904/98,304; RAM code 32,736/34,816; pool spare 8,704 bytes. All existing build guards pass. + +## Emulator parity + +The emulator also left `mc_host` disabled at boot. Consequently it never earned +FULL headroom and DRUM-X plus an ANALOG tetrad lost four kit voices, even without +simulated CPU pressure. It now enables the existing synchronous host-core mixer +after initialization, modeling the normal healthy FM-1 allocation policy without +creating a browser worker or inventing timing measurements. The real device's +core-fault restrictions are unchanged. `tests/web_polyphony_test.c` checks actual +emulator boot, four/six-track settings, kit plus tetrad and single-core fallback. diff --git a/tests/web_polyphony_test.c b/tests/web_polyphony_test.c new file mode 100644 index 00000000..bd3598a5 --- /dev/null +++ b/tests/web_polyphony_test.c @@ -0,0 +1,44 @@ +/* The emulator boots the same healthy two-core voice policy as the FM-1. + * Its host mixer executes the two jobs sequentially, not on browser threads. */ +#include "../web/emu/felucca_web.c" +#include + +static void render_ms(unsigned ms) +{ + for (unsigned n = 0; n < ms * 441u / 10u; n += 128) web_render(128); +} +static unsigned web_count(unsigned t) +{ + unsigned n = 0; + for (unsigned i = 0; i < NVOICE; i++) n += trk[t].v[i].active && trk[t].v[i].stage != 4; + return n; +} +int main(void) +{ + unsigned failed = 0; + web_nor_erase(); web_boot(); render_ms(3000); + printf("web boot: cores=%u headroom=%u cap=%u\n", mc_live() ? 2 : 1, voice_headroom, voice_cap()); + if (!mc_live() || !voice_headroom) failed++; + for (unsigned tracks = 4; tracks <= 6; tracks += 2) { + memset(trk, 0, sizeof trk); host_tracks_init(); + trks_put(tracks == 6); load_put(2); /* real TRACKS and FULL settings */ + for (unsigned t = 0; t < NTRK; t++) { + host_preset(&trk[t], t ? ENGI_ANALOG : ENGI_DRUM, 0); + trk[t].p[P_VOICE] = V_POLY; trk[t].p[P_SUS] = 127; + trk[t].p[P_VCAP] = trk[t].p[P_DDST] = 0; + } + render_ms(100); + for (unsigned l = 0; l < DV_NLANE; l++) trk_note_on(&trk[0], DRUM_LANE_NOTE[l], 110); + static const unsigned notes[] = {48, 52, 55, 59}; + for (unsigned j = 0; j < 4; j++) trk_note_on(&trk[1], notes[j], 100); + printf("web TRACKS=%u: kit=%u chord=%u cap=%u\n", tracks, web_count(0), web_count(1), voice_cap()); + if (trk_live != tracks || voice_cap() != (tracks == 6 ? 16 : 12) || + web_count(0) != 8 || web_count(1) != 4) failed++; + render_ms(3); + if (web_count(0) != 8 || web_count(1) != 4) failed++; + } + mc_host = 0; render_ms(100); + if (voice_headroom || voice_cap() > 8) failed++; + printf("web polyphony: %u failures\n", failed); + return !!failed; +} diff --git a/web/emu/felucca_web.c b/web/emu/felucca_web.c index e2f09bdb..7afe2c98 100644 --- a/web/emu/felucca_web.c +++ b/web/emu/felucca_web.c @@ -268,6 +268,10 @@ static void web_power_on(void) fm1_adc_init(); panel_init(); felucca_init(); + /* Model the normal FM-1's healthy two-core admission. The host mixer runs + * core 1's jobs synchronously; no browser thread or invented CPU timing. + * Leaving this off permanently limited the emulator to eight voices. */ + mc_host = 1; master_boot(); /* main.c (#137): the pot's level from the first block */ kb_boot_hold = 1; /* main.c (#137): the keys silent under the splash */ audio_init();