Files
JIANT/tests/loopq_test.c
T
Claude d03b4046e2 V10.8.71: FX > OTT, JIANT BYTE's two-band compressor on each track
Juan approved the port. BYTE 43923fd4 (Juan's GPL code), on FM's tracks,
FX chain, UI, project and preset formats and editor protocol:
- fx.c ott_block, after DIST in mix_part: a one-pole split at X-OVER,
  each band's block peak followed in log2 at TIME, the gains computed
  once a block and ramped across the next. DEPTH 0: not called, the
  track bit for bit. Under the overload guard (voice.c) half the depth;
  past 90 % average load none. The sound is never cut.
- The gain law is BYTE v1.1b4's, from the spec (Juan: "at 100 it barely
  changes the sound"): up to +28 dB upward below -12 dBFS, about 10:1
  downward above -15 dBFS, DEPTH squared, TIME 72 by default (attack
  ~1.5 ms, release ~40 ms), an 8:1 limiter over -3 dBFS. A -40 dBFS
  sine comes out at -13.5 dBFS, a -6 dBFS one at -10.1.
- FX > TRACK's fourth page OTT: DEPTH TIME UP/DN X-OVER (page ids
  0xB0..0xB3: BYTE's 0xD0 is DRONE CLAY's here). Its name large
  (page_big), LOW and HIGH: the level in dim grey cells (gx_col), the
  gain on the thermal ramp by its amount, with its dB. HOME's ECO tags
  a track with OTT on, in the same thermal colour.
- Kept with a project ('O' 'T' after 'G' 'T') and a user preset (byte
  138 'O', the four before it). Each value is stored less its default,
  so TIME, UP/DN and X-OVER are kept at DEPTH 0 too (BYTE's pending
  fix). Older files load with OTT off.
- Editor protocol 1.4: special ids P_COUNT + 0..3 (123..126) for OTT
  through TRACK_PARAM (31) and DESC; UI caps bit 4. BYTE's 0xD0..0xD3
  are not 7-bit bytes, and 0x50..0x53 are FM parameters. GET / SET,
  DUMP and the pushes are unchanged.
- GLO's map names A4 RESOUND, as G4 UNDO.

Flash (V10.8.70: 228 B free; OTT costs ~1.9 KB):
- str_cat and fmt_cat: one helper for the UI's 143 appends and 32
  number appends (-680 B image, -64 B BT);
- project.c: one writer and one reader for the array blocks
  (proj_blk, proj_at, proj_get: -500 B);
- more name tables packed with str_nth; the three note-name tables
  are one list;
- fam_on, home_is, ui_timers: one helper each;
- DRONE CLAY's main-loop side built for size; a note's start, a
  FILL, a CLAY strike and other once-an-event sound functions
  built for size (size_fns.py event_size).
Image 176 B free, BT 88 B free, RAM .data+.bss 1072 B free, pool spare
8224 B, RAM code 40200 of 42496 B. audio.c is V23's; the V23 renders
are present. REPIN=keep; a plain build passes.

CPU (tests/cpu_lines_test.py), each scene's worst block on core 0 and
core 1, V10.8.70 -> V10.8.71 OTT off -> every track at DEPTH 100:
  101 78/44 -> 79/44 -> 83/47    102 61/28 -> 62/28 -> 66/31
  103 80/14 -> 81/14 -> 84/14    104 46/14 -> 46/14 -> 49/14
  105 65/41 -> 66/41 -> 69/44    106 52/35 -> 53/36 -> 56/39
  107 58/11 -> 58/11 -> 62/11    108 51/29 -> 51/29 -> 55/32
  0c  70/58 -> 70/58 -> 74/62
With OTT off the sound's code sits up to 28 B off its old 32-byte
lines (the layout moved). The same build without the per-event minsize
measures the same.

