diff --git a/.github/workflows/cpu-audit.yml b/.github/workflows/cpu-audit.yml index bfa2928a..8c7049d2 100644 --- a/.github/workflows/cpu-audit.yml +++ b/.github/workflows/cpu-audit.yml @@ -2,12 +2,12 @@ name: 0.9.9 CPU and RAM audit on: push: - branches: [codex/fm1-v099-cpu3] + branches: [codex/fm1-v099-cpu4] workflow_dispatch: permissions: contents: read concurrency: - group: firmware-cpu3-audit + group: firmware-cpu4-audit cancel-in-progress: true jobs: build: @@ -55,6 +55,8 @@ jobs: done cc -O2 -w -Ibuild/gen -Ifirmware/src tests/chorus_sleep_test.c -lm -o build/host/chorus_sleep_test python3 tests/chorus_sleep_test.py build/host/chorus_sleep_test + cc -O2 -w -Ibuild/gen -Ifirmware/src tests/empty_fx_test.c -lm -o build/host/empty_fx_test + python3 tests/empty_fx_test.py build/host/empty_fx_test build/host/fm6_env_compare build/host/fm6_test build/host/voice_test @@ -79,7 +81,7 @@ jobs: printf '%s\n' "$GITHUB_SHA" > build/SOURCE_COMMIT - uses: actions/upload-artifact@v4 with: - name: fm1-v099-cpu3-audit + name: fm1-v099-cpu4-audit if-no-files-found: error path: | build/felucca.fwsc @@ -90,7 +92,3 @@ jobs: LICENSE LICENSING.md LICENSES/ - - name: Research only - compile the existing four-operator DIGITAL engine - env: - FELUCCA_FM4: "1" - run: python3 tools/build.py diff --git a/docs/CPU4_PERFORMANCE.md b/docs/CPU4_PERFORMANCE.md new file mode 100644 index 00000000..9996a98d --- /dev/null +++ b/docs/CPU4_PERFORMANCE.md @@ -0,0 +1,27 @@ +# 0.9.9 cpu4: live drum protection and empty FX work + +## Confirmed allocator defect + +A one-shot DRUM-X hit keeps sounding after MIDI key-up. The allocator and overload shedder previously classified it by `gate == 0`, like a released melodic tail. This allowed the last live kick to be discarded while three held melodic tracks remained protected; cpu3's requesting-track release preference could also reuse that kick for a new hat. + +`voice_held()` now classifies live one-shot voices as held for allocation and overload protection only. The drum envelope, MIDI gate, choke groups and rendering are unchanged. The existing lowest-note protection retains one live drum hit, while additional hits can still be stolen under load. This does not remove the physical CPU deadline or guarantee every hit survives any scene. + +`audio_test` reproduces both failures against cpu3 and passes with this fix: four tracks under shedding, and a new hat at a full eight-voice budget. It also checks pending drum hits under tight admission. Two existing mixed-song golden hashes intentionally change because allocation preserves the drum differently; all other reference hashes stay unchanged. + +## Empty bus work without losing tails + +Two conservative flags prove delay and plain ROOM buffers have never received nonzero input since boot or an actual state clear. In that case, avoid delay interpolated reads/feedback filters and ROOM's comb/allpass sample loops. Preserve write positions, parameter glides, LFO clocks and shared FX outputs. First nonzero input resumes the original kernels in the same block. Stereo/grain/low-rate delay and non-plain ROOM models conservatively disable their shortcut. + +These certificates do **not** assume zero sends imply zero tails. After real input, normal processing continues until an explicit clear. This improves unused buses, including on fresh boot and dry playing, but does not implement sleeping of previously excited tails. They require two bytes of persistent flags (alignment may affect target totals), not additional audio buffers. Chorus retains cpu3's exact zero-ring proof. + +`empty_fx_test` forces the original kernels as its reference and compares complete output, FX state, RNG state and final buffers over 12000 blocks, covering fresh silence, wake, tails, resets, delay modes, reverb model transitions, parameter movement and LOAD changes. It matches bit for bit. Host timings are diagnostic only and cannot predict the FM1's reported idle percentage. + +## Scope of external reference + +The official m-vave/fm1_open README and SDK build script confirm V14 and an `-O2` compiler configuration. Its current application license is GPLv3 with an SDK linking exception; its binary SDK has separate terms. No official source or binary SDK is incorporated here. Assertions about 320/360 MHz, cache failures or unsupported clocks are not established by the public application files examined and are not used to change JIANT's clock. JIANT's current audio compilation uses `-Os`; changing that or adding hardware loops needs separate target resource and timing validation. + +FM6 remains six operators. FULL has a per-track cap of four FM6 notes, LITE two, in addition to shared dynamic admission. A measured host benchmark or synthetic deadline test is not a hardware utilization measurement; final evaluation needs fresh-boot LOAD and a repeat of the same four-track pattern on the FM1, checking NOW, PEAK, LATE and SHED. + +## Host diagnostic measurement + +Five interleaved runs against cpu3's FX implementation, using the same harness and allocation code, produced median idle mixer times of 43.38 versus 29.88 ns/sample (31% lower), and empty FX chain times of 26.36 versus 8.23 ns/sample (69% lower). All scenario checksums match. Raw scenes are in `docs/performance/cpu4-host.jsonl`; timing variation affects unchanged engine scenes too, so those are not evidence of engine speedups. This is GCC `-O2` on the host, not JieLi hardware or a prediction that the reported 19% boot load will fall by 31%. diff --git a/docs/navigation-map.es.svg b/docs/navigation-map.es.svg index 5bcf9434..459610b3 100644 --- a/docs/navigation-map.es.svg +++ b/docs/navigation-map.es.svg @@ -1,6 +1,6 @@ - + -JIANT FM · Mapa de navegación · v0.9.9-cpu3 +JIANT FM · Mapa de navegación · v0.9.9-cpu4 @@ -197,7 +197,7 @@ JIANT FM Mapa de navegación -firmware v0.9.9-cpu3 · seis reglas, una cadena de páginas por sección +firmware v0.9.9-cpu4 · seis reglas, una cadena de páginas por sección Diez botones, diez secciones. SELECT recorre las páginas de una sección como una cadena; su botón salta de grupo en grupo. diff --git a/docs/navigation-map.svg b/docs/navigation-map.svg index 96a1f876..17e4a634 100644 --- a/docs/navigation-map.svg +++ b/docs/navigation-map.svg @@ -1,6 +1,6 @@ - + -JIANT FM · Navigation map · v0.9.9-cpu3 +JIANT FM · Navigation map · v0.9.9-cpu4 @@ -197,7 +197,7 @@ JIANT FM Navigation map -firmware v0.9.9-cpu3 · six rules, one chain of pages per section +firmware v0.9.9-cpu4 · six rules, one chain of pages per section Ten buttons, ten sections. SELECT walks a section's pages as one chain; its button jumps group to group. diff --git a/docs/performance/cpu4-host.jsonl b/docs/performance/cpu4-host.jsonl new file mode 100644 index 00000000..a11636cd --- /dev/null +++ b/docs/performance/cpu4-host.jsonl @@ -0,0 +1,25 @@ +{"scene": "ANALOG", "before_ns": 60.6931, "after_ns": 60.4742, "delta_pct": -0.3606670280476676, "checksum": "76190", "live_end": [4], "repeats": 5} +{"scene": "PHASE", "before_ns": 41.9171, "after_ns": 42.0595, "delta_pct": 0.33971815798325977, "checksum": "181218", "live_end": [4], "repeats": 5} +{"scene": "LOFI", "before_ns": 68.4514, "after_ns": 64.2745, "delta_pct": -6.101993531176864, "checksum": "19432", "live_end": [4], "repeats": 5} +{"scene": "VOICE vowels", "before_ns": 93.1999, "after_ns": 77.5664, "delta_pct": -16.774159628926643, "checksum": "4294890784", "live_end": [4], "repeats": 5} +{"scene": "VOICE words", "before_ns": 93.2972, "after_ns": 81.1722, "delta_pct": -12.996102776932217, "checksum": "144816", "live_end": [4], "repeats": 5} +{"scene": "WHEEL", "before_ns": 74.1463, "after_ns": 89.6428, "delta_pct": 20.899896555863194, "checksum": "77410", "live_end": [4], "repeats": 5} +{"scene": "DRUM", "before_ns": 33.578, "after_ns": 34.004, "delta_pct": 1.268687831318105, "checksum": "4294924290", "live_end": [3], "repeats": 5} +{"scene": "NOISE", "before_ns": 53.807, "after_ns": 54.7653, "delta_pct": 1.7809950378203654, "checksum": "4294919931", "live_end": [4], "repeats": 5} +{"scene": "FM6", "before_ns": 78.7931, "after_ns": 78.0231, "delta_pct": -0.9772429311703634, "checksum": "4294841544", "live_end": [4], "repeats": 5} +{"scene": "ANIMAL", "before_ns": 12.6426, "after_ns": 12.1481, "delta_pct": -3.9113789884992034, "checksum": "4294949301", "live_end": [4], "repeats": 5} +{"scene": "FM6 6 operators", "before_ns": 56.7978, "after_ns": 55.5552, "delta_pct": -2.187760793551863, "checksum": "4294862000", "live_end": [4], "repeats": 5} +{"scene": "FM6 4 operators", "before_ns": 41.9587, "after_ns": 42.9749, "delta_pct": 2.4219053497844145, "checksum": "6211", "live_end": [4], "repeats": 5} +{"scene": "FM6 2 operators", "before_ns": 36.177, "after_ns": 33.8309, "delta_pct": -6.4850595682339645, "checksum": "5727", "live_end": [4], "repeats": 5} +{"scene": "FX no input", "before_ns": 26.3576, "after_ns": 8.2342, "delta_pct": -68.75967462894953, "checksum": "0", "live_end": [0], "repeats": 5} +{"scene": "FX chorus input", "before_ns": 45.6902, "after_ns": 25.9363, "delta_pct": -43.23443539314776, "checksum": "3271", "live_end": [0], "repeats": 5} +{"scene": "FX delay input", "before_ns": 20.9303, "after_ns": 9.989, "delta_pct": -52.27493155855386, "checksum": "3152", "live_end": [0], "repeats": 5} +{"scene": "FX ROOM", "before_ns": 21.1763, "after_ns": 17.9296, "delta_pct": -15.331762394752623, "checksum": "2837", "live_end": [0], "repeats": 5} +{"scene": "FX SPRING", "before_ns": 44.1949, "after_ns": 29.0724, "delta_pct": -34.21774910679739, "checksum": "352", "live_end": [0], "repeats": 5} +{"scene": "FX SHIMMER", "before_ns": 27.6897, "after_ns": 24.6812, "delta_pct": -10.865050903404505, "checksum": "5390", "live_end": [0], "repeats": 5} +{"scene": "FX RESO", "before_ns": 37.0259, "after_ns": 31.2574, "delta_pct": -15.579634796183207, "checksum": "22164", "live_end": [0], "repeats": 5} +{"scene": "FX CLOUD", "before_ns": 30.631, "after_ns": 27.6148, "delta_pct": -9.8468871404786, "checksum": "4294909837", "live_end": [0], "repeats": 5} +{"scene": "mixer idle", "before_ns": 43.3834, "after_ns": 29.8774, "delta_pct": -31.13172319366394, "checksum": "0", "live_end": [0], "repeats": 5} +{"scene": "six FM6 tracks dry", "before_ns": 300.9881, "after_ns": 303.8491, "delta_pct": 0.9505359181974482, "checksum": "4294950880", "live_end": [12], "repeats": 5} +{"scene": "six VOICE tracks dry", "before_ns": 376.1684, "after_ns": 359.6594, "delta_pct": -4.388725900421198, "checksum": "8615", "live_end": [12], "repeats": 5} +{"scene": "four ANALOG tracks all sends", "before_ns": 224.1717, "after_ns": 219.1015, "delta_pct": -2.2617484722647907, "checksum": "1598", "live_end": [8], "repeats": 5} diff --git a/firmware/src/audio.c b/firmware/src/audio.c index 44849467..b5a6f0d8 100644 --- a/firmware/src/audio.c +++ b/firmware/src/audio.c @@ -109,7 +109,7 @@ static void shed_voice(void) for (p = 0; p < NPART; p++) for (i = 0; i < NVOICE; i++) { voice_t *v = &trk[p].v[i]; - if (v->active && !v->gate && v->stage != 4u && (!best || v->env < best->env)) + if (v->active && !voice_held(&trk[p], v) && v->stage != 4u && (!best || v->env < best->env)) best = v; } if (best) { @@ -122,7 +122,7 @@ static void shed_voice(void) uint32_t mode = trk_vmode(t), low = mode == V_POLY ? lowest_held(t) : 0u; for (i = 0; i < NVOICE; i++) { voice_t *v = &trk[p].v[i]; - if (v->active && v->gate && v->stage != 4u && + if (v->active && voice_held(t, v) && v->stage != 4u && ((mode == V_POLY && i != low) || (mode != V_POLY && i > 0u))) { if (!best || v->age < best->age) best = v; diff --git a/firmware/src/felucca.c b/firmware/src/felucca.c index 8bbcdb48..600f4bbe 100644 --- a/firmware/src/felucca.c +++ b/firmware/src/felucca.c @@ -38,7 +38,7 @@ #define FELUCCA_ID "FM-1_900" /* package identity (build.py: the .fwsc marker string) */ #endif #ifndef FELUCCA_VERSION -#define FELUCCA_VERSION "v0.9.9-cpu3" /* CPU fixes preview, based on stable JIANT 0.9.9 */ +#define FELUCCA_VERSION "v0.9.9-cpu4" /* CPU fixes preview, based on stable JIANT 0.9.9 */ #endif #if FELUCCA_OTA && !FELUCCA_FLASH #error "FELUCCA_OTA needs FELUCCA_FLASH" diff --git a/firmware/src/fx.c b/firmware/src/fx.c index 3f20bfbe..e58a9d05 100644 --- a/firmware/src/fx.c +++ b/firmware/src/fx.c @@ -23,6 +23,7 @@ static __attribute__((noinline)) uint32_t cho_admit(int32_t input, uint32_t n) cho_zeros = input ? 0u : cho_zeros + n < CHO_LEN ? cho_zeros + n : CHO_LEN; return run; } +static uint8_t room_used, dly_used; /* conservative zero-state certificates; never discard a tail */ static const uint16_t REV_COMB[4] = {1116, 1188, 1277, 1356}; static const uint16_t REV_AP[2] = {556, 441}; static int16_t rev_comb[1116 + 1188 + 1277 + 1356] __attribute__((section(".pool"))); @@ -706,9 +707,29 @@ static int32_t rev_size(void) int32_t g = GFX(GF_RSIZE); return 25000 + g * 40 + g * g / 7; } +/* A never-excited (or explicitly cleared) ROOM has exactly zero buffers and + * filter states. Advance its read/write clocks without six sample networks. + * After any input, normal rendering remains enabled for the whole tail. */ +static __attribute__((noinline)) int room_zero(const int32_t *in, uint32_t n) +{ + uint32_t i; + if (room_used) return 0; + for (i = 0; i < n; i++) if (in[i]) { room_used = 1; return 0; } + for (i = 0; i < 4u; i++) { + uint32_t k = fx.comb_i[i] + n; + fx.comb_i[i] = (uint16_t)(k >= REV_COMB[i] ? k - REV_COMB[i] : k); + } + for (i = 0; i < 2u; i++) { + uint32_t k = fx.ap_i[i] + n; + fx.ap_i[i] = (uint16_t)(k >= REV_AP[i] ? k - REV_AP[i] : k); + } + return 1; +} + /* ROOM (G_RTYPE 0): 4 damped combs + 2 allpasses (Freeverb-like, mono), added to out (WIDE: rev_room_mod) */ static __attribute__((noinline)) void rev_room(const int32_t *rev_in, int32_t *out, uint32_t n) { + if (room_zero(rev_in, n)) return; uint32_t i; int32_t size = rev_size(), dk = GFX(GF_RDAMP) * 200; /* (32767 - damp) */ /* (0.7.9) the combs' and allpasses' indices and low-passes in registers through the block (they were loaded and @@ -758,6 +779,7 @@ static __attribute__((noinline)) void rev_room(const int32_t *rev_in, int32_t *o * (MOD 0 here: offsets 0, the plain one's sound) */ static __attribute__((noinline)) void rev_room_mod(const int32_t *rev_in, int32_t *out, uint32_t n, int32_t wd) { + room_used = 1; uint32_t i, k; int32_t size = rev_size(), damp = 32767 - GFX(GF_RDAMP) * 200, m1[4], dm[4]; int32_t depth = song.g[G_RMOD] ? 64 + song.g[G_RMOD] * song.g[G_RMOD] * 4 : 0; /* Q8 samples: 0.25 .. 252 (~5.7 ms) */ @@ -823,6 +845,7 @@ static __attribute__((noinline)) void sp_chain(int32_t *ap, uint32_t ns) /* SPRING (see the top), added to out */ static __attribute__((noinline)) void rev_spring(const int32_t *rev_in, int32_t *out, uint32_t n) { + room_used = 1; uint32_t i, k, s = (uint32_t)GFX(GF_RSIZE); int32_t g = 19661 + (int32_t)s * 85 + (int32_t)(s * s) / 16; /* the loop's gain: 0.6 .. 0.96 (0.5: was 0.93) */ int32_t kl = 26000 - GFX(GF_RDAMP) * 160; /* its low-pass: ~9 kHz .. ~1.3 kHz */ @@ -909,6 +932,7 @@ static int32_t rev_air(void) static int32_t sh_tlp; /* (0.6.12) SHIMMER's tone: AIR's low-pass / its shelf */ static __attribute__((noinline)) void rev_shimmer(const int32_t *rev_in, int32_t *out, uint32_t n) { + room_used = 1; int32_t in[CTL], t[CTL], amt = song.g[G_RMOD] * 190; /* Q15: up to ~0.74 */ int32_t air = rev_air(), st = clamp(12 + air, -12, 24), tk = air < 0 ? 32767 + air * 1150 : 9000; int32_t step = (int32_t)semi_q16(st) - 65536; /* (the delay changes by 1 - speed a sample, Q16) */ @@ -947,6 +971,7 @@ static uint32_t reso_pitch(void) { return song.g[G_RTYPE] == 3 ? (uint32_t)clamp static uint32_t reso_folw(void) { return GFX(GF_RDAMP) >= 1 && GFX(GF_RDAMP) <= 6 ? (uint32_t)GFX(GF_RDAMP) : 0u; } static __attribute__((noinline)) void rev_reso(const int32_t *rev_in, int32_t *out, uint32_t n) { + room_used = 1; const track_t *t = &trk[0]; uint32_t i, k, per[4], mask, s, fol = reso_folw(), up = reso_pitch(); int32_t sz = GFX(GF_RSIZE), dk = 32767 - 60 * 200, note[4], deg = 0, nn; @@ -1018,6 +1043,7 @@ static uint32_t cl_rand(void) { fx.cl_rng = fx.cl_rng * 1664525u + 1013904223u; * heard dry, they bloom into a tail around the sound. SIZE full freezes the line (the cloud holds) */ static __attribute__((noinline)) void rev_cloud(const int32_t *rev_in, int32_t *out, uint32_t n) { + room_used = 1; static const uint32_t PITCH[4] = {65536u, 131072u, 32768u, 98184u}; /* x1, an octave up, down, a fifth up (Q16) */ uint32_t i, k, freeze = GFX(GF_RSIZE) >= 127; int32_t gap = 1700 - song.g[G_RRATE] * 11, dk = 32767 - GFX(GF_RDAMP) * 220, wd = song.g[G_RWIDE], air = rev_air(); @@ -1124,6 +1150,7 @@ static void rev_run(uint32_t ty, const int32_t *rev_in, int32_t *out, uint32_t n static void rev_state_clear(void) { uint32_t i; + room_used = 0; for (i = 0; i < sizeof rev_comb / 2u; i++) rev_comb[i] = 0; for (i = 0; i < sizeof rev_u.ap / 2u; i++) /* (int16: 997 of them, an odd count the int32 view misses one of) */ @@ -1495,6 +1522,23 @@ static int32_t fx_glide(int32_t cur, int32_t to, uint32_t n) if (s * (int32_t)n < d && d < 0) s = d / (int32_t)n; return s; } +/* Full-rate, mono, non-granular delay with a proven zero line and filters. + * All other configurations conservatively keep the original processing. + * This is not a send-level bypass: a single real input disables it until an + * explicit FX reset, so long echoes, feedback and low-level tails survive. */ +static __attribute__((noinline)) int delay_zero(const int32_t *in, uint32_t n, uint32_t low, int32_t ping, int32_t wide) +{ + uint32_t i; + if (dly_used) return 0; + if (low || ping || wide || fx.dsw || fx.dr_sh || fx.gr_on || fx.gr_old || + fx.dr_xf || fx.dr_now != fx.dl_now) { dly_used = 1; return 0; } + for (i = 0; i < n; i++) if (in[i]) { dly_used = 1; return 0; } + for (i = 0; i < n; i++) dlo_x[i] = dlo_xr[i] = 0; + fx.dly_w += n; + fx.dl_xf = fx.dl_xf > n ? fx.dl_xf - n : 0; + return 1; +} + static inline __attribute__((always_inline)) void fx_buses(const int32_t *cho_in, const int32_t *dly_in, const int32_t *rev_in, int32_t *wet, uint32_t n) { @@ -1586,7 +1630,9 @@ static inline __attribute__((always_inline)) void fx_buses(const int32_t *cho_in } rev_in = rpre_out; } - if (dly_lo_on) { /* (0.8.4) the delay at half / a quarter rate, or changing its + if (delay_zero(dly_in, n, (uint32_t)dly_lo_on, png, wd)) { + dly_lo_on = 1; /* existing loop consumes an exact zero stereo block */ + } else if (dly_lo_on) { /* (0.8.4) the delay at half / a quarter rate, or changing its * rate: its block first (dly_lo), the loop below takes it */ dlyk_t k; k.fb = fb; k.fb2 = fb2; k.hk = hk << fx.dr_sh; k.dig = dig; k.dton = dton; k.png = png; k.wd = wd; @@ -2307,6 +2353,7 @@ static __attribute__((noinline)) void fx_trip(uint32_t c1, uint32_t n) rev_clear(); /* (the pre-delay's line too: rev_x) */ fx.dt1 = fx.dt2 = fx.rt1 = fx.rt2 = 0; fx.dly_lp = fx.dly_hp = fx.rf_lp = fx.rpre_s = fx.cl_lp = fx.cl_half = 0; + dly_used = 0; fx_bad = 0; fx_trips++; if (c1) { diff --git a/firmware/src/voice.c b/firmware/src/voice.c index 7ecde676..4bd34fb0 100644 --- a/firmware/src/voice.c +++ b/firmware/src/voice.c @@ -326,11 +326,18 @@ static uint32_t voices_busy(void) /* sounding voices of al return n; } +/* Key-up ends a melodic hold, but a one-shot drum is still a live hit. + * Allocation/shedding must not confuse its key-up with a disposable release. */ +static int voice_held(const track_t *t, const voice_t *v) +{ + return v->gate || ENGINES[t->engine]->oneshot; +} + static uint32_t lowest_held(const track_t *t) /* index of the lowest held note (the bass), NVOICE = none */ { uint32_t i, low = NVOICE; for (i = 0; i < NVOICE; i++) - if (t->v[i].active && t->v[i].gate && (low == NVOICE || t->v[i].note < t->v[low].note)) + if (t->v[i].active && t->v[i].stage != 4u && voice_held(t, &t->v[i]) && (low == NVOICE || t->v[i].note < t->v[low].note)) low = i; return low; } @@ -352,7 +359,7 @@ static uint32_t voice_victim(const track_t *self, int soft, track_t **pp) uint32_t c; if (!v->active || v->stage == 4u) continue; - if (!v->gate) + if (!voice_held(t, v)) c = 1; /* released */ else if (mode != V_POLY && i > 0) c = 2; /* extra UNISON, or a voice left by a mode / cap change */ @@ -394,7 +401,7 @@ static uint32_t quiet_tail(track_t **pp) for (p = 0; p < NPART; p++) for (i = 0; i < NVOICE; i++) { const voice_t *v = &trk[p].v[i]; - if (!v->active || v->gate || v->stage == 4u || v->env_out >= 104) + if (!v->active || voice_held(&trk[p], v) || v->stage == 4u || v->env_out >= 104) continue; if (best == NVOICE || v->age < (*pp)->v[best].age) { best = i; @@ -461,7 +468,7 @@ static voice_t *voice_alloc(track_t *t, uint32_t note) * an extra fading voice for several blocks. Held notes stay protected. */ if (full) { for (i = 0; i < np; i++) - if (t->v[i].active && !t->v[i].gate && t->v[i].stage != 4u && + if (t->v[i].active && !voice_held(t, &t->v[i]) && t->v[i].stage != 4u && (own == np || t->v[i].age < t->v[own].age)) own = i; if (own < np) @@ -499,10 +506,10 @@ static voice_t *voice_alloc(track_t *t, uint32_t note) if (best < np) return &t->v[best]; for (i = 0; i < np; i++) /* the lowest held note is protected */ - if (t->v[i].gate && (low == np || t->v[i].note < t->v[low].note)) + if (t->v[i].active && t->v[i].stage != 4u && voice_held(t, &t->v[i]) && (low == np || t->v[i].note < t->v[low].note)) low = i; for (i = 0; i < np; i++) /* oldest released (not one fading out for another part) */ - if (!t->v[i].gate && t->v[i].stage != 4u && (best == np || t->v[i].age < t->v[best].age)) + if (!voice_held(t, &t->v[i]) && t->v[i].stage != 4u && (best == np || t->v[i].age < t->v[best].age)) best = i; if (best == np) for (i = 0; i < np; i++) /* oldest held, not the bass */ diff --git a/tests/audio_test.c b/tests/audio_test.c index b825db34..7526afd5 100644 --- a/tests/audio_test.c +++ b/tests/audio_test.c @@ -396,6 +396,45 @@ static void polyphony_headroom(void) mc_host = mc_off = 0; sys_load = LOAD_FULL; fresh(); } +/* A drum's MIDI key-up is not the end of its sound: its one-shot envelope + * still owns a live hit. Reproduce loss with DRUM-X plus three synth tracks. */ +static void drum_budget(void) +{ + uint32_t p, i; + voice_t *kick, *hat; + int32_t out[2*CTL]; + fresh(); host_preset(&trk[0], ENGI_DRUM, 0); + trk_note_on(&trk[0], 36, 100); trk_note_off(&trk[0], 36); + for(p=1;p<4;p++) { + host_preset(&trk[p],p&1?ENGI_FM6:ENGI_VOICE,0); + trk[p].p[P_VOICE]=V_MONO; trk_note_on(&trk[p],60+p,100); + } + for(i=0;i<8;i++) mix_block(out,CTL); + kick=held(&trk[0],36); shed_voice(); + check("DRUM-X + 3 tracks: overload cannot shed the last live hit just because its key is up", + kick && kick->active && kick->stage!=4 && shed_count==0); + + fresh(); host_preset(&trk[0], ENGI_DRUM, 0); + trk_note_on(&trk[0],36,100); trk_note_off(&trk[0],36); + voice_trims=0; load_tight=1; trk[1].p[P_VOICE]=V_MONO; trk_note_on(&trk[1],60,100); + kick=held(&trk[0],36); + check("DRUM-X: an unrendered pending hit is not a quiet release tail",kick && kick->stage!=4 && voice_trims==0); + + fresh(); host_preset(&trk[0], ENGI_DRUM, 0); + trk_note_on(&trk[0],36,100); trk_note_off(&trk[0],36); + for(p=1;p<4;p++) { + host_preset(&trk[p],p&1?ENGI_FM6:ENGI_VOICE,0); + trk[p].p[P_VOICE]=V_POLY; + trk_note_on(&trk[p],48+p,100); trk_note_off(&trk[p],48+p); + trk_note_on(&trk[p],60+p,100); + } + trk_note_on(&trk[1],67,100); /* eight admitted voices, including released synth tails */ + kick=held(&trk[0],36); trk_note_on(&trk[0],42,100); hat=held(&trk[0],42); + check("DRUM-X: new hat at capacity retains the kick and takes a released synth tail", + kick && kick->active && kick->note==36 && kick->stage!=4 && hat && hat!=kick && voices_busy()==8); + fresh(); +} + int main(void) { setvbuf(stdout, NULL, _IONBF, 0); @@ -404,6 +443,7 @@ int main(void) overload(); dma(); usb_in(); /* (last: its reverb tail would reach the tests after it) */ polyphony_headroom(); + drum_budget(); printf(bad ? "audio: %d FAILED\n" : "audio: all passed\n", bad); return bad != 0; } diff --git a/tests/empty_fx_test.c b/tests/empty_fx_test.c new file mode 100644 index 00000000..cd9374c9 --- /dev/null +++ b/tests/empty_fx_test.c @@ -0,0 +1,56 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Compare all zero-buffer shortcuts against forcing the original FX kernels. + * Covers fresh silence, sends, tails, resets, stereo/grain delay, reverb models, + * parameter movement and LOAD changes; hash complete audio, FX state and buffers. + */ +#define main hostsim_main +#include "hostsim.c" +#undef main +static uint64_t hash_bytes(uint64_t h,const void *p,size_t n) +{ + const uint8_t *s=p; + while(n--) h=(h^*s++)*1099511628211ull; + return h; +} +int main(int argc,char **argv) +{ + uint64_t h=1469598103934665603ull; + uint32_t reference=argc>1&&!strcmp(argv[1],"reference"), b,i,rng=12345,skips=0; + host_tracks_init(); + for(b=0;b<12000;b++) { + uint32_t send=b%2000u>=500u&&b%2000u<520u; + if(b==2000 || b==8000) fx_trip(0,CTL); + if(b>=3000 && b<6000) { + song.g[G_DPING]=(b/700)%2; song.g[G_WIDTH]=(b/500)%128; + song.g[G_DPIT]=(b/800)%3; song.g[G_DSPRY]=(b/900)%20; + song.g[G_RTYPE]=(b/400)%5; song.g[G_RMOD]=(b/37)%100; + } else { + song.g[G_DPING]=song.g[G_WIDTH]=song.g[G_DPIT]=song.g[G_DSPRY]=0; + song.g[G_RTYPE]=song.g[G_RMOD]=0; + } + song.g[G_CDEPTH]=(b/19)%128; song.g[G_CRATE]=(b/37)%128; + song.g[G_CSTER]=(int32_t)((b/7)%128)-64; + sys_load=(b/500)%3; + for(i=0;i>16)-32768:0; + fxq_d[i]=fxq_r[i]=send?(int32_t)(rng>>17)-16384:0; + } + if(reference) { room_used=dly_used=1; cho_zeros=0; } /* force original kernels even when their buffers are pristine */ + else if(cho_zeros>=CHO_LEN&&!send) { + skips++; + for(i=0;i