Files
JIANT/tests/slicer_test.c
T
Claude da1b1dd2c1 Copyright headers: name Juan Jiant on JIANT's own files, add him on the modified Felucca ones
Comment-only change (the built image is byte-identical: felucca.bin 583936 B, felucca.fwsc 684736 B, same SHA-256).

- 37 files written new for JIANT FM after the fork (no Felucca text in them: checked against ac6bfcbd by literal
  code lines, runs of consecutive lines, same-named functions and moves in their creating commit) carried Leo
  Kuroshita's copyright line copied from a template: it is now Juan Jiant's (SPDX GPL-3.0-only kept). Among them
  sing.c, eng_animal.c, eng_input.c, eng_string.c, pfx.c, seq_live.c, ui_engvis.c, ui_lens.c, ui_lz*.c, ui_being.c,
  ui_organic.c, ui_tech.c, ui_dx.c, ui_live.c, tools/lyrics/*.txt, gen_drum_maps.py, gen_px_font.py and 14 tests.
- 140 files that hold Felucca's code (Felucca 1.1.5.1 files changed since, imports of Felucca 1.5.x, the SLOOP-based
  song_main/song_play, and new files that carry copied Felucca helpers: drumx_voice.c dv_exp2/dv_kb, gen_lyrics.py's
  Huffman, test harness helpers) keep Leo's notice and add "Portions Copyright (C) 2026 Juan Ignacio Antonucci
  (Juan Jiant)". Files unchanged since the fork are left as they were.
- LICENSING.md and README.md name both copyright holders.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KMHk6yH4XbP1xxHYKCo9Mh
2026-11-11 18:04:53 +00:00

527 lines
22 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 SLICER (firmware/src/slicer.c), same sources as the firmware (through hostsim.c).
* build/host/slicer_test [DEMO_DIR] (run_tests.sh: build/slicer_demo)
* 1. no clicks: a 110 Hz sine through GATE / STUT at several rates, tempi, swings, and with the mode,
* pattern and depth turned while it runs: the largest sample step of the output stays within a few
* times the sine's own (a hard gate edge would be ~60 x).
* 2. timing: a constant signal through GATE at 97 BPM with swing: every step's middle is open or
* closed as the pattern says, every closing ramp ends on the step boundary (sample exact, from the
* swung step lengths of seq.c).
* 3. sync: the song with the transport: at every block the SLICER's step is the sequencer's.
* 4. OFF is transparent (the signal untouched), STUT repeats what the live step played.
* 5. (JIANT 0.6.3) the bus: the routed tracks through it, the others not; FX ON: the returns too; the repeats' pitch
* sequence (+12: twice the frequency, the step's rhythm kept; QNT SCL snaps to the scale).
* 6. cost: instructions per sample of the mix, the SLICER on against off (proc_pid_rusage).
* Demos (WAV, 44.1 kHz) into DEMO_DIR: dry / gated / stuttered versions of a pad, the acid line, the
* drums (track 4: DRUM), and the song. */
#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("slicer: %-74s %s\n", what, ok ? "ok" : "FAIL");
return ok ? 0 : 1;
}
/* (JIANT 0.6.3: one SLICER, on a bus: its globals; t unused) */
static void set_slicer(track_t *t, int mode, int pat, int rate, int depth)
{
(void)t;
song.g[G_SLMODE] = (int16_t)mode;
song.g[G_SLPAT] = (int16_t)pat;
song.g[G_SLRATE] = (int16_t)rate;
song.g[G_SLDEP] = (int16_t)depth;
}
/* a mono signal through the bus (both sides the same; the left back) */
static void sl_mono(int32_t *b, uint32_t n)
{
int32_t r[CTL];
memcpy(r, b, n * sizeof b[0]);
slicer_bus(b, r, n);
}
/* ---------------------------------------------------------- 1. clicks --- */
/* n seconds of a 110 Hz sine (amplitude 20000) through track 1's SLICER; turn: change the settings
* while it runs. Returns the largest |step| of the output; *in_step: the sine's own */
static int32_t sine_run(double secs, int turn, int32_t *in_step, int64_t *closed_energy)
{
uint32_t f, i, frames = (uint32_t)(secs * FS) / CTL * CTL;
int32_t prev = 0, pin = 0, mx = 0, mi = 0;
double ph = 0, dph = 2 * M_PI * 110.0 / FS;
track_t *t = &trk[0];
*closed_energy = 0;
slicer_start();
for (f = 0; f < frames; f += CTL) {
int32_t b[CTL];
if (turn && f % 3008u == 0u) { /* modes, patterns, depths, rates while it runs */
uint32_t k = f / 3008u;
set_slicer(t, (int)(k % 3u), (int)(1u + k * 7u % 16u), (int)(k % 6u), (int)(40u + k * 37u % 88u));
}
for (i = 0; i < CTL; i++) {
b[i] = (int32_t)lrint(20000.0 * sin(ph));
ph += dph;
if (f + i) {
int32_t d = abs(b[i] - pin);
mi = d > mi ? d : mi;
}
pin = b[i];
}
sl_mono(b, CTL);
for (i = 0; i < CTL; i++) {
if (f + i) {
int32_t d = abs(b[i] - prev);
mx = d > mx ? d : mx;
}
prev = b[i];
if (!sl.bit && sl.pos > SL_RAMP + CTL)
*closed_energy += (int64_t)b[i] * b[i];
}
}
*in_step = mi;
return mx;
}
static int test_clicks(void)
{
static const struct { const char *name; int mode, pat, rate, depth, bpm, swing; double secs; } C[] = {
{"GATE pattern 1, 1/16, 120 BPM, 100 %", SL_GATE, 1, 1, 127, 120, 0, 4},
{"GATE pattern 12, 1/32, 240 BPM, 100 %", SL_GATE, 12, 2, 127, 240, 0, 3},
{"GATE pattern 2, 32T, 240 BPM, swing 50 %", SL_GATE, 2, 5, 127, 240, 50, 3},
{"GATE pattern 5, 8T, 90 BPM, 60 %", SL_GATE, 5, 3, 76, 90, 10, 4},
{"STUT pattern 7, 1/16, 120 BPM, 100 %", SL_STUT, 7, 1, 127, 120, 0, 4},
{"STUT pattern 3, 32T, 200 BPM, 70 %, swing 30 %", SL_STUT, 3, 5, 90, 200, 30, 3},
{"STUT pattern 9, 1/8, 40 BPM (loop shorter than the step)", SL_STUT, 9, 0, 127, 40, 0, 8},
{"STUT pattern 13, 16T, 133 BPM", SL_STUT, 13, 4, 127, 133, 0, 4},
};
uint32_t c;
int bad = 0;
char what[160];
for (c = 0; c < sizeof C / sizeof C[0]; c++) {
int32_t in, out;
int64_t ce;
host_tracks_init();
slicer_reset();
song.g[G_BPM] = (int16_t)C[c].bpm;
song.g[G_SWING] = (int16_t)C[c].swing; /* (the bus: the global SWING) */
set_slicer(&trk[0], C[c].mode, C[c].pat, C[c].rate, C[c].depth);
out = sine_run(C[c].secs, 0, &in, &ce);
snprintf(what, sizeof what, "no clicks: %s: largest step %d (sine %d, %.1f x)", C[c].name, out, in,
(double)out / in);
bad += check(what, out <= 4 * in);
if (C[c].mode == SL_GATE && C[c].depth == 127) {
snprintf(what, sizeof what, " closed steps silent (rms %.2f)", sqrt((double)ce / (FS * C[c].secs)));
bad += check(what, ce < (int64_t)(FS * C[c].secs));
}
}
{
int32_t in, out;
int64_t ce;
host_tracks_init();
slicer_reset();
out = sine_run(10, 1, &in, &ce);
snprintf(what, sizeof what, "no clicks: mode / pattern / depth / rate turned while it runs: %d (%.1f x)", out,
(double)out / in);
bad += check(what, out <= 4 * in);
}
return bad;
}
/* ---------------------------------------------------------- 2. timing --- */
static int test_timing(void)
{
const uint32_t steps = 64u, pat = 8u;
uint32_t f = 0, k, b0 = 0, bad_mid = 0, bad_edge = 0, n = 0;
static int32_t out[16u * 44100u];
int bad = 0;
char what[160];
track_t *t = &trk[0];
host_tracks_init();
slicer_reset();
song.g[G_BPM] = 97;
song.g[G_SWING] = 30; /* (the bus: the global SWING alone) */
set_slicer(t, SL_GATE, (int)pat, 1, 127);
slicer_start();
while (f + CTL <= sizeof out / sizeof out[0]) {
uint32_t i;
for (i = 0; i < CTL; i++)
out[f + i] = 16384;
sl_mono(out + f, CTL);
f += CTL;
}
for (k = 0; k < steps; k++) { /* the step lengths as seq.c step_samples has them */
uint32_t base = (uint32_t)FS * 60u / 97u / 4u, len, idx = k & 15u, on = (SL_PAT[pat - 1u] >> idx) & 1u;
uint32_t non = (SL_PAT[pat - 1u] >> ((idx + 1u) & 15u)) & 1u;
int32_t sw = (20 + 10) * (int32_t)base / 250;
len = base + (uint32_t)((idx & 1u) ? -sw : sw);
if (b0 + len >= f)
break;
n++;
if (on ? out[b0 + len / 2u] != 16384 : abs(out[b0 + len / 2u]) > 2)
bad_mid++;
if (on && !non && (abs(out[b0 + len - 1u]) > 300 || out[b0 + len - 1u - SL_RAMP] != 16384))
bad_edge++; /* closed by the boundary, not earlier */
if (!on && non && (abs(out[b0 + len]) > 300 || out[b0 + len + SL_RAMP] != 16384))
bad_edge++; /* opens from the boundary */
b0 += len;
}
snprintf(what, sizeof what, "timing: GATE at 97 BPM, swing 30 %%: %u steps open / closed as the pattern says",
n);
bad += check(what, !bad_mid && n > 32u);
bad += check("timing: every ramp ends / starts on the swung step boundary (sample exact)", !bad_edge);
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 ACIDF[16] = {1, 0, 2, 0, 0, 0, 1, 2, 0, 0, 1, 0, 0, 2, 0, 1};
static const uint8_t AM[4] = {57, 60, 64, 67}, FMI[4] = {53, 57, 60, 64};
static const uint8_t LEAD[12] = {76, 0, 0, 79, 0, 0, 81, 0, 79, 0, 76, 0};
track_t *t1 = &trk[0], *t2 = &trk[1], *t3 = &trk[2], *td = &trk[3];
uint32_t i;
host_tracks_init();
slicer_reset();
song.g[G_BPM] = 120;
host_preset(t1, 0, 4);
host_preset(t2, 1, 5);
host_preset(t3, 3, 0);
host_drums(td); /* DRUM KIT (SAMPLE PERC until 1.0.2) */
for (i = 0; i < 16u; i++) {
uint8_t n = ACID[i];
put_step(t1, i, n ? 1u : 0u, &n, n ? ST_NOTE : ST_REST, ACIDF[i]);
}
t2->p[P_SLEN] = 32;
t2->p[P_SGATE] = 120;
for (i = 0; i < 32u; i++)
put_step(t2, i, i % 16u == 0u ? 4u : 0u, i < 16u ? AM : FMI, i % 16u == 0u ? ST_NOTE : i % 16u < 14u ? ST_TIE : ST_REST, 0);
t3->p[P_SLEN] = 12;
for (i = 0; i < 12u; i++) {
uint8_t n = LEAD[i];
put_step(t3, i, n ? 1u : 0u, &n, n ? ST_NOTE : ST_REST, i == 0u ? SF_ACCENT : 0u);
}
for (i = 0; i < 16u; i++) {
uint8_t n[4];
uint32_t k = 0;
if (i % 4u == 0u)
n[k++] = 36;
if (i == 4u || i == 12u)
n[k++] = 38;
if (i % 2u == 0u)
n[k++] = i == 14u ? 46 : 42;
put_step(td, i, k, n, k ? ST_NOTE : ST_REST, i % 4u == 0u ? SF_ACCENT : 0u);
}
}
/* ------------------------------------------------------------ 3. sync --- */
static int test_sync(void)
{
uint32_t f, k, blocks = 0, miss = 0;
char what[160];
song_setup();
song.g[G_SWING] = 15;
for (k = 0; k < NTRK; k++) {
trk[k].p[P_SSWING] = 0; /* (the bus follows the global SWING) */
trk[k].p[P_SLEN] = 16; /* 16 steps of 1/16: the SLICER's bar */
}
set_slicer(&trk[0], SL_STUT, 3, 1, 127);
song.g[G_BPM] = 131;
transport_req = 1;
for (f = 0; f < 12u * FS; f += CTL) {
int32_t o[2 * CTL];
mix_block(o, CTL);
blocks++;
for (k = 0; k < NTRK; k++) { /* the SLICER step that holds the block's first sample */
uint32_t idx = sl.pos >= CTL ? sl.idx : (sl.idx + 15u) & 15u;
miss += idx != trk[k].seq_idx % 16u;
}
}
transport_req = 2;
snprintf(what, sizeof what, "sync: 131 BPM, swing 15 %%: every track's sequencer step at %u blocks", blocks);
k = check(what, !miss);
{ /* (JIANT) the RATE changed mid-song (1/8T -> 1/16) and the tempo moved: on the grid from the next step on */
int32_t o[2 * CTL];
uint32_t m2 = 0, n2 = 0;
song_setup();
song.g[G_SWING] = 0;
trk[0].p[P_SSWING] = 0;
trk[0].p[P_SLEN] = 16;
set_slicer(&trk[0], SL_GATE, 3, 3, 127); /* (RATE 3: 1/8T) */
song.g[G_BPM] = 97;
transport_req = 1;
for (f = 0; f < 3u * FS + 777u; f += CTL)
mix_block(o, CTL);
song.g[G_SLRATE] = 1; /* 1/16 */
song.g[G_BPM] = 113;
for (f = 0; f < 4u * FS; f += CTL) {
mix_block(o, CTL);
if (f > FS / 2u) { /* (after the next step) */
uint32_t idx = sl.pos >= CTL ? sl.idx : (sl.idx + 15u) & 15u;
m2 += idx != trk[0].seq_idx % 16u;
n2++;
}
}
transport_req = 2;
snprintf(what, sizeof what, "sync: RATE 1/8T -> 1/16 and 97 -> 113 BPM while playing: on the sequencer's step (%u of %u)",
n2 - m2, n2);
k |= check(what, !m2 && n2 > 100u);
}
return k;
}
/* ------------------------------------------------------- 4. OFF / STUT --- */
static int test_off_stut(void)
{
uint32_t f, i, same = 1, rep_ok = 0, rep_n = 0;
track_t *t = &trk[0];
int bad = 0;
host_tracks_init();
slicer_reset();
slicer_start();
for (f = 0; f < FS; f += CTL) { /* OFF: untouched */
int32_t b[CTL], c[CTL];
for (i = 0; i < CTL; i++)
b[i] = c[i] = (int32_t)((f + i) * 2654435761u >> 17) - 16384;
sl_mono(b, CTL);
same &= !memcmp(b, c, sizeof b);
}
bad += check("OFF: the signal is not touched", same);
/* STUT, pattern 7 (x...), 1/16 at 120 BPM, 100 %: the repeat steps play the live step again */
set_slicer(t, SL_STUT, 7, 1, 127);
slicer_start();
song.playing = 0; /* (its own clock: the transport's grid does not run here) */
{
static int32_t in[4u * 44100u], out[4u * 44100u];
uint32_t len = (uint32_t)FS * 60u / 120u / 4u;
for (f = 0; f < sizeof in / sizeof in[0]; f++)
in[f] = out[f] = (int32_t)(12000.0 * sin(2 * M_PI * 150.0 * f / FS)); /* 18.75 periods a step */
for (f = 0; f + CTL <= sizeof in / sizeof in[0]; f += CTL)
sl_mono(out + f, CTL);
for (f = 0; f + 4u * len < sizeof in / sizeof in[0]; f += 4u * len) /* steps 1..3 of every 4 = step 0 */
for (i = 1; i < 4u; i++) {
uint32_t a = f + i * len + len / 2u, b = f + len / 2u;
rep_n++;
rep_ok += abs(out[a] - in[b]) < 400; /* (22 kHz recording, read between samples) */
}
}
{
char what[160];
snprintf(what, sizeof what, "STUT: the repeat steps play the live step (%u of %u checked)", rep_ok, rep_n);
bad += check(what, rep_ok == rep_n && rep_n > 8u);
}
return bad;
}
/* ------------------------------------------------------------ 5. 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)
{
uint32_t f, k;
uint64_t i0;
int32_t o[2 * CTL];
song_setup();
set_slicer(&trk[0], on ? SL_STUT : 0, 4, 1, 100); /* (everything in, FX too: the defaults) */
transport_req = 1;
for (f = 0; f < FS; f += CTL)
mix_block(o, CTL);
i0 = instr_now();
for (f = 0; f < 2u * FS; f += CTL)
mix_block(o, CTL);
transport_req = 2;
return i0 ? (double)(instr_now() - i0) / (2.0 * FS) : 0;
}
static int test_cost(void)
{
double off = cost_run(0), on = cost_run(1);
char what[160];
if (!off) {
printf("slicer: cost: no instruction counter on this host\n");
return 0;
}
snprintf(what, sizeof what, "cost: the song, the SLICER on (everything in): %.0f instructions / sample (off %.0f): +%.0f",
on, off, on - off);
return check(what, on - off < 120);
}
/* ------------------------------------------------------------ demos --- */
/* the song with the SLICER (mode, pattern, rate, depth) on the tracks of mask (bit k: track k + 1, bit 6: FX); solo: that
* track alone */
static void demo_song(const char *dir, const char *name, int mode, int pat, int rate, int depth, uint32_t mask, uint32_t solo)
{
char path[512];
FILE *w;
uint32_t f, k, frames = 8u * FS;
snprintf(path, sizeof path, "%s/%s", dir, name);
if (!(w = fopen(path, "wb")))
return;
song_setup();
set_slicer(&trk[0], mode, pat, rate, depth);
for (k = 0; k <= NTRK; k++)
song.g[G_SLT1 + k] = (int16_t)((mask >> k) & 1u);
for (k = 0; k < NTRK; k++)
if (solo && k + 1u != solo)
trk[k].p[P_LEVEL] = 0;
transport_req = 1;
wav_hdr(w, frames);
for (f = 0; f < frames; f += CTL) {
int32_t o[2 * CTL];
uint32_t i;
mix_block(o, CTL);
for (i = 0; i < CTL; i++)
wav_put(w, o[2 * i], o[2 * i + 1]);
}
transport_req = 2;
fclose(w);
for (k = 0; k < G_SL_N; k++)
song.g[G_SLMODE + k] = GP[G_SLMODE + k].def;
}
static void demos(const char *dir)
{
demo_song(dir, "song_dry.wav", 0, 1, 1, 127, 0x7Fu, 0);
demo_song(dir, "song_master_stut.wav", SL_STUT, 9, 1, 127, 0x7Fu, 0); /* everything, FX too */
demo_song(dir, "song_drums_stut.wav", SL_STUT, 12, 2, 127, 1u << 3, 0); /* the drums alone, the rest dry */
demo_song(dir, "pad_gate_p1_16th.wav", SL_GATE, 1, 1, 127, 0x7Fu, 2);
demo_song(dir, "acid_stut_p7.wav", SL_STUT, 7, 1, 127, 0x7Fu, 1);
song.g[G_SLPLEN] = 4; song.g[G_SLP0] = 0; song.g[G_SLP0 + 1] = 7; song.g[G_SLP0 + 2] = 12; song.g[G_SLP0 + 3] = -5;
demo_song(dir, "song_master_stut_pitch.wav", SL_STUT, 7, 1, 127, 0x7Fu, 0); /* the repeats 0 +7 +12 -5 */
printf("slicer: demos in %s (song dry / the whole mix stuttered / the drums alone / pitched repeats)\n", dir);
}
/* (JIANT 0.6.3) the bus: what goes in, FX, the pitch of the repeats */
static int zc(const int32_t *b, uint32_t n) /* rising zero crossings */
{
uint32_t i;
int c = 0;
for (i = 1; i < n; i++)
c += b[i - 1] < 0 && b[i] >= 0;
return c;
}
static int test_bus(void)
{
int bad = 0;
char what[160];
uint32_t f, i;
{ /* routing: GATE 100 % pattern 13 (.x.x): track 1 in chops, out does not */
int32_t o[2 * CTL];
uint64_t e_in = 0, e_out = 0;
song_setup();
for (i = 1; i < NTRK; i++) trk[i].p[P_LEVEL] = 0;
trk[0].p[P_DLY] = trk[0].p[P_REV] = trk[0].p[P_CHOR] = 0;
set_slicer(&trk[0], SL_GATE, 13, 1, 127);
for (i = 0; i <= NTRK; i++) song.g[G_SLT1 + i] = 0;
transport_req = 1;
for (f = 0; f < 4u * FS; f += CTL) {
mix_block(o, CTL);
if (!sl.bit && sl.pos > SL_RAMP + CTL)
for (i = 0; i < CTL; i++) e_out += (uint64_t)((int64_t)o[2 * i] * o[2 * i]);
}
transport_req = 2;
song_setup();
for (i = 1; i < NTRK; i++) trk[i].p[P_LEVEL] = 0;
trk[0].p[P_DLY] = trk[0].p[P_REV] = trk[0].p[P_CHOR] = 0;
set_slicer(&trk[0], SL_GATE, 13, 1, 127);
for (i = 0; i <= NTRK; i++) song.g[G_SLT1 + i] = (int16_t)(i == 0u);
transport_req = 1;
for (f = 0; f < 4u * FS; f += CTL) {
mix_block(o, CTL);
if (!sl.bit && sl.pos > SL_RAMP + CTL)
for (i = 0; i < CTL; i++) e_in += (uint64_t)((int64_t)o[2 * i] * o[2 * i]);
}
transport_req = 2;
snprintf(what, sizeof what, "bus: T1 out: its closed steps sound (%.0f), T1 in: silent (%.0f)", sqrt((double)e_out), sqrt((double)e_in));
bad += check(what, e_out > 1000000u && e_in * 100u < e_out);
}
{ /* FX ON / OFF: the reverb's tail in the closed steps, cut or ringing */
int32_t o[2 * CTL];
uint64_t e[2] = {0, 0};
uint32_t fx;
for (fx = 0; fx < 2u; fx++) {
song_setup();
for (i = 1; i < NTRK; i++) trk[i].p[P_LEVEL] = 0;
trk[0].p[P_REV] = 127; song.g[G_RSIZE] = 120;
set_slicer(&trk[0], SL_GATE, 7, 1, 127);
for (i = 0; i < NTRK; i++) song.g[G_SLT1 + i] = 1;
song.g[G_SLFX] = (int16_t)fx;
transport_req = 1;
for (f = 0; f < 4u * FS; f += CTL) {
mix_block(o, CTL);
if (!sl.bit && sl.pos > SL_RAMP + CTL)
for (i = 0; i < CTL; i++) e[fx] += (uint64_t)((int64_t)o[2 * i] * o[2 * i]);
}
transport_req = 2;
}
snprintf(what, sizeof what, "bus: FX OFF the reverb rings in the closed steps (%.0f), FX ON cut too (%.0f)", sqrt((double)e[0]), sqrt((double)e[1]));
bad += check(what, e[0] > 100000u && e[1] * 100u < e[0]);
}
{ /* pitch: STUT pattern 7 (x...), the repeats +12: twice the crossings of the live step, the step's length kept */
static int32_t in[2u * 44100u], out0[2u * 44100u], out1[2u * 44100u];
uint32_t len = (uint32_t)FS * 60u / 120u / 4u, p;
int z_live = 0, z0 = 0, z1 = 0, zq = 0;
host_tracks_init();
song.g[G_BPM] = 120; song.g[G_SWING] = 0;
set_slicer(&trk[0], SL_STUT, 7, 1, 127);
song.playing = 0;
for (f = 0; f < sizeof in / sizeof in[0]; f++)
in[f] = (int32_t)(12000.0 * sin(2 * M_PI * 300.0 * f / FS));
for (p = 0; p < 3u; p++) {
int32_t *out = p == 1u ? out1 : out0;
static int32_t outq[2u * 44100u];
if (p == 2u) out = outq;
slicer_reset();
slicer_start();
song.g[G_SLPQ] = 0;
for (i = 0; i < 16u; i++) song.g[G_SLP0 + i] = (int16_t)(p == 1u ? 12 : p == 2u ? 1 : 0);
if (p == 2u) song.g[G_SLPQ] = 1; /* (+1 on C major snaps to 0 or +2: never +1) */
for (i = 0; i < NTRK; i++) trk[i].p[P_SCALE] = 1; /* (MAJ) */
memcpy(out, in, sizeof in);
for (f = 0; f + CTL <= sizeof in / sizeof in[0]; f += CTL)
sl_mono(out + f, CTL);
for (f = 4u * len; f + 4u * len < sizeof in / sizeof in[0]; f += 4u * len) { /* step 2 of each 4 (a repeat) */
if (p == 0u) { z0 += zc(out + f + len + 200u, len - 400u); z_live += zc(in + f + 200u, len - 400u); }
if (p == 1u) z1 += zc(out + f + len + 200u, len - 400u);
if (p == 2u) zq += zc(out + f + len + 200u, len - 400u);
}
}
for (i = 0; i < 16u; i++) song.g[G_SLP0 + i] = 0;
song.g[G_SLPQ] = 1;
snprintf(what, sizeof what, "pitch: the repeats at 0 / +12: %d / %d crossings (live %d): an octave up", z0, z1, z_live);
bad += check(what, abs(z0 - z_live) <= z_live / 10 && abs(z1 - 2 * z0) <= z0 / 6);
snprintf(what, sizeof what, " QNT SCL: +1 snaps to the scale (%d crossings, +1 would be %d)", zq, (int)(z0 * 1.0595));
bad += check(what, abs(zq - z0) <= z0 / 30 || abs(zq - (int)(z0 * 1.1225)) <= z0 / 30);
}
return bad;
}
int main(int argc, char **argv)
{
int bad = 0;
bad += test_clicks();
bad += test_timing();
bad += test_sync();
bad += test_off_stut();
bad += test_bus();
bad += test_cost();
if (argc > 1)
demos(argv[1]);
printf("%s\n", bad ? "SLICER TEST FAILED" : "slicer test passed");
return bad != 0;
}