tests/ott_test.c (in CI), cpu_lines_test.c CL_OTT, app_contract (the
special ids), ui_test (the FX chain of 20, GLO's RESOUND).

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

90 lines
4.1 KiB
C

// Copyright (C) 2026 Juan Ignacio Antonucci (Juan Jiant). All rights reserved.
/* (V10.8.66, JIANT BYTE 68b546c9's loopq) MATH's LOOP with WAVE SYNC: 1 .. 8 a division of the song (4 BAR .. 1/32),
* the window aligned to the transport, the note's t from 0 at each window's start. LOOP 0 and every other WAVE as
* before (the hashes taken from V10.8.65's code); at 125 BPM a bar is a whole number of blocks (1440 x 64), so a
* 1 BAR loop repeats sample for sample, and two notes started at different times play the same loop on the same bars.
* Built and run by CI (voice-user-check.yml) */
#define UI_TEST_NO_MAIN 1
#include "ui_test.c"
/* WAVE w, LOOP lp, note n, BPM bpm: the note starts at block st; nb blocks rendered into out (or hashed if out == 0) */
static uint32_t run(int16_t w, int16_t lp, uint32_t n, int bpm, uint32_t st, uint32_t nb, int32_t *out)
{
static track_t t;
static voice_t v;
static int32_t o[CTL];
vmod_t m;
tsvf_t flt;
uint32_t k, i, h = 2166136261u;
memset(&t, 0, sizeof t); memset(&v, 0, sizeof v); memset(&m, 0, sizeof m);
t.p[P_E0] = 2; t.p[P_E1] = w; t.p[P_E2] = 4; t.p[P_E7] = lp; t.p[P_FCUT] = 127; t.p[P_FRES] = 50;
m.amp0 = m.amp1 = 32767; m.shape = 64 << 8;
tsvf_coef(&flt, 127 << 8, 50);
song.g[G_BPM] = bpm;
bar_n = 0; beat_n = 0; beat_pos = 0;
for (k = 0; k < nb; k++) {
memset(o, 0, sizeof o);
if (k == st)
lofi_note_on(&t, &v);
if (k >= st)
lofi_byte_render(&t, &v, o, CTL, &m, pitch_inc((int32_t)n << 4), 1, 8, &flt);
for (i = 0; i < CTL; i++) {
h = (h ^ (uint32_t)o[i]) * 16777619u;
if (out) out[k * CTL + i] = o[i];
}
beat_pos += CTL;
if (beat_pos >= beat_samples()) {
beat_pos -= beat_samples();
beat_n = (beat_n + 1u) & 3u;
if (!beat_n) bar_n++;
}
}
return h;
}
#ifndef LOOPQ_H0 /* (V10.8.65's own: run with an argument on that code to print them) */
#define LOOPQ_H0 0x0306bb47u
#define LOOPQ_H1 0x0306bb47u
#define LOOPQ_H2 0x39bbfc71u
#define LOOPQ_H3 0x57add740u
#define LOOPQ_H4 0x57add740u
#define LOOPQ_H5 0x57add740u
#endif
int main(int argc, char **argv)
{
static const struct { int16_t w, lp; } C[] = {{7, 0}, {7, 40}, {7, 127}, {5, 0}, {5, 3}, {5, 60}};
static const uint32_t H[6] = {LOOPQ_H0, LOOPQ_H1, LOOPQ_H2, LOOPQ_H3, LOOPQ_H4, LOOPQ_H5};
uint32_t bar, k, nb, eq, eq2;
static int32_t a[8000 * CTL], b[8000 * CTL];
int bad = 0, i;
for (i = 0; i < 6; i++) {
uint32_t h = run(C[i].w, C[i].lp, 60, 120, 0, 1500, 0);
if (argc > 1) { printf("#define LOOPQ_H%d 0x%08xu\n", i, h); continue; }
char s[96];
snprintf(s, sizeof s, "as before: WAVE %s LOOP %d", C[i].w == 7 ? "SYNC" : "BYTE", C[i].lp);
bad += check(s, h == H[i]);
}
if (argc > 1)
return 0;
song.g[G_BPM] = 125;
bar = 4u * beat_samples() / CTL;
nb = bar * 4u;
run(7, 3, 60, 125, 0, nb, a); /* (1 BAR) */
eq = memcmp(&a[bar * CTL], &a[2u * bar * CTL], bar * CTL * sizeof a[0]) == 0
&& memcmp(&a[bar * CTL], &a[3u * bar * CTL], bar * CTL * sizeof a[0]) == 0;
bad += check("SYNC LOOP 1 BAR at 125 BPM: bars 2, 3 and 4 the same, sample for sample", eq);
run(7, 3, 60, 125, 300, nb, b); /* (the same note, started 300 blocks later) */
eq2 = memcmp(&a[2u * bar * CTL], &b[2u * bar * CTL], 2u * bar * CTL * sizeof a[0]) == 0; /* (bars 3 and 4: the filters' state settled) */
bad += check("SYNC LOOP 1 BAR: a note started later plays the same loop on the same bars", eq2);
run(7, 0, 60, 125, 0, nb, b);
bad += check("SYNC LOOP OFF: bars 2 and 3 differ (no loop)", memcmp(&b[bar * CTL], &b[2u * bar * CTL], bar * CTL * sizeof b[0]) != 0);
#ifndef LOOPQ_OLD
{
int nm = 1;
for (k = 0; k < 9; k++) { char v[8]; const char *u; param_format(&LOFI_LOOPQ, (int32_t)k, v, &u); nm &= !strcmp(v, str_nth(N_LOOPQ, k)); }
bad += check("the card names LOOP 0 .. 8: OFF 4 BAR .. 1/32", nm);
}
#endif
printf(bad ? "loopq: %d FAILED\n" : "loopq: all ok\n", bad);
return bad != 0;
}