diff --git a/.github/workflows/voice-user-check.yml b/.github/workflows/voice-user-check.yml index f93dc3de..e520d353 100644 --- a/.github/workflows/voice-user-check.yml +++ b/.github/workflows/voice-user-check.yml @@ -53,6 +53,16 @@ jobs: } - name: Firmware memory and reach checks run: tail -n 20 build/song-check/target.log + - name: DRUM performance and multilingual intentional lyric regression + run: | + set -euo pipefail + cc -O1 -g -w -Wno-implicit-function-declaration -fsanitize=address,bounds -Ibuild/gen -Ifirmware/src tests/drum_voice_extensions_test.c -lm -o build/song-check/drum-voice + ASAN_OPTIONS=detect_leaks=0 UBSAN_OPTIONS=halt_on_error=1 build/song-check/drum-voice | tee build/song-check/drum-voice.log + cc -O1 -w -Wno-implicit-function-declaration -Ibuild/gen -Ifirmware/src tests/drumx_oct_test.c -lm -o build/song-check/classic-octaves + build/song-check/classic-octaves | tee build/song-check/classic-octaves.log + cc -O1 -w -Wno-implicit-function-declaration -Ibuild/gen -Ifirmware/src tests/voice_test.c -lm -o build/song-check/voice-reading + build/song-check/voice-reading | tee build/song-check/voice-reading.log + python3 tests/voice_web_test.py - name: FIT clock, persistence and audio timing run: | set -euo pipefail diff --git a/firmware/src/eng_drum.c b/firmware/src/eng_drum.c index dd83b05a..4332848c 100644 --- a/firmware/src/eng_drum.c +++ b/firmware/src/eng_drum.c @@ -206,7 +206,7 @@ static const char *drum_lane_abbr(const track_t *t, uint32_t l) } /* the lanes step s strikes: its hits, and its notes on their lanes (a NOTE step only) */ -static uint32_t step_lanes_of(const track_t *t, const step_t *s) +static __attribute__((noinline)) uint32_t step_lanes_of(const track_t *t, const step_t *s) { uint32_t m = 0, i; if (s->time != ST_NOTE) @@ -218,7 +218,7 @@ static uint32_t step_lanes_of(const track_t *t, const step_t *s) /* .. and which of them are accented */ static uint32_t step_lanes(const step_t *s) {return step_lanes_of(0,s);} -static uint32_t step_accents_of(const track_t *t,const step_t *s) +static __attribute__((noinline)) uint32_t step_accents_of(const track_t *t,const step_t *s) {return s->flags&SF_ACCENT?step_lanes_of(t,s):s->acc&step_lanes_of(t,s);} static uint32_t step_accents(const step_t *s) { return step_accents_of(0,s); } diff --git a/firmware/src/sing.c b/firmware/src/sing.c index dfe1fc72..181ff02e 100644 --- a/firmware/src/sing.c +++ b/firmware/src/sing.c @@ -826,7 +826,8 @@ static uint32_t sy_gen_word(const track_t *t, sing_t *s, uint32_t lang, uint32_t const char *q=SY_EXT_WORDS[lang-LG_RU]; uint32_t pick=theme*2u+(sy_rnd(&s->rng)&1u); if(theme==TH_ANY) pick=sy_rnd(&s->rng)&15u; - if(lyr>LYR_NW) q="la"; + if(!ly_en_ok) q="la"; + else if(lyr>LYR_NW) q=SCAT_ES[sy_rnd(&s->rng)%NELEM(SCAT_ES)]; else while(pick--) while(*q++); str_cpy(s->w,q,sizeof s->w); s->prem--; diff --git a/firmware/src/sing_ext.c b/firmware/src/sing_ext.c index d15e298d..065b311c 100644 --- a/firmware/src/sing_ext.c +++ b/firmware/src/sing_ext.c @@ -9,14 +9,15 @@ #define LP (1u<<(LG_PT-LG_RU)) #define LG (1u<<(LG_GN-LG_RU)) typedef struct { char s[5]; uint8_t langs,a,b; } sy_rule_t; -static const sy_rule_t SY_RULES[] = { - {"shch",LR,PH_SH,0}, {"sch",LD,PH_SH,0}, {"eau",LF,PH_O,0}, +static const sy_rule_t SY_RULES[] LY_DICT_SEC = { + {"shch",LR,PH_SH,0}, {"sch",LD,PH_SH,0}, {"eau",LF,PH_O,0}, {"oeu",LF,PH_ER,0}, {"zh",LR|LZ,PH_ZH,0}, {"kh",LR,PH_X,0}, {"sh",LR|LZ,PH_SH,0}, {"ch",LR|LZ,PH_CH,0}, {"ch",LD,PH_X,0}, {"ch",LF|LP|LG,PH_SH,0}, {"ts",LR|LD,PH_TS,0}, {"yu",LR,PH_Y,PH_U}, {"ya",LR,PH_Y,PH_A}, {"yo",LR,PH_Y,PH_O}, {"ye",LR,PH_Y,PH_E}, {"ei",LD,PH_A,PH_I}, {"ie",LD,PH_I,0}, {"eu",LD,PH_O,PH_I}, {"ae",LD,PH_EH,0}, {"oe",LD,PH_ER,0}, {"ue",LD,PH_UJ,0}, + {"ei",LF,PH_E,0}, {"eh",LF,PH_EH,0}, {"ou",LF,PH_U,0}, {"eu",LF,PH_ER,0}, {"oi",LF,PH_W,PH_A}, {"gn",LF,PH_NY,0}, {"nh",LP,PH_NY,0}, {"lh",LP,PH_Y,0}, {"ny",LG,PH_NY,0}, {"ng",LZ|LG,PH_NG,0}, @@ -34,6 +35,7 @@ static const sy_rule_t SY_RULES[] = { }; static uint32_t sy_ext(uint32_t lang, const char *w, uint32_t n, uint8_t *tc, uint8_t *tk) { + if(!ly_en_ok) return sy_es_tok(w,n,tc,tk); /* unverified/missing optional bank */ uint32_t i=0,m=0,mask=1u<<(lang-LG_RU); while(ip[P_DKEYMODE]=1; + for(k=35;k<=81;k++) ok &= drum_note_lane(dt,k)==drum_lane(k); + bad+=check("EXT preserves every GM note 35..81",ok); + ok=1; + for(k=0;k<27;k++) { + song.octave=-1;key_dn(k);lanes_b(2); + uint32_t l=k<13?DV_KICK:DV_TOM; + ok &= kb_snd[k][0]==k && drum_kit[3][l].st==(int32_t)k-(k<13?6:19) && !drum_kit[3][l].dm; + key_upk(k);lanes_b(2); + ok &= !kb_on[k] && !dxo_n[3]; + } + bad+=check("EXT -1: 13 chromatic kicks and 14 toms, captured note-offs",ok); + ok=1; + for(k=0;k<12;k++) { + song.octave=-2;key_dn(k);lanes_b(2); + n=drum_fx_note(k);uint32_t l=DX_EXT_FX[k]&7; + ok &= kb_snd[k][0]==n && (drum_kit[3][l].dm>>2)==k+1u; + /* Changing map and octave while held must not lose the release. */ + dt->p[P_DKEYMODE]=0;song.octave=2;key_upk(k);lanes_b(2); + ok &= !kb_on[k]&&!dxo_n[3];dt->p[P_DKEYMODE]=1; + trk_note_on(dt,DRUM_LANE_NOTE[l],100); + ok &= !drum_kit[3][l].dm; + } + bad+=check("EXT -2: per-hit FX captured; ordinary hits restore kit, no stuck key",ok); + /* A hit can start after side_begin: bus contents must not leak from the + * previously rendered track on the same core. */ + dt->p[P_DXIMG]=0;memset(dx_snd,0,sizeof dx_snd); + dx_core_t *dc=&DXC;dc->xon=0; + for(k=0;ksb[2][k]=123456; + trk_note_on(dt,drum_fx_note(0),100); + int32_t g[4],*bus,amt; + ok=drum_side_of(dc,DV_KICK,drum_send(dt,DV_KICK),g,&bus,&amt)&&amt==63&&bus==dc->sb[2]; + for(k=0;kp[P_DKEYMODE]=1;song.octave=1; + key_dn(k);lanes_b(2); + ok &= dxo_n[3]==1 && dxo[3][0].half==2 && dxo[3][0].ph==0; + uint32_t per=div_samples(dt->p[P_SDIV])/4u; + for(p=0;p<64;p++) dxo_tick(dt,per); + ok &= dxo[3][0].ph==0 && dxo[3][0].part==0; + song.octave=0;key_upk(k);lanes_b(2); + ok &= !dxo_n[3]&&!kb_on[k]; + } + bad+=check("EXT fills repeat while held, wrap after one bar, release at changed octave",ok); + drum_setup();dt->p[P_DKEYMODE]=1; + midi_play(dt,0,98,100); + bad+=check("EXT external keyboard starts ratchet sets",dxo_n[3]==1&&dxo[3][0].half==3); + dxo_off(dt,DXO_MIDI+98); + bad+=check("EXT external keyboard releases the performance",!dxo_n[3]); + /* Recording stores the same lane/rate recipe, not virtual control notes. */ + drum_setup();dt->p[P_DKEYMODE]=1;song.rec=1u<<3;seq_start(); + lanes_until(1,step_len(1)/8u);dxo_on(dt,99,0,100,DXO_MIDI+99); + lanes_until(5,step_len(5)/4u);dxo_off(dt,DXO_MIDI+99);seq_stop(); + ok=1;n=0; + for(k=2;k<5;k++) { + const step_t *s=&dt->step[k];n+=s->hit!=0; + for(j=0;jn;j++) ok &= s->note[j]<86; + for(j=0;j<8;j++) ok &= step_lmode(s,j)<=LM_X4; + } + bad+=check("EXT held recording writes actual GM lanes and per-lane ratchets",ok&&n>=2); + /* Lane view and lane editing must agree with the renderer for encoded FX. */ + step_t *s=&dt->step[7];step_clear(s);s->time=ST_NOTE;s->n=1;s->note[0]=drum_fx_note(10);s->vel=100; + ok=step_lanes_of(dt,s)==(1u<engine=t->eng_req;song.sel=0; + lyr_set(0,"hola luna.");t->p[P_VLANG]=LG_ES;t->p[P_VLYR]=LYR_FIXED;t->p[P_E0]=2; + sing[0].pend=1;sing_block(t);sing_t first=sing[0]; + sing[0].pend=1;sing_block(t); + ok=sing[0].wsy==first.wsy&&sing[0].nsy==first.nsy&&!strcmp(sing[0].w,first.w); + bad+=check("VOICE TEXT FIXED: repeated POS really repeats the selected syllable",ok); + t->p[P_E0]=0;sing[0].pend=1;sing_block(t); + bad+=check("VOICE TEXT FIXED: POS 0 advances automatically",sing[0].nsy!=first.nsy); + /* Same word and syllable selected from the real text, including punctuation. */ + lyric_word=31;lyric_syl=1;char label[20];uint32_t pos=lyric_pick(label); + bad+=check("LYRIC STEP clamps selection to the last word past punctuation",pos==3&&!strcmp(label,"luna")); + lyric_word=0;lyric_syl=2;pos=lyric_pick(label); + bad+=check("LYRIC STEP maps a word/syllable to absolute POS",pos==2&&!strcmp(label,"hola")); + ui.home=0;for(i=0;ip[P_VLYR]==LYR_FIXED; + bad+=check("LYRIC STEP places a real POS lock without using either component",ok); + /* Saved project preserves the new choices and locks in the current format. */ + t->p[P_VLANG]=LG_GN;trk[3].p[P_DKEYMODE]=1; + static project_t before,after;static project_store_t blob; + project_capture(&before); + ok=proj_pack(&blob,&before)&&proj_import(&after,&blob,sizeof blob)&& + after.t[0].p[P_VLANG]==LG_GN&&after.t[0].p[P_VLYR]==LYR_FIXED&&after.t[3].p[P_DKEYMODE]==1; + bad+=check("Project round trip preserves languages, fixed lyrics and EXT key map",ok); + return bad; +} +int main(void) +{ + int bad=extensions()+lyrics(); + printf("drum/voice extensions: %s\n",bad?"FAILED":"all ok");return bad!=0; +} diff --git a/tests/drumx_oct_test.c b/tests/drumx_oct_test.c index 103ed0e1..5c0dbdd6 100644 --- a/tests/drumx_oct_test.c +++ b/tests/drumx_oct_test.c @@ -869,6 +869,7 @@ static int rec_ratch(void) return bad; } +#ifndef DRUM_OCT_NO_MAIN int main(void) { int bad = 0; @@ -888,3 +889,5 @@ int main(void) printf("drumx octaves: all ok\n"); return 0; } +#endif + diff --git a/tests/voice_test.c b/tests/voice_test.c index 08d1e21c..1ce90b80 100644 --- a/tests/voice_test.c +++ b/tests/voice_test.c @@ -474,6 +474,7 @@ static void check_reading(void) static const char *const LN[4] = {"", "ES", "EN", "JA"}; uint32_t bad_w = 0, tot = 0; for (l = LG_ES; l <= LG_JA; l++) { + const char *const *ref=l==LG_ES?LY_ES_BANK_REF_W:l==LG_EN?LY_EN_BANK_REF_W:LY_JA_BANK_REF_W; const ly_bank_t *bk = &LY_BANK[l - 1u]; uint32_t nwds = l == LG_ES ? LY_ES_NW : l == LG_EN ? LY_EN_NW : LY_JA_NW; for (k = 0; k < nwds; k++) { @@ -481,6 +482,7 @@ static void check_reading(void) char nw2[24]; char word[20]; const char *w = ly_word(bk, k, word); + bad_w += strcmp(w,ref[k])!=0; /* exact text, not only the syllable count */ (void)sy_word(l, nw2, sy_norm(w, (uint32_t)strlen(w), nw2, sizeof nw2), ph, &n); tot++; if (n != (bk->meta[k] & 15u)) { diff --git a/tests/voice_web_test.py b/tests/voice_web_test.py new file mode 100644 index 00000000..d724a34e --- /dev/null +++ b/tests/voice_web_test.py @@ -0,0 +1,24 @@ +"""Run the editor's real transliterator; never silently drop a native lyric.""" +from pathlib import Path +import re,subprocess +s=Path('web/editor.html').read_text() +a=s.index('function lyricText(') +fn=s[a:s.index('\n}',a)+2] +js="import assert from 'node:assert/strict';\n"+fn+''' +assert.equal(lyricText('Привет мир','RU'),'Privet mir'.toLowerCase()); +assert.equal(lyricText('щёлк','RU'),'shchyolk'); +assert.equal(lyricText('größer','DE'),'groesser'); +assert.equal(lyricText('nǐ hǎo lǜ','ZH'),'ni hao lv'); +assert.equal(lyricText('coração','PT'),'corasa~o'); +assert.equal(lyricText('pytũ ñ','GN'),'pytu~ ny'); +assert.equal(lyricText('été chat','FR'),'eitei chat'); +assert.throws(()=>lyricText('你好','ZH'),/pinyin/); +assert.throws(()=>lyricText('щ'.repeat(16),'RU'),/63/); +assert.equal(lyricText('niño corazón'),'ninyo corazon'); +assert.equal(lyricText('a'.repeat(100)).length,63); // legacy protocol bound +assert.equal(lyricText('a'.repeat(63),'EN').length,63); +console.log('voice web: transliteration, nasal/umlaut markers, UTF rejection and expanded-length bound passed'); +''' +out=Path('build/song-check');out.mkdir(parents=True,exist_ok=True) +(out/'voice-web.mjs').write_text(js) +subprocess.run(['node',str(out/'voice-web.mjs')],check=True) diff --git a/tools/gen_lyrics.py b/tools/gen_lyrics.py index 0b623171..322df855 100644 --- a/tools/gen_lyrics.py +++ b/tools/gen_lyrics.py @@ -503,6 +503,7 @@ def main(): counts = {} for lang in ("es", "en", "ja"): rows = load_bank(lang, nsyl[lang]) + bank_words = [] txt, offs, meta, grp = bytearray(), [], [], [[[0, 0] for _ in CATS] for _ in THEMES] n = 0 for t in range(len(THEMES)): @@ -510,12 +511,16 @@ def main(): r = rows.get((t, c), []) grp[t][c] = [n, len(r)] for w, ns, fem in r: + assert len(w) <= 19, "singer word buffer" + bank_words.append(w) offs.append(len(txt)) txt += w.encode() + b"\0" meta.append(ns | (16 if fem else 0)) n += 1 counts[lang] = n U = lang.upper() + L.append(f"#ifdef LY_EN_REF\nstatic const char *const LY_{U}_BANK_REF_W[] = {{" + + ','.join('"'+w+'"' for w in bank_words) + "};\n#endif") L.append(f"#define LY_{U}_NW {n}u") # Exact alphabet packing: 0 is word terminator, 1..26 a..z. # Sparse offsets remain every 16 words, now measured in bits. @@ -532,7 +537,7 @@ def main(): L.append(f"static const uint16_t LY_{U}_GRP[{len(THEMES)}][{len(CATS)}] = {{\n {rows_c}}};") out.write_text("\n".join(L) + "\n") print(f"lyrics: {len(PHONEMES)} phonemes; English dictionary {len(words)} words, " - f"{len(blob) + 2 * len(idx) + len(tp) + len(tl) + len(th) + nlut} B (Huffman; {plain} B as bytes); " + f"{len(blob) + 2 * len(idx) + len(tp) + len(tl) + len(th) + nlut + 2*len(pairs)} B (Huffman/pairs; {plain} B as bytes); " f"banks ES {counts['es']} EN {counts['en']} JA {counts['ja']} words -> {out}") diff --git a/web/editor.html b/web/editor.html index f11cc598..fc576900 100644 --- a/web/editor.html +++ b/web/editor.html @@ -2685,7 +2685,7 @@ const TEXT = { layout: "(The firmware has a different parameter count; showing a plain list.)", ctlHelp: "Sliders: click, then fine-tune with the wheel or arrow keys (Shift: steps of 10); double-click resets.", lyricT: "Lyric (VOICE WORDS)", - lyricHelp: "The VOICE track's lyric (up to 63 characters). EDIT > WORDS: LANG picks the language (ES / EN / JA, Japanese in romaji), LYRIC TEXT sings this. Each note sings the next syllable; a \"-\" holds the vowel one more note.", + lyricHelp: "VOICE lyrics: up to 63 characters after transliteration. ES, EN, JA (romaji), RU, DE, FR, ZH (pinyin), PT, GN. New languages use approximate phonetic singing rules; Mandarin notes follow your melody. TEXT advances each note; TEXT FIXED repeats POS. A \"-\" holds the vowel one more note.", lyricSend: "Send", lyricLang: "LANG", lyricSrc: "LYRIC", @@ -3133,6 +3133,7 @@ async function lyricRead(d = dev) { if (!lyricShown()) return; const r = parse[CMD.LYRIC](await rq(req.lyric(d.sel || 0))); if (document.activeElement !== $("lyric")) $("lyric").value = r.text; + lyricPreview(); } $("lyricsend").addEventListener("click", () => { if (!lyricShown()) return; @@ -3165,6 +3166,10 @@ function updateBrowser() { const sel = $("engine"); $("lyricbox").hidden = !lyricShown(); if (lyricShown()) { + for (const [id,param] of [["lyrlang",LYR_ID.lang],["lyrsrc",LYR_ID.src]]) { + const max=dev.pdesc[param]?.max; + if (Number.isInteger(max)) for (const option of $(id).options) option.disabled=+option.value>max; + } if (document.activeElement !== $("lyrlang")) $("lyrlang").value = String(Math.max(0, Math.min(9, dev.dump.p[LYR_ID.lang] | 0))); if (document.activeElement !== $("lyrsrc")) $("lyrsrc").value = String(Math.max(0, Math.min(25, dev.dump.p[LYR_ID.src] | 0))); }