mirror of
https://github.com/juanjiant-bit/JIANT.git
synced 2026-12-06 04:44:33 +01:00
core.h CTL 32 -> 64 (tools/gen_tables.py; the half buffer 128 frames: two mix_block passes a half, not four), so the fixed cost of a block (events_block, mc_split, the core-1 handshake, buffers cleared and summed, sends, buses, master) is paid half as often. Everything that counted blocks of 32 counts in CTL: envelope / LFO tables, glides, fades, the steal fade, the leveler's (its peak still read over 32) and DUCK's followers, DRUM-X FLAM / PUNCH / pan slew / group fade, the FX gate, DJF crossfade, SPRING / RESO glides, WORDS' phoneme timing, the FX layer's LPF / HPF sweep (perform.c PF_CSTEP), the mod matrix's NOISE and STEP eases. The sequencer did not get coarser: a note inside the block carries its sample (core.h ev_off; voice.c voice_begin / voice_off_at / track_render render the sounding voice up to it and the new one from it; every engine but FM6, which renders whole blocks and keeps the nearer edge). tests/ctl64_timing_test.c: on a MICRO-shifted pattern every rendered onset is within 2 samples of the sample-at-a-time sequencer (ANALOG POLY worst 2, ANALOG MONO cuts worst 2, DRUM kit hits worst 1); the 32-sample build placed them -22 .. +5 samples off. Host CPU (tests/cpu_vg.py, exact instructions / sample, 32 -> 64): mix/idle 516 -> 426 (-17.5 %), seq/mono4 1514 -> 1188 (-21.5 %), eng/DRUM 1477 -> 1156 (-21.7 %), eng/FM6 1710 -> 1507 (-11.9 %), eng/VOICE 1500 -> 1337 (-10.9 %), VOICE.EN 1783 -> 1619 (-9.2 %), ANALOG / PHASE / LOFI / NOISE / WHEEL -6 .. -9 %, reverbs and delays -7 .. -8 %, mix/full 2671 -> 2505 (-6.2 %), seq/plain 2381 -> 2158 (-9.4 %), seq/heavy 2783 -> 2485 (-10.7 %), song/cputest 3016 -> 2742 (-9.1 %), peak/VOICE.EN6 3304 -> 2937 (-11.1 %). Firmware: image 567896 B, .data+.bss 88276 of 98304 (+9 KB: the CTL-long buffers), RAM code 21848 of 24576; the render loops' target cost as before (tests/target_budget.txt). docs/CPU3_PERFORMANCE.md, README (the dual-core section), CPU5_PERFORMANCE.md. Goldens: tests/golden.txt, cpu_baseline_vg.txt, target_budget.txt regenerated (GOLDEN_UPDATE / BUDGET_UPDATE: the sound changes through the buses' one-block lag, now 1.45 ms, and the leveler's reading); djf_test / micro_test reference hashes of the 0.9.0 renders redone at CTL 64. Host tests that counted blocks count in CTL (reverb DUCK 3 / 20 ms, voice glide 163 blocks of 32 and 1/8 st a block, click_test, drumx_oct_test); drumx_test's HANDS and PUNCH checks reset the kit's noise generator before each compared strike (they compared different noise realizations: up to x5 strike to strike on the 32-sample build too, measured). Full host suite: every section passes but gen_nav_map's stale docs/navigation-map.svg, which the base reports as well. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KMHk6yH4XbP1xxHYKCo9Mh
134 lines
6.2 KiB
C
134 lines
6.2 KiB
C
/* SPDX-License-Identifier: GPL-3.0-only
|
|
* Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */
|
|
/* (0.9.9 ctl64) where the sequencer's notes land in the rendered audio, against where the sequencer puts them when it
|
|
* runs a sample at a time (seq_tick(t, 1): micro_test's reference): a MICRO-shifted pattern (steps off the grid by
|
|
* 64ths, as a live recording leaves them) on an ANALOG track with an instant attack, rendered through mix_block in
|
|
* blocks of CTL samples. Each note's onset (the master's first sample above the floor after a rest) minus the
|
|
* sequencer's sample for it. With blocks of 32 (before) a note started at its block's first sample: 0 .. 31 samples
|
|
* early or late; now (any CTL) at its own sample: within 2 (the ramp's first sample rounds to 0; the sequencer's
|
|
* sample-at-a-time run is itself a sample behind). Also: the same with the
|
|
* track MONO (each note cuts the one before: the voice restarted in place at the sample), and a DRUM kit's hits.
|
|
* build/host/ctl64_timing_test [OUT.wav] (OUT.wav: the POLY render, for listening / plotting) */
|
|
#define UI_TEST_NO_MAIN 1
|
|
#include "ui_test.c"
|
|
|
|
static int bad;
|
|
static void ck(const char *what, int ok)
|
|
{
|
|
printf("ctl64: %-100s %s\n", what, ok ? "ok" : "FAIL");
|
|
bad += !ok;
|
|
}
|
|
#define NN 6u
|
|
static const int8_t MIC[NN] = {0, 13, -9, 27, -30, 5}; /* each step's MICRO (64ths) */
|
|
|
|
static void pattern(uint32_t engine, uint32_t mode)
|
|
{
|
|
track_t *t = &trk[0];
|
|
uint32_t i;
|
|
ui_power_on();
|
|
song.master_q12 = 4096;
|
|
for (i = 1; i < NTRK; i++) trk[i].p[P_MUTE] = 1;
|
|
set_engine_of(t, engine);
|
|
t->engine = t->eng_req;
|
|
apply_preset_to(t, 0);
|
|
t->p[P_MUTE] = 0; t->p[P_SLEN] = 2 * NN; t->p[P_SDIV] = 2; t->p[P_SSWING] = 0; song.g[G_SWING] = 0;
|
|
t->p[P_VOICE] = (int16_t)mode; t->p[P_SGATE] = 40; t->p[P_ATK] = 0; t->p[P_REL] = 10;
|
|
t->p[P_CHOR] = t->p[P_DLY] = t->p[P_REV] = 0; t->p[P_DIST] = 0;
|
|
for (i = 0; i < NSTEP; i++) step_clear(&t->step[i]);
|
|
for (i = 0; i < NN; i++) { /* a note, then a rest (the onset after silence) */
|
|
step_t *s = &t->step[2 * i];
|
|
s->time = ST_NOTE; s->vel = 100;
|
|
if (engine == ENGI_DRUM) s->hit = (uint8_t)(1u << DV_HATC); /* (the closed hat: its tail is short) */
|
|
else { s->n = 1; s->note[0] = (uint8_t)(48 + 3 * i); }
|
|
ST_MICRO_SET(s, MIC[i]);
|
|
}
|
|
song.g[G_BPM] = 128;
|
|
for (i = 0; i < 200u; i++) { int32_t o[2 * CTL]; mix_block(o, CTL); } /* (the sound load settled) */
|
|
}
|
|
/* the sequencer alone, a sample at a time: the sample each of the NN notes starts on */
|
|
static void reference(uint32_t engine, uint32_t mode, int32_t *at)
|
|
{
|
|
track_t *t = &trk[0];
|
|
uint32_t now, k, v0, n = 0;
|
|
pattern(engine, mode);
|
|
seq_start();
|
|
for (k = 0; k < NN; k++) at[k] = -1;
|
|
for (now = 0; now < 2u * NN * 5168u + 2000u && n < NN; now++) { /* (a step at 128 BPM 1/16: 5168 samples) */
|
|
v0 = vage;
|
|
seq_tick(t, 1);
|
|
if (vage != v0) at[n++] = (int32_t)now;
|
|
}
|
|
seq_stop();
|
|
}
|
|
/* rendered in blocks: each note's onset in the track's own render (events_block, then track_render as mix_part does:
|
|
* the dry part, exactly 0 while nothing sounds; the master's leveler and DC blocker would never settle to 0) */
|
|
static void rendered(uint32_t engine, uint32_t mode, int32_t *on, const char *wav)
|
|
{
|
|
track_t *t = &trk[0];
|
|
static int32_t o[CTL];
|
|
uint32_t b, i, n = 0, zeros = 1000;
|
|
FILE *f = wav ? fopen(wav, "wb") : 0;
|
|
uint32_t frames = 2u * NN * 5168u + 4000u;
|
|
pattern(engine, mode);
|
|
transport_req = 1; ui_input();
|
|
for (i = 0; i < NN; i++) on[i] = -1;
|
|
if (f) wav_hdr(f, (frames / CTL) * CTL);
|
|
for (b = 0; b < frames / CTL; b++) {
|
|
events_block(CTL);
|
|
track_render(t, o, CTL);
|
|
for (i = 0; i < CTL; i++) {
|
|
int32_t x = o[i], a = x < 0 ? -x : x;
|
|
if (f) wav_put(f, x >> 2, x >> 2);
|
|
if (a >= 4) { /* (a kit's tail leaves a few LSBs) */
|
|
if (zeros >= 200u && n < NN) on[n++] = (int32_t)(b * CTL + i); /* (the first sample after a silence) */
|
|
zeros = 0;
|
|
} else
|
|
zeros++;
|
|
}
|
|
}
|
|
if (f) fclose(f);
|
|
transport_req = 2; ui_input();
|
|
}
|
|
static int32_t worst(const int32_t *ref, const int32_t *on, int32_t *mn, int32_t *mx)
|
|
{
|
|
uint32_t k;
|
|
int32_t w = 0;
|
|
*mn = 1 << 30; *mx = -(1 << 30);
|
|
for (k = 0; k < NN; k++) {
|
|
int32_t d = on[k] - ref[k], a = d < 0 ? -d : d;
|
|
if (ref[k] < 0 || on[k] < 0) return 1 << 20;
|
|
if (a > w) w = a;
|
|
if (d < *mn) *mn = d;
|
|
if (d > *mx) *mx = d;
|
|
}
|
|
return w;
|
|
}
|
|
int main(int argc, char **argv)
|
|
{
|
|
static const struct { uint32_t engine, mode; const char *name; int32_t tol; } C[3] = {
|
|
{ENGI_ANALOG, V_POLY, "ANALOG POLY", 2}, {ENGI_ANALOG, V_MONO, "ANALOG MONO (each note cuts the last)", 2},
|
|
{ENGI_DRUM, V_POLY, "DRUM kit hits", 2}};
|
|
int32_t ref[NN], on[NN], mn, mx, w;
|
|
uint32_t c, k;
|
|
char what[200];
|
|
for (c = 0; c < 3u; c++) {
|
|
reference(C[c].engine, C[c].mode, ref);
|
|
rendered(C[c].engine, C[c].mode, on, c == 0u && argc > 1 ? argv[1] : 0);
|
|
for (k = 0; k < NN; k++) /* the grid of a run in blocks: the transport's position is 0 at
|
|
* the end of the block PLAY lands in (seq_start), so it sits
|
|
* CTL - 1 samples after the sample-at-a-time run's */
|
|
if (ref[k] >= 0 && k) ref[k] += (int32_t)CTL - 1; /* (not the first: PLAY's step starts the block) */
|
|
w = worst(ref, on, &mn, &mx);
|
|
printf("ctl64: %s: sequencer at", C[c].name);
|
|
for (k = 0; k < NN; k++) printf(" %d", ref[k]);
|
|
printf("; rendered at");
|
|
for (k = 0; k < NN; k++) printf(" %d", on[k]);
|
|
printf(" (onset - sequencer: %d .. %d samples)\n", mn, mx);
|
|
snprintf(what, sizeof what, "%s: every note's onset within %d sample(s) of the sequencer's (worst %d; blocks of %u)",
|
|
C[c].name, C[c].tol, w, (unsigned)CTL);
|
|
ck(what, w <= C[c].tol);
|
|
}
|
|
printf(bad ? "ctl64 timing: %d FAILED\n" : "ctl64 timing: all passed\n", bad);
|
|
return bad != 0;
|
|
}
|