mirror of
https://github.com/juanjiant-bit/JIANT.git
synced 2026-12-05 20:34:27 +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
1070 lines
45 KiB
C
1070 lines
45 KiB
C
/* SPDX-License-Identifier: GPL-3.0-only
|
|
* Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments
|
|
* Portions Copyright (C) 2026 Juan Ignacio Antonucci (Juan Jiant) */
|
|
/* Host test of the FX hold layer's effects (firmware/src/perform.c), same sources as the firmware (through
|
|
* hostsim.c). build/host/perform_test [DEMO_DIR] (run_tests.sh: build/perform_demo)
|
|
* 1. timing: REPEAT starts on the next 1/16 of the transport (sample exact) and ends when let go (the live
|
|
* signal back, bit for bit, after the 2.9 ms ramp); the filters start at once.
|
|
* 2. stereo: REPEAT keeps left and right apart (a silent right channel stays silent; each side follows its
|
|
* own input).
|
|
* 3. a REPEAT too long for the loop (1/8 below 81 BPM) does nothing at all.
|
|
* 4. the SLICER: its recordings are not used meanwhile and are dropped afterwards.
|
|
* 5. the keys: a layer key plays nothing and sends no MIDI; a key held before FX stays a note; the white
|
|
* keys past the first 5 are the layer's too but do nothing.
|
|
* 6. idle: nothing held, nothing ramping, the mix is bit-identical (and the goldens of regress.c too).
|
|
* 7. no clicks, no overflow; the filters, the CRUSH and THROW macros and the mutes do what they say.
|
|
* 8. cost: instructions per sample of the song, idle and with every effect at once (proc_pid_rusage).
|
|
* 9. the punch-in MIDI effects (pfx.c): OCT+ doubles a held note's frequency and lets it back; A#4 DRM leaves a synth
|
|
* alone; DEC- shortens a kick's tail (DECY back after the block); STUTTER 1/16 strikes a kick 4 times a beat;
|
|
* 1/2 TEMPO slows the sequencer and, let go, puts it where it would have been; RANDOM moves some notes.
|
|
* Demos (WAV) into DEMO_DIR. TONIC removed REVERSE, TAPE STOP, FREEZE and OCT UP / DN (perform.c). */
|
|
#define main hostsim_main
|
|
#include "hostsim.c"
|
|
#undef main
|
|
#ifdef __APPLE__
|
|
#include <libproc.h>
|
|
#include <sys/resource.h>
|
|
#endif
|
|
|
|
static int check(const char *what, int ok)
|
|
{
|
|
printf("perform: %-73s %s\n", what, ok ? "ok" : "FAIL");
|
|
return ok ? 0 : 1;
|
|
}
|
|
|
|
/* ------------------------------------------------------ a test signal --- */
|
|
#define NT (6u * 44100u)
|
|
static int32_t in_l[NT], in_r[NT], out_l[NT], out_r[NT];
|
|
static void test_signal(double fl, double al, double fr, double ar)
|
|
{
|
|
uint32_t t;
|
|
for (t = 0; t < NT; t++) {
|
|
in_l[t] = (int32_t)lrint(al * sin(2 * M_PI * fl * t / FS));
|
|
in_r[t] = (int32_t)lrint(ar * sin(2 * M_PI * fr * t / FS + 1.0));
|
|
}
|
|
}
|
|
static void perf_reset(void)
|
|
{
|
|
memset(&pf, 0, sizeof pf);
|
|
pf.src = pf.next = PF_N;
|
|
pf.lc = PF_TOP;
|
|
for (uint32_t m = 0; m < NTRK; m++) pf.mg[m] = 32768;
|
|
perf_held = perf_act = 0;
|
|
perf_kill = 0;
|
|
memset((void *)perf_k, 0, sizeof perf_k);
|
|
perf_latched = 0;
|
|
pfx_tgt = 0;
|
|
pfx_any = 0;
|
|
sl_lent = 0;
|
|
slicer_reset();
|
|
}
|
|
/* the stage alone on the test signal: samples [t0, t1); ev: press (+e + 1) / let go (-(e + 1)) at block bt */
|
|
typedef struct { uint32_t t; int e; } ev_t;
|
|
static int busy_seen;
|
|
static int8_t run_crush; /* KNOB 2 (CRUSH) during run(), 0 = untouched */
|
|
static int8_t run_k4; /* KNOB 4 (DEPTH) during run() */
|
|
static void run(uint32_t bpm, int playing, const ev_t *ev, uint32_t nev, uint32_t t1)
|
|
{
|
|
uint32_t t, k = 0;
|
|
host_tracks_init();
|
|
perf_reset();
|
|
perf_k[1] = run_crush;
|
|
perf_k[3] = run_k4;
|
|
song.g[G_BPM] = (int16_t)bpm;
|
|
song.playing = (uint8_t)playing;
|
|
perf_start();
|
|
busy_seen = 0;
|
|
for (t = 0; t < t1; t += CTL) {
|
|
while (k < nev && ev[k].t <= t) {
|
|
perf_press((uint32_t)(ev[k].e > 0 ? ev[k].e - 1 : -ev[k].e - 1), ev[k].e > 0);
|
|
k++;
|
|
}
|
|
memcpy(out_l + t, in_l + t, CTL * 4);
|
|
memcpy(out_r + t, in_r + t, CTL * 4);
|
|
clk_pos = t % div_samples(2); /* (the transport's 1/16 at the block's start, as events_block leaves it) */
|
|
clk_n = t / div_samples(2);
|
|
if (perf_begin(CTL)) {
|
|
busy_seen = 1;
|
|
perf_block(out_l + t, out_r + t, CTL);
|
|
}
|
|
}
|
|
}
|
|
#define P16 5508u /* a 1/16 at 120 BPM (V10.8.40: a beat 22032, a multiple of 24 samples) */
|
|
static int same(uint32_t a, uint32_t b) /* out == in on [a, b), both sides */
|
|
{
|
|
uint32_t t;
|
|
for (t = a; t < b; t++)
|
|
if (out_l[t] != in_l[t] || out_r[t] != in_r[t])
|
|
return 0;
|
|
return 1;
|
|
}
|
|
static int32_t err_vs(uint32_t a, uint32_t b, int32_t (*src)(const int32_t *, uint32_t), int side)
|
|
{
|
|
uint32_t t;
|
|
int32_t e = 0;
|
|
for (t = a; t < b; t++) {
|
|
int32_t d = abs((side ? out_r : out_l)[t] - src(side ? in_r : in_l, t));
|
|
e = d > e ? d : e;
|
|
}
|
|
return e;
|
|
}
|
|
static uint32_t shift_d; /* the loop: in[t - shift_d] */
|
|
static int32_t delayed(const int32_t *x, uint32_t t) { return x[t - shift_d]; }
|
|
static int32_t peak(const int32_t *x, uint32_t a, uint32_t b)
|
|
{
|
|
int32_t m = 0;
|
|
for (; a < b; a++)
|
|
m = abs(x[a]) > m ? abs(x[a]) : m;
|
|
return m;
|
|
}
|
|
|
|
/* ------------------------------------------------------------ 1. timing --- */
|
|
static int test_timing(void)
|
|
{
|
|
int bad = 0;
|
|
char what[160];
|
|
test_signal(440, 12000, 277, 9000);
|
|
{ /* REPEAT 1/16: pressed mid-1/16, records the next 1/16, then loops it */
|
|
ev_t ev[] = {{992, PF_R16 + 1}, {20000, -(PF_R16 + 1)}};
|
|
int32_t el, er, el2;
|
|
run(120, 1, ev, 2, 40000);
|
|
shift_d = P16;
|
|
el = err_vs(2 * P16 + 160, 3 * P16 - 160, delayed, 0);
|
|
er = err_vs(2 * P16 + 160, 3 * P16 - 160, delayed, 1);
|
|
shift_d = 2 * P16;
|
|
el2 = err_vs(3 * P16 + 160, 20000 - 160, delayed, 0);
|
|
snprintf(what, sizeof what, "REPEAT 1/16: live until the 1/16 after the press + one 1/16 (exact)");
|
|
bad += check(what, same(0, 2 * P16));
|
|
snprintf(what, sizeof what, " then the 1/16 from that 1/16, looped (error L %d R %d, 2nd pass %d of 12000)", el, er, el2);
|
|
bad += check(what, el < 100 && er < 100 && el2 < 100);
|
|
bad += check(" let go: the live signal again after the ramp, bit for bit", same(20000 + 160, 40000));
|
|
bad += check(" the buffer given back, nothing left running", !sl_lent && pf.mode == BM_NONE && !pf.busy);
|
|
}
|
|
{ /* stopped: at once */
|
|
ev_t ev[] = {{992, PF_R16 + 1}};
|
|
run(120, 0, ev, 1, 12000);
|
|
bad += check("stopped: a 1/16 effect starts at once", (perf_act & PF_BIT(PF_R16)) && !same(992, 12000));
|
|
}
|
|
{ /* the immediate ones: FREEZE (V10.7.59, was LPF) at once, not on the 1/16 */
|
|
ev_t ev[] = {{992, PF_FRZ + 1}};
|
|
run(120, 1, ev, 1, 3000);
|
|
bad += check("FREEZE starts at once (not on the 1/16)", !(PF_Q & PF_BIT(PF_FRZ)) && (perf_act & PF_BIT(PF_FRZ)));
|
|
}
|
|
return bad;
|
|
}
|
|
|
|
/* ------------------------------------------------------------ 2. stereo --- */
|
|
static int test_stereo(void)
|
|
{
|
|
static const struct { const char *name; int e; } C[] = {{"REPEAT 1/8", PF_R8}};
|
|
uint32_t c;
|
|
int bad = 0;
|
|
char what[160];
|
|
for (c = 0; c < sizeof C / sizeof C[0]; c++) {
|
|
ev_t ev[] = {{992, C[c].e + 1}, {60000, -(C[c].e + 1)}};
|
|
int32_t pl, pr;
|
|
double cl = 0, cr = 0, nl = 0, nr = 0;
|
|
uint32_t t;
|
|
test_signal(440, 12000, 0, 0); /* the right side silent */
|
|
run(120, 1, ev, 2, 70000);
|
|
pl = peak(out_l, 30000, 60000);
|
|
pr = peak(out_r, 0, 70000);
|
|
snprintf(what, sizeof what, "%s: a silent right side stays silent (L %d, R %d)", C[c].name, pl, pr);
|
|
bad += check(what, pr == 0 && pl > 3000);
|
|
test_signal(440, 12000, 3 * 440, 12000); /* each side its own pitch */
|
|
run(120, 1, ev, 2, 70000);
|
|
for (t = 30000u; t < 50000u; t++) {
|
|
cl += (double)out_l[t] * out_l[t - 1];
|
|
nl += (double)out_l[t] * out_l[t];
|
|
cr += (double)out_r[t] * out_r[t - 1];
|
|
nr += (double)out_r[t] * out_r[t];
|
|
}
|
|
cl = nl > 0 ? cl / nl : 1;
|
|
cr = nr > 0 ? cr / nr : 1;
|
|
snprintf(what, sizeof what, " each side keeps its own pitch (lag-1 correlation L %.3f, R %.3f)", cl, cr);
|
|
bad += check(what, cl > 0.99 && cr < 0.99 && cr > 0.9 && cl - cr > 0.008);
|
|
}
|
|
return bad;
|
|
}
|
|
|
|
/* -------------------------------------------------------- 3. too long --- */
|
|
static int test_too_long(void)
|
|
{
|
|
int bad = 0;
|
|
ev_t ev[] = {{992, PF_R8 + 1}, {40000, -(PF_R8 + 1)}};
|
|
test_signal(440, 12000, 277, 9000);
|
|
run(72, 1, ev, 2, 50000);
|
|
bad += check("REPEAT 1/8 at 72 BPM (417 ms, the loop holds 371 at 22 kHz): V10.59 plays it at 11 kHz (lo-fi)",
|
|
!same(0, 40000) && (perf_avail() & PF_BIT(PF_R8)));
|
|
{ /* (V10.59) the 11 kHz loop repeats: a 1/8 later the same (a 440 Hz / 277 Hz pair: within the lo-fi's error) */
|
|
char what[160];
|
|
uint32_t L = div_samples(1), t, a0 = 30000u; /* (V10.8.40: the sequencer's 1/8, a beat a multiple of 24 samples) */ /* (recorded from the 1/16 after 992, played
|
|
* a 1/8 later: the input of a 1/8 before) */
|
|
double e = 0, p = 0;
|
|
for (t = a0; t < a0 + 4000u; t++) {
|
|
double d = (double)out_l[t] - in_l[t - L];
|
|
e += d * d;
|
|
p += (double)out_l[t] * out_l[t];
|
|
}
|
|
snprintf(what, sizeof what, " .. a loop: a 1/8 later the same within %.1f %%", p > 0 ? 100.0 * sqrt(e / p) : 100.0);
|
|
bad += check(what, p > 0 && e < p * 0.01);
|
|
}
|
|
run(36, 1, ev, 2, 50000);
|
|
bad += check("REPEAT 1/8 at 36 BPM (833 ms, past 742 even at 11 kHz): nothing happens, bit for bit",
|
|
same(0, 50000) && !busy_seen && !sl_lent && !(perf_avail() & PF_BIT(PF_R8)));
|
|
run(120, 1, ev, 2, 50000);
|
|
bad += check("REPEAT 1/8 at 120 BPM (250 ms): it plays", !same(0, 40000) && (perf_avail() & PF_BIT(PF_R8)));
|
|
song.g[G_BPM] = 41;
|
|
bad += check(" REPEAT 1/8 fits from 41 BPM, 1/16 from 21 (V10.59: below 81 / 41 at 11 kHz)",
|
|
(perf_avail() & PF_BIT(PF_R8)) &&
|
|
(song.g[G_BPM] = 40, !(perf_avail() & PF_BIT(PF_R8))) &&
|
|
(song.g[G_BPM] = 21, perf_avail() & PF_BIT(PF_R16)) &&
|
|
(song.g[G_BPM] = 20, !(perf_avail() & PF_BIT(PF_R16))));
|
|
{ /* a REPEAT held while the tempo slows past its fit stops cleanly */
|
|
uint32_t t;
|
|
int32_t mx = 0;
|
|
host_tracks_init();
|
|
perf_reset();
|
|
song.g[G_BPM] = 120;
|
|
song.playing = 1;
|
|
perf_start();
|
|
test_signal(110, 12000, 110, 12000);
|
|
perf_press(PF_R8, 1);
|
|
for (t = 0; t < 120000u; t += CTL) {
|
|
uint32_t i;
|
|
if (t == 60000u)
|
|
song.g[G_BPM] = 72;
|
|
memcpy(out_l + t % NT, in_l + t % NT, CTL * 4);
|
|
memcpy(out_r + t % NT, in_r + t % NT, CTL * 4);
|
|
if (perf_begin(CTL))
|
|
perf_block(out_l + t % NT, out_r + t % NT, CTL);
|
|
for (i = 1; i < CTL && t > 1000u; i++) {
|
|
int32_t d = abs(out_l[t % NT + i] - out_l[t % NT + i - 1]);
|
|
mx = d > mx ? d : mx;
|
|
}
|
|
}
|
|
perf_press(PF_R8, 0);
|
|
bad += check(" a REPEAT 1/8 held while the tempo drops below its fit: it ends, no click",
|
|
pf.mode == BM_NONE && !sl_lent && mx < 4 * 190);
|
|
}
|
|
return bad;
|
|
}
|
|
|
|
/* ------------------------------------------------------------ the song --- */
|
|
static void song_setup(void)
|
|
{
|
|
static const uint8_t ACID[16] = {45, 45, 57, 45, 0, 48, 45, 55, 45, 0, 57, 52, 45, 48, 0, 50};
|
|
static const uint8_t AM[4] = {57, 60, 64, 67};
|
|
track_t *t1 = &trk[0], *t2 = &trk[1], *td = &trk[3];
|
|
uint32_t i;
|
|
memset(trk, 0, sizeof trk);
|
|
host_tracks_init();
|
|
perf_reset();
|
|
song.g[G_BPM] = 120;
|
|
host_preset(t1, 0, 4);
|
|
host_preset(t2, 1, 5);
|
|
host_drums(td); /* DRUM KIT (SAMPLE PERC until 1.0.2) */
|
|
for (i = 0; i < 16u; i++) {
|
|
uint8_t n = ACID[i], d[4], k = 0;
|
|
put_step(t1, i, n ? 1u : 0u, &n, n ? ST_NOTE : ST_REST, 0);
|
|
put_step(t2, i, i % 8u == 0u ? 4u : 0u, AM, i % 8u == 0u ? ST_NOTE : ST_TIE, 0);
|
|
if (i % 4u == 0u) d[k++] = 36;
|
|
if (i % 2u == 0u) d[k++] = 42;
|
|
if (i == 4u || i == 12u) d[k++] = 38;
|
|
put_step(td, i, k, d, k ? ST_NOTE : ST_REST, 0);
|
|
}
|
|
trk[0].p[P_PAN] = -40; /* the mix itself stereo */
|
|
trk[1].p[P_PAN] = 40;
|
|
}
|
|
static int32_t song_l[10u * 44100u + CTL], song_r[10u * 44100u + CTL]; /* (room for a 10 s render), and
|
|
* the last block may run past the frames asked */
|
|
static void song_render(uint32_t frames, void (*at)(uint32_t t))
|
|
{
|
|
uint32_t t, i;
|
|
int32_t o[2 * CTL];
|
|
transport_req = 1;
|
|
for (t = 0; t < frames; t += CTL) {
|
|
if (at)
|
|
at(t);
|
|
mix_block(o, CTL);
|
|
for (i = 0; i < CTL; i++) {
|
|
song_l[t + i] = o[2 * i];
|
|
song_r[t + i] = o[2 * i + 1];
|
|
}
|
|
}
|
|
transport_req = 2;
|
|
mix_block(o, CTL);
|
|
}
|
|
|
|
/* ------------------------------------------------------------ 4. SLICER --- */
|
|
static int slicer_ok;
|
|
static void stut_at(uint32_t t)
|
|
{
|
|
uint32_t k;
|
|
if (t == 44032u)
|
|
perf_press(PF_R16, 1);
|
|
(void)k;
|
|
if (t > 50000u && t < 80000u && (sl.rec_on || sl.loop))
|
|
slicer_ok = 0;
|
|
if (t > 50000u && t < 80000u && !sl_lent)
|
|
slicer_ok = 0;
|
|
if (t == 80000u)
|
|
perf_press(PF_R16, 0);
|
|
if (t == 80000u + 320u && (sl_lent || sl.rec || sl.loop))
|
|
slicer_ok = 0;
|
|
}
|
|
static int test_slicer(void)
|
|
{
|
|
uint32_t k;
|
|
song_setup();
|
|
(void)k;
|
|
song.g[G_SLMODE] = SL_STUT; /* (JIANT 0.6.3: the bus, everything in) */
|
|
song.g[G_SLPAT] = 1;
|
|
song.g[G_SLRATE] = 1;
|
|
song.g[G_SLDEP] = 127;
|
|
slicer_ok = 1;
|
|
song_render(120000, stut_at);
|
|
return check("SLICER STUT: live (no recording, no repeat) while REPEAT has the buffer, dropped after", slicer_ok);
|
|
}
|
|
|
|
/* -------------------------------------------------------------- 5. keys --- */
|
|
static int test_keys(void)
|
|
{
|
|
int bad = 0;
|
|
uint32_t mo0, fx = 1u << 3, k = 6; /* (a button bit for FX; key 6: a white key, B3: LPF) */
|
|
song_setup();
|
|
usb.config = 1;
|
|
mo_r = mo_w = 0;
|
|
kb_mask = perf_mask = fx;
|
|
fm1_in.buttons = fx;
|
|
fm1_in.notes = 1u << k;
|
|
keyboard_block();
|
|
mo0 = mo_w;
|
|
events_block(CTL);
|
|
bad += check("a key pressed while FX is held: no voice, no MIDI, the layer's, its effect held",
|
|
!busy_now() && mo0 == 0u && (kb_layer >> k) & 1u && (perf_held & PF_BIT(perf_key(k))));
|
|
fm1_in.buttons = 0; /* FX let go first: the effect stays with the key */
|
|
keyboard_block();
|
|
bad += check(" FX let go first: the key still holds its effect", (perf_held & PF_BIT(perf_key(k))) != 0u);
|
|
fm1_in.notes = 0;
|
|
keyboard_block();
|
|
bad += check(" let go: no note-off, the effect off", mo_w == 0u && !kb_layer && !perf_held);
|
|
fm1_in.notes = 1u << 7; /* a key, then FX: a note, and its note-off later */
|
|
keyboard_block();
|
|
fm1_in.buttons = fx;
|
|
keyboard_block();
|
|
fm1_in.notes = 0;
|
|
keyboard_block();
|
|
bad += check("a key held before FX stays a note (note-on and note-off sent)", mo_w == 2u && !kb_layer);
|
|
kb_mask = perf_mask = 0; /* no layer now (a menu): keys are notes */
|
|
fm1_in.notes = 1u << 7;
|
|
keyboard_block();
|
|
bad += check("no layer (kb_mask 0): FX held, keys are notes", mo_w == 3u && !kb_layer);
|
|
fm1_in.notes = 0;
|
|
fm1_in.buttons = 0;
|
|
keyboard_block();
|
|
{ /* the white keys past the first 5 (D4 on), and black keys past the mutes: the layer's, nothing */
|
|
uint32_t q, ok = 1, assigned = 0;
|
|
for (q = 0; q < 27u; q++)
|
|
if (perf_key(q) < PF_N)
|
|
assigned |= 1u << q;
|
|
kb_mask = perf_mask = fx;
|
|
mo0 = mo_w;
|
|
for (q = 0; q < 27u; q++) {
|
|
if ((assigned >> q) & 1u)
|
|
continue;
|
|
fm1_in.buttons = fx;
|
|
fm1_in.notes = 1u << q;
|
|
keyboard_block();
|
|
ok &= (kb_layer >> q) & 1u && kb_note[q] == KB_SILENT && !perf_held && mo_w == mo0;
|
|
fm1_in.notes = 0;
|
|
keyboard_block();
|
|
ok &= !kb_layer && !perf_held && mo_w == mo0;
|
|
}
|
|
fm1_in.buttons = 0;
|
|
bad += check("the keys without an effect (G5, the black keys past the mutes): silent, nothing held",
|
|
ok && (uint32_t)__builtin_popcount(assigned) == PF_N); /* (15 white F3 .. F5, 4 black) */
|
|
pfx_tgt = 0; /* (A#4 stepped it) */
|
|
kb_mask = perf_mask = 0;
|
|
}
|
|
usb.config = 0;
|
|
return bad;
|
|
}
|
|
|
|
/* -------------------------------------------------------------- 6. idle --- */
|
|
static int test_idle(void)
|
|
{
|
|
static int32_t a_l[NT], a_r[NT];
|
|
uint32_t t, diff = 0;
|
|
int bad = 0, fd[2];
|
|
pid_t pid;
|
|
song_setup();
|
|
if (pipe(fd) || (pid = fork()) < 0)
|
|
return check("idle: fork", 0);
|
|
if (!pid) { /* the same state, FX held the whole time, no key */
|
|
kb_mask = perf_mask = 1u << 3;
|
|
fm1_in.buttons = 1u << 3;
|
|
song_render(3u * FS, 0);
|
|
close(fd[0]);
|
|
if (write(fd[1], song_l, 3u * FS * 4u) < 0 || write(fd[1], song_r, 3u * FS * 4u) < 0)
|
|
_exit(1);
|
|
_exit(0);
|
|
}
|
|
close(fd[1]);
|
|
song_render(3u * FS, 0);
|
|
{
|
|
FILE *f = fdopen(fd[0], "rb");
|
|
size_t got = fread(a_l, 4, 3u * FS, f) + fread(a_r, 4, 3u * FS, f);
|
|
fclose(f);
|
|
waitpid(pid, 0, 0);
|
|
diff = got != 6u * FS;
|
|
}
|
|
for (t = 0; t < 3u * FS; t++)
|
|
diff += a_l[t] != song_l[t] || a_r[t] != song_r[t];
|
|
bad += check("idle (FX held, no key): the song bit for bit as without the layer", !diff);
|
|
{ /* after an effect: once its ramps are over, the stage is skipped again */
|
|
uint32_t f;
|
|
int32_t o[2 * CTL];
|
|
perf_press(PF_R16, 1);
|
|
for (f = 0; f < FS; f += CTL)
|
|
mix_block(o, CTL);
|
|
perf_press(PF_R16, 0);
|
|
for (f = 0; f < 512u; f += CTL)
|
|
mix_block(o, CTL);
|
|
bad += check(" after an effect is let go and its ramp is over: skipped again", !pf.busy && !perf_begin(CTL));
|
|
}
|
|
return bad;
|
|
}
|
|
|
|
/* ----------------------------------------------- 7. clicks, the rest --- */
|
|
static int test_misc(void)
|
|
{
|
|
int bad = 0;
|
|
char what[160];
|
|
static const struct { const char *name; int e; uint32_t off; } C[] = {
|
|
{"REPEAT 1/8", PF_R8, 30000}, {"REPEAT 1/16", PF_R16, 30000}, {"REPEAT 1/32", PF_R32, 30000},
|
|
{"REVERSE", PF_REV, 30000}, {"TAPE STOP", PF_TAPE, 60000}, {"PITCH UP", PF_PUP, 100000},
|
|
{"PITCH DOWN", PF_PDN, 100000}, {"STRETCH", PF_STR, 60000}}; /* (V10.7.59: were LPF HPF) */
|
|
uint32_t c, t;
|
|
int32_t own;
|
|
test_signal(110, 16000, 110, 16000);
|
|
for (own = 0, t = 1; t < NT; t++)
|
|
own = abs(in_l[t] - in_l[t - 1]) > own ? abs(in_l[t] - in_l[t - 1]) : own;
|
|
for (c = 0; c < sizeof C / sizeof C[0]; c++) {
|
|
ev_t ev[] = {{992, C[c].e + 1}, {C[c].off, -(C[c].e + 1)}};
|
|
int32_t mx = 0;
|
|
run(133, 1, ev, 2, C[c].off + 9000);
|
|
for (t = 1; t < C[c].off + 9000; t++) {
|
|
int32_t d = abs(out_l[t] - out_l[t - 1]);
|
|
mx = d > mx ? d : mx;
|
|
}
|
|
snprintf(what, sizeof what, "no clicks: %s on a 110 Hz sine, in and out: largest step %d (sine %d)", C[c].name, mx, own);
|
|
bad += check(what, mx <= 4 * own);
|
|
bad += check(" back to the live signal, bit for bit", same(C[c].off + 3000, C[c].off + 9000));
|
|
}
|
|
{ /* full scale in, no overflow (V10.7.59: the LPF / HPF keys gone; KNOB 1's FILTER below) */
|
|
for (t = 0; t < NT; t++) { /* full scale square waves, past Q15 */
|
|
in_l[t] = (t / 37u) & 1u ? 120000 : -120000;
|
|
in_r[t] = (t / 53u) & 1u ? 120000 : -120000;
|
|
}
|
|
{
|
|
ev_t e2[] = {{0, PF_R16 + 1}};
|
|
run_crush = 100;
|
|
run(120, 1, e2, 1, 100000);
|
|
run_crush = 0;
|
|
snprintf(what, sizeof what, "4x full scale through KNOB 2 CRUSH + REPEAT: peak %d (no wrap)",
|
|
peak(out_l, 0, 100000) > peak(out_r, 0, 100000) ? peak(out_l, 0, 100000) : peak(out_r, 0, 100000));
|
|
bad += check(what, peak(out_l, 0, 100000) < 300000 && peak(out_r, 0, 100000) < 300000);
|
|
}
|
|
}
|
|
{ /* KNOB 1 left: a low-pass at once; KNOB 4: the REPEAT's level */
|
|
test_signal(5000, 30000, 5000, 30000);
|
|
host_tracks_init();
|
|
perf_reset();
|
|
song.g[G_BPM] = 120;
|
|
song.playing = 1;
|
|
perf_start();
|
|
perf_k[0] = -100;
|
|
for (t = 0; t < 20000u; t += CTL) {
|
|
memcpy(out_l + t, in_l + t, CTL * 4);
|
|
memcpy(out_r + t, in_r + t, CTL * 4);
|
|
if (perf_begin(CTL))
|
|
perf_block(out_l + t, out_r + t, CTL);
|
|
}
|
|
perf_k[0] = 0;
|
|
snprintf(what, sizeof what, "KNOB 1 FILTER all the way left: a 5 kHz sine down to %d", peak(out_l, 10000, 20000));
|
|
bad += check(what, peak(out_l, 10000, 20000) < 3000);
|
|
}
|
|
{ /* THROW (KNOB 3): the dry mix into the delay and reverb sends; mutes: a track ramps out */
|
|
static int32_t ml[CTL], mr[CTL], sd[CTL], sr[CTL], z[CTL];
|
|
uint32_t i;
|
|
host_tracks_init();
|
|
perf_reset();
|
|
song.playing = 1;
|
|
perf_k[2] = 100;
|
|
for (t = 0; t < 1024u; t += CTL) {
|
|
for (i = 0; i < CTL; i++)
|
|
ml[i] = mr[i] = 8000, sd[i] = sr[i] = 0;
|
|
if (perf_begin(CTL))
|
|
perf_pre(ml, mr, z, z, sd, sr, CTL);
|
|
}
|
|
bad += check("KNOB 3 THROW at 100: the dry mix into both sends, full, the dry mix untouched",
|
|
sd[CTL - 1] > 7900 && sr[CTL - 1] > 7900 && ml[CTL - 1] == 8000 && mr[CTL - 1] == 8000);
|
|
perf_k[2] = 0;
|
|
}
|
|
{
|
|
int32_t o[2 * CTL];
|
|
uint32_t f;
|
|
int32_t before = 0, during = 0;
|
|
song_setup();
|
|
trk[1].p[P_SLEN] = 1; trk[3].p[P_SLEN] = 1;
|
|
trk[1].step[0].n = 0; trk[3].step[0].n = 0; /* only track 1 plays, dry */
|
|
trk[0].p[P_CHOR] = trk[0].p[P_DLY] = trk[0].p[P_REV] = 0;
|
|
transport_req = 1;
|
|
for (f = 0; f < 2u * FS; f += CTL) {
|
|
uint32_t i;
|
|
if (f == 44096u)
|
|
perf_press(PF_M1, 1);
|
|
mix_block(o, CTL);
|
|
for (i = 0; i < CTL; i++) {
|
|
if (f > FS / 2u && f < 44096u) before = abs(o[2 * i]) > before ? abs(o[2 * i]) : before;
|
|
if (f > FS + 512u) during = abs(o[2 * i]) > during ? abs(o[2 * i]) : during;
|
|
}
|
|
}
|
|
perf_press(PF_M1, 0);
|
|
transport_req = 2;
|
|
mix_block(o, CTL);
|
|
snprintf(what, sizeof what, "black key 1: track 1 muted while held (peak %d -> %d), P_MUTE untouched", before, during);
|
|
bad += check(what, before > 1000 && during < 200 && !trk[0].p[P_MUTE]);
|
|
}
|
|
return bad;
|
|
}
|
|
|
|
/* -------------------------------------------------------------- 8. cost --- */
|
|
static uint64_t instr_now(void)
|
|
{
|
|
#ifdef __APPLE__
|
|
struct rusage_info_v4 ri;
|
|
if (!proc_pid_rusage(getpid(), RUSAGE_INFO_V4, (rusage_info_t *)&ri))
|
|
return ri.ri_instructions;
|
|
#endif
|
|
return 0;
|
|
}
|
|
static double cost_run(int on)
|
|
{
|
|
static const int ALL[] = {PF_R16, PF_FRZ, PF_M1 + 2};
|
|
uint32_t f, k;
|
|
uint64_t i0;
|
|
int32_t o[2 * CTL];
|
|
song_setup();
|
|
transport_req = 1;
|
|
for (f = 0; f < FS; f += CTL)
|
|
mix_block(o, CTL);
|
|
if (on == 1) {
|
|
for (k = 0; k < sizeof ALL / sizeof ALL[0]; k++)
|
|
perf_press((uint32_t)ALL[k], 1);
|
|
perf_k[1] = perf_k[2] = 100; /* the CRUSH and THROW macros */
|
|
} else if (on == 3) { /* REPEAT 1/16 alone: the layer's own cost, for scale */
|
|
perf_press(PF_R16, 1);
|
|
}
|
|
i0 = instr_now();
|
|
for (f = 0; f < 2u * FS; f += CTL)
|
|
mix_block(o, CTL);
|
|
for (k = 0; k < PF_N; k++)
|
|
perf_press(k, 0);
|
|
perf_k[1] = perf_k[2] = perf_k[3] = 0;
|
|
transport_req = 2;
|
|
return i0 ? (double)(instr_now() - i0) / (2.0 * FS) : 0;
|
|
}
|
|
static int test_cost(void)
|
|
{
|
|
double idle = cost_run(0), on = cost_run(1), rep = cost_run(3);
|
|
char what[200];
|
|
int bad;
|
|
if (!idle) {
|
|
printf("perform: cost: no instruction counter on this host\n");
|
|
return 0;
|
|
}
|
|
snprintf(what, sizeof what, "cost: the song %.0f instructions / sample idle, %.0f with REPEAT+LPF+HPF+MUTE, K2 CRUSH, K3 THROW: +%.0f",
|
|
idle, on, on - idle);
|
|
bad = check(what, on - idle < 400);
|
|
printf("perform: cost: over the idle song: REPEAT 1/16 alone +%.0f (the layer's own stage)\n", rep - idle);
|
|
return bad;
|
|
}
|
|
|
|
/* ------------------------------------------------------------ demos --- */
|
|
static void demo_at(uint32_t t)
|
|
{
|
|
static const struct { uint32_t t; int e; } D[] = { /* press +(e + 1), let go -(e + 1) */
|
|
{88192, PF_R8 + 1}, {110080, -(PF_R8 + 1)}, {110080, PF_R16 + 1}, {121088, PF_R32 + 1},
|
|
{126592, -(PF_R32 + 1)}, {132096, -(PF_R16 + 1)}, {176384, PF_REV + 1}, {220480, -(PF_REV + 1)},
|
|
{264576, PF_TAPE + 1}, {308672, -(PF_TAPE + 1)}, {440896, PF_M1 + 1}, {462848, -(PF_M1 + 1)}};
|
|
uint32_t i;
|
|
if (t == 462848u)
|
|
perf_k[2] = 100; /* KNOB 3 THROW for a moment */
|
|
if (t == 474880u)
|
|
perf_k[2] = 0;
|
|
for (i = 0; i < sizeof D / sizeof D[0]; i++)
|
|
if (D[i].t == t)
|
|
perf_press((uint32_t)abs(D[i].e) - 1u, D[i].e > 0);
|
|
}
|
|
static void demos(const char *dir)
|
|
{
|
|
char path[512];
|
|
FILE *f;
|
|
uint32_t t;
|
|
song_setup();
|
|
song_render(NT - 4096u, demo_at);
|
|
snprintf(path, sizeof path, "%s/perform_tour.wav", dir);
|
|
if (!(f = fopen(path, "wb")))
|
|
return;
|
|
wav_hdr(f, NT - 4096u);
|
|
for (t = 0; t < NT - 4096u; t++)
|
|
wav_put(f, song_l[t], song_r[t]);
|
|
fclose(f);
|
|
printf("perform: demo %s (REPEAT 1/8, a 1/16 -> 1/32 roll, LPF, HPF, MUTE 1, KNOB 3 THROW)\n", path);
|
|
}
|
|
|
|
/* ------------------------------------------------- 9. punch-in MIDI --- */
|
|
static uint32_t zc(const int32_t *x, uint32_t a, uint32_t b) /* zero crossings, low-passed (2 poles; V10.7.17: half the
|
|
* corner it was, the saw's own partials crossed too) */
|
|
{
|
|
uint32_t i, c = 0;
|
|
int32_t y1 = 0, y2 = 0, p = 0;
|
|
for (i = a; i < b; i++) {
|
|
y1 += (x[i] - y1) >> 6;
|
|
y2 += (y1 - y2) >> 6;
|
|
if (i > a + 400u)
|
|
c += p < 0 && y2 >= 0;
|
|
p = y2;
|
|
}
|
|
return c;
|
|
}
|
|
static void pfx_render(uint32_t frames, uint32_t press_at, uint32_t free_at, uint32_t e)
|
|
{
|
|
uint32_t t, i;
|
|
int32_t o[2 * CTL];
|
|
for (t = 0; t < frames; t += CTL) {
|
|
if (t == press_at)
|
|
perf_press(e, 1);
|
|
if (t == free_at)
|
|
perf_press(e, 0);
|
|
mix_block(o, CTL);
|
|
for (i = 0; i < CTL; i++)
|
|
song_l[t + i] = o[2 * i];
|
|
}
|
|
}
|
|
static int test_pfx(void)
|
|
{
|
|
int bad = 0;
|
|
uint32_t c0, c1, c2, i, hits = 0;
|
|
track_t *t1 = &trk[0], *td = &trk[3];
|
|
int32_t o[2 * CTL];
|
|
/* OCT+ on a held note; then with DRM: the synth untouched */
|
|
song_setup();
|
|
for (i = 0; i < NTRK; i++) trk[i].p[P_DIST] = trk[i].p[P_CHOR] = trk[i].p[P_DLY] = trk[i].p[P_REV] = 0;
|
|
host_preset(t1, 0, 1);
|
|
t1->p[P_CHOR] = t1->p[P_DLY] = t1->p[P_REV] = 0; /* (V10.7.17: the preset's sends off too: a reverb's colour moved
|
|
* the count, the dry one alone) */
|
|
for (i = P_LD_PIT; i <= P_LD_AMP; i++) t1->p[i] = 0; /* (V10.6i: presets that move, the LFO and the matrix on the */
|
|
for (i = P_M1SRC; i <= P_M4AMT; i++) t1->p[i] = 0; /* sound: a pitch counted by zero crossings must hold still) */
|
|
trk_note_on(t1, 45, 100);
|
|
pfx_render(4u * 44032u, 88064u, 132096u, PF_OCTU); /* (its first second: the sound settles) */
|
|
c0 = zc(song_l, 66048u, 88064u);
|
|
c1 = zc(song_l, 110080u, 132096u);
|
|
c2 = zc(song_l, 154112u, 176128u);
|
|
bad += check("OCT+: a held note an octave up while held, back after", c1 > c0 * 1.7 && c1 < c0 * 2.3 &&
|
|
c2 > c0 * 0.85 && c2 < c0 * 1.15 && !t1->pfx_pit);
|
|
pfx_tgt = 2;
|
|
pfx_render(2u * 44032u, 22016u, 88064u, PF_OCTU);
|
|
c1 = zc(song_l, 44032u, 66048u);
|
|
c0 = c2;
|
|
bad += check(" A#4 DRM: OCT+ leaves the synth alone", c1 > c0 * 0.85 && c1 < c0 * 1.15 && !t1->pfx_pit);
|
|
pfx_tgt = 0;
|
|
trk_note_off(t1, 45);
|
|
/* DEC- on a kick: the tail shorter; DECY as it was outside the block */
|
|
{
|
|
double r0 = 0, r1 = 0;
|
|
int16_t d0 = td->p[P_E3];
|
|
uint32_t m;
|
|
for (m = 0; m < 2u; m++) {
|
|
for (i = 0; i < 44100u; i += CTL) mix_block(o, CTL);
|
|
if (m) perf_press(PF_DSHT, 1);
|
|
mix_block(o, CTL); /* (the effect in) */
|
|
trk_note_on(td, 36, 100);
|
|
pfx_render(11008u, 0xFFFFFFFFu, 0xFFFFFFFFu, 0);
|
|
for (i = 2205u; i < 8820u; i++) *(m ? &r1 : &r0) += (double)song_l[i] * song_l[i];
|
|
if (m) perf_press(PF_DSHT, 0);
|
|
}
|
|
mix_block(o, CTL);
|
|
bad += check("DEC-: a kick's tail shorter; DECY as stored outside the ISR", r1 < r0 * 0.5 && td->p[P_E3] == d0);
|
|
}
|
|
/* STUTTER 1/16 on the drums: the last kick 4 times a beat (120 BPM: 22050 samples) */
|
|
song_setup();
|
|
trk_note_on(td, 36, 100);
|
|
mix_block(o, CTL);
|
|
perf_press(PF_S8, 1);
|
|
for (i = 0; i < 22016u; i += CTL) {
|
|
mix_block(o, CTL);
|
|
hits += drum_kit[3][DV_KICK].age == 1u;
|
|
}
|
|
perf_press(PF_S8, 0);
|
|
mix_block(o, CTL);
|
|
bad += check("STUTTER 1/8 (JIANT 0.4, was 1/16): the last kick twice in a beat; let go: none more", hits == 2u && !(td->pfx & PFX_REP));
|
|
/* (JIANT 0.4) ATK+ on the drums: a hit's first ms softer (faded in); DEC- on a synth: its sustain 0 (a pluck), put
|
|
* back after; ARP on the drums: a fill, each press another */
|
|
{
|
|
double e0 = 0, e1 = 0;
|
|
uint32_t m;
|
|
for (m = 0; m < 2u; m++) {
|
|
song_setup();
|
|
for (i = 0; i < 22016u; i += CTL) mix_block(o, CTL);
|
|
if (m) perf_press(PF_ATK, 1);
|
|
mix_block(o, CTL);
|
|
mix_block(o, CTL);
|
|
trk_note_on(td, 38, 110);
|
|
pfx_render(4416u, 0xFFFFFFFFu, 0xFFFFFFFFu, 0);
|
|
for (i = 0; i < 441u; i++) *(m ? &e1 : &e0) += (double)song_l[i] * song_l[i];
|
|
if (m) perf_press(PF_ATK, 0);
|
|
}
|
|
mix_block(o, CTL);
|
|
bad += check("ATK+ on the drums: a snare's first 10 ms softer (faded in)", e1 < e0 * 0.5 && e0 > 0);
|
|
}
|
|
{
|
|
int16_t s0;
|
|
song_setup();
|
|
s0 = t1->p[P_SUS] = 100;
|
|
perf_press(PF_DSHT, 1);
|
|
for (i = 0; i < 4u * CTL; i += CTL) mix_block(o, CTL);
|
|
{
|
|
int16_t during;
|
|
uint32_t v;
|
|
int32_t env = 0;
|
|
trk_note_on(t1, 60, 100);
|
|
for (i = 0; i < 22016u; i += CTL) mix_block(o, CTL);
|
|
for (v = 0; v < NVOICE; v++)
|
|
if (t1->v[v].active && t1->v[v].env > env) env = t1->v[v].env;
|
|
during = t1->p[P_SUS];
|
|
perf_press(PF_DSHT, 0);
|
|
mix_block(o, CTL);
|
|
bad += check("DEC- on a synth: its sustain 0 (a held note decays away), back after", env < (1 << 24) / 20 &&
|
|
during == s0 && t1->p[P_SUS] == s0);
|
|
trk_note_off(t1, 60);
|
|
}
|
|
}
|
|
{
|
|
uint8_t f[2][16];
|
|
uint32_t m, n, same = 0, notes[2] = {0, 0};
|
|
for (m = 0; m < 2u; m++) {
|
|
song_setup();
|
|
perf_press(PF_ARP, 1);
|
|
for (n = 0; n < 16u; n++) {
|
|
f[m][n] = 0;
|
|
for (i = 0; i < 5504u; i += CTL) {
|
|
mix_block(o, CTL);
|
|
if (td->pfx_snn && !f[m][n]) { f[m][n] = td->pfx_sn[0]; notes[m]++; }
|
|
}
|
|
}
|
|
perf_press(PF_ARP, 0);
|
|
mix_block(o, CTL);
|
|
}
|
|
for (n = 0; n < 16u; n++) same += f[0][n] == f[1][n];
|
|
bad += check("ARP on the drums: a fill without a note struck first, another at the next press", notes[0] >= 8u &&
|
|
notes[1] >= 8u && same < 12u);
|
|
}
|
|
/* 1/2 TEMPO: the sequencer at half speed while held; let go, where it would have been */
|
|
{
|
|
uint16_t i0, ih;
|
|
uint32_t p0;
|
|
song_setup();
|
|
song_render(4u * 22016u, 0);
|
|
i0 = trk[0].seq_idx; p0 = trk[0].seq_pos;
|
|
song_setup();
|
|
transport_req = 1;
|
|
for (i = 0; i < 4u * 22016u; i += CTL) {
|
|
if (i == 22016u) perf_press(PF_HALF, 1);
|
|
if (i == 3u * 22016u) { ih = trk[0].seq_idx; perf_press(PF_HALF, 0); }
|
|
mix_block(o, CTL);
|
|
}
|
|
transport_req = 2;
|
|
mix_block(o, CTL);
|
|
bad += check("1/2 TEMPO: half the steps while held; let go, the sequencer where it would have been",
|
|
(uint16_t)(ih - 4u) <= 5u && trk[0].seq_idx == i0 && trk[0].seq_pos == p0);
|
|
}
|
|
/* RANDOM: some notes moved (an octave, a fifth, a fourth), none without it */
|
|
{
|
|
uint32_t moved = 0, far = 0, m;
|
|
song_setup();
|
|
host_preset(t1, 0, 1);
|
|
for (m = 0; m < 2u; m++) {
|
|
if (m) perf_press(PF_RND, 1);
|
|
mix_block(o, CTL);
|
|
for (i = 0; i < 24u; i++) {
|
|
uint32_t v;
|
|
trk_note_on(t1, 57, 100);
|
|
for (v = 0; v < NVOICE; v++)
|
|
if (t1->v[v].active && t1->v[v].note == 57 && t1->v[v].gate) {
|
|
int32_t d = t1->v[v].pitch16 - 57 * 16;
|
|
moved += m ? d != 0 : (uint32_t)(d != 0) * 100u;
|
|
far += d > 12 * 16 || d < -12 * 16;
|
|
}
|
|
trk_note_off(t1, 57);
|
|
mix_block(o, CTL);
|
|
}
|
|
if (m) perf_press(PF_RND, 0);
|
|
}
|
|
bad += check("RANDOM: some notes moved (octave, fifth, fourth), none past an octave; none without it",
|
|
moved > 3u && moved < 100u && !far);
|
|
}
|
|
/* ARP TRNS: a key (F4: +5 from C4) transposes the track's sequence, plays nothing itself */
|
|
{
|
|
uint32_t seen = 0, wrong = 0, v;
|
|
song_setup();
|
|
t1->p[P_AMODE] = AM_TRNS;
|
|
input_on(t1, 65, 100);
|
|
input_off(t1, 65);
|
|
transport_req = 1;
|
|
for (i = 0; i < 4u * 22016u; i += CTL) {
|
|
mix_block(o, CTL);
|
|
for (v = 0; v < NVOICE; v++)
|
|
if (t1->v[v].active && t1->v[v].gate) {
|
|
seen |= t1->v[v].note == 50u; /* (step 1: A2 45, +5) */
|
|
wrong |= t1->v[v].note == 45u || t1->v[v].note == 65u;
|
|
}
|
|
}
|
|
transport_req = 2;
|
|
mix_block(o, CTL);
|
|
bad += check("ARP TRNS: a key transposes the sequence by its interval from C4 (kept when let go), no note itself",
|
|
t1->trn == 5 && seen && !wrong);
|
|
}
|
|
/* the punch-in lane: REC armed, OCT+ held over steps 4..7 of the 64: recorded there (its tracks: DRM); the next
|
|
* pass plays it on the drums (DRUM's pitch offset at step 5, none at step 10), not on the synths; stopped,
|
|
* FX + G5 clears it */
|
|
{
|
|
uint32_t s16, st, ok = 1, pit5 = 0, pit10 = 1, syn = 0;
|
|
song_setup();
|
|
memset(pfx_lane, 0, sizeof pfx_lane);
|
|
s16 = beat_samples() / 4u;
|
|
song.rec = 1;
|
|
pfx_tgt = 2;
|
|
transport_req = 1;
|
|
for (i = 0; i < 64u * s16; i += CTL) {
|
|
st = (i / s16) & 63u;
|
|
if (st == 4u && !(perf_held & PF_BIT(PF_OCTU))) perf_press(PF_OCTU, 1);
|
|
if (st == 8u && (perf_held & PF_BIT(PF_OCTU))) perf_press(PF_OCTU, 0);
|
|
mix_block(o, CTL);
|
|
}
|
|
song.rec = 0;
|
|
pfx_tgt = 0;
|
|
for (st = 0; st < 64u; st++)
|
|
ok &= pfx_lane_at(st) == (st >= 4u && st < 8u ? (uint32_t)(PF_OCTU - PF_OCTD + 1) : 0u);
|
|
ok &= pfx_ltgt == 2u;
|
|
for (i = 64u * s16; i < 128u * s16; i += CTL) {
|
|
st = ((i - 64u * s16) / s16) & 63u;
|
|
mix_block(o, CTL);
|
|
if (st == 5u) pit5 = td->pfx_pit == 192, syn |= t1->pfx_pit != 0;
|
|
if (st == 10u) pit10 = td->pfx_pit;
|
|
}
|
|
transport_req = 2;
|
|
mix_block(o, CTL);
|
|
bad += check("punch-in lane: REC + OCT+ over steps 4..7 recorded (its tracks DRM); played back on the drums only",
|
|
ok && pit5 && !pit10 && !syn);
|
|
perf_press(PF_CLR, 1);
|
|
mix_block(o, CTL);
|
|
perf_press(PF_CLR, 0);
|
|
for (ok = 1, st = 0; st < 64u; st++) ok &= !pfx_lane_at(st);
|
|
bad += check(" stopped, FX + G5 clears the lane", ok);
|
|
}
|
|
/* (0.6.99) FX > PUNCH: LEN 16 of 1/8: the lane 16 steps of two sixteenths; a press over sixteenths 12..15 lands on
|
|
* steps 6 and 7, and the second pass (sixteenths 32..) plays it there again (the lane wraps at 16 of 1/8 = 32
|
|
* sixteenths); stopped, CLEAR empties it and the defaults come back */
|
|
{
|
|
uint32_t s16, st, ok = 1, pit6 = 0, pit0 = 1;
|
|
song_setup();
|
|
memset(pfx_lane, 0, sizeof pfx_lane);
|
|
song.g[G_PFXLEN] = 16; song.g[G_PFXRES] = 0;
|
|
s16 = beat_samples() / 4u;
|
|
song.rec = 1;
|
|
pfx_tgt = 0;
|
|
transport_req = 1;
|
|
for (i = 0; i < 32u * s16; i += CTL) {
|
|
st = (i / s16) & 63u;
|
|
if (st == 12u && !(perf_held & PF_BIT(PF_OCTU))) perf_press(PF_OCTU, 1);
|
|
if (st == 16u && (perf_held & PF_BIT(PF_OCTU))) perf_press(PF_OCTU, 0);
|
|
mix_block(o, CTL);
|
|
}
|
|
song.rec = 0;
|
|
ok &= pfx_lane_at(6) == (uint32_t)(PF_OCTU - PF_OCTD + 1) && pfx_lane_at(7) == (uint32_t)(PF_OCTU - PF_OCTD + 1) &&
|
|
!pfx_lane_at(5) && !pfx_lane_at(8) && !pfx_lane_at(16);
|
|
for (i = 32u * s16; i < 64u * s16; i += CTL) { /* the second pass of the 16 */
|
|
st = ((i - 32u * s16) / s16) & 63u;
|
|
mix_block(o, CTL);
|
|
if (st == 13u) pit6 = t1->pfx_pit == 192;
|
|
if (st == 2u) pit0 = t1->pfx_pit;
|
|
}
|
|
transport_req = 2;
|
|
mix_block(o, CTL);
|
|
if (!(ok && pit6 && !pit0)) printf(" punch LEN 16 of 1/8: lane %u %u %u, pit %u %u\n", pfx_lane_at(5), pfx_lane_at(6), pfx_lane_at(7), pit6, pit0);
|
|
bad += check("PUNCH LEN 16 RES 1/8: a press over sixteenths 12..15 on steps 6 7, played again on the lane's second pass", ok && pit6 && !pit0);
|
|
song.g[G_PFXLEN] = 64; song.g[G_PFXRES] = 1;
|
|
}
|
|
return bad;
|
|
}
|
|
|
|
/* (0.9.9-snd2) LOOP 3 / 5 / 7 (G#4, C#5, D#5): pressed while step 8 plays, the steps after are 6 7 8 6 7 8 .. (4 5 6 7 8 ..),
|
|
* not on the bar; every track its own last steps; let go, the sequencer where it would have been */
|
|
static int loop_case(uint32_t e, uint32_t nn, const uint8_t *want, uint32_t nw)
|
|
{
|
|
static int32_t o[2 * CTL];
|
|
uint8_t got[16];
|
|
uint32_t i, k = 0, last = 0xFFFFu, pressed = 0, t0 = 0, ok;
|
|
uint16_t i0, id;
|
|
uint32_t p0;
|
|
song_setup();
|
|
transport_req = 1;
|
|
for (i = 0; i < 8u * 22016u && k < nw; i += CTL) {
|
|
if (!pressed && trk[0].seq_idx == 8u && trk[0].seq_pos > 2000u) { perf_press(e, 1); pressed = 1; t0 = i; }
|
|
mix_block(o, CTL);
|
|
if (pressed && trk[0].seq_idx != last && i > t0) got[k++] = (uint8_t)trk[0].seq_idx;
|
|
last = trk[0].seq_idx;
|
|
}
|
|
id = trk[3].seq_idx; /* (the drums too: the same window) */
|
|
perf_press(e, 0);
|
|
for (; i < 8u * 22016u; i += CTL)
|
|
mix_block(o, CTL);
|
|
transport_req = 2;
|
|
mix_block(o, CTL);
|
|
i0 = trk[0].seq_idx; p0 = trk[0].seq_pos;
|
|
song_setup(); /* (the reference: the same time without LOOP) */
|
|
song_render(8u * 22016u, 0);
|
|
ok = k == nw && !memcmp(got, want, nw) && id >= 8u - (nn - 1u) && id <= 8u;
|
|
printf("perform: LOOP %u: steps after the press", (unsigned)nn);
|
|
for (i = 0; i < k; i++) printf(" %u", got[i]);
|
|
printf("; let go: step %u (%u without it)\n", i0, trk[0].seq_idx);
|
|
return check(nn == 3u ? "LOOP 3: the last 3 steps again (6 7 8 6 7 8 ..), let go where it would have been"
|
|
: nn == 5u ? "LOOP 5: the last 5 steps again (4 5 6 7 8 4 ..), let go where it would have been"
|
|
: "LOOP 7: the last 7 steps again (2 .. 8 2 ..), let go where it would have been",
|
|
ok && i0 == trk[0].seq_idx && p0 == trk[0].seq_pos);
|
|
}
|
|
static uint32_t zc_raw(const int32_t *x, uint32_t a, uint32_t b) /* zero crossings, upwards */
|
|
{
|
|
uint32_t c = 0;
|
|
for (a++; a < b; a++)
|
|
c += x[a - 1] < 0 && x[a] >= 0;
|
|
return c;
|
|
}
|
|
static int32_t max_step(const int32_t *x, uint32_t a, uint32_t b)
|
|
{
|
|
int32_t m = 0;
|
|
for (a++; a < b; a++)
|
|
m = abs(x[a] - x[a - 1]) > m ? abs(x[a] - x[a - 1]) : m;
|
|
return m;
|
|
}
|
|
/* (V10.7.36's, back in V10.7.59) REVERSE, TAPE STOP, PITCH UP / DOWN; (V10.7.59) STRETCH */
|
|
static int test_new(void)
|
|
{
|
|
int bad = 0;
|
|
char what[200];
|
|
uint32_t t;
|
|
{ /* REVERSE: pressed mid-1/16, starts on the next; its first window records (live), then each 1/16 is the one
|
|
* before it backwards */
|
|
ev_t ev[] = {{992, PF_REV + 1}, {12u * P16 + 100u, -(PF_REV + 1)}};
|
|
int32_t e = 0, pk;
|
|
uint32_t w;
|
|
test_signal(110, 12000, 165, 9000);
|
|
run(120, 1, ev, 2, 14u * P16);
|
|
for (w = 2; w < 11u; w++)
|
|
for (t = (w + 1u) * P16 + 200u; t < (w + 2u) * P16 - 200u; t++) {
|
|
int32_t d = abs(out_l[t] - in_l[(w + 1u) * P16 - 3u - (t - (w + 1u) * P16)]);
|
|
e = d > e ? d : e;
|
|
}
|
|
pk = peak(out_l, 2u * P16, 12u * P16);
|
|
snprintf(what, sizeof what, "REVERSE: live until the next 1/16 and one more, then each 1/16 the one before backwards "
|
|
"(error %d of 12000, peak %d)", e, pk);
|
|
bad += check(what, same(0, 2u * P16) && e < 400 && pk <= 12100);
|
|
bad += check(" let go: the live signal again after the ramp, bit for bit; the buffer given back",
|
|
same(12u * P16 + 400u, 14u * P16) && !sl_lent && pf.mode == BM_NONE);
|
|
}
|
|
{ /* TAPE STOP: a beat (4 x 1/16 at 120) slowing (fewer crossings), then silence while held */
|
|
ev_t ev[] = {{P16, PF_TAPE + 1}, {12u * P16, -(PF_TAPE + 1)}};
|
|
uint32_t c0, c1, c2;
|
|
int32_t sil, pk;
|
|
test_signal(440, 12000, 440, 12000);
|
|
run(120, 1, ev, 2, 14u * P16);
|
|
c0 = zc_raw(out_l, 2u * P16 + 200u, 2u * P16 + 2200u);
|
|
c1 = zc_raw(out_l, 4u * P16 + 200u, 4u * P16 + 2200u);
|
|
c2 = zc_raw(in_l, 4u * P16 + 200u, 4u * P16 + 2200u);
|
|
sil = peak(out_l, 6u * P16 + 600u, 12u * P16);
|
|
pk = peak(out_l, 2u * P16, 12u * P16);
|
|
snprintf(what, sizeof what, "TAPE STOP: slower and lower (crossings %u -> %u, live %u), then silent while held "
|
|
"(peak %d), bounded (%d)", c0, c1, c2, sil, pk);
|
|
bad += check(what, c1 < c0 * 3u / 4u && c0 > c2 * 3u / 4u && sil == 0 && pk <= 12100);
|
|
bad += check(" let go: the live signal again after the ramp, bit for bit", same(12u * P16 + 400u, 14u * P16));
|
|
}
|
|
{ /* PITCH UP / DOWN: at once; an octave up / down after a bar (about 2x / 0.5x the crossings), in time */
|
|
static const int E[2] = {PF_PUP, PF_PDN};
|
|
uint32_t j;
|
|
for (j = 0; j < 2u; j++) {
|
|
ev_t ev[] = {{992, E[j] + 1}, {28u * P16, -(E[j] + 1)}};
|
|
uint32_t c, c0;
|
|
int32_t pk, st;
|
|
test_signal(330, 12000, 330, 12000);
|
|
run(120, 1, ev, 2, 30u * P16);
|
|
c = zc_raw(out_l, 20u * P16, 27u * P16);
|
|
c0 = zc_raw(in_l, 20u * P16, 27u * P16);
|
|
pk = peak(out_l, 0, 28u * P16);
|
|
st = max_step(out_l, 0, 30u * P16);
|
|
snprintf(what, sizeof what, "PITCH %s: after a bar %u crossings for %u (x%.2f), peak %d, largest step %d",
|
|
j ? "DOWN" : "UP", c, c0, (double)c / c0, pk, st);
|
|
bad += check(what, (j ? c > c0 * 4u / 10u && c < c0 * 6u / 10u : c > c0 * 18u / 10u && c < c0 * 22u / 10u) &&
|
|
!same(992, 2u * P16) && pk <= 12500 && st < 3000);
|
|
bad += check(" let go: back with the ramp, bit for bit", same(28u * P16 + 400u, 30u * P16) && !sl_lent);
|
|
}
|
|
}
|
|
{ /* STRETCH: half a beat recorded (live meanwhile), then played back slower at its own pitch: as many crossings
|
|
* a second as the input (a 330 Hz sine: its pitch kept), not the live signal, bounded; let go, live again */
|
|
ev_t ev[] = {{P16, PF_STR + 1}, {20u * P16, -(PF_STR + 1)}};
|
|
uint32_t c, c0;
|
|
int32_t pk;
|
|
test_signal(330, 12000, 330, 12000);
|
|
run(120, 1, ev, 2, 22u * P16);
|
|
c = zc_raw(out_l, 8u * P16, 18u * P16);
|
|
c0 = zc_raw(in_l, 8u * P16, 18u * P16);
|
|
pk = peak(out_l, 0, 20u * P16);
|
|
snprintf(what, sizeof what, "STRETCH: after half a beat its own pitch (%u crossings for %u), bounded (peak %d)", c, c0, pk);
|
|
bad += check(what, c > c0 * 9u / 10u && c < c0 * 11u / 10u && same(0, 2u * P16) && pk <= 12500);
|
|
bad += check(" let go: the live signal again after the ramp, bit for bit; the buffer given back",
|
|
same(20u * P16 + 400u, 22u * P16) && !sl_lent && pf.mode == BM_NONE);
|
|
}
|
|
return bad;
|
|
}
|
|
static int test_loops(void)
|
|
{
|
|
static const uint8_t W3[9] = {6, 7, 8, 6, 7, 8, 6, 7, 8}, W5[10] = {4, 5, 6, 7, 8, 4, 5, 6, 7, 8};
|
|
static const uint8_t W7[14] = {2, 3, 4, 5, 6, 7, 8, 2, 3, 4, 5, 6, 7, 8};
|
|
int bad = 0;
|
|
bad += loop_case(PF_LP3, 3u, W3, 9u);
|
|
(void)W5; (void)W7; /* (V10.7.59: LOOP 5 / 7's keys are PITCH's) */
|
|
return bad;
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
int bad = 0;
|
|
bad += test_loops();
|
|
bad += test_new();
|
|
bad += test_timing();
|
|
bad += test_stereo();
|
|
bad += test_too_long();
|
|
bad += test_slicer();
|
|
bad += test_keys();
|
|
bad += test_idle();
|
|
bad += test_misc();
|
|
bad += test_pfx();
|
|
bad += test_cost();
|
|
if (argc > 1)
|
|
demos(argv[1]);
|
|
printf("%s\n", bad ? "PERFORM TEST FAILED" : "perform test passed");
|
|
return bad != 0;
|
|
}
|