Files
JIANT/tests/resync_test.c
T
Claude 3c6854b0f5 V10.8.40: the tempo exact and every DIV on one grid, a track's place from the transport's, RESYNC, MOOD on the drums
(a user: "the sequencer creeps ahead of the project's tempo"; the owner: "after a pattern change, an edit, EUCLID, a
variation, a track's start no longer lines up with the others'; I stop and play again")

- the tempo (fx.c beat_samples, seq_time): a beat a multiple of 24 samples, so every division of it is whole and tracks
  on different DIVs, the click and the clock out keep one grid (were FS * 60 / BPM cut, and cut again a division: at
  133 BPM a 1/16 track 8 ms a minute ahead of the tempo, a 1/32 one 20 ms, so 12 ms a minute apart); mix_block leaves
  a sample of the sequencer's time out when what that cut adds up to one: FS * 60 samples are BPM beats exactly
  (tests/drift_test.c: 0 samples after ten minutes, eight tempos, every DIV, SWING, FIT, the click). The DELAY's time
  as it was (the DAC's samples: beat_real)
- a track's place (seq.c seq_anchor): at every step it enters, the step and the samples into it from the transport's
  1/16s since its origin (PLAY, a song's section in, RESYNC) over its DIV. A track left alone is there already; one
  whose LEN or DIV changed under it (EUCLID's STEPS, MUTATE, a variation of another length, the knobs, SWING) is back
  with the others at its next step (tests/resync_test.c: 14 actions x 18 moments and EUCLID's knobs, none off; before:
  11 of the 14 left a track off). LIVE's playheads, a JUMP, FIT's own clock and an odd LEN with SWING as they run
- RESYNC: SEQ held + PLAY while it plays: every track from its first step at the next bar, in time (the banner, the
  [SEQ] layer's footer)
- GEN's MOOD on the drums in every GENRE mode (the owner: "CALM changes nothing audible, everything still has drums"):
  CALM the kit's levels down (the kick first; at -50 a low, short, dark closed hat alone), DANCE drums in every piece,
  a kick on the bar's first and third beats from +25 and on every beat from +40, the kit up and driven; the energy
  +-60 (was 40); MID byte for byte V10.8.39's (gen_entry_test). tests/gen_mood.c: the study's table
- usb_host.c uh_hub_status in the image (the Bluetooth segment's room)
- tests: the clocks that counted the DAC's samples count the sequencer's (rep_sync), the references that hold a
  sequence's timing follow (micro's 0.9.0 render, expr's MIDI OUT checksum, perform's 1/16, 14 golden renders: every
  key kept); layout re-recorded (REPIN=keep)

Image 583316 B of 584336 (1020 B free), RAM 97008 of 98304, RAM code 32504 of 34816, pool spare 8480 B, BT segment
73700 of 73728 B. audio.c as V23's.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KMHk6yH4XbP1xxHYKCo9Mh
2026-11-24 22:29:50 +00:00

107 lines
7.0 KiB
C

/* SPDX-License-Identifier: GPL-3.0-only */
/* Copyright (C) 2026 Juan Ignacio Antonucci (Juan Jiant) */
/* (V10.8.40, the owner: "after changes while it plays a track's start no longer lines up with the others'; stop and
* play again") twin runs through events_block: one left alone, one with a live action on track 1 undone some steps
* later (LEN, DIV, both, a sound's shorter pattern, EUCLID's steps, FIT on and off, a tempo change, SWING), at several
* moments of the bar; a bar after the undo every track's step and its samples into it as the run left alone has them.
* And RESYNC: polymetric tracks from their first step at the next bar, in time, the others untouched */
#define UI_TEST_NO_MAIN 1
#include "ui_test.c"
static int rs_bad;
typedef struct { uint16_t idx[NTRK]; uint32_t pos[NTRK]; } snap_t;
static void setup(void)
{
static const uint8_t LEN[NTRK] = {16, 16, 32, 12, 16, 8}, DIV[NTRK] = {2, 2, 3, 2, 1, 5};
ui_power_on();
song.g[G_BPM] = 133; song.g[G_SWING] = 0; song.g[G_CLOCK] = 0;
for (uint32_t k = 0; k < NTRK; k++) {
track_t *q = &trk[k];
q->p[P_SLEN] = LEN[k]; q->p[P_SDIV] = DIV[k]; q->p[P_SSWING] = k == 4 ? 40 : 0; q->seq_fit = 0;
for (uint32_t i = 0; i < NSTEP; i++) step_clear(&q->step[i]);
}
transport_req = 1;
events_block(CTL);
}
static void run(uint32_t samples) { for (uint32_t el = 0; el < samples; el += CTL) events_block(CTL); }
static void snap(snap_t *s) { for (uint32_t k = 0; k < NTRK; k++) { s->idx[k] = trk[k].seq_idx; s->pos[k] = trk[k].seq_pos; } }
typedef void (*act_t)(int on);
static int16_t keep[4];
static void a_len12(int on) { if (on) keep[0] = trk[1].p[P_SLEN], trk[1].p[P_SLEN] = 12; else trk[1].p[P_SLEN] = keep[0]; }
static void a_len5(int on) { if (on) keep[0] = trk[1].p[P_SLEN], trk[1].p[P_SLEN] = 5; else trk[1].p[P_SLEN] = keep[0]; }
static void a_len32(int on) { if (on) keep[0] = trk[1].p[P_SLEN], trk[1].p[P_SLEN] = 32; else trk[1].p[P_SLEN] = keep[0]; }
static void a_div8(int on) { if (on) keep[1] = trk[1].p[P_SDIV], trk[1].p[P_SDIV] = 1; else trk[1].p[P_SDIV] = keep[1]; }
static void a_div32(int on) { if (on) keep[1] = trk[1].p[P_SDIV], trk[1].p[P_SDIV] = 3; else trk[1].p[P_SDIV] = keep[1]; }
static void a_divT(int on) { if (on) keep[1] = trk[1].p[P_SDIV], trk[1].p[P_SDIV] = 5; else trk[1].p[P_SDIV] = keep[1]; }
static void a_knob(int on) { fit_ui_edit(&trk[1], &trk[1].p[P_SDIV], on ? 1 : 2); } /* (the DIV knob's own path) */
static void a_knobl(int on) { fit_ui_edit(&trk[1], &trk[1].p[P_SLEN], on ? 7 : 16); }
static void a_both(int on) { a_len12(on); a_div8(on); }
static void a_fit(int on) { fit_ui_set(&trk[1], on ? 128u | 12u : 16u); }
static void a_bpm(int on) { song.g[G_BPM] = on ? 97 : 133; }
static void a_swing(int on) { trk[1].p[P_SSWING] = on ? 70 : 0; }
static void a_gsw(int on) { song.g[G_SWING] = on ? 55 : 0; }
static void a_mute(int on) { trk[1].p[P_MUTE] = on ? 1 : 0; }
int main(void)
{
static const struct { const char *name; act_t f; } A[] = {
{"LEN 16 > 12 > 16", a_len12}, {"LEN 16 > 5 > 16", a_len5}, {"LEN 16 > 32 > 16", a_len32},
{"DIV 1/16 > 1/8 > 1/16", a_div8}, {"DIV 1/16 > 1/32 > 1/16", a_div32}, {"DIV 1/16 > 1/16T > 1/16", a_divT},
{"DIV knob (rescaled) and back", a_knob}, {"LEN knob 16 > 7 > 16", a_knobl}, {"LEN and DIV together", a_both},
{"FIT 12 on and off", a_fit}, {"tempo 133 > 97 > 133", a_bpm}, {"track SWING 70 and back", a_swing},
{"global SWING 55 and back", a_gsw}, {"mute and unmute", a_mute}};
static const uint32_t at[] = {7, 3001, 5000, 9973, 23456, 40001}, hold[] = {4973u * 3u + 100u, 4973u * 7u + 2500u, 4973u * 29u + 11u};
printf("%-32s %s\n", "action on track 2, undone", "tracks off the others afterwards (of 18 moments)");
for (uint32_t a = 0; a < NELEM(A); a++) {
uint32_t off = 0, worst = 0;
for (uint32_t i = 0; i < NELEM(at); i++)
for (uint32_t h = 0; h < NELEM(hold); h++) {
snap_t ref, got;
uint32_t tail = 240000u, d = 0;
setup(); run(40000u + at[i]); run(hold[h]); run(tail); snap(&ref);
setup(); run(40000u + at[i]); A[a].f(1); run(hold[h]); A[a].f(0); run(tail); snap(&got);
if (A[a].f == a_bpm) { /* (a tempo change moves every track together: against track 1) */
for (uint32_t k = 0; k < NTRK; k++) if (trk[k].p[P_SLEN] == 16 && trk[k].p[P_SDIV] == 2) d |= got.idx[k] != got.idx[0] || got.pos[k] != got.pos[0];
} else
for (uint32_t k = 0; k < NTRK; k++) d |= ref.idx[k] != got.idx[k] || ref.pos[k] != got.pos[k];
off += d;
if (d) { uint32_t e = (got.idx[1] + 16u - ref.idx[1]) % 16u; worst = e > worst ? e : worst; }
}
printf("%-32s %2u %s\n", A[a].name, off, off ? "DESYNC" : "in phase");
rs_bad += off != 0;
}
{ /* EUCLID on track 2 while it plays (the real knobs: eu_put writes the pattern and its LEN), MUTATE: its place
* the transport's after each (a 1/16 track: step = the 1/16s since PLAY mod LEN, the samples the click's) */
static const struct { const char *name; uint8_t k; int16_t v; } E[] = {
{"EUCLID STEPS 12", EK_STEPS, 12}, {"EUCLID ROTATE 5", EK_ROT, 5}, {"EUCLID HITS 7", EK_HITS, 7},
{"EUCLID STEPS 7", EK_STEPS, 7}, {"EUCLID STEPS 16", EK_STEPS, 16}, {"EUCLID ROLE 2", EK_K4, 2},
{"EUCLID STEPS 24", EK_STEPS, 24}, {"EUCLID STEPS 16 again", EK_STEPS, 16}, {"MUTATE", 255, 0}};
uint32_t ok;
setup(); song.sel = 1; run(40000u);
for (uint32_t i = 0; i < NELEM(E); i++) {
uint32_t len;
fm1_ms += 3000u;
if (E[i].k == 255) { eu_mutate(1, eu_of(1)); eu_gen(1, 0); } else eu_put(E[i].k, E[i].v);
run(4973u * 11u + 777u * i);
len = (uint32_t)trk[1].p[P_SLEN];
ok = trk[1].p[P_SDIV] == 2 && trk[1].seq_idx == clk_n % len && trk[1].seq_pos == clk_pos &&
trk[0].seq_idx == clk_n % 16u && trk[0].seq_pos == clk_pos;
printf("%-32s LEN %2u %s\n", E[i].name, len, ok ? "in phase" : "DESYNC");
rs_bad += !ok;
}
}
{ /* RESYNC: asked mid-bar; at the next bar the 12-step and the 1/32 tracks at their step 0 with the 16-step ones */
uint32_t s16, bar;
setup(); s16 = div_samples(2); bar = 16u * s16;
run(bar * 4u + 3000u); /* (bar 5: the 12-step track 80 steps in, its step 8 at the bar) */
seq_rs = (clk_n / 16u + 1u) * 16u;
while (clk_n < seq_rs || clk_pos < 2u * CTL) events_block(CTL);
rs_bad += check("RESYNC: at the next bar every track on its first step, in time",
trk[3].seq_idx == 0 && trk[0].seq_idx == 0 && trk[2].seq_idx == 0 && trk[3].seq_pos == trk[0].seq_pos && trk[5].seq_idx == 0);
run(bar * 6u);
rs_bad += check("RESYNC: its request gone after it", !seq_rs);
}
printf(rs_bad ? "resync: FAIL\n" : "resync: ok\n");
return rs_bad ? 1 : 0;
}