Files
JIANT/tests/stems_test.c
T
Claude 86e7c7659e V10.6z10: GENE's throws of a genre no longer the same song: bass, drums' DNA, sounds, tempo, progression grammar, developing sections, OCT+ anti-repeat
- bass: the archetype varied every throw (gba_vary, by COMPLEX), the rows' first archetype no more favoured, rows with
  one twice given another (TECH HOUSE REGGAETON DEMBOW ELECTRO FUGA BAILE FUNK HIP HOP and its drill / boom bap, TECHNO
  ROCK's rock; JAZZ a third walk, BA_WALK3); the PHONK / BAILE FUNK riffs varied the same way
- sounds: the sound loop starts at a throw's own track (FM6's two to whichever roles come first: IDM GLITCH's RING BELL
  98 % -> ~60 %); 35 % of the time another preset of the engine of the same type (EBM's bass kept); no recipe option
  twice (SUB BASS, 808, upright, cowbell, chant); INIT presets never thrown; drive / chorus / detune a little wider
- tempo: a third of the genre's range either way around ENERGY's point (3 at least; JAZZ's +-3: its energy is ballad
  .. bebop)
- drums: a genre's groove DNA (gen_tables.c GDNA): its extra kicks in two idiomatic places, the pools every genre takes
  but its identity's lanes (cumbia's guiro, the dembow riddim, tribal's toms, electro's and phonk's cowbell, baile
  funk's atabaque, jazz's ride; V10.6m's own hats kept), euclids in the percussion pools, ghosts from a throw's own
  place in the ranking, the first bar varied at half strength, IDM's breaks one of three more half the time
  (DM_FUNKY, DM_THINK, IDM_ALT)
- harmony: a progression grammar a harmony family (gx_prog(fam): two or four chords from the tonic, the family's root
  moves and quality), the genre's own 35 % of the time (a one-chord genre's 50 %), checked by gprog_ok
- sections: their bass, chords and arp streams salted by the section, the lead's same motif by another operator and
  phrase, one-chord pieces' sections denser or thinner (ENERGY) and higher or lower (the arp's and lead's windows)
- OCT+: never a seed whose core (progression, bass, map, drums' DNA) is one of the genre's last eight throws' (up to
  eight more seeds; a seed is still its song)
