Files
JIANT/tests/rep_sync_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

121 lines
5.6 KiB
C

// Copyright (C) 2026 Juan Ignacio Antonucci (Juan Jiant). All rights reserved.
/* (V10.7.59) the repeats on the tempo: RATCH x2 .. x8 (a step component), STUTTER (a step component), the punch-in
* STUT 1/8 / 1/16 and ARP: each note-on of track 1 against its ideal sample on the transport's grid (a block's
* resolution: CTL), straight and swung, at a few tempos. A stumble: a note more than a block off its place, or one
* missing / extra. Built and run: cc ... tests/rep_sync_test.c */
#define UI_TEST_NO_MAIN 1
#include "ui_test.c"
static uint32_t rs_clock;
static void rs_setup(uint32_t bpm, uint32_t swing, uint32_t every)
{
uint32_t i, k;
ui_power_on();
for (i = 0; i < NTRK; i++) {
track_t *t = &trk[i];
track_defaults_steps(t);
t->p[P_SLEN] = 16;
t->p[P_SDIV] = 2;
t->p[P_SSWING] = 0;
t->p[P_SGATE] = 12;
for (k = 0; k < 16u && !i; k++)
if (!(k % every))
t->step[k] = (step_t){{(uint8_t)(48 + k)}, 1, ST_NOTE, 0, 100};
}
song.g[G_BPM] = (int16_t)bpm;
song.g[G_SWING] = (int16_t)swing;
memset(fg_set, 0, sizeof fg_set);
transport_req = 1; /* (mix_block starts the transport: seq_start) */
rs_clock = 0;
}
static uint32_t rs_run(uint32_t samples, uint32_t *at, uint32_t max)
{
uint32_t n = 0, end = rs_clock + samples;
while (rs_clock < end) {
uint32_t v0 = vage;
static int32_t o[2 * CTL];
/* (V10.8.40) the clock in the sequencer's samples: a block less the sample mix_block leaves out (fx.c seq_time) */
uint32_t adv = tempo_acc + CTL * ((uint32_t)FS * 60u - beat_samples() * (uint32_t)song.g[G_BPM]) >= (uint32_t)FS * 60u ? CTL - 1u : CTL;
mix_block(o, CTL); /* (the whole block: the punch-ins, the events, the parts) */
for (; v0 < vage; v0++) {
if (n < max) at[n] = rs_clock;
n++;
}
rs_clock += adv;
}
return n;
}
static void comp_put(step_t *s, uint32_t a, uint32_t len, uint32_t v)
{
s->comp = CO_MAKE(a, CC_ALWAYS); s->carg = (uint8_t)v; s->clen[0] = (uint8_t)(len - 1u); s->cnm[0] = 0;
}
/* the onsets against the grid: want[] the ideal samples; returns the worst error in samples, *miss the count off */
static uint32_t rs_cmp(const uint32_t *at, uint32_t n, const uint32_t *want, uint32_t m, int32_t *miss)
{
uint32_t i, worst = 0;
*miss = (int32_t)n - (int32_t)m;
for (i = 0; i < n && i < m; i++) {
uint32_t d = at[i] > want[i] ? at[i] - want[i] : want[i] - at[i];
worst = d > worst ? d : worst;
}
return worst;
}
int main(void)
{
static const uint32_t BPM[3] = {93, 120, 137};
static uint32_t at[512], want[512];
int bad = 0;
uint32_t b, h, sw, m, i, k, n, worst;
int32_t miss;
char what[200];
for (b = 0; b < 3u; b++)
for (sw = 0; sw < 2u; sw++)
for (h = 2; h <= 8u; h++) { /* RATCH xh on every 4th step (a note each beat), 2 bars */
uint32_t P;
rs_setup(BPM[b], sw ? 60u : 0u, 4u);
for (k = 0; k < 16u; k += 4u)
comp_put(&trk[0].step[k], CA_RATCH, 1u, h - 2u);
P = div_samples(2);
n = rs_run(32u * P, at, 512);
for (m = 0, i = 0; i < 8u; i++) /* the beats (swing moves the odd 1/16s: a beat's start stays) */
for (k = 0; k < h; k++)
want[m++] = i * 4u * P + k * step_samples(&trk[0], P, 0) / h;
worst = rs_cmp(at, n, want, m, &miss);
snprintf(what, sizeof what, "RATCH x%u at %u BPM%s: %u notes for %u, worst %u samples off (a block %u)", h,
BPM[b], sw ? " swung" : "", n, m, worst, (unsigned)CTL);
bad += check(what, !miss && worst <= CTL);
}
for (b = 0; b < 3u; b++) { /* STUTTER over 4 steps from step 0: a note each step, on the grid */
uint32_t P;
rs_setup(BPM[b], 0, 16u);
comp_put(&trk[0].step[0], CA_STUT, 4u, 0);
P = div_samples(2);
n = rs_run(16u * P, at, 512);
for (m = 0; m < 4u; m++) want[m] = m * P;
worst = rs_cmp(at, n < 4u ? n : 4u, want, 4u, &miss);
snprintf(what, sizeof what, "STUTTER x4 at %u BPM: the first four notes on the steps (worst %u samples), %u in all",
BPM[b], worst, n);
bad += check(what, n >= 4u && worst <= CTL);
}
for (b = 0; b < 3u; b++) /* the punch-in STUT 1/16 and 1/8 held a bar on a note a beat */
for (k = 0; k < 2u; k++) {
uint32_t P, per;
rs_setup(BPM[b], 0, 4u);
P = div_samples(2);
n = rs_run(4u * P, at, 512); /* (a beat played: its note the one repeated) */
perf_held = PF_BIT(k ? PF_S8 : PF_S16);
n = rs_run(16u * P, at, 512);
perf_held = 0;
per = k ? 2u * P : P;
for (m = 0; m * per <= 16u * P; m++) want[m] = 4u * P + m * per; /* (the press's note, then each repeat on
* the grid: a 1/8 on the beat, V10.7.59) */
worst = rs_cmp(at, n, want, m, &miss);
if (getenv("RS_V")) { for (i = 0; i < n && i < 20u; i++) printf(" %d", (int)at[i] - (int)(4u * P)); printf(" (P %u)\n", P); }
snprintf(what, sizeof what, "punch-in STUT %s at %u BPM: %u notes for %u, worst %u samples off", k ? "1/8" : "1/16",
BPM[b], n, m, worst);
bad += check(what, !miss && worst <= CTL);
}
printf(bad ? "rep-sync: %d FAILED\n" : "rep-sync: all on the grid\n", bad);
return bad != 0;
}