mirror of
https://github.com/juanjiant-bit/JIANT.git
synced 2026-12-06 04:44:33 +01:00
web/emu: RESOUND, new sounds for the whole song, its notes kept (studio's RADIO)
(the owner: "a song I like but not its sounds: randomize the presets of every sequence of the song playing, mine or the generator's") - web_gen_resound(seed): every track with a part a new sound by its role (a bass a bass's, the chords a chord's, the drums another kit), out of GEN's own picker (gen_sound, gen_kit, gen_mix, gen_fxs, gen_evolve), asked again till the engine or the preset differs. A GEN draft: its roles and its genre (EXPLORE: EXPLORE's); a project of the player's: the roles by what each track plays (gls_role), the genre a seed's near the song's tempo. The steps, the pattern, the arrangement kept; the four stored parts given the same new sounds (their own LEVEL / PAN kept where they had their own), nothing loaded: the music plays on. One UNDO point (GLO + G4) and web_gen_resound_undo (the parts and the sounds as they were); web_gen_resound_seed (the last seed). - ui_layer.c's own RL_N (1) shadows GEN's after it: the web code uses WEB_RL_N. - tests: web/emu/resound_web_test.c (a GEN song and a player's song: steps kept, sounds new, the parts too, the same seed the same sounds, UNDO, it sounds, it plays on), its CI step. The emulator's alone: felucca.fwsc unchanged (1342370a...). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KMHk6yH4XbP1xxHYKCo9Mh
This commit is contained in:
3 files changed
+252
No files matched your search
@@ -308,6 +308,8 @@ jobs:
|
||||
build/emu/native-check build/emu/native.f32
|
||||
cc -O2 -ffp-contract=off -w -Wno-implicit-function-declaration -Wno-incompatible-pointer-types -Ibuild/gen -Ifirmware/src web/emu/gen_web_test.c -lm -o build/emu/gen-web-test # (studio's RADIO page: web_gen_info / web_gen_cmd)
|
||||
build/emu/gen-web-test
|
||||
cc -O2 -ffp-contract=off -w -Wno-implicit-function-declaration -Wno-incompatible-pointer-types -Ibuild/gen -Ifirmware/src web/emu/resound_web_test.c -lm -o build/emu/resound-web-test # (studio's RADIO page: RESOUND)
|
||||
build/emu/resound-web-test
|
||||
node web/emu/emu_test.mjs build/emu/felucca.wasm build/emu/native.f32
|
||||
sha256sum build/emu/felucca.wasm # (for web/SPLIT_BETA.json emulator_sha256)
|
||||
- uses: actions/upload-artifact@v4
|
||||
|
||||
@@ -589,6 +589,167 @@ static void web_gen_run(void)
|
||||
web_gen_count_piece();
|
||||
}
|
||||
|
||||
/* (the owner, on the RADIO: "a song I like but not its sounds") RESOUND: every track's notes, steps, arrangement and
|
||||
* song kept, new sounds for all of them at once, each by its role (a bass a bass's, the chords a chord's, the drums a
|
||||
* kit), out of GEN's own picker (gen_sound, gen_kit, gen_mix, gen_fxs, gen_evolve) with a seed of its own. A GEN piece
|
||||
* (a draft: its roles and its genre known): that genre's sounds (EXPLORE: EXPLORE's); a project of the player's: the roles
|
||||
* by what each track plays (gls_role, FROM LOOP's), the genre a seed's among those whose tempo is near the song's. The
|
||||
* four parts in proj_slot given the same new sounds (web_rs_part), so the song's next section brings them; nothing
|
||||
* loaded, the music plays on; the staged next section dropped (song_poll stages it again). One UNDO point (GLO + G4:
|
||||
* the playing part) and, from the page, web_gen_resound_undo: the parts and the music's sounds as they were.
|
||||
* web_gen_resound(seed): seed 0..9999; 0 = done, 1 = nothing to resound (no track with a part), 2 = could not pack.
|
||||
* web_gen_resound_seed(): the last seed applied (0xFFFFFFFF: none, or undone).
|
||||
* web_gen_resound_undo(): 0 = back as it was, 1 = nothing to undo (a new piece since, or none).
|
||||
* The emulator's alone: nothing here is in the FM-1's binary. */
|
||||
#define WEB_RL_N (RL_TEX + 1u) /* (gen's RL_N: ui_layer.c, after it, has its own) */
|
||||
static project_store_t web_rs_bk[4]; /* the parts before the last RESOUND */
|
||||
static uint8_t web_rs_ok, web_rs_role[NTRK];
|
||||
static int16_t web_rs_gi; /* the genre's index, -1 EXPLORE */
|
||||
static uint16_t web_rs_seed;
|
||||
static uint32_t web_rs_last = 0xFFFFFFFFu, web_rs_sig;
|
||||
static void web_rs_apply(void) /* the sounds on the tracks playing (gs gp gmut gx gq: the caller's) */
|
||||
{
|
||||
uint32_t i, k, n;
|
||||
memset(&gs, 0, sizeof gs); memset(&gx, 0, sizeof gx); gx.eng = -1;
|
||||
gp.seed = web_rs_seed;
|
||||
for (i = 0; i < GP_N; i++) gp.amt[i] = GA_AUTO;
|
||||
gseed(GS_PICK);
|
||||
if (web_rs_gi < 0) { gx.on = 1; gx_genre(&gmut); gs.gi = NGENRE; }
|
||||
else { gs.gi = (uint8_t)web_rs_gi; gmut = GENRE[gs.gi]; }
|
||||
gs.g = &gmut;
|
||||
gen_pick();
|
||||
gmut.kit = (uint8_t)((gmut.kit + 1u + gr() % (KIT_N - 1u)) % KIT_N); /* (another kit than the genre's) */
|
||||
gs.energy = gp.energy; gs.complex = (uint8_t)(gp.complex ? gp.complex : 50u);
|
||||
for (k = 0; k < WEB_RL_N; k++) gs.trk_of[k] = NTRK;
|
||||
for (k = 0; k < NTRK; k++) {
|
||||
uint32_t r = web_rs_role[k];
|
||||
gs.role[k] = (uint8_t)(r < WEB_RL_N ? r : RL_TEX);
|
||||
if (r >= WEB_RL_N) continue;
|
||||
gs.act[r] = 1;
|
||||
if (gs.trk_of[r] == NTRK) gs.trk_of[r] = (uint8_t)k;
|
||||
}
|
||||
gs.fm6 = 0; gs.ftl = 0;
|
||||
gseed(GS_SOUND);
|
||||
for (n = gr() % NTRK, k = 0; k < NTRK; k++) { /* (gen_make's order: from a throw's own track on) */
|
||||
uint32_t ti = (k + n) % NTRK, r = web_rs_role[ti];
|
||||
track_t *t = &trk[ti];
|
||||
if (ti >= trk_live || r >= WEB_RL_N) continue;
|
||||
if (r == RL_DRUM) { if (drum_track(t)) gen_kit(t); continue; }
|
||||
if (drum_track(t)) continue; /* (a kit's track playing a melody: its kit kept) */
|
||||
{ /* (another sound than the one it had: GEN's picker asked again, up to 8 times, till the engine or the preset
|
||||
* differs; its FM6 count and filter type as before each ask) */
|
||||
uint32_t e0 = t->eng_req, p0 = t->preset, tries;
|
||||
uint8_t fm6 = gs.fm6, ftl = gs.ftl, odd = gx.odd;
|
||||
for (tries = 0; tries < 8u; tries++) {
|
||||
gs.fm6 = fm6; gs.ftl = ftl; gx.odd = odd;
|
||||
if (gx.on) gx.eng = gx_engine(r);
|
||||
gen_sound(t, r, r == RL_BASS ? gmut.snd[GP_BASS] : r == RL_PAD ? gmut.snd[GP_CHORDS] : r == RL_LEAD ? gmut.snd[GP_LEAD] :
|
||||
r == RL_ARP ? gmut.snd[GP_ARP] : gmut.tex);
|
||||
gx.eng = -1;
|
||||
if (gx.on) gx_sound(t, r);
|
||||
if (t->eng_req != e0 || t->preset != p0) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
gseed(GS_MIX);
|
||||
for (k = 0; k < NTRK && k < trk_live; k++)
|
||||
if (web_rs_role[k] < WEB_RL_N) { gen_mix(&trk[k], web_rs_role[k]); gen_fxs(&trk[k], web_rs_role[k]); gen_evolve(&trk[k], web_rs_role[k]); }
|
||||
}
|
||||
/* a stored part's sounds made the new ones (its steps, pattern, mutes kept): every track with a part its engine, preset,
|
||||
* sound parameters (not param_kept's), FM6 patch, GAIN, KEY TRK; LEVEL and PAN the new ones where the part had the old
|
||||
* ones (a part's own mix kept); the DRUM-X kit where a track plays drums */
|
||||
static project_t web_rs_old, web_rs_new;
|
||||
static void web_rs_part(project_t *S, const project_t *N, const project_t *O)
|
||||
{
|
||||
uint32_t k, i, dr = 0;
|
||||
for (k = 0; k < NTRK; k++) {
|
||||
if (web_rs_role[k] >= WEB_RL_N) continue;
|
||||
dr |= web_rs_role[k] == RL_DRUM;
|
||||
for (i = 0; i < P_COUNT; i++)
|
||||
if (!param_kept(i) || ((i == P_LEVEL || i == P_PAN) && S->t[k].p[i] == O->t[k].p[i])) S->t[k].p[i] = N->t[k].p[i];
|
||||
S->t[k].engine = N->t[k].engine; S->t[k].preset = N->t[k].preset;
|
||||
memcpy(S->fm6[k], N->fm6[k], sizeof S->fm6[k]);
|
||||
S->tgain[k] = N->tgain[k]; S->dnz[NTRK + 1u + k] = N->dnz[NTRK + 1u + k];
|
||||
}
|
||||
if (dr) {
|
||||
memcpy(S->dx, N->dx, sizeof S->dx); memcpy(S->dx_mot, N->dx_mot, sizeof S->dx_mot);
|
||||
S->dx_tone = N->dx_tone; S->dx_hands = N->dx_hands;
|
||||
memcpy(S->dx_snd, N->dx_snd, sizeof S->dx_snd); memcpy(S->dx_lay, N->dx_lay, sizeof S->dx_lay);
|
||||
memcpy(S->dx_fml, N->dx_fml, sizeof S->dx_fml);
|
||||
}
|
||||
}
|
||||
static void web_rs_parts(const project_t *N, const project_t *O) /* the four stored parts (an empty one left) */
|
||||
{
|
||||
uint32_t s;
|
||||
for (s = 0; s < 4u; s++) {
|
||||
if (!proj_import(&proj_scratch, &proj_slot[s], sizeof proj_slot[s])) continue;
|
||||
web_rs_part(&proj_scratch, N, O);
|
||||
if (proj_pack(&proj_wire, &proj_scratch)) { memcpy(&proj_slot[s], &proj_wire, sizeof proj_slot[s]); live.dirty |= (uint8_t)(1u << s); }
|
||||
}
|
||||
proj_wire_gen++;
|
||||
fm1_irq_off(); sec_stage.ready = 0; snd_held = snd_seen = 0; fm1_irq_on(); /* (the next section staged with the old
|
||||
* sounds: staged again; no sound held as the player's) */
|
||||
}
|
||||
EXPORT uint32_t web_gen_resound_seed(void) { return web_rs_last; }
|
||||
EXPORT uint32_t web_gen_resound(uint32_t seed)
|
||||
{
|
||||
struct { __typeof__(gp) p; __typeof__(gs) s; ggenre_t g; __typeof__(gx) x; uint32_t q; } save = {gp, gs, gmut, gx, gq};
|
||||
uint32_t k, any = 0, h = seed % 10000u, gen = song_draft && gs.g;
|
||||
if (!bt_hw_seg()) return 1;
|
||||
for (k = 0; k < NTRK; k++) { /* the roles: GEN's own, else by what each track plays */
|
||||
uint32_t r = gen && k < trk_live ? gs.role[k] : k < trk_live ? gls_role(&trk[k]) : WEB_RL_N;
|
||||
if (k < trk_live && drum_track(&trk[k])) r = RL_DRUM;
|
||||
else if (r == RL_DRUM) r = WEB_RL_N; /* (a part GEN gave the drums on a track not DRUM-X's) */
|
||||
web_rs_role[k] = (uint8_t)(r < WEB_RL_N ? r : WEB_RL_N);
|
||||
any |= r < WEB_RL_N;
|
||||
}
|
||||
if (!any) return 1;
|
||||
if (gen) web_rs_gi = (int16_t)(gs.gi < NGENRE ? gs.gi : -1);
|
||||
else { /* (a seed's genre, its tempo near the song's: gls_genre's EXPLORE) */
|
||||
uint32_t bpm = (uint32_t)song.g[G_BPM], x = h * 2654435761u + 1u, i, gi = 0;
|
||||
for (i = 0; i < 32u; i++) {
|
||||
x ^= x << 13; x ^= x >> 17; x ^= x << 5;
|
||||
gi = x % NGENRE;
|
||||
if (bpm + 24u >= GENRE[gi].bpm_lo && bpm <= GENRE[gi].bpm_hi + 24u) break;
|
||||
}
|
||||
web_rs_gi = (int16_t)gi;
|
||||
}
|
||||
web_rs_seed = (uint16_t)h;
|
||||
undo_mark(); /* (GLO + G4: the part playing as it was) */
|
||||
project_capture(&web_rs_old);
|
||||
memcpy(web_rs_bk, proj_slot, sizeof proj_slot);
|
||||
web_rs_apply();
|
||||
gp = save.p; gs = save.s; gmut = save.g; gx = save.x; gq = save.q;
|
||||
project_capture(&web_rs_new);
|
||||
web_rs_parts(&web_rs_new, &web_rs_old);
|
||||
web_rs_ok = 1; web_rs_last = h; web_rs_sig = gp.sig;
|
||||
{
|
||||
char b[8];
|
||||
fmt_int(b, (int32_t)h);
|
||||
ui_say("RESOUND #", b);
|
||||
}
|
||||
ui.force = 1;
|
||||
return 0;
|
||||
}
|
||||
EXPORT uint32_t web_gen_resound_undo(void)
|
||||
{
|
||||
uint32_t k;
|
||||
if (!web_rs_ok || gp.sig != web_rs_sig) return 1;
|
||||
memcpy(proj_slot, web_rs_bk, sizeof proj_slot);
|
||||
live.dirty |= 15u; proj_wire_gen++;
|
||||
for (k = 0; k < NTRK && k < trk_live; k++) { /* the music playing: each track's sound as it was, it plays on */
|
||||
if (web_rs_role[k] >= WEB_RL_N) continue;
|
||||
sound_put(&web_rs_old, k);
|
||||
trk[k].p[P_LEVEL] = web_rs_old.t[k].p[P_LEVEL]; trk[k].p[P_PAN] = web_rs_old.t[k].p[P_PAN];
|
||||
trk_gain[k] = web_rs_old.tgain[k] > 12u ? 12 : web_rs_old.tgain[k];
|
||||
kt_v[k] = web_rs_old.dnz[NTRK + 1u + k] & 3u;
|
||||
}
|
||||
fm1_irq_off(); sec_stage.ready = 0; snd_held = snd_seen = 0; fm1_irq_on();
|
||||
web_rs_ok = 0; web_rs_last = 0xFFFFFFFFu;
|
||||
ui_message("SOUNDS BACK"); ui.force = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* for the test and the bench (web/emu/emu_test.mjs), a heavy song straight into the tracks (as hostsim's
|
||||
* renders set them): T1 FM6 PAD, T2 TRIO (its first preset; PHYS, retired in TONIC, was here), T3 VOICE CHOIR AAH (GRAIN, retired in JIANT, was here), 4-note chords on all 16
|
||||
* steps, held; T4 DRUM, kick snare and hats. PLAY is the page's (or the test's) to press */
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-only
|
||||
* Copyright (C) 2026 Juan Ignacio Antonucci (Juan Jiant) */
|
||||
/* (studio's RADIO page) web_gen_resound / web_gen_resound_undo on the native build of the emulator's glue: a GEN
|
||||
* song and a project of the player's get new sounds, every track's steps and the stored parts' steps kept, the parts'
|
||||
* sounds the same new ones, the same seed the same sounds, UNDO the sounds back, it still sounds */
|
||||
#include "felucca_web.c"
|
||||
static int bad;
|
||||
static void ck(const char *what, int ok) { printf("%-64s %s\n", what, ok ? "ok" : "FAIL"); bad += !ok; }
|
||||
static float peak;
|
||||
static void run(uint32_t blocks)
|
||||
{
|
||||
while (blocks--) {
|
||||
uint32_t i;
|
||||
web_render(512);
|
||||
for (i = 0; i < 512u; i++) if (out_l[i] > peak) peak = out_l[i]; else if (-out_l[i] > peak) peak = -out_l[i];
|
||||
}
|
||||
}
|
||||
static uint32_t snd_of(const track_t *t) /* a track's sound: its engine, preset, its sound's parameters */
|
||||
{
|
||||
uint32_t h = t->eng_req * 131u + t->preset, i;
|
||||
for (i = 0; i < P_COUNT; i++) if (!param_kept(i)) h = h * 31u + (uint16_t)t->p[i];
|
||||
return h;
|
||||
}
|
||||
static uint32_t snd_all(void) { uint32_t h = 7, k; for (k = 0; k < trk_live; k++) h = h * 1000003u + snd_of(&trk[k]); return h; }
|
||||
static uint32_t steps_all(void) { uint32_t h = 7, k; for (k = 0; k < trk_live; k++) h = h * 1000003u + steps_sig(&trk[k]); return h; }
|
||||
static uint32_t slot_steps(uint32_t s, uint32_t *snd) /* a stored part's steps (and its sounds) */
|
||||
{
|
||||
uint32_t h = 7, k, i;
|
||||
*snd = 0;
|
||||
if (!proj_import(&proj_scratch, &proj_slot[s], sizeof proj_slot[s])) return 0;
|
||||
for (k = 0; k < NTRK; k++) {
|
||||
for (i = 0; i < NSTEP; i++) h = h * 31u + proj_scratch.t[k].step[i].time * 7u + proj_scratch.t[k].step[i].note[0];
|
||||
*snd = *snd * 31u + proj_scratch.t[k].engine * 131u + proj_scratch.t[k].preset + (uint16_t)proj_scratch.t[k].p[P_E0];
|
||||
}
|
||||
return h;
|
||||
}
|
||||
int main(void)
|
||||
{
|
||||
uint32_t st0, sn0, sn1, sn2, s, used = 0, kept = 0, moved = 0, ss[4], sv[4], v;
|
||||
web_nor_erase();
|
||||
web_boot();
|
||||
run(40);
|
||||
web_gen(1u + 3u, 1791, 60, 2); /* a SONG of the fourth genre */
|
||||
run(8);
|
||||
st0 = steps_all(); sn0 = snd_all();
|
||||
for (s = 0; s < 4u; s++) ss[s] = slot_steps(s, &sv[s]);
|
||||
ck("a GEN song: a draft, its parts stored", song_draft && ss[0]);
|
||||
ck("RESOUND 1234: done", web_gen_resound(1234) == 0);
|
||||
ck(" the steps as they were", steps_all() == st0);
|
||||
sn1 = snd_all();
|
||||
ck(" the sounds new", sn1 != sn0);
|
||||
for (s = 0; s < 4u; s++) {
|
||||
uint32_t h = slot_steps(s, &v);
|
||||
if (!ss[s]) continue;
|
||||
used++; kept += h == ss[s]; moved += v != sv[s];
|
||||
}
|
||||
printf(" parts stored %u, their steps kept %u, their sounds new %u\n", used, kept, moved);
|
||||
ck(" every stored part's steps kept, their sounds new", used && kept == used && moved == used);
|
||||
ck(" the seed reported", web_gen_resound_seed() == 1234u);
|
||||
peak = 0; web_gen_cmd(4, 1); run(200);
|
||||
ck(" it sounds (playing)", peak > 0.01f && web_gen_info()[7] == 1);
|
||||
web_gen_cmd(4, 0); run(30);
|
||||
ck("UNDO: the sounds back", web_gen_resound_undo() == 0 && snd_all() == sn0 && steps_all() == st0);
|
||||
ck(" the parts' sounds back", slot_steps(0, &v) == ss[0] && v == sv[0]);
|
||||
ck(" undo again: nothing", web_gen_resound_undo() == 1 && web_gen_resound_seed() == 0xFFFFFFFFu);
|
||||
web_gen_resound(1234);
|
||||
sn2 = snd_all();
|
||||
ck("the same seed again: the same sounds", sn2 == sn1);
|
||||
web_gen_resound_undo();
|
||||
web_gen_resound(4321);
|
||||
ck("another seed: other sounds", snd_all() != sn1 && steps_all() == st0);
|
||||
web_gen_cmd(4, 1); run(20);
|
||||
ck("RESOUND while it plays: it plays on", web_gen_resound(99) == 0 && (run(20), web_gen_info()[7] == 1));
|
||||
web_gen_cmd(4, 0); run(30);
|
||||
/* a project of the player's: the heavy song (FM6 PAD, TRIO, VOICE chords, DRUM), no draft */
|
||||
web_nor_erase();
|
||||
web_boot();
|
||||
run(20);
|
||||
web_test_heavy();
|
||||
run(4);
|
||||
st0 = steps_all(); sn0 = snd_all();
|
||||
song_draft = 0; /* (the native build's statics outlive web_boot: a project loaded ends it) */
|
||||
ck("the player's song (no draft): RESOUND 77 done", !song_draft && web_gen_resound(77) == 0);
|
||||
ck(" its steps as they were, its sounds new", steps_all() == st0 && snd_all() != sn0);
|
||||
peak = 0; web_gen_cmd(4, 1); run(200);
|
||||
ck(" it sounds", peak > 0.01f);
|
||||
printf(bad ? "resound-web: %d FAILED\n" : "resound-web: all ok\n", bad);
|
||||
return bad != 0;
|
||||
}
|
||||
Reference in new issue
Block a user