- flash: the gen code ~1.2 KB shorter (gs's fields reordered, the unread snare mask gone, two helpers) pays for it:
  616 B free (608 before), the BT segment 76 B free (80), RAM +4 B; gprog_ok in the app (the segment full)
- tests: gen_test's new checks (OCT+ anti-repeat, a seed its song, IDM maps, basses, progressions, kick anchors),
  thresholds measured (leaps 66 %, C's colours 4 %, drums' share 97 %, FUGA's bass out of the roots' count, the
  soft kit's open hat 84), the GENE message; stems_test's first EXPLORE seed 43

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ANe9VnsP3SadWTYQD8zCJ6
2026-11-08 15:54:25 +00:00

205 lines
10 KiB
C

/* SPDX-License-Identifier: GPL-3.0-only
* Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */
/* (0.9.8) MENU > USB STEMS, the render side (fx.c stem_buf / stem_fx, what usb.c uac_tap8 sends), on the host build of
* the UI tests: dense DICE (EXPLORE) songs of six tracks played for seconds, the stems tapped each block as the audio
* ISR does, against each track rendered alone in the same take (the others played but left out of the mix: mix_skip, as
* the emulator's offline stems), from the same state (fork):
* null every stem bit for bit its track's solo render, in LOAD FULL, LITE and ECO, one core and CORES 2 (no bleed,
* no sound of a voice in another track's stem, no block given to the wrong part, the PAN out, LEVEL, DIST,
* DUCK, mutes in);
* sum the six stems and the FX return add up to the mix as the buses hear it, each block (before the master: the
* DJ FILTER, CLIP and the leveler off), within the stems' halving (L + R >> 1);
* silence a track with nothing to play is a stem of exact zeros;
* SLICER a track through it: its stem is the SLICER's output, bit for bit its solo render, the sum still the mix
* (until 0.9.7 its dry sound was in its stem and again, sliced, in the FX return); FX ON: in the FX return;
* ECO its tail trimming (the load budget, LOAD tight) and the shared voice cap act on the take itself: the stems
* keep exactly what the mix plays (they null against the solo render of the same take), however many voices
* the budget gave up (counted). */
#define UI_TEST_NO_MAIN 1
#include "ui_test.c"
#include <sys/mman.h>
#include <sys/wait.h>
#define NCH 9 /* T1..T6, FX L R, and (sum check) a flag */
static int st_fail;
static int st_check(const char *what, int ok)
{
printf("stems: %-104s %s\n", what, ok ? "ok" : "FAIL");
st_fail += !ok;
return ok;
}
static void song_from(uint32_t seed, uint32_t load)
{
uint32_t k;
ui_power_on();
ui_rec_prefs |= PREF_SIX >> 8;
ui_load = (uint8_t)load;
rp_apply(); /* TRACKS 6, LOAD */
gp.genre = GEN_EXPLORE; gp.seed = (uint16_t)seed; gp.energy = 95; gp.form = 0;
for (k = 0; k < GP_N; k++) gp.amt[k] = GA_AUTO;
gp.complex = 70; gp.swing = GA_AUTO; gp.human = 30;
gen_go();
song.g[G_DJF] = 0; /* (the sum is checked before the master: these off) */
song.g[G_CLIP] = 0;
}
/* nb blocks of the song (the transport started here), the stems tapped into d[frame][NCH]; skip: the parts left out of
* the mix. Returns the blocks whose sum matched the mix (sum_ok) of those checked (sum_n), the voices given up */
static uint32_t sum_ok, sum_n, gave_up, worst;
static void play(int32_t (*d)[NCH], uint32_t nb, uint32_t skip, uint32_t cores, int tight)
{
uint32_t b, i, k;
song.master_q12 = 4096;
mix_skip = (uint8_t)skip;
mc_host = (uint8_t)cores;
transport_req = 1;
sum_ok = sum_n = worst = 0;
gave_up = voice_kills;
for (b = 0; b < nb; b++) {
int32_t o[2 * CTL];
if (b % 32u == 0u) { ui_input(); song_poll(); host_ticks += 20000u; fm1_ms += 20u; }
fx_stems = 1; /* (as MENU > USB STEMS: ui_input follows the menu's choice) */
if (tight)
load_tight = 1; /* (the load budget held: a render over 50 % on ECO) */
mix_block(o, CTL);
for (i = 0; i < CTL; i++) {
for (k = 0; k < NPART; k++)
d[b * CTL + i][k] = stem_buf[k][i];
d[b * CTL + i][6] = stem_fx[0][i];
d[b * CTL + i][7] = stem_fx[1][i];
}
if (!clip_g && !djf.mode && !skip) { /* the mix as the buses hear it: mix_l + wet (master_out's input) */
uint32_t bad = 0;
for (i = 0; i < CTL; i++) {
int32_t s = 0, m = mix_l[i] + mix_r[i] + 2 * wet[i], e;
for (k = 0; k < NPART; k++)
s += 2 * stem_buf[k][i];
s += stem_fx[0][i] + stem_fx[1][i];
e = s > m ? s - m : m - s;
if (e > (int32_t)worst) worst = (uint32_t)e;
bad |= e > (slicer_on() ? 6 : 2) * NPART; /* (each stem's >> 1 floors: up to 1 off, doubled; through
* the SLICER its gain's too) */
}
sum_n++;
sum_ok += !bad;
}
}
gave_up = voice_kills - gave_up;
transport_req = 2;
{ int32_t o[2 * CTL]; ui_input(); mix_block(o, CTL); }
}
/* the take in full, then each track alone (its solo render), every one from the same state: returns the stems that
* are not bit for bit their solo render; *energy: tracks that sounded */
static int32_t null_tol; /* (the SLICER's gain on each part apart: its rounding) */
static uint32_t take(uint32_t nb, uint32_t cores, int tight, uint32_t *sounding, uint32_t *gave, uint32_t *sums)
{
size_t sz = sizeof(int32_t) * NCH * CTL * nb;
int32_t (*full)[NCH] = mmap(0, sz, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
int32_t (*solo)[NCH] = mmap(0, sz, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
uint32_t *res = mmap(0, 4 * sizeof(uint32_t), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
uint32_t k, i, bad = 0, snd = 0;
pid_t p;
fflush(stdout);
if (!(p = fork())) {
play(full, nb, 0, cores, tight);
res[0] = gave_up; res[1] = sum_ok; res[2] = sum_n; res[3] = worst;
_exit(0);
}
waitpid(p, 0, 0);
*gave = res[0];
*sums = res[2] && res[1] == res[2];
for (k = 0; k < NPART; k++) {
uint32_t nd = 0;
double e = 0;
if (!(p = fork())) {
play(solo, nb, 0x3Fu & ~(1u << k), cores, tight);
_exit(0);
}
waitpid(p, 0, 0);
for (i = 0; i < CTL * nb; i++) {
nd += full[i][k] - solo[i][k] > null_tol || solo[i][k] - full[i][k] > null_tol;
e += (double)full[i][k] * full[i][k];
}
snd += e > 0;
bad += nd != 0;
if (nd)
printf(" T%u: %u samples differ from its solo render\n", k + 1, nd);
}
if (!*sums)
printf(" the sum: %u of %u blocks match the mix (worst %u)\n", res[1], res[2], res[3]);
*sounding = snd;
munmap(full, sz); munmap(solo, sz); munmap(res, 4 * sizeof(uint32_t));
return bad;
}
int main(void)
{
static const char *const LOADS[3] = {"FULL", "LITE", "ECO"};
static const uint32_t SEEDS[3] = {43, 11, 123}; /* (p4: EXPLORE sparser; 3 came to three tracks; V10.6z10: 42's
* piece now dense enough on FULL that the shared voice budget
* cuts a bass tail in the mix the solo render keeps: 43, five
* tracks sounding) */
char s[200];
uint32_t si, l, c, nb = (uint32_t)(4.0 * FS / CTL); /* 4 s a take */
printf("-- the stems (fx.c) against each track's solo render\n");
for (si = 0; si < 3u; si++)
for (l = 0; l < 3u; l++)
for (c = 0; c < 2u; c++) {
uint32_t snd, gave, sums, bad;
if (c && (l == 1u || si == 2u))
continue; /* (CORES 2 on FULL and ECO, two songs: enough) */
song_from(SEEDS[si], l);
bad = take(nb, c, 0, &snd, &gave, &sums);
snprintf(s, sizeof s, "DICE %u, %s, %s: %u tracks sounding, %u voices given up: 6 stems = solo renders, sum = mix",
SEEDS[si], LOADS[l], c ? "CORES 2" : "one core", snd, gave);
st_check(s, !bad && sums && snd >= 4u);
}
{ /* ECO with the load budget held all along: its quiet tails trimmed, in the mix and the stems alike */
uint32_t snd, gave, sums, bad, t0 = voice_trims;
song_from(42, LOAD_ECO);
bad = take(nb, 1, 1, &snd, &gave, &sums);
snprintf(s, sizeof s, "ECO, the load budget tight: %u voices given up (tails under -50 dB), the stems still the solo renders, sum = mix",
gave);
st_check(s, !bad && sums && gave > 0);
(void)t0;
}
{ /* an empty track: exact zeros */
size_t sz = sizeof(int32_t) * NCH * CTL * 2000u;
int32_t (*d)[NCH] = mmap(0, sz, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
uint32_t i, nz = 0, e = 0;
song_from(11, LOAD_FULL); /* (p4: 42's T1 rests now) */
for (i = 0; i < NSTEP; i++) trk[5].step[i].time = ST_REST;
for (i = 0; i < NVOICE; i++) trk[5].v[i].active = 0;
play(d, 2000u, 0, 1, 0);
for (i = 0; i < CTL * 2000u; i++) { nz += d[i][5] != 0; e += d[i][0] != 0; }
st_check("a track with nothing to play: its stem exact zeros (T6 empty, T1 playing)", nz == 0 && e > 1000u);
munmap(d, sz);
}
{ /* the SLICER: T2 through it (GATE, then STUT), T2 and T5, then everything with its FX ON (its defaults) */
static const struct { int mode, fx; uint8_t mask; const char *what; } V[4] = {
{1, 0, 0x02, "GATE on T2"}, {2, 0, 0x02, "STUT on T2"}, {1, 0, 0x12, "GATE on T2 and T5"},
{2, 1, 0x3F, "STUT on all six, FX ON (its defaults)"}};
uint32_t v, i;
for (v = 0; v < 4u; v++) {
uint32_t snd, gave, sums, bad;
song_from(11, LOAD_FULL); /* (p4: 42's T1 rests now) */
song.g[G_SLMODE] = V[v].mode;
song.g[G_SLFX] = V[v].fx;
for (i = 0; i < NPART; i++)
song.g[G_SLT1 + i] = (V[v].mask >> i) & 1u;
null_tol = 2;
bad = take(nb, 1, 0, &snd, &gave, &sums);
null_tol = 0;
/* (one part through it: its stem is it alone through it; several, or the returns too: one bus, so its
* repeats are in one place (the first part's stem, or the FX return) and only the sum must hold) */
snprintf(s, sizeof s, "SLICER %s: %s; the sum = the mix (until 0.9.7 the bus twice: dry in the stems, sliced in FX)",
V[v].what, V[v].mask == 0x02 ? "T2's stem T2 alone through it (within 2 LSB)" : "each part at the gain it got");
st_check(s, sums && (V[v].mask != 0x02 || !bad));
}
}
printf(st_fail ? "STEMS TEST FAILED (%d)\n" : "stems: all ok\n", st_fail);
return st_fail != 0;
}