mirror of
https://github.com/juanjiant-bit/JIANT.git
synced 2026-12-05 12:24:42 +01:00
(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
77 lines
4.1 KiB
C
77 lines
4.1 KiB
C
/* SPDX-License-Identifier: GPL-3.0-only */
|
|
/* Copyright (C) 2026 Juan Ignacio Antonucci (Juan Jiant) */
|
|
/* (V10.8.40, a user: "the sequencer creeps ahead of the project's tempo") the sequencer against the ideal grid: ten
|
|
* minutes of blocks through seq_time and events_block (mix_block's two) at each tempo, every track on its own DIV / SWING / FIT, the metronome's
|
|
* 1/16 clock too; where a step starts (the samples rendered less seq_pos) against k x FS x 60 / (BPM x its division).
|
|
* (FIT's place is reckoned from its steps' own lengths: a sample or two of the reckoning's.)
|
|
* Passes with at most DRIFT_MAX samples off at the end of the ten minutes, on every track, and no track off another */
|
|
#define UI_TEST_NO_MAIN 1
|
|
#include "ui_test.c"
|
|
|
|
#define DRIFT_MAX 3
|
|
static int dr_bad;
|
|
/* a track's division of the beat as a ratio (N_DIV order: 1/4 1/8 1/16 1/32 1/8T 1/16T) */
|
|
static const uint8_t DEN[6] = {1, 2, 4, 8, 3, 6};
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
static const uint32_t tempos[] = {60, 90, 120, 121, 133, 140, 174, 239};
|
|
static const struct { uint8_t div, swing, fit, len; const char *name; } T[NTRK] = {
|
|
{2, 0, 0, 16, "1/16"}, {1, 0, 0, 16, "1/8"}, {3, 0, 0, 32, "1/32"}, {5, 0, 0, 12, "1/16T"},
|
|
{2, 60, 0, 16, "1/16 sw60"}, {2, 0, 128u | 16u, 18, "FIT 18:16"}};
|
|
uint32_t minutes = argc > 1 ? (uint32_t)atoi(argv[1]) : 10u, worst = 0;
|
|
printf("drift after %u min, samples (ms a minute); + is early\n%-5s", minutes, "BPM");
|
|
for (uint32_t k = 0; k < NTRK; k++) printf(" %-18s", T[k].name);
|
|
printf(" %-18s\n", "click 1/16");
|
|
for (uint32_t b = 0; b < NELEM(tempos); b++) {
|
|
uint64_t steps[NTRK] = {0}, total = (uint64_t)FS * 60u * minutes, el = 0;
|
|
uint32_t last[NTRK], bpm = tempos[b];
|
|
ui_power_on();
|
|
song.g[G_BPM] = (int16_t)bpm; 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] = T[k].len; q->p[P_SDIV] = T[k].div; q->p[P_SSWING] = T[k].swing; q->seq_fit = T[k].fit;
|
|
for (uint32_t i = 0; i < NSTEP; i++) step_clear(&q->step[i]);
|
|
}
|
|
transport_req = 1;
|
|
events_block(CTL);
|
|
for (uint32_t k = 0; k < NTRK; k++) last[k] = trk[k].seq_idx;
|
|
while (el < total) {
|
|
events_block(seq_time(CTL)); /* (as fx.c mix_block) */
|
|
el += CTL;
|
|
for (uint32_t k = 0; k < NTRK; k++) {
|
|
uint32_t len = T[k].len, d = (trk[k].seq_idx + len - last[k]) % len;
|
|
steps[k] += d; last[k] = trk[k].seq_idx;
|
|
}
|
|
}
|
|
printf("%-5u", bpm);
|
|
for (uint32_t k = 0; k <= NTRK; k++) {
|
|
/* where the playhead is, in samples of the ideal grid: whole steps (pairs with swing, loops with FIT) */
|
|
uint32_t den = k < NTRK ? DEN[T[k].div] : 4u;
|
|
double step = (double)FS * 60.0 / ((double)bpm * den), at, d;
|
|
if (k == NTRK) at = (double)clk_n * step + clk_pos;
|
|
else {
|
|
uint64_t s = steps[k]; uint32_t in = trk[k].seq_pos, i;
|
|
if (T[k].fit) {
|
|
double loop = step * 16.0; /* SPAN 16 units a loop of LEN steps */
|
|
uint32_t per = div_samples(T[k].div);
|
|
at = (double)(s / T[k].len) * loop;
|
|
for (i = 0; i < s % T[k].len; i++) at += (double)step_samples(&trk[k], per, i) * loop / (16.0 * per);
|
|
at += in;
|
|
} else {
|
|
uint32_t per = div_samples(T[k].div);
|
|
at = (double)(s / 2u) * 2.0 * step;
|
|
if (s & 1u) at += (double)step_samples(&trk[k], per, 0) * step / per;
|
|
at += in;
|
|
}
|
|
}
|
|
d = at - (double)el; /* + : further on than the samples played: early */
|
|
printf(" %+8.1f (%+6.2f) ", d, d * 1000.0 / FS / minutes);
|
|
if (fabs(d) > worst) worst = (uint32_t)fabs(d);
|
|
}
|
|
printf("\n");
|
|
}
|
|
dr_bad += check("the sequencer on the tempo's grid for ten minutes: every DIV, SWING, FIT and the click", worst <= DRIFT_MAX);
|
|
return dr_bad ? 1 : 0;
|
|
}
|