Files
JIANT/tests/gen_dump.c
Claude d3bb2ebebc V10.8.72: GEN puts OTT on the electronic genres, a much harder OTT, BYTE's formula DIST types, VISUAL steady under load
Juan: "Habría que implementar el OTT en el generador para los géneros más
electrónicos".

GEN (gen.c gen_ott, after the mix and the FX; RESOUND too):
- GOTT, a genre each, the drums and the bass at DEPTH 40 .. 60:
  - 40: HOUSE, DEEP HOUSE, MINIMAL (its sub alone, 1 dB up);
  - 44: TECH HOUSE, TRIBAL (drums only), REGGAETON, IDM GLITCH (drums
    only), TECHNO ROCK (its synth 80s);
  - 48 .. 54: DRUM & BASS, ELECTRO, BREAKBEAT, DEMBOW, ELECTRO METAL,
    HIP HOP's trap, drill and pluggnb, HARD TECHNO, EBM, BAILE FUNK;
  - 60: HARD BASS, PHONK, DUBSTEP.
  MOOD DANCE adds 4.
- In most of them, one seed in two, the lead goes hard at 60 .. 78. When
  the lead is a riff already up front (GAIN 6), the texture takes it.
  Pads never. Three tracks at most.
- Per role TIME, UP/DN and X-OVER: the drums TIME 44 and a little less
  upward, the bass X-OVER 26 (its sub whole), the lead X-OVER 55.
- None on the acoustic and organic genres (cumbia, jazz, neo classic,
  dream pop, shoegaze, kraut, metalcore, IDM ambient and weird), on
  HIP HOP's boom bap and lofi, on TECHNO ROCK's rock, on EXPLORE, nor
  at MOOD CALM.
- Each OTT track's LEVEL comes down by the depth squared (gen_peak:
  every piece under -1 dBFS with the trims as they were). No draw from
  the piece's random streams: every other choice is as it was, and the
  seed is still deterministic.
- RESOUND sets the genre's OTT, or clears it, on the tracks it gives
  sounds. A track RESOUND does not touch keeps its OTT.
- Not per section: the sections do not store OTT.

FX > OTT, a much more extreme law (Juan via the coordinator; this
replaces the alignment to BYTE d9feaf71; BYTE v1.1b5 has no commit yet):
- Up at 0.97 dB a dB toward -18 dBFS, at most +36 dB, faded out under
  -66 dBFS (a -46 dBFS band gets +27 dB).
- 20:1 over -22 dBFS, at most -36 dB.
- Both bands driven together into dsp.c's soft clip, +9 dB at the full
  weight: dense and saturated, never a hard clip, never past -0.3 dBFS.
- DEPTH squared to 70, then a cubic to 100 (weight 30: 0.09, 60: 0.36,
  70: 0.49, 80: 0.85, 90: 0.98).
- TIME 48 by default (~32 ms back, 1 ms up), so it pumps with the kick.
- Each block's band peaks are read first, so a hit after quiet is not
  boosted by the quiet's gain, and a gain going down takes effect at
  once. Still a gain per block, then the ramp.
- DEPTH 0 is still not run (bit-exact). Under the overload guard, half
  the weight.
- ott_test: at DEPTH 100 a -46 dBFS sine comes out at -10.0 dBFS and a
  -6 dBFS sine at -7.7 dBFS (from the rms), 2.3 dB apart.
- Stored TIME is kept less its default: a V10.8.71 file's TIME comes out
  24 lower (its default 72 loads as the new default 48).

DIST TYPE gets JIANT BYTE's formula effects (origin/main DIST_EQ; on
BYTE's formula machine there, fixed code here):
- 6 RING, 7 STEPS, 8 XOR, 9 WOB, 10 SFOLD, 11 SAT. They are cases of
  the shaper (dist_shape, in RAM); deq_k gives each block's constant.
