Files
skiff/tests/drift_test.c
T
illuminus5 881307d3cd Skiff 2.5: 16 voices a track, a true-stereo delay and chorus, takes played while stopped, a song you can follow
- Voices: up to 16 a track and 16 shared on two cores (8 on one); every FM-1 moves to 2 CORES once. GRAIN and PHYS
  keep 3, VOICE 4, FM6 6; UNISON, the drums and SLICE 8. A new note takes the quietest fading voice first.
- The delay's MODE (PRESETS on GLO > DELAY): MONO as before, bit for bit; STEREO, two lines at half the rate; PING.
  Each track's PAN reaches the delay; with STEREO or PING the chorus's CHORUS and FLANGER are stereo too. Older
  projects load MONO, a new one starts STEREO.
- FREE TAKE: play with the transport stopped, then SHIFT + SAVE: the tempo, the bars and the first beat guessed, on
  a screen of their own (PLAY listens, OCT+ keeps, OCT- puts the track back).
- FX > DELAY and FX > REVERB: the track's send beside the bus's own settings. A card for PRESETS where it does
  something special (DELAY's MODE, PATTERN's DIR, INSERT's MIX); INSERT is one page.
- A song you can follow: BAR n OF N on SONG, a line along the header to where the song is, each entry's bars. On
  SONG, SHIFT + PLAY plays from the entry, SHIFT + EDIT empties it (SAVE held brings it back).
- SAVE > PROJECT's KNOB 3: LOAD, NEW on any slot, CLEAR SONG, CLEAR TRACKS.
- FILTR on FX > INSERT (LP through BP to HP by SHAPE); STRUM on SCL > CHORD (1 to 100 ms, DOWN, UP, ALT); MENU >
  CONTROL > KEEP SENDS; REMOTE's knobs (CC 116-119, 85-87, relative; #90); LARGE keeps HOME's names (#97); HOME's
  scope in each theme's look; NOTES' delete hint; the SMK-37's knob names in the hints.
- Undo keeps 6 levels (was 8): the room went to the free take's log.
- Fixed:
  - Tracks of different DIVs drifted apart (#107): one grid for every DIV, the click, the launch points, CLOCK OUT.
  - Noise in fading notes (#110), improved: the low bits kept down to the output, USB dithered; SPEAKER EQ's
    LOWCUT and BASS+ no longer make them grainy.
  - An external clock's BPM jumped (#111): the mean of the last 8 beats (after SLOOP 2.7.2).
  - INSERT's FLANG and CHOR clipped their line on loud chords (#101).
  - The installer page finds the SMK-37's update port on macOS (#83).
  - A TAKE could put a pass of the pattern before a switch into the new one.
  - fm1_install.py could hang after the unit restarted into its update mode.
2026-11-09 10:20:14 -06:00

115 lines
4.8 KiB
C

/* SPDX-License-Identifier: GPL-3.0-only
* Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */
/* (2.5, #107) Host test: the tracks' step clocks, the click and the launch points stay on one grid however long they
* play, through the same sources as the firmware (hostsim.c):
* build/host/drift_test
* 1. the quarter (core.h bpm_quarter): a multiple of 24 at every BPM (40..240), within 12 samples of FS * 60 / BPM, and
* every straight and triplet DIV (fx.c div_samples) a whole share of it.
* 2. T1 1/8 (8 steps), T2 1/16 (16), T3 8T (12), T4 1/32 (32), T5 16T (24): each loops a bar. Run 30 minutes at 120 BPM
* and 10 at 40 97 128 140 174 240: at every bar start all five wrap to step 0 in the same block, the same samples into
* it, and the click's bar and the launch points' bar start as many blocks from it as at the third bar. 2.2 (each
* DIV rounded on its own) fails: at 120 BPM its 1/16 track gained 2 samples a beat on the 1/8 one (#107: they met
* after ~30 minutes). */
#define main hostsim_main
#include "hostsim.c"
#undef main
#define NO_OFF 0x7FFFFFFF
static int check(const char *what, int ok)
{
printf("drift: %-100s %s\n", what, ok ? "ok" : "FAIL");
return ok ? 0 : 1;
}
static int test_quarter(void)
{
static const uint8_t DEN[6] = {1, 2, 4, 8, 3, 6}; /* N_DIV 1/4 .. 16T (fx.c DIV_DEN) */
uint32_t b, d, bad = 0, worst = 0;
song.g[G_CLOCK] = 0;
for (b = 40; b <= 240u; b++) {
uint32_t q = bpm_quarter(b), x = (uint32_t)FS * 60u, e = q * b > x ? q * b - x : x - q * b;
song.g[G_BPM] = (int16_t)b;
bad += q % 24u != 0 || beat_samples() != q;
e = (e + b - 1u) / b; /* |q - FS 60 / b|, samples (rounded up) */
worst = e > worst ? e : worst;
for (d = 0; d < 6u; d++)
bad += div_samples(d) * DEN[d] != q;
}
return check("the quarter: x24, within 12 samples of FS*60/BPM, every DIV 1/4..16T a whole share (BPM 40..240)",
!bad && worst <= 12u);
}
/* a counter's bar starting in block blk: the same blocks after the tracks' bar each time (the first is the reference) */
static void bar_offset(int32_t *off, uint32_t blk, uint32_t bar_blk, uint32_t *bad)
{
int32_t o = (int32_t)blk - (int32_t)bar_blk;
if (*off == NO_OFF)
*off = o;
else if (o != *off)
++*bad;
}
/* minutes at bpm; returns the bars, *bad the bars the clocks disagreed at */
static uint32_t run(uint32_t bpm, uint32_t minutes, uint32_t *bad)
{
static const uint8_t DIV[5] = {1, 2, 4, 3, 5}; /* 1/8 1/16 8T 1/32 16T (N_DIV) */
static const uint8_t LEN[5] = {8, 16, 12, 32, 24}; /* a bar each */
uint32_t k, blk, nblk = minutes * 60u * (uint32_t)FS / CTL, bars = 0, last[5], bar_blk = 0, clk_last = 0, ls_last = 0;
int32_t clk_off = NO_OFF, ls_off = NO_OFF;
host_tracks_init();
song.g[G_BPM] = (int16_t)bpm;
for (k = 0; k < 5u; k++) {
trk[k].p[P_SDIV] = DIV[k];
trk[k].p[P_SLEN] = LEN[k];
last[k] = 0xFFFFu;
}
*bad = 0;
transport_req = 1;
for (blk = 0; blk < nblk; blk++) {
uint32_t w = 0;
events_block(CTL);
for (k = 0; k < 5u; k++) {
w |= (uint32_t)(trk[k].seq_idx == 0 && last[k] != 0) << k;
last[k] = trk[k].seq_idx;
}
if (w) { /* a bar starts: for all five, the same samples into it */
bars++;
bar_blk = blk;
if (w != 31u)
++*bad;
else
for (k = 1; k < 5u; k++)
if (trk[k].seq_pos != trk[0].seq_pos) {
++*bad;
break;
}
}
if (bars >= 3u && clk_step == 0 && clk_last != 0) /* the click's bar */
bar_offset(&clk_off, blk, bar_blk, bad);
if (bars >= 3u && launch_steps != ls_last && !(launch_steps % 16u)) /* the launch points' bar */
bar_offset(&ls_off, blk, bar_blk, bad);
clk_last = clk_step;
ls_last = launch_steps;
}
transport_req = 2;
events_block(CTL);
return bars;
}
int main(void)
{
static const uint16_t BPM[7] = {120, 40, 97, 128, 140, 174, 240};
uint32_t i, fails = 0;
char what[160];
fails += test_quarter();
for (i = 0; i < 7u; i++) {
uint32_t bad, min = i ? 10u : 30u, bars = run(BPM[i], min, &bad);
snprintf(what, sizeof what, "%u BPM, %u min: 1/8 1/16 8T 1/32 16T, the click, the launch points: %u bars, %u off",
(unsigned)BPM[i], (unsigned)min, (unsigned)bars, (unsigned)bad);
fails += check(what, !bad && bars + 1u >= min * BPM[i] / 4u);
}
printf(fails ? "drift: %u FAILED\n" : "drift: all passed\n", (unsigned)fails);
return fails ? 1 : 0;
}