SLOOP 2.8.4: the bug-fix release. Clean fades (the mix rounded to the nearest, no more distortion at the end of notes on 3.5 mm and USB); UNISON no longer stacks its voices in phase (every engine); PHYS strings in tune; NOISE's NZ ARCADE, SAMPLE and GRAIN follow the top keys, GRAIN no longer starved by a released note; a firm press on a layer button opens its pages (up to 1 s); on REC READY a knob changes only its own value; the SONG screen's confirmations always ask again; MIDI Bank Select 8 + Program Change shows the right message; a user kit's root and a project's velocities bounded; the way back to the official firmware with M-VAVE's V16. New tests for each (the editor's protocol fuzzed under ASan + UBSan)

This commit is contained in:
isod89 committed 2026-10-29 20:34:46 -04:00
1 parent 5eb24c1dc1
commit 91f30182d9
49 files changed
+3199 -266

No files matched your search

+1 -1
View File
@@ -225,6 +225,6 @@ Dans l'éditeur, onglet **Song & sections** → **Backup** : **Save a backup** e
- **Secours USB :** maintiens **OCT−** seul à l'allumage (*SLOOP USB RESCUE*), puis réinstalle.
- **Installation interrompue :** le FM-1 reste en mode mise à jour ; relance INSTALL et il termine. Un paquet abîmé est refusé et le FM-1 attend un paquet correct.
- **Retour au firmware officiel :** sur la page d'installation, ouvre **Return to the official firmware (V15)** : fais d'abord une sauvegarde avec l'éditeur, télécharge FM-1 V15 sur m-vave.com, choisis son fichier FM-1.fwsc (seul ce fichier exact est accepté) et installe-le. M-UPGRADE de M-VAVE marche aussi (ferme les autres applis qui utilisent le MIDI).
- **Retour au firmware officiel :** fais d'abord une sauvegarde avec l'éditeur. Puis utilise l'outil de M-VAVE, **M-UPGRADE** (m-vave.com → Downloads → PC Software), avec le firmware officiel de la **FM-1** (PC Firmware → FM-1, **V16**, `FM-1.fwsc`) ; ferme les autres applis qui utilisent le MIDI. Si M-UPGRADE ne trouve pas la FM-1 (SLOOP se présente à l'ordinateur sous son propre nom, et sur certains systèmes M-UPGRADE ne la liste alors pas) : ouvre la page d'installation de **Clipper** (https://isod89.github.io/clipper-fm1/webapp/installer/) et utilise son **Return to the official firmware** (ça marche avec SLOOP sur la FM-1 : pas besoin d'installer Clipper) avec ce `FM-1.fwsc` (V16 ou V15 ; le fichier est vérifié avant toute écriture). Pour revenir à SLOOP, réinstalle-le et restaure ta sauvegarde.
SLOOP est libre (GPL-3.0), basé sur Felucca de Leo Kuroshita (Hügelton Instruments). M-VAVE et FM-1 sont des marques de leurs propriétaires ; SLOOP n'y est pas affilié.
+2 -2
View File
@@ -1,6 +1,6 @@
<p align="center"><img src="assets/logo/sloop-logo.png" alt="SLOOP" width="420"></p>
# SLOOP 2.8.3 — The Complete Guide
# SLOOP 2.8.4 — The Complete Guide
Everything SLOOP does, every button, every combination, every page, in one place. This guide is written to be read from the top the first time, then used as a reference: the [cheat sheet](#26-cheat-sheet) at the end has every combination on one page.
@@ -1260,7 +1260,7 @@ A 2.4 backup restores into 2.4 (or later) only. **Save a backup before every upd
### Going back to the official firmware
**(2.8)** The in-browser return-to-stock was removed, because it was not reliable on every system. To go back to the official firmware, use **M-VAVE's own updater, M-UPGRADE** (m-vave.com → Downloads → PC Software → M-UPGRADE) with the official **FM-1 V15** firmware (PC Firmware → FM-1 V15); close every other app that uses MIDI first. Save a backup with the editor before you go. To come back, install SLOOP again and restore your backup.
**(2.8)** The in-browser return-to-stock was removed, because it was not reliable on every system. To go back to the official firmware, use **M-VAVE's own updater, M-UPGRADE** (m-vave.com → Downloads → PC Software → M-UPGRADE) with the official **FM-1** firmware (PC Firmware → FM-1, **V16**, `FM-1.fwsc`); close every other app that uses MIDI first. If M-UPGRADE does not find the FM-1 (SLOOP shows up under its own name, and some systems' M-UPGRADE then does not list it): open **Clipper**'s installer page (https://isod89.github.io/clipper-fm1/webapp/installer/) and use its **Return to the official firmware** (it works with SLOOP on the FM-1: no need to install Clipper) with that file (V16 or V15; checked before anything is written). Save a backup with the editor before you go. To come back, install SLOOP again and restore your backup.
If the official firmware comes up with odd settings or a scrambled display, it is reading the settings SLOOP left in the FM-1's memory — nothing is damaged. A factory reset in M-VAVE's own firmware, or M-UPGRADE's full restore, clears it; and installing SLOOP again brings your work back exactly as it was.
+4 -4
View File
@@ -17,7 +17,7 @@ Free and open source (GPL-3.0), based on <a href="https://github.com/hugelton/Fe
SLOOP turns the FM-1 into a four-track groovebox you play live: **three synths and a drum machine** with 16 sounds on the white keys, twelve synthesis engines, 153 sounds, 37 drum kits, your own samples, a song mode you play with your hands, USB audio, MIDI in on the jack and MIDI clock — and now **physical models** (guitars, sitar, bells, hand drums), a **noise** engine, **six-operator FM with DX7 patches**, **parameter locks**, **micro timing**, **fills**, a **quick chain** of sections and the **sequencer to MIDI out**. House, techno, hip-hop, trap, drum & bass, amapiano, synthwave, lo-fi, ambient, chiptune — it does not pick a style for you. No factory patterns, nothing to load: everything you hear, you play.
> **Status:** 2.8.3 (hold a note under others: on a POLY track a note you hold keeps sounding while you record over it and on playback, free take included, it goes on through the notes already there when you overdub, and SEQ → NOTES LEN runs on under later notes — a long bass under a melody; a MONO or LEGATO sound says *MONO: SET VOICE POLY*; no stuck note after a MIDI burst; drums: on a busy beat the kick no longer drops out; a quick button tap no longer flashes its layer page; a sample or slice played again starts with its ATK, no click; the second core: a bad read no longer crashes the FM-1, SLOOP goes on with one core). 2.8.1 (the per-step note sheet, held with OCT+, now shows as a strip along the bottom of the screen instead of a box over the sequencer, so the piano roll and the drum grid stay fully visible; and it reopens on the row you last used, for a quick MOVE). 2.8: a NOTES piano-roll editor for the synth tracks and the same per-step sheet on the drums, the playing section A–D shown on the main screen, resonance on every filter, the FX filter on the drums, drum TUNE on the noise sounds, a settable punch-in fade, steadier MIDI clock in, MIDI Bank Select; fixes: a reliable USB RESCUE, the browser installer finds the FM-1's loader by its handshake, the in-browser return-to-stock removed — use M-UPGRADE. 2.7: two processor cores, fifteen arp modes, KBD HOLD, drum TUNE and DECAY, favourite sounds, looping samples, QUANT off, MIDI 3, your own screen colours; after 2.6's 27 punch-in effects, INSERT and MIDI LEARN. Still a beta: install at your own risk, and please [report](../../issues) what you find. Your projects, presets, samples and settings are kept when you update, and you can go back at any time (see [Going back](#going-back)).
> **Status:** 2.8.4 (fixes: no more distortion at the end of notes, 3.5 mm and USB; UNISON no longer stacks its voices in phase; PHYS strings in tune; NZ ARCADE, SAMPLE and GRAIN follow the top keys; a firm press on a layer button opens its pages; on REC READY a knob changes only its own value; the way back to the official firmware with V16). 2.8.3 (hold a note under others: on a POLY track a note you hold keeps sounding while you record over it and on playback, free take included, it goes on through the notes already there when you overdub, and SEQ → NOTES LEN runs on under later notes — a long bass under a melody; a MONO or LEGATO sound says *MONO: SET VOICE POLY*; no stuck note after a MIDI burst; drums: on a busy beat the kick no longer drops out; a quick button tap no longer flashes its layer page; a sample or slice played again starts with its ATK, no click; the second core: a bad read no longer crashes the FM-1, SLOOP goes on with one core). 2.8.1 (the per-step note sheet, held with OCT+, now shows as a strip along the bottom of the screen instead of a box over the sequencer, so the piano roll and the drum grid stay fully visible; and it reopens on the row you last used, for a quick MOVE). 2.8: a NOTES piano-roll editor for the synth tracks and the same per-step sheet on the drums, the playing section A–D shown on the main screen, resonance on every filter, the FX filter on the drums, drum TUNE on the noise sounds, a settable punch-in fade, steadier MIDI clock in, MIDI Bank Select; fixes: a reliable USB RESCUE, the browser installer finds the FM-1's loader by its handshake, the in-browser return-to-stock removed — use M-UPGRADE. 2.7: two processor cores, fifteen arp modes, KBD HOLD, drum TUNE and DECAY, favourite sounds, looping samples, QUANT off, MIDI 3, your own screen colours; after 2.6's 27 punch-in effects, INSERT and MIDI LEARN. Still a beta: install at your own risk, and please [report](../../issues) what you find. Your projects, presets, samples and settings are kept when you update, and you can go back at any time (see [Going back](#going-back)).
## Contents
@@ -155,7 +155,7 @@ Projects, autosaves and backups from 2.3 load as they are. The full list, and wh
| **Lights for playing in the dark** | HOME menu: **LIGHTS** (every button glows, LOW / MID / HIGH), **KEYS** (the C keys or every white key), **NOTES** (the notes playing light their keys, by @renebohne). |
| **Backup and restore** | The web editor saves everything on the FM-1 in one file — the music in progress, projects, user presets, samples, settings — and puts it all back. |
| **CHOP, any length** | A recording longer than a sample slot (about 7 s) works: keep the chops you want, shorten them, or **Fit to slot**. |
| **Back to the official firmware** | From the installer page, with a backup first: select M-VAVE's FM-1 V15 file and install it. |
| **Back to the official firmware** | A backup first, then M-VAVE's M-UPGRADE with the official FM-1 V16 (or, if it does not find the FM-1, Clipper's installer page: Return to the official firmware, no need to install Clipper). |
| **Steadier** | Knobs that answer every click; no dropped notes over USB MIDI; one voice fades on overload, never the bass or the lead; keys a millisecond faster; no stuck note after a VOICE change; stricter checks of what is read back from flash. |
The full list, and what came in 2.0, 2.1 and 2.2: [SLOOP.md](SLOOP.md#new-in-23). Release notes: [Releases](../../releases).
@@ -289,7 +289,7 @@ Nothing to download or compile. Your projects, user presets, samples and setting
### Going back
- **To an earlier SLOOP:** install the `.fwsc` of its [release](../../releases) (for example [2.3](../../releases/tag/v2.3)). Your samples, user presets and settings stay. **Projects saved by 2.4** (format FUN5: locks, nudges, fills) **do not open in 2.3 or older** — 2.3 sees them as empty, and its autosave can write over the music in progress; a 2.4 backup restores into 2.4 only. **Save a backup before you go back**, and restore it once you are on 2.4 again.
- **To the official firmware:** on the installer page, open **Return to the official firmware (V15)**. Save a backup with the editor first, download FM-1 V15 from m-vave.com and select its `FM-1.fwsc` — only that exact file is accepted. M-VAVE's updater, M-UPGRADE, works too. To come back, install SLOOP again and restore your backup.
- **To the official firmware:** save a backup with the editor first. Then use M-VAVE's own updater, **M-UPGRADE** (m-vave.com → Downloads → PC Software), with the official **FM-1** firmware (PC Firmware → FM-1, **V16**, `FM-1.fwsc`); close every other app that uses MIDI first. If M-UPGRADE does not find the FM-1 (SLOOP shows up on the computer under its own name, and some systems' M-UPGRADE then does not list it): open **Clipper**'s installer page (https://isod89.github.io/clipper-fm1/webapp/installer/) and use its **Return to the official firmware** (it works with SLOOP on the FM-1: no need to install Clipper) with that `FM-1.fwsc` (V16 or V15; the file is checked before anything is written). To come back to SLOOP, install it again and restore your backup.
### Rescue
@@ -510,7 +510,7 @@ Something else? [Open an issue](../../issues): what you did, what you expected,
| Audio | 44.1 kHz, fixed-point DSP; USB audio input (the master output, 16-bit stereo at 44.1 or 48 kHz, class compliant) |
| MIDI | USB class-compliant in / out (the keys, or the sequencer too); TRS MIDI IN (3.5 mm); MIDI clock in (USB or TRS), clock only if you like (IN = CLOCK) |
| Lights | button backlight (3 levels), C keys / white keys, played notes |
| Update | over USB from the browser (SHA-256 and CRC checked), USB rescue, return to the official V15 |
| Update | over USB from the browser (SHA-256 and CRC checked), USB rescue, return to the official firmware (M-UPGRADE, V16) |
## Documentation
+5 -3
View File
@@ -1,12 +1,14 @@
<p align="center"><img src="assets/logo/sloop-logo.png" alt="SLOOP" width="480"></p>
# SLOOP 2.8.3
# SLOOP 2.8.4
**A live groovebox firmware for the M-VAVE FM-1 — for any style.** Four tracks — three synths and a drum machine with 16 sounds on the white keys — twelve synthesis engines (six-operator FM with DX7 patches, and now physical models and noise), 153 sounds, 37 drum kits (808, 909, trap, phonk, house, techno, UK garage, jungle, amapiano, reggaeton, synthwave, chiptune, ambient, jazz…), your own samples, ghost notes and ratchets, parameter locks, micro timing and fills, note repeat, one-key chords, 27 punch-in effects, a vinyl / sidechain / DJ-filter master, and a teenage-engineering-style screen that always shows what your hands can do next. No factory patterns, nothing to load: everything you hear, you play.
SLOOP is free and open source (GPL-3.0), based on [Felucca](https://github.com/hugelton/Felucca) by Leo Kuroshita / Hügelton Instruments.
> **Status:** 2.8.3, running on the FM-1. Still a beta: install at your own risk, and please report what you find (GitHub issues).
> **Status:** 2.8.4, running on the FM-1. Still a beta: install at your own risk, and please report what you find (GitHub issues).
> **2.8.4:** a bug-fix release. no more distortion at the end of notes, 3.5 mm and USB; UNISON no longer stacks its voices in phase; PHYS strings in tune; NZ ARCADE, SAMPLE and GRAIN follow the top keys; a firm press on a layer button opens its pages; on REC READY a knob changes only its own value; the way back to the official firmware with V16.
> **2.8.3:** hold a note under others. On a POLY track, a note you hold while you play others over it keeps sounding while you record and when you play it back, in a free take too (it used to restart and cut out), it goes on through steps that already have notes when you overdub, and in SEQ → NOTES its LEN now runs on under the notes after it (a long bass under a melody) instead of stopping at *NOTE AHEAD*. On a MONO or LEGATO sound (track 1's 808 BOOM), the screen says *MONO: SET VOICE POLY*. MIDI in: a burst too fast to keep no longer leaves a note stuck. A quick tap on a button no longer flashes its layer page: a layer shows after 0.35 s held (0.14 s before), or at once when you use a key or knob. Drums: on a busy beat the kick (and the other hits) no longer drop out: a drum sound hit again takes its own voice before another's, and the kick is taken last. Samples (SAMPLE, SLICE): a sample played again on a voice still sounding (the same chop again on POLY, every note on MONO, LEGATO or UNISON) now starts from silence with its ATK; it used to start at the level the voice had, with a click, and ATK did nothing. The second core: on some FM-1s it can misread a word under heavy USB traffic (a backup over USB); it now checks every job before running it and refuses a wrong one, and SLOOP goes on with one core until the next power-off instead of crashing (a fault on the second core used to leave the crash screen until a power cycle).
@@ -639,6 +641,6 @@ The glow is a short pulse on every scan of the panel (about 900 times a second):
- **USB rescue:** hold **OCT−** alone while switching on (*SLOOP USB RESCUE*), then install again.
- **Interrupted install:** the FM-1 stays in update mode; press Install again and it finishes. A damaged package is refused, and the FM-1 keeps waiting for a good one.
- **Back to the official firmware:** on the installer page, open **Return to the official firmware (V15)**: save a backup with the editor first, download FM-1 V15 from m-vave.com, select its FM-1.fwsc (only that exact file is accepted) and install it. M-VAVE's own updater, M-UPGRADE, works too (close every other app that uses MIDI first). To come back to SLOOP, install it again and restore your backup.
- **Back to the official firmware:** save a backup with the editor first. Then use M-VAVE's own updater, **M-UPGRADE** (m-vave.com → Downloads → PC Software), with the official **FM-1** firmware (PC Firmware → FM-1, **V16**, `FM-1.fwsc`); close every other app that uses MIDI first. If M-UPGRADE does not find the FM-1 (SLOOP shows up on the computer under its own name, and some systems' M-UPGRADE then does not list it): open **Clipper**'s installer page (https://isod89.github.io/clipper-fm1/webapp/installer/) and use its **Return to the official firmware** (it works with SLOOP on the FM-1: no need to install Clipper) with that `FM-1.fwsc` (V16 or V15; the file is checked before anything is written). To come back to SLOOP, install it again and restore your backup.
- **Credits:** SLOOP is based on Felucca by Leo Kuroshita (@kurogedelic), Hügelton Instruments — engines, sequencer, editor and installer. Played-note key lights: @renebohne (pull request #11). The web editor's local audio preview (the firmware's engines in the browser, WebAssembly): @ordenador, Mario Faúndez Vidal (pull request #120). The knob acceleration (KNOB ACCEL) and the LEVEL / PAN glide in 2.7: after JIANT FM by juanjiant-bit. MIDI CC 74 on each engine's cutoff in 2.7: after @renebohne (pull request #71). The second core and 38 KB of RAM in 2.7: andrerezemini (pull request #111), on the dual-core start of Charles Vestal (X0X) and keremimo (Melodee). TRS MIDI input buffer fix: Felucca [Salt] by ChanceTheMaker, found by keremimo. Knob reading, MIDI input, overload shedding, LED glow, key debounce, MIDI clock, the USB audio input and the return to the official firmware after Felucca 1.0 / 1.0.1. INSERT, LFO SYNC / TRIG / POL, ENV SYNC, the ANALOG filter types, note LEN, MIDI LEARN and the latched-arp fix (#191) after Felucca 1.4 / 1.4.1 / 1.5; the live drum mutes after Felucca 1.4.1; Program Change (@renebohne, Felucca PR #179), the 1/4D delay and the REV / ECHO THROW after Felucca 1.5.1; in 2.7 the arp modes REPEAT, DNUP, UP+8, CONV, DIVG, PINKY, THUMB, WALK and CHORD after Felucca 1.5.1. These Felucca features were first asked for by Wulgaren, etyrnal, benjaminguerrer, gospodindilly-ops, Armstrong1980, oMauNaProducer, lostfictions and planist79 (Felucca discussions #78, #104, #154, #170, #173, #175, #177, #178; issue #191). And thanks to everyone who commented, tested and reported on SLOOP: most of 2.6 comes from you. Font: Terminus and Terminus Bold (SIL OFL 1.1). Samples: Versilian Studios VSCO-2 CE and VCSL, Sonic Pi (all CC0). PHASE: CrispyZebra (GPL). FM6: msfa from Dexed by Google Inc. and Pascal Gauthier (Apache-2.0), ported to integer C for Felucca 1.0 by Leo Kuroshita. VOICE after klattsch (MIT). Interface ideas after teenage engineering's pocket operators and EP-133, Elektron's step entry and Akai's MPC (swing, note repeat, erase) — SLOOP is not affiliated with any of them.
- **Licence:** GPL-3.0, no warranty. M-VAVE and FM-1 are trademarks of their owners; SLOOP is not affiliated with them. Drum kit names describe styles; they do not refer to any product.
+3 -3
View File
@@ -1,17 +1,17 @@
# SLOOP 2.8.3: build the firmware, then open the browser installer.
# SLOOP 2.8.4: build the firmware, then open the browser installer.
# Uses the dependencies already prepared (WSL MinUI-Build, JieLi toolchain, SDK files in build/deps/ac79).
# SLICE stays out (FELUCCA_SLICE=0): with its built-in BREAK the image does not fit the app slot.
$ErrorActionPreference = 'Stop'
Set-Location $PSScriptRoot
Write-Host ""
Write-Host " S L O O P 2.8.3" -ForegroundColor White
Write-Host " S L O O P 2.8.4" -ForegroundColor White
Write-Host " ---- ---- ---- ----" -ForegroundColor DarkGray
Write-Host "== Building the firmware (WSL MinUI-Build)" -ForegroundColor Cyan
Remove-Item Env:FELUCCA_SLICE -ErrorAction SilentlyContinue
python tools/build_windows.py --distro MinUI-Build --toolchain /root/fm1-codex-deps/jieli/toolchain --sdk build/deps/ac79 --slice 0
if ($LASTEXITCODE -ne 0) { throw "The build failed" }
Write-Host "== Making the installer site" -ForegroundColor Cyan
python web/make_site.py build/felucca.fwsc 2.8.3 build/sloop-site
python web/make_site.py build/felucca.fwsc 2.8.4 build/sloop-site
if ($LASTEXITCODE -ne 0) { throw "make_site failed" }
Write-Host ""
Write-Host "Installer: http://localhost:8766/webapp/installer/ (Chrome or Edge, FM-1 on USB)" -ForegroundColor Green
Binary file not shown.
Binary file not shown.
+1 -1
View File
@@ -890,7 +890,7 @@
<button id="connect" class="pri" data-t="connect" data-ic="port_usb_c"></button>
<div class="links"><a class="dim" href="../installer/" data-t="installer"></a><button class="lang" id="lang"></button></div>
<button id="install" class="pri" data-t="install" hidden></button>
<!--DL--><a class="dim" id="offline" href="sloop-editor.html" download="sloop-editor-2.8.3.html" data-t="offline"></a><!--/DL-->
<!--DL--><a class="dim" id="offline" href="sloop-editor.html" download="sloop-editor-2.8.4.html" data-t="offline"></a><!--/DL-->
</div>
</aside>
Binary file not shown.
+6 -6
View File
@@ -90,7 +90,7 @@
<p id="status"></p>
<pre id="log"></pre>
<a class="ed" href="../editor/" data-t="editor"></a>
<p class="small"><a href="../editor/sloop-editor.html" download="sloop-editor-2.8.3.html" data-t="edOffline"></a></p>
<p class="small"><a href="../editor/sloop-editor.html" download="sloop-editor-2.8.4.html" data-t="edOffline"></a></p>
<p><button id="app" class="ed" hidden data-t="appInstall"></button></p>
<hr>
<p class="small" data-t="direct"></p>
@@ -442,7 +442,7 @@ const TEXT = {
direct: "USB ケーブルはパソコンに直接つないでください。Probe や Transporter などの機材は不要です。",
brick: "万一インストールに失敗して起動しなくなった場合は、復旧に Transporter が必要です:",
beta: "これはベータ版で、不安定な場合があります。このカスタムファームウェアを使ったことで FM-1 が壊れたり不具合が起きたりしても、作者は一切の責任を負いません。自己責任でお使いください。",
back: "公式ファームウェアに戻すには、M-VAVE 公式のアップデーター M-UPGRADE(Downloads → PC Software → M-UPGRADE)と公式ファームウェア(PC Firmware → FM-1 V15)が必要です。",
back: "公式ファームウェアに戻すには、M-VAVE 公式のアップデーター M-UPGRADE(Downloads → PC Software → M-UPGRADE)と公式ファームウェア(PC Firmware → FM-1、V16)が必要です。",
nomidi: "このブラウザでは使えません。Chrome か Edge で開いてください。", loadfail: "読み込めませんでした: ",
start: "開始します", verify: "確認中", loader: "書き込みモードに切り替え中", write: "書き込み中",
reboot: "再起動中", done: "完了しました", stopped: "途中で止まりました。USB を挿し直してもう一度押してください。",
@@ -466,7 +466,7 @@ const TEXT = {
stockValid: "公式 V15 を確認しました", stockBad: "公式 V15 ではありません: ",
stockConfirm: "FM-1 に公式 V15 をインストールします。SLOOP の曲は公式ファームウェアでは開けません。バックアップは保存しましたか?",
stockFinish: "FM-1 は SLOOP の書き込みモードです。先に「インストール」で SLOOP の書き込みを終えてから、公式 V15 に戻してください。",
back: "公式ファームウェアに戻すには、M-VAVE 公式のアップデーター M-UPGRADE(Downloads → PC Software → M-UPGRADE)と公式ファームウェアを使ってください。FM-1 が見つからない場合は、MIDI を使う他のアプリとブラウザのタブを閉じてください。",
back: "公式ファームウェアに戻すには、M-VAVE 公式のアップデーター M-UPGRADE(Downloads → PC Software → M-UPGRADE)と公式ファームウェアを使ってください。FM-1 が見つからない場合は、MIDI を使う他のアプリとブラウザのタブを閉じてください。それでも見つからない場合は、Clipper のインストールページを開き、その「Return to the official firmware」を使ってください(Clipper を入れる必要はありません)。",
},
en: {
intro: "Connect the FM-1 by USB. (Works in Chrome or Edge.)",
@@ -478,7 +478,7 @@ const TEXT = {
direct: "Connect the USB cable directly to the computer. No probe or Transporter is needed.",
brick: "If an install fails and the FM-1 no longer starts, recovering it needs a Transporter:",
beta: "This is a beta and may be unstable. The author accepts no responsibility if your FM-1 is damaged or misbehaves because of this custom firmware. Use it at your own risk.",
back: "To go back to the official firmware you need M-VAVE's official updater, M-UPGRADE (Downloads → PC Software → M-UPGRADE), and the official firmware (PC Firmware → FM-1 V15).",
back: "To go back to the official firmware you need M-VAVE's official updater, M-UPGRADE (Downloads → PC Software → M-UPGRADE), and the official firmware (PC Firmware → FM-1, V16).",
nomidi: "This browser cannot do it. Open the page in Chrome or Edge.", loadfail: "Could not load: ",
start: "Starting", verify: "Verifying", loader: "Switching to update mode", write: "Writing",
reboot: "Restarting", done: "Done", stopped: "Stopped. Replug the USB cable and press Install again.",
@@ -502,7 +502,7 @@ const TEXT = {
stockValid: "Official V15 verified", stockBad: "Not the official V15: ",
stockConfirm: "Install the official V15 on the FM-1? The official firmware cannot open SLOOP's music. Did you save a backup?",
stockFinish: "The FM-1 is in SLOOP's update mode. Press Install to finish the SLOOP update first, then return to the official V15.",
back: "To return to the official firmware, use M-VAVE's own updater, M-UPGRADE (Downloads → PC Software → M-UPGRADE), with the official firmware from M-VAVE. If it does not find the FM-1, close every other app and browser tab that uses MIDI.",
back: "To return to the official firmware, use M-VAVE's own updater, M-UPGRADE (Downloads → PC Software → M-UPGRADE), with the official firmware from M-VAVE (PC Firmware → FM-1, V16). If it does not find the FM-1, close every other app and browser tab that uses MIDI; if it still does not, open Clipper's installer page and use its Return to the official firmware (no need to install Clipper).",
},
};
let lang = (navigator.language || "en").toLowerCase().startsWith("ja") ? "ja" : "en";
@@ -536,7 +536,7 @@ const sayK = (k, arg = "") => { lastKey = k; lastArg = arg; $("status").textCont
const say = (txt) => { lastKey = null; $("status").textContent = txt; };
const log = (t) => { $("log").textContent += t + "\n"; };
let image = null;
const meta = {"version": "2.8.3", "product": "FM-1_900", "pkg": "../../firmware/sloop-2.8.3.fwsc", "sha256": "5444afd3c69c409352e1aed35a56205f13f11e60790de146593c4618a43f3528"};
const meta = {"version": "2.8.4", "product": "FM-1_900", "pkg": "../../firmware/sloop-2.8.4.fwsc", "sha256": "5a6a0843c868650dba6718cf85e43e719aec18c3dc5cc803c57c38b382158d4e"};
let writing = false;
const lockAll = (on) => {
+2 -2
View File
@@ -4,9 +4,9 @@
// https, so Web MIDI asks as usual (a downloaded file on Android opens as content://, where Chrome refuses MIDI).
// Online the network always wins (the page as published, never an old one); the copy is only the fallback.
// A new site (any file changed) is a new sw.js: the new copy replaces the old one.
const STAMP = "2.8.3-ab5e64e912da"; // version + a hash of the files
const STAMP = "2.8.4-e184aa2f1c74"; // version + a hash of the files
const CACHE = "sloop-site-" + STAMP;
const FILES = ["../firmware/sloop-2.8.3.fwsc", "editor/", "editor/FUKIAI-LICENSE.txt", "editor/fukiai.ttf", "editor/preview-worklet.js", "editor/preview.js", "editor/sloop-preview.wasm", "icon-192.png", "icon-512.png", "icon-maskable-512.png", "installer/", "sloop.webmanifest"]; // relative to this file
const FILES = ["../firmware/sloop-2.8.4.fwsc", "editor/", "editor/FUKIAI-LICENSE.txt", "editor/fukiai.ttf", "editor/preview-worklet.js", "editor/preview.js", "editor/sloop-preview.wasm", "icon-192.png", "icon-512.png", "icon-maskable-512.png", "installer/", "sloop.webmanifest"]; // relative to this file
const KEEP = new Set(FILES.map((f) => new URL(f, self.location).href));
const key = (url) => { // the copy's name of a request: no query, index.html = the folder
+3 -2
View File
@@ -350,7 +350,8 @@ static void drum_on(uint32_t note, uint32_t vel)
{
const smp_zone_t *z = drum_zone_of(v);
v->s[3] = sample_next(z, v, 0);
v->s[5] = (int32_t)((pow2_q16((int32_t)note * 16 - z->root16) >> 8) * (z->rate >> 8));
/* (after 2.8.3) clamped: a user kit zone's root is not checked (a typed root of 300 shifted by 2^20) */
v->s[5] = (int32_t)((pow2_q16(clamp((int32_t)note * 16 - z->root16, -1536, 2047)) >> 8) * (z->rate >> 8));
}
{
uint32_t vi = (uint32_t)(v - drums.v);
@@ -365,7 +366,7 @@ static void drum_on(uint32_t note, uint32_t vel)
shift = shift * 16 + (tw ? drum_tune[ln] * 16 : 0); /* (2.7) TUNE: the sound's semitones */
if (shift) {
const smp_zone_t *z = drum_zone_of(v);
v->s[5] = (int32_t)((pow2_q16((int32_t)note * 16 + shift - z->root16) >> 8) * (z->rate >> 8));
v->s[5] = (int32_t)((pow2_q16(clamp((int32_t)note * 16 + shift - z->root16, -1536, 2047)) >> 8) * (z->rate >> 8));
}
}
}
+7
View File
@@ -12,6 +12,13 @@ static inline int32_t mulq16(int32_t a, uint32_t k)
return (int32_t)(((a >> 16) * (int32_t)k) + (int32_t)(((uint32_t)(a & 0xFFFF) * k) >> 16));
}
static inline int32_t clamp(int32_t v, int32_t lo, int32_t hi) { return v < lo ? lo : v > hi ? hi : v; }
/* x * g / 4096 rounded to the nearest, in 32 bits wherever ((x >> k) * g) >> (12 - k) fits (the same bound): the k low
* bits of x go in apart instead of being dropped. The mix's gains (fx.c: a part's LEVEL, mute / duck, the MASTER, DIST's
* drive) took x >> k first and lost them: a floor to steps of 2^k x the gain (a part's sum to 16 LSB of the output at
* MASTER 4096), signal-correlated distortion that stays as loud while a note fades out (SLOOP Pro #4). k, a constant:
* ~6 ops */
#define MULQ12R(x, g, k) \
((((x) >> (k)) * (g) + ((((x) & ((1 << (k)) - 1)) * (g) + (1 << ((k) - 1))) >> (k)) + (1 << (11 - (k)))) >> (12 - (k)))
/* sine, linearly interpolated between the 1024 table points (plain lookup: THD -55 dB) */
static inline int32_t sine_i(uint32_t ph)
+8
View File
@@ -158,6 +158,14 @@ static const preset_t ANALOG_PRESETS[] = {
{"SINE PAD", {3, 10, 64, 4, 90, 0, 0, 32}, {80, 90, 118, 90}, 0, 0, FX(0, 60, 20, 65)},
};
/* (after Clipper 1.2) UNISON (voice.c unison_spread): both oscillators moved by r (Q32) of a turn of the note,
* each by its share: as if started that much sooner (osc 2 took its phase from ph[0] before the spread: in phase) */
static void analog_spread(track_t *t, voice_t *v, uint32_t r)
{
v->ph[0] += r;
v->ph[1] += uni_turns(r, v->pitch16, t->p[P_E1] * 16 / 100);
}
static const engine_t ENG_ANALOG = {
"ANALOG", {"OSC", "FLT"},
{
+11
View File
@@ -142,6 +142,17 @@ static const preset_t DIGITAL_PRESETS[] = {
{"FM GRAND", {4, 1, 2, 12, 60, 40, 10, 0}, {0, 90, 20, 60}, 0, 0, FX(0, 20, 14, 30)},
};
/* (after Clipper 1.2) UNISON (voice.c unison_spread): the four operators moved together by r (Q32) of a turn of
* the note, each by its ratio's share (phases 0 at each note: every voice in phase) */
static void digital_spread(track_t *t, voice_t *v, uint32_t r)
{
const int16_t *p = t->p;
v->ph[0] += r;
v->ph[1] += (uint32_t)(((uint64_t)r * RATIO_Q8[p[P_E1] % 15]) >> 8);
v->ph[2] += (uint32_t)(((uint64_t)r * RATIO_Q8[p[P_E2] % 15]) >> 8);
v->s[7] = (int32_t)((uint32_t)v->s[7] + (uint32_t)(((uint64_t)r * RATIO_Q8[p[P_E3] % 15]) >> 8));
}
static const engine_t ENG_DIGITAL = {
"DIGITAL", {"OPS", "MOD"},
{
+20
View File
@@ -374,6 +374,26 @@ static const preset_t FM6_PRESETS[] = {
{"NYLON PICK", {0, 0, 0, 0, 0, 0, 0, 7}, {0, 0, 127, 0}, 0, 0, FX(0, 20, 35, 30)},
};
/* (after Clipper 1.2) UNISON (voice.c unison_spread): the six operators moved together by r (Q32) of a turn of
* the note, each by its own frequency's share (fixed ones too): the relative phases, the timbre, kept (phases 0 from
* silence: every voice in phase) */
static void fm6_spread(track_t *t, voice_t *v, uint32_t r)
{
fm6_note_t *nt = fm6_note_of(t, v);
uint32_t tr = (uint32_t)(t - trk), k;
int32_t lf, f0;
if (!nt || tr >= NPART)
return;
lf = fm6_note_logfreq(v->pitch16 + (fm6_eff[tr].p[FP_TRNSP] - 24) * 16, v->fine);
f0 = fm6_freq(lf);
if (f0 <= 0)
return;
for (k = 0; k < 6u; k++) {
int32_t fk = fm6_freq((nt->fixed >> k) & 1u ? nt->base[k] : lf + nt->base[k]); /* Q24 cycles a sample */
nt->op[k].phase = (int32_t)((uint32_t)nt->op[k].phase + (uint32_t)(((uint64_t)(r >> 8) * (uint32_t)fk) / (uint32_t)f0));
}
}
static const engine_t ENG_FM6 = {
"FM6", {"OPS", "PATCH"},
{
+24 -8
View File
@@ -28,8 +28,8 @@
* share of reversed grains (up to 50 %). TONE: a one-pole low-pass (+ the track's FLT
* modulation), as SAMPLE's CUT. A grain is fitted into its zone (shortened if the zone is short).
*
* Cost bound: the grain rate is capped at 2 source samples per output sample (max 2 decodes, 4
* for a reverse grain); a grain only starts while the part's grains decode at most GR_LOAD_MAX
* Cost bound: a grain's rate is capped at GR_LOAD_MAX source samples per output sample (it was 2: the high
* keys of a low-rate source all played one pitch); a grain only starts while the part's grains decode at most GR_LOAD_MAX
* (8) source samples per output sample in all (a reverse grain counts twice); at most one grain
* start per voice and block (<= 255 skipped decodes), one index entry per block. Host count, one
* part, worst settings: ~1050 instructions / sample (~1170 while the PERC index builds), against
@@ -43,8 +43,9 @@
#define GR_NIDX 1024 /* seek index entries per part (PERC: 1001) */
#define GR_MAXZ 32 /* zones per set (PERC has 24, a user slot <= 16) */
#define GR_RB 128 /* reverse window, source samples */
#define GR_STEP_MAX (2u << 16) /* grain rate cap: 2 source samples per output sample */
#define GR_LOAD_MAX (8u << 16) /* decodes per output sample of all a part's grains (a reverse grain counts twice) */
#define GR_STEP_MAX GR_LOAD_MAX /* grain rate cap: as much as the part's load allows (it was 2 source samples an output
* sample: a source went flat 2.5 octaves over its root, LOFI CLOUD above C7) */
/* sin^2(pi i / 256), Q15: the grain window */
static const int16_t GR_HANN[257] = {
@@ -214,6 +215,11 @@ static void gr_fill(const gr_part_t *P, gr_grain_t *g, int16_t *rb, uint32_t zl,
g->rlo = lo;
}
/* (after 2.8.3) a held note's grain refused for the part's load: the released notes start none until one of the
* held notes' grains starts (their grains end on their own): a note played in the release of the note before was
* starved of grains (PNO FREEZE 88 -> 90: -35 dB) while the fading one kept the load */
static uint8_t gr_wait[NPART];
/* start a grain of voice vi (zone zl) */
static void gr_spawn(gr_part_t *P, const track_t *t, uint32_t vi, uint32_t zl, uint32_t iv, const vmod_t *m)
{
@@ -232,10 +238,10 @@ static void gr_spawn(gr_part_t *P, const track_t *t, uint32_t vi, uint32_t zl, u
/* rate: the note against the zone's root, PITCH, the random detune (RAND^2, up to +-1 oct) */
amt = p[P_E6] * p[P_E6] * 192 / (127 * 127);
d16 = m->pitch16 - z->root16 + p[P_E4] * 16 + (((int32_t)(r1 & 0xFFFFu) - 32768) * amt >> 15);
step = (pow2_q16(clamp(d16, -1536, 576)) >> 8) * (z->rate >> 8);
step = (pow2_q16(clamp(d16, -1536, 1536)) >> 8) * (z->rate >> 8);
step = step > GR_STEP_MAX ? GR_STEP_MAX : step < 256u ? 256u : step;
rev = ((r1 >> 16) & 255u) < (uint32_t)p[P_E6]; /* RAND 127: half of them */
span = (len * step) >> 16; /* source samples the grain reads */
span = (uint32_t)(((uint64_t)len * step) >> 16); /* source samples the grain reads */
if (span + 3u > n) { /* a short zone: shorter grain */
span = n - 3u;
len = (span << 8) / (step >> 8);
@@ -256,8 +262,13 @@ static void gr_spawn(gr_part_t *P, const track_t *t, uint32_t vi, uint32_t zl, u
for (i = 0, c = step << rev; i < GR_NG; i++) /* the part's decode load: a cap on the cost */
if (P->g[i].owner)
c += P->g[i].step << P->g[i].rev;
if (c > GR_LOAD_MAX)
if (c > GR_LOAD_MAX) {
if (t->v[vi].gate)
gr_wait[(uint32_t)(t - trk) % NPART] = 1;
return;
}
if (t->v[vi].gate)
gr_wait[(uint32_t)(t - trk) % NPART] = 0;
g->z = z;
g->step = step;
g->frac = 0;
@@ -364,7 +375,7 @@ static void grain_note_on(track_t *t, voice_t *v)
static void grain_block(track_t *t)
{
gr_part_t *P = (gr_part_t *)eng_arena_of(t, ENGI_GRAIN);
uint32_t src = (uint32_t)t->p[P_E0] % SMP_NALL, st = gr_stamp(src), i;
uint32_t src = (uint32_t)t->p[P_E0] % SMP_NALL, st = gr_stamp(src), i, held = 0;
if (!P->rng)
P->rng = 0x2545F491;
if (P->src != src + 1u || P->stamp != st) {
@@ -376,6 +387,10 @@ static void grain_block(track_t *t)
for (i = 0; i < GR_NG; i++)
if (P->g[i].owner && !t->v[(P->g[i].owner - 1u) % NVOICE].active)
P->g[i].owner = 0;
for (i = 0; i < NVOICE; i++)
held |= t->v[i].active && t->v[i].gate;
if (!held && (uint32_t)(t - trk) < NPART)
gr_wait[t - trk] = 0; /* (no note held: none waits) */
gr_build(P, t);
}
@@ -408,7 +423,8 @@ static void grain_render(track_t *t, voice_t *v, int32_t *out, uint32_t n, const
v->s[1] += (int32_t)iv + mulq15((int32_t)iv, j);
if (v->s[1] < 0)
v->s[1] = 0;
if (mine < (nact > 1u ? (GR_NG / nact > 2u ? GR_NG / nact : 2u) : GR_NG))
if (mine < (nact > 1u ? (GR_NG / nact > 2u ? GR_NG / nact : 2u) : GR_NG) &&
(v->gate || !gr_wait[(uint32_t)(t - trk) % NPART]))
gr_spawn(P, t, vi, (uint32_t)zl, iv, m);
}
lp = 4000 + ((clamp((p[P_E7] << 8) + m->cutoff, 0, 127 << 8) * 28767) >> 15);
+11
View File
@@ -215,6 +215,17 @@ static const preset_t LOFI_PRESETS[] = {
{"CHIP NOISE", {2, 3, 64, 0, 90, 0, 0, 127}, {0, 55, 0, 24}, 0, 0, FX(0, 0, 10, 10)},
};
/* (after Clipper 1.2) UNISON (voice.c unison_spread): the oscillator moved by r (Q32) of a turn of the note and
* the noise register from its own place (every note's from 0x7FFF: every voice the same noise) */
static void lofi_spread(track_t *t, voice_t *v, uint32_t r)
{
(void)t;
v->ph[0] += r;
v->s[2] = (int32_t)(((uint32_t)v->s[2] ^ (r >> 17)) & 0x7FFFu);
if (!v->s[2])
v->s[2] = 1;
}
static const engine_t ENG_LOFI = {
"LOFI", {"CHIP", "MOTN"},
{
+34 -7
View File
@@ -63,6 +63,20 @@ static uint32_t noise_inc(int32_t p)
inc = pitch_inc((uint32_t)clamp(p, 0, 2047));
return sh && inc >= 0x80000000u >> (sh - 1u) ? 0xFFFFFFFFu : inc << sh;
}
/* (after 2.8.3) the same, unbounded (Q32: 2^32 = one clock a sample). LFSR: a clock past the sample rate steps the
* register more than once a sample (the sequence read further on, as the register would be at that time): its pitch
* goes on rising with the keys. It used to stop at one step a sample, so every note above it played the same pitch
* (NZ ARCADE: TONE +84 semitones, the whole upper half of the keyboard; clipper-fm1 #10) */
static uint64_t noise_inc64(int32_t p)
{
uint32_t sh = 0;
while (p > 2047) {
p -= 192;
sh++;
}
return (uint64_t)pitch_inc((uint32_t)clamp(p, 0, 2047)) << (sh < 20u ? sh : 20u);
}
#define NZ_STEPS_MAX 64u /* register steps a sample at most (64 x 44.1 kHz) */
static uint32_t isqrt32(uint32_t x)
{
@@ -103,6 +117,7 @@ static void noise_render(track_t *t, voice_t *v, int32_t *out, uint32_t n, const
uint32_t ph = v->ph[0], reg = v->ph[1]; /* state in locals: out[] may alias v->s[] */
int32_t drift = (int32_t)v->ph[2], d16 = 0, gain = 32767, gq, colr, cut, k, a1, a2, a3, g, bpg, mix, cf, thr = 0;
uint32_t inc = 0, taps = NOISE_TAPS[sel];
uint64_t inc64 = 0; /* (after 2.8.3) LFSR: its clock, Q32, past the sample rate too */
/* drift: a new random target every 0.7..3 s, followed with a 0.7 s lag */
if (drft) {
int32_t tg = v->s[3] >> 16, cnt = v->s[3] & 0xFFFF;
@@ -149,7 +164,7 @@ static void noise_render(track_t *t, voice_t *v, int32_t *out, uint32_t n, const
}
if (mode == NZ_LFSR) {
uint32_t mask = taps; /* the register's own bits (MODE / LEN changes) */
inc = noise_inc(m->pitch16 + p[P_E7] * 16 + d16);
inc64 = noise_inc64(m->pitch16 + p[P_E7] * 16 + d16);
mask |= mask >> 1;
mask |= mask >> 2;
mask |= mask >> 4;
@@ -175,9 +190,10 @@ static void noise_render(track_t *t, voice_t *v, int32_t *out, uint32_t n, const
break;
}
case NZ_LFSR: {
uint32_t o = ph;
ph += inc;
if (ph < o)
uint64_t a = (uint64_t)ph + inc64;
uint32_t ns = (uint32_t)(a >> 32) < NZ_STEPS_MAX ? (uint32_t)(a >> 32) : NZ_STEPS_MAX;
ph = (uint32_t)a;
while (ns--) /* (after 2.8.3: as many steps as clocks in this sample) */
reg = (reg >> 1) ^ (-(reg & 1u) & taps);
w = (reg & 1u) ? 12000 : -12000;
break;
@@ -192,14 +208,14 @@ static void noise_render(track_t *t, voice_t *v, int32_t *out, uint32_t n, const
x = w;
if (colr) { /* pink: three leaky poles (Kellet), brown: a leaky integrator */
int32_t pk;
b0 = ((b0 * 32690) >> 15) + ((w * 3245) >> 15);
b1 = ((b1 * 31555) >> 15) + ((w * 9716) >> 15);
b0 = clamp(((b0 * 32690) >> 15) + ((w * 3245) >> 15), -65535, 65535); /* (after 2.8.3: bounded: a held */
b1 = clamp(((b1 * 31555) >> 15) + ((w * 9716) >> 15), -65535, 65535); /* LFSR level grew them past 2^31 / 32690) */
b2 = ((b2 * 18678) >> 15) + ((w * 17247) >> 14);
pk = (b0 + b1 + b2 + ((w * 6055) >> 15)) >> 2;
if (colr <= (64 << 8)) {
x = w + mulq15(pk - w, cf);
} else {
br = ((br * 32580) >> 15) + ((w * 3480) >> 15);
br = clamp(((br * 32580) >> 15) + ((w * 3480) >> 15), -65535, 65535);
x = pk + mulq15(br - pk, cf);
}
}
@@ -256,6 +272,17 @@ static const preset_t NOISE_PRESETS[] = {
{"RADIO", {NZ_LFSR, 20, 70, 90, 64, 0, 60, 48}, {10, 70, 120, 50}, 0, 0, FX(0, 10, 30, 40)},
};
/* (after Clipper 1.2) UNISON (voice.c unison_spread): the phase moved by r (Q32) and the noise from its own
* seed (the note's: every voice the same noise at DTUNE 0) */
static void noise_spread(track_t *t, voice_t *v, uint32_t r)
{
(void)t;
v->ph[0] += r;
v->s[2] = (int32_t)((uint32_t)v->s[2] ^ r);
if (!v->s[2])
v->s[2] = 1;
}
static const engine_t ENG_NOISE = {
.name = "NOISE",
.page_title = {"SRC", "MOVE"},
+9
View File
@@ -182,6 +182,15 @@ static const preset_t PHASE_PRESETS[] = {
{"CZ RESO", {6, 0, 80, 90, 0, 0, 0, 0}, {0, 70, 60, 40}, 0, 0, FX(0, 10, 25, 30)},
};
/* (after Clipper 1.2) UNISON (voice.c unison_spread): line 1, line 2 (DTN cents up) and the sub (an octave
* down) moved by r (Q32) of a turn of the note, each by its share (lines 2 and the sub from 0 at each note) */
static void phase_spread(track_t *t, voice_t *v, uint32_t r)
{
v->ph[0] += r;
v->ph[1] += uni_turns(r, v->pitch16, t->p[P_E4] * 16 / 100);
v->ph[2] += r >> 1;
}
static const engine_t ENG_PHASE = {
"PHASE", {"PHS", "LINE"},
{
+46 -2
View File
@@ -112,7 +112,7 @@ static inline const smp_zone_t *smp_zone(uint32_t zi)
}
/* voice: ph[0] position (samples), ph[1] fraction Q16, s[0] predictor, s[1] step
* index, s[2] previous sample, s[3] current sample, s[4] zone, s[5] step Q16 */
* index, s[2] previous sample, s[3] current sample, s[4] zone, s[5] (UNISON) output samples before it starts */
static inline int32_t sample_next(const smp_zone_t *z, voice_t *v, int loop)
{
uint32_t pos = v->ph[0], b = SMP_DATA[z->off + (pos >> 1)];
@@ -157,23 +157,47 @@ static void sample_note_on(track_t *t, voice_t *v)
v->s[0] = 0;
v->s[1] = 0;
v->s[2] = v->s[3] = 0;
v->s[5] = 0; /* (after Clipper 1.2) no start delay (UNISON: sample_spread) */
v->s[6] = zi == 0xFFFFu; /* 1 = sample ended (one-shot); a kit key with no sound stays silent */
v->s[7] = 0; /* lo-pass state */
}
#ifndef SMP_STEP_MAX
#define SMP_STEP_MAX (8u << 16) /* decodes an output sample at most (a 44.1 kHz zone 3 octaves up: 8, the cost bound as before) */
#endif
static void sample_render(track_t *t, voice_t *v, int32_t *out, uint32_t n, const vmod_t *m)
{
const int16_t *p = t->p;
const smp_zone_t *z = smp_zone((uint32_t)v->s[4]);
uint32_t i, frac = v->ph[1];
int32_t d16 = clamp(m->pitch16 + p[P_E1] * 16 - z->root16, -1536, 576); /* <= 3 octaves up: bounded decode load */
int32_t d16 = clamp(m->pitch16 + p[P_E1] * 16 - z->root16, -1536, 1536);
uint32_t r = pow2_q16(d16), stepq = (r >> 8) * (z->rate >> 8); /* Q16 samples per output */
uint32_t lim = (pow2_q16(576) >> 8) * (z->rate >> 8); /* the decode load bounded: 3 octaves up, or SMP_STEP_MAX
* source samples an output sample if that is more (a 16 kHz
* set, one zone: its pitch went flat 3 octaves over its root) */
int32_t bits = p[P_E2], lp = 4000 + ((clamp((p[P_E4] << 8) + m->cutoff, 0, 127 << 8) * 28767) >> 15);
int32_t drv = p[P_E6], sh = bits / 10;
vmod_t m0;
if (stepq > (lim > SMP_STEP_MAX ? lim : SMP_STEP_MAX))
stepq = lim > SMP_STEP_MAX ? lim : SMP_STEP_MAX;
if (v->s[6] || !z->n) {
v->active = 0;
return;
}
if (v->s[5]) { /* (after Clipper 1.2) UNISON: this voice starts later */
if ((uint32_t)v->s[5] >= n) {
v->s[5] -= (int32_t)n;
return;
}
i = (uint32_t)v->s[5]; /* within this block: the rest of it, its level ramp as it was */
v->s[5] = 0;
m0 = *m;
m0.amp0 = amp_at(m, i);
m0.amp1 = m0.amp0 + (m->amp1 - m->amp0);
m = &m0;
out += i;
n -= i;
}
if (v->ph[0] == 0 && v->ph[1] == 0 && v->s[3] == 0)
v->s[3] = sample_next(z, v, p[P_E3]); /* prime the interpolator */
for (i = 0; i < n; i++) {
@@ -203,6 +227,26 @@ static void sample_render(track_t *t, voice_t *v, int32_t *out, uint32_t n, cons
}
/* (after Clipper 1.2) UNISON (voice.c unison_spread): the voice starts r (Q32) of four periods of the pitch it
* sounds later (s[5]: output samples of silence first; nothing decoded, per note): every voice read the same samples
* from the same start, in phase (+9 dB over POLY). Four: a sample may sound lower than its key says (UP BASS: two
* octaves). At most the time of 256 source samples (~6 .. 12 ms at its root) and of a quarter of the zone */
static void sample_spread(track_t *t, voice_t *v, uint32_t r)
{
const int16_t *p = t->p;
const smp_zone_t *z = smp_zone((uint32_t)v->s[4]);
int32_t d16 = clamp(v->pitch16 + p[P_E1] * 16 - z->root16, -1536, 1536);
uint32_t stepq = (pow2_q16(d16) >> 8) * (z->rate >> 8); /* Q16 source samples an output sample */
uint32_t b = pitch_inc((uint32_t)clamp(v->pitch16 + p[P_E1] * 16, 0, 2047)); /* the pitch it sounds (TUNE) */
uint32_t d, q; /* (32-bit divides: two a voice, per note) */
if (v->s[6] || !z->n || !b || !stepq || v->ph[0] || v->ph[1])
return;
d = (0xFFFFFFFFu / b) << 2; /* four periods (output samples; < 21600 at pitch 0) */
q = ((z->n >> 2 < 256u ? z->n >> 2 : 256u) << 16) / stepq; /* the time of 256 source samples */
v->s[5] = (int32_t)(((d < q ? d : q) * (r >> 16)) >> 16); /* x r (the span shortened, not clamped: a clamp */
/* gave many voices the same start) */
}
static const engine_t ENG_SAMPLE = {
"SAMPLE", {"SET", "TONE"},
{
+10
View File
@@ -377,6 +377,16 @@ static const preset_t TRIO_PRESETS[] = {
{"PULSE PAD", {1, 0, 12, 20, 0, 70, 10, 30}, {60, 90, 115, 85}, 0, 0, FX(0, 50, 20, 60), XP(P_LD_SHP + 1, 25, P_LRATE + 1, 30)},
};
/* (after Clipper 1.2) UNISON (voice.c unison_spread): the three oscillators moved by r (Q32) of a turn of the
* note, each by its share (its interval, DTN): as if started that much sooner (2 and 3 from fixed phases at each note) */
static void trio_spread(track_t *t, voice_t *v, uint32_t r)
{
const int16_t *p = t->p;
v->ph[0] += r;
v->ph[1] += uni_turns(r, v->pitch16, p[P_E1] * 16 + p[P_E3] * 16 / 100);
v->ph[2] += uni_turns(r, v->pitch16, p[P_E2] * 16 - p[P_E3] * 16 / 100);
}
static const engine_t ENG_TRIO = {
"TRIO", {"OSC", "TONE"},
{
+8
View File
@@ -16,6 +16,14 @@ static inline int32_t soft_knee(int32_t y, int32_t k) /* linear up to k, then
return y < 0 ? -a : a;
}
/* (pitch_inc: felucca_tables.h, SLOOP 2.5: from the top octave) */
/* (after Clipper 1.2) UNISON's start-phase spread (voice.c unison_spread): r (Q32: a turn of the note at pitch p16,
* 1/16 semitone) in turns of an oscillator d16 (1/16 semitone) above it, the share of the same time; per note */
static uint32_t uni_turns(uint32_t r, int32_t p16, int32_t d16)
{
uint32_t b = pitch_inc((uint32_t)clamp(p16, 0, 2047));
return b ? (uint32_t)(((uint64_t)r * pitch_inc((uint32_t)clamp(p16 + d16, 0, 2047))) / b) : r;
}
#include "eng_analog.c"
#include "eng_digital.c"
#include "eng_phase.c"
+14 -9
View File
@@ -47,7 +47,8 @@ static void track_dist(track_t *t, int32_t *b, uint32_t n)
int32_t x = b[i], y;
t->dist_hp += (x - t->dist_hp + 64) >> 7; /* ~55 Hz low cut: keep the bass out of the clipper */
x = clamp(x - t->dist_hp, -230000, 230000); /* (x >> 2) * g fits 32 bits; the clip is flat out there */
y = softclip((((x >> 2) * g) >> 10) + bias) - b0; /* >> 2 first: no overflow for loud poly */
y = softclip(MULQ12R(x, g, 2) + bias) - b0; /* (as (x >> 2) * g >> 10 in 32 bits: no overflow for loud
* poly; #4: rounded, no step of 4 x the drive) */
t->dist_lp1 += mulq15(y - t->dist_lp1, k); /* two poles: tames the fizz */
t->dist_lp2 += mulq15(t->dist_lp1 - t->dist_lp2, k);
b[i] = mulq15(t->dist_lp2, mk);
@@ -714,10 +715,13 @@ static void mix_part_run(track_t *t, uint32_t n, mixacc_t *mx, int32_t *b)
t->lvl = mix_glide(lvl0, lvl), t->gpl = mix_glide(gl0, gl), t->gpr = mix_glide(gr0, gr);
dl = (t->lvl - lvl0) >> CTL_LOG2, dgl = t->gpl - gl0, dgr = t->gpr - gr0;
for (i = 0; i < n; i++) {
int32_t x = ((b[i] >> 2) * (lvl0 + dl * (int32_t)i)) >> 10, a; /* pre-shift: 8 loud voices */
int32_t lv = lvl0 + dl * (int32_t)i, bi = b[i], x = MULQ12R(bi, lv, 2), a; /* (#4) rounded, all of b: 8 loud
* voices in 32 bits as ((b >> 2) * lv) >> 10 was */
int32_t xs, g = ga + (((gb - ga) * (int32_t)i) >> CTL_LOG2);
if (g < 32767)
x = (x >> 4) * (g >> 3) >> 8; /* (Q15 in two halves: no 32-bit overflow) */
if (g < 32767) { /* (always, at rest: mulq15(32767, 32767) is 32766) */
g >>= 3; /* (Q12: no 32-bit overflow) */
x = MULQ12R(x, g, 4);
}
a = x < 0 ? -x : x;
xs = clamp(x, -xmax, xmax); /* sends: mulq15 would overflow */
if (a > pk)
@@ -729,8 +733,9 @@ static void mix_part_run(track_t *t, uint32_t n, mixacc_t *mx, int32_t *b)
if (r)
mx->sr[i] += mulq15(xs, r);
gl = gl0 + ((dgl * (int32_t)i) >> CTL_LOG2), gr = gr0 + ((dgr * (int32_t)i) >> CTL_LOG2); /* (2.7) */
mx->l[i] += ((x >> 4) * gl) >> 8; /* (x may pass 2^19: >> 4 first) */
mx->r[i] += ((x >> 4) * gr) >> 8;
mx->l[i] += (x * (gl >> 4) + 128) >> 8; /* (x may pass 2^19: PAN's Q12 to Q8, exact at rest: 64 a step;
* #4: x >> 4 floored the part to 16 LSB) */
mx->r[i] += (x * (gr >> 4) + 128) >> 8;
}
t->peak = pk;
}
@@ -1231,15 +1236,15 @@ static void mix_block(int32_t *out, uint32_t n)
static uint8_t usb_was;
for (i = 0; i < n; i++) {
int32_t m = m0 + (((m1 - m0) * (int32_t)i) >> CTL_LOG2);
ol[i] = ((mix_l[i] >> 2) * m) >> 10;
orr[i] = ((mix_r[i] >> 2) * m) >> 10;
ol[i] = MULQ12R(mix_l[i], m, 2); /* (#4: rounded; (x >> 2) * m >> 10 floored to 4 LSB) */
orr[i] = MULQ12R(mix_r[i], m, 2);
master_pre(&ol[i], &orr[i]);
if ((i & 1u)) { /* the visualiser: every other sample, as audio.c reads it */
vis_tap[2u * i] = (int16_t)knee(mix_l[i]);
vis_tap[2u * i + 1u] = (int16_t)knee(mix_r[i]);
}
if (usb_full_now) { /* USB AUDIO = FULL: MASTER all the way up (4096) */
ul[i] = (mix_l[i] >> 2) << 2, ur[i] = (mix_r[i] >> 2) << 2;
ul[i] = mix_l[i], ur[i] = mix_r[i]; /* (#4: x 4096 / 4096, every bit; it was floored to 4 LSB) */
master_pre_usb(&ul[i], &ur[i]);
}
}
+54 -17
View File
@@ -138,6 +138,22 @@ static int32_t px_atan(int32_t x)
return px_m(x, p, 30);
}
/* atan2(y, x) in turns, Q32 (-1/2 .. 1/2 turn); y, x Q30 (|.| <= 2); one 64 / 32 division (per block only) */
static int64_t px_atan2t(int32_t y, int32_t x)
{
int32_t ay = y < 0 ? -y : y, ax = x < 0 ? -x : x;
int64_t t;
if (!ay)
t = 0;
else if (ay <= ax)
t = px_m(px_atan((int32_t)(((int64_t)ay << 30) / ax)), 683565276, 30); /* rad / 2 pi */
else
t = (1 << 30) - px_m(px_atan((int32_t)(((int64_t)ax << 30) / ay)), 683565276, 30);
if (x < 0)
t = ((int64_t)1 << 31) - t;
return y < 0 ? -t : t;
}
static uint32_t px_isqrt64(uint64_t v) /* floor(sqrt(v)) */
{
uint64_t r = 0, b = (uint64_t)1 << 62;
@@ -473,11 +489,10 @@ typedef struct {
} px_string_t;
typedef struct { /* per block */
uint32_t delay; /* samples, Q16 */
int32_t src_ratio; /* Q30, 1.0 = no resampling */
int32_t comp; /* damping compensation, Q30 */
uint32_t dl; /* the delay line's read delay, steps Q16 (no all-pass) */
int32_t G; /* OnePole: g / (1 + g), Q30 */
int32_t m_ap, m_main; /* ap / main delay out of the delay, Q30 */
uint32_t ap, mn; /* with the dispersion all-pass: its delay and the line's, Q16 */
int32_t ap_gain; /* Q30 */
int32_t noise_amt, noise_flt; /* Q30 */
int32_t curving; /* bridge curving, Q30 */
@@ -498,7 +513,7 @@ static __attribute__((noinline)) void px_string_block(px_string_blk_t *B, px_str
{
int32_t b = brightness + px_m(accent >> 2, 65536 - brightness, 16);
int32_t d = damping + px_m(accent >> 2, 65536 - damping, 16);
int32_t nl, dcut, sp, sc, x;
int32_t nl, dcut, sp;
uint32_t f = f0 > 0x40000000u ? 0x40000000u : f0, delay, df, ratio;
if (f < 65536u) /* 0.67 Hz */
f = 65536u;
@@ -543,7 +558,6 @@ static __attribute__((noinline)) void px_string_block(px_string_blk_t *B, px_str
B->src_ratio = ratio >= 1073634406u ? 1 << 30 : (int32_t)ratio; /* >= 0.9999: none */
if (B->src_ratio == 1 << 30)
S->src = 1u << 30;
B->delay = delay;
dcut = 786432 + px_m(px_m(d, d, 16), 3932160, 16) + b * 24; /* 12 + 60 d^2 + 24 b semitones, Q16 */
if (dcut > 84 << 16)
dcut = 84 << 16;
@@ -567,14 +581,7 @@ static __attribute__((noinline)) void px_string_block(px_string_blk_t *B, px_str
int32_t s = px_sin(df >> 1), c = px_sin((df >> 1) + 0x40000000u);
B->G = (int32_t)(((int64_t)s << 30) / (s + c));
}
/* damping compensation 1 - 2 atan(1 / ratio) / 2 pi, ratio = 2^(dcut / 12) >= 2 */
x = (int32_t)(((uint64_t)1 << 46) / px_exp2(dcut / 12)); /* 1 / ratio, Q30 */
B->comp = (1 << 30) - px_m(px_atan(x), 341782638, 30); /* * 1 / pi */
sp = px_m(px_m(nl, 131072 - nl, 16), 14746, 16); /* nl (2 - nl) 0.225, Q16 */
sc = (int32_t)(((uint64_t)delay * 238) >> 16); /* 160 / sr * delay, Q16 */
sc = px_clamp(sc, 65536, 137626);
B->m_ap = sp << 14;
B->m_main = (1 << 30) - px_m(sp, px_m(26739 - px_m(sp, 20185, 16), sc, 16), 2);
{
int32_t na = nl > 49152 ? (nl - 49152) * 4 : 0; /* 4 (nl - 0.75) */
B->noise_amt = px_m(px_m(na, na, 16), 107374182, 16); /* ^2 * 0.1, Q30 */
@@ -582,6 +589,35 @@ static __attribute__((noinline)) void px_string_block(px_string_blk_t *B, px_str
B->curving = px_m(px_m(nl, nl, 16), 10737418, 16); /* nl^2 0.01 */
B->ap_gain = -(int32_t)(((int64_t)663568203 * nl) / (9830 + nl)); /* -0.618 nl / (0.15 + nl) */
}
{ /* (after 2.8.3) the loop in tune: its delays and the phase lags of its filters at the fundamental add up
* to one period. DaisySP takes 2 atan(1 / ratio) / 2 pi of a period off for the damping filter (twice the lag
* of its OnePole: the compensation of Rings' two-pole Svf) and shortens the line for the dispersion all-pass
* by a rule of thumb that grows with the delay: the strings were sharp, by up to +20 cents high and +100 below
* F2. Here: the OnePole's lag atan(tan(pi f) / g), the DcBlock's lead, the all-pass's lag at its integer
* delay and the linear read's at its fraction, exactly; turns Q32, per block */
uint32_t ph = (uint32_t)(((uint64_t)1 << 48) / delay); /* the fundamental, turns per string step, Q32 */
int32_t sn = px_sin(ph), cs = px_sin(ph + 0x40000000u);
int32_t s = px_sin(df >> 1), c = px_sin((df >> 1) + 0x40000000u); /* sin, cos (pi df) */
int64_t lag = px_atan2t(px_m(px_sin(ph >> 1), c, 30), px_m(px_sin((ph >> 1) + 0x40000000u), s, 30))
- ((1 << 30) - (int64_t)(ph >> 1)
- px_atan2t(px_m(1073498345, sn, 30), (1 << 30) - px_m(1073498345, cs, 30))); /* - DcBlock */
uint32_t ap = (uint32_t)(((uint64_t)delay * (uint32_t)sp) >> 16), mn;
B->dl = delay - (uint32_t)((lag * delay) >> 32);
if (ap >= 4u << 16) {
uint32_t psi = (ap >> 16) * ph, a; /* the all-pass: lag psi + 2 atan2(g sin, 1 - g cos) */
int64_t lap = psi + 2 * px_atan2t(px_m(B->ap_gain, px_sin(psi), 30),
(1 << 30) - px_m(B->ap_gain, px_sin(psi + 0x40000000u), 30));
mn = delay - (uint32_t)(((lag + lap) * delay) >> 32);
a = (mn & 0xFFFFu) << 14; /* the linear read: lag atan2(a sin, 1 - a + a cos) */
lap = px_atan2t(px_m((int32_t)a, sn, 30), (1 << 30) - (int32_t)a + px_m((int32_t)a, cs, 30)) -
(int64_t)(((uint64_t)(mn & 0xFFFFu) * ph) >> 16);
mn -= (uint32_t)((lap * delay) >> 32);
} else {
mn = 0;
}
B->ap = ap;
B->mn = mn;
}
}
static inline int32_t px_hermite(const int32_t *l, uint32_t wp, uint32_t delay) /* DelayLine::ReadHermite */
@@ -642,16 +678,17 @@ static void px_string_run(const px_string_blk_t *B, px_string_t *S, const int32_
/* the string */
src += (uint32_t)B->src_ratio;
if (src > 1u << 30) {
uint32_t dl = (uint32_t)(((uint64_t)B->delay * (uint32_t)B->comp) >> 30);
uint32_t dl = B->dl;
int32_t s;
src -= 1u << 30;
if (!B->curved) {
int32_t nz = (int32_t)(px_rand(&rs) >> 12) - (1 << 19); /* rand - 0.5 */
uint32_t q;
disp += px_m(B->noise_flt, nz - disp, 30);
dl = (uint32_t)(((uint64_t)dl * (uint32_t)((1 << 30) + px_m(disp, B->noise_amt, 20))) >> 30);
q = (uint32_t)((1 << 30) + px_m(disp, B->noise_amt, 20)); /* the dispersion noise */
{
uint32_t ap = (uint32_t)(((uint64_t)dl * (uint32_t)B->m_ap) >> 30);
uint32_t mn = (uint32_t)(((uint64_t)dl * (uint32_t)B->m_main) >> 30);
uint32_t ap = (uint32_t)(((uint64_t)B->ap * q) >> 30);
uint32_t mn = (uint32_t)(((uint64_t)B->mn * q) >> 30);
if (ap >= 4u << 16 && mn >= 4u << 16) {
uint32_t t = wp + (mn >> 16);
int32_t a = S->line[t & PX_LMASK], bb = S->line[(t + 1u) & PX_LMASK], rd, w;
@@ -662,7 +699,7 @@ static void px_string_run(const px_string_blk_t *B, px_string_t *S, const int32_
swp = (swp - 1u) & PX_SMASK;
s = rd - px_m(w, B->ap_gain, 30);
} else {
s = px_hermite(S->line, wp, dl);
s = px_hermite(S->line, wp, (uint32_t)(((uint64_t)dl * q) >> 30));
}
}
} else {
+17
View File
@@ -545,6 +545,7 @@ static void proj_apply(const project_t *p, int all)
st->n = 4;
if (st->time > ST_REST)
st->time = ST_REST;
st->vel &= 127u; /* (after 2.8.3: past 127 from a file, up to twice as loud) */
for (j = 0; j < 4u; j++)
st->note[j] &= 127u;
}
@@ -631,6 +632,20 @@ UI_SMALL static void project_erase(uint32_t slot)
ui_say("ERASED SECTION ", SEC_NAME[slot]);
}
/* (2.8.4) a part whose sound is on an engine this firmware does not have (a project Clipper wrote: HYBRID,
* FMX, VECTOR...; left in the flash when SLOOP is installed after Clipper): proj_apply wrapped the engine number round
* onto another engine with the other one's values (Clipper's HYBRID played as 808 BOOM without its TRN -24: two
* octaves high, until another sound was chosen). The part's default sound instead; its pattern and mix stay */
UI_SMALL static void proj_foreign_parts(const project_t *p)
{
uint32_t k;
for (k = 0; k < NPART; k++)
if (p->t[k].preset != 0xFFu && p->t[k].engine >= NENGINES) {
set_engine_of(&trk[k], TRK_DEF[k][0]);
apply_preset_to(&trk[k], TRK_DEF[k][1]);
}
}
/* a project into the working one: the transport stops, everything sounding is released */
UI_SMALL static void project_apply(const project_t *p)
{
@@ -649,6 +664,7 @@ UI_SMALL static void project_apply(const project_t *p)
apply_preset_to(&trk[k], TRK_DEF[k][1]);
steps_clear(&trk[k]);
}
proj_foreign_parts(p);
sync_reload = 1;
ui.force = 1;
}
@@ -731,6 +747,7 @@ UI_SMALL static void autosave_resume(void) /* power-on: the project
drch_seed = 0;
proj_apply(q, 1);
song.sel = (uint8_t)(q->sel < NTRK ? q->sel : 0u);
proj_foreign_parts(q); /* (2.8.4) Clipper's working project: its own sounds, default */
for (n = 0; n < NPART; n++)
trk[n].engine = trk[n].eng_req; /* (nothing sounds yet: no fade) */
#endif
+4 -2
View File
@@ -3,7 +3,7 @@
/* Felucca user interface. Four columns map to KNOB 1..4. Rendering is lazy:
* every element remembers what it last drew and is redrawn only on change. */
#ifndef FELUCCA_VERSION
#define FELUCCA_VERSION "SLOOP 2.8.3" /* the beat machine firmware for the FM-1 (based on Felucca) */
#define FELUCCA_VERSION "SLOOP 2.8.4" /* the beat machine firmware for the FM-1 (based on Felucca) */
#endif
static void project_save(uint32_t slot);
static void arrangement_save(void);
@@ -978,7 +978,9 @@ UI_SMALL static void pc_poll(void)
if (&trk[i] == TSEL)
sync_reload = 1;
} else if (bank == PC_USER_BANK) { /* (2.7.2) user presets straight: PC n = user slot n (0..31) */
if (!up_load_to(&trk[i], n)) /* (an empty slot or past the end: nothing) */
if (up_load_to(&trk[i], n)) /* (an empty slot or past the end: nothing; after 2.8.3: it
* read the result the wrong way round: "PROG n" for an empty
* slot, no message for a preset loaded) */
continue;
} else { /* (2.7.2) linear: bank 0 the sounds 0..127, bank 1 128..255 */
n = bank * 128u + (r - 1u);
+4
View File
@@ -1180,9 +1180,13 @@ UI_SMALL static void ui_input(void)
}
if (rec_wait && !ft_on && !ci_on) { /* the REC screen, armed: how it records */
rec_knobs(); /* (tempo and sound still work; the track too: */
enc_hold |= 15u << EN_K1; /* (after 2.8.3, sloop-pro #6) KNOB 1..4 are the REC screen's this
* pass: a detent counted after rec_knobs read it never reaches
* the page under it too (K3 START also moved TRACKS' LEN) */
} else if (rec_wait || ft_on) { /* the arm follows) */
for (k = 0; k < 4u; k++) /* a take / the count-in: KNOB 1..4 edit nothing */
panel_enc(EN_K1 + k);
enc_hold |= 15u << EN_K1;
}
#if FELUCCA_ARRANGER
if (on_song_page()) {
+3 -1
View File
@@ -29,7 +29,9 @@ static uint8_t sec_armed; /* store over a used sec
static uint32_t sec_armed_ms;
static uint8_t chain_tap[CHAIN_MAX], chain_taps; /* the section keys tapped in this SAVE hold (the first
* is asked for at once; two or more: a chain on release) */
#define TAP_MS 450u /* a press shorter than this, untouched: a tap */
#define TAP_MS 1000u /* a press shorter than this, untouched: a tap (after 2.8.3: was
* 0.45 s: a firm press of FX, EDIT, ARP, SEQ, SEL, GLO or SAVE opened
* nothing, the layer flashed and HOME stayed; clipper-fm1 #24) */
#define SHOW_MS 350u /* the layer shows after this (a tap does not flash it; 2.8.3: was 0.14 s,
* a quick tap flashed it; a key or knob used shows it at once) */
+5 -5
View File
@@ -2,7 +2,7 @@
/* Compact 240 x 240 song-order editor. All changes and flash saves require
* stopped transport. The four existing project slots are sections A..D. */
static uint8_t song_cursor, song_store_armed, song_load_armed;
static uint32_t song_store_deadline;
static uint32_t song_store_t; /* when REC or OCT+ asked for its confirmation (ms) */
UI_SMALL static int on_song_page(void) { return !ui.home && cur_page()->scope == SC_SONG; }
UI_SMALL static void song_sane(void) /* a bad chain (blank / damaged settings): defaults */
{
@@ -111,19 +111,19 @@ UI_SMALL static void song_screen_input(uint32_t pressed, uint32_t home)
arrangement_enabled ^= 1u;
ui_message(arrangement_enabled ? "SONG MODE" : "LOOP MODE");
} else if (b == B_OCTUP) { /* load: a second press within 3 s (unsaved work goes) */
if (song_load_armed && (int32_t)(fm1_ms - song_store_deadline) <= 0) {
if (song_load_armed && fm1_ms - song_store_t <= 3000u) {
song_load_armed = 0;
project_load(scene);
} else {
song_load_armed = 1;
song_store_armed = 0;
song_store_deadline = fm1_ms + 3000u;
song_store_t = fm1_ms;
ui_message("OCT+ AGAIN: LOAD");
}
} else if (project_used(scene) &&
(!song_store_armed || (int32_t)(fm1_ms - song_store_deadline) > 0)) {
(!song_store_armed || fm1_ms - song_store_t > 3000u)) {
song_store_armed = 1;
song_store_deadline = fm1_ms + 3000u;
song_store_t = fm1_ms;
ui_message("REC AGAIN: REPLACE");
} else {
project_save(scene);
+41 -3
View File
@@ -290,6 +290,7 @@ static void glide_set(track_t *t, voice_t *v, int glide)
#define VP_ON 1u
#define VP_OFF 2u
#define VP_GLIDE 4u
#define VP_UNI 8u /* (after Clipper 1.2) an extra UNISON voice: its start spread (unison_spread) */
static void voice_start(track_t *t, voice_t *v, uint32_t note, uint32_t vel, int glide)
{
const engine_t *e = ENGINES[t->engine];
@@ -355,6 +356,37 @@ static void voice_start(track_t *t, voice_t *v, uint32_t note, uint32_t vel, int
}
}
/* a UNISON voice's start phases moved by r (Q32: a turn of its note), as if it had started that much of a period
* sooner: in phase the voices stack, spread they sum as noise */
static void unison_spread(track_t *t, voice_t *v, uint32_t r)
{
const engine_t *e = ENGINES[t->engine];
/* (after Clipper 1.2) each engine moves all its oscillators (and reseeds its noise): ph[0] alone left the others in
* phase (ANALOG's osc 2, TRIO's 2 and 3, DIGITAL's and FM6's operators, the subs, SAMPLE's start...) */
if (e == &ENG_ANALOG)
analog_spread(t, v, r);
else if (e == &ENG_DIGITAL)
digital_spread(t, v, r);
else if (e == &ENG_PHASE)
phase_spread(t, v, r);
else if (e == &ENG_LOFI)
lofi_spread(t, v, r);
else if (e == &ENG_TRIO)
trio_spread(t, v, r);
else if (e == &ENG_NOISE)
noise_spread(t, v, r);
else if (e == &ENG_FM6)
fm6_spread(t, v, r);
else if (e == &ENG_SAMPLE)
sample_spread(t, v, r);
#if FELUCCA_SLICE
else if (e == &ENG_SLICE)
; /* (slices: as played) */
#endif
else
v->ph[0] += r;
}
/* MONO / LEGATO / UNISON: one note on one voice (eight for UNISON, or the
* engine's voice cap, spread by DETUNE over the same width) */
static void mono_play(track_t *t, uint32_t note, uint32_t vel, int retrig, int glide)
@@ -372,11 +404,12 @@ static void mono_play(track_t *t, uint32_t note, uint32_t vel, int retrig, int g
continue; /* no room for this extra UNISON voice */
/* level: about the same sum for 8 or 4 voices at random phases */
voice_start(t, v, note, nv >= NVOICE ? vel * 36u / 100u : nv > 1u ? vel / 2u : vel, glide);
if (nv > 1u && i && !eng_sampled(ENGINES[t->engine]) && !was_sounding) { /* random start phases: */
if (nv > 1u && i && !was_sounding) { /* random start phases (SAMPLE: its start; not SLICE): */
static uint32_t seed = 0x1234567u; /* in phase they stack, evenly spread they cancel */
seed = seed * 1664525u + 1013904223u;
v->ph[0] += seed;
}
unison_spread(t, v, seed);
} else if (nv > 1u && i && (v->pend & VP_ON))
v->pend |= VP_UNI; /* (a sample's, after its fade: spread as it starts) */
} else { /* legato: new pitch, same envelope */
v->note = (uint8_t)note;
v->pitch16 = (int32_t)note * 16;
@@ -774,6 +807,11 @@ static uint32_t track_render(track_t *t, int32_t *out, uint32_t n)
v->pend = 0;
if (voice_room(t, 0)) { /* (it was not counted while fading: within the budget) */
voice_start(t, v, v->pend_note, v->pend_vel, (pf & VP_GLIDE) != 0);
if (pf & VP_UNI) { /* (after Clipper 1.2) UNISON: not in phase with the others */
static uint32_t seed = 0x13579BDu;
seed = seed * 1664525u + 1013904223u;
unison_spread(t, v, seed);
}
if (pf & VP_OFF) { /* let go within the fade (~1.5 ms): released as it starts */
v->gate = 0;
v->stage = 3;
+147
View File
@@ -0,0 +1,147 @@
/* SPDX-License-Identifier: GPL-3.0-only */
/* After an install (a power-on on the flash as it was), track 1 (and the other parts) sound as their sound: the
* values the boot leaves equal the ones the same sound gets when it is loaded again. And (2.8.4) a working project
* Clipper left in the flash (SLOOP installed after Clipper): a part on an engine SLOOP does not have (HYBRID, 12 and
* up) used to wrap round onto ANALOG with HYBRID's values: 808 BOOM without its TRN -24, two octaves high; it gets
* its default sound now. Exit status: failed checks. */
#include "editor_host.c"
static int fails;
static void check(int c, const char *what) { printf("boot_sound: %-80s %s\n", what, c ? "ok" : "FAIL"); fails += !c; }
static int16_t snapv[NPART][P_COUNT];
static void boot_as_main(void)
{
uint32_t i;
persist_boot();
settings_init();
panel_init();
for (i = 0; i < G_COUNT; i++) song.g[i] = GP[i].def;
fm6_init();
for (i = 0; i < NTRK; i++) {
track_t *t = &trk[i];
track_defaults(t);
if (i < NPART) { set_engine_of(t, TRK_DEF[i][0]); apply_preset_to(t, TRK_DEF[i][1]); t->engine = t->eng_req; }
track_defaults_steps(t);
}
TDRUM->p[P_E0] = DRUM_DEFAULT_KIT;
song.sel = 0;
autosave_resume();
layers_init();
go_home();
ui.force = 1;
}
static void compare(const char *when)
{
uint32_t k, i;
char b[160];
for (k = 0; k < NPART; k++) {
int16_t now[P_COUNT];
uint32_t e = trk[k].eng_req, pi = trk[k].preset, bad = 0;
memcpy(now, trk[k].p, sizeof now);
memcpy(snapv[k], trk[k].p, sizeof now);
apply_preset_to(&trk[k], pi); /* the same sound loaded again */
for (i = 0; i < P_COUNT; i++)
if (now[i] != trk[k].p[i]) {
if (bad++ < 6)
printf("boot_sound: %s track %u (%s %s): p[%u] %s %d, loaded again %d\n", when, k + 1, ENGINES[e]->name,
ENGINES[e]->presets[pi % ENGINES[e]->npresets].name, i, i < P_E0 ? TP[i].label : "E", now[i], trk[k].p[i]);
}
snprintf(b, sizeof b, "%s: track %u plays its sound as loaded (every value)", when, k + 1);
check(!bad, b);
memcpy(trk[k].p, now, sizeof now);
}
}
/* track k's note: its zero-crossing rate over 0.3 .. 0.8 s (Hz, the fundamental of a bass sine) */
static double note_hz(uint32_t k, uint32_t note)
{
static int32_t o[CTL * 2];
uint32_t b, i, zc = 0, n = 0;
int32_t prev = 0;
for (i = 0; i < NTRK; i++) trk_all_off(&trk[i]);
for (b = 0; b < 600; b++) mix_block(o, CTL);
trk_note_on(&trk[k], note, 100);
for (b = 0; b < 1200; b++) {
mix_block(o, CTL);
if (b < 400) continue;
for (i = 0; i < CTL; i++, n++) { int32_t y = o[2 * i]; if ((prev < 0) != (y < 0)) zc++; prev = y; }
}
trk_note_off(&trk[k], note);
return zc / 2.0 * FS / n;
}
static void pitch_check(const char *when)
{
uint32_t k;
char b[160];
for (k = 0; k < NPART; k++) {
double a = note_hz(k, 48), c;
apply_preset_to(&trk[k], trk[k].preset);
c = note_hz(k, 48);
printf("boot_sound: %s track %u note C3: %.1f Hz, the sound loaded again %.1f Hz\n", when, k + 1, a, c);
snprintf(b, sizeof b, "%s: track %u at its pitch (as the sound loaded again)", when, k + 1);
check(a > c * 0.97 && a < c * 1.03, b);
}
}
/* the FM-1's key C4 (key 7) on track k: the note its voice plays */
static int key_note(uint32_t k)
{
uint32_t i, f;
int n = -1;
song.sel = (uint8_t)k;
for (f = 0; f < 4; f++) ui_frame();
fm1_in.notes = 1u << 7;
for (f = 0; f < 6; f++) ui_frame();
for (i = 0; i < NVOICE; i++) if (trk[k].v[i].active && trk[k].v[i].gate) n = trk[k].v[i].note;
fm1_in.notes = 0;
for (f = 0; f < 30; f++) ui_frame();
return n;
}
static void key_check(const char *when)
{
uint32_t k;
char b[160];
for (k = 0; k < NPART; k++) {
int a = key_note(k), c;
printf("boot_sound: %s track %u: octave %d, TRN %d, key C4 plays note %d\n", when, k + 1, song.octave, trk[k].p[P_TRANS], a);
apply_preset_to(&trk[k], trk[k].preset);
c = key_note(k);
printf("boot_sound: %s track %u: the sound loaded again, key C4 plays note %d\n", when, k + 1, c);
snprintf(b, sizeof b, "%s: track %u, key C4 plays the same note as with the sound loaded again", when, k + 1);
check(a == c, b);
}
}
int main(void)
{
uint32_t i;
harness_init();
memset(nor, 0xFF, sizeof nor); /* 1. a first install: nothing in the flash */
boot_as_main();
compare("first power-on");
boot_as_main();
boot_as_main();
key_check("first power-on");
for (i = 0; i < 400; i++) ui_frame(); /* (an autosave) */
persist_flush_now();
boot_as_main(); /* 2. an update: the flash as it was */
compare("power-on after an update");
boot_as_main();
boot_as_main();
key_check("power-on after an update");
{ /* 3. a working project Clipper wrote: track 1 on engine 12 (HYBRID), its TRN 0, a pattern */
static project_t q;
proj_capture(&q);
q.t[0].engine = NENGINES; /* (Clipper's HYBRID: the first engine SLOOP does not have) */
q.t[0].preset = 0;
pt_set(&q.t[0], P_TRANS, 0);
q.t[0].step[0].time = ST_NOTE; q.t[0].step[0].n = 1; q.t[0].step[0].note[0] = 48;
q.sum = proj_sum(&q);
st_save(OBJ_AUTOSAVE, &q, sizeof q);
boot_as_main();
printf("boot_sound: over Clipper's project: track 1 %s %s, TRN %d\n", ENGINES[trk[0].eng_req]->name,
ENGINES[trk[0].eng_req]->presets[trk[0].preset].name, trk[0].p[P_TRANS]);
check(trk[0].eng_req == TRK_DEF[0][0] && trk[0].preset == TRK_DEF[0][1] && trk[0].p[P_TRANS] == -24,
"over Clipper's working project: track 1 gets its default sound (808 BOOM, TRN -24)");
check(trk[0].step[0].time == ST_NOTE && trk[0].step[0].note[0] == 48, "... and keeps its pattern");
key_check("over Clipper's working project");
}
printf("boot_sound: %d failed\n", fails);
return fails != 0;
}
+1 -1
View File
@@ -102,7 +102,7 @@ static uint32_t put(uint32_t k, uint32_t part, const uint8_t *d, uint32_t nd)
static uint32_t hit_win = 22050; /* the crossings' window: half a second (a sample: 80 ms) */
static void hit_render(uint32_t note, double *zc, double *tail)
{
static int32_t L[66150], R[66150], RV[66150], DL[66150];
static int32_t L[66150 + CTL], R[66150 + CTL], RV[66150 + CTL], DL[66150 + CTL]; /* (+ CTL: the last block) */
uint32_t i, n = 66150, c = 0;
double e0 = 0, e1 = 0;
memset(&drums, 0, sizeof drums);
+945
View File
@@ -0,0 +1,945 @@
/* SPDX-License-Identifier: GPL-3.0-only */
/* Fuzz of the web editor's SysEx protocol (firmware/src/editor.c ed_handle and what it reaches) on the host
* harness tests/editor_host.c, under AddressSanitizer + UBSan:
* editor_fuzz MODE ITER SEED
* MODE 0 single frames: every command byte 0..255, lengths at the edges (4, 5, the expected, -1, +1, huge),
* arguments 7-bit (and 8-bit when injected straight into the frame buffer)
* MODE 1 sequences: sample uploads (begin / write / end, in and out of order), backup restore of every
* object (valid CRC, random or mutated content: checked "as a load"), user presets, FM6 patches, SYN
* kits, steps, locks, LIVE ops; interleaved with UI frames (random panel use) and the audio
* MODE 2 USB-MIDI in: random event packets (every CIN, cable, channel, notes vel 0, CC / NRPN / bend /
* pressure / program), SysEx split over packets, with the audio and UI running
* After every frame: every track parameter and lock inside its range, steps sane, the audio bounded.
* A failure prints the last operations (the reproducer) and aborts. */
#include <stddef.h>
#include "editor_host.c"
#include <sanitizer/common_interface_defs.h>
static uint32_t sd = 1;
static uint32_t rn(uint32_t n) { sd ^= sd << 13; sd ^= sd >> 17; sd ^= sd << 5; return n ? sd % n : 0; }
/* ---- the reproducer log: the last operations */
#define LOGN 48
typedef struct { uint8_t kind; uint16_t n; uint8_t b[700]; uint32_t ms; } op_t; /* kind: 0 inject, 1 usb sysex, 2 ui frame, 3 audio, 4 midi pkt */
static op_t lg[LOGN];
static uint32_t lgn;
static void logop(uint32_t kind, const uint8_t *b, uint32_t n)
{
op_t *o = &lg[lgn++ % LOGN];
o->kind = (uint8_t)kind;
o->n = (uint16_t)(n > sizeof o->b ? sizeof o->b : n);
o->ms = fm1_ms;
if (b) memcpy(o->b, b, o->n);
}
static void dump(void)
{
uint32_t i, j, s = lgn > LOGN ? lgn - LOGN : 0;
fprintf(stderr, "---- last %u operations (oldest first), seed %u ----\n", lgn - s, sd);
for (i = s; i < lgn; i++) {
const op_t *o = &lg[i % LOGN];
static const char *K[] = {"inject", "usb", "ui", "audio", "midi", "uart", "boot"};
fprintf(stderr, "#%u %s ms=%u n=%u:", i, K[o->kind], o->ms, o->n);
for (j = 0; j < o->n && j < 160u; j++)
fprintf(stderr, " %02X", o->b[j]);
fprintf(stderr, "%s\n", o->n > 160u ? " ..." : "");
}
}
static void on_death(void) { dump(); }
static void fail(const char *what)
{
dump();
fprintf(stderr, "FAIL: %s\n", what);
abort();
}
static void after(void)
{
char why[256];
if (!params_check(why, sizeof why))
fail(why);
if (audio_bad)
fail("audio out of bounds");
}
static void frame(const uint8_t *f, uint32_t n, int via_usb)
{
logop(via_usb ? 1 : 0, f, n);
if (via_usb)
usb_sysex(f, n);
else
ed_inject(f, n);
after();
}
static void cmdv(uint32_t cmd, const uint8_t *a, uint32_t na)
{
uint8_t f[700];
f[0] = ED_HDR0; f[1] = ED_HDR1; f[2] = ED_HDR2; f[3] = (uint8_t)cmd;
if (na > sizeof f - 4) na = sizeof f - 4;
memcpy(f + 4, a, na);
frame(f, 4 + na, rn(4) == 0);
}
static void uif(void)
{
logop(2, 0, 0);
ui_frame();
after();
}
static void aud(uint32_t nb)
{
uint8_t b = (uint8_t)nb;
logop(3, &b, 1);
audio_blocks(nb);
after();
}
/* random panel use, as the UI fuzz of tests/ui_pages_test.c */
static uint32_t held;
static void ui_rand(void)
{
if (rn(6) == 0) {
uint32_t bt = rn(NB);
edges_btn |= 1u << panel.btn[bt];
if (bt != B_HOME && rn(3) == 0) held ^= 1u << panel.btn[bt];
}
if (rn(30) == 0) held = 0;
fm1_in.buttons = held & ~(1u << panel.btn[B_HOME]);
if (rn(4) == 0) encs[rn(7)] += (int32_t)rn(5) - 2;
fm1_in.notes = rn(10) == 0 ? (1u << rn(27)) : (rn(3) ? fm1_in.notes : 0);
uif();
if (ui.menu && rn(4)) { ui.menu = 0; ui.force = 1; }
}
/* ---- builders */
static uint32_t pack7(uint8_t *o, const uint8_t *p, uint32_t n) /* editor.c ed_pack7 */
{
uint32_t w = 0;
while (n) {
uint32_t k = n > 7u ? 7u : n, m = 0, i;
for (i = 0; i < k; i++) m |= (uint32_t)(p[i] >> 7) << i;
o[w++] = (uint8_t)m;
for (i = 0; i < k; i++) o[w++] = p[i] & 127u;
p += k; n -= k;
}
return w;
}
static uint32_t put5(uint8_t *o, uint32_t v) { uint32_t i; for (i = 0; i < 5; i++) o[i] = (v >> (7 * i)) & 127u; return 5; }
static uint32_t v14(uint8_t *o, int32_t v) { uint32_t u = (uint32_t)(v + 8192); o[0] = u & 127u; o[1] = (u >> 7) & 127u; return 2; }
static int32_t rval(void)
{
switch (rn(6)) {
case 0: return -8192;
case 1: return 8191;
case 2: return (int32_t)rn(16384) - 8192;
case 3: return (int32_t)rn(300) - 150;
default: return (int32_t)rn(128);
}
}
static void rbytes(uint8_t *b, uint32_t n, int bit8) { uint32_t i; for (i = 0; i < n; i++) b[i] = (uint8_t)(bit8 ? rn(256) : rn(128)); }
static void mutate(uint8_t *b, uint32_t n)
{
uint32_t k = rn(4), i;
for (i = 0; i < k && n; i++) {
uint32_t at = rn(n);
switch (rn(4)) {
case 0: b[at] = (uint8_t)rn(256); break;
case 1: b[at] ^= (uint8_t)(1u << rn(8)); break;
case 2: b[at] = 0xFF; break;
default: b[at] = 0; break;
}
}
}
/* a backup object restored: begin, data (pack7, 1..256 a frame), commit; the CRC right (the content is checked as a load) */
static void bk_restore(uint32_t id, const uint8_t *raw, uint32_t len)
{
uint8_t a[700];
uint32_t n = 0, pos = 0, crc = st_crc32(raw, len);
a[n++] = 0; a[n++] = (uint8_t)id; n += put5(a + n, len); n += put5(a + n, crc);
cmdv(ED_BK_PUT, a, n);
while (pos < len) {
uint32_t k = 1 + rn(256);
if (k > len - pos) k = len - pos;
n = 0;
a[n++] = 1; a[n++] = (uint8_t)id; n += put5(a + n, pos);
n += pack7(a + n, raw + pos, k);
cmdv(ED_BK_PUT, a, n);
pos += k;
if (rn(200) == 0) break; /* (cut off) */
}
a[0] = rn(30) ? 2 : 3; a[1] = (uint8_t)id;
cmdv(ED_BK_PUT, a, 2);
}
/* random project content, the sum right */
static void proj_random(project_t *p)
{
uint32_t i;
if (rn(2)) {
proj_capture(p);
mutate((uint8_t *)p + 8, sizeof *p - 12);
if (rn(2)) {
uint32_t k = 4 + rn(60);
for (i = 0; i < k; i++) ((uint8_t *)p)[8 + rn(sizeof *p - 12)] = (uint8_t)rn(256);
}
} else {
rbytes((uint8_t *)p, sizeof *p, 1);
}
p->magic = PROJ_MAGIC;
p->size = sizeof *p;
p->sum = proj_sum(p);
}
static void projv_random(uint8_t *b, uint32_t *len)
{
static const uint32_t SZ[5] = {sizeof(project_v5_t), sizeof(project_v4_t), sizeof(project_v3_t), sizeof(project_v2_t), sizeof(project_v1_t)};
static const uint32_t MG[5] = {PROJ_MAGIC_V5, PROJ_MAGIC_V4, PROJ_MAGIC_V3, PROJ_MAGIC_V2, PROJ_MAGIC_V1};
uint32_t v = rn(5), n = SZ[v];
rbytes(b, n, 1);
if (rn(2)) { /* mostly plausible values */
uint32_t i;
for (i = 8; i < n - 4; i += 2) { b[i] = (uint8_t)rn(130); b[i + 1] = rn(8) ? 0 : (uint8_t)rn(256); }
}
((uint32_t *)b)[0] = MG[v];
((uint32_t *)b)[1] = n;
*(uint32_t *)(b + n - 4) = proj_hash(b, n - 4);
*len = n;
}
static void smp_upload(uint32_t k)
{
uint8_t a[700], hdr[512];
smp_user_hdr_t *h = (smp_user_hdr_t *)hdr;
uint32_t n, data_len = 256u * (1 + rn(40)), off, i;
if (rn(8)) { a[0] = (uint8_t)k; cmdv(ED_SMP_BEGIN, a, 1); }
for (off = 0; off < data_len; off += 256) {
uint8_t d[256];
uint32_t o = SMP_USER_DATA + off;
if (rn(40) == 0) continue; /* (a lost write) */
rbytes(d, 256, 1);
n = 0;
a[n++] = (uint8_t)k; a[n++] = o & 127u; a[n++] = (o >> 7) & 127u; a[n++] = (o >> 14) & 127u;
n += pack7(a + n, d, 256);
cmdv(ED_SMP_WRITE, a, n);
if (rn(30) == 0) aud(1 + rn(4));
}
memset(hdr, 0, sizeof hdr);
h->magic = SMP_USER_MAGIC; h->version = 1; h->nz = (uint8_t)(1 + rn(16));
memcpy(h->name, "FUZZ", 4);
h->data_len = data_len;
for (i = 0; i < h->nz; i++) {
smp_zone_t *z = &h->zone[i];
uint32_t zo = rn(data_len), maxn = 2u * (data_len - zo);
z->off = zo; z->n = 1 + rn(maxn); z->le = rn(z->n); z->ls = rn(z->le + 1);
z->rate = 1 + rn(4u << 16); z->root16 = (int16_t)(rn(128) * 16); z->pred = (int16_t)rval(); z->idx = (uint8_t)rn(89);
z->lo = (uint8_t)rn(128); z->hi = (uint8_t)(z->lo + rn(128 - z->lo)); z->looped = (uint8_t)rn(3);
}
h->crc = st_crc32(nor + SMP_USER_OFF(k) + SMP_USER_DATA, data_len);
if (rn(6) == 0) mutate(hdr, sizeof(smp_user_hdr_t));
for (i = 0; i < 16; i++) if (h->zone[i].root16 < 0 || h->zone[i].root16 > 2032) h->zone[i].root16 = 960; /* (drums.c drum_on, reported) */
n = 0;
a[n++] = (uint8_t)k;
n += pack7(a + n, hdr, sizeof(smp_user_hdr_t));
cmdv(ED_SMP_END, a, n);
}
static void up_put_rand(void)
{
uint8_t a[700];
uint32_t n = 0, i, nl = 1 + rn(12);
a[n++] = (uint8_t)rn(36); a[n++] = (uint8_t)rn(NENGINES + 2);
for (i = 0; i < nl; i++) a[n++] = (uint8_t)(32 + rn(95));
a[n++] = 0;
for (i = 0; i < P_COUNT; i++) n += v14(a + n, rval());
for (i = 0; i < 32; i++) a[n++] = (uint8_t)rn(128);
if (rn(5) == 0) n = rn(n + 3);
cmdv(ED_UP_PUT, a, n);
}
static void cmd_rand(int bit8)
{
static const uint8_t CMDS[] = {ED_INFO, ED_GET, ED_SET, ED_DUMP, ED_DESC, ED_STEP_GET, ED_STEP_SET, ED_PRESET, ED_PROJECT,
ED_NAMES, ED_SMP_BEGIN, ED_SMP_WRITE, ED_SMP_END, ED_SMP_ERASE, ED_SMP_INFO, ED_UP_LIST, ED_UP_GET, ED_UP_PUT,
ED_UP_STORE, ED_UP_LOAD, ED_UP_ERASE, ED_WATCH, ED_CHANGED, ED_RELOAD, ED_PING, ED_STEP_CHANGED, ED_TRACK,
ED_TRACK_MIX, ED_TRACK_DUMP, ED_TRACK_STEP, ED_TRACK_PARAM, ED_TRACK_CHANGED, ED_DRUM_STEP, ED_BK_LIST, ED_BK_GET,
ED_BK_PUT, ED_LOCK_GET, ED_LOCK_SET, ED_MICRO_GET, ED_MICRO_SET, ED_FILL_GET, ED_FILL_SET, ED_FM6_GET, ED_FM6_PUT,
ED_FM6_LIST, ED_FM6_ERASE, 72, 73, 74, 75, 76, ED_LIVE};
static const uint32_t EXP[128] = {[ED_GET] = 2, [ED_SET] = 4, [ED_DESC] = 2, [ED_STEP_GET] = 1, [ED_STEP_SET] = 12,
[ED_PRESET] = 2, [ED_PROJECT] = 2, [ED_NAMES] = 1, [ED_SMP_BEGIN] = 1, [ED_SMP_WRITE] = 300, [ED_SMP_END] = 550,
[ED_SMP_ERASE] = 1, [ED_UP_LIST] = 2, [ED_UP_GET] = 1, [ED_UP_PUT] = 3 + 13 + 2 * P_COUNT + 32, [ED_UP_STORE] = 6,
[ED_UP_LOAD] = 1, [ED_UP_ERASE] = 1, [ED_WATCH] = 1, [ED_TRACK] = 1, [ED_TRACK_MIX] = 4, [ED_TRACK_DUMP] = 1,
[ED_TRACK_STEP] = 13, [ED_TRACK_PARAM] = 4, [ED_DRUM_STEP] = 14, [ED_BK_GET] = 8, [ED_BK_PUT] = 12,
[ED_LOCK_GET] = 1, [ED_LOCK_SET] = 5, [ED_MICRO_GET] = 1, [ED_MICRO_SET] = 3, [ED_FILL_GET] = 1, [ED_FILL_SET] = 3,
[ED_FM6_GET] = 2, [ED_FM6_PUT] = 130, [ED_FM6_ERASE] = 1, [73] = 1, [74] = 24, [76] = 3, [ED_LIVE] = 5};
uint8_t f[700];
uint32_t cmd = rn(10) == 0 ? rn(bit8 ? 256 : 128) : CMDS[rn(sizeof CMDS)], e = cmd < 128 ? EXP[cmd] : 0, na, i;
switch (rn(8)) {
case 0: na = 0; break;
case 1: na = 1; break;
case 2: na = e ? e - 1 : 2; break;
case 3: na = e + 1; break;
case 4: na = rn(640 - 4 + 1); break;
case 5: na = rn(20); break;
default: na = e; break;
}
if (na > 636) na = 636;
f[0] = ED_HDR0; f[1] = ED_HDR1; f[2] = ED_HDR2; f[3] = (uint8_t)cmd;
for (i = 0; i < na; i++) {
uint32_t r = rn(10);
f[4 + i] = (uint8_t)(r < 3 ? rn(8) : r < 5 ? 127 - rn(4) : r < 6 && bit8 ? 128 + rn(128) : rn(bit8 && rn(8) == 0 ? 256 : 128));
}
if ((cmd == ED_SET || cmd == ED_GET || cmd == ED_DESC) && na >= 2 && rn(2)) { f[4] = (uint8_t)rn(2); f[5] = (uint8_t)rn(f[4] ? G_COUNT + 2 : P_COUNT + 2); }
if (cmd == ED_SET && na >= 4 && rn(2)) v14(f + 6, rval());
if (cmd == ED_LIVE && na >= 1 && rn(2)) f[4] = (uint8_t)rn(14);
if ((cmd == ED_TRACK_PARAM || cmd == ED_LOCK_SET) && na >= 3 && rn(2)) { f[4] = (uint8_t)rn(NTRK); f[5] = (uint8_t)rn(cmd == ED_LOCK_SET ? NSTEP : P_COUNT); }
if (cmd == ED_LOCK_SET && na >= 5 && rn(2)) { f[6] = (uint8_t)rn(P_COUNT); v14(f + 7, rval()); }
if (cmd == ED_TRACK_PARAM && na >= 4 && rn(2)) v14(f + 6, rval());
if (bit8)
frame(f, 4 + na, 0);
else
frame(f, 4 + na, rn(3) == 0);
}
static void play_slots(void);
static void fz_seq_step(void)
{
uint8_t a[700], raw[4096];
uint32_t n, len, r = rn(100);
if (r < 15) { cmd_rand(0); return; }
if (r < 30) { ui_rand(); return; }
if (r < 35) { aud(1 + rn(30)); return; }
if (r < 38) { smp_upload(rn(SMP_USER_SLOTS)); return; }
if (r < 40) { /* out of order sample commands */
uint32_t k = rn(SMP_USER_SLOTS + 1), c = ED_SMP_BEGIN + rn(5);
n = 0; a[n++] = (uint8_t)k;
if (c == ED_SMP_WRITE) { uint32_t o = rn(2) ? SMP_USER_DATA + 256 * rn(300) : rn(1u << 21); uint8_t d[256]; a[n++] = o & 127; a[n++] = (o >> 7) & 127; a[n++] = (o >> 14) & 127; rbytes(d, 256, 1); n += pack7(a + n, d, 1 + rn(256)); }
if (c == ED_SMP_END) { uint8_t d[480]; rbytes(d, 480, 1); n += pack7(a + n, d, rn(2) ? 480 : rn(480)); }
cmdv(c, a, n);
return;
}
if (r < 45) { cmdv(ED_BK_LIST, a, 0); return; }
if (r < 48) { /* GET of a random object */
uint32_t id = rn(2) ? rn(12) : 32 + rn(5), off = rn(2) ? 0 : rn(4096), cnt = 1 + rn(256);
n = 0; a[n++] = (uint8_t)id; n += put5(a + n, off); a[n++] = cnt & 127; a[n++] = (uint8_t)(cnt >> 7);
cmdv(ED_BK_GET, a, n);
return;
}
if (r < 58) { /* restore an object */
uint32_t id = rn(12);
switch (id) {
case 0: case 2: case 3: case 4: case 5:
if (rn(3)) { proj_random((project_t *)raw); len = sizeof(project_t); }
else projv_random(raw, &len);
if (id && rn(10) == 0) len = 0;
break;
case 1: persist_fill((persist_t *)raw); len = sizeof(persist_t); if (rn(2)) mutate(raw + 4, len - 4); break;
case 6: case 7: {
up_bank_t *b = (up_bank_t *)raw;
uint32_t i;
rbytes(raw, sizeof *b, 1);
b->magic = UP_BANK_MAGIC; b->rsize = sizeof(up_rec_t); b->nslot = UP_PER_BANK;
for (i = 0; i < UP_PER_BANK; i++)
if (rn(2)) { b->r[i].used = UP_USED; b->r[i].ver = UP_VER; b->r[i].engine = (uint8_t)rn(NENGINES); b->r[i].np = (uint8_t)(8 + rn(UP_PMAX - 7)); b->r[i].name[0] = 'A'; }
len = rn(10) ? sizeof *b : 0;
break;
}
case 8: {
fm6_bank_t *b = (fm6_bank_t *)raw;
rbytes(raw, sizeof *b, 0);
b->magic = FM6_BANK_MAGIC; b->ver = 1; b->nslot = FM6_BANK_N; b->used = rn(1u << 27); b->rsv = 0;
len = rn(10) ? sizeof *b : 0;
break;
}
case 9: {
dsu_bank_t *b = (dsu_bank_t *)raw;
rbytes(raw, sizeof *b, 1);
b->magic = DSU_MAGIC; b->ver = 1; b->n = DSU_N;
len = sizeof *b;
break;
}
case 10: rbytes(raw, MIDI_PART, 1); len = rn(2) ? MIDI_PART : rn(2) ? 2 * ML_N : 2 * ML_N + 4; break;
case 11: {
theme_t *t = (theme_t *)raw;
rbytes(raw, sizeof *t, 1);
t->magic = rn(4) ? THEME_MAGIC : THEME_MAGIC1;
t->crc = st_crc32(t, 36);
len = rn(8) ? (t->magic == THEME_MAGIC ? sizeof *t : 36) : 0;
break;
}
default: len = 0;
}
bk_restore(id, raw, len);
return;
}
if (r < 62) { up_put_rand(); return; }
if (r < 64) { n = 0; a[n++] = (uint8_t)rn(34); a[n++] = 'X'; a[n++] = 0; cmdv(ED_UP_STORE, a, rn(3)); return; }
if (r < 67) { a[0] = (uint8_t)rn(34); cmdv(rn(3) ? ED_UP_LOAD : ED_UP_ERASE, a, 1); return; }
if (r < 71) { /* an FM6 patch */
n = 0; a[n++] = (uint8_t)rn(3); a[n++] = (uint8_t)rn(30);
rbytes(a + n, 128, 0); n += 128;
cmdv(ED_FM6_PUT, a, n);
return;
}
if (r < 75) { /* a SYN kit edit */
uint8_t d[400];
uint32_t part = rn(18), m = part < 16 ? sizeof(dsnd_t) : part == 16 ? 10 : 1;
n = 0; a[n++] = (uint8_t)rn(5); a[n++] = (uint8_t)part;
rbytes(d, m, 1);
if (part == 17) d[0] = (uint8_t)rn(DS_NKITS + 1);
n += pack7(a + n, d, m);
cmdv(74, a, n);
if (rn(3) == 0) { a[0] = (uint8_t)rn(4); a[1] = (uint8_t)rn(16); a[2] = (uint8_t)rn(128); cmdv(76, a, 3); }
return;
}
if (r < 82) { /* LIVE */
n = 0; a[n++] = (uint8_t)rn(14);
{ uint32_t i, k = rn(8); for (i = 0; i < k; i++) a[n++] = (uint8_t)(rn(3) ? rn(8) : rn(128)); }
cmdv(ED_LIVE, a, n);
return;
}
if (r < 85) { a[0] = (uint8_t)rn(NENGINES + 1); a[1] = (uint8_t)rn(64); cmdv(ED_PRESET, a, 2); return; }
if (r < 87) { a[0] = (uint8_t)rn(3); a[1] = (uint8_t)rn(4); cmdv(ED_PROJECT, a, 2); return; }
if (r < 89) { a[0] = (uint8_t)rn(NTRK); cmdv(ED_TRACK, a, 1); return; }
if (r < 92) { a[0] = 1; a[1] = G_ENGSEL; v14(a + 2, (int32_t)rn(NENGINES + 2)); cmdv(ED_SET, a, 4); return; }
if (r < 95) { a[0] = (uint8_t)rn(NTRK); a[1] = (uint8_t)rn(NSTEP); a[2] = (uint8_t)rn(P_COUNT); v14(a + 3, rval()); cmdv(ED_LOCK_SET, a, 5); return; }
if (r < 97) { a[0] = (uint8_t)(rn(2)); cmdv(ED_WATCH, a, 1); a[0] = 3; cmdv(ED_WATCH, a, 1); return; }
if (r < 99) { play_slots(); return; }
{ uint32_t i; for (i = 0; i < 60; i++) ui_rand(); }
}
static uint32_t eng_by_name(const char *n) { uint32_t e; for (e = 0; e < NENGINES; e++) if (!strcmp(ENGINES[e]->name, n)) return e; return 0; }
/* the user sample slots played: SAMPLE / GRAIN on a part, the drum kit USRn, the TEXTURE bed, notes and the transport */
static void play_slots(void)
{
uint8_t a[16];
uint32_t t = rn(NPART), e = rn(2) ? eng_by_name("SAMPLE") : eng_by_name("GRAIN"), i;
a[0] = (uint8_t)t; cmdv(ED_TRACK, a, 1);
a[0] = (uint8_t)e; a[1] = (uint8_t)rn(8); cmdv(ED_PRESET, a, 2);
a[0] = (uint8_t)t; a[1] = P_E0; v14(a + 2, (int32_t)(SMP_NSETS + rn(SMP_USER_SLOTS))); cmdv(ED_TRACK_PARAM, a, 4);
a[0] = TRK_DRUM; a[1] = P_E0; v14(a + 2, (int32_t)(DRUM_USR + rn(5))); cmdv(ED_TRACK_PARAM, a, 4);
a[0] = 1; a[1] = G_TXSRC; v14(a + 2, (int32_t)(7 + rn(4))); cmdv(ED_SET, a, 4);
a[0] = 1; a[1] = G_TXWHEN; v14(a + 2, 1); cmdv(ED_SET, a, 4);
if (rn(2)) { a[0] = 1; a[1] = 1; cmdv(ED_LIVE, a, 2); }
for (i = 0; i < 6; i++) {
uint8_t b[4] = {9, (uint8_t)(0x90 | (rn(2) ? t : 9)), (uint8_t)rn(128), (uint8_t)(1 + rn(127))};
logop(4, b, 4);
ep1_take(b, 4);
aud(2 + rn(10));
if (rn(3) == 0) { b[0] = 8; b[1] = (uint8_t)(0x80 | (b[1] & 15)); logop(4, b, 4); ep1_take(b, 4); }
}
}
static void uart_rand(void)
{
uint32_t k = 1 + rn(24), i;
uint8_t b[24];
for (i = 0; i < k; i++) {
uint32_t r = rn(10);
b[i] = (uint8_t)(r < 2 ? 0x80 + rn(0x80) : r < 3 ? 0xF8 + rn(8) : r < 4 ? 0xF0 + rn(8) : rn(128));
um_byte(b[i]);
}
logop(5, b, k);
}
/* ---- MODE 3: a boot from a damaged / foreign flash (and .noinit RAM): every object a valid storage record (its CRC
* right) with random or mutated content of the lengths the loaders look for, damaged copies, random sample headers;
* then the boot (persist_boot, settings_init, panel_init, felucca_init's part) and use */
static void st_put(uint32_t obj, const void *p, uint32_t n)
{
if (rn(12) == 0) { /* a torn write: the header or the payload damaged */
fl_fail_at = (int)(1 + rn(8));
(void)st_save(obj, p, n);
fl_fail_at = -1;
return;
}
(void)st_save(obj, p, n);
if (rn(3) == 0) (void)st_save(obj, p, n); /* both copies */
}
static void slot_random(uint32_t k)
{
uint8_t *img = nor + SMP_USER_OFF(k);
smp_user_hdr_t *h = (smp_user_hdr_t *)img;
uint32_t i, data_len = rn(4) ? rn(SMP_USER_SIZE - SMP_USER_DATA + 1) : rn(4096);
if (rn(3) == 0) return;
memset(img, 0xFF, SMP_USER_SIZE);
for (i = 0; i < data_len; i += 64) img[SMP_USER_DATA + i] = (uint8_t)rn(256);
rbytes(img, sizeof *h, 1);
h->magic = SMP_USER_MAGIC; h->version = 1; h->nz = (uint8_t)(1 + rn(16)); h->data_len = data_len;
for (i = 0; i < h->nz; i++) {
smp_zone_t *z = &h->zone[i];
if (rn(4) == 0) continue; /* (random: refused) */
z->off = data_len ? rn(data_len) : 0; z->n = data_len ? 1 + rn(2u * (data_len - z->off)) : 0;
z->le = z->n ? rn(z->n) : 0; z->ls = rn(z->le + 1); z->rate = 1 + rn(4u << 16); z->idx = (uint8_t)rn(89);
z->lo = (uint8_t)rn(128); z->hi = (uint8_t)(z->lo + rn(128 - z->lo));
z->root16 = (int16_t)(rn(128) * 16); /* (a root outside the notes: drums.c drum_on, reported) */
}
if (rn(5) == 0) mutate(img, sizeof *h);
for (i = 0; i < 16; i++) if (h->zone[i].root16 < 0 || h->zone[i].root16 > 2032) h->zone[i].root16 = 960; /* (see above) */
}
static void flash_random(void)
{
static uint8_t raw[4096];
uint32_t i, len;
memset(nor, 0xFF, sizeof nor);
flash_ok = 1;
if (rn(2)) { /* the settings (+ SYN kits + MIDI part), a side record */
persist_t *ps = (persist_t *)raw;
dsu_bank_t *db = (dsu_bank_t *)(raw + sizeof(persist_t));
side_rec_t sr;
persist_fill(ps);
if (rn(3) == 0) mutate(raw, sizeof *ps);
if (rn(4) == 0) rbytes(raw + 4, sizeof *ps - 4, 1);
if (rn(2)) ps->arrangement.count = (uint8_t)rn(20);
rbytes((uint8_t *)db, sizeof *db, 1);
db->magic = DSU_MAGIC; db->ver = 1; db->n = DSU_N;
rbytes(raw + sizeof(persist_t) + sizeof(dsu_bank_t), MIDI_PART, 1);
{
static const uint32_t L[] = {sizeof(persist_t), PERSIST_SIZE_V22, 16u + sizeof(panel_t), 8u + sizeof(panel_t),
sizeof(persist_t) + sizeof(dsu_bank_t), sizeof(persist_t) + sizeof(dsu_bank_t) + 2 * ML_N,
sizeof(persist_t) + sizeof(dsu_bank_t) + 2 * ML_N + 4, sizeof(persist_t) + sizeof(dsu_bank_t) + MIDI_PART};
len = L[rn(NELEM(L))];
}
if (len == 16u + sizeof(panel_t)) ps->magic = 0x50455232u;
if (len == 8u + sizeof(panel_t)) ps->magic = 0x50455231u;
rbytes((uint8_t *)&sr, sizeof sr, 1);
sr.th.magic = rn(2) ? THEME_MAGIC : THEME_MAGIC1; sr.th.crc = st_crc32(&sr.th, 36);
sr.fmagic = FAVS_MAGIC; sr.fcrc = st_crc32(&sr.fmagic, 4u + sizeof sr.fav);
st_side = &sr; st_side_len = rn(4) ? sizeof sr : rn(sizeof sr);
st_put(OBJ_SETTINGS, raw, len);
st_side = 0;
}
for (i = 0; i < 5; i++) { /* the projects and the autosave */
uint32_t obj = i < 4 ? OBJ_PROJECT0 + i : OBJ_AUTOSAVE;
if (rn(3) == 0) continue;
if (rn(3)) { proj_random((project_t *)raw); len = sizeof(project_t); }
else projv_random(raw, &len);
if (rn(10) == 0) len = rn(len + 1);
st_put(obj, raw, len);
}
for (i = 0; i < 2; i++) { /* the user preset banks */
up_bank_t *b = (up_bank_t *)raw;
uint32_t j;
if (rn(3) == 0) continue;
rbytes(raw, sizeof *b, 1);
b->magic = UP_BANK_MAGIC; b->rsize = sizeof(up_rec_t); b->nslot = UP_PER_BANK;
for (j = 0; j < UP_PER_BANK; j++)
if (rn(2)) { b->r[j].used = UP_USED; b->r[j].ver = UP_VER; b->r[j].engine = (uint8_t)rn(NENGINES); b->r[j].np = (uint8_t)(8 + rn(UP_PMAX - 7)); b->r[j].name[0] = (char)(32 + rn(95)); }
st_put(OBJ_UPRESET0 + i, raw, rn(10) ? sizeof *b : rn(sizeof *b));
}
if (rn(2)) { /* the FM6 bank */
fm6_bank_t *b = (fm6_bank_t *)raw;
rbytes(raw, sizeof *b, 0);
b->magic = FM6_BANK_MAGIC; b->ver = 1; b->nslot = FM6_BANK_N; b->used = rn(1u << 27); b->rsv = 0;
st_put(OBJ_FM6BANK, raw, sizeof *b);
}
for (i = 0; i < SMP_USER_SLOTS; i++) slot_random(i);
for (i = 0; i < 4; i++) { /* .noinit: garbage, or a valid project (a warm reset) */
if (rn(2)) rbytes((uint8_t *)&proj_slot[i], sizeof proj_slot[i], 1);
else proj_random(&proj_slot[i]);
}
if (rn(30) == 0) { /* random bytes over a few sectors */
uint32_t k = rn(8);
for (i = 0; i < k; i++) nor[0x97000 + rn(0x100000 - 0x97000)] = (uint8_t)rn(256);
}
}
static void boot(void)
{
uint32_t i;
logop(6, 0, 0);
flash_random();
memset(&settings, 0, sizeof settings);
if (rn(2)) rbytes((uint8_t *)&settings, sizeof settings, 1);
persist_boot();
settings_init();
panel_init();
for (i = 0; i < G_COUNT; i++) song.g[i] = GP[i].def;
fm6_init();
for (i = 0; i < NTRK; i++) {
track_t *t = &trk[i];
track_defaults(t);
if (i < NPART) { set_engine_of(t, TRK_DEF[i][0]); apply_preset_to(t, TRK_DEF[i][1]); t->engine = t->eng_req; }
track_defaults_steps(t);
}
TDRUM->p[P_E0] = DRUM_DEFAULT_KIT;
song.sel = 0;
autosave_resume();
song.g[G_SYNC] = (int16_t)lights_sync; song.g[G_MIDI] = (int16_t)lights_mout; song.g[G_ROUTE] = (int16_t)lights_min;
song.g[G_CH1] = midi_set[0], song.g[G_CH2] = midi_set[1], song.g[G_CH3] = midi_set[2];
song.g[G_DRCH] = midi_set[3], song.g[G_CHOTH] = midi_set[4], song.g[G_BEND] = midi_set[5];
song.g[G_FXCH] = midi_set[6]; song.g[G_DRMAP] = midi_set[7]; song.g[G_CLKOUT] = midi_set[9]; song.g[G_RMCH] = midi_set[8];
song.g[G_FXFADE] = fxfade;
layers_init();
go_home();
ui.force = 1;
after();
}
/* ---- MODE 4: every command over every engine / track / id / step at the edges, deterministic; a reply that fills
* ed_out (cut short) is reported */
static uint32_t cut_replies;
static void xcmd(uint32_t cmd, const uint8_t *a, uint32_t na)
{
uint8_t f[700];
f[0] = ED_HDR0; f[1] = ED_HDR1; f[2] = ED_HDR2; f[3] = (uint8_t)cmd;
memcpy(f + 4, a, na);
logop(0, f, 4 + na);
ed_inject(f, 4 + na);
if (ed_n >= sizeof ed_out - 1u) {
cut_replies++;
printf("reply cut short: cmd %u args", cmd);
{ uint32_t i; for (i = 0; i < na && i < 8; i++) printf(" %u", a[i]); }
printf(" (%u bytes)\n", ed_n);
}
after();
}
static void exhaustive(void)
{
static const int32_t V[] = {-8192, -1, 0, 1, 63, 64, 127, 128, 8191};
uint8_t a[700];
uint32_t e, p, id, t, st, v, sc;
for (e = 0; e <= NENGINES; e++) {
a[0] = (uint8_t)e; xcmd(ED_NAMES, a, 1);
for (p = 0; e < NENGINES && p < ENGINES[e]->npresets + 2u; p++) {
a[0] = 0; xcmd(ED_TRACK, a, 1);
a[0] = (uint8_t)e; a[1] = (uint8_t)p; xcmd(ED_PRESET, a, 2);
aud(4);
}
for (id = 0; id < P_COUNT + 2u; id++) {
a[0] = 0; a[1] = (uint8_t)id; xcmd(ED_DESC, a, 2); xcmd(ED_GET, a, 2);
for (v = 0; v < NELEM(V); v++) { a[0] = 0; a[1] = (uint8_t)id; v14(a + 2, V[v]); xcmd(ED_SET, a, 4); }
for (t = 0; t < NTRK; t++)
for (v = 0; v < NELEM(V); v++) { a[0] = (uint8_t)t; a[1] = (uint8_t)id; v14(a + 2, V[v]); xcmd(ED_TRACK_PARAM, a, 4); }
aud(2);
{ uint32_t f2; for (f2 = 0; f2 < 3; f2++) ui_frame(); }
}
if (e < NENGINES) { a[0] = 0; a[1] = 0; xcmd(ED_PRESET, a, 0); }
}
for (sc = 0; sc < 2; sc++)
for (id = 0; id < G_COUNT + 2u; id++) {
a[0] = (uint8_t)sc; a[1] = (uint8_t)id; xcmd(ED_DESC, a, 2);
if (sc == 1 && (id == G_ENGSEL)) continue;
for (v = 0; v < NELEM(V); v++) { a[0] = (uint8_t)sc; a[1] = (uint8_t)id; v14(a + 2, V[v]); xcmd(ED_SET, a, 4); aud(1); }
}
a[0] = TRK_DRUM; xcmd(ED_TRACK, a, 1);
for (id = 0; id < P_COUNT; id++) { a[0] = 0; a[1] = (uint8_t)id; xcmd(ED_DESC, a, 2); }
for (t = 0; t <= NTRK; t++) {
a[0] = (uint8_t)(t % NTRK); xcmd(ED_TRACK, a, 1);
for (st = 0; st < NSTEP + 1; st++) {
uint8_t b[16];
uint32_t k;
for (k = 0; k < 13; k++) b[k] = (uint8_t)(k & 1 ? 127 : st);
b[0] = (uint8_t)t; b[1] = (uint8_t)st; xcmd(ED_TRACK_STEP, b, 13);
b[0] = (uint8_t)st; xcmd(ED_STEP_SET, b, 12);
b[0] = (uint8_t)st; for (k = 1; k < 14; k++) b[k] = 127; xcmd(ED_DRUM_STEP, b, 14);
b[0] = (uint8_t)t; b[1] = (uint8_t)st; b[2] = 127; xcmd(ED_MICRO_SET, b, 3); b[2] = 0; xcmd(ED_MICRO_SET, b, 3);
b[2] = (uint8_t)st; xcmd(ED_FILL_SET, b, 3);
for (id = 0; id < P_COUNT + 1; id += 7) { b[0] = (uint8_t)t; b[1] = (uint8_t)st; b[2] = (uint8_t)id; v14(b + 3, st & 1 ? 8191 : -8192); xcmd(ED_LOCK_SET, b, 5); }
}
a[0] = (uint8_t)t; xcmd(ED_LOCK_GET, a, 1); xcmd(ED_MICRO_GET, a, 1); xcmd(ED_FILL_GET, a, 1); xcmd(ED_TRACK_DUMP, a, 1);
a[0] = 1; a[1] = 1; xcmd(ED_LIVE, a, 2); aud(200); a[1] = 0; xcmd(ED_LIVE, a, 2); aud(20);
}
for (p = 0; p < 3; p++)
for (id = 0; id < 40; id++) { a[0] = (uint8_t)p; a[1] = (uint8_t)id; xcmd(ED_FM6_GET, a, 2); }
xcmd(ED_FM6_LIST, a, 0);
for (id = 0; id < 128; id++) { a[0] = (uint8_t)id; xcmd(73, a, 1); }
xcmd(72, a, 0);
for (id = 0; id < 128; id++) { a[0] = (uint8_t)id; a[1] = 2; xcmd(ED_UP_LIST, a, 2); a[0] = (uint8_t)id; xcmd(ED_UP_GET, a, 1); }
xcmd(ED_BK_LIST, a, 0);
for (id = 0; id < 128; id++) {
uint32_t off;
for (off = 0; off < 0x14200; off += 256) {
uint32_t n = 0;
a[n++] = (uint8_t)id; n += put5(a + n, off); a[n++] = 0; a[n++] = 2;
xcmd(ED_BK_GET, a, n);
if (a[0] && id != 0 && rx_n > 0 && rx_last[6] != 0) break; /* (past its end) */
}
}
xcmd(ED_SMP_INFO, a, 0); xcmd(ED_INFO, a, 0); xcmd(ED_DUMP, a, 0); a[0] = 0; xcmd(ED_TRACK, a, 0);
for (p = 0; p < 16; p++)
for (id = 0; id < 130; id += 1) {
a[0] = (uint8_t)p; a[1] = (uint8_t)id; a[2] = (uint8_t)(id * 7); a[3] = (uint8_t)(id & 1); a[4] = (uint8_t)(id >> 1);
a[5] = 1; a[6] = 2; a[7] = 3;
xcmd(ED_LIVE, a, 2 + (id % 7));
if (id % 16 == 0) aud(8);
}
printf("exhaustive: %u replies cut short\n", cut_replies);
}
/* ---- MODE 5: MIDI in only (USB packets and TRS bytes), then every note let go on every channel (and the pedal up):
* after 4 s no voice may still be held */
static void midi_let_go(void)
{
uint32_t ch, n;
for (ch = 0; ch < 16; ch++) {
uint8_t b[4] = {0x0B, (uint8_t)(0xB0 | ch), 64, 0};
while (!ep1_take(b, 4)) audio_blocks(1);
for (n = 0; n < 128; n++) {
uint8_t o[4] = {0x08, (uint8_t)(0x80 | ch), (uint8_t)n, 0};
while (!ep1_take(o, 4)) audio_blocks(1);
}
audio_blocks(2);
}
audio_blocks(4u * FS / CTL);
}
static int midi_hang_check(void)
{
uint32_t k, v, bad = 0;
for (k = 0; k < NPART; k++)
for (v = 0; v < NVOICE; v++)
if (trk[k].v[v].active && trk[k].v[v].gate) {
fprintf(stderr, "held: track %u voice %u note %u (arp mode %d hold %d, voice mode %d, nheld %u)\n", k, v,
trk[k].v[v].note, trk[k].p[P_AMODE], trk[k].p[P_AHOLD], trk[k].p[P_VOICE], trk[k].nheld);
bad++;
}
return bad == 0;
}
/* ---- MODE 6: round trips. After random use (stopped): the working project captured (project.c proj_capture), then
* (a) the editor's backup of object 0 read (LIST, GET) and restored (PUT, commit), (b) saved to a section and loaded,
* (c) the autosave written and resumed: each must give back the same project, byte for byte */
static project_t rt_a, rt_b;
static const char *proj_field(uint32_t off)
{
static char b[96];
uint32_t t0 = (uint32_t)offsetof(project_t, t), ts = sizeof(proj_trk_t);
if (off < t0) { snprintf(b, sizeof b, "header/globals byte %u (g[%u])", off, off >= 8 ? (off - 8) / 2 : 0); return b; }
if (off >= t0 + NTRK * ts) { snprintf(b, sizeof b, "sum"); return b; }
{
uint32_t k = (off - t0) / ts, o = (off - t0) % ts;
if (o < offsetof(proj_trk_t, e)) snprintf(b, sizeof b, "track %u p[%u]", k, o / 2);
else if (o < offsetof(proj_trk_t, x)) snprintf(b, sizeof b, "track %u e[%u]", k, (o - (uint32_t)offsetof(proj_trk_t, e)) / 2);
else if (o < offsetof(proj_trk_t, engine)) snprintf(b, sizeof b, "track %u x[%u] (p[%u])", k, o - (uint32_t)offsetof(proj_trk_t, x), PROJ_NC6 + o - (uint32_t)offsetof(proj_trk_t, x));
else if (o < offsetof(proj_trk_t, step)) snprintf(b, sizeof b, "track %u engine/preset", k);
else if (o < offsetof(proj_trk_t, mf)) snprintf(b, sizeof b, "track %u step %u byte %u", k, (o - (uint32_t)offsetof(proj_trk_t, step)) / 10, (o - (uint32_t)offsetof(proj_trk_t, step)) % 10);
else if (o < offsetof(proj_trk_t, lock)) snprintf(b, sizeof b, "track %u mf[%u]", k, o - (uint32_t)offsetof(proj_trk_t, mf));
else snprintf(b, sizeof b, "track %u lock %u", k, (o - (uint32_t)offsetof(proj_trk_t, lock)) / 4);
}
return b;
}
static int rt_cmp(const char *what)
{
uint32_t i, nd = 0;
const uint8_t *x = (const uint8_t *)&rt_a, *y = (const uint8_t *)&rt_b;
static const uint8_t SETTING[] = {G_SLOT, G_LOAD, G_SYNC, G_MIDI, G_ROUTE}; /* (in a project, not loaded: the FM-1's) */
for (i = 0; i < sizeof SETTING; i++) rt_b.g[SETTING[i]] = rt_a.g[SETTING[i]];
for (i = 0; i < sizeof rt_a - 4; i++)
if (x[i] != y[i]) {
if (nd < 6) fprintf(stderr, "%s: %s: %02X -> %02X\n", what, proj_field(i), x[i], y[i]);
nd++;
}
if (nd) fprintf(stderr, "%s: %u bytes differ\n", what, nd);
return nd == 0;
}
static void stop_all(void)
{
uint8_t a[2] = {1, 0};
cmdv(ED_LIVE, a, 2);
transport_req = 2;
audio_blocks(20);
arrangement_enabled = 0;
}
static void midi_rand(void);
static void scramble(void) /* other use in between (stopped after) */
{
uint32_t j, k = 5 + rn(40);
for (j = 0; j < k; j++) {
uint32_t r = rn(10);
if (r < 5) fz_seq_step(); else if (r < 8) ui_rand(); else midi_rand();
}
stop_all();
}
/* other edits that never write a section, the autosave or a backup object (so what was saved is still there) */
static void scramble_light(void)
{
uint8_t a[700];
uint32_t j, k = 5 + rn(40);
for (j = 0; j < k; j++) {
uint32_t r = rn(12), t = rn(NTRK);
switch (r) {
case 0: a[0] = 0; a[1] = (uint8_t)rn(P_COUNT); v14(a + 2, rval()); cmdv(ED_SET, a, 4); break;
case 1: a[0] = (uint8_t)t; a[1] = (uint8_t)rn(P_COUNT); v14(a + 2, rval()); cmdv(ED_TRACK_PARAM, a, 4); break;
case 2: a[0] = (uint8_t)t; a[1] = (uint8_t)rn(NSTEP); rbytes(a + 2, 11, 0); cmdv(ED_TRACK_STEP, a, 13); break;
case 3: a[0] = (uint8_t)rn(NSTEP); rbytes(a + 1, 13, 0); cmdv(ED_DRUM_STEP, a, 14); break;
case 4: a[0] = (uint8_t)t; a[1] = (uint8_t)rn(NSTEP); a[2] = (uint8_t)rn(P_COUNT); v14(a + 3, rval()); cmdv(ED_LOCK_SET, a, rn(4) ? 5 : 3); break;
case 5: a[0] = (uint8_t)t; a[1] = (uint8_t)rn(NSTEP); a[2] = (uint8_t)rn(128); cmdv(ED_MICRO_SET, a, 3); break;
case 6: a[0] = (uint8_t)t; a[1] = (uint8_t)rn(NSTEP); a[2] = (uint8_t)rn(4); cmdv(ED_FILL_SET, a, 3); break;
case 7: a[0] = (uint8_t)rn(NENGINES); a[1] = (uint8_t)rn(32); cmdv(ED_PRESET, a, 2); break;
case 8: a[0] = (uint8_t)t; cmdv(ED_TRACK, a, 1); break;
case 9: a[0] = 1; a[1] = (uint8_t)rn(G_COUNT); if (a[1] == G_SAVE || a[1] == G_LOAD || a[1] == G_NEWPRJ || a[1] == G_CLRSEQ || a[1] == G_INITSND) a[1] = G_BPM; v14(a + 2, rval()); cmdv(ED_SET, a, 4); break;
case 10: a[0] = 12; a[1] = (uint8_t)rn(16); a[2] = (uint8_t)rn(16); a[3] = (uint8_t)rn(8); cmdv(ED_LIVE, a, 4); break;
default: midi_rand(); aud(1); break;
}
}
stop_all();
}
static void bk_read0(uint8_t *raw)
{
uint8_t a[16];
uint32_t off, n;
cmdv(ED_BK_LIST, a, 0);
for (off = 0; off < sizeof(project_t); off += 256) {
uint32_t c = sizeof(project_t) - off > 256 ? 256 : (uint32_t)sizeof(project_t) - off, k, w;
n = 0; a[n++] = 0; n += put5(a + n, off); a[n++] = c & 127; a[n++] = (uint8_t)(c >> 7);
cmdv(ED_BK_GET, a, n);
if (rx_n < 13 || rx_last[6] != 0) { fprintf(stderr, "BK_GET rc %u\n", rx_n > 6 ? rx_last[6] : 99); fail("backup GET"); }
for (k = 14, w = 0; w < c && k < rx_n - 1; ) { /* F0 7D 46 4C 23 id rc off(5) n(2) pack7.. F7 */
uint32_t m = rx_last[k++], j;
for (j = 0; j < 7 && w < c && k < rx_n - 1; j++) raw[off + w++] = (uint8_t)(rx_last[k++] | ((m >> j) & 1u) << 7);
}
}
}
static int bk_restore_ok(const uint8_t *raw)
{
uint32_t tries;
for (tries = 0; tries < 20; tries++) { /* (bk_restore cuts some off at random: again) */
bk_restore(0, raw, sizeof(project_t));
if (rx_n >= 8 && rx_last[5] == 2 && rx_last[7] == 0) return 1; /* (the commit; not an abort) */
stop_all();
}
return 0;
}
static void round_trip(void)
{
static uint8_t raw[sizeof(project_t)];
uint32_t i;
stop_all();
if (song.playing || transport_req) return;
/* the backup of the working project reads as what it is */
proj_capture(&rt_a);
bk_read0(raw);
if (memcmp(raw, &rt_a, sizeof raw)) {
for (i = 0; i < sizeof raw && raw[i] == ((uint8_t *)&rt_a)[i]; i++) ;
fprintf(stderr, "the backup read differs from the capture at %s\n", proj_field(i));
fail("backup GET data");
}
/* restored once (its values put in range), captured: the project as it loads */
if (!bk_restore_ok(raw)) fail("restore of an unchanged backup refused");
audio_blocks(2);
proj_capture(&rt_a);
memcpy(raw, &rt_a, sizeof raw);
/* (a) other use, then that backup restored: the same project */
scramble_light();
if (!bk_restore_ok(raw)) fail("restore refused");
audio_blocks(2);
proj_capture(&rt_b);
if (!rt_cmp("backup -> other use -> restore")) fail("a backup restored does not give the project back");
/* (b) a section saved, other use, loaded (from RAM, or from flash) */
{
uint32_t sl = rn(4);
project_save(sl);
scramble_light();
int lost = rn(2);
if (lost) proj_slot[sl].magic ^= 0xFFu; /* (the RAM copy lost: from flash) */
if (song.playing || transport_req) return;
project_load(sl);
proj_capture(&rt_b);
if (!rt_cmp("section save -> other use -> load (before the audio)")) { fprintf(stderr, "slot %u, %s\n", sl, lost ? "from flash" : "from RAM"); fail("a section saved and loaded is not the same"); }
audio_blocks(2);
proj_capture(&rt_b);
if (!rt_cmp("section save -> other use -> load")) { fprintf(stderr, "slot %u, %s\n", sl, lost ? "from flash" : "from RAM"); fail("a section saved and loaded is not the same"); }
}
/* (c) the autosave, other use, the power-on resume */
(void)st_save(OBJ_AUTOSAVE, &rt_a, sizeof rt_a);
scramble_light();
{ /* (at power-on nothing sounds: autosave_resume switches the engines at once) */
uint32_t k, v;
for (k = 0; k < NTRK; k++) for (v = 0; v < NVOICE; v++) trk[k].v[v].active = trk[k].v[v].gate = 0;
for (v = 0; v < NDRUM; v++) drums.v[v].active = 0;
}
autosave_resume();
audio_blocks(2);
proj_capture(&rt_b);
if (!rt_cmp("autosave -> other use -> resume")) fail("the autosave resumed is not the project saved");
}
/* ---- MODE 2: USB-MIDI in */
static void midi_rand(void)
{
uint32_t cin = rn(16), cable = rn(4) ? 0 : rn(16), ch = rn(16), st, d1, d2, pkt;
switch (rn(10)) {
case 0: st = 0x90 | ch; d1 = rn(128); d2 = rn(3) ? rn(128) : 0; cin = 9; break;
case 1: st = 0x80 | ch; d1 = rn(128); d2 = rn(128); cin = 8; break;
case 2: st = 0xB0 | ch; d1 = rn(4) ? rn(128) : (uint32_t)(98 + rn(4)); d2 = rn(128); cin = 11; break;
case 3: st = 0xE0 | ch; d1 = rn(128); d2 = rn(128); cin = 14; break;
case 4: st = 0xC0 | ch; d1 = rn(128); d2 = 0; cin = 12; break;
case 5: st = (rn(2) ? 0xD0 : 0xA0) | ch; d1 = rn(128); d2 = rn(128); cin = st >> 4; break;
case 6: st = 0xF8 + rn(8); d1 = d2 = 0; cin = 15; break;
default: st = rn(256); d1 = rn(256); d2 = rn(256); break;
}
pkt = cin | cable << 4 | st << 8 | d1 << 16 | d2 << 24;
{
uint8_t b[4] = {(uint8_t)pkt, (uint8_t)(pkt >> 8), (uint8_t)(pkt >> 16), (uint8_t)(pkt >> 24)};
logop(4, b, 4);
if (!ep1_take(b, 4))
audio_blocks(1); /* (the ring full: the audio drains it) */
}
}
int main(int argc, char **argv)
{
uint32_t mode = argc > 1 ? (uint32_t)atoi(argv[1]) : 0, iter = argc > 2 ? (uint32_t)atoi(argv[2]) : 10000, i;
sd = argc > 3 ? (uint32_t)atoi(argv[3]) : 1;
if (!sd) sd = 1;
__sanitizer_set_death_callback(on_death);
harness_init();
after();
for (i = 0; i < iter; i++) {
if (i && i % 5000 == 0) { printf("mode %u: %u iterations ok\n", mode, i); fflush(stdout); }
if (mode == 0) {
cmd_rand(rn(3) == 0);
if (rn(20) == 0) aud(1 + rn(8));
if (rn(200) == 0) ui_rand();
} else if (mode == 1) {
fz_seq_step();
} else if (mode == 6) {
scramble();
round_trip();
} else if (mode == 5) {
uint32_t k = 1 + rn(16), j;
for (j = 0; j < k; j++) midi_rand();
if (rn(3) == 0) uart_rand();
if (rn(2) == 0) aud(1 + rn(4));
after();
if (i % 2000 == 1999) {
midi_let_go();
if (!midi_hang_check()) fail("a note still held after every note-off");
}
} else if (mode == 4) {
exhaustive();
break;
} else if (mode == 3) { /* each boot in a child: its own state */
pid_t pid;
int st = 0;
fflush(stdout); fflush(stderr);
pid = fork();
if (!pid) {
uint32_t j, n = 40 + rn(200);
boot();
for (j = 0; j < n; j++) {
uint32_t r = rn(10);
if (r < 4) fz_seq_step();
else if (r < 6) play_slots();
else if (r < 8) ui_rand();
else { uint32_t k = 1 + rn(8), q; for (q = 0; q < k; q++) midi_rand(); aud(2); }
}
_exit(0);
}
waitpid(pid, &st, 0);
if (!WIFEXITED(st) || WEXITSTATUS(st)) { printf("boot %u (seed %u): child failed\n", i, sd); return 1; }
rn(1);
} else {
uint32_t k = 1 + rn(16), j;
for (j = 0; j < k; j++) midi_rand();
if (rn(3) == 0) uart_rand();
if (rn(3) == 0) aud(1 + rn(4));
if (rn(20) == 0) ui_rand();
if (rn(50) == 0) fz_seq_step();
after();
}
}
printf("editor_fuzz mode %u: %u iterations ok (flash: %u erases, %u programs, %u refused; audio peak %d)\n", mode, iter,
fl_erases, fl_progs, fl_bad, audio_peak);
return 0;
}
+32
View File
@@ -0,0 +1,32 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-3.0-only
# The editor protocol / external input fuzz (tests/editor_fuzz.c) under AddressSanitizer + UBSan.
# sh tests/editor_fuzz.sh [ITER] [SEED] (from the repo root, after ./build.sh)
set -e
cd "$(dirname "$0")/.."
OUT=build/host/edfz
mkdir -p "$OUT/gen"
# SMP_DATA read through a pointer: the user sample slots are addressed as offsets from it (one flash), which
# -fsanitize=bounds would take for an overflow of the array; AddressSanitizer still checks every byte
{ echo '#define SMP_DATA (smp_data_v)'; sed 's/^static const uint8_t SMP_DATA\[/static const uint8_t SMP_DATA_ARR[/' build/gen/felucca_samples.h;
echo 'static const uint8_t *volatile smp_data_v = SMP_DATA_ARR;'; } > "$OUT/gen/felucca_samples.h"
${CC:-cc} -O1 -g -w -fsanitize=address,undefined -fno-sanitize=shift-base,signed-integer-overflow -fno-sanitize-recover=all \
-I"$OUT/gen" -Ibuild/gen -Ifirmware/src -Ifirmware/hal -o "$OUT/editor_fuzz" tests/editor_fuzz.c -lm
N=${1:-20000}
S=${2:-1}
"$OUT/editor_fuzz" 0 $((N * 10)) "$S" # single frames, every command, lengths at the edges
"$OUT/editor_fuzz" 1 "$N" "$S" # sequences: uploads, restores, presets, FM6, SYN kits, LIVE, UI, audio
"$OUT/editor_fuzz" 2 "$N" "$S" # USB-MIDI and TRS bytes in, with the rest
"$OUT/editor_fuzz" 3 $((N / 20)) "$S" # boots from a damaged flash (a child each)
"$OUT/editor_fuzz" 4 1 "$S" # every command over every engine / track / id / step
"$OUT/editor_fuzz" 5 "$N" "$S" # MIDI in only, then no note may be left held
"$OUT/editor_fuzz" 6 $((N / 100)) "$S" # backup / section / autosave round trips give the project back
# the reproducers of what it found (tests/editor_repro.c): each must run clean once fixed
${CC:-cc} -O1 -g -w -fsanitize=address,undefined -fno-sanitize=shift-base,signed-integer-overflow -fno-sanitize-recover=all \
-I"$OUT/gen" -Ibuild/gen -Ifirmware/src -Ifirmware/hal -o "$OUT/editor_repro" tests/editor_repro.c -lm
for r in 1 2 3; do "$OUT/editor_repro" $r; done
# (2.8.4) power-on after an install: the parts sound as their sounds, a working project Clipper left: default sounds
${CC:-cc} -O1 -g -w -fsanitize=address,undefined -fno-sanitize=shift-base,signed-integer-overflow -fno-sanitize-recover=all \
-I"$OUT/gen" -Ibuild/gen -Ifirmware/src -Ifirmware/hal -o "$OUT/boot_sound_test" tests/boot_sound_test.c -lm
"$OUT/boot_sound_test" > "$OUT/boot_sound.log" || { cat "$OUT/boot_sound.log"; exit 1; }
tail -n 1 "$OUT/boot_sound.log"
+293
View File
@@ -0,0 +1,293 @@
/* SPDX-License-Identifier: GPL-3.0-only */
/* Host harness for the web editor's SysEx protocol (firmware/src/editor.c, editor_fm6.c, editor_dsyn.c,
* editor_live.c) with the real storage.c / upreset.c / project.c (fm6_bank.c, arranger_scene.c) on a RAM image
* of the 1 MiB NOR, the real usb.c SysEx assembly (FELUCCA_OTA), the real UI (as tests/ui_pages_test.c) and the
* audio (mix_block) between frames. Included by tests/editor_fuzz.c. Same include order as felucca.c. */
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define FELUCCA_ARRANGER 1
#define FELUCCA_FLASH 1
#define FELUCCA_OTA 1
/* the flash: a RAM image, read where it is (the XIP window) */
static uint8_t nor[0x100000] __attribute__((aligned(4096)));
#define SMP_USER_XIP(k) ((const uint8_t *)nor + SMP_USER_OFF((uint32_t)(k)))
#define FM6_BANK_XIP(copy) ((const uint8_t *)nor + st_sector(OBJ_FM6BANK, copy) + ST_PAYLOAD_OFF)
#define ST_XIP_PTR(off) ((const uint8_t *)nor + (off))
/* (the user slots' zones are rebased onto SMP_DATA, eng_sample.c smp_user_scan: one 32-bit offset space, as the flash
* is on the FM-1, so their reads index SMP_DATA past its own size into the flash image. Under -fsanitize=bounds, build
* with -I to a copy of build/gen/felucca_samples.h whose SMP_DATA is read through a pointer: tests/editor_fuzz.sh) */
#define main hostsim_main
#include "hostsim.c"
#undef main
#include <assert.h>
static uint16_t screen[240*240];
static void lcd_sync(void) {}
static void lcd_blit(uint32_t x, uint32_t y, uint32_t w, uint32_t h, const uint16_t *p)
{ uint32_t i,j; assert(x+w<=240 && y+h<=240); for(j=0;j<h;j++) for(i=0;i<w;i++) screen[(y+j)*240+x+i]=p[j*w+i]; }
#include "../firmware/src/gfx.c"
static void lcd_fill(uint32_t x,uint32_t y,uint32_t w,uint32_t h,uint16_t c)
{ uint32_t i,j; assert(x+w<=240&&y+h<=240); for(j=0;j<h;j++)for(i=0;i<w;i++)screen[(y+j)*240+x+i]=swap16(c); }
static int32_t encs[7];
static uint32_t fm1_ticks(void) { return fm1_ms * 1000u * 24u; }
#define FM1_TICKS_PER_US 24u
static int32_t fm1_enc_take(uint32_t e) { int32_t s = encs[e]; encs[e] = 0; return s; }
static uint8_t fm1_led[16], fm1_led_dim[16], fm1_led_bg[16];
static volatile uint16_t fm1_led_bg_ns;
#define FM1_NCOL 16u
static const int8_t FM1_KEYMAP[5][16];
static void fm1_led_key(uint32_t id, int on) { (void)id; (void)on; }
static uint32_t edges_btn, notes_seen;
static uint32_t fm1_input_edges(int x) { uint32_t e = edges_btn; (void)x; edges_btn = 0; return e; }
static uint32_t fm1_input_note_edges(void) { uint32_t e = fm1_in.notes & ~notes_seen; notes_seen = fm1_in.notes; return e; }
static void fm1_wdt_feed(void) {}
static int32_t fm1_adc_read(int c) { (void)c; return -1; }
static struct { uint32_t magic, stage, page, home, ui_frames; } felucca_dbg;
#define FELUCCA_ICONS 1
#define SCOPE_N 512u
static int16_t scope_buf[SCOPE_N], scope_bufr[SCOPE_N];
static uint32_t scope_w;
#include "../firmware/src/panel.c"
#include "../firmware/src/ui.c"
#include "../firmware/src/ui_song.c"
#include "../firmware/src/ui_studio.c"
#include "../firmware/src/icons.c"
#include "../firmware/src/ui_draw.c"
#include "../firmware/src/ui_vis.c"
#include "../firmware/src/ui_layers.c"
#include "../firmware/src/ui_menu.c"
#include "../firmware/src/ui_input.c"
/* ---- felucca.c's flash part, on the RAM image (as hal/fm1_flash.h: ranges, one page a program) */
#define FL_DATA_LO 0x00097000u
#define FL_DATA_HI 0x000E0000u
#define FL_GLOB_LO 0x000FC000u
#define FL_GLOB_HI 0x000FF000u
#define FL_OTA_LO 0x000E0000u
#define FL_OTA_HI 0x000E5000u
#define FL_FM6_LO 0x000E5000u
#define FL_FM6_HI 0x000E7000u
#define FL_USR4_LO 0x000E7000u
#define FL_USR4_HI 0x000FB000u
#define FL_IN(off, n, lo, hi) ((uint32_t)(off) >= (lo) && (uint32_t)(off) <= (hi) && (uint32_t)(n) <= (hi) - (uint32_t)(off))
#define FL_STORE_OK(off, n) (FL_IN(off, n, FL_DATA_LO, FL_DATA_HI) || FL_IN(off, n, FL_GLOB_LO, FL_GLOB_HI) || \
FL_IN(off, n, FL_FM6_LO, FL_FM6_HI) || FL_IN(off, n, FL_USR4_LO, FL_USR4_HI))
#define FL_RANGE_OK(off, n) (FL_STORE_OK(off, n) || FL_IN(off, n, FL_OTA_LO, FL_OTA_HI))
#define FL_FAR(fn) fn
static uint32_t fl_erases, fl_progs, fl_bad; /* counters; fl_bad: a refused (out of range) access */
static int fl_fail_at = -1; /* > 0: the n-th program from now fails (a torn write) */
static uint32_t fl_jedec_ram(void) { return 0x856014u; }
static void fl_plain_window_init(void) {}
static uint32_t irq_save(void) { return 0; }
static void irq_restore(uint32_t f) { (void)f; }
static void fl_inval(uint32_t off, uint32_t n) { (void)off; (void)n; }
static int fl_erase4k_ram(uint32_t off, uint32_t *took)
{
*took = 0;
if ((off & 0xFFFu) || !FL_RANGE_OK(off, 0x1000u)) { fl_bad++; return -1; }
memset(nor + off, 0xFF, 0x1000u);
fl_erases++;
return 0;
}
static int fl_prog_ram(uint32_t off, const uint8_t *src, uint32_t n, uint32_t *took)
{
uint32_t i;
*took = 0;
if (!FL_RANGE_OK(off, n) || n == 0 || n > 256u || ((off & 0xFFu) + n) > 256u) { fl_bad++; return -1; }
if (fl_fail_at > 0 && --fl_fail_at == 0) { fl_fail_at = -1; return -3; }
for (i = 0; i < n; i++)
nor[off + i] &= src[i];
fl_progs++;
return 0;
}
static int fl_read_ram(uint32_t off, uint8_t *dst, uint32_t n)
{
if (off >= sizeof nor || n > sizeof nor - off) { fl_bad++; return -1; }
memcpy(dst, nor + off, n);
return 0;
}
static int fl_write(uint32_t off, const uint8_t *src_ram, uint32_t n)
{
uint32_t took;
while (n) {
uint32_t chunk = 256u - (off & 0xFFu);
int rc;
if (chunk > n) chunk = n;
rc = fl_prog_ram(off, src_ram, chunk, &took);
if (rc) return rc;
off += chunk; src_ram += chunk; n -= chunk;
}
return 0;
}
static uint8_t flash_ok;
static int st_read(uint32_t off, void *dst, uint32_t n)
{
uint8_t *d = dst;
while (n) {
uint32_t k = n > 256u ? 256u : n;
int rc = fl_read_ram(off, d, k);
if (rc) return rc;
off += k; d += k; n -= k;
}
return 0;
}
static void audio_silence(void) {}
static int fl_erase4k_quiet(uint32_t off, uint32_t *took) { audio_silence(); return fl_erase4k_ram(off, took); }
static int st_erase(uint32_t off) { uint32_t took; if (!FL_STORE_OK(off, 0x1000u)) return -8; return fl_erase4k_quiet(off, &took); }
static int st_prog(uint32_t off, const void *src, uint32_t n) { if (!FL_STORE_OK(off, n)) return -8; return fl_write(off, src, n); }
#include "../firmware/src/storage.c"
#include "../firmware/src/upreset.c"
#include "../firmware/src/project.c"
/* ---- the ota hooks usb.c needs (felucca.c) */
static uint32_t ota_now_ms(void) { return fm1_ms; }
static void rx_take(void);
static void ota_idle(void) { rx_take(); } /* the host takes the replies */
#include "../firmware/src/editor.c"
#include "../firmware/src/splash.c"
/* ---- the harness: frames, replies */
static uint8_t rx_last[1024];
static uint32_t rx_n; /* the last reply (F0..F7), from the SysEx ring */
static void rx_take(void)
{
while (so_r != so_w) {
uint32_t pkt = sx_out_q[so_r % SXQ], cin = pkt & 15u, k, nb = cin == 4u || cin == 7u ? 3u : cin == 6u ? 2u : 1u;
so_r++;
for (k = 0; k < nb; k++) {
uint8_t b = (uint8_t)(pkt >> (8u * (k + 1u)));
if (b == 0xF0u) rx_n = 0;
if (rx_n < sizeof rx_last) rx_last[rx_n++] = b;
}
}
}
/* a frame of n bytes (between F0 and F7) straight into the frame buffer, as usb.c leaves it: ed_service */
static void ed_inject(const uint8_t *f, uint32_t n)
{
if (n > sizeof sx_frame) n = sizeof sx_frame;
memcpy(sx_frame, f, n);
sx_frame_len = n;
sx_ready = 1;
rx_n = 0;
ed_service();
rx_take();
sx_ready = 0; /* (ota_service would take one that is not the editor's) */
}
/* the same through USB-MIDI packets (usb.c midi_in_event / sysex_byte) */
static void usb_sysex(const uint8_t *f, uint32_t n)
{
uint8_t b[700];
uint32_t m = 0, i;
b[m++] = 0xF0;
for (i = 0; i < n && m < sizeof b - 1; i++) b[m++] = f[i];
b[m++] = 0xF7;
for (i = 0; i < m; i += 3) {
uint32_t k = m - i >= 3 ? 3 : m - i, cin = k == 3 && i + 3 < m ? 4u : k == 3 ? 7u : 4u + k;
uint32_t pkt = cin | (uint32_t)b[i] << 8 | (k > 1 ? (uint32_t)b[i + 1] << 16 : 0) | (k > 2 ? (uint32_t)b[i + 2] << 24 : 0);
midi_in_event(pkt);
}
rx_n = 0;
ed_service();
rx_take();
sx_ready = 0;
}
static int32_t audio_peak;
static uint32_t audio_bad;
static void audio_blocks(uint32_t nb)
{
static int32_t o[CTL * 2];
uint32_t q, i;
for (q = 0; q < nb; q++) {
mix_block(o, CTL);
for (i = 0; i < 2u * CTL; i++) {
int32_t a = o[i] < 0 ? -o[i] : o[i];
if (a > audio_peak) audio_peak = a;
if (a > 40000) audio_bad++;
}
for (i = 1; i < CTL; i += 2u) {
scope_bufr[scope_w & (SCOPE_N - 1u)] = vis_tap[2u * i + 1u];
scope_buf[scope_w++ & (SCOPE_N - 1u)] = vis_tap[2u * i];
}
}
}
static void ui_frame(void)
{
audio_blocks(22);
ed_service();
ui_input(); ui_leds(); ui_draw();
autosave_tick();
sections_flush();
fm1_ms += 16;
}
static void harness_init(void)
{
uint32_t i;
memset(nor, 0xFF, sizeof nor);
if ((uintptr_t)nor < (uintptr_t)SMP_DATA || (uintptr_t)nor - (uintptr_t)SMP_DATA > 0xF0000000u) {
printf("editor: the flash image must lie above SMP_DATA within 4 GiB (32-bit offsets)\n");
exit(2);
}
panel = PANEL_DEFAULT;
layers_init();
settings.palette = 4;
palette_set(4);
host_tracks_init();
persist_boot();
for (i = 0; i < NPART; i++) { set_engine_of(&trk[i], TRK_DEF[i][0]); apply_preset_to(&trk[i], TRK_DEF[i][1]); trk[i].engine = trk[i].eng_req; }
TDRUM->p[P_E0] = DRUM_DEFAULT_KIT;
usb.config = 1;
}
/* every parameter of every track inside its range (as the editor / a load must leave them) */
static uint32_t vel_over; /* steps with a velocity > 127 seen (a restored project) */
static int params_check(char *why, size_t nw)
{
uint32_t k, i;
for (k = 0; k < NTRK; k++) {
const track_t *t = &trk[k];
for (i = 0; i < P_COUNT; i++) {
const param_desc_t *d = k == TRK_DRUM && i == P_E0 ? &DRUM_KIT_DESC :
i >= P_E0 && i <= P_E7 ? &ENGINES[t->eng_req % NENGINES]->edit[i - P_E0] : &TP[i];
if (k == TRK_DRUM && i > P_E0 && i <= P_E7)
continue; /* (the drum track has no engine values) */
if (k != TRK_DRUM && i >= P_E0 && t->engine != t->eng_req)
continue; /* (an engine switch fading: the values are the next one's) */
if (t->p[i] < d->min || t->p[i] > d->max) {
snprintf(why, nw, "trk %u p[%u] (%s) = %d outside %d..%d (eng %u)", k, i, d->label, t->p[i], d->min, d->max,
t->eng_req);
return 0;
}
}
if (t->eng_req >= NENGINES) { snprintf(why, nw, "trk %u eng_req %u", k, t->eng_req); return 0; }
for (i = 0; i < NLOCK; i++) {
const plock_t *l = &t->lock[i];
const param_desc_t *d;
if (l->step == LOCK_FREE) continue;
if (l->step >= NSTEP || l->param >= P_COUNT) { snprintf(why, nw, "trk %u lock %u step %u param %u", k, i, l->step, l->param); return 0; }
d = k == TRK_DRUM && l->param == P_E0 ? &DRUM_KIT_DESC :
l->param >= P_E0 && l->param <= P_E7 ? 0 : &TP[l->param];
if (d && (l->val < d->min || l->val > d->max)) { /* (an engine value: clamped when it plays, seq.c lock_write) */
snprintf(why, nw, "trk %u lock %u (step %u, %s) = %d outside %d..%d", k, i, l->step, d->label, l->val, d->min, d->max);
return 0;
}
}
if (!is_drum(t))
for (i = 0; i < NSTEP; i++) {
const step_t *s = &t->step[i];
uint32_t j;
if (s->vel > 127u) vel_over++;
if (s->n > 4u || s->time > ST_REST) { snprintf(why, nw, "trk %u step %u n %u time %u vel %u", k, i, s->n, s->time, s->vel); return 0; }
for (j = 0; j < 4u; j++)
if (s->note[j] > 127u) { snprintf(why, nw, "trk %u step %u note %u", k, i, s->note[j]); return 0; }
}
for (i = 0; i < NSTEP; i++)
if (t->micro[i] < MICRO_MIN || t->micro[i] > MICRO_MAX) { snprintf(why, nw, "trk %u micro[%u] %d", k, i, t->micro[i]); return 0; }
}
for (i = 0; i < G_COUNT; i++)
if (song.g[i] < GP[i].min || song.g[i] > GP[i].max) {
snprintf(why, nw, "g[%u] (%s) = %d outside %d..%d", i, GP[i].label, song.g[i], GP[i].min, GP[i].max);
return 0;
}
if (song.sel >= NTRK) { snprintf(why, nw, "sel %u", song.sel); return 0; }
return 1;
}
+154
View File
@@ -0,0 +1,154 @@
/* SPDX-License-Identifier: GPL-3.0-only */
/* Reproducers of what tests/editor_fuzz.c found, on the same harness (tests/editor_host.c):
* editor_repro 1 a user sample slot whose zone root lies outside the MIDI notes, played as a drum kit (KIT USR1):
* drums.c drum_on -> eng_sample.c pow2_q16 shifts by more than 31 (UB; a garbage playback step)
* editor_repro 2 MIDI Bank Select 8 + Program Change (ui.c pc_poll, PC_USER_BANK): an empty user slot says
* "T1 PROG n", a user preset that loads says nothing (the test of up_load_to's result is inverted)
* editor_repro 3 a backup restore (BK_PUT object 0) of a project whose steps carry a velocity > 127 (project.c
* proj_apply keeps it): the notes play up to 2x louder than the loudest a step can be
* Build as tests/editor_fuzz.sh builds editor_fuzz.c. */
#include "editor_host.c"
static void ed(uint32_t cmd, const uint8_t *a, uint32_t na)
{
uint8_t f[700];
f[0] = ED_HDR0; f[1] = ED_HDR1; f[2] = ED_HDR2; f[3] = (uint8_t)cmd;
memcpy(f + 4, a, na);
usb_sysex(f, 4 + na); /* through usb.c's SysEx assembly, as the editor sends it */
}
static uint32_t pack7(uint8_t *o, const uint8_t *p, uint32_t n)
{
uint32_t w = 0;
while (n) {
uint32_t k = n > 7u ? 7u : n, m = 0, i;
for (i = 0; i < k; i++) m |= (uint32_t)(p[i] >> 7) << i;
o[w++] = (uint8_t)m;
for (i = 0; i < k; i++) o[w++] = p[i] & 127u;
p += k; n -= k;
}
return w;
}
static void midi(uint8_t st, uint8_t d1, uint8_t d2)
{
uint8_t b[4] = {(uint8_t)(st >> 4), st, d1, d2};
ep1_take(b, 4);
}
static int repro_root(void)
{
uint8_t a[700], d[256], hdr[sizeof(smp_user_hdr_t)];
smp_user_hdr_t *h = (smp_user_hdr_t *)hdr;
uint32_t n, i;
a[0] = 0; ed(ED_SMP_BEGIN, a, 1); /* slot USR1 */
for (i = 0; i < 256; i++) d[i] = (uint8_t)(i * 37u);
n = 0; a[n++] = 0; a[n++] = 512 & 127; a[n++] = 512 >> 7; a[n++] = 0;
n += pack7(a + n, d, 256);
ed(ED_SMP_WRITE, a, n);
memset(hdr, 0, sizeof hdr);
h->magic = SMP_USER_MAGIC; h->version = 1; h->nz = 1; memcpy(h->name, "ROOT", 4);
h->data_len = 256; h->crc = st_crc32(d, 256);
h->zone[0].off = 0; h->zone[0].n = 512; h->zone[0].ls = 0; h->zone[0].le = 511; h->zone[0].rate = 0x8000;
h->zone[0].lo = 0; h->zone[0].hi = 127;
h->zone[0].root16 = 32767; /* every check of the header passes: smp_zone_ok has no root check */
n = 0; a[n++] = 0; n += pack7(a + n, hdr, sizeof hdr);
ed(ED_SMP_END, a, n);
printf("SMP_END rc %u, usr_nz[0] %u\n", rx_n > 6 ? rx_last[6] : 99u, usr_nz[0]);
a[0] = TRK_DRUM; a[1] = P_E0; a[2] = (uint8_t)((DRUM_USR + 8192) & 127); a[3] = (uint8_t)((DRUM_USR + 8192) >> 7);
ed(ED_TRACK_PARAM, a, 4); /* the drum track's KIT: USR1 */
printf("drum kit %d (USR1 = %u); a kick on MIDI channel 10:\n", TDRUM->p[P_E0], DRUM_USR);
midi(0x99, 36, 100);
audio_blocks(1); /* -> drums.c drum_on -> pow2_q16(36 * 16 - 32767) */
printf("drum voice step %d (a sane one: ~0x8000 for rate 0x8000 at its root)\n", drums.v[0].s[5]);
{ uint32_t v, ok = 1; /* (any voice: the kick's step bounded, 8 octaves down at most) */
for (v = 0; v < sizeof drums.v / sizeof drums.v[0]; v++)
if (drums.v[v].s[5] < 0 || drums.v[v].s[5] > (int32_t)(16u << 16))
ok = 0;
printf("repro 1 (a user kit zone with root16 32767): %s\n", ok ? "ok" : "FAIL");
return !ok; }
}
static int repro_pc(void)
{
uint8_t a[700];
uint32_t n = 0, i, bad = 0;
/* a user preset in slot 0 (UP_PUT), slot 5 empty */
a[n++] = 0; a[n++] = 0; memcpy(a + n, "MY LEAD", 7); n += 7; a[n++] = 0;
for (i = 0; i < P_COUNT; i++) { uint32_t u = (uint32_t)(TP[i].def + 8192); if (i >= P_E0) u = (uint32_t)(ENGINES[0]->edit[i - P_E0].def + 8192); a[n++] = u & 127; a[n++] = (u >> 7) & 127; }
for (i = 0; i < 32; i++) a[n++] = 0;
ed(ED_UP_PUT, a, n);
printf("UP_PUT slot 0 rc %u, used %d, slot 5 used %d\n", rx_n > 6 ? rx_last[6] : 99u, up_used(0), up_used(5));
/* channel 1 plays track 1: Bank Select 8 (user presets straight), then Program Change 5 (an empty slot) */
ui.msg[0] = 0;
midi(0xB0, 0, 8); midi(0xC0, 5, 0);
ui_frame(); ui_frame();
printf("PC 5 in bank 8 (slot 5 empty): message \"%s\", track 1 user preset %u\n", ui.msg, trk[0].user);
bad += ui.msg[0] != 0 || trk[0].user != 0;
ui.msg[0] = 0;
midi(0xB0, 0, 8); midi(0xC0, 0, 0);
ui_frame(); ui_frame();
printf("PC 0 in bank 8 (slot 0 = MY LEAD): message \"%s\", track 1 user preset %u\n", ui.msg, trk[0].user);
bad += strcmp(ui.msg, "T1 PROG 0") != 0 || trk[0].user != 1;
ui.msg[0] = 0;
midi(0xB0, 0, 0); midi(0xC0, 3, 0);
ui_frame(); ui_frame();
printf("PC 3 in bank 0 (a factory sound, for comparison): message \"%s\"\n", ui.msg);
printf("repro 2 (MIDI bank 8 + program change: the message of an empty and of a stored slot): %s\n", bad ? "FAIL" : "ok");
return bad != 0;
}
static int repro_vel(void)
{
static project_t p;
uint8_t a[700];
uint32_t n, pos = 0, crc, i, k, bad = 0;
int32_t pk0 = 0, pk1 = 0;
for (k = 0; k < 2; k++) {
/* track 1: a note on every step, its velocity 127 (k 0) or 255 (k 1), accent off; the rest silent */
proj_capture(&p);
for (i = 0; i < NSTEP; i++) {
step_t *s = &p.t[0].step[i];
memset(s, 0, sizeof *s);
s->n = 1; s->note[0] = 48; s->time = ST_NOTE; s->vel = k ? 255 : 127;
}
for (i = 1; i < NTRK; i++) memset(p.t[i].step, 0, sizeof p.t[i].step);
p.t[0].p[P_LEVEL] = 100;
p.sum = proj_sum(&p);
crc = st_crc32(&p, sizeof p);
n = 0; a[n++] = 0; a[n++] = 0;
for (i = 0; i < 5; i++) a[n++] = ((uint32_t)sizeof p >> (7 * i)) & 127;
for (i = 0; i < 5; i++) a[n++] = (crc >> (7 * i)) & 127;
ed(ED_BK_PUT, a, n);
for (pos = 0; pos < sizeof p; pos += 256) {
uint32_t c = sizeof p - pos > 256 ? 256 : (uint32_t)sizeof p - pos;
n = 0; a[n++] = 1; a[n++] = 0;
for (i = 0; i < 5; i++) a[n++] = (pos >> (7 * i)) & 127;
n += pack7(a + n, (const uint8_t *)&p + pos, c);
ed(ED_BK_PUT, a, n);
}
a[0] = 2; a[1] = 0; ed(ED_BK_PUT, a, 2);
printf("restore (step velocity %u): commit rc %u; track 1 step 0 velocity now %u\n", k ? 255 : 127,
rx_n > 7 ? rx_last[7] : 99u, trk[0].step[0].vel);
bad += trk[0].step[0].vel > 127u;
audio_peak = 0;
transport_req = 1;
audio_blocks(2000);
transport_req = 2;
audio_blocks(400);
if (k) pk1 = audio_peak; else pk0 = audio_peak;
{
uint32_t v; int mx = 0;
for (v = 0; v < NVOICE; v++) if (trk[0].v[v].vel > mx) mx = trk[0].v[v].vel;
}
}
printf("output peak: velocity 127 -> %d, velocity 255 -> %d\n", pk0, pk1);
bad += pk1 > pk0 + pk0 / 16;
printf("repro 3 (a restored step of velocity 255): %s\n", bad ? "FAIL" : "ok");
return bad != 0;
}
int main(int argc, char **argv)
{
int which = argc > 1 ? atoi(argv[1]) : 1;
harness_init();
return which == 1 ? repro_root() : which == 2 ? repro_pc() : repro_vel();
}
+145
View File
@@ -0,0 +1,145 @@
/* SPDX-License-Identifier: GPL-3.0-only */
/* SLOOP Pro #4: "3.5mm & USB audio output has distorted noise while notes fading out". The mix floored each part to
* 16 LSB of the output (fx.c mix_part_run: x >> 4 at the mute / duck gain, always applied at rest since
* mulq15(32767, 32767) is 32766, and again at the PAN gain; b >> 2 at LEVEL), the MASTER to 4 LSB (mix >> 2), USB AUDIO =
* FULL to 4 LSB, DIST's drive to 4 x its gain: an error of ~5.5 LSB rms whatever the level, all of it on the note's
* harmonics (distortion, not hiss), so a note fading out turned into a buzz (THD+N -8 dB at -60 dBFS). Now rounded
* (dsp.c MULQ12R): the error is the 16-bit output's own rounding.
* Each case holds a note that decays slowly (SUS 0), renders the output as the codec (and USB) gets it and, over
* windows of 8192 samples, fits the note (its harmonics, amplitudes moving as a quadratic) by least squares: what is
* left is the error. Checked between -70 and -30 dBFS (808 SLIDE: -40): its rms under 1 LSB (an ideal 16-bit rounding:
* 0.29; it was 5 to 6.5), and the THD+N of the window nearest -60 dBFS under -28 dB (it was -12 to -19). Cases: a
* clean sine (no drive, no FX) at MASTER 4096 and at 2048 (the power-on level), the same through USB AUDIO = FULL
* (MASTER ignored), and 808 SLIDE (sine, DRV, DIST 30) at 4096.
* Exit status: the number of failed checks. */
#define main hostsim_main
#include "hostsim.c"
#undef main
#define NBLK 13000u /* ~9.4 s: the sine from -6 to below -80 dBFS */
#define WIN 8192
static int32_t cap[NBLK * CTL];
static double incq[NBLK]; /* the note's phase step a block (2^32 a turn) */
static int fails;
static void check(int ok, const char *what) { printf("fade: %-96s %s\n", what, ok ? "ok" : "FAIL"); fails += !ok; }
/* least squares fit of H harmonics of w (each with a constant, linear and quadratic amplitude) and a line; returns the
* rms of what is left, *sig the fit's rms */
static double fit_left(const double *y, double w, int H, double *sig)
{
enum { KMAX = 6 * 16 + 2 };
static double A[KMAX][KMAX], bv[KMAX], phi[KMAX], c[KMAX];
int K = 6 * H + 2, i, j, k, n;
double e2 = 0, s2 = 0;
memset(A, 0, sizeof A), memset(bv, 0, sizeof bv);
for (n = 0; n < WIN; n++) {
double t = (n - WIN / 2.0) / WIN;
for (i = 1, k = 0; i <= H; i++) {
double s = sin(i * w * n), cs = cos(i * w * n);
phi[k++] = s, phi[k++] = cs, phi[k++] = s * t, phi[k++] = cs * t, phi[k++] = s * t * t, phi[k++] = cs * t * t;
}
phi[k++] = 1, phi[k++] = t;
for (i = 0; i < K; i++) {
bv[i] += phi[i] * y[n];
for (j = 0; j <= i; j++)
A[i][j] += phi[i] * phi[j];
}
}
for (i = 0; i < K; i++) /* Cholesky, then the two triangular solves */
for (j = 0; j <= i; j++) {
double s = A[i][j];
for (k = 0; k < j; k++)
s -= A[i][k] * A[j][k];
A[i][j] = i == j ? sqrt(s > 1e-30 ? s : 1e-30) : s / A[j][j];
}
for (i = 0; i < K; i++) {
double s = bv[i];
for (k = 0; k < i; k++)
s -= A[i][k] * c[k];
c[i] = s / A[i][i];
}
for (i = K - 1; i >= 0; i--) {
double s = c[i];
for (k = i + 1; k < K; k++)
s -= A[k][i] * c[k];
c[i] = s / A[i][i];
}
for (n = 0; n < WIN; n++) {
double t = (n - WIN / 2.0) / WIN, f = 0;
for (i = 1, k = 0; i <= H; i++, k += 6) {
double s = sin(i * w * n), cs = cos(i * w * n);
f += (c[k] + c[k + 2] * t + c[k + 4] * t * t) * s + (c[k + 1] + c[k + 3] * t + c[k + 5] * t * t) * cs;
}
e2 += (y[n] - f - c[K - 2] - c[K - 1] * t) * (y[n] - f - c[K - 2] - c[K - 1] * t);
s2 += f * f;
}
*sig = sqrt(s2 / WIN);
return sqrt(e2 / WIN);
}
/* sine: the analog engine's SIN, no drive, no FX; else 808 SLIDE as it comes (its DIST), dry (no sends). usb: capture
* USB AUDIO = FULL's stream instead of the codec's */
static void run(const char *name, int sine, int32_t master, int usb, int H, int top)
{
static int32_t o[2 * CTL];
static double y[WIN];
track_t *t = &trk[0];
uint32_t b, i, n;
double worst = 0, wlev = 0, at60 = 1e9, thdn60 = 0, d60 = 1e9;
char s[240];
host_tracks_init();
for (i = 0; i < NVOICE; i++) /* (the case before: its note, held, gone) */
memset(&t->v[i], 0, sizeof t->v[i]);
t->nmono = 0, t->mono_note = 0;
song.master_q12 = (uint32_t)master;
host_preset(t, 0, 3); /* ANALOG 808 SLIDE */
if (sine) {
t->p[P_E0] = 3, t->p[P_E1] = 0, t->p[P_E2] = 0, t->p[P_E3] = 0, t->p[P_E4] = 127, t->p[P_E5] = 0;
t->p[P_E6] = 0, t->p[P_DIST] = 0, t->p[P_ED_PIT] = 0;
t->p[P_ATK] = 0, t->p[P_DEC] = 118, t->p[P_SUS] = 0, t->p[P_REL] = 60;
}
t->p[P_CHOR] = t->p[P_DLY] = t->p[P_REV] = 0;
usb_full_now = (uint8_t)usb;
for (b = 0; b < 4; b++)
mix_block(o, CTL);
trk_note_on(t, 60, 100);
for (b = 0; b < NBLK; b++) {
uint32_t ph = t->v[0].ph[0];
mix_block(o, CTL);
incq[b] = (double)(uint32_t)(t->v[0].ph[0] - ph) / CTL;
for (i = 0; i < CTL; i++)
cap[b * CTL + i] = usb ? usb_out[2 * i] : o[2 * i];
}
usb_full_now = 0;
for (n = 0; n + WIN <= NBLK * CTL; n += WIN) {
double rms = 0, lev, left, sig;
for (i = 0; i < WIN; i++)
rms += (double)cap[n + i] * cap[n + i];
lev = 20 * log10(sqrt(rms / WIN) * sqrt(2.0) / 32767 + 1e-12); /* dBFS of a sine as loud */
if (lev > top || lev < -70)
continue;
for (i = 0; i < WIN; i++)
y[i] = cap[n + i];
left = fit_left(y, 2 * M_PI * incq[(n + WIN / 2) / CTL] / 4294967296.0, H, &sig);
if (left > worst)
worst = left, wlev = lev;
if (fabs(lev + 60) < d60)
d60 = fabs(lev + 60), at60 = lev, thdn60 = 20 * log10(left / sig);
}
snprintf(s, sizeof s, "%s: error while it fades (-70..%d dBFS) at most %.2f LSB rms (at %.0f dBFS), bound 1",
name, top, worst, wlev);
check(worst > 0 && worst < 1.0, s);
snprintf(s, sizeof s, "%s: THD+N at %.0f dBFS %.1f dB, bound -28", name, at60, thdn60);
check(d60 < 5 && thdn60 < -28, s);
}
int main(void)
{
run("sine, MASTER 4096", 1, 4096, 0, 1, -30);
run("sine, MASTER 2048 (power-on)", 1, 2048, 0, 1, -30);
run("sine, USB AUDIO = FULL", 1, 2048, 1, 1, -30);
run("808 SLIDE (DRV, DIST 30), MASTER 4096", 0, 4096, 0, 15, -40); /* (from -40: its drive's own grit, -58 dB under
* the note, follows the note: eng_analog.c, not the fade) */
printf("fade: %d failed\n", fails);
return fails;
}
+182 -182
View File
@@ -1,184 +1,184 @@
# FELUCCA golden renders (tests/regress.c): name, FNV-1a 64 of the output samples.
# Rewritten by GOLDEN_UPDATE=1 tests/run_tests.sh -- only for an intended change of the sound.
preset/ANALOG/00_808_BOOM 69d0901c64773d4c
preset/ANALOG/01_808_DIRTY 13baa79fb0755730
preset/ANALOG/02_SUB_BASS abdebef79fb80860
preset/ANALOG/03_808_SLIDE 4ffca0e08379ba48
preset/ANALOG/04_ACID_303 7b34a7bbb4d84c82
preset/ANALOG/05_PLUGG_BASS da4ffb25aa27adf8
preset/ANALOG/06_REESE 12bae0ba2bf32215
preset/ANALOG/07_WOBBLE ccd93c7fac93b59c
preset/ANALOG/08_FUNK_BASS 1d2f05993423676b
preset/ANALOG/09_G-FUNK_LD f311076810b13436
preset/ANALOG/10_TRAP_PLUCK 97c18830fddd545c
preset/ANALOG/11_SYN_BRASS 763e5d7c6fccdf86
preset/ANALOG/12_SUPERSAW 7b011debfd85e923
preset/ANALOG/13_WARM_PAD 2d52f18b6ece5992
preset/ANALOG/14_DARK_STR 28ced2ee15a9e75e
preset/ANALOG/15_ATMOS_PAD 3aa962707a591993
preset/ANALOG/16_PAN_FLUTE 286c0db55fead3cc
preset/ANALOG/17_FAT_LEAD ef3e7318d99fb312
preset/ANALOG/18_MONO_BASS 561f16f5eda2940c
preset/ANALOG/19_PWM_LEAD 52b45468d9501a18
preset/ANALOG/20_SAW_BASS 345c4dd1f0f310ec
preset/ANALOG/21_SINE_PAD bdacce6c70aa91dc
preset/DIGITAL/00_RHODES 421fe16e43b750a8
preset/DIGITAL/01_DX_RHODES 6eaf3fe5e76d0308
preset/DIGITAL/02_WURLI 766b59505a188766
preset/DIGITAL/03_CLAV cc3238f92a9137a2
preset/DIGITAL/04_M1_PIANO 562df51d78c2c270
preset/DIGITAL/05_AFRO_KEYS fd9d3c8fdd2a7276
preset/DIGITAL/06_TRAP_BELL 7a43417bb95c66e3
preset/DIGITAL/07_MUSIC_BOX ae7dd85ba48c5c19
preset/DIGITAL/08_MARIMBA 1afed4d945973f8c
preset/DIGITAL/09_KALIMBA b6d7e2d695868e50
preset/DIGITAL/10_PLUGG_BELL b2a99d2ad75cd688
preset/DIGITAL/11_GLASS_PAD c2742b8b784fd907
preset/DIGITAL/12_FM_BASS 52862e1e7445f4e2
preset/DIGITAL/13_STEEL_DRUM d1eb74682165e643
preset/DIGITAL/14_GLOCKEN 0636919143151a78
preset/DIGITAL/15_CELESTA 1a5bad30d3f37955
preset/DIGITAL/16_XYLOPHONE 7e6660fa87085d14
preset/DIGITAL/17_HARP 5db832f89080cf58
preset/DIGITAL/18_BASS_GTR 9aa5cd6c12eaa870
preset/DIGITAL/19_TUBE_BELL 6072767f1d183b76
preset/DIGITAL/20_FM_PLUCK 1a82523e312bcc4d
preset/DIGITAL/21_FM_GRAND 6d3520e310a5265b
preset/PHASE/00_CZ_BASS 0af10af70faa24f1
preset/PHASE/01_SOFT_KEYS 1302c3907079f4a4
preset/PHASE/02_CZ_STRING 09e82139f1fdcf12
preset/PHASE/03_RESO_PLUCK 652f45b6e999a4e3
preset/PHASE/04_CZ_BRASS 66aa186da039bbdd
preset/PHASE/05_CZ_LEAD e1b036cb5107ba6a
preset/PHASE/06_CZ_PAD 753c31dfd4e86885
preset/PHASE/07_CZ_RESO 0899ebc55106697d
preset/LOFI/00_GAME_LEAD 2b0101cbd336635d
preset/LOFI/01_GB_BASS d2baabc5474103d4
preset/LOFI/02_8BIT_ARP 806922784ebe92fd
preset/LOFI/03_NES_BASS 45488b0a033b5ce8
preset/LOFI/04_CHIP_CHORD e55424ac13f3ece1
preset/LOFI/05_1BIT_BEEP e1742bf68ea67ad1
preset/LOFI/06_WAVE_LEAD 23a2f1e11d67dfad
preset/LOFI/07_CHIP_NOISE ca1058917a10b3b0
preset/SAMPLE/00_GRAND_PNO 9c5d53a1ab12d0fc
preset/SAMPLE/01_UP_BASS ab929b7cd01d615c
preset/SAMPLE/02_VIBES 6e14271dc9c6ebf0
preset/SAMPLE/03_HORN_STAB f2b3917cde0d0110
preset/SAMPLE/04_STRING_STB 131105f7f10785fe
preset/SAMPLE/05_LOFI_FLUTE 0db1d1b6c42b8dff
preset/SAMPLE/06_SCRATCH e64ad5d2d779891c
preset/SAMPLE/07_GM_KIT 13999abe5e115815
preset/SAMPLE/08_DUSTY_PNO 09c7cc02bc9e2468
preset/SAMPLE/09_LOFI_KEYS 9c85a710ae9edfa6
preset/SAMPLE/10_DEEP_BASS d68154cf4ef76038
preset/VOICE/00_CHOIR_AAH d71bac99365842d0
preset/VOICE/01_SOUL_OOH 54efb0da8718978f
preset/VOICE/02_TALKBOX 21c8a39e3ffaed5a
preset/VOICE/03_WOW_BASS 2b3e7f74138ae8a0
preset/VOICE/04_HARMONICA 2b0c12b4331d68c6
preset/VOICE/05_ROBOT 25af475d3031ab3d
preset/VOICE/06_VOX_PAD f11e65a2934657c3
preset/TRIO/00_FAT_BASS aae2a8d886288062
preset/TRIO/01_MIN_STAB eea67a68ea470e80
preset/TRIO/02_MIN7_STAB 3c04ebffb1f9b66b
preset/TRIO/03_RAVE_STAB 12f9334768fa999e
preset/TRIO/04_DUB_CHORD 5b1db563ceeab2e6
preset/TRIO/05_SAW_PAD c3671956d48a22f5
preset/TRIO/06_SYNC_LEAD ba69a3efce95f6dc
preset/TRIO/07_HOOVER 1740917f80172506
preset/TRIO/08_ACCORDION c3e77a567b85a75c
preset/TRIO/09_ENSEMBLE 11022ca584ec6a67
preset/TRIO/10_80S_POLY b8ad1b14065de51e
preset/TRIO/11_SQR_LEAD d98536f9d4590375
preset/TRIO/12_POWER_STAB aff37a8b7ce92421
preset/TRIO/13_PULSE_PAD 30a1990d9db892cb
preset/WHEEL/00_SOUL_ORGAN cef2bd90f0e1c34c
preset/WHEEL/01_GOSPEL 65c1181e19719dd8
preset/WHEEL/02_JAZZ_ORGAN 559525673e373810
preset/WHEEL/03_DIRTY_B3 02ffafecc2a084b7
preset/WHEEL/04_HOUSE_ORGN 1e676ba00c8e2be9
preset/WHEEL/05_ROCK_ORGAN b1c318b9361b9cd5
preset/WHEEL/06_CHAPEL 05ff719df9583b1b
preset/WHEEL/07_REGGAE_ORG 2be04c3f7b04d4da
preset/GRAIN/00_LOFI_CLOUD bda40c6aad4f1319
preset/GRAIN/01_VIBE_HAZE 0a76ecddbe3e2211
preset/GRAIN/02_FLUTE_DUST 5d640471862bfabd
preset/GRAIN/03_STR_CLOUD 4bf449a155919813
preset/GRAIN/04_SHIMMER f247719d39436922
preset/GRAIN/05_DRONE d66c0c2ae68a36aa
preset/GRAIN/06_PNO_FREEZE e64d7776f4704a51
preset/GRAIN/07_HORN_CLOUD 76c412766bd79821
preset/FM6/00_TINE_EP d140f3fe55e42633
preset/FM6/01_GLASS_BELL 659b1cdce56b7af2
preset/FM6/02_ROUND_BASS daf611066fa95457
preset/FM6/03_BRASS_SECT b73c24e3c390d538
preset/FM6/04_SOFT_PAD f1605fea2af19078
preset/FM6/05_WOOD_BARS b8bc4acff797552b
preset/FM6/06_DRAWBARS c731dba26e816787
preset/FM6/07_NYLON_PICK 08f20f5ef9e920ac
preset/PHYS/00_BELL_TREE edc6ba7c5a18080e
preset/PHYS/01_MODAL_BAR f1efdb63f9fb7d78
preset/PHYS/02_STR_PLUCK 9a8d92d71a1e5361
preset/PHYS/03_BOWED_MTL e0b35c074ce5e89a
preset/PHYS/04_THUMB_PNO 2d0f1bae79e0ca6f
preset/PHYS/05_HAND_DRUM c63514883fe1e9df
preset/PHYS/06_MEMB_TOMS c4bf65287922da13
preset/PHYS/07_SITAR 9c5e4177782304b2
preset/PHYS/08_PHYS_HARP 016d601ec02d1623
preset/PHYS/09_NYLON_GTR 0c0c6581fccfb380
preset/PHYS/10_STEEL_GTR 644f4d2ed5e018d6
preset/PHYS/11_MUTED_GTR 9ff8ea386c541b51
preset/PHYS/12_PLUCK_BASS 4574b89266e09213
preset/PHYS/13_KOTO 35273505b119cdb7
preset/PHYS/14_BANJO 09002b8927701730
preset/PHYS/15_CELLO_BOW 42550aeaf1f47bc8
preset/PHYS/16_TANPURA f2b8c85ed6ffd9cb
preset/PHYS/17_CHIMES 1449edbcafaacf7b
preset/PHYS/18_BIG_BELL 9b4e849f930e3473
preset/PHYS/19_VIBRA_BAR 0ec323cb72fde185
preset/PHYS/20_GLASS_BOWL c9cf505ecea3b8f5
preset/PHYS/21_STEEL_PAN 50d84bb716aaa718
preset/PHYS/22_WOOD_BLOCK 8fe5f920d2efe9e5
preset/PHYS/23_TABLA 67b4b8b89b8f041b
preset/PHYS/24_CONGA f8da9d4b3c9bd3c7
preset/PHYS/25_TIMPANI b4cab8352e46bad3
preset/NOISE/00_WIND 1b7c905854ade21e
preset/NOISE/01_RAIN 9baef5e15ae337cb
preset/NOISE/02_NZ_ARCADE 2e2d7b4eeaff3af6
preset/NOISE/03_NZ_METAL 2edc99e81ffc69f9
preset/NOISE/04_OCEAN 6d626b093f874d1d
preset/NOISE/05_VINYL adccb64a58d666fe
preset/NOISE/06_HISS 2bddccebfba286de
preset/NOISE/07_RISER fcea3ada4f424206
preset/NOISE/08_NZ_SNARE b0fe837467457eee
preset/NOISE/09_BITCRUSH 57785f07c4efb016
preset/NOISE/10_RADIO 7bdab4709d2209ac
drums/gm_kit b56f39d6452ad27c
mode/ANALOG/POLY 8469751e1f620a8c
mode/ANALOG/MONO 9583d8d67d814abc
mode/ANALOG/LEGATO 688683752bbf85f8
mode/ANALOG/UNISON 8bb858f31b261198
mode/DIGITAL/POLY 6eaf3fe5e76d0308
mode/DIGITAL/MONO 05ef3c10b54c76a1
mode/DIGITAL/LEGATO a7613f98364ceb26
mode/DIGITAL/UNISON 762ab1e50571e207
mode/VOICE/POLY d71bac99365842d0
mode/VOICE/MONO 9450adb85fb70d90
mode/VOICE/LEGATO 1a04dbc937476869
mode/VOICE/UNISON 1fbb5b94bb4ec6fc
sends/ANALOG/dry 8bd8ed5fdef461b8
sends/ANALOG/chorus 54db3f297abe1ef6
sends/ANALOG/delay b7b81d709bc097c4
sends/ANALOG/reverb 0b9eca45667b05f9
sends/ANALOG/all 041a19e59e693ea0
sends/ANALOG/dist 9f8d9c59091192da
sends/DIGITAL/dry 8dbda764d41b9db8
sends/DIGITAL/chorus 392d686336b442c7
sends/DIGITAL/delay a7796f5483684590
sends/DIGITAL/reverb 054e0968f4fe10af
sends/DIGITAL/all 89200ffa1d59426f
sends/DIGITAL/dist 175553bf51b61037
song/4track_mix ff4ab83a67ee9a84
slicer/gate/ANALOG_DARK_STR 35d6d06a168b40d2
slicer/stut/DIGITAL_RHODES 2272d80d58109e6b
slicer/song_gate_stut 59e22f92ed7d4a31
preset/ANALOG/00_808_BOOM 0b447c66765e1780
preset/ANALOG/01_808_DIRTY 402ad42574c9a7ac
preset/ANALOG/02_SUB_BASS e2923181844810dc
preset/ANALOG/03_808_SLIDE 5dff1c7d531ee278
preset/ANALOG/04_ACID_303 346da39aa7f3ba1c
preset/ANALOG/05_PLUGG_BASS 4f878f049d4f9f02
preset/ANALOG/06_REESE 0b341da1e28243b8
preset/ANALOG/07_WOBBLE dea178509223ea46
preset/ANALOG/08_FUNK_BASS 3db9a745ec1a7158
preset/ANALOG/09_G-FUNK_LD 682ace11dc49f73b
preset/ANALOG/10_TRAP_PLUCK a329c6b1562dea26
preset/ANALOG/11_SYN_BRASS f759ee59095882e2
preset/ANALOG/12_SUPERSAW 0cc1745ddf9a6816
preset/ANALOG/13_WARM_PAD f861aef46c6bbca2
preset/ANALOG/14_DARK_STR f4a10734e614634c
preset/ANALOG/15_ATMOS_PAD be708497a0721e5f
preset/ANALOG/16_PAN_FLUTE f891b1935c6ec338
preset/ANALOG/17_FAT_LEAD 2a465282cf8cb8f6
preset/ANALOG/18_MONO_BASS a0764d7d351ce155
preset/ANALOG/19_PWM_LEAD 22e1b90b9afc14e6
preset/ANALOG/20_SAW_BASS fef83f603f87c2e7
preset/ANALOG/21_SINE_PAD ac2c3e1097ed46c9
preset/DIGITAL/00_RHODES 5f5ad5cd2136e782
preset/DIGITAL/01_DX_RHODES 204cbf2c76b7a0e9
preset/DIGITAL/02_WURLI e779222017ee3599
preset/DIGITAL/03_CLAV 3321a83373d6e9e3
preset/DIGITAL/04_M1_PIANO bc6323763204faa4
preset/DIGITAL/05_AFRO_KEYS 68c291f135233400
preset/DIGITAL/06_TRAP_BELL 7f421b9e39a510c7
preset/DIGITAL/07_MUSIC_BOX 96e97bfdfd417eb9
preset/DIGITAL/08_MARIMBA 76d6078e62c4f049
preset/DIGITAL/09_KALIMBA ccf823e7c13606f1
preset/DIGITAL/10_PLUGG_BELL 974d5069bf693723
preset/DIGITAL/11_GLASS_PAD d61a2a8e676b02e9
preset/DIGITAL/12_FM_BASS fee2f20e0a867b96
preset/DIGITAL/13_STEEL_DRUM 87b450979d293646
preset/DIGITAL/14_GLOCKEN 5a7917dc6d3d57ca
preset/DIGITAL/15_CELESTA c286f82a0cefea6e
preset/DIGITAL/16_XYLOPHONE 726a89ff2ebcd209
preset/DIGITAL/17_HARP 1fd85ccbd81241f0
preset/DIGITAL/18_BASS_GTR 5b8ff67b66407afe
preset/DIGITAL/19_TUBE_BELL 370d0b038877010d
preset/DIGITAL/20_FM_PLUCK 11e18ba62acd7a68
preset/DIGITAL/21_FM_GRAND a25107190408a0df
preset/PHASE/00_CZ_BASS a109028ba9c13d54
preset/PHASE/01_SOFT_KEYS be302531219fcd4d
preset/PHASE/02_CZ_STRING 0ca6bf45690f0912
preset/PHASE/03_RESO_PLUCK d42a0dd298b6ae18
preset/PHASE/04_CZ_BRASS a6f15822f71268fe
preset/PHASE/05_CZ_LEAD 3de2941533798291
preset/PHASE/06_CZ_PAD 7c8e04dd3421f4ec
preset/PHASE/07_CZ_RESO 5ef775d5cb4f71d2
preset/LOFI/00_GAME_LEAD 82d1172ddd442934
preset/LOFI/01_GB_BASS 3f93277dbbb3aff4
preset/LOFI/02_8BIT_ARP 8ba73e2cfbd0b963
preset/LOFI/03_NES_BASS 537e5fe05d7bcbbc
preset/LOFI/04_CHIP_CHORD 0db187b6da64ebe9
preset/LOFI/05_1BIT_BEEP abb71c2ee4a0884b
preset/LOFI/06_WAVE_LEAD 23eb147f89c28417
preset/LOFI/07_CHIP_NOISE 22efb4c099541363
preset/SAMPLE/00_GRAND_PNO c5bd0a26a3076792
preset/SAMPLE/01_UP_BASS 9cd78d7954dd3048
preset/SAMPLE/02_VIBES d20fef74597b3425
preset/SAMPLE/03_HORN_STAB 3863c2e2aeeed5da
preset/SAMPLE/04_STRING_STB 1aa3f3493bcab904
preset/SAMPLE/05_LOFI_FLUTE 6141680de17b31e2
preset/SAMPLE/06_SCRATCH e273141b29f87f90
preset/SAMPLE/07_GM_KIT ccb7d54e9f18defb
preset/SAMPLE/08_DUSTY_PNO 1e9a4db62b5bfe0e
preset/SAMPLE/09_LOFI_KEYS fb4440a8ab2f51a2
preset/SAMPLE/10_DEEP_BASS ce2ced55a60f4d20
preset/VOICE/00_CHOIR_AAH 26fb9dea09985f7e
preset/VOICE/01_SOUL_OOH acae5800585911b0
preset/VOICE/02_TALKBOX a39aafcb80c658e2
preset/VOICE/03_WOW_BASS 15d362c817aa50fe
preset/VOICE/04_HARMONICA 7ef0da8a7838e198
preset/VOICE/05_ROBOT 650b63ad403bc58c
preset/VOICE/06_VOX_PAD fb38da0d22f38172
preset/TRIO/00_FAT_BASS 55de2129707c9759
preset/TRIO/01_MIN_STAB 2632da5b6f5278ba
preset/TRIO/02_MIN7_STAB 924e16723dcbdf7a
preset/TRIO/03_RAVE_STAB 38ab10f19800f567
preset/TRIO/04_DUB_CHORD a4a848aa7c4e6fb2
preset/TRIO/05_SAW_PAD 5d0d56c4f97a86ce
preset/TRIO/06_SYNC_LEAD 7f2f110503e62854
preset/TRIO/07_HOOVER 1e4f7e683b631207
preset/TRIO/08_ACCORDION e3adc78aaf56c651
preset/TRIO/09_ENSEMBLE 1de51bf96c1ea62d
preset/TRIO/10_80S_POLY e15eeea90a81e3f7
preset/TRIO/11_SQR_LEAD 8b5006dca7e98bf9
preset/TRIO/12_POWER_STAB 426632fc9bbe3633
preset/TRIO/13_PULSE_PAD 7ede6e645a132617
preset/WHEEL/00_SOUL_ORGAN 26c89c7956496366
preset/WHEEL/01_GOSPEL 1b6edcb57fa356b6
preset/WHEEL/02_JAZZ_ORGAN 41f45c9a0a40e035
preset/WHEEL/03_DIRTY_B3 f89b98547cb413ed
preset/WHEEL/04_HOUSE_ORGN 3b6645c81426f98e
preset/WHEEL/05_ROCK_ORGAN e8d878966bc133e2
preset/WHEEL/06_CHAPEL 451598b2ab4a87f1
preset/WHEEL/07_REGGAE_ORG ea6c8bc9f3c4c181
preset/GRAIN/00_LOFI_CLOUD 034b7f18af079e20
preset/GRAIN/01_VIBE_HAZE 0379d917e27966f3
preset/GRAIN/02_FLUTE_DUST 12add7edf9162f68
preset/GRAIN/03_STR_CLOUD a231e1a0864947bf
preset/GRAIN/04_SHIMMER 32e5e2b8cddff364
preset/GRAIN/05_DRONE 4cd52520e801c91c
preset/GRAIN/06_PNO_FREEZE b3a3e829d8535c31
preset/GRAIN/07_HORN_CLOUD 5ec7a9ade292a9e3
preset/FM6/00_TINE_EP df7fd766762b90a6
preset/FM6/01_GLASS_BELL 512effee3105d062
preset/FM6/02_ROUND_BASS 7b6733a39172aa35
preset/FM6/03_BRASS_SECT 0855b5f153aa30b1
preset/FM6/04_SOFT_PAD c79174217f6a41fd
preset/FM6/05_WOOD_BARS fcfc5103a90c8fea
preset/FM6/06_DRAWBARS f4786e2ee7c24d5e
preset/FM6/07_NYLON_PICK 12ce3ec683dc8f1f
preset/PHYS/00_BELL_TREE c1bdfc2ee4ab4cd0
preset/PHYS/01_MODAL_BAR 5ca8061f30cac5fe
preset/PHYS/02_STR_PLUCK 2d57233485a869fc
preset/PHYS/03_BOWED_MTL 7d7d620187f27a70
preset/PHYS/04_THUMB_PNO 1a932cdac0ae37e4
preset/PHYS/05_HAND_DRUM eb9804b2da02dd61
preset/PHYS/06_MEMB_TOMS e857a1a9388100c0
preset/PHYS/07_SITAR 7a91f38db13c97d0
preset/PHYS/08_PHYS_HARP be266a95d2124d01
preset/PHYS/09_NYLON_GTR f95e828e41b4a551
preset/PHYS/10_STEEL_GTR 754b79d70a1bb02a
preset/PHYS/11_MUTED_GTR 1a32f57ee1033ad2
preset/PHYS/12_PLUCK_BASS b98f0da93cbaec62
preset/PHYS/13_KOTO 4b742f86ffaeee0f
preset/PHYS/14_BANJO 1a3e377c0cb47c82
preset/PHYS/15_CELLO_BOW 8915d724b2724143
preset/PHYS/16_TANPURA aa68abf882613fb3
preset/PHYS/17_CHIMES 9852dc7da5d6b1cf
preset/PHYS/18_BIG_BELL fd47d525dff22f88
preset/PHYS/19_VIBRA_BAR 5db1d37fb3049d54
preset/PHYS/20_GLASS_BOWL 70bc0b6f0132af8f
preset/PHYS/21_STEEL_PAN 14e57d642408270f
preset/PHYS/22_WOOD_BLOCK 6cfa419e4b61f9ba
preset/PHYS/23_TABLA 4b03983f9626197d
preset/PHYS/24_CONGA e9d11f7b0763ae75
preset/PHYS/25_TIMPANI 939cb7f59f82b1e8
preset/NOISE/00_WIND e75c83b582bb4fbb
preset/NOISE/01_RAIN 2c992f744ec541b6
preset/NOISE/02_NZ_ARCADE 0a0be8449a37e00c
preset/NOISE/03_NZ_METAL 5400d750b982eaf4
preset/NOISE/04_OCEAN bdb5fb14db807d32
preset/NOISE/05_VINYL 1fedc73a6d496c62
preset/NOISE/06_HISS f6a42c48b1f28fe6
preset/NOISE/07_RISER 2f998600041970eb
preset/NOISE/08_NZ_SNARE 2b234bbe1c868c6c
preset/NOISE/09_BITCRUSH f370a5d34807afbc
preset/NOISE/10_RADIO 34a0abd39bdabed7
drums/gm_kit 51ef07025d5d8f29
mode/ANALOG/POLY d293ec26631dfae0
mode/ANALOG/MONO 18ee6950d997f284
mode/ANALOG/LEGATO 7ec96f14879328dc
mode/ANALOG/UNISON aa0364a434c13494
mode/DIGITAL/POLY 204cbf2c76b7a0e9
mode/DIGITAL/MONO d0cf1562ee94c654
mode/DIGITAL/LEGATO f861780fe755a834
mode/DIGITAL/UNISON 1b6a3f40ffee50e0
mode/VOICE/POLY 26fb9dea09985f7e
mode/VOICE/MONO a2abce138163e87e
mode/VOICE/LEGATO e4553da7d08dd888
mode/VOICE/UNISON a18664fb7e044302
sends/ANALOG/dry 32009a1c0faa103c
sends/ANALOG/chorus bcf4ea50a8f3cd47
sends/ANALOG/delay c244e53616253300
sends/ANALOG/reverb 7d444abe4455918a
sends/ANALOG/all 49e62440b8a98684
sends/ANALOG/dist 51775c08074a6974
sends/DIGITAL/dry 23ca5cb853d051e4
sends/DIGITAL/chorus 1e73519b25da7850
sends/DIGITAL/delay c13ca497feace3c8
sends/DIGITAL/reverb e7300b18533ad0f2
sends/DIGITAL/all c5ac0e9084b3c54e
sends/DIGITAL/dist 1c055b97ac0e23ac
song/4track_mix 98532af20f7b4d31
slicer/gate/ANALOG_DARK_STR 254a2e23a4e028bd
slicer/stut/DIGITAL_RHODES bd7cf0fa9a98ce22
slicer/song_gate_stut 63b91e6114945bd0
+86
View File
@@ -0,0 +1,86 @@
/* SPDX-License-Identifier: GPL-3.0-only */
/* GRAIN: a note played in the release of the note before sounds as loud as alone. A grain starts only while the
* part's grains decode at most GR_LOAD_MAX source samples an output sample; the released note kept starting grains
* through its long release, so the new held note's grains were refused for the load: SCAN PAD 86 then 88 (290 ms
* after the release) came out 29 dB down, SLOOP's PNO FREEZE 88 then 90 35 dB down, for the whole note.
* For each preset, note n (C5 .. F#7, every 2) for 1 s, released, 290 ms later n + 2 for 1 s: from 0.29 s on it holds
* at least a third of the grains it holds alone (starved: none; the rms is printed). Exit status: failed checks. */
#define main hostsim_main
#include "hostsim.c"
#undef main
#if CLIPPER_SYNTH
#define TAPL mix_l
#define TAPR mix_r
#else
#define TAPL acc[0].l
#define TAPR acc[0].r
#endif
static int32_t o[CTL * 2];
static void reset(uint32_t pi)
{
uint32_t i, b, k;
for (k = 0; k < NPART; k++) {
trk_all_off(&trk[k]);
for (i = 0; i < NVOICE; i++) trk[k].v[i].active = 0, trk[k].v[i].stage = 0, trk[k].v[i].env = 0, trk[k].v[i].env_out = 0;
}
for (b = 0; b < 400; b++) mix_block(o, CTL);
for (i = 0; i < P_E0; i++) trk[0].p[i] = TP[i].def;
host_preset(&trk[0], ENGI_GRAIN, pi);
trk[0].p[P_AMODE] = 0, trk[0].p[P_DLY] = trk[0].p[P_REV] = 0, trk[0].p[P_VOICE] = V_POLY;
for (b = 0; b < 64; b++) mix_block(o, CTL);
}
/* note held for blocks: the rms of blocks from .. on, *ng the mean count of its grains there (the held voices') */
static double hold(uint32_t note, uint32_t blocks, uint32_t from, double *ng)
{
gr_part_t *P = (gr_part_t *)eng_arena_of(&trk[0], ENGI_GRAIN);
uint32_t b, i;
double s2 = 0, g = 0;
trk_note_on(&trk[0], note, 100);
for (b = 0; b < blocks; b++) {
mix_block(o, CTL);
if (b < from)
continue;
for (i = 0; i < CTL; i++) {
double x = (TAPL[i] + TAPR[i]) / 2.0;
s2 += x * x;
}
for (i = 0; i < GR_NG; i++)
g += P->g[i].owner && trk[0].v[(P->g[i].owner - 1u) % NVOICE].gate;
}
trk_note_off(&trk[0], note);
if (ng)
*ng = g / (blocks - from);
return sqrt(s2 / ((blocks - from) * CTL));
}
int main(void)
{
uint32_t pi, b, gap = 400, n1, n2;
int fails = 0;
host_tracks_init();
for (pi = 0; pi < ENGINES[ENGI_GRAIN]->npresets; pi++) {
uint32_t bad = 0;
double worst = 1e9;
for (n1 = 72; n1 <= 100; n1 += 2) {
double alone, after, g0, g1;
n2 = n1 + 2;
reset(pi);
alone = hold(n2, 1400, 400, &g0);
reset(pi);
hold(n1, 1400, 1300, 0); /* 1 s */
for (b = 0; b < gap; b++) /* released, 290 ms */
mix_block(o, CTL);
after = hold(n2, 1400, 400, &g1);
if (g1 < g0 / 3) { /* (the level alone varies +-6 dB from cloud to cloud) */
bad++;
printf("grain: %-14s note %u: %.1f grains, rms %6.0f alone; 290 ms after note %u's release %.1f grains, rms %6.0f (%+.1f dB)\n",
ENGINES[ENGI_GRAIN]->presets[pi].name, n2, g0, alone, n1, g1, after, 20 * log10((after + 1) / (alone + 1)));
}
if (g1 / (g0 + 1e-9) < worst)
worst = g1 / (g0 + 1e-9);
}
printf("grain: %-14s 15 pairs C5 .. F#7: %s (the fewest grains: %.0f %% of alone)\n", ENGINES[ENGI_GRAIN]->presets[pi].name, bad ? "FAIL" : "ok", worst * 100);
fails += bad != 0;
}
printf("grain: %d failed\n", fails);
return fails;
}
+181
View File
@@ -0,0 +1,181 @@
/* SPDX-License-Identifier: GPL-3.0-only */
/* The FM-1's knobs (after 2.8.3; the SMK-37 version: SLOOP Pro): every page, every knob turned alone changes one value at
* most (sloop-pro #6: on REC READY, K3 START also moved K2 LENGTH). A turn is a detent at the read and one the scan ISR counts
* right after it (as on the device, where the scan runs while a UI pass does: tests/ui_pages_test.c enc_late); the page,
* HOME, the REC READY screen over each page, the synth and the drum track. What a turn changed: the global and track
* parameters, the steps, the REC screen's MODE / LENGTH / START / QUANT, the track, the page.
* cc -O2 -w -Ibuild/gen -Ifirmware/src -Ifirmware/hal tests/knob_walk_test.c -lm */
#define UI_PAGES_HARNESS_ONLY 1
#include "ui_pages_test.c"
typedef struct {
int16_t g[G_COUNT], p[NTRK][P_COUNT];
step_t step[NTRK][NSTEP];
uint8_t eng[NTRK], preset[NTRK];
int32_t x[12];
} snap_t;
static snap_t s0, s1;
static void snap(snap_t *s)
{
uint32_t k;
memcpy(s->g, song.g, sizeof s->g);
for (k = 0; k < NTRK; k++) {
memcpy(s->p[k], trk[k].p, sizeof s->p[k]);
memcpy(s->step[k], trk[k].step, sizeof s->step[k]);
s->eng[k] = trk[k].eng_req, s->preset[k] = trk[k].preset;
}
s->x[0] = rec_tempo, s->x[1] = rec_count, s->x[2] = rec_quant_off, s->x[3] = song.sel, s->x[4] = ui.page;
s->x[5] = ui.home, s->x[6] = ui.step_page, s->x[7] = ui.cursor, s->x[8] = drum_page, s->x[9] = drum_cursor;
s->x[10] = rec_wait, s->x[11] = ui.zoom;
}
/* the values a turn changed (a new sound, PRESETS: one), their names into what */
static uint32_t changed(char *what, size_t n)
{
static const char *const XN[12] = {"MODE", "START", "QUANT", "track", "page", "home", "step page", "cursor",
"drum page", "drum cursor", "rec arm", "zoom"};
uint32_t c = 0, k, i;
what[0] = 0;
#define NOTE(...) do { size_t l = strlen(what); c++; if (l + 24u < n) snprintf(what + l, n - l, __VA_ARGS__); } while (0)
for (i = 0; i < G_COUNT; i++)
if (s0.g[i] != s1.g[i])
NOTE(" g%u", i);
for (k = 0; k < NTRK; k++) {
if (s0.eng[k] != s1.eng[k] || s0.preset[k] != s1.preset[k]) {
NOTE(" t%u sound", k);
continue;
}
for (i = 0; i < P_COUNT; i++)
if (s0.p[k][i] != s1.p[k][i])
NOTE(" t%u p%u%s", k, i, i == P_SLEN ? "(LEN)" : "");
for (i = 0; i < NSTEP; i++)
if (memcmp(&s0.step[k][i], &s1.step[k][i], sizeof s0.step[k][i])) {
NOTE(" t%u steps", k); /* (the pattern: one value; a note's LEN is its TIE steps) */
break;
}
}
for (i = 0; i < 12u; i++)
if (s0.x[i] != s1.x[i] && !(i >= 4u && i <= 9u && s0.x[3] != s1.x[3]))
NOTE(" %s", XN[i]); /* (ALGORITHM: the new track's page, ui.c page_fix, is the same move) */
#undef NOTE
return c;
}
static uint32_t enc_of(uint32_t role) /* the FM-1: the encoder of a role (EN_SELECT .. EN_K4) */
{
return panel.enc[role] % 7u;
}
static uint32_t bad;
/* knob K(kn + 1) one detent (and a late one), on the screen as it is now; where: what is up */
static void turn(uint32_t kn, int32_t d, const char *where)
{
char what[256];
uint32_t e = enc_of(kn), c, i;
for (i = 0; i < 7u; i++)
encs[i] = enc_late[i] = 0;
ui.hot_t = 0, ui.bpm_t = 0, ui.msg_t = 0, ui.arm = 0;
frame(); /* (what the last turn left settles: GLO > MIDI's channels, ui.c
* midi_chan_fix, a frame later) */
snap(&s0);
encs[e] = d, enc_late[e] = d;
frame();
frame(); /* (a detent left for the next pass: read there) */
snap(&s1);
c = changed(what, sizeof what);
if (c > 1u) {
bad++;
if (bad <= 60u)
printf("knob_walk: %-26s encoder role %u %+d changed %u values:%s\n", where, kn, d, c, what);
}
}
int main(int argc, char **argv)
{
uint32_t i, pg, kn, t, rec;
static track_t keep[NTRK];
outdir = argc > 1 ? argv[1] : "build/host";
panel = PANEL_DEFAULT;
layers_init();
settings.palette = 4;
palette_set(4);
host_tracks_init();
for (i = 0; i < NPART; i++) { set_engine_of(&trk[i], TRK_DEF[i][0]); apply_preset_to(&trk[i], TRK_DEF[i][1]); trk[i].engine = trk[i].eng_req; }
TDRUM->p[P_E0] = DRUM_DEFAULT_KIT;
for (t = 0; t < NTRK; t++) /* a pattern on every track: the REC screen's LENGTH and START */
for (i = 0; i < 16u; i += 4u) {
if (t == TRK_DRUM) {
dstep_set(&trk[t].dstep[i], 0, LV_NORM, 0);
} else {
trk[t].step[i].time = ST_NOTE; trk[t].step[i].n = 1; trk[t].step[i].note[0] = (uint8_t)(48 + i);
}
}
memcpy(keep, trk, sizeof keep);
go_home(); ui.force = 1; frame();
{ /* sloop-pro #6, on the FM-1: REC READY (a pattern: LENGTH, START, QUANT), on TRACKS: KNOB 3 (START) */
uint32_t ok;
rec_count = 0; trk[0].p[P_SLEN] = 32; song.sel = 0;
go_home(); rec_wait = 1; ui.force = 1; frame();
encs[enc_of(EN_K3)] = 1; enc_late[enc_of(EN_K3)] = 1; frame(); frame();
ok = rec_count == 1u && trk[0].p[P_SLEN] == 32;
check(ok, "#6 REC READY, K3 START -> count: K2 LENGTH stays 2 bars");
printf("knob_walk: (START %u, LENGTH %d steps)\n", rec_count, trk[0].p[P_SLEN]);
rec_wait = 0; rec_count = 0; frame();
}
{ /* the count-in, a free take: KNOB 1..4 edit nothing (not the page under them either) */
char what[256];
uint32_t n = 0, w;
for (w = 0; w < 2u; w++)
for (kn = 0; kn < 4u; kn++) {
go_home(); song.sel = 0; frame();
rec_wait = (uint8_t)!w, ci_on = (uint8_t)!w, ft_on = (uint8_t)w;
for (i = 0; i < 7u; i++)
encs[i] = enc_late[i] = 0;
snap(&s0);
encs[enc_of(EN_K1 + kn)] = 1; enc_late[enc_of(EN_K1 + kn)] = 1; frame(); frame();
snap(&s1);
n += changed(what, sizeof what) != 0u;
rec_wait = 0, ci_on = 0, ft_on = 0; frame();
}
check(!n, "the count-in, a free take: K1..K4 change nothing");
memcpy(trk, keep, sizeof keep);
}
for (rec = 0; rec < 2u; rec++)
for (t = 0; t < 2u; t++)
for (pg = 0; pg <= NPAGES; pg++) {
char where[48];
const char *name;
song.sel = (uint8_t)(t ? TRK_DRUM : 0u);
song.playing = 0, transport_req = 0, song.rec = 0, ft_on = 0, ci_on = 0;
ui.menu = 0; ui.layer = LY_PLAY; ui.sheet = 0; vis_on = 0;
if (pg == NPAGES) {
go_home();
name = "HOME";
} else {
ui.page = (uint8_t)pg; ui.home = 0; song.seq_mode = 0;
name = PAGES[pg].title;
}
rec_wait = (uint8_t)rec;
ui.force = 1; frame();
if (pg < NPAGES && (ui.page != pg || ui.home))
continue; /* (a page this track does not have) */
if (rec && !rec_wait)
continue; /* (the song page: no arm) */
snprintf(where, sizeof where, "%s%s %s", rec ? "REC READY over " : "", name, t ? "(drums)" : "(synth)");
for (kn = 0; kn < NE; kn++) {
uint32_t r = kn;
if (pg < NPAGES && !rec && r >= EN_K1 && PAGES[pg].scope == SC_GLOBAL &&
(PAGES[pg].id[r - EN_K1] == G_LOAD || PAGES[pg].id[r - EN_K1] == G_SAVE ||
PAGES[pg].id[r - EN_K1] == G_CLRSEQ || PAGES[pg].id[r - EN_K1] == G_INITSND ||
PAGES[pg].id[r - EN_K1] == G_NEWPRJ))
continue; /* (a GO: a detent arms, a second one acts on the whole pattern / project) */
turn(kn, 1, where);
turn(kn, -1, where);
song.sel = (uint8_t)(t ? TRK_DRUM : 0u); /* (ALGORITHM: back to the track) */
if (pg < NPAGES && (ui.page != pg || ui.home))
break; /* (SELECT walked the pages) */
}
memcpy(trk, keep, sizeof keep);
rec_wait = 0;
}
check(!bad, "every page, HOME, REC READY (synth, drums): each knob alone changes one value at most");
printf("knob_walk: %s\n", fails ? "FAIL" : "ok");
return fails != 0;
}
+88
View File
@@ -0,0 +1,88 @@
/* SPDX-License-Identifier: GPL-3.0-only */
/* NOISE in LFSR mode: its register clock follows the keys past the sample rate. A Clipper report (clipper-fm1 #10):
* NZ ARCADE (TONE +84 semitones) played the same pitch on the whole upper half of the keyboard: the clock stopped at
* one register step a sample. Now a sample takes as many steps as clocks passed: the register's period (127 steps, the
* short register of NZ ARCADE) gives a fundamental of clock / 127 that goes on rising. For each note: the spectrum at
* that fundamental stands out of the rest, and no two notes give the same samples. Exit status: failed checks. */
#define main hostsim_main
#include "hostsim.c"
#undef main
#define NB 1200u /* blocks a note (~0.9 s) */
static int32_t cap[24][NB * CTL];
static int fails;
static void ok(int c, const char *what)
{
printf("noise: %-96s %s\n", what, c ? "ok" : "FAIL");
fails += !c;
}
/* the magnitude of the DFT of x[0..n) at f Hz (Hann window), and its median over 200 Hz .. 10 kHz */
static double mag_at(const int32_t *x, uint32_t n, double f)
{
double re = 0, im = 0;
uint32_t i;
for (i = 0; i < n; i++) {
double w = 0.5 - 0.5 * cos(2 * M_PI * i / n), a = 2 * M_PI * f * i / FS;
re += x[i] * w * cos(a);
im -= x[i] * w * sin(a);
}
return sqrt(re * re + im * im);
}
int main(void)
{
uint32_t e, pi = 0, k, b, nn = 0, same = 0, weak = 0;
static int32_t o[CTL * 2];
const engine_t *en = ENGINES[ENGI_NOISE];
host_tracks_init();
for (k = 0; k < en->npresets; k++)
if (!strcmp(en->presets[k].name, "NZ ARCADE"))
pi = k;
ok(!strcmp(en->presets[pi].name, "NZ ARCADE"), "NZ ARCADE found");
e = ENGI_NOISE;
host_preset(&trk[0], e, pi);
trk[0].p[P_VOICE] = V_POLY;
for (k = 36; k <= 102; k += 3, nn++) {
trk_all_off(&trk[0]);
for (b = 0; b < 400u; b++)
mix_block(o, CTL);
trk_note_on(&trk[0], k, 100);
for (b = 0; b < NB; b++) {
uint32_t i;
mix_block(o, CTL);
for (i = 0; i < CTL; i++)
cap[nn][b * CTL + i] = o[2 * i];
}
trk_note_off(&trk[0], k);
}
for (k = 0; k < nn; k++) {
uint32_t note = 36 + 3 * k, n = 16384, a = 4000, j;
double clock = 440.0 * pow(2.0, (note + en->presets[pi].e[7] - 69) / 12.0), f0 = clock / 127.0, m, med;
static double s[64];
if (k + 1 < nn && !memcmp(&cap[k][a], &cap[k + 1][a], 4096u * 4u))
same++;
if (f0 > 10000)
continue;
m = 0;
for (j = 0; j < 7; j++) { /* the strongest bin around f0 (+-3 bins) */
double v = mag_at(&cap[k][a], n, f0 + (j - 3.0) * FS / n);
if (v > m)
m = v;
}
for (j = 0; j < 64; j++) /* a sample of the spectrum: 200 Hz .. 10 kHz */
s[j] = mag_at(&cap[k][a], n, 200.0 + j * 153.1);
for (j = 1; j < 64; j++) { /* (sorted: the median) */
double v = s[j];
uint32_t q = j;
while (q && s[q - 1] > v) { s[q] = s[q - 1]; q--; }
s[q] = v;
}
med = s[32];
printf("noise: NZ ARCADE note %3u: clock %8.0f Hz, fundamental %6.0f Hz, %5.1f dB over the median\n", note, clock, f0,
20 * log10(m / (med + 1e-9)));
if (20 * log10(m / (med + 1e-9)) < 6)
weak++;
}
ok(same == 0, "NZ ARCADE: no two notes (3 semitones apart, C2..F#7) give the same samples");
ok(weak == 0, "NZ ARCADE: each note's fundamental (clock / 127) stands 6 dB over the spectrum's median");
printf("noise: %d failed\n", fails);
return fails;
}
+134
View File
@@ -0,0 +1,134 @@
/* SPDX-License-Identifier: GPL-3.0-only */
/* PHYS in tune: every pitched factory preset plays its notes at the equal-tempered pitch. The STRING and SYMP models
* were sharp: STR PLUCK +20 cents above E5 and +56 below E2, PLUCK BASS +71, BANJO +86, HARPSICH +104 at E1 .. E2
* (the loop's damping filter was compensated by twice its lag, the dispersion all-pass by a rule of thumb that grew
* with the delay; phys_dsp.c px_string_block).
* Pitched: the STRING and SYMP models (plucked strings, the sympathetic ones), and MODAL with a harmonic body
* (STRC 32 .. 38: stiffness 0) struck. Not here: MODAL's stiff bodies (bars, bells, blocks: their fundamental is set
* off on purpose, Rings' NthHarmonicCompensation), its bowed presets (noise through the same resonators: in tune as
* the struck ones, their phase too noisy to measure) and MEMB (drums).
* For each preset, notes 28 .. 100 every 4 (velocity 100, the preset's sound without vibrato): the fundamental from
* the phase advance of its partial between two windows 0.25 s apart (exact on a synthetic tone: SELF=cents tests the
* estimator); fails beyond +-5 cents (env TOL). The strings with a curved bridge (STRING below STRC 31, SYMP with BUZZ:
* KOTO, SITAR, TANPURA) bend their pitch as loud as they ring (the bridge shortens the string on the way up, longer on
* the way down: Rings' CURVED_BRIDGE, by design: SITAR -16 at E5): +-20 cents for them (BENDTOL); their loop is in tune (+-1 cent
* with the bridge straight). ONLY=name measures one preset. Exit status: failed checks. */
#define main hostsim_main
#include "hostsim.c"
#undef main
#if CLIPPER_SYNTH
#define TAPL mix_l
#define TAPR mix_r
#else
#define TAPL acc[0].l
#define TAPR acc[0].r
#endif
#define W 16384u /* window, samples (0.37 s) */
#define D 11025u /* the second window this much later (0.25 s) */
#define NX (W + D)
static double x[NX];
/* the Hann-windowed DFT of x[o .. o + W) at f Hz: re, im */
static void dft(uint32_t o, double f, double *re, double *im)
{
uint32_t i;
double r = 0, m = 0, w = 2 * M_PI * f / FS, c = cos(w), s = sin(w), cr = 1, ci = 0;
for (i = 0; i < W; i++) {
double h = (0.5 - 0.5 * cos(2 * M_PI * i / W)) * x[o + i], t;
r += h * cr, m -= h * ci;
t = cr * c - ci * s, ci = ci * c + cr * s, cr = t; /* (rotate: e^(j w i)) */
}
*re = r, *im = m;
}
/* the fundamental near fe: the strongest of +-80 cents (2-cent steps), then the phase advance over D samples */
static double f0_of(double fe)
{
double best = 0, bf = fe, k, r0, i0, r1, i1, dp;
for (k = -80; k <= 80; k += 2) {
double ff = fe * pow(2, k / 1200.0), v;
dft(0, ff, &r0, &i0);
v = r0 * r0 + i0 * i0;
if (v > best)
best = v, bf = ff;
}
dft(0, bf, &r0, &i0);
dft(D, bf, &r1, &i1);
dp = atan2(i1, r1) - atan2(i0, r0) - 2 * M_PI * bf * D / FS; /* = 2 pi (f - bf) D / FS, mod 2 pi */
dp -= 2 * M_PI * floor(dp / (2 * M_PI) + 0.5);
return bf + dp * FS / (2 * M_PI * D);
}
static int pitched(const preset_t *pr)
{
if (pr->e[0] == PM_STRING || pr->e[0] == PM_SYMP)
return 1;
return pr->e[0] == PM_MODAL && pr->e[1] >= 32 && pr->e[1] <= 38 && !pr->e[6]; /* harmonic, struck */
}
static int bent(const preset_t *pr) /* a curved bridge (px_string_block: STRUCTURE < 0.24) */
{
return (pr->e[0] == PM_STRING && pr->e[1] * 516 < 15729) || (pr->e[0] == PM_SYMP && 16384 - pr->e[6] * 129 < 15729);
}
int main(void)
{
static int32_t o[CTL * 2];
const engine_t *en = ENGINES[ENGI_PHYS];
double tol = getenv("TOL") ? atof(getenv("TOL")) : 5.0, btol = getenv("BENDTOL") ? atof(getenv("BENDTOL")) : 20.0;
uint32_t pi, n, i, b, k, fails = 0;
host_tracks_init();
if (getenv("SELF")) { /* the estimator on a decaying 3-partial tone */
for (n = 28; n <= 100; n += 4) {
double fe = 440 * pow(2, ((int)n - 69) / 12.0), ft = fe * pow(2, atof(getenv("SELF")) / 1200);
for (i = 0; i < NX; i++) {
double t = (i + 4480.0) / FS;
x[i] = exp(-t * 3) * (8000 * sin(2 * M_PI * ft * t) + 6000 * sin(2 * M_PI * 2.01 * ft * t + 1) +
3000 * sin(2 * M_PI * 3 * ft * t));
}
printf(" %u:%+.2f", n, 1200 * log2(f0_of(fe) / ft));
}
printf("\n");
return 0;
}
for (pi = 0; pi < en->npresets; pi++) {
const preset_t *pr = &en->presets[pi];
double worst = 0, t = bent(pr) ? btol : tol;
uint32_t bad = 0, wn = 0;
if (!pitched(pr) || (getenv("ONLY") && !strstr(pr->name, getenv("ONLY"))))
continue;
printf("phys_tune: %-12s", pr->name);
for (n = 28; n <= 100; n += 4) {
double fe = 440 * pow(2, ((int)n - 69) / 12.0), c;
uint32_t any = 1;
for (k = 0; k < NPART; k++)
trk_all_off(&trk[k]);
for (b = 0; b < 6000u && any; b++) { /* the last note rung out */
mix_block(o, CTL);
for (any = 0, i = 0; i < NVOICE; i++)
any |= trk[0].v[i].active;
}
for (i = 0; i < P_E0; i++) /* the preset as ui.c apply_preset_to loads it (dry) */
trk[0].p[i] = TP[i].def;
host_preset(&trk[0], ENGI_PHYS, pi);
trk[0].p[P_AMODE] = 0, trk[0].p[P_DLY] = trk[0].p[P_REV] = 0, trk[0].p[P_VOICE] = V_POLY;
trk[0].p[P_LD_PIT] = 0; /* (no vibrato) */
for (b = 0; b < 16; b++)
mix_block(o, CTL);
trk_note_on(&trk[0], n, 100);
for (b = 0; b < 140; b++) /* (0.1 s: the attack) */
mix_block(o, CTL);
for (b = 0; b < NX / CTL; b++) {
mix_block(o, CTL);
for (i = 0; i < CTL; i++)
x[b * CTL + i] = (TAPL[i] + TAPR[i]) / 2.0;
}
trk_note_off(&trk[0], n);
c = 1200 * log2(f0_of(fe) / fe);
printf(" %3u:%+5.1f", n, c);
if (fabs(c) > t)
bad++;
if (fabs(c) > fabs(worst))
worst = c, wn = n;
}
printf(" %s (worst %+.1f cents at %u%s)\n", bad ? "FAIL" : "ok", worst, wn, bent(pr) ? "; curved bridge: +-20" : "");
fails += bad != 0;
}
printf("phys_tune: %u failed\n", fails);
return (int)fails;
}
+17
View File
@@ -48,6 +48,8 @@ $CC -O2 -w -Ibuild/gen -Ifirmware/src -o "$OUT/song_audio_test" tests/song_audio
run "song: four simultaneous tracks, scene transition and stop" "$OUT/song_audio_test" "$OUT/song-demo.wav"
$CC -O2 -w -Ibuild/gen -Ifirmware/src -o "$OUT/song_ui_test" tests/song_ui_test.c -lm
run "song screen: commands, load (OCT+ twice), display bounds" "$OUT/song_ui_test" "$OUT/song-screen.ppm"
$CC -O2 -w -Ibuild/gen -Ifirmware/src -o "$OUT/song_arm_test" tests/song_arm_test.c -lm
run "song screen: a confirmation left unconfirmed asks again weeks later (no load / replace on one press)" "$OUT/song_arm_test"
$CC -O2 -w -Ibuild/gen -Ifirmware/src -o "$OUT/studio_drums_test" tests/studio_drums_test.c -lm
run "drum lanes, kit audio, metronome, record arm, free take" "$OUT/studio_drums_test" "$OUT/drum-styles.wav"
@@ -61,6 +63,10 @@ $CC -O2 -w -Ibuild/gen -Ifirmware/src -o "$OUT/drum_steal_test" tests/drum_steal
run "2.8.3: drum voices on a busy beat, every kit: no kick cut by another sound" "$OUT/drum_steal_test"
$CC -O2 -w -Ibuild/gen -Ifirmware/src -o "$OUT/chop_attack_test" tests/chop_attack_test.c -lm
run "2.8.3: a sample played again starts from silence with its ATK (POLY same note, MONO, LEGATO, UNISON), no click" "$OUT/chop_attack_test"
$CC -O2 -w -Ibuild/gen -Ifirmware/src -o "$OUT/fade_noise_test" tests/fade_noise_test.c -lm
run "SLOOP Pro #4: a note fading out keeps 16-bit resolution (DAC, MASTER 2048, USB FULL, 808 SLIDE): no 16 LSB floor" "$OUT/fade_noise_test"
$CC -O2 -w -Ibuild/gen -Ifirmware/src -Ifirmware/hal -o "$OUT/knob_walk_test" tests/knob_walk_test.c -lm
run "every page, HOME, REC READY: a knob turned alone changes one value (sloop-pro #6: REC READY K3 not K2 too)" "$OUT/knob_walk_test" "$OUT"
$CC -O2 -w -Ibuild/gen -Ifirmware/src -o "$OUT/drumkit_test" tests/drumkit_test.c -lm
run "synthesised drum kits: every kit x sound bounded, audible, finite, levels, cost" "$OUT/drumkit_test" "$OUT/drum-kits.wav" "$OUT/drum-kits.txt"
@@ -161,6 +167,17 @@ run "SLICER: no clicks, timing, sync with the sequencer, STUT, cost, demos" "$OU
$CC -O2 -w -Ibuild/gen -Ifirmware/src -o "$OUT/fm6_test" tests/fm6_test.c -lm
mkdir -p build/fm6_demo
run "FM6: algorithms, envelopes, retrigger, DC, clipping, macros, patch formats, voices, the bank, demos" "$OUT/fm6_test" build/fm6_demo
$CC -O2 -w -Ibuild/gen -Ifirmware/src -Ifirmware/hal -o "$OUT/noise_clock_test" tests/noise_clock_test.c -lm
run "NOISE LFSR: the clock follows the keys past the sample rate (NZ ARCADE, clipper-fm1 #10)" "$OUT/noise_clock_test"
$CC -O2 -w -Ibuild/gen -Ifirmware/src -Ifirmware/hal -o "$OUT/sample_pitch_test" tests/sample_pitch_test.c -lm
run "SAMPLE, GRAIN: the pitch follows the keys to the top of the keyboard (up to the decode bound)" "$OUT/sample_pitch_test"
$CC -O2 -w -Ibuild/gen -Ifirmware/src -Ifirmware/hal -o "$OUT/grain_release_test" tests/grain_release_test.c -lm
run "GRAIN: a note played in the release of the one before is not starved of grains" "$OUT/grain_release_test"
$CC -O2 -w -Ibuild/gen -Ifirmware/src -Ifirmware/hal -o "$OUT/phys_tune_test" tests/phys_tune_test.c -lm
run "PHYS: every pitched preset in tune (+-5 cents; a curved bridge +-20), notes 28..100" "$OUT/phys_tune_test"
$CC -O2 -w -Ibuild/gen -Ifirmware/src -Ifirmware/hal -o "$OUT/unison_level_test" tests/unison_level_test.c -lm
run "UNISON: every engine spreads its voices' phases (no stack of voices in phase over POLY)" "$OUT/unison_level_test"
run "the editor protocol and the other inputs (USB / TRS MIDI, damaged flash) fuzzed under ASan + UBSan, and its reproducers" sh tests/editor_fuzz.sh "${EDFZ_N:-2000}" 1
$CC -O2 -w -Ibuild/gen -Ifirmware/src -o "$OUT/regress" tests/regress.c -lm
# the CPU budget: counted by the kernel on macOS; elsewhere under callgrind when valgrind is there (exact, ~45 s;
# SKIP_CPU_VALGRIND=1 to time instead, which is only a rough check)
+241
View File
@@ -0,0 +1,241 @@
/* SPDX-License-Identifier: GPL-3.0-only */
/* SAMPLE and GRAIN follow the keys to the top of the FM-1's keyboard (OCT +3: note 115). Both bounded their decode
* load with a cap on the playback rate (SAMPLE: 3 octaves over the zone's root; GRAIN: 2 source samples an output
* sample), so every key past it played the same pitch: Clipper's sets are one 16 kHz zone (VOX's root A3), so SAMPLE
* CHOIR was flat from A6 (93) and VOX CLOUD from G6 (87); SLOOP's top zones (root C5) went flat from C8 (108).
* For each preset that follows the keys (C4 -> C5 one octave up): each note two semitones over the one before sounds
* 1..3 semitones higher (the shift of its log-frequency spectrum, or of its strongest peak, or 4 semitones over the note before it;
* no two steps in a row wrong), from C4 to TOP (env TOP, default 115). GRAIN: up to
* where a grain would read more than 8 source samples an output sample (its part's decode bound, GR_LOAD_MAX, with the
* preset's PTCH and RAND detune), if that comes first: past it a grain's pitch may stop (the cost bound). SAMPLE: up to
* where a voice would decode more than 8 source samples an output sample (a 44.1 kHz zone 3 octaves up, the bound it
* always had; SMP_STEP_MAX), if that comes first.
* Exit status: failed checks. */
#define main hostsim_main
#include "hostsim.c"
#undef main
#if CLIPPER_SYNTH
#define TAPL mix_l
#define TAPR mix_r
#else
#define TAPL acc[0].l
#define TAPR acc[0].r
#endif
#define N 32768u /* (0.74 s: a cloud of short grains averages out) */
#define LB 8 /* log-spectrum bins a semitone */
#define LN (128 * LB) /* MIDI 8 .. 136 */
static double re_[N], im_[N];
static int fails;
static void fft(double *re, double *im, uint32_t n)
{
uint32_t i, j = 0, k, m;
for (i = 1; i < n; i++) {
uint32_t bit = n >> 1;
for (; j & bit; bit >>= 1) j ^= bit;
j ^= bit;
if (i < j) { double t = re[i]; re[i] = re[j]; re[j] = t; t = im[i]; im[i] = im[j]; im[j] = t; }
}
for (m = 2; m <= n; m <<= 1) {
double a = -2 * M_PI / m;
for (k = 0; k < n; k += m)
for (i = 0; i < m / 2; i++) {
double wr = cos(a * i), wi = sin(a * i);
double xr = re[k + i + m / 2] * wr - im[k + i + m / 2] * wi, xi = re[k + i + m / 2] * wi + im[k + i + m / 2] * wr;
re[k + i + m / 2] = re[k + i] - xr; im[k + i + m / 2] = im[k + i] - xi;
re[k + i] += xr; im[k + i] += xi;
}
}
}
/* note k of preset pi: its log spectrum (dB over a -60 dB floor) into ls, returns the rms */
static double render(uint32_t e, uint32_t pi, uint32_t note, double *ls)
{
static int32_t o[CTL * 2];
static double x[N], mag[N / 2 + 1];
uint32_t i, b, any = 1, k;
double s = 0, s2 = 0, mx = 1e-9;
for (k = 0; k < NPART; k++)
trk_all_off(&trk[k]);
for (b = 0; b < 3000u && any; b++) { /* the last note's release */
mix_block(o, CTL);
for (any = 0, i = 0; i < NVOICE; i++)
any |= trk[0].v[i].active;
}
for (i = 0; i < P_E0; i++) /* the preset as ui.c apply_preset_to loads it (dry) */
trk[0].p[i] = TP[i].def;
host_preset(&trk[0], e, pi);
trk[0].p[P_AMODE] = 0;
trk[0].p[P_DLY] = trk[0].p[P_REV] = 0;
trk[0].p[P_VOICE] = V_POLY;
for (b = 0; b < 16; b++)
mix_block(o, CTL);
trk_note_on(&trk[0], note, 100);
for (b = 0; b < 140; b++) /* (0.1 s: the attack) */
mix_block(o, CTL);
for (b = 0; b < N / CTL; b++) {
mix_block(o, CTL);
for (i = 0; i < CTL; i++)
x[b * CTL + i] = (TAPL[i] + TAPR[i]) / 2.0;
}
trk_note_off(&trk[0], note);
for (i = 0; i < N; i++)
s += x[i];
for (i = 0; i < N; i++) {
double v = x[i] - s / N;
s2 += v * v;
re_[i] = v * (0.5 - 0.5 * cos(2 * M_PI * i / N));
im_[i] = 0;
}
fft(re_, im_, N);
for (i = 0; i <= N / 2; i++)
mag[i] = sqrt(re_[i] * re_[i] + im_[i] * im_[i]);
for (i = 0; i < LN; i++) { /* the strongest bin within each 1/8 semitone */
double f0 = 440.0 * pow(2, ((double)i / LB + 8 - 0.5 / LB - 69) / 12), f1 = f0 * pow(2, 1.0 / (12 * LB));
double b0 = f0 * N / FS, b1 = f1 * N / FS, v = 0;
uint32_t a = (uint32_t)b0, c;
if (b1 >= N / 2) {
ls[i] = 0;
continue;
}
if (b1 - b0 < 1) {
double fr = (b0 + b1) / 2 - a;
v = mag[a] * (1 - fr) + mag[a + 1] * fr;
} else
for (c = a; c <= (uint32_t)b1; c++)
if (mag[c] > v)
v = mag[c];
ls[i] = v;
if (v > mx)
mx = v;
}
for (i = 0; i < LN; i++) {
double d = 20 * log10(ls[i] / mx + 1e-9) + 60;
ls[i] = d > 0 ? d : 0;
}
return sqrt(s2 / N);
}
/* GRAIN: source samples an output sample a grain of the note reads at most (PTCH, the RAND detune at its top), Q16 */
static double grain_rate(uint32_t pi, uint32_t note)
{
const preset_t *pr = &ENGINES[ENGI_GRAIN]->presets[pi];
uint32_t src = (uint32_t)pr->e[0] % SMP_NALL;
int32_t zl = gr_find(src, note);
const smp_zone_t *z;
double d16;
if (zl < 0)
return 0;
z = gr_zone(src, (uint32_t)zl);
d16 = note * 16.0 + pr->e[4] * 16 - z->root16 + pr->e[6] * pr->e[6] * 192.0 / (127 * 127);
return pow(2, d16 / 192) * z->rate / 65536.0;
}
/* SAMPLE: the playback rate of the note (source samples an output sample) and its cap (eng_sample.c sample_render) */
static int sample_capped(uint32_t pi, uint32_t note)
{
const preset_t *pr = &ENGINES[4]->presets[pi];
uint32_t si = (uint32_t)pr->e[0] % SMP_NALL, i;
const smp_zone_t *z = 0;
double rate, lim;
if (si >= SMP_NSETS)
return 0;
for (i = 0; i < SMP_SETS[si].nz; i++)
if (note >= SMP_ZONES[SMP_SETS[si].z0 + i].lo && note <= SMP_ZONES[SMP_SETS[si].z0 + i].hi)
z = &SMP_ZONES[SMP_SETS[si].z0 + i];
if (!z)
z = &SMP_ZONES[SMP_SETS[si].z0];
rate = pow(2, (note * 16.0 + pr->e[1] * 16 - z->root16) / 192) * z->rate / 65536.0;
lim = 8.0 * z->rate / 65536.0;
return rate > (lim > (double)(SMP_STEP_MAX >> 16) ? lim : (double)(SMP_STEP_MAX >> 16));
}
/* how far b's spectrum lies over a's, in semitones (-4 .. +14) */
static double shift(const double *a, const double *b)
{
int s, i, best = 0;
double bv = -1;
for (s = -4 * LB; s <= 14 * LB; s++) {
double ab = 0, aa = 0, bb = 0;
for (i = 0; i < LN; i++) {
int j = i + s;
double y = j >= 0 && j < LN ? b[j] : 0;
ab += a[i] * y, aa += a[i] * a[i], bb += y * y;
}
if (aa > 0 && bb > 0 && ab / sqrt(aa * bb) > bv)
bv = ab / sqrt(aa * bb), best = s;
}
return (double)best / LB;
}
/* the same from the strongest peak alone (a second opinion: either one right is enough) */
static double peak_shift(const double *a, const double *b)
{
int i, ia = 0, ib = 0;
for (i = 1; i < LN; i++) {
if (a[i] > a[ia])
ia = i;
if (b[i] > b[ib])
ib = i;
}
return (double)(ib - ia) / LB;
}
int main(void)
{
static const uint32_t EN[2] = {4, ENGI_GRAIN}; /* SAMPLE, GRAIN */
static double l0[LN], l1[LN], lp[LN]; /* notes n, n + 2, n - 2 */
uint32_t top = getenv("TOP") ? (uint32_t)atoi(getenv("TOP")) : 115u, k, pi, n;
host_tracks_init();
for (k = 0; k < 2u; k++) {
const engine_t *en = ENGINES[EN[k]];
for (pi = 0; pi < en->npresets; pi++) {
double r60 = render(EN[k], pi, 60, l0), r72 = render(EN[k], pi, 72, l1), sh = shift(l0, l1), r;
uint32_t bad = 0, first = 0, tested = 0, run = 0, runs = 0; /* runs: two wrong steps in a row (one alone:
* a grain cloud's spectrum can fool the estimate once) */
if (r60 < 30 || r72 < 30 || sh < 11 || sh > 13) {
printf("pitch: %-6s %-14s C4 -> C5: %+5.2f semitones: does not follow the keys (a kit), not tested\n",
en->name, en->presets[pi].name, sh);
continue;
}
r = render(EN[k], pi, 60, l0);
memcpy(lp, l0, sizeof lp);
for (n = 60; n + 2u <= top; n += 2u) {
double r1, d;
if (EN[k] == ENGI_GRAIN && grain_rate(pi, n + 2u) > 8.0) {
printf("pitch: %-6s %-14s from note %u: past the grain decode bound, not tested\n", en->name, en->presets[pi].name, n + 2u);
break;
}
if (EN[k] == 4u && sample_capped(pi, n + 2u)) {
printf("pitch: %-6s %-14s from note %u: past the decode bound, not tested\n", en->name, en->presets[pi].name, n + 2u);
break;
}
r1 = render(EN[k], pi, n + 2u, l1);
if (r > r60 / 30 && r1 > r60 / 30) {
d = shift(l0, l1);
tested++;
if (d < 1.0 || d > 3.0)
d = peak_shift(l0, l1);
if ((d < 1.0 || d > 3.0) && n > 60u) { /* (a noisy cloud: n - 2 -> n + 2 is 4 semitones) */
double d4 = shift(lp, l1), p4 = peak_shift(lp, l1);
if ((d4 >= 2.5 && d4 <= 5.5) || (p4 >= 2.5 && p4 <= 5.5))
d = 2.0;
}
if (d < 1.0 || d > 3.0) {
if (!bad++)
first = n;
if (bad <= 4)
printf("pitch: %-6s %-14s note %3u -> %3u: %+5.2f semitones\n", en->name, en->presets[pi].name, n, n + 2u, d);
runs += ++run >= 2u;
} else {
run = 0;
}
}
memcpy(lp, l0, sizeof lp);
memcpy(l0, l1, sizeof l0);
r = r1;
}
printf("pitch: %-6s %-14s C4..%u, %2u steps of 2 semitones: %s", en->name, en->presets[pi].name, n < top ? n : top, tested,
runs ? "FAIL" : "ok");
if (bad)
printf(" (%u wrong, %u in a row, the first from note %u)", bad, runs, first);
printf("\n");
fails += runs != 0;
}
}
printf("pitch: %d failed\n", fails);
return fails;
}
+66
View File
@@ -0,0 +1,66 @@
/* SPDX-License-Identifier: GPL-3.0-only */
/* The song screen's confirmations (ui_song.c): OCT+ (load) and REC over a used section (replace) ask for a second
* press within 3 s. The arm was compared with a deadline as a signed difference: one left unconfirmed read as still
* armed 24.9 to 49.7 days later (a single press loaded or replaced a section). Now the time since the arm.
* Exit status: failed checks. */
#define FELUCCA_ARRANGER 1
#define main hostsim_main
#include "hostsim.c"
#undef main
#include <assert.h>
static uint16_t screen[240*240];
static void lcd_sync(void) {}
static void lcd_blit(uint32_t x, uint32_t y, uint32_t w, uint32_t h, const uint16_t *p)
{
uint32_t i,j;
assert(x+w<=240 && y+h<=240);
for(j=0;j<h;j++) for(i=0;i<w;i++) screen[(y+j)*240+x+i]=p[j*w+i];
}
#include "../firmware/src/gfx.c"
enum {B_FX,B_SCL,B_ENV,B_LFO,B_EDIT,B_GLO,B_HOME,B_SAVE,B_ARP,B_SEQ,B_PLAY,B_REC,B_OCTDN,B_OCTUP,NB};
enum {EN_SELECT,EN_ALGO,EN_PRESET,EN_K1,EN_K2,EN_K3,EN_K4,NE};
static struct {uint8_t btn[NB];} panel;
static struct {uint8_t home,page,force,msg_t;char msg[24];} ui;
static int32_t enc[NE];
static uint32_t ready, scene_saves, order_saves, loads;
static uint32_t arrangement_ready(void) {return ready;}
static void arrangement_apply(uint32_t scene) {(void)scene;}
static uint32_t section_bars(uint32_t s) {(void)s;return 1;}
static const page_t *cur_page(void) {return &PAGES[ui.page];}
static int project_used(uint32_t i) {return (ready>>i)&1u;}
static void project_save(uint32_t i) {ready|=1u<<i;scene_saves++;}
static void project_load(uint32_t i) {(void)i;loads++;}
static void settings_save(void) {}
static void arrangement_save(void) {order_saves++;}
static void ui_message(const char *s) {str_cpy(ui.msg,s,sizeof ui.msg);ui.msg_t=40;}
static void go_home(void) {ui.home=1;}
static void open_family(uint32_t f) {(void)f;ui.home=1;}
static int32_t panel_enc(uint32_t i) {int32_t s=enc[i];enc[i]=0;return s;}
static void song_backup(void) {}
static void song_restore(void) {}
#include "../firmware/src/ui_song.c"
static void press(uint32_t b) {song_screen_input(1u<<panel.btn[b],0);}
int main(void)
{
uint32_t i, fails = 0, s0, l0;
arr_defaults(&arrangement);
for(i=0;i<NB;i++) panel.btn[i]=(uint8_t)i;
for(i=0;i<NPAGES;i++) if(PAGES[i].scope==SC_SONG) ui.page=(uint8_t)i;
ready = 1; /* section A saved */
fm1_ms = 1000000u;
press(B_OCTUP); /* "OCT+ AGAIN: LOAD", then left */
fm1_ms += 0x80000000u + 5000u; /* 24.9 days later */
l0 = loads;
press(B_OCTUP); /* one press: must ask again, not load */
printf("song_arm: OCT+ once, 24.9 days after an OCT+ left unconfirmed: %s (%s)\n", loads == l0 ? "asks again" : "LOADED at once", ui.msg);
fails += loads != l0;
press(B_OCTDN); /* (no arm left: LOOP / SONG MODE toggled) */
s0 = scene_saves;
fm1_ms = 2000000u;
press(B_REC); /* "REC AGAIN: REPLACE", then left */
fm1_ms += 0x80000000u + 5000u;
press(B_REC); /* one press: must ask again, not replace */
printf("song_arm: REC once, 24.9 days after a REC left unconfirmed: %s (%s)\n", scene_saves == s0 ? "asks again" : "REPLACED at once", ui.msg);
fails += scene_saves != s0;
return (int)fails;
}
+23 -1
View File
@@ -254,6 +254,28 @@ int main(int argc, char **argv)
release(B_FX); frame();
check(!shown && cur_fam() == FAM_FX, "2.8.3: FX tapped in 0.3 s: no flash of the layer, the FX pages");
}
{ /* (after 2.8.3, clipper-fm1 #24) a firm press, let go untouched within a second, opens what a quick tap opens:
* a press of 0.6 s used to open nothing (TAP 0.45 s: the layer flashed, the TRACKS screen stayed); held
* 1.3 s: a look at the layer, back where it was */
static const uint32_t LB[7] = {B_FX, B_EDIT, B_ARP, B_SEQ, B_SCL, B_GLO, B_SAVE};
uint32_t q, ok = 1;
for (q = 0; q < 7u; q++) {
uint32_t h_home, h_page, t_home, t_page;
go_home(); frames(2);
h_home = ui.home; h_page = ui.page;
tap(LB[q]); frames(3);
t_home = ui.home; t_page = ui.page;
ok &= t_home != h_home || t_page != h_page; /* (the tap opens something) */
go_home(); frames(2);
press(LB[q]); frames(37); release(LB[q]); frames(3); /* (0.6 s) */
ok &= ui.home == t_home && ui.page == t_page && !ui.menu;
go_home(); frames(2);
press(LB[q]); frames(80); release(LB[q]); frames(3); /* (1.3 s) */
ok &= ui.home == h_home && ui.page == h_page && ui.layer == LY_PLAY;
}
go_home(); frames(2);
check(ok, "FX, EDIT, ARP, SEQ, SEL, GLO, SAVE pressed 0.6 s untouched: what a tap opens; held 1.3 s: no page");
}
go_home(); frame();
press(B_FX); frames(24); check(ui.layer == LY_FX && punch.hold, "FX held: the punch layer shows"); /* (2.8.3: after 0.35 s) */
check(keys_guide() == (1u << key_of_white(0) | 1u << key_of_white(4) | 1u << key_of_white(8) | 1u << key_of_white(12)),
@@ -1468,7 +1490,7 @@ int main(int argc, char **argv)
{ int16_t bpm = song.g[G_BPM], lv = trk[0].p[P_LEVEL];
encs[panel.enc[EN_K2]] = 5; frame();
check(trk[0].p[P_LEVEL] == lv && song.g[G_BPM] == bpm, "visualiser: KNOB 2 (the hidden TRACKS screen) edits nothing, SELECT is not the tempo"); }
press(B_GLO); frames(40); /* (held past a tap) */
press(B_GLO); frames(70); /* (held past a tap: 1 s, clipper-fm1 #24) */
check(ui.layer == LY_MIX, "visualiser: a layer held shows its screen");
release(B_GLO); frames(4);
check(vis_shown(), "visualiser: ... and it comes back");
+103
View File
@@ -0,0 +1,103 @@
/* SPDX-License-Identifier: GPL-3.0-only */
/* VOICE = UNISON about as loud as POLY, on every engine. Unison starts its extra voices at random phases (voice.c
* unison_spread) and at a lower level (the velocity: about the same sum). In phase they stack: 8 voices at 0.36 are
* +9 dB over one. unison_spread moved ph[0] only, and most engines keep more oscillators (ph[1], ph[2], operators, a
* sample's read position): their voices stacked in phase (ANALOG WARM PAD +12.9 dB, PHASE CZ LEAD +10.6, SAMPLE +8.4
* on average). Each engine now spreads all of its oscillators by the same time shift (their relative phases, the
* timbre, as they were); SAMPLE starts a voice up to four periods later (at most 256 source samples).
* For every preset of every engine, notes 36 and 60 (velocity 100, chorus, delay, reverb off): the rms over
* 0.05 .. 0.55 s in UNISON (the preset's DETUNE) against POLY. Fails when a render is more than +8 dB over POLY or an
* engine's mean over +5 dB. Exit status: failed checks. (The same file as Clipper's, which also plays UNI4.) */
#define main hostsim_main
#include "hostsim.c"
#undef main
#if CLIPPER_SYNTH
#define TAPL mix_l
#define TAPR mix_r
#else
#define TAPL acc[0].l
#define TAPR acc[0].r
#endif
static int32_t o[CTL * 2];
static double play(uint32_t e, uint32_t p, uint32_t mode, uint32_t note)
{
uint32_t i, b, k, any = 1;
double s2 = 0;
for (k = 0; k < NPART; k++)
trk_all_off(&trk[k]);
for (b = 0; b < 6000u && any; b++) { /* the last note rung out */
mix_block(o, CTL);
for (any = 0, i = 0; i < NVOICE; i++)
any |= trk[0].v[i].active;
}
for (i = 0; i < P_E0; i++) /* the preset as ui.c apply_preset_to loads it */
trk[0].p[i] = TP[i].def;
host_preset(&trk[0], e, p);
trk[0].p[P_AMODE] = 0, trk[0].p[P_DLY] = trk[0].p[P_REV] = 0, trk[0].p[P_CHOR] = 0;
trk[0].p[P_VOICE] = (int16_t)mode;
for (b = 0; b < 16; b++)
mix_block(o, CTL);
trk_note_on(&trk[0], note, 100);
for (b = 0; b < 760; b++) {
mix_block(o, CTL);
if (b >= 69)
for (i = 0; i < CTL; i++) {
double x = (TAPL[i] + TAPR[i]) / 2.0;
s2 += x * x;
}
}
trk_note_off(&trk[0], note);
return sqrt(s2 / ((760 - 69) * CTL));
}
#if CLIPPER_SYNTH
#define NM 2u
static const uint32_t MODE[NM] = { V_UNISON, V_PUNI4 };
static const char *const MN[NM] = { "UNISON", "UNI4" };
#else
#define NM 1u
static const uint32_t MODE[NM] = { V_UNISON };
static const char *const MN[NM] = { "UNISON" };
#endif
/* engine e: in each unison mode, the mean unison / POLY ratio (dB) of its presets at notes 36 and 60 */
static void engine(uint32_t e, int *fails)
{
const engine_t *en = ENGINES[e];
uint32_t p, k, m, n = 0;
double sum[NM][2], worst[NM], mean;
const char *wn[NM];
for (m = 0; m < NM; m++)
sum[m][0] = sum[m][1] = 0, worst[m] = -99, wn[m] = "";
for (p = 0; p < en->npresets; p++, n++)
for (k = 0; k < 2u; k++) {
uint32_t note = k ? 60u : 36u;
double r0 = play(e, p, V_POLY, note);
for (m = 0; m < NM; m++) {
double d = 20 * log10((play(e, p, MODE[m], note) + 1) / (r0 + 1));
if (d > 8.0) {
printf("unison: %-7s %-6s %-14s note %u: %+.1f dB over POLY FAIL\n", en->name, MN[m],
en->presets[p].name, note, d);
++*fails;
}
if (d > worst[m])
worst[m] = d, wn[m] = en->presets[p].name;
sum[m][k] += d;
}
}
for (m = 0; n && m < NM; m++) {
mean = (sum[m][0] + sum[m][1]) / (2 * n);
printf("unison: %-7s %-6s mean %+5.1f dB over POLY (note 36 %+5.1f, 60 %+5.1f; %3u presets; the most %+5.1f, %s)%s\n",
en->name, MN[m], mean, sum[m][0] / n, sum[m][1] / n, n, worst[m], wn[m], mean > 5.0 ? " FAIL" : "");
if (mean > 5.0)
++*fails;
}
}
int main(void)
{
int fails = 0;
uint32_t e;
host_tracks_init();
for (e = 0; e < NENGINES; e++)
engine(e, &fails);
printf("unison: %d failed\n", fails);
return fails;
}
+4 -4
View File
@@ -102,7 +102,7 @@ const TEXT = {
direct: "USB ケーブルはパソコンに直接つないでください。Probe や Transporter などの機材は不要です。",
brick: "万一インストールに失敗して起動しなくなった場合は、復旧に Transporter が必要です:",
beta: "これはベータ版で、不安定な場合があります。このカスタムファームウェアを使ったことで FM-1 が壊れたり不具合が起きたりしても、作者は一切の責任を負いません。自己責任でお使いください。",
back: "公式ファームウェアに戻すには、M-VAVE 公式のアップデーター M-UPGRADE(Downloads → PC Software → M-UPGRADE)と公式ファームウェア(PC Firmware → FM-1 V15)が必要です。",
back: "公式ファームウェアに戻すには、M-VAVE 公式のアップデーター M-UPGRADE(Downloads → PC Software → M-UPGRADE)と公式ファームウェア(PC Firmware → FM-1、V16)が必要です。",
nomidi: "このブラウザでは使えません。Chrome か Edge で開いてください。", loadfail: "読み込めませんでした: ",
start: "開始します", verify: "確認中", loader: "書き込みモードに切り替え中", write: "書き込み中",
reboot: "再起動中", done: "完了しました", stopped: "途中で止まりました。USB を挿し直してもう一度押してください。",
@@ -126,7 +126,7 @@ const TEXT = {
stockValid: "公式 V15 を確認しました", stockBad: "公式 V15 ではありません: ",
stockConfirm: "FM-1 に公式 V15 をインストールします。SLOOP の曲は公式ファームウェアでは開けません。バックアップは保存しましたか?",
stockFinish: "FM-1 は SLOOP の書き込みモードです。先に「インストール」で SLOOP の書き込みを終えてから、公式 V15 に戻してください。",
back: "公式ファームウェアに戻すには、M-VAVE 公式のアップデーター M-UPGRADE(Downloads → PC Software → M-UPGRADE)と公式ファームウェアを使ってください。FM-1 が見つからない場合は、MIDI を使う他のアプリとブラウザのタブを閉じてください。",
back: "公式ファームウェアに戻すには、M-VAVE 公式のアップデーター M-UPGRADE(Downloads → PC Software → M-UPGRADE)と公式ファームウェアを使ってください。FM-1 が見つからない場合は、MIDI を使う他のアプリとブラウザのタブを閉じてください。それでも見つからない場合は、Clipper のインストールページを開き、その「Return to the official firmware」を使ってください(Clipper を入れる必要はありません)。",
},
en: {
intro: "Connect the FM-1 by USB. (Works in Chrome or Edge.)",
@@ -138,7 +138,7 @@ const TEXT = {
direct: "Connect the USB cable directly to the computer. No probe or Transporter is needed.",
brick: "If an install fails and the FM-1 no longer starts, recovering it needs a Transporter:",
beta: "This is a beta and may be unstable. The author accepts no responsibility if your FM-1 is damaged or misbehaves because of this custom firmware. Use it at your own risk.",
back: "To go back to the official firmware you need M-VAVE's official updater, M-UPGRADE (Downloads → PC Software → M-UPGRADE), and the official firmware (PC Firmware → FM-1 V15).",
back: "To go back to the official firmware you need M-VAVE's official updater, M-UPGRADE (Downloads → PC Software → M-UPGRADE), and the official firmware (PC Firmware → FM-1, V16).",
nomidi: "This browser cannot do it. Open the page in Chrome or Edge.", loadfail: "Could not load: ",
start: "Starting", verify: "Verifying", loader: "Switching to update mode", write: "Writing",
reboot: "Restarting", done: "Done", stopped: "Stopped. Replug the USB cable and press Install again.",
@@ -162,7 +162,7 @@ const TEXT = {
stockValid: "Official V15 verified", stockBad: "Not the official V15: ",
stockConfirm: "Install the official V15 on the FM-1? The official firmware cannot open SLOOP's music. Did you save a backup?",
stockFinish: "The FM-1 is in SLOOP's update mode. Press Install to finish the SLOOP update first, then return to the official V15.",
back: "To return to the official firmware, use M-VAVE's own updater, M-UPGRADE (Downloads → PC Software → M-UPGRADE), with the official firmware from M-VAVE. If it does not find the FM-1, close every other app and browser tab that uses MIDI.",
back: "To return to the official firmware, use M-VAVE's own updater, M-UPGRADE (Downloads → PC Software → M-UPGRADE), with the official firmware from M-VAVE (PC Firmware → FM-1, V16). If it does not find the FM-1, close every other app and browser tab that uses MIDI; if it still does not, open Clipper's installer page and use its Return to the official firmware (no need to install Clipper).",
},
};
let lang = (navigator.language || "en").toLowerCase().startsWith("ja") ? "ja" : "en";