- They use BYTE's input scale, TONE stage and blend; there is no low cut
  and no make-up. NOISE moves the input as BYTE's does, at FM's NOISE
  depth.
- SOFT .. AMP keep 0 .. 5, and old projects sound the same.
- Within 1.5 % of the formulas in floating point (dist_eq_test). The
  output is a quarter inside so the TONE poles fit in 32 bits (BYTE's
  can wrap).
- BYTE's GATE, LPF, LFO.F, HPF and RND are left out: the flash.
- The SENDS have no drive of their own in FM (SENDS' DIST is the track's
  DIST), so there is no separate send SAT / SFOLD.

HOME > VISUAL: every frame the UI paces is drawn. V10.8.67 left out
every other or third frame by the animation's ticks, unevenly (3 to 7
drawn a second, gaps of 150 .. 400 ms). Now each frame draws less:
- past 65 % load, the first picture alone and 300 points (copies as the
  budget holds them); past 80 %, 150 points;
- the animation frozen: the picture is kept and not drawn again (it was
  never drawn at FREEZE);
- ui.force is cleared after a VISUAL frame (it was left set).
Host (tests/vis_cadence_test.c), frames a second and work a second,
V10.8.71 -> V10.8.72:
- idle: 66 -> 66;
- 69 % now / 66 % average: 6.7 (gaps 150 ms), 0.6 ms -> 20 (50 ms), 0.4 ms;
- 82 % / 50 %: 6.8 (350 ms), 0.7 ms -> 20 (50 ms), 0.4 ms;
- 82 % / 79 %: 3.3 (400 ms), 0.3 ms -> 10 (100 ms), 0.2 ms.
Off the page nothing of it runs.

MOOD CALM's rows checked: V10.8.68's message said "longer sections,
slower RADIO", but its code is BYTE 09ec6b57's, where Juan asked "CALM's
pieces too long". CALM -50 rows: HOUSE x 12, PARTS 356 bars against
MID's 624, SONG 490 against 1140; the radio loops 9 bars against 17.
Left as it is; gen_entry_test pins the direction.

Flash (V10.8.71: 176 B free; this work ~2.7 KB):
- more enum lists packed in PNE (str_nth): FM6's ALG and SLOT, MATH's
  BYTE and FLOAT, VOICE's LYRIC LANG THEME LOOP, ARP MODE, SCALE,
  ENGINE, KEY MAP, EXT's MODE, STRING's EXCITE, WHEEL's PERC. name_of
  reads packed lists; descdump is identical but for DIST TYPE.
- BTAPP_FN / UH_SEG functions are now seen by size_fns.py; 13 per-key,
  per-step and per-half-buffer sound functions built for size.
- the shaper's soft clip one copy in RAM (dist_sclip, bit-exact).
Image 12 B free, BT 36 B free, RAM .data+.bss 1048 B free, pool spare
8224 B, RAM code 40384 of 42496 B (headroom 2112). audio.c is V23's.
REPIN=keep; a plain build passes.

CPU (tests/cpu_lines_test.py), each scene's worst block, core 0/core 1,
V10.8.71 -> V10.8.72:
  101 79/44 -> 78/44    102 62/28 -> 62/28    103 81/14 -> 85/14 (TRIBAL: OTT drums)
  104 46/14 -> 50/14 (BREAKBEAT: drums, bass)   105 66/41 -> 66/41
  106 53/36 -> 52/36    107 58/11 -> 62/11 (HARD BASS: drums, bass)
  108 51/29 -> 51/29    0c  70/58 -> 70/58
The GEN scenes with OTT pay ~4 % on core 0, mostly ott_block's flash
lines (the first OTT track). DIST at 127 on all six tracks of 101: SOFT
81/46, WOB 81/46, SAT 82/47, RING 84/46 (CL_DTYPE).

gen_peak: 270 pieces, 0 over -1 dBFS (loudest stem -2.5, mix -1.1).
gen_test's mix pass and the rest hold.

Tests:
- ott_test: the law, the curve, GEN's OTT, RESOUND;
- tests/dist_eq_test.c and tests/vis_cadence_test.c are new, in CI;
- app_contract: DIST TYPE's DESC;
- gen_entry: MID recorded again, CALM's direction;
- cpu_lines_test.c: CL_DTYPE;
- the local workflow: all 23 steps pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KMHk6yH4XbP1xxHYKCo9Mh
2026-11-28 15:49:34 +00:00

207 lines
12 KiB
C

/* SPDX-License-Identifier: GPL-3.0-only
* Copyright (C) 2026 Juan Ignacio Antonucci (Juan Jiant)
* The generator audited (firmware/src/gen.c): a piece as text, to read its harmony as a musician reads a lead sheet:
* the key and the SCALE / CHORD pages as GEN wrote them, the chords bar by bar (a symbol and its roman numeral), every
* part a line a bar (the notes by name, '=' held, '.' rest, a chord's notes joined by '/'), each section of a FORM
* (its key). Optionally the piece heard: a WAV of it playing (its song, with PARTS or SONG), SECONDS long.
* cc -O1 -w -Ibuild/gen -Ifirmware/src -Itests -o build/host/gen_dump tests/gen_dump.c -lm
* build/host/gen_dump GENRE SEED [ENERGY [FORM [OUT.wav SECONDS]]] (GENRE 1..NGENRE, NGENRE + 1 EXPLORE, 0 every genre; FORM 0 1 2) */
#define UI_TEST_NO_MAIN 1
#include "ui_test.c"
static const char *NS[12] = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"};
static const char *NF[12] = {"C", "Db", "D", "Eb", "E", "F", "Gb", "G", "Ab", "A", "Bb", "B"};
static const char **NN = NS;
static void spell(void) /* flats in the flat keys (as the relative major's signature) */
{
uint32_t rel = (uint32_t)(gs.root + (gminor() ? 3 : 0)) % 12u;
NN = rel == 5u || rel == 10u || rel == 3u || rel == 8u || rel == 1u || rel == 6u ? NF : NS;
}
static const char *RLN[6] = {"DRUM", "BASS", "PAD", "LEAD", "ARP", "TEX"};
static const char *FAM[6] = {"LOOP", "JAZZY", "POP", "COLOR", "CINE", "JAZZ"};
static const char *CDN[12] = {"OFF", "TRIAD", "7TH", "ADD9", "SUS2", "SUS4", "MAJ", "MIN", "7", "MAJ7", "MIN7", "POWER"};
static const char *QN[4] = {"OFF", "SNAP", "WHITE", "SEQ"};
static void nname(char *b, int n) { sprintf(b, "%s%d", NN[(n % 12 + 12) % 12], n / 12 - 1); }
/* a chord's symbol (Cm7, Ebmaj7, G7, Fsus4, Dm7b5, C(add9), Am9, C5) and its roman numeral in the key */
static void chord_name(const gch_t *c, char *sym, char *rom)
{
static const char *R[7] = {"I", "II", "III", "IV", "V", "VI", "VII"};
int32_t t3 = giv(c, 2), t5 = giv(c, 4), t7 = giv(c, 6), root = (int32_t)gtone(c, 0, 12) % 12;
int32_t rel = ((root - gs.root) % 12 + 12) % 12, dia = gs.sc[c->deg];
uint32_t q = c->q, minor = t3 == 3, i;
const char *tri = t5 == 6 && minor ? "dim" : t5 == 8 ? "+" : minor ? "m" : "", *ext = "";
char r[8];
if (q == Q_7 || q == Q_7NO5) ext = t7 == 11 ? (minor ? "(maj7)" : "maj7") : t7 == 10 ? (t5 == 6 && minor ? "7b5" : "7") : "6";
else if (q == Q_9 || q == Q_R9) ext = t7 == 11 && !minor ? "maj9" : "9";
else if (q == Q_ADD9) ext = "(add9)";
else if (q == Q_6) ext = "6";
else if (q == Q_11) ext = "11";
if (q == Q_7 && t5 == 6 && minor && t7 == 10) tri = "m";
if (q == Q_SUS2) { tri = "sus2"; ext = ""; }
if (q == Q_SUS4) { tri = "sus4"; ext = ""; }
if (q == Q_QUART) { tri = "sus4"; ext = "(7)"; }
if (q == Q_POWER) { tri = "5"; ext = ""; }
sprintf(sym, "%s%s%s", NN[root], tri, ext);
sprintf(r, "%s%s", rel < dia ? "b" : rel > dia ? "#" : "", R[c->deg]);
for (i = 0; minor && r[i]; i++) if (r[i] == 'I' || r[i] == 'V') r[i] = (char)(r[i] - 'A' + 'a');
sprintf(rom, "%s%s%s%s", r, t5 == 6 && minor ? "o" : "", q == Q_7 || q == Q_9 || q == Q_R9 ? "7" : "", c->alt ? "*" : "");
}
static int32_t dump_lift; /* (a section in another key: its notes flagged in its key) */
static void dump_track(const track_t *t, uint32_t r, uint32_t bars)
{
uint32_t i, j, len = dlen(t);
char b[16];
if (r == RL_DRUM) {
static const char *LN[8] = {"BD", "SD", "CP", "CH", "OH", "TM", "RS", "CB"};
uint32_t l;
for (l = 0; l < 8u; l++) {
int any = 0;
for (i = 0; i < len; i++) any |= t->step[i].time == ST_NOTE && (t->step[i].hit >> l) & 1u;
if (!any) continue;
printf(" %-4s ", LN[l]);
for (i = 0; i < bars * 16u && i < len; i++) {
const step_t *s = &t->step[i];
int on = s->time == ST_NOTE && (s->hit >> l) & 1u;
if (i && i % 16u == 0u) putchar('|');
putchar(!on ? '.' : (s->acc >> l) & 1u ? 'X' : s->vel >= 90 ? 'x' : s->vel >= 60 ? 'o' : ',');
}
putchar('\n');
}
return;
}
for (i = 0; i < len; i++) {
const step_t *s = &t->step[i];
if (i % 16u == 0u) printf(i ? "\n | " : " | ");
if (s->time == ST_NOTE && s->n) {
for (j = 0; j < s->n; j++) { nname(b, s->note[j]); printf("%s%s", j ? "/" : "", b); }
if (!gin_mode(s->note[0] - dump_lift)) printf("!");
printf(s->flags & SF_SLIDE ? "~ " : s->flags & SF_ACCENT ? "^ " : " "); /* (V10.6p: a slide, an accent) */
} else printf(s->time == ST_TIE ? "= " : ". ");
}
printf("\n");
}
static void dump_piece(void)
{
uint32_t k, i, bars = (gs.len + 15u) / 16u;
char sym[24], rom[16];
printf("harmony: %s%s%s%s%s%s palette %02x progression:", FAM[HXF(gs.hx) % 6u], gs.hx & HX_RAISE ? " RAISE" : "",
gs.hx & HX_SEC ? " SEC" : "", gs.hx & HX_BOR ? " BORROW" : "", gs.hx & HX_LIFT ? " LIFT" : "", gs.hx & HX_APPR ? " APPR" : "", gs.pal);
for (k = 0; k < gs.pn; k++) printf(" %u%s", gs.pdeg[k] + 1u, QF(gs.pq[k]) ? "*" : "");
printf(" (* coloured: borrowed, secondary, raised)\nchords:");
for (k = 0; k < gs.nch; k++) {
chord_name(&gs.ch[k], sym, rom);
printf(" %s[%s] @%u+%u", sym, rom, gs.ch[k].at, gs.ch[k].len);
}
printf("\n");
for (i = 0; i < bars; i++) {
printf("bar %u:", i + 1u);
for (k = 0; k < gs.nch; k++)
if (gs.ch[k].at / 16u == i) { chord_name(&gs.ch[k], sym, rom); printf(" %s (%s)", sym, rom); }
printf("\n");
}
for (k = 0; k < NTRK; k++) {
const track_t *t = &trk[k];
const engine_t *e = ENGINES[t->eng_req % NENGINES];
uint32_t r = gs.role[k];
if (!gs.act[r] || (r == RL_TEX && k != gs.trk_of[RL_TEX])) { printf("T%u %-4s off\n", k + 1u, RLN[r]); continue; }
printf("T%u %-4s %s %s LEN %d%s\n", k + 1u, RLN[r], e->name, t->preset < e->npresets ? e->presets[t->preset].name : "-",
t->p[P_SLEN], t->p[P_MUTE] ? " MUTED" : "");
dump_track(t, r, 4);
}
}
int main(int argc, char **argv)
{
uint32_t genre = argc > 1 ? (uint32_t)atoi(argv[1]) : 0, seed = argc > 2 ? (uint32_t)atoi(argv[2]) : 1;
uint32_t energy = argc > 3 ? (uint32_t)atoi(argv[3]) : 50, form = argc > 4 ? (uint32_t)atoi(argv[4]) : 0;
const char *wav_path = argc > 5 ? argv[5] : 0;
double secs = argc > 6 ? atof(argv[6]) : 30.0;
uint32_t from = genre ? genre : 1, to = genre ? genre : NGENRE, g, k, s;
ui_power_on(); go_home(); frames(4);
settings.palette = UI_JIANT_INDEX; palette_set(UI_JIANT_INDEX);
ui_rec_prefs |= PREF_SIX >> 8; rp_apply();
song.master_q12 = 4096;
for (g = from; g <= to; g++) {
uint32_t pd;
gp.genre = (uint8_t)g; gp.seed = (uint16_t)seed; gp.energy = (uint8_t)energy; gp.form = (uint8_t)form;
for (k = 0; k < GP_N; k++) gp.amt[k] = GA_AUTO;
gp.complex = 50; gp.swing = GA_AUTO; gp.human = 30;
gen_go();
pd = gs.trk_of[RL_PAD];
spell();
printf("\n=== %s seed %u energy %u form %s %d BPM swing %d\n", gs.g->name, seed, energy, form == 2u ? "SONG" : form ? "PARTS" : "LOOP",
song.g[G_BPM], song.g[G_SWING]);
printf("SCALE page: ROOT %s SCALE %s QUANT %s CHORD page (T%u): %s, VOICING %s, STRUM %d\n", NN[trk[0].p[P_ROOT] % 12],
PN_AT(N_SCALE, trk[0].p[P_SCALE]), QN[trk[0].p[P_QUANT] & 3], pd + 1u, pd < NTRK ? CDN[trk[pd].p[P_CHRD] % 12] : "-",
pd < NTRK && trk[pd].p[P_CVOI] == 1 ? "LEAD" : "CLOSE", pd < NTRK ? trk[pd].p[P_CSTR] : 0);
dump_piece();
if (live.mode && chain_config.count) { /* the sections GEN stored (A is the piece above) */
static project_t p;
printf("song:");
for (k = 0; k < chain_config.count; k++) printf(" %c x%u", 'A' + chain_config.row[k].slot, chain_config.row[k].bars);
printf("\n");
for (k = 0; k < chain_config.count; k++) { /* (V10.6m) each row: its scene (who plays), where from, its VAR */
const scene_t *sc = &song_idx.scene[song_cur][k];
uint32_t t2;
printf(" row %2u %c x%-2u plays:", k + 1u, 'A' + chain_config.row[k].slot, chain_config.row[k].bars);
for (t2 = 0; t2 < NTRK; t2++) {
uint32_t mu = sc->on ? (t2 < 4u ? (sc->mute >> t2) & 1u : (sc->on >> (t2 - 3u)) & 1u) : 0u;
if (!mu && gs.act[gs.role[t2]]) printf(" %s", RLN[gs.role[t2]]);
else if (!mu && gs.role[t2] == RL_TEX && t2 == gs.trk_of[RL_TEX]) printf(" (TEX)");
if (row_src(k, t2, chain_config.row[k].slot) != chain_config.row[k].slot)
printf("<%c", 'A' + row_src(k, t2, chain_config.row[k].slot));
if (row_var(k, t2)) printf("[%s]", str_nth(RV_NAME, row_var(k, t2)));
}
if (sc->mute >> 4) printf(" drum groups out: %s%s%s%s", sc->mute & 0x10u ? "K" : "", sc->mute & 0x20u ? "S" : "",
sc->mute & 0x40u ? "H" : "", sc->mute & 0x80u ? "P" : "");
printf("\n");
}
for (s = 1; s < 4u; s++) {
uint32_t m = 0, mel = 0;
if (!((dice_secs >> s) & 1u) || !proj_import(&p, &proj_slot[s], sizeof(project_store_t))) continue;
for (k = 0; k < NTRK; k++) if (gs.role[k] != RL_DRUM) { mel = k; break; }
printf("--- section %c: ROOT %s SCALE %s; muted:", 'A' + s, NN[p.t[mel].p[P_ROOT] % 12], PN_AT(N_SCALE, p.t[mel].p[P_SCALE]));
dump_lift = ((p.t[mel].p[P_ROOT] - gs.root) % 12 + 12) % 12;
for (k = 0; k < NTRK; k++) if (p.t[k].p[P_MUTE]) { printf(" T%u", k + 1u); m++; }
printf(m ? "\n" : " none\n");
for (k = 0; k < NTRK; k++) {
track_t tt;
uint32_t r = gs.role[k];
if (!gs.act[r] ? !(r == RL_TEX && s == 2u && k == gs.trk_of[RL_TEX]) : (p.t[k].p[P_MUTE] && r != RL_DRUM) || (r == RL_TEX && k != gs.trk_of[RL_TEX])) continue; /* (V10.6m: the drums too, the build's riser) */
memset(&tt, 0, sizeof tt);
memcpy(tt.step, p.t[k].step, sizeof tt.step);
proj_steps(tt.step);
tt.p[P_SLEN] = p.t[k].p[P_SLEN];
printf("T%u %-4s\n", k + 1u, RLN[r]);
dump_track(&tt, r, 4);
}
}
}
dump_lift = 0;
if (wav_path && genre) { /* the piece heard: its song (PARTS, SONG) or its loop */
FILE *w = fopen(wav_path, "wb");
uint32_t nsamp = 0, want = (uint32_t)(secs * FS), f = 0, i;
if (!w) { fprintf(stderr, "cannot write %s\n", wav_path); return 1; }
wav_hdr(w, 0);
if (live.mode) chain_play_ui(); else transport_req = 1;
while (nsamp < want) {
uint32_t upto = (uint32_t)((uint64_t)(++f) * FS / 30u);
ui_input();
song_poll();
while (nsamp < upto && nsamp < want) {
int32_t o[2 * CTL];
int16_t sm[2 * CTL];
mix_block(o, CTL);
for (i = 0; i < 2u * CTL; i++) sm[i] = (int16_t)clamp(o[i], -32768, 32767);
fwrite(sm, 2, 2u * CTL, w);
nsamp += CTL;
}
host_ticks += 1000000u / 30u; fm1_ms += 1000u / 30u;
}
transport_req = 2; ui_input();
fclose(w);
if ((w = fopen(wav_path, "r+b"))) { wav_hdr(w, nsamp); fclose(w); }
printf("wav: %s (%.0f s)\n", wav_path, secs);
}
}
return 0;
}