commit a3f9fd04c85f99f74db6b881fb9ef91d38f70e95 Author: isod89 Date: Sun Oct 4 11:08:49 2026 -0400 SLOOP 2.0 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..ff82a3a --- /dev/null +++ b/.gitattributes @@ -0,0 +1,7 @@ +* text=auto +*.bat text eol=crlf +*.ps1 text eol=crlf +*.sh text eol=lf +*.wav binary +*.png binary +*.ttf binary diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6669814 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +build/ +.DS_Store +__pycache__/ diff --git a/BUILDING.md b/BUILDING.md new file mode 100644 index 0000000..9925165 --- /dev/null +++ b/BUILDING.md @@ -0,0 +1,110 @@ +# Building SLOOP + +The build makes three files in `build/`: + +| File | What | +| --- | --- | +| `felucca.bin` | the firmware app | +| `loader/ota.bin` | the update loader | +| `felucca.fwsc` | the installable package (app + loader) | + +## Windows (WSL) + +`INSTALL-SLOOP.bat` builds in a WSL distribution and opens the installer on +`http://localhost:8766/webapp/installer/`. It needs Python 3 with Pillow on Windows, a WSL +distribution with the JieLi toolchain, and the three SDK files (below) in `build/deps/ac79`. +Set `SLOOP_WSL_DISTRO` (default `Ubuntu`) and `SLOOP_TOOLCHAIN` (a Linux path, default +`/root/.jieli/toolchain`) if yours differ. + +## Prerequisites (macOS) + +- Python 3 with Pillow: `pip3 install Pillow` +- Docker Desktop. The JieLi toolchain is Linux x86-64 only; the build runs each tool in a + `linux/amd64` `debian:bookworm-slim` container (Rosetta on Apple silicon). Keep the source + tree in a folder Docker can share, e.g. under `/Users`. +- The JieLi Linux toolchain (clang 4.0.1 for pi32v2, from JieLi's package server): + + ``` + tools/get_toolchain.sh # installs to ~/.jieli/toolchain + ``` + +- The JieLi AC79 SDK (Apache-2.0). The package uses three of its files + (`cpu/wl82/tools/uboot.boot`, `cfg_tool.bin`, `cfg/eq_cfg_hw.bin`); they are not part of this tree. + + ``` + git clone --depth 1 --branch AC79NN_SDK_V1.2.1_2023-12-13 \ + https://gitee.com/Jieli-Tech/fw-AC79_AIoT_SDK.git ~/fw-AC79_AIoT_SDK + ``` + +- Node.js (optional, for the web tests). + +On Linux x86-64 the toolchain runs natively and Docker is not needed. + +## Build + +``` +./build.sh +``` + +`JIELI_TOOLCHAIN` and `AC79_SDK` override the default locations +(`~/.jieli/toolchain`, `~/fw-AC79_AIoT_SDK`). + +`./build.sh --release 0.9-beta` makes a release build: the package identity becomes +`FM-1_909` and the version string `0.9-BETA`; the package is `build/felucca-0.9-beta.fwsc`. + +Build options (environment, `0` or `1`; defaults in `firmware/src/felucca.c`): + +| Flag | Default | | +| --- | --- | --- | +| `FELUCCA_FLASH` | 1 | settings, presets and projects in flash | +| `FELUCCA_OTA` | 1 | update entry (needs `FELUCCA_FLASH`) | +| `FELUCCA_CDC` | 1 | USB serial console | +| `FELUCCA_UART` | 0 | TRS MIDI IN (not tested on hardware) | + +## Samples + +The CC0 instrument samples that the SAMPLE engine uses are in `assets/samples-cc0/` +(Versilian Studios, see `ATTRIBUTION.txt` there). `tools/fetch_cc0.py` downloads them +again from the source repositories. Without that folder the build still works and the +SAMPLE engine has only the generated drum kit. + +## Tests + +``` +tests/run_tests.sh +``` + +Runs the host tests (flash storage, user presets, MIDI parser, update entry, update +loader, a DSP render, the 4-track mix, project formats, the SLICER, the regression suite, +the command-line installer) and, with Node.js, the web page tests. Run it after `./build.sh` +(it uses `build/` and needs `AC79_SDK` set as for the build). + +The regression suite (`tests/regress.c`) renders every engine and preset and compares a +hash of each render with `tests/golden.txt`; it also checks levels, voices and the CPU +cost (`tests/cpu_baseline.txt`, `tests/target_budget.txt`). After an intended change of +the sound, `GOLDEN_UPDATE=1 sh tests/run_tests.sh` rewrites the hashes; `BUDGET_UPDATE=1` +does the same for the cost files. + +## Install + +On Windows, `INSTALL-SLOOP.bat` builds and opens the web installer (Chrome or Edge). The +`.fwsc` of each release is on the GitHub releases page. + +From the command line (needs `pip3 install mido python-rtmidi`): + +``` +python3 tools/fm1_install.py build/felucca.fwsc +python3 tools/fm1_install.py --info # identity of the connected FM-1 +``` + +Or, to install your own build from the web installer, make a local copy of the site and open it from `localhost` +(Web MIDI needs a secure context): + +``` +python3 web/make_site.py build/felucca.fwsc dev /tmp/felucca-site +cd /tmp/felucca-site && python3 -m http.server 8000 +# open http://localhost:8000/webapp/installer/ +``` + +Installing firmware is at your own risk. If an install fails and the FM-1 no longer +starts, recovery needs [FM-1-transporter](https://github.com/kurogedelic/FM-1-transporter). diff --git a/DEMARRAGE-RAPIDE-FR.md b/DEMARRAGE-RAPIDE-FR.md new file mode 100644 index 0000000..c63bd4f --- /dev/null +++ b/DEMARRAGE-RAPIDE-FR.md @@ -0,0 +1,145 @@ +

SLOOP

+ +# SLOOP 2.0 — démarrage rapide + +**SLOOP** transforme le M-VAVE FM-1 en machine à beats hip-hop : trois synthés et une batterie de 16 sons sur les touches blanches, 54 sons hip-hop / drum & bass, 34 kits, ghost notes et ratchets, note repeat, accords sur une touche, 16 effets punch-in, et un écran à la teenage engineering qui montre toujours ce que tes mains peuvent faire. Aucun motif d'usine : tout ce que tu entends, tu le joues. + +Le manuel complet (en anglais) : [SLOOP.md](SLOOP.md). + +--- + +## Installer + +1. Double-clique **`INSTALL-SLOOP.bat`** dans le dossier SLOOP : il compile le firmware et ouvre l'installateur sur `http://localhost:8766/webapp/installer/`. +2. Dans **Chrome ou Edge**, branche le FM-1 en USB (câble de données, directement, sans hub). +3. **INSTALL**, autorise le MIDI, attends *Done*. Garde la fenêtre noire ouverte jusque-là. + +L'éditeur web : `http://localhost:8766/webapp/editor/` (ou **`OPEN-EDITOR.bat`**). + +## Un beat en soixante secondes + +1. **ALGORITHM** sur la piste **4** (orange, batterie). Les touches blanches jouent 16 sons : **F3 kick**, G3 kick 2, A3 snare, B3 clap, **C4 charley**… **PRESETS** choisit le kit : essaie *808* ou *BOOMBAP*. +2. **REC** : *rec ready*. **Joue librement, à ton tempo** — pas de clic, pas de décompte. Garde **OCT−** enfoncé en frappant pour des ghost notes, **OCT+** pour des frappes fortes. +3. **Appuie sur REC sur le « 1 » qui suit ta dernière mesure** : la boucle se ferme, sa durée fixe le tempo, les frappes se calent sur la grille et la boucle joue aussitôt. +4. **REC** pendant la lecture : tu enregistres par-dessus (overdub). Maintiens **ARP** et garde la touche du charley : un roulement en 1/16, enregistré en ratchets. +5. **ALGORITHM** sur la piste **1** (bleue, *808 BOOM*), **REC**, joue une basse. Maintiens **SCL** et appuie sur la tonalité du morceau (ex. ré) ; sur la piste 2, maintiens SCL et tourne **KNOB 1** sur *7TH* : chaque touche blanche joue un accord de la gamme. +6. Maintiens **FX** + une touche blanche : un effet punch-in. Toujours FX enfoncé : **KNOB 2** = DUST (vinyle), **KNOB 3** = DUCK (pompe). +7. Une erreur ? Maintiens **EDIT** et appuie sur **OCT−** : annuler. + +## Les couleurs + +| Couleur | Piste | Bouton | +| --- | --- | --- | +| **bleu** | 1 · synthé | KNOB 1 | +| **vert** | 2 · synthé | KNOB 2 | +| **jaune** | 3 · synthé | KNOB 3 | +| **orange** | 4 · batterie | KNOB 4 | + +Blanc = ce que tu touches. Rouge = enregistrement. + +## Tapé ou maintenu : les calques + +Chaque bouton de fonction a deux vies. **Tapé** (appuyé puis relâché sans rien toucher d'autre) : ses pages s'ouvrent, comme avant. **Maintenu** : un **calque** — les 16 touches blanches et les KNOB 1–4 changent de rôle, l'écran affiche les 16 touches en tuiles et les boutons en cadrans. Relâché : on rejoue. + +| Maintenir | Touches | KNOB 1 · 2 · 3 · 4 | +| --- | --- | --- | +| **FX** — *punch* | effet punch-in tant que la touche est tenue | FILTRE · DUST · DUCK · — | +| **EDIT** — *effacer* | efface ce son / cette note du motif | DÉCALER · LONGUEUR ×2 / ½ · TRANSPOSER · — | +| **ARP** — *roll* | note repeat calé sur la grille | VITESSE · — · — · — | +| **SEQ** — *pas* | les pas 1–16 de la page | SON / NOTE · DIV · SWING · LONGUEUR | +| **SCL** — *tonalité* | la tonalité du morceau | ACCORD · GAMME · TOUCHES · TRANSPOSER | +| **GLO** — *mix* | 1–4 mute · 5–8 solo · 16 tap tempo | volume des pistes 1 · 2 · 3 · 4 | + +| Commande | Action | +| --- | --- | +| **PLAY** | lecture / arrêt des quatre pistes (marche aussi dans un calque) | +| **REC** | en lecture : enregistre tout de suite / arrête · à l'arrêt : arme (la première note démarre) · prise libre : ferme la boucle | +| **REC maintenu** | efface la piste choisie (un anneau se remplit, ~2 s ; relâche avant et rien ne se passe) | +| **SAVE** | sur TRACKS : l'écran SONG · ailleurs : les pages SAVE | +| **SAVE maintenu** | sauvegarde le projet dans son emplacement (SAVE → PROJECT, SLOT 1–4) | +| **EDIT + OCT− / OCT+** | annuler / rétablir | +| **ALGORITHM** | choisit la piste (sur toutes les pages) | +| **PRESETS** | le son de la piste, ou le kit de batterie | +| **SELECT** | tempo (toujours, même dans un calque) | +| **OCT− / OCT+** | synthés : octave (les deux : retour à 0) · batterie, maintenus : ghost / fort | +| **HOME** | l'écran TRACKS · maintenu : menu (couleur, coupe-bas, zoom, calibration, à propos) | + +## La batterie : 16 sons sur les touches blanches + +| Touche | Son | Touche | Son | Touche | Son | Touche | Son | +| --- | --- | --- | --- | --- | --- | --- | --- | +| F3 | kick | C4 | charley fermé | G4 | snare 2 | D5 | ride | +| G3 | kick 2 | D4 | charley ouvert | A4 | tom grave | E5 | shaker | +| A3 | snare | E4 | charley pédale | B4 | tom aigu | F5 | conga | +| B3 | clap | F4 | rim | C5 | crash | G5 | cloche | + +Une touche noire joue le son de la touche blanche à sa gauche (deux doigts sur un son pour les roulements rapides). Chaque frappe a un **niveau** — GHOST, SOFT, NORM (comme jouée), HARD — et un **ratchet** x1–x4 (la frappe répétée dans son pas). + +## Enregistrer + +| Quand | REC fait | Ensuite | +| --- | --- | --- | +| **En lecture** | enregistre la piste **tout de suite** | REC à nouveau arrête l'enregistrement, la boucle continue | +| **À l'arrêt, projet avec des notes** | arme (*rec ready*) | **ta première note démarre la boucle et devient le pas 1** | +| **À l'arrêt, projet vide** | arme (*play freely*) | une **prise libre** : la boucle suit ton jeu | + +**Prise libre :** joue librement ; l'écran montre les secondes et la boucle que ça donnerait (*2 bars · 92 bpm*). **REC sur le « 1 » qui suit ta dernière mesure** : SLOOP choisit 1, 2 ou 4 mesures au tempo le plus proche, cale tes notes et lance la boucle. **PLAY** abandonne la prise. + +Les notes vont au pas le plus proche **tel que tu l'as entendu** (la latence de ~12 ms est compensée). La lumière PLAY clignote à chaque temps : un métronome visuel. Clic audible : GLO → GLOBAL → CLICK. + +**Swing** façon MPC : de 50 % (droit) à 75 % — GLO → GLOBAL → SWING pour tout, SEQ maintenu + KNOB 3 par piste (ils s'additionnent). + +## Les calques en détail + +**FX — punch.** Les 16 touches blanches = les 16 effets (boucles 1/4 à 1/32, stutter, reverse, tape stop, demi-vitesse, filtres, téléphone, bit crush, alias, gate, écho, wobble), tant que la touche est tenue. KNOB 1 = filtre DJ (gauche passe-bas, droite passe-haut, centre OFF), KNOB 2 = DUST, KNOB 3 = DUCK. + +**EDIT — effacer.** EDIT + une touche : ce son (batterie) ou cette note (synthé) quitte le motif — **en lecture**, de chaque pas que la tête de lecture traverse tant que tu tiens la touche (façon MPC : garde le charley une mesure et les charleys de cette mesure disparaissent) ; **à l'arrêt**, de tout le motif. KNOB 1 décale le motif d'un pas, KNOB 2 le double (×2, copie) ou le coupe en deux, KNOB 3 transpose (synthés). **EDIT + OCT−** annule, **EDIT + OCT+** rétablit. + +**ARP — roll (note repeat).** ARP + une touche tenue : elle se répète sur la grille à la vitesse de KNOB 1 (1/8, 1/16, 1/32, 32T, 1/64), toujours en rythme. En enregistrement, un roll s'écrit en ratchets. + +**SEQ — pas (séquenceur pas à pas).** Les 16 touches blanches = les 16 pas de la page ; les quatre premières touches noires (F#3, G#3, A#3, C#4) ou OCT− / OCT+ = pages 1–4. +- Pas vide : appuie, il est posé (batterie : avec le son affiché, le dernier pad frappé ou KNOB 1 ; synthé : avec la dernière note ou le dernier accord joué). +- Pas posé : appuie et relâche, il s'efface. Tiens-le et tourne un bouton : il est modifié et gardé — KNOB 1 son / note, **KNOB 2 niveau**, **KNOB 3 ratchet**. Plusieurs pas tenus se modifient ensemble. +- Sans pas tenu : KNOB 2 = DIV, KNOB 3 = swing de la piste, KNOB 4 = longueur (1–64 pas ; chaque piste boucle sur sa longueur). + +**SCL — tonalité et accords.** Une touche = la tonalité du morceau (la fondamentale des trois synthés). KNOB 1 = **ACCORD** de la piste : OFF, TRIAD, 7TH, 9TH (1-3-7-9, le voicing lo-fi / R&B), SUS4, POWER. Avec un accord, **les touches blanches parcourent la gamme à partir de C4** : C4 = l'accord du I, D4 du II, E4 du III… un doigt, un accord, enregistré comme tel. KNOB 2 = gamme (16 gammes), KNOB 3 = touches (OFF chromatique, SNAP arrondi à la gamme, WHITE gamme sur les blanches), KNOB 4 = transposition. Changer de son ne change jamais la tonalité, le motif ni le mix de la piste. + +**GLO — mix.** Touches blanches 1–4 = mute des pistes 1–4, 5–8 = solo, la dernière (G5) = **tap tempo**. KNOB 1–4 = volume des pistes 1–4. + +## Annuler, effacer, sauvegarder + +- **Annuler / rétablir :** EDIT + OCT− / OCT+ (un niveau : le dernier passage d'enregistrement, effacement, piste effacée, modification de pas ou de motif). +- **Effacer une piste :** maintiens REC ; après 0,7 s un anneau se remplit ; tiens encore ~1,3 s. Relâche avant : rien. Annuler la ramène. +- **Sauvegarder :** maintiens SAVE, l'anneau, puis le projet est écrit dans son emplacement (SAVE → PROJECT : SLOT 1–4). +- **Sauvegarde automatique :** à l'arrêt, 2,5 s sans toucher (au plus toutes les 20 s), le projet en cours est gardé ; au rallumage, SLOOP revient comme tu l'as laissé. +- **Nouveau projet :** SAVE → TOOLS → NEW (tourner sur GO). + +## Le master : DUST, DUCK, FILT + +- **DUST** : le mix dans un vieux sampler et sur un vinyle — saturation douce, fréquence d'échantillonnage réduite, moins de bits, passe-bas, et pendant la lecture un léger souffle et des craquements (à l'arrêt, silence). +- **DUCK** : chaque kick fait « pomper » les synthés (sidechain), sur une croche, à tout tempo. +- **FILT** : filtre DJ — à gauche passe-bas, à droite passe-haut, au centre OFF. + +Réglables avec FX maintenu (KNOB 1–3) ou GLO → MASTER. + +## Mode chanson + +1. Fais une boucle, arrête, et appuie sur **SAVE** sur TRACKS : l'écran SONG. +2. **KNOB 2** choisit la section A–D ; **REC** y mémorise les quatre pistes (une section occupée demande un second REC dans les 3 s). +3. **KNOB 1** choisit une étape de la chaîne, **KNOB 3** sa durée en mesures, **KNOB 4** la longueur de la chaîne. **SAVE** sauvegarde la chaîne. +4. **OCT−** bascule boucle / chanson, **PLAY** joue la chaîne jusqu'au bout ; ta boucle de travail revient à l'arrêt. **OCT+ deux fois** (en 3 s) recharge une section pour la modifier. + +## L'éditeur web + +Chrome ou Edge, FM-1 en USB, **Connect**. Il suit l'appareil en direct. + +- **Sequencer** sur la piste batterie : une grille 16 sons × pas, avec le **kit**. Choisis un **niveau** (GHOST, SOFT, NORM, HARD) et un **roll** (x1–x4), puis clique : une frappe ; reclique (même niveau et roll) : effacée ; Maj+clic : un niveau plus fort. +- **Settings → MASTER** : DUST, DUCK, FILT, ROLL. **Tracks** : les quatre tranches (volume, pan, mute ; SOLO et REC affichés). **Samples** : tes sons USR1–USR3 et le découpage CHOP. + +## Secours + +- **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 :** M-UPGRADE de M-VAVE et le firmware FM-1 de m-vave.com. + +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é. diff --git a/INSTALL-SLOOP.bat b/INSTALL-SLOOP.bat new file mode 100644 index 0000000..32422fd --- /dev/null +++ b/INSTALL-SLOOP.bat @@ -0,0 +1,4 @@ +@echo off +title SLOOP installer +powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0build-sloop.ps1" +pause diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f288702 --- /dev/null +++ b/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/LICENSING.md b/LICENSING.md new file mode 100644 index 0000000..5ee88a0 --- /dev/null +++ b/LICENSING.md @@ -0,0 +1,65 @@ +# Felucca licensing + +Felucca is free software. Its **code** is licensed under the GNU General Public License, +version 3 only (`GPL-3.0-only`, full text in `LICENSE`). Its **assets** are not part of +that licence: the icon atlas `assets/icons.png`, the panel image `docs/panel.jpg` and the drum sounds made by +`tools/gen_waves.py` (the Hügelton Sample Pack) are Copyright (C) 2026 Hügelton Instruments, +all rights reserved. Their licence terms will be published later. + +Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments + +## What is code (GPL-3.0-only) + +Every file in this tree that carries an `SPDX-License-Identifier: GPL-3.0-only` header: + +- the firmware: `firmware/` (app, HAL, update loader) +- the build script and tools: `build.sh`, `tools/` +- the web pages (installer, editor) and their tests: `web/` (not the Fukiai font, below) +- the host tests: `tests/` + +You may use, study, change and share it under the GPL. If you distribute Felucca, or +firmware derived from it, you must also give your recipients its complete corresponding +source under the same licence. That includes devices that ship with modified Felucca +inside. + +## Additional permission (GPL-3.0 section 7) + +As an additional permission under GPL-3.0 section 7, you may combine Felucca, or a work +based on it, with the Felucca Assets (above), and convey the combination. +This is allowed even though the Felucca Assets are not licensed under the GPL, provided +that: + +- you follow the GPL for every part that is not a Felucca Asset; and +- you follow the terms published for the assets. + +The Felucca Assets are data (wavetables, icons, sample data). They are not program +code. A firmware image built from the GPL sources with replacement assets, or with no +assets, is entirely governed by the GPL. + +## Third-party material + +| What | Licence | Where | +| --- | --- | --- | +| Instrument samples (Versilian Studios VSCO-2 CE, VCSL) | CC0 1.0 | `assets/samples-cc0/`, provenance in `ATTRIBUTION.txt` there | +| Terminus font 8x16 (ter-u16n) | SIL OFL 1.1 | `assets/fonts/ter-u16n.bdf`, `assets/fonts/Terminus-LICENSE.txt` | +| Fukiai icon font (Hügelton Instruments), web editor only | MIT | `web/fukiai.ttf`, `web/FUKIAI-LICENSE.txt` | +| CrispyZebra by Leo Kuroshita (): the PHASE engine's waveforms are a C port of its oscillator | GPL-3.0 | `firmware/src/eng_phase.c` | +| klattsch by Tony Gies (): design reference for the VOICE (formant) engine; no code copied. Formant data from Klatt (1980) / Hillenbrand et al. (1995) | MIT (klattsch) | credit only | +| JieLi AC79 SDK: `uboot.boot`, `cfg_tool.bin`, `eq_cfg_hw.bin` are read from your SDK checkout at build time and placed in the package; no SDK files are in this tree | Apache-2.0 | | + +## Contributions + +Contributions are welcome under GPL-3.0-only. By submitting one, you agree that it may be +combined with the Felucca Assets under the section 7 permission above. + +## Trademarks + +"Felucca" and "Hügelton Instruments" are names of Hügelton Instruments. + +"M-VAVE" and "FM-1" are trademarks of their respective owners. Felucca is independent +firmware that runs on FM-1 hardware. It is not affiliated with, endorsed by or supported +by those owners. + +## Radio + +Felucca never enables the Bluetooth / Wi-Fi radio of the hardware. diff --git a/OPEN-EDITOR.bat b/OPEN-EDITOR.bat new file mode 100644 index 0000000..c574c43 --- /dev/null +++ b/OPEN-EDITOR.bat @@ -0,0 +1,12 @@ +@echo off +title SLOOP editor +cd /d "%~dp0" +if not exist build\sloop-site\webapp\editor\index.html ( + echo The editor is not built yet: run INSTALL-SLOOP.bat first. + pause + exit /b 1 +) +start "" http://localhost:8766/webapp/editor/ +echo SLOOP editor: http://localhost:8766/webapp/editor/ (keep this window open while you use it) +python -m http.server 8766 --bind 127.0.0.1 --directory build/sloop-site +pause diff --git a/README.md b/README.md new file mode 100644 index 0000000..a0486ef --- /dev/null +++ b/README.md @@ -0,0 +1,55 @@ +

SLOOP

+ +

A hip-hop beat machine firmware for the M-VAVE FM-1.
+Free and open source (GPL-3.0), based on Felucca.

+ +--- + +SLOOP turns the FM-1 into a four-track beat machine you play live: three synths and a drum machine with 16 sounds on the white keys. No factory patterns, nothing to load: everything you hear, you play. + +## Features + +- **Hold a button, touch a key.** Every function button is a layer: hold it and the 16 white keys and the four knobs change job, and the screen shows how. Tap it and its pages open. + - **FX**: 16 punch-in effects (loops, stutter, reverse, tape stop, filters, crush…) + - **EDIT**: erase a sound or a note as the loop plays; shift, double or halve the pattern; undo / redo + - **ARP**: note repeat (1/8 to 1/64), locked to the grid + - **SEQ**: step entry, with a level and a ratchet per step + - **SCL**: the key of the song, and one-key chords (triad, 7th, 9th, sus4, power) + - **GLO**: mute, solo, tap tempo, track levels +- **Drums:** 16 sounds on the white keys, ghost and hard hits (hold OCT− / OCT+), ratchets x1–x4, 34 kits (5 sampled, 29 synthesised: 808, 909, boom bap, trap, drill, lo-fi, jungle…). +- **Sounds:** 54 presets for hip-hop and drum & bass on 9 engines — 808s that slide, Rhodes, organs, horn and string stabs, talkbox, granular pads, scratches. +- **Recording with no click:** a free take sets the loop length and the tempo from your playing; REC records at once while playing; notes land where you heard them (latency-compensated). +- **Groove:** MPC-style swing (50–75 %), a sample-accurate clock (no drift at any tempo), polymeters. +- **Master:** DUST (old sampler + vinyl), DUCK (the kick pumps the synths), a DJ filter. +- **Memory:** undo / redo, autosave of the working project, 4 projects, 32 user presets, a song mode of 4 sections. +- **Your own samples:** three user slots; the web editor chops a recording into 16 pieces (tap along while it plays) and uploads them. +- **Web editor:** every parameter, the drum track as a 16-lane grid, the mixer, a preset library, sample upload. Live sync with the device. + +## Install + +1. Get the `.fwsc` of the latest [release](../../releases), or build it (below). +2. On Windows, double-click **`INSTALL-SLOOP.bat`**: it builds the firmware and opens the installer in the browser. +3. Connect the FM-1 by USB (a data cable, no hub), open the installer in **Chrome or Edge**, press **INSTALL** and wait for *Done*. + +Going back: M-VAVE's own updater (M-UPGRADE) and the official FM-1 firmware. If an install is cut off, the FM-1 stays in update mode: press Install again and it finishes. + +> Custom firmware is installed at your own risk. If an FM-1 no longer starts, recovery needs [FM-1-transporter](https://github.com/kurogedelic/FM-1-transporter). + +## Documentation + +- [SLOOP.md](SLOOP.md) — the manual +- [DEMARRAGE-RAPIDE-FR.md](DEMARRAGE-RAPIDE-FR.md) — guide de démarrage en français +- [BUILDING.md](BUILDING.md) — building and testing +- [web/EDITOR_PROTOCOL.md](web/EDITOR_PROTOCOL.md) — the editor's SysEx protocol + +## Building + +See [BUILDING.md](BUILDING.md). In short: the JieLi toolchain and three files of the AC79 SDK, then `./build.sh` (Linux / macOS) or `INSTALL-SLOOP.bat` (Windows with WSL). `tests/run_tests.sh` runs the host test suite (audio renders, sequencer timing, UI, storage, update loader, web pages). + +## Credits + +SLOOP is a fork of **[Felucca](https://github.com/hugelton/Felucca)** by Leo Kuroshita (@kurogedelic), Hügelton Instruments: the engines, the sequencer, the editor and the installer come from there. Font: Terminus (SIL OFL 1.1). Samples: Versilian Studios VSCO-2 CE and VCSL (CC0), Hügelton Sample Pack. PHASE engine after CrispyZebra; VOICE after klattsch. Icons: Fukiai. + +## Licence + +Code: GPL-3.0-only (see [LICENSE](LICENSE) and [LICENSING.md](LICENSING.md) for the assets). No warranty. M-VAVE and FM-1 are trademarks of their owners; SLOOP is not affiliated with M-VAVE. Drum kit names describe styles, not products. diff --git a/SLOOP.md b/SLOOP.md new file mode 100644 index 0000000..393ad4d --- /dev/null +++ b/SLOOP.md @@ -0,0 +1,320 @@ +

SLOOP

+ +# SLOOP 2.0 + +**The hip-hop beat machine firmware for the M-VAVE FM-1.** Four tracks — three synths and a drum machine with 16 sounds on the white keys — 54 sounds for hip-hop and drum & bass, 34 drum kits, ghost notes and ratchets, note repeat, one-key chords, 16 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.0, running on the FM-1. Still a beta: install at your own risk, and please report what you find (GitHub issues). + +### New in 2.0 + +- **Hold a button, touch a key.** Every function button is a *layer*: hold it and the 16 white keys and the four knobs change job, the screen shows how. Tap it and its pages open as before. +- **16 drum sounds on the white keys**, black keys double them. **OCT− / OCT+ held** = ghost / hard hits. Hits keep their level and a **ratchet** (x1–x4) in the pattern. +- **Note repeat** (ARP + key), **erase as it plays** (EDIT + key), **steps under your fingers** (SEQ + key, Elektron style), **one-key chords in the song's key** (SCL), **mute / solo / tap tempo** (GLO). +- **Undo / redo** (EDIT + OCT− / OCT+), **hold REC to clear**, **hold SAVE to save**, and an **autosave** that brings your beat back at power-on. +- **MPC swing** (50–75 %), a sample-accurate clock (no drift, any tempo), tighter glides for the 808s. +- **Master:** **DUST** (an old sampler and a record: bits, rate, crackle), **DUCK** (the kick pumps the synths), **FILT** (DJ filter: low-pass ← OFF → high-pass). +- **Web editor:** the drum track as a 16-lane grid with levels and ratchets, the kit, the master page. +- **Safer updates:** the installer checks the package's SHA-256 and only resumes SLOOP's own update loader; the loader checks the package CRC before it starts the new firmware, and refuses a flash chip it does not know. + +--- + +## Contents + +1. [Install](#install) +2. [Sixty seconds to a beat](#sixty-seconds-to-a-beat) +3. [The colour code](#the-colour-code) +4. [The panel: tap, hold, layers](#the-panel-tap-hold-layers) +5. [The drum track](#the-drum-track) +6. [Recording](#recording) +7. [Layers in detail](#layers-in-detail) +8. [Undo, clear, save, autosave](#undo-clear-save-autosave) +9. [Master: DUST, DUCK, FILT](#master-dust-duck-filt) +10. [Punch-in effects](#punch-in-effects) +11. [Screens](#screens) +12. [The sound bank](#the-sound-bank) +13. [Drum kits](#drum-kits) +14. [Your own samples](#your-own-samples-usr1usr3) +15. [Song mode](#song-mode) +16. [The web editor](#the-web-editor) +17. [Sound design pages](#sound-design-pages) +18. [Specifications](#specifications) +19. [Rescue, going back, credits](#rescue-going-back-credits) + +--- + +## Install + +1. Double-click **`INSTALL-SLOOP.bat`** in the SLOOP folder. It builds the firmware and opens the installer at `http://localhost:8766/webapp/installer/`. +2. In **Chrome or Edge**, connect the FM-1 to the computer by USB (a data cable, directly — no hub). +3. Press **INSTALL**, allow MIDI access, and wait for *Done*. Keep the black window open until then. + +The FM-1 restarts on the SLOOP logo. The editor is at `http://localhost:8766/webapp/editor/` (or **`OPEN-EDITOR.bat`**). + +## Sixty seconds to a beat + +1. **ALGORITHM** to track **4** (orange, drums). The white keys play 16 sounds: **F3 kick**, G3 kick 2, A3 snare, B3 clap, **C4 hat**, D4 open hat… **PRESETS** picks a kit: try *808* or *BOOMBAP*. +2. Press **REC**: *rec ready*. **Play a beat freely, at your own tempo** — no click, no count-in. Hold **OCT−** while you hit for ghost notes, **OCT+** for hard ones. +3. **Press REC on the "1" after your last bar.** The loop closes: its length sets the tempo, the hits snap to the grid, the loop plays at once. +4. **REC** again while it plays: you record on top (overdub). Hold **ARP** and hold the hat key: a 1/16 hat roll, recorded as ratchets. +5. Turn **ALGORITHM** to track **1** (blue, *808 BOOM*), **REC**, play a bass line. Hold **SCL** and press the key of your song (e.g. D); on track 2 hold SCL and turn **KNOB 1** to *7TH*: every white key is now a chord of the key. +6. Hold **FX** and press a white key for a punch-in effect; still holding FX, turn **KNOB 2** for DUST, **KNOB 3** for DUCK. +7. Made a mistake? Hold **EDIT** and press **OCT−**: undo. + +## The colour code + +| Colour | Track | Knob | +| --- | --- | --- | +| **blue** | 1 · synth | KNOB 1 | +| **green** | 2 · synth | KNOB 2 | +| **yellow** | 3 · synth | KNOB 3 | +| **orange** | 4 · drums | KNOB 4 | + +The four dials at the bottom of the screen show what KNOB 1–4 do now. White always means *what you are touching*. Red always means *recording*. + +## The panel: tap, hold, layers + +Every function button has two lives. **Tap** it (press and let go, touching nothing else): its pages open, as on any FM-1 firmware. **Hold** it: a **layer** — the 16 white keys and KNOB 1–4 change job while it is held, and after 0.14 s the screen shows the 16 keys as tiles and the knobs as dials. Let go: back to playing. + +| Hold | Keys | KNOB 1 · 2 · 3 · 4 | Tap | +| --- | --- | --- | --- | +| **FX** — *punch* | a punch-in effect while the key is held | FILTER · DUST · DUCK · — | FX pages | +| **EDIT** — *erase* | erase that sound / note from the pattern | SHIFT · LENGTH ×2 / ½ · TRANSPOSE · — | EDIT pages (drums: grid / kit) | +| **ARP** — *roll* | note repeat on the grid | RATE · — · — · — | ARP pages | +| **SEQ** — *steps* | steps 1–16 of the page | SOUND / NOTE · DIV · SWING · LENGTH | SEQ pages (drums: grid / kit) | +| **SCL** — *key* | the key of the song | CHORD · SCALE · KEYS · TRANSPOSE | SCL pages | +| **GLO** — *mix* | 1–4 mute · 5–8 solo · 16 tap tempo | level of tracks 1 · 2 · 3 · 4 | GLO pages | + +Other controls: + +| Control | Action | +| --- | --- | +| **PLAY** | start / stop all four tracks (works inside any layer) | +| **REC** | playing: record now / stop · stopped: arm (the first note starts) · free take: close the loop | +| hold **REC** | clear the selected track (a ring fills: keep holding ~2 s; let go before and nothing happens) | +| **SAVE** | on TRACKS: the SONG screen · elsewhere: the SAVE pages | +| hold **SAVE** | save the project into its slot (PROJECT page, SLOT 1–4) | +| **EDIT + OCT− / OCT+** | undo / redo | +| **ALGORITHM** | select the track (on every page) | +| **PRESETS** | the selected track's sound, or the drum kit | +| **SELECT** | tempo (always, even inside a layer) | +| **OCT− / OCT+** | synth tracks: octave (both: back to 0) · drum track, held: ghost / hard hits | +| **HOME** | the TRACKS screen · hold: menu (colour, low cut, zoom, calibration, about) | +| **ENV / LFO** | their pages | + +## The drum track + +Track 4 plays **16 sounds, one per white key** from the lowest F to the highest G; a black key plays the sound of the white key on its left (two fingers on one sound, for fast rolls). + +| Key | Sound | Key | Sound | Key | Sound | Key | Sound | +| --- | --- | --- | --- | --- | --- | --- | --- | +| F3 | kick | C4 | hat | G4 | snare 2 | D5 | ride | +| G3 | kick 2 | D4 | open hat | A4 | low tom | E5 | shaker | +| A3 | snare | E4 | pedal hat | B4 | hi tom | F5 | conga | +| B3 | clap | F4 | rim | C5 | crash | G5 | cowbell | + +**Levels:** every hit has one of four levels — **GHOST**, **SOFT**, **NORM** (as played), **HARD**. Hold **OCT−** while you hit for ghost notes, **OCT+** for hard hits; they are recorded so. **Ratchets:** a hit can repeat x1–x4 inside its step (ARP rolls record them; SEQ + a step + KNOB 3 sets them). The closed and pedal hats choke the open one. + +## Recording + +SLOOP records live and layers every pass on top of the last (overdub). Notes go to the nearest step **as you heard it**: the time between a key and its sound (~12 ms) is taken back, so what you play on the beat lands on the beat. Chords are kept on the synth tracks (up to 4 notes a step); held notes become ties. + +| When | REC does | Then | +| --- | --- | --- | +| **Playing** | records the selected track **at once** | REC again stops recording, the loop plays on | +| **Stopped, project with notes** | arms (*rec ready*, the REC light blinks) | **your first note starts the loop and is step 1**; PLAY starts it too | +| **Stopped, empty project** | arms (*rec ready* · *play freely*) | a **free take**: see below | + +**Free take — the loop follows you.** On an empty project there is no tempo yet, so you set it by playing: + +1. REC, then play freely. The screen shows *free take*, the seconds, and the loop it would make right now (*2 bars · 92 bpm*). +2. **Press REC on the "1" after your last bar.** The time from your first note to that press is the loop: SLOOP picks 1, 2 or 4 bars at the tempo nearest the one set (within 3 % the set tempo is kept), writes your notes into it with their lengths and levels, and plays it at once. All four tracks take that length. +3. **PLAY** during a free take drops it. A take closes by itself after 24 s. + +- While recording the REC light is solid and the track shows a red *rec*. Turn ALGORITHM and the take moves to the next track without stopping. +- The **PLAY light flashes on every beat**: a visual metronome. An audible click: GLO → GLOBAL → **CLICK** (`OFF`, `REC`, `ON`); it is never recorded. +- **Swing** is MPC swing: 50 % straight to 75 % (GLO → GLOBAL → SWING for all tracks, SEQ + KNOB 3 per track). The swing of a track adds to the global one. + +## Layers in detail + +### FX — punch + +The 16 white keys are the [punch-in effects](#punch-in-effects); they run while the key is held. The knobs drive the [master](#master-dust-duck-filt): **KNOB 1 FILTER** (turn left: low-pass, right: high-pass, centre: off), **KNOB 2 DUST**, **KNOB 3 DUCK**. Keys pressed while FX is held never play or record notes. + +### EDIT — erase + +Hold EDIT and press a key: that sound (drums) or that note (synths; with CHORD on, the notes of its chord) leaves the selected track's pattern — **while playing**, from every step the playhead passes while you hold the key (MPC style: hold the hat key for one bar and the hats of that bar are gone); **stopped**, from the whole pattern at once. *ERASED* flashes. The knobs reshape the whole pattern: + +- **KNOB 1 SHIFT** — every step one later / earlier (turns the groove around). +- **KNOB 2 LENGTH** — right: ×2 (the pattern copied after itself, up to 64 steps); left: ½. +- **KNOB 3 TRANSPOSE** — every note a semitone up / down (synth tracks). +- **OCT− undo · OCT+ redo** (the knob turns of one hold count as one change). + +### ARP — roll (note repeat) + +Hold ARP and hold a key: it repeats on the grid at the **RATE** of KNOB 1 — 1/8, 1/16, 1/32, 32T, 1/64 — locked to the tempo and the swing, so it always lands in time. On the drum track OCT− / OCT+ make it ghost / hard. While recording, a roll is written as ratchets (a 1/32 roll on a 1/16 track: x2 on each step). Rolls end with their key. + +### SEQ — steps (step sequencer) + +The 16 white keys are the 16 steps of the page; the lit ones play. The first four black keys (F#3, G#3, A#3, C#4) or **OCT− / OCT+** pick page 1–4 (steps 1–16, 17–32, 33–48, 49–64, up to the track's LENGTH). + +- **An empty step:** press its key — it is set at once. Drums: with the sound shown (KNOB 1 picks it, or the last pad you hit); synths: with the note or chord you played last. +- **A set step:** press and let go — it is cleared. Hold it and turn a knob instead — it is edited, and kept: **KNOB 1** sound (drums) / note (synths), **KNOB 2 LEVEL** (ghost, soft, norm, hard), **KNOB 3 RATCHET** (x1–x4). Hold several step keys to edit them together. +- **No step held:** KNOB 1 the sound / note to set · KNOB 2 **DIV** (1/4 … 1/32, triplets) · KNOB 3 **SWING** of the track · KNOB 4 **LENGTH** (1–64 steps; each track loops on its own length, polymeters stay in phase). + +### SCL — key and chords + +- **Any key** sets the **key of the song**: the root of all three synth tracks (*KEY D*). +- **KNOB 1 CHORD** (selected synth track): OFF, TRIAD, 7TH, 9TH (1-3-7-9, the lo-fi / R&B voicing), SUS4, POWER. With a chord on, **the white keys walk the scale from C4** — C4 is the chord of the key's I, D4 the II, E4 the III… — and one finger plays the whole chord, recorded as a chord. With SCALE on CHR, the chords come from the minor scale. +- **KNOB 2 SCALE** for all synth tracks (16 scales: major, minor, dorian, mixolydian, pentatonics, harmonic, blues…). +- **KNOB 3 KEYS**: OFF (all keys chromatic), SNAP (every key rounded to the scale), WHITE (the white keys walk the scale, the black keys are silent). +- **KNOB 4 TRANSPOSE** the selected track, ±24 semitones. + +Changing a sound (PRESETS, a user preset) never changes the key, the chord mode, the pattern or the mix of its track. + +### GLO — mix + +- White keys **1–4 mute** tracks 1–4 (a muted track fades out in a few ms and plays no new notes; its pattern runs on in time), keys **5–8 solo** them (several solos add up). The tiles show what is heard. +- The last white key (**G5**): **tap tempo** (two taps or more). +- **KNOB 1–4: the levels** of tracks 1–4. + +## Undo, clear, save, autosave + +- **Undo / redo:** hold EDIT, press OCT− / OCT+. One level: the last recording pass, erase, clear, step or pattern edit; redo takes it back again. +- **Clear a track:** hold REC. After 0.7 s the press is cancelled and a ring fills; keep holding ~1.3 s more and the selected track is cleared (*TRACK 2 CLEARED*). Let go before: nothing. Undo brings it back. +- **Save:** hold SAVE: the ring, then the project is saved into its slot (SAVE → PROJECT: SLOT 1–4, LOAD, SAVE). +- **Autosave:** when the transport is stopped and you have not touched anything for 2.5 s (at most every 20 s), the working project is kept in flash; at power-on SLOOP comes back exactly as you left it. +- **New project:** SAVE → TOOLS → NEW (turn to GO): the four tracks back to their power-on sounds, empty patterns (undoable). + +## Master: DUST, DUCK, FILT + +On the whole mix, after the tracks' sends (FX + KNOB 1–3, or GLO → MASTER): + +- **DUST** 0–100 %: the mix through an old sampler and a record — drive into a soft clip, a lower sample rate (down to ~11 kHz), fewer bits (down to 8), a low-pass closing to ~3 kHz, and while the transport plays a little hiss and crackle (a stopped SLOOP is silent). +- **DUCK** 0–100 %: every kick pumps the synth tracks down and back over an 1/8 note — the sidechain sound, in time at any tempo. +- **FILT**: a DJ filter. Left of centre a low-pass closing, right a high-pass opening, centre OFF. It glides (no zipper noise). +- **ROLL** (GLO → MASTER): the note-repeat rate of ARP + key. + +## Punch-in effects + +Hold **FX**, then hold a white key — the 16 white keys from the lowest F to the highest G. The effect runs on the whole mix while the key is held and lets go cleanly when you release it. Loops and the gate are locked to the tempo and start on the grid. + +| Key | Effect | Key | Effect | +| --- | --- | --- | --- | +| 1 | loop 1/4 | 9 | low-pass sweep | +| 2 | loop 1/8 | 10 | high-pass sweep | +| 3 | loop 1/16 | 11 | phone | +| 4 | loop 1/32 | 12 | bit crush | +| 5 | stutter (1/16 triplets) | 13 | alias (sample-rate drop) | +| 6 | reverse | 14 | gate 1/16 | +| 7 | tape stop | 15 | echo (dotted 1/8) | +| 8 | half speed | 16 | tape wobble | + +## Screens + +- **TRACKS** (HOME) — the performance view: tempo, swing, transport, bar.beat; each track with its sound, its steps, the playhead, mute / solo / rec badges and its level. Dials: *swing · level · steps · pan* (KNOB 2 on a muted track unmutes it). +- **Layers** — while a layer button is held: 16 tiles (the white keys) and the knobs' dials, in the layer's colour. +- **DRUMS** (EDIT or SEQ tapped on TRACKS with the drum track) — **grid**: the 16 sounds × 16 steps, levels as shades, ratchets as notches; dials *sound · step · hit · level*. **kit**: 16 pads that flash on every hit; dials *kit · level · reverb · pan*. EDIT / SEQ tapped switches grid ↔ kit. +- **REC READY / FREE TAKE** — while REC is armed, and during a free take: the seconds and the loop it makes. +- **Holds** — the ring of REC (clear) and SAVE (save) while held. +- **SONG** — the section chain. +- **Sound pages** (ENV, LFO, FX, SCL, EDIT, ARP, SEQ, GLO, SAVE) — the full synth, colour-coded. + +## The sound bank + +54 sounds made for hip-hop and drum & bass — boom bap, trap and drill, lo-fi, R&B and soul, jungle. **PRESETS** browses them all on a synth track (the engine follows). SLOOP starts (on a new project) at **90 BPM** with *808 BOOM* on track 1, *RHODES* on track 2, *LOFI FLUTE* on track 3 and the 808 kit on track 4. + +| Role | Sounds (engine) | +| --- | --- | +| **808 & sub** | 808 BOOM, 808 DIRTY, SUB BASS (ANALOG) — they slide between held notes (~70 ms) with a punch of pitch on the attack, two octaves under the keys | +| **Basses** | REESE, WOBBLE, FUNK BASS (ANALOG) · FM BASS (DIGITAL) · CZ BASS (PHASE) · FAT BASS (TRIO) · WOW BASS (VOICE) · GB BASS (LOFI) · UP BASS, DEEP BASS (SAMPLE: a real upright) | +| **Keys** | RHODES, DX RHODES, WURLI, CLAV (DIGITAL) · SOFT KEYS (PHASE) · DUSTY PNO, LOFI KEYS (SAMPLE: an old upright piano) | +| **Organ** | SOUL ORGAN, GOSPEL, JAZZ ORGAN, DIRTY B3 (WHEEL) | +| **Bells & plucks** | TRAP BELL, MUSIC BOX, MARIMBA (DIGITAL) · TRAP PLUCK (ANALOG) · RESO PLUCK (PHASE) · VIBES (SAMPLE) | +| **Stabs** | HORN STAB, STRING STB (SAMPLE) · MIN STAB, MIN7 STAB (TRIO) · SYN BRASS (ANALOG) · CZ BRASS (PHASE) | +| **Leads** | G-FUNK LD (ANALOG) · TALKBOX (VOICE) · SYNC LEAD, HOOVER (TRIO) · LOFI FLUTE (SAMPLE) · GAME LEAD, 8BIT ARP (LOFI) | +| **Pads & voices** | WARM PAD, DARK STR, ATMOS PAD (ANALOG) · CZ STRING (PHASE) · CHOIR AAH, SOUL OOH (VOICE) · LOFI CLOUD, VIBE HAZE, FLUTE DUST (GRAIN) | +| **DJ & drums** | SCRATCH — scratch, backspin, rewind across the keys · GM KIT (SAMPLE) | + +The sampled sounds (SAMPLE engine, **SET**: DUSTY (piano), BASS, VIBES, HORNS, STRGS, FLUTE, SCRCH, PERC) are free recordings (CC0: Versilian Studios VSCO-2 CE and VCSL, Sonic Pi), retuned and coloured like a record through an old sampler. + +## Drum kits + +34 kits — **PRESETS** on the drum track, KNOB 1 on the kit page, or the editor. 1–5 are the sampled GM kit and its treatments; 6–34 are synthesised (analogue-style kick, snare, clap, six-oscillator metallic hats and cymbals, toms, congas, rim, cowbell, clave; FM and 8-bit voices for the game kits), so they cost almost no memory. + +| # | Kit | Style | # | Kit | Style | +| --- | --- | --- | --- | --- | --- | +| 1 | ORIGINAL | acoustic | 18 | ELECTRO | electro | +| 2 | DEEP | soft | 19 | JUNGLE | drum & bass | +| 3 | TIGHT | punchy | 20 | DUBSTEP | bass music | +| 4 | BRIGHT | bright | 21 | DEMBOW | reggaeton | +| 5 | DUST | dusty | 22 | AFRO | afrobeat | +| 6 | 808 | hip hop | 23 | LATIN | latin | +| 7 | 909 | house | 24 | DISCO | disco | +| 8 | 606 | acid | 25 | SYNTHWV | synthwave | +| 9 | VINTAGE | rhythm box | 26 | CHIP | chiptune | +| 10 | 80S | 80s pop | 27 | 8BIT | handheld | +| 11 | TRAP | trap | 28 | ARCADE | video game | +| 12 | DRILL | UK drill | 29 | GLITCH | glitch | +| 13 | BOOMBAP | hip hop | 30 | INDUSTR | industrial | +| 14 | LO-FI | lo-fi | 31 | TRIBAL | tribal | +| 15 | HOUSE | house | 32 | HYPER | hyperpop | +| 16 | TECHNO | techno | 33 | AMBIENT | ambient | +| 17 | MINIMAL | minimal | 34 | JAZZ | jazz (brushes) | + +The kit is saved with projects and song sections. MIDI notes in on the drum channel (10) play the nearest of the 16 sounds. + +## Your own samples (USR1–USR3) + +Three slots of about 7.4 s each hold your own sounds, played by a synth track: engine **SAMPLE**, **SET** = USR1 / USR2 / USR3. Load them from the web editor, tab **Samples**: + +- **Files:** up to 16 WAV per slot (any rate, mono or stereo). The note each one plays at its own speed is in its name (`KEYS_C4.wav`, C4 = 60). +- **CHOP:** open or drop a recording (WAV, MP3, AIFF…) and cut it into up to 16 chops, one per key — live with **TAP** (or the space bar) while it plays (*snap to the hit* puts each tap on its attack), **Find hits**, **Grid** or **Equal parts**; then **Send to USR1/2/3**, or **Download WAVs**. + +## Song mode + +1. Build a loop, stop, and press **SAVE** on TRACKS: the SONG screen. +2. **KNOB 2** picks section A–D; **REC** stores the four tracks into it (a used section asks for REC again within 3 s). +3. **KNOB 1** picks a step of the chain, **KNOB 3** its length in bars, **KNOB 4** the chain length. **SAVE** stores the chain. +4. **OCT−** switches loop / song, **PLAY** plays the chain to the end; your working loop is back when it stops. **OCT+ twice** (within 3 s) loads a section to edit it. + +## The web editor + +Open it from the installer page, or with **`OPEN-EDITOR.bat`** (`http://localhost:8766/webapp/editor/`), in Chrome or Edge with the FM-1 on USB, and press **Connect**. It follows the device live (turn a knob on the FM-1, the editor moves). + +- **Sound** — every parameter of the selected track, the engines and presets, files. +- **Sequencer** — the pattern settings and the steps. On the **drum track**: a grid of the 16 sounds × the steps, with the **kit**. Choose a **level** (GHOST, SOFT, NORM, HARD) and a **roll** (x1–x4), then click: a hit; click it again (same level and roll): cleared; Shift+click: one level louder. +- **Tracks** — the four channel strips (level, pan, mute; SOLO and REC shown as on the device). +- **Library**, **Samples** (with CHOP), **Projects**, **Settings** (GLOBAL, **MASTER**: DUST, DUCK, FILT, ROLL; DRUMS). + +The protocol is documented in [web/EDITOR_PROTOCOL.md](web/EDITOR_PROTOCOL.md) (v5). + +## Sound design pages + +The full Felucca engine is underneath: nine synthesis engines (analog, 4-op FM, phase distortion, lo-fi chip, sampler, formant voice, three-oscillator, tonewheel organ, granular), envelopes (with a pitch punch for the 808s), LFO, arpeggiator, scales and chords, glide and voice modes, per-track drive and slicer, chorus / delay / reverb sends, 32 user presets, 4 projects. + +## Specifications + +| | | +| --- | --- | +| Tracks | 3 synth parts (8 voices shared) + drums (16 sounds, 6 voices) | +| Sounds | 54 hip-hop / drum & bass presets on 9 engines, 8 sampled sets (CC0) | +| Sequencer | 64 steps per track, own length and division each; chords with a level and ratchet per note; drums with a level and ratchet per sound; ties, slide; MPC swing 50–75 %; one sample-accurate clock for steps, arp, rolls, slicer and song (no drift) | +| Performance | layers (hold a button: keys and knobs change job): punch-in FX, erase, note repeat, step entry, key / chords, mute / solo / tap tempo | +| Drum kits | 34 (5 sampled, 29 synthesised) | +| Effects | 16 punch-in effects; master DUST, DUCK, DJ filter; per track drive, slicer, chorus / delay / reverb sends; master limiter | +| Recording | live, quantised as heard (latency-compensated), overdub; records at once while playing; free take sets loop length and tempo | +| Memory | undo / redo, 4 projects, 32 user presets, autosave of the working project, song of 4 sections × 16 steps × 1–64 bars | +| Audio | 44.1 kHz, fixed-point DSP | +| MIDI | USB class-compliant in / out; channels 1–3 the synths, 10 the drums | +| Update | over USB from the browser (package SHA-256 and CRC checked) | + +## Rescue, going back, credits + +- **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:** M-VAVE's updater, M-UPGRADE, and the FM-1 firmware from m-vave.com. +- **Credits:** SLOOP is based on Felucca by Leo Kuroshita (@kurogedelic), Hügelton Instruments — engines, sequencer, editor and installer. Font: Terminus (SIL OFL 1.1). Samples: Versilian Studios VSCO-2 CE and VCSL (CC0), Hügelton Sample Pack. PHASE: CrispyZebra (GPL). 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. diff --git a/assets/fonts/Terminus-LICENSE.txt b/assets/fonts/Terminus-LICENSE.txt new file mode 100644 index 0000000..d65472b --- /dev/null +++ b/assets/fonts/Terminus-LICENSE.txt @@ -0,0 +1,94 @@ +Terminus Font (ter-u16n.bdf) +Copyright (C) 2020 Dimitar Toshkov Zhekov +Source: https://github.com/retro-vault/font-vault (source/fonts/terminus) + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +http://scripts.sil.org/OFL + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION AND CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/assets/fonts/ter-u16n.bdf b/assets/fonts/ter-u16n.bdf new file mode 100644 index 0000000..18839c6 --- /dev/null +++ b/assets/fonts/ter-u16n.bdf @@ -0,0 +1,31216 @@ +STARTFONT 2.1 +FONT -xos4-Terminus-Medium-R-Normal--16-160-72-72-C-80-ISO10646-1 +SIZE 16 72 72 +FONTBOUNDINGBOX 8 16 0 -4 +STARTPROPERTIES 20 +FAMILY_NAME "Terminus" +FOUNDRY "xos4" +SETWIDTH_NAME "Normal" +ADD_STYLE_NAME "" +COPYRIGHT "Copyright (C) 2020 Dimitar Toshkov Zhekov" +NOTICE "Licensed under the SIL Open Font License, Version 1.1" +WEIGHT_NAME "Medium" +SLANT "R" +PIXEL_SIZE 16 +POINT_SIZE 160 +RESOLUTION_X 72 +RESOLUTION_Y 72 +SPACING "C" +AVERAGE_WIDTH 80 +CHARSET_REGISTRY "ISO10646" +CHARSET_ENCODING "1" +MIN_SPACE 8 +FONT_ASCENT 12 +FONT_DESCENT 4 +DEFAULT_CHAR 65533 +ENDPROPERTIES +CHARS 1356 +STARTCHAR char0 +ENCODING 0 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +66 +42 +00 +42 +42 +42 +00 +42 +42 +66 +00 +00 +00 +00 +ENDCHAR +STARTCHAR space +ENCODING 32 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR exclam +ENCODING 33 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +10 +10 +10 +10 +10 +10 +10 +00 +10 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR quotedbl +ENCODING 34 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +24 +24 +24 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR numbersign +ENCODING 35 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +24 +24 +24 +7E +24 +24 +7E +24 +24 +24 +00 +00 +00 +00 +ENDCHAR +STARTCHAR dollar +ENCODING 36 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +10 +10 +7C +92 +90 +90 +7C +12 +12 +92 +7C +10 +10 +00 +00 +ENDCHAR +STARTCHAR percent +ENCODING 37 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +64 +94 +68 +08 +10 +10 +20 +2C +52 +4C +00 +00 +00 +00 +ENDCHAR +STARTCHAR ampersand +ENCODING 38 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +18 +24 +24 +18 +30 +4A +44 +44 +44 +3A +00 +00 +00 +00 +ENDCHAR +STARTCHAR quotesingle +ENCODING 39 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +10 +10 +10 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR parenleft +ENCODING 40 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +08 +10 +20 +20 +20 +20 +20 +20 +10 +08 +00 +00 +00 +00 +ENDCHAR +STARTCHAR parenright +ENCODING 41 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +20 +10 +08 +08 +08 +08 +08 +08 +10 +20 +00 +00 +00 +00 +ENDCHAR +STARTCHAR asterisk +ENCODING 42 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +24 +18 +7E +18 +24 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR plus +ENCODING 43 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +10 +10 +7C +10 +10 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR comma +ENCODING 44 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +10 +10 +20 +00 +00 +00 +ENDCHAR +STARTCHAR hyphen +ENCODING 45 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +7E +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR period +ENCODING 46 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +10 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR slash +ENCODING 47 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +04 +04 +08 +08 +10 +10 +20 +20 +40 +40 +00 +00 +00 +00 +ENDCHAR +STARTCHAR zero +ENCODING 48 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +42 +42 +46 +4A +52 +62 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR one +ENCODING 49 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +08 +18 +28 +08 +08 +08 +08 +08 +08 +3E +00 +00 +00 +00 +ENDCHAR +STARTCHAR two +ENCODING 50 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +42 +42 +02 +04 +08 +10 +20 +40 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR three +ENCODING 51 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +42 +42 +02 +1C +02 +02 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR four +ENCODING 52 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +02 +06 +0A +12 +22 +42 +7E +02 +02 +02 +00 +00 +00 +00 +ENDCHAR +STARTCHAR five +ENCODING 53 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7E +40 +40 +40 +7C +02 +02 +02 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR six +ENCODING 54 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +1C +20 +40 +40 +7C +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR seven +ENCODING 55 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7E +02 +02 +04 +04 +08 +08 +10 +10 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR eight +ENCODING 56 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +42 +42 +42 +3C +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR nine +ENCODING 57 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +42 +42 +42 +42 +3E +02 +02 +04 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR colon +ENCODING 58 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +10 +10 +00 +00 +00 +10 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR semicolon +ENCODING 59 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +10 +10 +00 +00 +00 +10 +10 +20 +00 +00 +00 +ENDCHAR +STARTCHAR less +ENCODING 60 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +04 +08 +10 +20 +40 +20 +10 +08 +04 +00 +00 +00 +00 +ENDCHAR +STARTCHAR equal +ENCODING 61 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +7E +00 +00 +7E +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR greater +ENCODING 62 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +40 +20 +10 +08 +04 +08 +10 +20 +40 +00 +00 +00 +00 +ENDCHAR +STARTCHAR question +ENCODING 63 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +42 +42 +42 +04 +08 +08 +00 +08 +08 +00 +00 +00 +00 +ENDCHAR +STARTCHAR at +ENCODING 64 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7C +82 +9E +A2 +A2 +A2 +A6 +9A +80 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR A +ENCODING 65 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +42 +42 +42 +42 +7E +42 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR B +ENCODING 66 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7C +42 +42 +42 +7C +42 +42 +42 +42 +7C +00 +00 +00 +00 +ENDCHAR +STARTCHAR C +ENCODING 67 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +42 +42 +40 +40 +40 +40 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR D +ENCODING 68 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +78 +44 +42 +42 +42 +42 +42 +42 +44 +78 +00 +00 +00 +00 +ENDCHAR +STARTCHAR E +ENCODING 69 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7E +40 +40 +40 +78 +40 +40 +40 +40 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR F +ENCODING 70 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7E +40 +40 +40 +78 +40 +40 +40 +40 +40 +00 +00 +00 +00 +ENDCHAR +STARTCHAR G +ENCODING 71 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +42 +42 +40 +40 +4E +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR H +ENCODING 72 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +42 +42 +42 +42 +7E +42 +42 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR I +ENCODING 73 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +38 +10 +10 +10 +10 +10 +10 +10 +10 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR J +ENCODING 74 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +0E +04 +04 +04 +04 +04 +04 +44 +44 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR K +ENCODING 75 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +42 +44 +48 +50 +60 +60 +50 +48 +44 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR L +ENCODING 76 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +40 +40 +40 +40 +40 +40 +40 +40 +40 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR M +ENCODING 77 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +82 +C6 +AA +92 +92 +82 +82 +82 +82 +82 +00 +00 +00 +00 +ENDCHAR +STARTCHAR N +ENCODING 78 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +42 +42 +42 +62 +52 +4A +46 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR O +ENCODING 79 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +42 +42 +42 +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR P +ENCODING 80 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7C +42 +42 +42 +42 +7C +40 +40 +40 +40 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Q +ENCODING 81 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +42 +42 +42 +42 +42 +42 +42 +4A +3C +02 +00 +00 +00 +ENDCHAR +STARTCHAR R +ENCODING 82 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7C +42 +42 +42 +42 +7C +50 +48 +44 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR S +ENCODING 83 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +42 +40 +40 +3C +02 +02 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR T +ENCODING 84 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +FE +10 +10 +10 +10 +10 +10 +10 +10 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR U +ENCODING 85 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +42 +42 +42 +42 +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR V +ENCODING 86 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +42 +42 +42 +42 +42 +24 +24 +24 +18 +18 +00 +00 +00 +00 +ENDCHAR +STARTCHAR W +ENCODING 87 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +82 +82 +82 +82 +82 +92 +92 +AA +C6 +82 +00 +00 +00 +00 +ENDCHAR +STARTCHAR X +ENCODING 88 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +42 +42 +24 +24 +18 +18 +24 +24 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Y +ENCODING 89 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +82 +82 +44 +44 +28 +10 +10 +10 +10 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Z +ENCODING 90 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7E +02 +02 +04 +08 +10 +20 +40 +40 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR bracketleft +ENCODING 91 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +38 +20 +20 +20 +20 +20 +20 +20 +20 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR backslash +ENCODING 92 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +40 +40 +20 +20 +10 +10 +08 +08 +04 +04 +00 +00 +00 +00 +ENDCHAR +STARTCHAR bracketright +ENCODING 93 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +38 +08 +08 +08 +08 +08 +08 +08 +08 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR asciicircum +ENCODING 94 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +10 +28 +44 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR underscore +ENCODING 95 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +7E +00 +00 +ENDCHAR +STARTCHAR grave +ENCODING 96 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +08 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR a +ENCODING 97 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +3C +02 +3E +42 +42 +42 +3E +00 +00 +00 +00 +ENDCHAR +STARTCHAR b +ENCODING 98 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +40 +40 +40 +7C +42 +42 +42 +42 +42 +7C +00 +00 +00 +00 +ENDCHAR +STARTCHAR c +ENCODING 99 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +3C +42 +40 +40 +40 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR d +ENCODING 100 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +02 +02 +02 +3E +42 +42 +42 +42 +42 +3E +00 +00 +00 +00 +ENDCHAR +STARTCHAR e +ENCODING 101 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +3C +42 +42 +7E +40 +40 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR f +ENCODING 102 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +0E +10 +10 +7C +10 +10 +10 +10 +10 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR g +ENCODING 103 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +3E +42 +42 +42 +42 +42 +3E +02 +02 +3C +00 +ENDCHAR +STARTCHAR h +ENCODING 104 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +40 +40 +40 +7C +42 +42 +42 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR i +ENCODING 105 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +10 +10 +00 +30 +10 +10 +10 +10 +10 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR j +ENCODING 106 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +04 +04 +00 +0C +04 +04 +04 +04 +04 +04 +44 +44 +38 +00 +ENDCHAR +STARTCHAR k +ENCODING 107 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +40 +40 +40 +42 +44 +48 +70 +48 +44 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR l +ENCODING 108 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +30 +10 +10 +10 +10 +10 +10 +10 +10 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR m +ENCODING 109 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +FC +92 +92 +92 +92 +92 +92 +00 +00 +00 +00 +ENDCHAR +STARTCHAR n +ENCODING 110 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +7C +42 +42 +42 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR o +ENCODING 111 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +3C +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR p +ENCODING 112 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +7C +42 +42 +42 +42 +42 +7C +40 +40 +40 +00 +ENDCHAR +STARTCHAR q +ENCODING 113 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +3E +42 +42 +42 +42 +42 +3E +02 +02 +02 +00 +ENDCHAR +STARTCHAR r +ENCODING 114 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +5E +60 +40 +40 +40 +40 +40 +00 +00 +00 +00 +ENDCHAR +STARTCHAR s +ENCODING 115 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +3E +40 +40 +3C +02 +02 +7C +00 +00 +00 +00 +ENDCHAR +STARTCHAR t +ENCODING 116 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +10 +10 +10 +7C +10 +10 +10 +10 +10 +0E +00 +00 +00 +00 +ENDCHAR +STARTCHAR u +ENCODING 117 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +42 +42 +42 +42 +42 +42 +3E +00 +00 +00 +00 +ENDCHAR +STARTCHAR v +ENCODING 118 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +42 +42 +42 +24 +24 +18 +18 +00 +00 +00 +00 +ENDCHAR +STARTCHAR w +ENCODING 119 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +82 +82 +92 +92 +92 +92 +7C +00 +00 +00 +00 +ENDCHAR +STARTCHAR x +ENCODING 120 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +42 +42 +24 +18 +24 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR y +ENCODING 121 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +42 +42 +42 +42 +42 +42 +3E +02 +02 +3C +00 +ENDCHAR +STARTCHAR z +ENCODING 122 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +7E +04 +08 +10 +20 +40 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR braceleft +ENCODING 123 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +0C +10 +10 +10 +20 +10 +10 +10 +10 +0C +00 +00 +00 +00 +ENDCHAR +STARTCHAR bar +ENCODING 124 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +10 +10 +10 +10 +10 +10 +10 +10 +10 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR braceright +ENCODING 125 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +30 +08 +08 +08 +04 +08 +08 +08 +08 +30 +00 +00 +00 +00 +ENDCHAR +STARTCHAR asciitilde +ENCODING 126 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +62 +92 +8C +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR nbspace +ENCODING 160 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR exclamdown +ENCODING 161 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +10 +10 +00 +10 +10 +10 +10 +10 +10 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR cent +ENCODING 162 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +10 +10 +7C +92 +90 +90 +90 +92 +7C +10 +10 +00 +00 +ENDCHAR +STARTCHAR sterling +ENCODING 163 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +18 +24 +20 +20 +78 +20 +20 +20 +22 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR currency +ENCODING 164 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +44 +38 +44 +44 +44 +38 +44 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR yen +ENCODING 165 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +82 +82 +44 +28 +10 +7C +10 +7C +10 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR brokenbar +ENCODING 166 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +10 +10 +10 +10 +00 +00 +10 +10 +10 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR section +ENCODING 167 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +38 +44 +40 +30 +48 +44 +44 +24 +18 +04 +44 +38 +00 +00 +00 +ENDCHAR +STARTCHAR dieresis +ENCODING 168 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +24 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR copyright +ENCODING 169 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +7E +81 +99 +A5 +A1 +A5 +99 +81 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR ordfeminine +ENCODING 170 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +38 +04 +3C +44 +3C +00 +7C +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR guillemotleft +ENCODING 171 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +12 +24 +48 +90 +48 +24 +12 +00 +00 +00 +00 +ENDCHAR +STARTCHAR logicalnot +ENCODING 172 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +7E +02 +02 +02 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR softhyphen +ENCODING 173 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +3C +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR registered +ENCODING 174 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +7E +81 +B9 +A5 +B9 +A9 +A5 +81 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR macron +ENCODING 175 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +3C +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR degree +ENCODING 176 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +18 +24 +24 +18 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR plusminus +ENCODING 177 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +10 +10 +7C +10 +10 +00 +7C +00 +00 +00 +00 +ENDCHAR +STARTCHAR twosuperior +ENCODING 178 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +18 +24 +04 +08 +10 +3C +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR threesuperior +ENCODING 179 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +38 +04 +18 +04 +04 +38 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR acute +ENCODING 180 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +08 +10 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR mu +ENCODING 181 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +42 +42 +42 +42 +42 +46 +7A +40 +40 +40 +00 +ENDCHAR +STARTCHAR paragraph +ENCODING 182 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7E +92 +92 +92 +92 +72 +12 +12 +12 +12 +00 +00 +00 +00 +ENDCHAR +STARTCHAR periodcentered +ENCODING 183 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +10 +10 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR cedilla +ENCODING 184 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +10 +10 +20 +00 +ENDCHAR +STARTCHAR onesuperior +ENCODING 185 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +10 +30 +10 +10 +10 +38 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR ordmasculine +ENCODING 186 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +38 +44 +44 +44 +38 +00 +7C +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR guillemotright +ENCODING 187 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +90 +48 +24 +12 +24 +48 +90 +00 +00 +00 +00 +ENDCHAR +STARTCHAR onequarter +ENCODING 188 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +20 +60 +20 +22 +24 +08 +10 +22 +46 +8A +1E +02 +02 +00 +00 +ENDCHAR +STARTCHAR onehalf +ENCODING 189 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +20 +60 +20 +22 +24 +08 +10 +20 +4C +92 +04 +08 +1E +00 +00 +ENDCHAR +STARTCHAR threequarters +ENCODING 190 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +E0 +10 +60 +12 +E4 +08 +10 +22 +46 +8A +1E +02 +02 +00 +00 +ENDCHAR +STARTCHAR questiondown +ENCODING 191 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +10 +10 +00 +10 +10 +20 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR Agrave +ENCODING 192 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +08 +00 +3C +42 +42 +42 +7E +42 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Aacute +ENCODING 193 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +08 +10 +00 +3C +42 +42 +42 +7E +42 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Acircumflex +ENCODING 194 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +18 +24 +00 +3C +42 +42 +42 +7E +42 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Atilde +ENCODING 195 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +32 +4C +00 +3C +42 +42 +42 +7E +42 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Adieresis +ENCODING 196 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +24 +00 +3C +42 +42 +42 +7E +42 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Aring +ENCODING 197 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +18 +24 +18 +3C +42 +42 +42 +7E +42 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR AE +ENCODING 198 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7E +90 +90 +90 +FC +90 +90 +90 +90 +9E +00 +00 +00 +00 +ENDCHAR +STARTCHAR Ccedilla +ENCODING 199 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +42 +42 +40 +40 +40 +40 +42 +42 +3C +10 +10 +20 +00 +ENDCHAR +STARTCHAR Egrave +ENCODING 200 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +08 +00 +7E +40 +40 +40 +78 +40 +40 +40 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR Eacute +ENCODING 201 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +08 +10 +00 +7E +40 +40 +40 +78 +40 +40 +40 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR Ecircumflex +ENCODING 202 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +18 +24 +00 +7E +40 +40 +40 +78 +40 +40 +40 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR Edieresis +ENCODING 203 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +24 +00 +7E +40 +40 +40 +78 +40 +40 +40 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR Igrave +ENCODING 204 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +20 +10 +00 +38 +10 +10 +10 +10 +10 +10 +10 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Iacute +ENCODING 205 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +08 +10 +00 +38 +10 +10 +10 +10 +10 +10 +10 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Icircumflex +ENCODING 206 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +18 +24 +00 +38 +10 +10 +10 +10 +10 +10 +10 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Idieresis +ENCODING 207 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +44 +44 +00 +38 +10 +10 +10 +10 +10 +10 +10 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Eth +ENCODING 208 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +78 +44 +42 +42 +F2 +42 +42 +42 +44 +78 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Ntilde +ENCODING 209 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +32 +4C +00 +42 +42 +62 +52 +4A +46 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Ograve +ENCODING 210 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +08 +00 +3C +42 +42 +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR Oacute +ENCODING 211 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +08 +10 +00 +3C +42 +42 +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR Ocircumflex +ENCODING 212 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +18 +24 +00 +3C +42 +42 +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR Otilde +ENCODING 213 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +32 +4C +00 +3C +42 +42 +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR Odieresis +ENCODING 214 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +24 +00 +3C +42 +42 +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR multiply +ENCODING 215 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +42 +24 +18 +18 +24 +42 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Oslash +ENCODING 216 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +43 +42 +46 +4A +52 +62 +42 +C2 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR Ugrave +ENCODING 217 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +08 +42 +42 +42 +42 +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR Uacute +ENCODING 218 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +08 +10 +42 +42 +42 +42 +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR Ucircumflex +ENCODING 219 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +18 +24 +00 +42 +42 +42 +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR Udieresis +ENCODING 220 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +24 +00 +42 +42 +42 +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR Yacute +ENCODING 221 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +08 +10 +82 +82 +44 +44 +28 +10 +10 +10 +10 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Thorn +ENCODING 222 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +40 +40 +7C +42 +42 +42 +42 +7C +40 +40 +00 +00 +00 +00 +ENDCHAR +STARTCHAR germandbls +ENCODING 223 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +38 +44 +44 +48 +7C +42 +42 +42 +62 +5C +00 +00 +00 +00 +ENDCHAR +STARTCHAR agrave +ENCODING 224 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +10 +08 +00 +3C +02 +3E +42 +42 +42 +3E +00 +00 +00 +00 +ENDCHAR +STARTCHAR aacute +ENCODING 225 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +08 +10 +00 +3C +02 +3E +42 +42 +42 +3E +00 +00 +00 +00 +ENDCHAR +STARTCHAR acircumflex +ENCODING 226 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +18 +24 +00 +3C +02 +3E +42 +42 +42 +3E +00 +00 +00 +00 +ENDCHAR +STARTCHAR atilde +ENCODING 227 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +32 +4C +00 +3C +02 +3E +42 +42 +42 +3E +00 +00 +00 +00 +ENDCHAR +STARTCHAR adieresis +ENCODING 228 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +24 +24 +00 +3C +02 +3E +42 +42 +42 +3E +00 +00 +00 +00 +ENDCHAR +STARTCHAR aring +ENCODING 229 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +18 +24 +18 +3C +02 +3E +42 +42 +42 +3E +00 +00 +00 +00 +ENDCHAR +STARTCHAR ae +ENCODING 230 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +6C +12 +72 +9E +90 +90 +6C +00 +00 +00 +00 +ENDCHAR +STARTCHAR ccedilla +ENCODING 231 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +3C +42 +40 +40 +40 +42 +3C +10 +10 +20 +00 +ENDCHAR +STARTCHAR egrave +ENCODING 232 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +10 +08 +00 +3C +42 +42 +7E +40 +40 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR eacute +ENCODING 233 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +08 +10 +00 +3C +42 +42 +7E +40 +40 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR ecircumflex +ENCODING 234 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +18 +24 +00 +3C +42 +42 +7E +40 +40 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR edieresis +ENCODING 235 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +24 +24 +00 +3C +42 +42 +7E +40 +40 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR igrave +ENCODING 236 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +20 +10 +00 +30 +10 +10 +10 +10 +10 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR iacute +ENCODING 237 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +08 +10 +00 +30 +10 +10 +10 +10 +10 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR icircumflex +ENCODING 238 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +30 +48 +00 +30 +10 +10 +10 +10 +10 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR idieresis +ENCODING 239 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +48 +48 +00 +30 +10 +10 +10 +10 +10 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR eth +ENCODING 240 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +28 +10 +28 +3C +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR ntilde +ENCODING 241 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +32 +4C +00 +7C +42 +42 +42 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR ograve +ENCODING 242 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +10 +08 +00 +3C +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR oacute +ENCODING 243 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +08 +10 +00 +3C +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR ocircumflex +ENCODING 244 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +18 +24 +00 +3C +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR otilde +ENCODING 245 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +32 +4C +00 +3C +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR odieresis +ENCODING 246 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +24 +24 +00 +3C +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR divide +ENCODING 247 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +10 +10 +00 +7C +00 +10 +10 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR oslash +ENCODING 248 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +02 +3C +46 +4A +52 +62 +42 +BC +00 +00 +00 +00 +ENDCHAR +STARTCHAR ugrave +ENCODING 249 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +10 +08 +00 +42 +42 +42 +42 +42 +42 +3E +00 +00 +00 +00 +ENDCHAR +STARTCHAR uacute +ENCODING 250 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +08 +10 +00 +42 +42 +42 +42 +42 +42 +3E +00 +00 +00 +00 +ENDCHAR +STARTCHAR ucircumflex +ENCODING 251 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +18 +24 +00 +42 +42 +42 +42 +42 +42 +3E +00 +00 +00 +00 +ENDCHAR +STARTCHAR udieresis +ENCODING 252 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +24 +24 +00 +42 +42 +42 +42 +42 +42 +3E +00 +00 +00 +00 +ENDCHAR +STARTCHAR yacute +ENCODING 253 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +08 +10 +00 +42 +42 +42 +42 +42 +42 +3E +02 +02 +3C +00 +ENDCHAR +STARTCHAR thorn +ENCODING 254 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +40 +40 +40 +7C +42 +42 +42 +42 +42 +7C +40 +40 +40 +00 +ENDCHAR +STARTCHAR ydieresis +ENCODING 255 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +24 +24 +00 +42 +42 +42 +42 +42 +42 +3E +02 +02 +3C +00 +ENDCHAR +STARTCHAR Amacron +ENCODING 256 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +3C +00 +3C +42 +42 +42 +42 +7E +42 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR amacron +ENCODING 257 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +3C +00 +3C +02 +3E +42 +42 +42 +3E +00 +00 +00 +00 +ENDCHAR +STARTCHAR Abreve +ENCODING 258 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +18 +00 +3C +42 +42 +42 +7E +42 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR abreve +ENCODING 259 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +24 +18 +00 +3C +02 +3E +42 +42 +42 +3E +00 +00 +00 +00 +ENDCHAR +STARTCHAR Aogonek +ENCODING 260 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +42 +42 +42 +42 +7E +42 +42 +42 +42 +02 +04 +03 +00 +ENDCHAR +STARTCHAR aogonek +ENCODING 261 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +3C +02 +3E +42 +42 +42 +3E +02 +04 +03 +00 +ENDCHAR +STARTCHAR Cacute +ENCODING 262 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +08 +10 +00 +3C +42 +42 +40 +40 +40 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR cacute +ENCODING 263 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +08 +10 +00 +3C +42 +40 +40 +40 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR Ccircumflex +ENCODING 264 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +18 +24 +00 +3C +42 +42 +40 +40 +40 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR ccircumflex +ENCODING 265 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +18 +24 +00 +3C +42 +40 +40 +40 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR Cdotaccent +ENCODING 266 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +00 +3C +42 +42 +40 +40 +40 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR cdotaccent +ENCODING 267 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +10 +10 +00 +3C +42 +40 +40 +40 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR Ccaron +ENCODING 268 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +18 +00 +3C +42 +42 +40 +40 +40 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR ccaron +ENCODING 269 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +24 +18 +00 +3C +42 +40 +40 +40 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR Dcaron +ENCODING 270 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +18 +00 +78 +44 +42 +42 +42 +42 +42 +44 +78 +00 +00 +00 +00 +ENDCHAR +STARTCHAR dcaron +ENCODING 271 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +18 +02 +02 +02 +3E +42 +42 +42 +42 +42 +3E +00 +00 +00 +00 +ENDCHAR +STARTCHAR Dcroat +ENCODING 272 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +78 +44 +42 +42 +F2 +42 +42 +42 +44 +78 +00 +00 +00 +00 +ENDCHAR +STARTCHAR dcroat +ENCODING 273 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +02 +0F +02 +3E +42 +42 +42 +42 +42 +3E +00 +00 +00 +00 +ENDCHAR +STARTCHAR Emacron +ENCODING 274 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +3C +00 +7E +40 +40 +40 +78 +40 +40 +40 +40 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR emacron +ENCODING 275 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +3C +00 +3C +42 +42 +7E +40 +40 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR Ebreve +ENCODING 276 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +18 +00 +7E +40 +40 +40 +78 +40 +40 +40 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR ebreve +ENCODING 277 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +24 +18 +00 +3C +42 +42 +7E +40 +40 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR Edotaccent +ENCODING 278 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +00 +7E +40 +40 +40 +78 +40 +40 +40 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR edotaccent +ENCODING 279 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +10 +10 +00 +3C +42 +42 +7E +40 +40 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR Eogonek +ENCODING 280 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7E +40 +40 +40 +78 +40 +40 +40 +40 +7E +02 +04 +03 +00 +ENDCHAR +STARTCHAR eogonek +ENCODING 281 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +3C +42 +42 +7E +40 +40 +3C +08 +10 +0C +00 +ENDCHAR +STARTCHAR Ecaron +ENCODING 282 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +18 +00 +7E +40 +40 +40 +78 +40 +40 +40 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR ecaron +ENCODING 283 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +24 +18 +00 +3C +42 +42 +7E +40 +40 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR Gcircumflex +ENCODING 284 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +18 +24 +00 +3C +42 +40 +40 +4E +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR gcircumflex +ENCODING 285 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +18 +24 +00 +3E +42 +42 +42 +42 +42 +3E +02 +02 +3C +00 +ENDCHAR +STARTCHAR Gbreve +ENCODING 286 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +18 +00 +3C +42 +40 +40 +4E +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR gbreve +ENCODING 287 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +24 +18 +00 +3E +42 +42 +42 +42 +42 +3E +02 +02 +3C +00 +ENDCHAR +STARTCHAR Gdotaccent +ENCODING 288 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +00 +3C +42 +40 +40 +4E +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR gdotaccent +ENCODING 289 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +08 +08 +00 +3E +42 +42 +42 +42 +42 +3E +02 +02 +3C +00 +ENDCHAR +STARTCHAR Gcommaaccent +ENCODING 290 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +42 +42 +40 +40 +4E +42 +42 +42 +3C +00 +10 +10 +20 +ENDCHAR +STARTCHAR gcommaaccent +ENCODING 291 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +08 +08 +00 +3E +42 +42 +42 +42 +42 +3E +02 +02 +3C +00 +ENDCHAR +STARTCHAR Hcircumflex +ENCODING 292 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +18 +24 +00 +42 +42 +42 +42 +7E +42 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR hcircumflex +ENCODING 293 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +0C +12 +40 +40 +40 +7C +42 +42 +42 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Hbar +ENCODING 294 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +42 +FF +42 +42 +7E +42 +42 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR hbar +ENCODING 295 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +40 +F0 +40 +7C +42 +42 +42 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Itilde +ENCODING 296 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +32 +4C +00 +38 +10 +10 +10 +10 +10 +10 +10 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR itilde +ENCODING 297 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +34 +58 +00 +30 +10 +10 +10 +10 +10 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Imacron +ENCODING 298 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +7C +00 +38 +10 +10 +10 +10 +10 +10 +10 +10 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR imacron +ENCODING 299 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +78 +00 +30 +10 +10 +10 +10 +10 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Ibreve +ENCODING 300 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +18 +00 +38 +10 +10 +10 +10 +10 +10 +10 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR ibreve +ENCODING 301 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +48 +30 +00 +30 +10 +10 +10 +10 +10 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Iogonek +ENCODING 302 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +38 +10 +10 +10 +10 +10 +10 +10 +10 +38 +10 +20 +18 +00 +ENDCHAR +STARTCHAR iogonek +ENCODING 303 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +10 +10 +00 +30 +10 +10 +10 +10 +10 +38 +10 +20 +18 +00 +ENDCHAR +STARTCHAR Idotaccent +ENCODING 304 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +00 +38 +10 +10 +10 +10 +10 +10 +10 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR dotlessi +ENCODING 305 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +30 +10 +10 +10 +10 +10 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR IJ +ENCODING 306 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +E7 +42 +42 +42 +42 +42 +42 +52 +52 +EC +00 +00 +00 +00 +ENDCHAR +STARTCHAR ij +ENCODING 307 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +42 +42 +00 +C6 +42 +42 +42 +42 +42 +E2 +12 +12 +0C +00 +ENDCHAR +STARTCHAR Jcircumflex +ENCODING 308 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +0C +12 +00 +0E +04 +04 +04 +04 +04 +44 +44 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR jcircumflex +ENCODING 309 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +0C +12 +00 +0C +04 +04 +04 +04 +04 +04 +44 +44 +38 +00 +ENDCHAR +STARTCHAR Kcommaaccent +ENCODING 310 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +42 +44 +48 +50 +60 +60 +50 +48 +44 +42 +00 +10 +10 +20 +ENDCHAR +STARTCHAR kcommaaccent +ENCODING 311 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +40 +40 +40 +42 +44 +48 +70 +48 +44 +42 +00 +10 +10 +20 +ENDCHAR +STARTCHAR kgreenlandic +ENCODING 312 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +42 +44 +48 +70 +48 +44 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Lacute +ENCODING 313 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +20 +40 +00 +40 +40 +40 +40 +40 +40 +40 +40 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR lacute +ENCODING 314 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +08 +10 +00 +30 +10 +10 +10 +10 +10 +10 +10 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Lcommaaccent +ENCODING 315 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +40 +40 +40 +40 +40 +40 +40 +40 +40 +7E +00 +10 +10 +20 +ENDCHAR +STARTCHAR lcommaaccent +ENCODING 316 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +30 +10 +10 +10 +10 +10 +10 +10 +10 +38 +00 +10 +10 +20 +ENDCHAR +STARTCHAR Lcaron +ENCODING 317 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +18 +40 +40 +40 +40 +40 +40 +40 +40 +40 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR lcaron +ENCODING 318 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +48 +30 +00 +30 +10 +10 +10 +10 +10 +10 +10 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Ldot +ENCODING 319 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +40 +40 +40 +40 +44 +44 +40 +40 +40 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR ldot +ENCODING 320 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +30 +10 +10 +10 +11 +11 +10 +10 +10 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Lslash +ENCODING 321 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +40 +40 +40 +40 +60 +C0 +40 +40 +40 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR lslash +ENCODING 322 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +30 +10 +10 +10 +18 +30 +10 +10 +10 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Nacute +ENCODING 323 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +08 +10 +42 +42 +42 +62 +52 +4A +46 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR nacute +ENCODING 324 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +08 +10 +00 +7C +42 +42 +42 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Ncommaaccent +ENCODING 325 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +42 +42 +42 +62 +52 +4A +46 +42 +42 +42 +00 +10 +10 +20 +ENDCHAR +STARTCHAR ncommaaccent +ENCODING 326 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +7C +42 +42 +42 +42 +42 +42 +00 +10 +10 +20 +ENDCHAR +STARTCHAR Ncaron +ENCODING 327 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +18 +42 +42 +42 +62 +52 +4A +46 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR ncaron +ENCODING 328 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +24 +18 +00 +7C +42 +42 +42 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR napostrophe +ENCODING 329 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +80 +00 +7C +42 +42 +42 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Eng +ENCODING 330 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +42 +42 +42 +62 +52 +4A +46 +42 +42 +42 +02 +02 +0C +00 +ENDCHAR +STARTCHAR eng +ENCODING 331 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +7C +42 +42 +42 +42 +42 +42 +02 +02 +0C +00 +ENDCHAR +STARTCHAR Omacron +ENCODING 332 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +3C +00 +3C +42 +42 +42 +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR omacron +ENCODING 333 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +3C +00 +3C +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR Obreve +ENCODING 334 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +18 +00 +3C +42 +42 +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR obreve +ENCODING 335 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +24 +18 +00 +3C +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR Ohungarumlaut +ENCODING 336 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +12 +24 +00 +3C +42 +42 +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR ohungarumlaut +ENCODING 337 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +12 +24 +00 +3C +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR OE +ENCODING 338 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7E +90 +90 +90 +9C +90 +90 +90 +90 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR oe +ENCODING 339 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +7C +92 +92 +9E +90 +90 +7C +00 +00 +00 +00 +ENDCHAR +STARTCHAR Racute +ENCODING 340 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +08 +10 +00 +7C +42 +42 +42 +7C +50 +48 +44 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR racute +ENCODING 341 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +08 +10 +00 +5E +60 +40 +40 +40 +40 +40 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Rcommaaccent +ENCODING 342 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7C +42 +42 +42 +42 +7C +50 +48 +44 +42 +00 +10 +10 +20 +ENDCHAR +STARTCHAR rcommaaccent +ENCODING 343 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +5E +60 +40 +40 +40 +40 +40 +00 +40 +40 +80 +ENDCHAR +STARTCHAR Rcaron +ENCODING 344 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +18 +00 +7C +42 +42 +42 +7C +50 +48 +44 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR rcaron +ENCODING 345 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +24 +18 +00 +5E +60 +40 +40 +40 +40 +40 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Sacute +ENCODING 346 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +08 +10 +00 +3C +42 +40 +40 +3C +02 +02 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR sacute +ENCODING 347 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +04 +08 +00 +3E +40 +40 +3C +02 +02 +7C +00 +00 +00 +00 +ENDCHAR +STARTCHAR Scircumflex +ENCODING 348 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +18 +24 +00 +3C +42 +40 +40 +3C +02 +02 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR scircumflex +ENCODING 349 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +18 +24 +00 +3E +40 +40 +3C +02 +02 +7C +00 +00 +00 +00 +ENDCHAR +STARTCHAR Scedilla +ENCODING 350 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +42 +40 +40 +3C +02 +02 +42 +42 +3C +10 +10 +20 +00 +ENDCHAR +STARTCHAR scedilla +ENCODING 351 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +3E +40 +40 +3C +02 +02 +7C +10 +10 +20 +00 +ENDCHAR +STARTCHAR Scaron +ENCODING 352 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +18 +00 +3C +42 +40 +40 +3C +02 +02 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR scaron +ENCODING 353 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +24 +18 +00 +3E +40 +40 +3C +02 +02 +7C +00 +00 +00 +00 +ENDCHAR +STARTCHAR Tcedilla +ENCODING 354 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +FE +10 +10 +10 +10 +10 +10 +10 +10 +10 +08 +08 +10 +00 +ENDCHAR +STARTCHAR tcedilla +ENCODING 355 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +10 +10 +10 +7C +10 +10 +10 +10 +10 +0E +04 +04 +08 +00 +ENDCHAR +STARTCHAR Tcaron +ENCODING 356 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +18 +00 +FE +10 +10 +10 +10 +10 +10 +10 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR tcaron +ENCODING 357 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +18 +00 +10 +10 +7C +10 +10 +10 +10 +10 +0E +00 +00 +00 +00 +ENDCHAR +STARTCHAR Tbar +ENCODING 358 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +FE +10 +10 +10 +7C +10 +10 +10 +10 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR tbar +ENCODING 359 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +10 +10 +10 +7C +10 +38 +10 +10 +10 +0E +00 +00 +00 +00 +ENDCHAR +STARTCHAR Utilde +ENCODING 360 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +32 +4C +00 +42 +42 +42 +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR utilde +ENCODING 361 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +32 +4C +00 +42 +42 +42 +42 +42 +42 +3E +00 +00 +00 +00 +ENDCHAR +STARTCHAR Umacron +ENCODING 362 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +3C +00 +42 +42 +42 +42 +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR umacron +ENCODING 363 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +3C +00 +42 +42 +42 +42 +42 +42 +3E +00 +00 +00 +00 +ENDCHAR +STARTCHAR Ubreve +ENCODING 364 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +18 +42 +42 +42 +42 +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR ubreve +ENCODING 365 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +24 +18 +00 +42 +42 +42 +42 +42 +42 +3E +00 +00 +00 +00 +ENDCHAR +STARTCHAR Uring +ENCODING 366 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +18 +24 +18 +42 +42 +42 +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR uring +ENCODING 367 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +18 +24 +18 +42 +42 +42 +42 +42 +42 +3E +00 +00 +00 +00 +ENDCHAR +STARTCHAR Uhungarumlaut +ENCODING 368 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +12 +24 +00 +42 +42 +42 +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR uhungarumlaut +ENCODING 369 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +12 +24 +00 +42 +42 +42 +42 +42 +42 +3E +00 +00 +00 +00 +ENDCHAR +STARTCHAR Uogonek +ENCODING 370 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +42 +42 +42 +42 +42 +42 +42 +42 +42 +3C +08 +10 +0C +00 +ENDCHAR +STARTCHAR uogonek +ENCODING 371 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +42 +42 +42 +42 +42 +42 +3E +02 +04 +03 +00 +ENDCHAR +STARTCHAR Wcircumflex +ENCODING 372 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +18 +24 +00 +82 +82 +82 +82 +92 +92 +AA +C6 +82 +00 +00 +00 +00 +ENDCHAR +STARTCHAR wcircumflex +ENCODING 373 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +18 +24 +00 +82 +82 +92 +92 +92 +92 +7C +00 +00 +00 +00 +ENDCHAR +STARTCHAR Ycircumflex +ENCODING 374 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +18 +24 +00 +82 +82 +44 +44 +28 +10 +10 +10 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR ycircumflex +ENCODING 375 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +18 +24 +00 +42 +42 +42 +42 +42 +42 +3E +02 +02 +3C +00 +ENDCHAR +STARTCHAR Ydieresis +ENCODING 376 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +44 +44 +00 +82 +82 +44 +44 +28 +10 +10 +10 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Zacute +ENCODING 377 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +08 +10 +00 +7E +02 +04 +08 +10 +20 +40 +40 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR zacute +ENCODING 378 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +08 +10 +00 +7E +04 +08 +10 +20 +40 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR Zdotaccent +ENCODING 379 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +00 +7E +02 +04 +08 +10 +20 +40 +40 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR zdotaccent +ENCODING 380 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +10 +10 +00 +7E +04 +08 +10 +20 +40 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR Zcaron +ENCODING 381 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +18 +00 +7E +02 +04 +08 +10 +20 +40 +40 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR zcaron +ENCODING 382 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +24 +18 +00 +7E +04 +08 +10 +20 +40 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR longs +ENCODING 383 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +0E +10 +10 +10 +10 +10 +10 +10 +10 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni0186 +ENCODING 390 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +42 +42 +02 +02 +02 +02 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni018E +ENCODING 398 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7E +02 +02 +02 +1E +02 +02 +02 +02 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR Schwa +ENCODING 399 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +42 +02 +02 +7E +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni0190 +ENCODING 400 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +42 +42 +40 +38 +40 +40 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR florin +ENCODING 402 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +0C +12 +10 +10 +7C +10 +10 +10 +10 +10 +10 +90 +60 +00 +ENDCHAR +STARTCHAR uni019D +ENCODING 413 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +42 +42 +42 +62 +52 +4A +46 +42 +42 +42 +40 +40 +80 +00 +ENDCHAR +STARTCHAR uni019E +ENCODING 414 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +7C +42 +42 +42 +42 +42 +42 +02 +02 +02 +00 +ENDCHAR +STARTCHAR uni01B5 +ENCODING 437 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7E +02 +04 +08 +7E +10 +20 +40 +40 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni01B6 +ENCODING 438 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +7E +04 +08 +7C +10 +20 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR Ezh +ENCODING 439 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7E +02 +04 +08 +1C +02 +02 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni01CD +ENCODING 461 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +18 +00 +3C +42 +42 +42 +7E +42 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni01CE +ENCODING 462 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +24 +18 +00 +3C +02 +3E +42 +42 +42 +3E +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni01CF +ENCODING 463 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +18 +00 +38 +10 +10 +10 +10 +10 +10 +10 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni01D0 +ENCODING 464 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +48 +30 +00 +30 +10 +10 +10 +10 +10 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni01D1 +ENCODING 465 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +18 +00 +3C +42 +42 +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni01D2 +ENCODING 466 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +24 +18 +00 +3C +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni01D3 +ENCODING 467 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +18 +42 +42 +42 +42 +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni01D4 +ENCODING 468 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +24 +18 +00 +42 +42 +42 +42 +42 +42 +3E +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni01E2 +ENCODING 482 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +7C +00 +7E +90 +90 +90 +FC +90 +90 +90 +90 +9E +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni01E3 +ENCODING 483 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +7C +00 +6C +12 +72 +9E +90 +90 +6C +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni01E4 +ENCODING 484 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +42 +42 +40 +40 +4E +42 +4F +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni01E5 +ENCODING 485 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +3E +42 +42 +4F +42 +42 +3E +02 +02 +3C +00 +ENDCHAR +STARTCHAR Gcaron +ENCODING 486 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +18 +00 +3C +42 +40 +40 +4E +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR gcaron +ENCODING 487 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +24 +18 +00 +3E +42 +42 +42 +42 +42 +3E +02 +02 +3C +00 +ENDCHAR +STARTCHAR uni01E8 +ENCODING 488 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +18 +42 +44 +48 +50 +60 +60 +50 +48 +44 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni01E9 +ENCODING 489 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +18 +40 +40 +40 +42 +44 +48 +70 +48 +44 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni01EA +ENCODING 490 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +42 +42 +42 +42 +42 +42 +42 +42 +3C +08 +10 +0C +00 +ENDCHAR +STARTCHAR uni01EB +ENCODING 491 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +3C +42 +42 +42 +42 +42 +3C +08 +10 +0C +00 +ENDCHAR +STARTCHAR uni01EC +ENCODING 492 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +3C +00 +3C +42 +42 +42 +42 +42 +42 +42 +42 +3C +08 +10 +0C +00 +ENDCHAR +STARTCHAR uni01ED +ENCODING 493 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +3C +00 +3C +42 +42 +42 +42 +42 +3C +08 +10 +0C +00 +ENDCHAR +STARTCHAR uni01EE +ENCODING 494 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +18 +00 +7E +04 +08 +1C +02 +02 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni01EF +ENCODING 495 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +24 +18 +00 +7E +02 +04 +08 +1C +02 +02 +42 +42 +3C +00 +ENDCHAR +STARTCHAR uni01F0 +ENCODING 496 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +12 +0C +00 +0C +04 +04 +04 +04 +04 +04 +44 +44 +38 +00 +ENDCHAR +STARTCHAR uni01F4 +ENCODING 500 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +08 +10 +00 +3C +42 +40 +40 +4E +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni01F5 +ENCODING 501 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +04 +08 +00 +3E +42 +42 +42 +42 +42 +3E +02 +02 +3C +00 +ENDCHAR +STARTCHAR AEacute +ENCODING 508 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +08 +10 +00 +7E +90 +90 +90 +FC +90 +90 +90 +9E +00 +00 +00 +00 +ENDCHAR +STARTCHAR aeacute +ENCODING 509 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +08 +10 +00 +6C +12 +72 +9E +90 +90 +6C +00 +00 +00 +00 +ENDCHAR +STARTCHAR Oslashacute +ENCODING 510 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +08 +10 +00 +3D +42 +46 +4A +52 +62 +42 +C2 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR oslashacute +ENCODING 511 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +08 +10 +02 +3C +46 +4A +52 +62 +42 +BC +00 +00 +00 +00 +ENDCHAR +STARTCHAR Scommaaccent +ENCODING 536 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +42 +40 +40 +3C +02 +02 +42 +42 +3C +00 +10 +10 +20 +ENDCHAR +STARTCHAR scommaaccent +ENCODING 537 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +3E +40 +40 +3C +02 +02 +7C +00 +10 +10 +20 +ENDCHAR +STARTCHAR Tcommaaccent +ENCODING 538 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +FE +10 +10 +10 +10 +10 +10 +10 +10 +10 +00 +10 +10 +20 +ENDCHAR +STARTCHAR tcommaaccent +ENCODING 539 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +10 +10 +10 +7C +10 +10 +10 +10 +10 +0E +00 +04 +04 +08 +ENDCHAR +STARTCHAR uni0232 +ENCODING 562 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +7C +00 +82 +82 +44 +44 +28 +10 +10 +10 +10 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni0233 +ENCODING 563 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +3C +00 +42 +42 +42 +42 +42 +42 +3E +02 +02 +3C +00 +ENDCHAR +STARTCHAR dotlessj +ENCODING 567 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +0C +04 +04 +04 +04 +04 +04 +44 +44 +38 +00 +ENDCHAR +STARTCHAR uni0254 +ENCODING 596 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +3C +42 +02 +02 +02 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni0258 +ENCODING 600 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +3C +42 +42 +7E +02 +02 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR schwa +ENCODING 601 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +3C +02 +02 +7E +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni025B +ENCODING 603 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +3C +42 +40 +38 +40 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni0272 +ENCODING 626 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +7C +42 +42 +42 +42 +42 +42 +40 +40 +80 +00 +ENDCHAR +STARTCHAR ezh +ENCODING 658 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +7E +02 +04 +08 +1C +02 +02 +42 +42 +3C +00 +ENDCHAR +STARTCHAR commaturnedmod +ENCODING 699 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +08 +10 +10 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii57929 +ENCODING 700 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +08 +08 +10 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii64937 +ENCODING 701 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +08 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR circumflex +ENCODING 710 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +18 +24 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR caron +ENCODING 711 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +18 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR breve +ENCODING 728 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +18 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR dotaccent +ENCODING 729 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR ogonek +ENCODING 731 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +08 +10 +0C +00 +ENDCHAR +STARTCHAR tilde +ENCODING 732 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +32 +4C +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR hungarumlaut +ENCODING 733 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +12 +24 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR gravecomb +ENCODING 768 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +08 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR acutecomb +ENCODING 769 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +08 +10 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni0302 +ENCODING 770 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +18 +24 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR tildecomb +ENCODING 771 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +32 +4C +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni0304 +ENCODING 772 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +3C +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni0305 +ENCODING 773 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +7E +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni0306 +ENCODING 774 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +18 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni0307 +ENCODING 775 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni0308 +ENCODING 776 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +24 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni030A +ENCODING 778 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +18 +24 +18 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni030B +ENCODING 779 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +12 +24 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni030C +ENCODING 780 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +18 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni0329 +ENCODING 809 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +10 +10 +00 +ENDCHAR +STARTCHAR tonos +ENCODING 900 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +40 +80 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR dieresistonos +ENCODING 901 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +08 +10 +00 +24 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Alphatonos +ENCODING 902 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +40 +80 +3C +42 +42 +42 +42 +7E +42 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR anoteleia +ENCODING 903 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +10 +10 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Epsilontonos +ENCODING 904 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +40 +80 +7E +40 +40 +40 +78 +40 +40 +40 +40 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR Etatonos +ENCODING 905 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +40 +80 +42 +42 +42 +42 +7E +42 +42 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Iotatonos +ENCODING 906 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +40 +80 +38 +10 +10 +10 +10 +10 +10 +10 +10 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Omicrontonos +ENCODING 908 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +40 +80 +3C +42 +42 +42 +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR Upsilontonos +ENCODING 910 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +40 +80 +00 +82 +82 +44 +44 +28 +10 +10 +10 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Omegatonos +ENCODING 911 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +40 +80 +3C +42 +42 +42 +42 +42 +42 +24 +24 +66 +00 +00 +00 +00 +ENDCHAR +STARTCHAR iotadieresistonos +ENCODING 912 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +08 +10 +48 +48 +00 +30 +10 +10 +10 +10 +10 +0C +00 +00 +00 +00 +ENDCHAR +STARTCHAR Alpha +ENCODING 913 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +42 +42 +42 +42 +7E +42 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Beta +ENCODING 914 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7C +42 +42 +42 +7C +42 +42 +42 +42 +7C +00 +00 +00 +00 +ENDCHAR +STARTCHAR Gamma +ENCODING 915 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7E +40 +40 +40 +40 +40 +40 +40 +40 +40 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Delta +ENCODING 916 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +10 +10 +28 +28 +44 +44 +44 +82 +82 +FE +00 +00 +00 +00 +ENDCHAR +STARTCHAR Epsilon +ENCODING 917 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7E +40 +40 +40 +78 +40 +40 +40 +40 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR Zeta +ENCODING 918 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7E +02 +02 +04 +08 +10 +20 +40 +40 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR Eta +ENCODING 919 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +42 +42 +42 +42 +7E +42 +42 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Theta +ENCODING 920 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +42 +42 +42 +5A +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR Iota +ENCODING 921 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +38 +10 +10 +10 +10 +10 +10 +10 +10 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Kappa +ENCODING 922 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +42 +44 +48 +50 +60 +60 +50 +48 +44 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Lambda +ENCODING 923 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +10 +10 +28 +28 +44 +44 +44 +82 +82 +82 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Mu +ENCODING 924 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +82 +C6 +AA +92 +92 +82 +82 +82 +82 +82 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Nu +ENCODING 925 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +42 +42 +42 +62 +52 +4A +46 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Xi +ENCODING 926 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7E +00 +00 +00 +3C +00 +00 +00 +00 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR Omicron +ENCODING 927 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +42 +42 +42 +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR Pi +ENCODING 928 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7E +42 +42 +42 +42 +42 +42 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Rho +ENCODING 929 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7C +42 +42 +42 +42 +7C +40 +40 +40 +40 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Sigma +ENCODING 931 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7E +40 +20 +10 +08 +08 +10 +20 +40 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR Tau +ENCODING 932 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +FE +10 +10 +10 +10 +10 +10 +10 +10 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Upsilon +ENCODING 933 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +82 +82 +44 +44 +28 +10 +10 +10 +10 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Phi +ENCODING 934 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +10 +7C +92 +92 +92 +92 +92 +92 +7C +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Chi +ENCODING 935 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +42 +42 +24 +24 +18 +18 +24 +24 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Psi +ENCODING 936 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +92 +92 +92 +92 +92 +92 +92 +7C +10 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Omega +ENCODING 937 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +42 +42 +42 +42 +42 +42 +24 +24 +66 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Iotadieresis +ENCODING 938 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +44 +44 +00 +38 +10 +10 +10 +10 +10 +10 +10 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR Upsilondieresis +ENCODING 939 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +44 +44 +00 +82 +82 +44 +44 +28 +10 +10 +10 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR alphatonos +ENCODING 940 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +08 +10 +00 +3A +46 +44 +44 +44 +46 +3A +00 +00 +00 +00 +ENDCHAR +STARTCHAR epsilontonos +ENCODING 941 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +08 +10 +00 +3C +42 +40 +38 +40 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR etatonos +ENCODING 942 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +08 +10 +00 +7C +42 +42 +42 +42 +42 +42 +02 +02 +02 +00 +ENDCHAR +STARTCHAR iotatonos +ENCODING 943 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +08 +10 +00 +30 +10 +10 +10 +10 +10 +0C +00 +00 +00 +00 +ENDCHAR +STARTCHAR upsilondieresistonos +ENCODING 944 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +08 +10 +00 +24 +00 +42 +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR alpha +ENCODING 945 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +3A +46 +44 +44 +44 +46 +3A +00 +00 +00 +00 +ENDCHAR +STARTCHAR beta +ENCODING 946 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +38 +44 +44 +48 +7C +42 +42 +42 +42 +7C +40 +40 +40 +00 +ENDCHAR +STARTCHAR gamma +ENCODING 947 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +82 +82 +44 +44 +28 +28 +10 +10 +10 +10 +00 +ENDCHAR +STARTCHAR delta +ENCODING 948 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3E +10 +08 +3C +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR epsilon +ENCODING 949 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +3C +42 +40 +38 +40 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR zeta +ENCODING 950 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7E +04 +08 +10 +20 +40 +40 +40 +40 +3C +02 +02 +04 +00 +ENDCHAR +STARTCHAR eta +ENCODING 951 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +7C +42 +42 +42 +42 +42 +42 +02 +02 +02 +00 +ENDCHAR +STARTCHAR theta +ENCODING 952 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +38 +44 +44 +44 +7C +44 +44 +44 +44 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR iota +ENCODING 953 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +30 +10 +10 +10 +10 +10 +0C +00 +00 +00 +00 +ENDCHAR +STARTCHAR kappa +ENCODING 954 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +42 +44 +48 +70 +48 +44 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR lambda +ENCODING 955 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +20 +20 +10 +10 +28 +28 +44 +44 +82 +82 +00 +00 +00 +00 +ENDCHAR +STARTCHAR mugreek +ENCODING 956 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +42 +42 +42 +42 +42 +46 +7A +40 +40 +40 +00 +ENDCHAR +STARTCHAR nu +ENCODING 957 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +42 +42 +42 +24 +24 +18 +18 +00 +00 +00 +00 +ENDCHAR +STARTCHAR xi +ENCODING 958 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3E +40 +40 +40 +3C +40 +40 +40 +40 +3C +02 +02 +04 +00 +ENDCHAR +STARTCHAR omicron +ENCODING 959 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +3C +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR pi +ENCODING 960 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +7E +42 +42 +42 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR rho +ENCODING 961 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +3C +42 +42 +42 +42 +42 +7C +40 +40 +40 +00 +ENDCHAR +STARTCHAR sigma1 +ENCODING 962 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +3C +42 +40 +40 +40 +40 +3C +02 +02 +04 +00 +ENDCHAR +STARTCHAR sigma +ENCODING 963 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +3E +44 +44 +44 +44 +44 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR tau +ENCODING 964 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +FE +10 +10 +10 +10 +10 +0C +00 +00 +00 +00 +ENDCHAR +STARTCHAR upsilon +ENCODING 965 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +42 +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR phi +ENCODING 966 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +4C +92 +92 +92 +92 +92 +7C +10 +10 +10 +00 +ENDCHAR +STARTCHAR chi +ENCODING 967 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +42 +42 +24 +24 +18 +18 +24 +24 +42 +42 +00 +ENDCHAR +STARTCHAR psi +ENCODING 968 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +92 +92 +92 +92 +92 +92 +7C +10 +10 +10 +00 +ENDCHAR +STARTCHAR omega +ENCODING 969 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +44 +82 +92 +92 +92 +92 +6C +00 +00 +00 +00 +ENDCHAR +STARTCHAR iotadieresis +ENCODING 970 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +48 +48 +00 +30 +10 +10 +10 +10 +10 +0C +00 +00 +00 +00 +ENDCHAR +STARTCHAR upsilondieresis +ENCODING 971 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +24 +24 +00 +42 +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR omicrontonos +ENCODING 972 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +08 +10 +00 +3C +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR upsilontonos +ENCODING 973 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +08 +10 +00 +42 +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR omegatonos +ENCODING 974 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +08 +10 +00 +44 +82 +92 +92 +92 +92 +6C +00 +00 +00 +00 +ENDCHAR +STARTCHAR theta1 +ENCODING 977 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +38 +44 +44 +44 +3E +04 +C4 +44 +44 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR phi1 +ENCODING 981 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +10 +7C +92 +92 +92 +92 +92 +7C +10 +00 +00 +00 +ENDCHAR +STARTCHAR uni03F0 +ENCODING 1008 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +C2 +24 +18 +10 +30 +48 +86 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni03F1 +ENCODING 1009 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +3C +42 +42 +42 +42 +42 +7C +40 +40 +3C +00 +ENDCHAR +STARTCHAR uni03F2 +ENCODING 1010 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +3C +42 +40 +40 +40 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni03F3 +ENCODING 1011 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +04 +04 +00 +0C +04 +04 +04 +04 +04 +04 +44 +44 +38 +00 +ENDCHAR +STARTCHAR uni03F4 +ENCODING 1012 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +42 +42 +42 +7E +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni03F5 +ENCODING 1013 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +1E +20 +40 +7C +40 +20 +1E +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni03F6 +ENCODING 1014 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +78 +04 +02 +3E +02 +04 +78 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni0400 +ENCODING 1024 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +08 +00 +7E +40 +40 +40 +78 +40 +40 +40 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10023 +ENCODING 1025 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +24 +00 +7E +40 +40 +40 +78 +40 +40 +40 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10051 +ENCODING 1026 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +F8 +20 +20 +3C +22 +22 +22 +22 +22 +24 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10052 +ENCODING 1027 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +08 +10 +00 +7E +40 +40 +40 +40 +40 +40 +40 +40 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10053 +ENCODING 1028 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +42 +40 +40 +78 +40 +40 +40 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10054 +ENCODING 1029 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +42 +40 +40 +3C +02 +02 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10055 +ENCODING 1030 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +38 +10 +10 +10 +10 +10 +10 +10 +10 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10056 +ENCODING 1031 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +44 +44 +00 +38 +10 +10 +10 +10 +10 +10 +10 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10057 +ENCODING 1032 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +0E +04 +04 +04 +04 +04 +04 +44 +44 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10058 +ENCODING 1033 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +30 +50 +90 +9C +92 +92 +92 +92 +92 +9C +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10059 +ENCODING 1034 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +90 +90 +90 +9C +F2 +92 +92 +92 +92 +9C +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10060 +ENCODING 1035 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +F8 +20 +20 +3C +22 +22 +22 +22 +22 +22 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10061 +ENCODING 1036 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +08 +10 +42 +44 +48 +50 +60 +60 +50 +48 +44 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni040D +ENCODING 1037 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +08 +42 +42 +42 +46 +4A +52 +62 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10062 +ENCODING 1038 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +18 +42 +42 +42 +42 +42 +3E +02 +02 +02 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10145 +ENCODING 1039 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +42 +42 +42 +42 +42 +42 +42 +42 +42 +7E +18 +18 +00 +00 +ENDCHAR +STARTCHAR afii10017 +ENCODING 1040 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +42 +42 +42 +42 +7E +42 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10018 +ENCODING 1041 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7C +40 +40 +7C +42 +42 +42 +42 +42 +7C +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10019 +ENCODING 1042 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7C +42 +42 +42 +7C +42 +42 +42 +42 +7C +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10020 +ENCODING 1043 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7E +40 +40 +40 +40 +40 +40 +40 +40 +40 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10021 +ENCODING 1044 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +44 +44 +44 +44 +44 +44 +44 +44 +FE +82 +00 +00 +00 +ENDCHAR +STARTCHAR afii10022 +ENCODING 1045 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7E +40 +40 +40 +78 +40 +40 +40 +40 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10024 +ENCODING 1046 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +92 +92 +92 +54 +38 +54 +92 +92 +92 +92 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10025 +ENCODING 1047 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +42 +42 +02 +1C +02 +02 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10026 +ENCODING 1048 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +42 +42 +42 +46 +4A +52 +62 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10027 +ENCODING 1049 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +18 +42 +42 +42 +46 +4A +52 +62 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10028 +ENCODING 1050 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +42 +44 +48 +50 +60 +60 +50 +48 +44 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10029 +ENCODING 1051 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +0E +12 +22 +22 +22 +22 +22 +22 +22 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10030 +ENCODING 1052 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +82 +C6 +AA +92 +92 +82 +82 +82 +82 +82 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10031 +ENCODING 1053 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +42 +42 +42 +42 +7E +42 +42 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10032 +ENCODING 1054 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +42 +42 +42 +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10033 +ENCODING 1055 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7E +42 +42 +42 +42 +42 +42 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10034 +ENCODING 1056 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7C +42 +42 +42 +42 +7C +40 +40 +40 +40 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10035 +ENCODING 1057 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +42 +42 +40 +40 +40 +40 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10036 +ENCODING 1058 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +FE +10 +10 +10 +10 +10 +10 +10 +10 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10037 +ENCODING 1059 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +42 +42 +42 +42 +42 +3E +02 +02 +02 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10038 +ENCODING 1060 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +10 +7C +92 +92 +92 +92 +92 +92 +92 +92 +7C +10 +00 +00 +00 +ENDCHAR +STARTCHAR afii10039 +ENCODING 1061 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +42 +42 +24 +24 +18 +18 +24 +24 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10040 +ENCODING 1062 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +42 +42 +42 +42 +42 +42 +42 +42 +42 +3F +01 +01 +00 +00 +ENDCHAR +STARTCHAR afii10041 +ENCODING 1063 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +42 +42 +42 +42 +42 +3E +02 +02 +02 +02 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10042 +ENCODING 1064 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +92 +92 +92 +92 +92 +92 +92 +92 +92 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10043 +ENCODING 1065 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +92 +92 +92 +92 +92 +92 +92 +92 +92 +7F +01 +01 +00 +00 +ENDCHAR +STARTCHAR afii10044 +ENCODING 1066 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +C0 +40 +40 +7C +42 +42 +42 +42 +42 +7C +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10045 +ENCODING 1067 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +82 +82 +82 +F2 +8A +8A +8A +8A +8A +F2 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10046 +ENCODING 1068 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +40 +40 +40 +7C +42 +42 +42 +42 +42 +7C +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10047 +ENCODING 1069 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +42 +02 +02 +1E +02 +02 +02 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10048 +ENCODING 1070 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +8C +92 +92 +92 +92 +F2 +92 +92 +92 +8C +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10049 +ENCODING 1071 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3E +42 +42 +42 +42 +3E +0A +12 +22 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10065 +ENCODING 1072 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +3C +02 +3E +42 +42 +42 +3E +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10066 +ENCODING 1073 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +40 +40 +7C +42 +42 +42 +42 +42 +7C +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10067 +ENCODING 1074 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +38 +44 +44 +48 +7C +42 +42 +42 +42 +7C +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10068 +ENCODING 1075 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +7E +40 +40 +40 +40 +40 +40 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10069 +ENCODING 1076 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +3E +42 +42 +42 +42 +42 +3E +02 +02 +3C +00 +ENDCHAR +STARTCHAR afii10070 +ENCODING 1077 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +3C +42 +42 +7E +40 +40 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10072 +ENCODING 1078 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +92 +92 +54 +38 +54 +92 +92 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10073 +ENCODING 1079 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +3C +42 +02 +1C +02 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10074 +ENCODING 1080 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +42 +42 +42 +42 +42 +42 +3E +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10075 +ENCODING 1081 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +24 +18 +00 +42 +42 +42 +42 +42 +42 +3E +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10076 +ENCODING 1082 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +42 +44 +48 +70 +48 +44 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10077 +ENCODING 1083 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +1E +22 +22 +22 +22 +22 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10078 +ENCODING 1084 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +82 +C6 +AA +92 +82 +82 +82 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10079 +ENCODING 1085 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +42 +42 +42 +7E +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10080 +ENCODING 1086 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +3C +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10081 +ENCODING 1087 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +7E +42 +42 +42 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10082 +ENCODING 1088 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +7C +42 +42 +42 +42 +42 +7C +40 +40 +40 +00 +ENDCHAR +STARTCHAR afii10083 +ENCODING 1089 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +3C +42 +40 +40 +40 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10084 +ENCODING 1090 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +FE +10 +10 +10 +10 +10 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10085 +ENCODING 1091 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +42 +42 +42 +42 +42 +42 +3E +02 +02 +3C +00 +ENDCHAR +STARTCHAR afii10086 +ENCODING 1092 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +10 +7C +92 +92 +92 +92 +92 +7C +10 +00 +00 +00 +ENDCHAR +STARTCHAR afii10087 +ENCODING 1093 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +42 +42 +24 +18 +24 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10088 +ENCODING 1094 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +42 +42 +42 +42 +42 +42 +3F +01 +01 +00 +00 +ENDCHAR +STARTCHAR afii10089 +ENCODING 1095 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +42 +42 +42 +3E +02 +02 +02 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10090 +ENCODING 1096 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +92 +92 +92 +92 +92 +92 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10091 +ENCODING 1097 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +92 +92 +92 +92 +92 +92 +7F +01 +01 +00 +00 +ENDCHAR +STARTCHAR afii10092 +ENCODING 1098 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +60 +20 +3C +22 +22 +22 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10093 +ENCODING 1099 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +82 +82 +F2 +8A +8A +8A +F2 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10094 +ENCODING 1100 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +40 +40 +78 +44 +44 +44 +78 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10095 +ENCODING 1101 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +3C +42 +02 +1E +02 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10096 +ENCODING 1102 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +8C +92 +92 +F2 +92 +92 +8C +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10097 +ENCODING 1103 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +3E +42 +42 +3E +12 +22 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni0450 +ENCODING 1104 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +10 +08 +00 +3C +42 +42 +7E +40 +40 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10071 +ENCODING 1105 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +24 +24 +00 +3C +42 +42 +7E +40 +40 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10099 +ENCODING 1106 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +40 +F0 +40 +7C +42 +42 +42 +42 +42 +42 +02 +02 +0C +00 +ENDCHAR +STARTCHAR afii10100 +ENCODING 1107 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +08 +10 +00 +7E +40 +40 +40 +40 +40 +40 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10101 +ENCODING 1108 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +3C +42 +40 +78 +40 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10102 +ENCODING 1109 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +3E +40 +40 +3C +02 +02 +7C +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10103 +ENCODING 1110 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +10 +10 +00 +30 +10 +10 +10 +10 +10 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10104 +ENCODING 1111 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +48 +48 +00 +30 +10 +10 +10 +10 +10 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10105 +ENCODING 1112 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +04 +04 +00 +0C +04 +04 +04 +04 +04 +04 +44 +44 +38 +00 +ENDCHAR +STARTCHAR afii10106 +ENCODING 1113 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +70 +90 +9C +92 +92 +92 +9C +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10107 +ENCODING 1114 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +90 +90 +9C +F2 +92 +92 +9C +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10108 +ENCODING 1115 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +40 +F0 +40 +7C +42 +42 +42 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10109 +ENCODING 1116 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +08 +10 +00 +42 +44 +48 +70 +48 +44 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni045D +ENCODING 1117 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +10 +08 +00 +42 +42 +42 +42 +42 +42 +3E +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10110 +ENCODING 1118 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +24 +18 +00 +42 +42 +42 +42 +42 +42 +3E +02 +02 +3C +00 +ENDCHAR +STARTCHAR afii10193 +ENCODING 1119 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +42 +42 +42 +42 +42 +42 +7E +18 +18 +00 +00 +ENDCHAR +STARTCHAR afii10146 +ENCODING 1122 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +40 +F0 +40 +7C +42 +42 +42 +42 +42 +7C +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10194 +ENCODING 1123 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +20 +20 +78 +20 +20 +3C +22 +22 +22 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni046A +ENCODING 1130 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +FE +82 +44 +28 +38 +54 +92 +92 +92 +92 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni046B +ENCODING 1131 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +FE +44 +28 +38 +54 +92 +92 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10050 +ENCODING 1168 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +02 +02 +7E +40 +40 +40 +40 +40 +40 +40 +40 +40 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10098 +ENCODING 1169 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +02 +02 +7E +40 +40 +40 +40 +40 +40 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni0492 +ENCODING 1170 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7E +40 +40 +40 +F8 +40 +40 +40 +40 +40 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni0493 +ENCODING 1171 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +7E +40 +40 +F8 +40 +40 +40 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni0494 +ENCODING 1172 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7E +40 +40 +40 +40 +7C +42 +42 +42 +42 +02 +04 +00 +00 +ENDCHAR +STARTCHAR uni0495 +ENCODING 1173 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +7E +40 +40 +78 +44 +44 +44 +04 +08 +00 +00 +ENDCHAR +STARTCHAR uni0496 +ENCODING 1174 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +92 +92 +92 +54 +38 +54 +92 +92 +92 +93 +01 +01 +00 +00 +ENDCHAR +STARTCHAR uni0497 +ENCODING 1175 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +92 +92 +54 +38 +54 +92 +93 +01 +01 +00 +00 +ENDCHAR +STARTCHAR uni0498 +ENCODING 1176 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +42 +42 +02 +1C +02 +02 +42 +42 +3C +10 +10 +10 +00 +ENDCHAR +STARTCHAR uni0499 +ENCODING 1177 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +3C +42 +02 +1C +02 +42 +3C +10 +10 +10 +00 +ENDCHAR +STARTCHAR uni049A +ENCODING 1178 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +42 +44 +48 +50 +60 +60 +50 +48 +44 +43 +01 +01 +00 +00 +ENDCHAR +STARTCHAR uni049B +ENCODING 1179 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +42 +44 +48 +70 +48 +44 +43 +01 +01 +00 +00 +ENDCHAR +STARTCHAR uni049C +ENCODING 1180 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +42 +42 +54 +58 +70 +70 +58 +54 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni049D +ENCODING 1181 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +42 +54 +58 +70 +58 +54 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04A0 +ENCODING 1184 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +C2 +44 +48 +50 +60 +60 +50 +48 +44 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04A1 +ENCODING 1185 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +C2 +44 +48 +70 +48 +44 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04A2 +ENCODING 1186 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +42 +42 +42 +42 +7E +42 +42 +42 +42 +43 +01 +01 +00 +00 +ENDCHAR +STARTCHAR uni04A3 +ENCODING 1187 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +42 +42 +42 +7E +42 +42 +43 +01 +01 +00 +00 +ENDCHAR +STARTCHAR uni04A4 +ENCODING 1188 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +47 +44 +44 +44 +7C +44 +44 +44 +44 +44 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04A5 +ENCODING 1189 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +47 +44 +44 +7C +44 +44 +44 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04AA +ENCODING 1194 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +42 +42 +40 +40 +40 +40 +42 +42 +3C +10 +10 +10 +00 +ENDCHAR +STARTCHAR uni04AB +ENCODING 1195 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +3C +42 +40 +40 +40 +42 +3C +10 +10 +10 +00 +ENDCHAR +STARTCHAR uni04AE +ENCODING 1198 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +82 +82 +44 +44 +28 +10 +10 +10 +10 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04AF +ENCODING 1199 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +82 +82 +44 +44 +28 +28 +10 +10 +10 +10 +00 +ENDCHAR +STARTCHAR uni04B0 +ENCODING 1200 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +82 +82 +44 +44 +28 +10 +7C +10 +10 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04B1 +ENCODING 1201 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +82 +82 +44 +44 +28 +28 +10 +7C +10 +10 +00 +ENDCHAR +STARTCHAR uni04B2 +ENCODING 1202 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +42 +42 +24 +24 +18 +18 +24 +24 +42 +43 +01 +01 +00 +00 +ENDCHAR +STARTCHAR uni04B3 +ENCODING 1203 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +42 +42 +24 +18 +24 +42 +43 +01 +01 +00 +00 +ENDCHAR +STARTCHAR uni04B6 +ENCODING 1206 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +42 +42 +42 +42 +42 +3E +02 +02 +02 +03 +01 +01 +00 +00 +ENDCHAR +STARTCHAR uni04B7 +ENCODING 1207 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +42 +42 +42 +3E +02 +02 +03 +01 +01 +00 +00 +ENDCHAR +STARTCHAR uni04B8 +ENCODING 1208 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +42 +42 +42 +4A +4A +3E +0A +0A +02 +02 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04B9 +ENCODING 1209 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +42 +4A +4A +3E +0A +02 +02 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04BA +ENCODING 1210 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +40 +40 +40 +40 +7C +42 +42 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04BB +ENCODING 1211 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +40 +40 +7C +42 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04C0 +ENCODING 1216 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +38 +10 +10 +10 +10 +10 +10 +10 +10 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04C1 +ENCODING 1217 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +18 +00 +92 +92 +92 +54 +38 +54 +92 +92 +92 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04C2 +ENCODING 1218 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +24 +18 +00 +92 +92 +54 +38 +54 +92 +92 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04CF +ENCODING 1231 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +30 +10 +10 +10 +10 +10 +10 +10 +10 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04D0 +ENCODING 1232 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +18 +00 +3C +42 +42 +42 +7E +42 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04D1 +ENCODING 1233 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +24 +18 +00 +3C +02 +3E +42 +42 +42 +3E +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04D2 +ENCODING 1234 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +24 +00 +3C +42 +42 +42 +7E +42 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04D3 +ENCODING 1235 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +24 +24 +00 +3C +02 +3E +42 +42 +42 +3E +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04D4 +ENCODING 1236 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7E +90 +90 +90 +FC +90 +90 +90 +90 +9E +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04D5 +ENCODING 1237 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +6C +12 +72 +9E +90 +90 +6C +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04D6 +ENCODING 1238 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +18 +00 +7E +40 +40 +40 +78 +40 +40 +40 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04D7 +ENCODING 1239 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +24 +18 +00 +3C +42 +42 +7E +40 +40 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04D8 +ENCODING 1240 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +42 +02 +02 +7E +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii10846 +ENCODING 1241 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +3C +02 +02 +7E +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04DA +ENCODING 1242 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +24 +00 +3C +42 +02 +02 +7E +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04DB +ENCODING 1243 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +24 +24 +00 +3C +02 +02 +7E +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04DC +ENCODING 1244 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +44 +44 +00 +92 +92 +92 +54 +38 +54 +92 +92 +92 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04DD +ENCODING 1245 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +44 +44 +00 +92 +92 +54 +38 +54 +92 +92 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04DE +ENCODING 1246 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +24 +00 +3C +42 +42 +02 +1C +02 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04DF +ENCODING 1247 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +24 +24 +00 +3C +42 +02 +1C +02 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04E2 +ENCODING 1250 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +3C +00 +42 +42 +42 +46 +4A +52 +62 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04E3 +ENCODING 1251 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +3C +00 +42 +42 +42 +42 +42 +42 +3E +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04E4 +ENCODING 1252 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +24 +00 +42 +42 +42 +46 +4A +52 +62 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04E5 +ENCODING 1253 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +24 +24 +00 +42 +42 +42 +42 +42 +42 +3E +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04E6 +ENCODING 1254 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +24 +00 +3C +42 +42 +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04E7 +ENCODING 1255 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +24 +24 +00 +3C +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04E8 +ENCODING 1256 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +42 +42 +42 +7E +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04E9 +ENCODING 1257 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +3C +42 +42 +7E +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04EA +ENCODING 1258 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +24 +00 +3C +42 +42 +42 +7E +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04EB +ENCODING 1259 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +24 +24 +00 +3C +42 +42 +7E +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04EC +ENCODING 1260 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +24 +00 +3C +42 +02 +02 +1E +02 +02 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04ED +ENCODING 1261 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +24 +24 +00 +3C +42 +02 +1E +02 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04EE +ENCODING 1262 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +3C +00 +42 +42 +42 +42 +42 +3E +02 +02 +02 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04EF +ENCODING 1263 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +3C +00 +42 +42 +42 +42 +42 +42 +3E +02 +02 +3C +00 +ENDCHAR +STARTCHAR uni04F0 +ENCODING 1264 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +24 +00 +42 +42 +42 +42 +3E +02 +02 +02 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04F1 +ENCODING 1265 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +24 +24 +00 +42 +42 +42 +42 +42 +42 +3E +02 +02 +3C +00 +ENDCHAR +STARTCHAR uni04F2 +ENCODING 1266 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +12 +24 +00 +42 +42 +42 +42 +3E +02 +02 +02 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04F3 +ENCODING 1267 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +12 +24 +00 +42 +42 +42 +42 +42 +42 +3E +02 +02 +3C +00 +ENDCHAR +STARTCHAR uni04F4 +ENCODING 1268 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +24 +24 +00 +42 +42 +42 +42 +3E +02 +02 +02 +02 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04F5 +ENCODING 1269 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +24 +24 +00 +42 +42 +42 +3E +02 +02 +02 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04F8 +ENCODING 1272 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +48 +48 +00 +82 +82 +82 +F2 +8A +8A +8A +8A +F2 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni04F9 +ENCODING 1273 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +48 +48 +00 +82 +82 +F2 +8A +8A +8A +F2 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii57664 +ENCODING 1488 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +42 +42 +22 +22 +14 +28 +44 +44 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii57665 +ENCODING 1489 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7C +02 +02 +02 +02 +02 +02 +02 +02 +7F +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii57666 +ENCODING 1490 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +70 +08 +08 +08 +08 +08 +14 +24 +42 +82 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii57667 +ENCODING 1491 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7F +02 +02 +02 +02 +02 +02 +02 +02 +02 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii57668 +ENCODING 1492 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7C +02 +02 +42 +42 +42 +42 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii57669 +ENCODING 1493 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +30 +08 +08 +08 +08 +08 +08 +08 +08 +08 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii57670 +ENCODING 1494 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7C +08 +10 +10 +10 +10 +10 +10 +10 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii57671 +ENCODING 1495 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7C +42 +42 +42 +42 +42 +42 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii57672 +ENCODING 1496 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +4C +42 +42 +42 +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii57673 +ENCODING 1497 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +30 +08 +08 +08 +08 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii57674 +ENCODING 1498 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7C +02 +02 +02 +02 +02 +02 +02 +02 +02 +02 +02 +02 +00 +ENDCHAR +STARTCHAR afii57675 +ENCODING 1499 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7C +02 +02 +02 +02 +02 +02 +02 +02 +7C +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii57676 +ENCODING 1500 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +40 +40 +7E +02 +02 +02 +02 +04 +08 +10 +10 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii57677 +ENCODING 1501 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7C +42 +42 +42 +42 +42 +42 +42 +42 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii57678 +ENCODING 1502 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +DC +62 +42 +42 +42 +42 +42 +42 +42 +4E +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii57679 +ENCODING 1503 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +70 +08 +08 +08 +08 +08 +08 +08 +08 +08 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii57680 +ENCODING 1504 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +38 +04 +04 +04 +04 +04 +04 +04 +04 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii57681 +ENCODING 1505 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +FC +42 +42 +42 +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii57682 +ENCODING 1506 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +42 +42 +42 +22 +22 +22 +14 +14 +18 +60 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii57683 +ENCODING 1507 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +42 +42 +42 +32 +02 +02 +02 +02 +02 +02 +02 +02 +00 +ENDCHAR +STARTCHAR afii57684 +ENCODING 1508 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +42 +42 +42 +32 +02 +02 +02 +02 +7C +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii57685 +ENCODING 1509 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +42 +42 +22 +24 +18 +10 +10 +10 +10 +10 +10 +10 +10 +00 +ENDCHAR +STARTCHAR afii57686 +ENCODING 1510 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +42 +42 +22 +24 +18 +10 +08 +08 +04 +7C +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii57687 +ENCODING 1511 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7E +02 +02 +42 +42 +44 +48 +48 +48 +48 +40 +40 +40 +00 +ENDCHAR +STARTCHAR afii57688 +ENCODING 1512 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7C +02 +02 +02 +02 +02 +02 +02 +02 +02 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii57689 +ENCODING 1513 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +92 +92 +92 +92 +92 +A2 +C2 +82 +84 +F8 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii57690 +ENCODING 1514 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +FC +42 +42 +42 +42 +42 +42 +42 +42 +82 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni1E0C +ENCODING 7692 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +78 +44 +42 +42 +42 +42 +42 +42 +44 +78 +00 +10 +10 +00 +ENDCHAR +STARTCHAR uni1E0D +ENCODING 7693 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +02 +02 +02 +3E +42 +42 +42 +42 +42 +3E +00 +08 +08 +00 +ENDCHAR +STARTCHAR Klinebelow +ENCODING 7732 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +42 +44 +48 +50 +60 +60 +50 +48 +44 +42 +00 +3C +00 +00 +ENDCHAR +STARTCHAR klinebelow +ENCODING 7733 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +40 +40 +40 +42 +44 +48 +70 +48 +44 +42 +00 +3C +00 +00 +ENDCHAR +STARTCHAR uni1E36 +ENCODING 7734 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +40 +40 +40 +40 +40 +40 +40 +40 +40 +7E +00 +10 +10 +00 +ENDCHAR +STARTCHAR uni1E37 +ENCODING 7735 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +30 +10 +10 +10 +10 +10 +10 +10 +10 +38 +00 +10 +10 +00 +ENDCHAR +STARTCHAR uni1E40 +ENCODING 7744 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +82 +C6 +AA +92 +92 +82 +82 +82 +82 +82 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni1E41 +ENCODING 7745 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +10 +10 +00 +FC +92 +92 +92 +92 +92 +92 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni1E42 +ENCODING 7746 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +82 +C6 +AA +92 +92 +82 +82 +82 +82 +82 +00 +10 +10 +00 +ENDCHAR +STARTCHAR uni1E43 +ENCODING 7747 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +FC +92 +92 +92 +92 +92 +92 +00 +10 +10 +00 +ENDCHAR +STARTCHAR uni1E44 +ENCODING 7748 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +42 +42 +42 +62 +52 +4A +46 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni1E45 +ENCODING 7749 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +10 +10 +00 +7C +42 +42 +42 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni1E46 +ENCODING 7750 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +42 +42 +42 +62 +52 +4A +46 +42 +42 +42 +00 +10 +10 +00 +ENDCHAR +STARTCHAR uni1E47 +ENCODING 7751 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +7C +42 +42 +42 +42 +42 +42 +00 +10 +10 +00 +ENDCHAR +STARTCHAR uni1E6C +ENCODING 7788 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +FE +10 +10 +10 +10 +10 +10 +10 +10 +10 +00 +10 +10 +00 +ENDCHAR +STARTCHAR uni1E6D +ENCODING 7789 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +10 +10 +10 +7C +10 +10 +10 +10 +10 +0E +00 +04 +04 +00 +ENDCHAR +STARTCHAR Edotbelow +ENCODING 7864 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7E +40 +40 +40 +78 +40 +40 +40 +40 +7E +00 +10 +10 +00 +ENDCHAR +STARTCHAR edotbelow +ENCODING 7865 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +3C +42 +42 +7E +40 +40 +3C +00 +10 +10 +00 +ENDCHAR +STARTCHAR Etilde +ENCODING 7868 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +32 +4C +00 +7E +40 +40 +40 +78 +40 +40 +40 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR etilde +ENCODING 7869 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +32 +4C +00 +3C +42 +42 +7E +40 +40 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni1ECA +ENCODING 7882 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +38 +10 +10 +10 +10 +10 +10 +10 +10 +38 +00 +10 +10 +00 +ENDCHAR +STARTCHAR uni1ECB +ENCODING 7883 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +10 +10 +00 +30 +10 +10 +10 +10 +10 +38 +00 +10 +10 +00 +ENDCHAR +STARTCHAR Odotbelow +ENCODING 7884 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +42 +42 +42 +42 +42 +42 +42 +42 +3C +00 +10 +10 +00 +ENDCHAR +STARTCHAR odotbelow +ENCODING 7885 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +3C +42 +42 +42 +42 +42 +3C +00 +10 +10 +00 +ENDCHAR +STARTCHAR uni1EE4 +ENCODING 7908 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +42 +42 +42 +42 +42 +42 +42 +42 +42 +3C +00 +10 +10 +00 +ENDCHAR +STARTCHAR uni1EE5 +ENCODING 7909 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +42 +42 +42 +42 +42 +42 +3E +00 +08 +08 +00 +ENDCHAR +STARTCHAR Ytilde +ENCODING 7928 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +64 +98 +00 +82 +82 +44 +44 +28 +10 +10 +10 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR ytilde +ENCODING 7929 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +32 +4C +00 +42 +42 +42 +42 +42 +42 +3E +02 +02 +3C +00 +ENDCHAR +STARTCHAR uni2000 +ENCODING 8192 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2001 +ENCODING 8193 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR enspace +ENCODING 8194 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2003 +ENCODING 8195 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2004 +ENCODING 8196 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2005 +ENCODING 8197 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2006 +ENCODING 8198 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2007 +ENCODING 8199 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2008 +ENCODING 8200 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2009 +ENCODING 8201 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni200A +ENCODING 8202 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni200B +ENCODING 8203 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii61664 +ENCODING 8204 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii301 +ENCODING 8205 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii299 +ENCODING 8206 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii300 +ENCODING 8207 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR hyphentwo +ENCODING 8208 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +3C +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2011 +ENCODING 8209 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +3C +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR figuredash +ENCODING 8210 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +7E +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR endash +ENCODING 8211 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +7E +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR emdash +ENCODING 8212 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +FE +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii00208 +ENCODING 8213 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +FE +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR dblverticalbar +ENCODING 8214 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +28 +28 +28 +28 +28 +28 +28 +28 +28 +28 +00 +00 +00 +00 +ENDCHAR +STARTCHAR underscoredbl +ENCODING 8215 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +7E +00 +7E +ENDCHAR +STARTCHAR quoteleft +ENCODING 8216 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +08 +10 +10 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR quoteright +ENCODING 8217 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +08 +08 +10 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR quotesinglbase +ENCODING 8218 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +08 +08 +10 +00 +00 +00 +ENDCHAR +STARTCHAR quotereversed +ENCODING 8219 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +10 +10 +08 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR quotedblleft +ENCODING 8220 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +12 +24 +24 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR quotedblright +ENCODING 8221 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +12 +12 +24 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR quotedblbase +ENCODING 8222 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +24 +24 +48 +00 +00 +00 +ENDCHAR +STARTCHAR uni201F +ENCODING 8223 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +48 +48 +24 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR dagger +ENCODING 8224 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +10 +10 +7C +10 +10 +10 +10 +10 +10 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR daggerdbl +ENCODING 8225 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +10 +10 +7C +10 +10 +10 +10 +7C +10 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR bullet +ENCODING 8226 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +18 +3C +3C +18 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR ellipsis +ENCODING 8230 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +92 +92 +00 +00 +00 +00 +ENDCHAR +STARTCHAR perthousand +ENCODING 8240 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +48 +A8 +50 +10 +20 +20 +40 +54 +AA +94 +00 +00 +00 +00 +ENDCHAR +STARTCHAR minute +ENCODING 8242 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +10 +10 +10 +10 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR second +ENCODING 8243 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +24 +24 +24 +24 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR guilsinglleft +ENCODING 8249 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +04 +08 +10 +20 +10 +08 +04 +00 +00 +00 +00 +ENDCHAR +STARTCHAR guilsinglright +ENCODING 8250 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +20 +10 +08 +04 +08 +10 +20 +00 +00 +00 +00 +ENDCHAR +STARTCHAR exclamdbl +ENCODING 8252 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +24 +24 +24 +24 +24 +24 +24 +00 +24 +24 +00 +00 +00 +00 +ENDCHAR +STARTCHAR overline +ENCODING 8254 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +7E +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2070 +ENCODING 8304 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +18 +24 +24 +24 +24 +18 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2071 +ENCODING 8305 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +00 +30 +10 +10 +10 +38 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2074 +ENCODING 8308 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +0C +14 +3E +04 +04 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2075 +ENCODING 8309 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +38 +20 +38 +04 +04 +38 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2076 +ENCODING 8310 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +18 +20 +38 +24 +24 +18 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2077 +ENCODING 8311 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +3C +04 +08 +08 +10 +10 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2078 +ENCODING 8312 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +18 +24 +18 +24 +24 +18 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2079 +ENCODING 8313 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +18 +24 +24 +1C +04 +18 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni207A +ENCODING 8314 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +10 +10 +7C +10 +10 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni207B +ENCODING 8315 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +7C +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni207C +ENCODING 8316 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +7C +00 +7C +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni207D +ENCODING 8317 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +08 +10 +10 +10 +10 +08 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni207E +ENCODING 8318 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +10 +08 +08 +08 +08 +10 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR nsuperior +ENCODING 8319 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +38 +24 +24 +24 +24 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2080 +ENCODING 8320 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +18 +24 +24 +24 +24 +18 +00 +00 +00 +ENDCHAR +STARTCHAR uni2081 +ENCODING 8321 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +10 +30 +10 +10 +10 +38 +00 +00 +00 +ENDCHAR +STARTCHAR uni2082 +ENCODING 8322 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +18 +24 +04 +08 +10 +3C +00 +00 +00 +ENDCHAR +STARTCHAR uni2083 +ENCODING 8323 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +38 +04 +18 +04 +04 +38 +00 +00 +00 +ENDCHAR +STARTCHAR uni2084 +ENCODING 8324 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +04 +0C +14 +3E +04 +04 +00 +00 +00 +ENDCHAR +STARTCHAR uni2085 +ENCODING 8325 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +38 +20 +38 +04 +04 +38 +00 +00 +00 +ENDCHAR +STARTCHAR uni2086 +ENCODING 8326 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +18 +20 +38 +24 +24 +18 +00 +00 +00 +ENDCHAR +STARTCHAR uni2087 +ENCODING 8327 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +3C +04 +08 +08 +10 +10 +00 +00 +00 +ENDCHAR +STARTCHAR uni2088 +ENCODING 8328 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +18 +24 +18 +24 +24 +18 +00 +00 +00 +ENDCHAR +STARTCHAR uni2089 +ENCODING 8329 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +18 +24 +24 +1C +04 +18 +00 +00 +00 +ENDCHAR +STARTCHAR uni208A +ENCODING 8330 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +10 +10 +7C +10 +10 +00 +00 +00 +ENDCHAR +STARTCHAR uni208B +ENCODING 8331 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +7C +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni208C +ENCODING 8332 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +7C +00 +7C +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni208D +ENCODING 8333 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +08 +10 +10 +10 +10 +08 +00 +00 +00 +ENDCHAR +STARTCHAR uni208E +ENCODING 8334 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +10 +08 +08 +08 +08 +10 +00 +00 +00 +ENDCHAR +STARTCHAR uni2090 +ENCODING 8336 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +18 +04 +1C +24 +1C +00 +00 +00 +ENDCHAR +STARTCHAR uni2091 +ENCODING 8337 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +18 +24 +3C +20 +1C +00 +00 +00 +ENDCHAR +STARTCHAR uni2092 +ENCODING 8338 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +18 +24 +24 +24 +18 +00 +00 +00 +ENDCHAR +STARTCHAR uni2093 +ENCODING 8339 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +44 +28 +10 +28 +44 +00 +00 +00 +ENDCHAR +STARTCHAR uni2094 +ENCODING 8340 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +38 +04 +3C +24 +18 +00 +00 +00 +ENDCHAR +STARTCHAR uni2095 +ENCODING 8341 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +20 +20 +38 +24 +24 +24 +24 +00 +00 +00 +ENDCHAR +STARTCHAR uni2096 +ENCODING 8342 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +20 +20 +24 +28 +30 +28 +24 +00 +00 +00 +ENDCHAR +STARTCHAR uni2097 +ENCODING 8343 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +30 +10 +10 +10 +10 +10 +38 +00 +00 +00 +ENDCHAR +STARTCHAR uni2098 +ENCODING 8344 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +78 +54 +54 +54 +54 +00 +00 +00 +ENDCHAR +STARTCHAR uni209A +ENCODING 8346 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +38 +24 +24 +24 +38 +20 +20 +00 +ENDCHAR +STARTCHAR peseta +ENCODING 8359 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +F0 +88 +88 +88 +F4 +84 +8E +84 +84 +82 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii57636 +ENCODING 8362 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +F2 +8A +8A +AA +AA +AA +AA +A2 +A2 +BC +00 +00 +00 +00 +ENDCHAR +STARTCHAR Euro +ENCODING 8364 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +1C +22 +40 +F8 +40 +F8 +40 +22 +1C +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni20AE +ENCODING 8366 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +FE +10 +10 +1C +70 +1C +70 +10 +10 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2102 +ENCODING 8450 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +52 +52 +50 +50 +50 +50 +52 +52 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni210E +ENCODING 8462 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +40 +40 +40 +7C +42 +42 +42 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni210F +ENCODING 8463 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +40 +F0 +40 +7C +42 +42 +42 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2115 +ENCODING 8469 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +42 +42 +62 +52 +6A +56 +4A +46 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR afii61352 +ENCODING 8470 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +96 +96 +96 +D0 +F0 +F0 +B0 +96 +90 +96 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni211A +ENCODING 8474 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +52 +52 +52 +52 +52 +52 +52 +5A +3C +06 +00 +00 +00 +ENDCHAR +STARTCHAR uni211D +ENCODING 8477 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +F8 +A4 +A4 +A4 +A4 +B8 +A8 +B4 +AA +E6 +00 +00 +00 +00 +ENDCHAR +STARTCHAR trademark +ENCODING 8482 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +FB +55 +55 +51 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2124 +ENCODING 8484 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7E +02 +06 +0A +14 +28 +50 +60 +40 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR Ohm +ENCODING 8486 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +42 +42 +42 +42 +42 +42 +24 +24 +66 +00 +00 +00 +00 +ENDCHAR +STARTCHAR aleph +ENCODING 8501 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +44 +44 +22 +22 +34 +58 +88 +88 +84 +44 +00 +00 +00 +00 +ENDCHAR +STARTCHAR arrowleft +ENCODING 8592 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +20 +40 +FE +40 +20 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR arrowup +ENCODING 8593 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +10 +38 +54 +10 +10 +10 +10 +10 +10 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR arrowright +ENCODING 8594 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +08 +04 +FE +04 +08 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR arrowdown +ENCODING 8595 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +10 +10 +10 +10 +10 +10 +10 +54 +38 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR arrowboth +ENCODING 8596 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +24 +42 +FF +42 +24 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR arrowupdn +ENCODING 8597 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +10 +38 +54 +10 +10 +10 +10 +54 +38 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni21A4 +ENCODING 8612 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +22 +42 +FE +42 +22 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni21A6 +ENCODING 8614 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +88 +84 +FE +84 +88 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR arrowupdnbse +ENCODING 8616 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +10 +38 +54 +10 +10 +10 +54 +38 +10 +7C +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni21B2 +ENCODING 8626 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +02 +02 +02 +02 +02 +22 +42 +FE +40 +20 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni21B3 +ENCODING 8627 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +80 +80 +80 +80 +80 +88 +84 +FE +04 +08 +00 +00 +00 +00 +ENDCHAR +STARTCHAR carriagereturn +ENCODING 8629 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +02 +02 +02 +22 +42 +FE +40 +20 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni21BB +ENCODING 8635 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +F0 +30 +50 +92 +82 +82 +44 +38 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni21CB +ENCODING 8651 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +20 +40 +FE +00 +FE +04 +08 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni21CC +ENCODING 8652 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +08 +04 +FE +00 +FE +40 +20 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR arrowdblleft +ENCODING 8656 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +20 +7E +C0 +7E +20 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR arrowdblup +ENCODING 8657 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +10 +38 +6C +28 +28 +28 +28 +28 +28 +28 +00 +00 +00 +00 +ENDCHAR +STARTCHAR arrowdblright +ENCODING 8658 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +08 +FC +06 +FC +08 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR arrowdbldown +ENCODING 8659 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +28 +28 +28 +28 +28 +28 +28 +6C +38 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR arrowdblboth +ENCODING 8660 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +24 +7E +C3 +7E +24 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni21D5 +ENCODING 8661 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +10 +38 +6C +28 +28 +28 +28 +6C +38 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR universal +ENCODING 8704 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +82 +82 +82 +7C +44 +44 +28 +28 +10 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR existential +ENCODING 8707 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +7E +02 +02 +02 +7E +02 +02 +02 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2204 +ENCODING 8708 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +04 +7E +0A +0A +12 +7E +12 +22 +22 +7E +40 +00 +00 +00 +ENDCHAR +STARTCHAR emptyset +ENCODING 8709 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +02 +04 +7C +8A +92 +92 +A2 +7C +40 +80 +00 +00 +00 +00 +ENDCHAR +STARTCHAR increment +ENCODING 8710 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +10 +10 +28 +28 +44 +44 +44 +82 +82 +FE +00 +00 +00 +00 +ENDCHAR +STARTCHAR gradient +ENCODING 8711 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +FE +82 +82 +44 +44 +44 +28 +28 +10 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR element +ENCODING 8712 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +1E +20 +40 +40 +7E +40 +40 +20 +1E +00 +00 +00 +00 +ENDCHAR +STARTCHAR notelement +ENCODING 8713 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +02 +1E +24 +44 +48 +7E +48 +50 +30 +3E +20 +00 +00 +00 +ENDCHAR +STARTCHAR uni220A +ENCODING 8714 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +1E +20 +40 +7E +40 +20 +1E +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR suchthat +ENCODING 8715 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +78 +04 +02 +02 +7E +02 +02 +04 +78 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni220C +ENCODING 8716 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +40 +78 +24 +22 +12 +7E +12 +0A +0C +7C +04 +00 +00 +00 +ENDCHAR +STARTCHAR uni220D +ENCODING 8717 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +78 +04 +02 +7E +02 +04 +78 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR minus +ENCODING 8722 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +7E +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2213 +ENCODING 8723 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +7C +00 +10 +10 +7C +10 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2214 +ENCODING 8724 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +10 +10 +00 +10 +10 +7C +10 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2215 +ENCODING 8725 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +02 +04 +08 +10 +20 +40 +80 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2216 +ENCODING 8726 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +80 +40 +20 +10 +08 +04 +02 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR bulletoperator +ENCODING 8729 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +18 +18 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR radical +ENCODING 8730 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +06 +04 +04 +04 +04 +44 +44 +44 +24 +14 +0C +00 +00 +00 +00 +ENDCHAR +STARTCHAR infinity +ENCODING 8734 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +7C +92 +92 +92 +7C +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR orthogonal +ENCODING 8735 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +40 +40 +40 +40 +40 +7E +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2225 +ENCODING 8741 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +28 +28 +28 +28 +28 +28 +28 +28 +28 +28 +00 +00 +00 +00 +ENDCHAR +STARTCHAR logicaland +ENCODING 8743 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +10 +10 +28 +28 +44 +44 +82 +82 +00 +00 +00 +00 +ENDCHAR +STARTCHAR logicalor +ENCODING 8744 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +82 +82 +44 +44 +28 +28 +10 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR intersection +ENCODING 8745 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +3C +42 +42 +42 +42 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR union +ENCODING 8746 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +42 +42 +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR approxequal +ENCODING 8776 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +32 +4C +00 +32 +4C +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR notequal +ENCODING 8800 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +02 +7E +08 +10 +7E +40 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR equivalence +ENCODING 8801 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +7E +00 +00 +7E +00 +00 +7E +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR lessequal +ENCODING 8804 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +04 +08 +10 +20 +10 +08 +04 +00 +3E +00 +00 +00 +00 +ENDCHAR +STARTCHAR greaterequal +ENCODING 8805 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +20 +10 +08 +04 +08 +10 +20 +00 +7C +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni226A +ENCODING 8810 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +09 +12 +24 +48 +90 +48 +24 +12 +09 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni226B +ENCODING 8811 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +90 +48 +24 +12 +09 +12 +24 +48 +90 +00 +00 +00 +00 +ENDCHAR +STARTCHAR propersubset +ENCODING 8834 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +3E +40 +40 +40 +40 +40 +3E +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR propersuperset +ENCODING 8835 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +7C +02 +02 +02 +02 +02 +7C +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR reflexsubset +ENCODING 8838 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +3E +40 +40 +40 +40 +40 +3E +00 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR reflexsuperset +ENCODING 8839 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +7C +02 +02 +02 +02 +02 +7C +00 +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR perpendicular +ENCODING 8869 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +10 +10 +10 +10 +10 +10 +10 +FE +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni22C2 +ENCODING 8898 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3C +42 +42 +42 +42 +42 +42 +42 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni22C3 +ENCODING 8899 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +42 +42 +42 +42 +42 +42 +42 +42 +42 +3C +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2300 +ENCODING 8960 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +02 +04 +7C +8A +92 +92 +A2 +7C +40 +80 +00 +00 +00 +00 +ENDCHAR +STARTCHAR house +ENCODING 8962 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +10 +28 +44 +82 +82 +82 +82 +FE +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2308 +ENCODING 8968 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +38 +20 +20 +20 +20 +20 +20 +20 +20 +20 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2309 +ENCODING 8969 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +38 +08 +08 +08 +08 +08 +08 +08 +08 +08 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni230A +ENCODING 8970 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +20 +20 +20 +20 +20 +20 +20 +20 +20 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni230B +ENCODING 8971 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +08 +08 +08 +08 +08 +08 +08 +08 +08 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR revlogicalnot +ENCODING 8976 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +7E +40 +40 +40 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2319 +ENCODING 8985 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +40 +40 +40 +7E +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR integraltp +ENCODING 8992 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +0C +12 +12 +10 +10 +10 +10 +10 +10 +10 +10 +10 +10 +10 +ENDCHAR +STARTCHAR integralbt +ENCODING 8993 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +10 +10 +10 +10 +10 +10 +10 +90 +90 +60 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni239B +ENCODING 9115 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +04 +08 +10 +10 +20 +20 +20 +40 +40 +40 +40 +40 +40 +40 +40 +40 +ENDCHAR +STARTCHAR uni239C +ENCODING 9116 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +40 +40 +40 +40 +40 +40 +40 +40 +40 +40 +40 +40 +40 +40 +40 +40 +ENDCHAR +STARTCHAR uni239D +ENCODING 9117 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +40 +40 +40 +40 +40 +40 +40 +40 +40 +20 +20 +20 +10 +10 +08 +04 +ENDCHAR +STARTCHAR uni239E +ENCODING 9118 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +40 +20 +10 +10 +08 +08 +08 +04 +04 +04 +04 +04 +04 +04 +04 +04 +ENDCHAR +STARTCHAR uni239F +ENCODING 9119 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +04 +04 +04 +04 +04 +04 +04 +04 +04 +04 +04 +04 +04 +04 +04 +04 +ENDCHAR +STARTCHAR uni23A0 +ENCODING 9120 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +04 +04 +04 +04 +04 +04 +04 +04 +04 +08 +08 +08 +10 +10 +20 +40 +ENDCHAR +STARTCHAR uni23A1 +ENCODING 9121 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +7C +40 +40 +40 +40 +40 +40 +40 +40 +40 +40 +40 +40 +40 +40 +40 +ENDCHAR +STARTCHAR uni23A2 +ENCODING 9122 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +40 +40 +40 +40 +40 +40 +40 +40 +40 +40 +40 +40 +40 +40 +40 +40 +ENDCHAR +STARTCHAR uni23A3 +ENCODING 9123 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +40 +40 +40 +40 +40 +40 +40 +40 +40 +40 +40 +40 +40 +40 +40 +7C +ENDCHAR +STARTCHAR uni23A4 +ENCODING 9124 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +7C +04 +04 +04 +04 +04 +04 +04 +04 +04 +04 +04 +04 +04 +04 +04 +ENDCHAR +STARTCHAR uni23A5 +ENCODING 9125 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +04 +04 +04 +04 +04 +04 +04 +04 +04 +04 +04 +04 +04 +04 +04 +04 +ENDCHAR +STARTCHAR uni23A6 +ENCODING 9126 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +04 +04 +04 +04 +04 +04 +04 +04 +04 +04 +04 +04 +04 +04 +04 +7C +ENDCHAR +STARTCHAR uni23A7 +ENCODING 9127 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +0E +10 +20 +20 +20 +20 +20 +20 +20 +20 +20 +20 +20 +20 +20 +20 +ENDCHAR +STARTCHAR uni23A8 +ENCODING 9128 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +20 +20 +20 +20 +20 +20 +20 +C0 +C0 +20 +20 +20 +20 +20 +20 +20 +ENDCHAR +STARTCHAR uni23A9 +ENCODING 9129 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +20 +20 +20 +20 +20 +20 +20 +20 +20 +20 +20 +20 +20 +20 +10 +0E +ENDCHAR +STARTCHAR uni23AB +ENCODING 9131 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +E0 +10 +08 +08 +08 +08 +08 +08 +08 +08 +08 +08 +08 +08 +08 +08 +ENDCHAR +STARTCHAR uni23AC +ENCODING 9132 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +08 +08 +08 +08 +08 +08 +08 +06 +06 +08 +08 +08 +08 +08 +08 +08 +ENDCHAR +STARTCHAR uni23AD +ENCODING 9133 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +08 +08 +08 +08 +08 +08 +08 +08 +08 +08 +08 +08 +08 +08 +10 +E0 +ENDCHAR +STARTCHAR uni23AE +ENCODING 9134 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +10 +10 +10 +10 +10 +10 +10 +10 +10 +10 +10 +10 +10 +10 +ENDCHAR +STARTCHAR uni23AF +ENCODING 9135 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +FF +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni23BA +ENCODING 9146 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +FF +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni23BB +ENCODING 9147 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +FF +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni23BC +ENCODING 9148 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +FF +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni23BD +ENCODING 9149 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +FF +ENDCHAR +STARTCHAR uni23D0 +ENCODING 9168 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +10 +10 +10 +10 +10 +10 +10 +10 +10 +10 +10 +10 +10 +10 +ENDCHAR +STARTCHAR uni2409 +ENCODING 9225 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +88 +88 +F8 +88 +88 +88 +00 +1F +04 +04 +04 +04 +04 +00 +00 +ENDCHAR +STARTCHAR uni240A +ENCODING 9226 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +80 +80 +80 +80 +80 +F8 +00 +1F +10 +1C +10 +10 +10 +00 +00 +ENDCHAR +STARTCHAR uni240B +ENCODING 9227 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +88 +88 +50 +50 +20 +20 +00 +1F +04 +04 +04 +04 +04 +00 +00 +ENDCHAR +STARTCHAR uni240C +ENCODING 9228 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +F8 +80 +E0 +80 +80 +80 +00 +1F +10 +1C +10 +10 +10 +00 +00 +ENDCHAR +STARTCHAR uni240D +ENCODING 9229 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +70 +88 +80 +80 +88 +70 +00 +1E +11 +11 +1E +12 +11 +00 +00 +ENDCHAR +STARTCHAR uni2424 +ENCODING 9252 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +88 +C8 +A8 +98 +88 +88 +00 +10 +10 +10 +10 +10 +1F +00 +00 +ENDCHAR +STARTCHAR SF100000 +ENCODING 9472 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +FF +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2501 +ENCODING 9473 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +FF +FF +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR SF110000 +ENCODING 9474 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +10 +10 +10 +10 +10 +10 +10 +10 +10 +10 +10 +10 +10 +10 +ENDCHAR +STARTCHAR uni2503 +ENCODING 9475 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +18 +ENDCHAR +STARTCHAR uni2508 +ENCODING 9480 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +AA +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2509 +ENCODING 9481 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +AA +AA +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni250A +ENCODING 9482 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +10 +00 +10 +10 +10 +00 +10 +10 +10 +00 +10 +10 +10 +00 +ENDCHAR +STARTCHAR uni250B +ENCODING 9483 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +18 +18 +18 +00 +18 +18 +18 +00 +18 +18 +18 +00 +18 +18 +18 +00 +ENDCHAR +STARTCHAR SF010000 +ENCODING 9484 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +1F +10 +10 +10 +10 +10 +10 +10 +10 +ENDCHAR +STARTCHAR uni250D +ENCODING 9485 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +1F +1F +10 +10 +10 +10 +10 +10 +10 +ENDCHAR +STARTCHAR uni250E +ENCODING 9486 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +1F +18 +18 +18 +18 +18 +18 +18 +18 +ENDCHAR +STARTCHAR uni250F +ENCODING 9487 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +1F +1F +18 +18 +18 +18 +18 +18 +18 +ENDCHAR +STARTCHAR SF030000 +ENCODING 9488 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +F0 +10 +10 +10 +10 +10 +10 +10 +10 +ENDCHAR +STARTCHAR uni2511 +ENCODING 9489 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +F0 +F0 +10 +10 +10 +10 +10 +10 +10 +ENDCHAR +STARTCHAR uni2512 +ENCODING 9490 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +F8 +18 +18 +18 +18 +18 +18 +18 +18 +ENDCHAR +STARTCHAR uni2513 +ENCODING 9491 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +F8 +F8 +18 +18 +18 +18 +18 +18 +18 +ENDCHAR +STARTCHAR SF020000 +ENCODING 9492 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +10 +10 +10 +10 +10 +1F +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2515 +ENCODING 9493 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +10 +10 +10 +10 +10 +1F +1F +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2516 +ENCODING 9494 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +18 +18 +18 +18 +18 +18 +18 +1F +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2517 +ENCODING 9495 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +18 +18 +18 +18 +18 +18 +18 +1F +1F +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR SF040000 +ENCODING 9496 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +10 +10 +10 +10 +10 +F0 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2519 +ENCODING 9497 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +10 +10 +10 +10 +10 +F0 +F0 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni251A +ENCODING 9498 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +18 +18 +18 +18 +18 +18 +18 +F8 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni251B +ENCODING 9499 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +18 +18 +18 +18 +18 +18 +18 +F8 +F8 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR SF080000 +ENCODING 9500 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +10 +10 +10 +10 +10 +1F +10 +10 +10 +10 +10 +10 +10 +10 +ENDCHAR +STARTCHAR uni251D +ENCODING 9501 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +10 +10 +10 +10 +10 +1F +1F +10 +10 +10 +10 +10 +10 +10 +ENDCHAR +STARTCHAR uni251E +ENCODING 9502 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +18 +18 +18 +18 +18 +18 +18 +1F +10 +10 +10 +10 +10 +10 +10 +10 +ENDCHAR +STARTCHAR uni251F +ENCODING 9503 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +10 +10 +10 +10 +10 +1F +18 +18 +18 +18 +18 +18 +18 +18 +ENDCHAR +STARTCHAR uni2520 +ENCODING 9504 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +18 +18 +18 +18 +18 +18 +18 +1F +18 +18 +18 +18 +18 +18 +18 +18 +ENDCHAR +STARTCHAR uni2521 +ENCODING 9505 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +18 +18 +18 +18 +18 +18 +18 +1F +1F +10 +10 +10 +10 +10 +10 +10 +ENDCHAR +STARTCHAR uni2522 +ENCODING 9506 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +10 +10 +10 +10 +10 +1F +1F +18 +18 +18 +18 +18 +18 +18 +ENDCHAR +STARTCHAR uni2523 +ENCODING 9507 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +18 +18 +18 +18 +18 +18 +18 +1F +1F +18 +18 +18 +18 +18 +18 +18 +ENDCHAR +STARTCHAR SF090000 +ENCODING 9508 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +10 +10 +10 +10 +10 +F0 +10 +10 +10 +10 +10 +10 +10 +10 +ENDCHAR +STARTCHAR uni2525 +ENCODING 9509 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +10 +10 +10 +10 +10 +F0 +F0 +10 +10 +10 +10 +10 +10 +10 +ENDCHAR +STARTCHAR uni2526 +ENCODING 9510 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +18 +18 +18 +18 +18 +18 +18 +F8 +10 +10 +10 +10 +10 +10 +10 +10 +ENDCHAR +STARTCHAR uni2527 +ENCODING 9511 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +10 +10 +10 +10 +10 +F8 +18 +18 +18 +18 +18 +18 +18 +18 +ENDCHAR +STARTCHAR uni2528 +ENCODING 9512 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +18 +18 +18 +18 +18 +18 +18 +F8 +18 +18 +18 +18 +18 +18 +18 +18 +ENDCHAR +STARTCHAR uni2529 +ENCODING 9513 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +18 +18 +18 +18 +18 +18 +18 +F8 +F8 +10 +10 +10 +10 +10 +10 +10 +ENDCHAR +STARTCHAR uni252A +ENCODING 9514 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +10 +10 +10 +10 +10 +F8 +F8 +18 +18 +18 +18 +18 +18 +18 +ENDCHAR +STARTCHAR uni252B +ENCODING 9515 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +18 +18 +18 +18 +18 +18 +18 +F8 +F8 +18 +18 +18 +18 +18 +18 +18 +ENDCHAR +STARTCHAR SF060000 +ENCODING 9516 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +FF +10 +10 +10 +10 +10 +10 +10 +10 +ENDCHAR +STARTCHAR uni252D +ENCODING 9517 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +FF +F0 +10 +10 +10 +10 +10 +10 +10 +ENDCHAR +STARTCHAR uni252E +ENCODING 9518 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +FF +1F +10 +10 +10 +10 +10 +10 +10 +ENDCHAR +STARTCHAR uni252F +ENCODING 9519 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +FF +FF +10 +10 +10 +10 +10 +10 +10 +ENDCHAR +STARTCHAR uni2530 +ENCODING 9520 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +FF +18 +18 +18 +18 +18 +18 +18 +18 +ENDCHAR +STARTCHAR uni2531 +ENCODING 9521 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +FF +F8 +18 +18 +18 +18 +18 +18 +18 +ENDCHAR +STARTCHAR uni2532 +ENCODING 9522 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +FF +1F +18 +18 +18 +18 +18 +18 +18 +ENDCHAR +STARTCHAR uni2533 +ENCODING 9523 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +FF +FF +18 +18 +18 +18 +18 +18 +18 +ENDCHAR +STARTCHAR SF070000 +ENCODING 9524 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +10 +10 +10 +10 +10 +FF +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2535 +ENCODING 9525 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +10 +10 +10 +10 +10 +FF +F0 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2536 +ENCODING 9526 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +10 +10 +10 +10 +10 +FF +1F +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2537 +ENCODING 9527 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +10 +10 +10 +10 +10 +FF +FF +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2538 +ENCODING 9528 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +18 +18 +18 +18 +18 +18 +18 +FF +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2539 +ENCODING 9529 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +18 +18 +18 +18 +18 +18 +18 +FF +F8 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni253A +ENCODING 9530 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +18 +18 +18 +18 +18 +18 +18 +FF +1F +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni253B +ENCODING 9531 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +18 +18 +18 +18 +18 +18 +18 +FF +FF +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR SF050000 +ENCODING 9532 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +10 +10 +10 +10 +10 +FF +10 +10 +10 +10 +10 +10 +10 +10 +ENDCHAR +STARTCHAR uni253D +ENCODING 9533 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +10 +10 +10 +10 +10 +FF +F0 +10 +10 +10 +10 +10 +10 +10 +ENDCHAR +STARTCHAR uni253E +ENCODING 9534 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +10 +10 +10 +10 +10 +FF +1F +10 +10 +10 +10 +10 +10 +10 +ENDCHAR +STARTCHAR uni253F +ENCODING 9535 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +10 +10 +10 +10 +10 +FF +FF +10 +10 +10 +10 +10 +10 +10 +ENDCHAR +STARTCHAR uni2540 +ENCODING 9536 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +18 +18 +18 +18 +18 +18 +18 +FF +10 +10 +10 +10 +10 +10 +10 +10 +ENDCHAR +STARTCHAR uni2541 +ENCODING 9537 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +10 +10 +10 +10 +10 +FF +18 +18 +18 +18 +18 +18 +18 +18 +ENDCHAR +STARTCHAR uni2542 +ENCODING 9538 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +18 +18 +18 +18 +18 +18 +18 +FF +18 +18 +18 +18 +18 +18 +18 +18 +ENDCHAR +STARTCHAR uni2543 +ENCODING 9539 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +18 +18 +18 +18 +18 +18 +18 +FF +F0 +10 +10 +10 +10 +10 +10 +10 +ENDCHAR +STARTCHAR uni2544 +ENCODING 9540 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +18 +18 +18 +18 +18 +18 +18 +FF +1F +10 +10 +10 +10 +10 +10 +10 +ENDCHAR +STARTCHAR uni2545 +ENCODING 9541 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +10 +10 +10 +10 +10 +FF +F8 +18 +18 +18 +18 +18 +18 +18 +ENDCHAR +STARTCHAR uni2546 +ENCODING 9542 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +10 +10 +10 +10 +10 +FF +1F +18 +18 +18 +18 +18 +18 +18 +ENDCHAR +STARTCHAR uni2547 +ENCODING 9543 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +18 +18 +18 +18 +18 +18 +18 +FF +FF +10 +10 +10 +10 +10 +10 +10 +ENDCHAR +STARTCHAR uni2548 +ENCODING 9544 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +10 +10 +10 +10 +10 +FF +FF +18 +18 +18 +18 +18 +18 +18 +ENDCHAR +STARTCHAR uni2549 +ENCODING 9545 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +18 +18 +18 +18 +18 +18 +18 +FF +F8 +18 +18 +18 +18 +18 +18 +18 +ENDCHAR +STARTCHAR uni254A +ENCODING 9546 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +18 +18 +18 +18 +18 +18 +18 +FF +1F +18 +18 +18 +18 +18 +18 +18 +ENDCHAR +STARTCHAR uni254B +ENCODING 9547 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +18 +18 +18 +18 +18 +18 +18 +FF +FF +18 +18 +18 +18 +18 +18 +18 +ENDCHAR +STARTCHAR SF430000 +ENCODING 9552 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +FF +00 +FF +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR SF240000 +ENCODING 9553 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +28 +28 +28 +28 +28 +28 +28 +28 +28 +28 +28 +28 +28 +28 +28 +28 +ENDCHAR +STARTCHAR SF510000 +ENCODING 9554 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +1F +10 +1F +10 +10 +10 +10 +10 +10 +10 +ENDCHAR +STARTCHAR SF520000 +ENCODING 9555 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +3F +28 +28 +28 +28 +28 +28 +28 +28 +ENDCHAR +STARTCHAR SF390000 +ENCODING 9556 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +3F +20 +2F +28 +28 +28 +28 +28 +28 +28 +ENDCHAR +STARTCHAR SF220000 +ENCODING 9557 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +F0 +10 +F0 +10 +10 +10 +10 +10 +10 +10 +ENDCHAR +STARTCHAR SF210000 +ENCODING 9558 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +F8 +28 +28 +28 +28 +28 +28 +28 +28 +ENDCHAR +STARTCHAR SF250000 +ENCODING 9559 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +F8 +08 +E8 +28 +28 +28 +28 +28 +28 +28 +ENDCHAR +STARTCHAR SF500000 +ENCODING 9560 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +10 +10 +10 +10 +1F +10 +1F +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR SF490000 +ENCODING 9561 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +28 +28 +28 +28 +28 +28 +28 +3F +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR SF380000 +ENCODING 9562 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +28 +28 +28 +28 +28 +28 +2F +20 +3F +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR SF280000 +ENCODING 9563 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +10 +10 +10 +10 +F0 +10 +F0 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR SF270000 +ENCODING 9564 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +28 +28 +28 +28 +28 +28 +28 +F8 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR SF260000 +ENCODING 9565 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +28 +28 +28 +28 +28 +28 +E8 +08 +F8 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR SF360000 +ENCODING 9566 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +10 +10 +10 +10 +1F +10 +1F +10 +10 +10 +10 +10 +10 +10 +ENDCHAR +STARTCHAR SF370000 +ENCODING 9567 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +28 +28 +28 +28 +28 +28 +28 +2F +28 +28 +28 +28 +28 +28 +28 +28 +ENDCHAR +STARTCHAR SF420000 +ENCODING 9568 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +28 +28 +28 +28 +28 +28 +2F +20 +2F +28 +28 +28 +28 +28 +28 +28 +ENDCHAR +STARTCHAR SF190000 +ENCODING 9569 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +10 +10 +10 +10 +F0 +10 +F0 +10 +10 +10 +10 +10 +10 +10 +ENDCHAR +STARTCHAR SF200000 +ENCODING 9570 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +28 +28 +28 +28 +28 +28 +28 +E8 +28 +28 +28 +28 +28 +28 +28 +28 +ENDCHAR +STARTCHAR SF230000 +ENCODING 9571 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +28 +28 +28 +28 +28 +28 +E8 +08 +E8 +28 +28 +28 +28 +28 +28 +28 +ENDCHAR +STARTCHAR SF470000 +ENCODING 9572 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +FF +00 +FF +10 +10 +10 +10 +10 +10 +10 +ENDCHAR +STARTCHAR SF480000 +ENCODING 9573 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +FF +28 +28 +28 +28 +28 +28 +28 +28 +ENDCHAR +STARTCHAR SF410000 +ENCODING 9574 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +FF +00 +EF +28 +28 +28 +28 +28 +28 +28 +ENDCHAR +STARTCHAR SF450000 +ENCODING 9575 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +10 +10 +10 +10 +FF +00 +FF +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR SF460000 +ENCODING 9576 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +28 +28 +28 +28 +28 +28 +28 +FF +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR SF400000 +ENCODING 9577 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +28 +28 +28 +28 +28 +28 +EF +00 +FF +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR SF540000 +ENCODING 9578 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +10 +10 +10 +10 +FF +10 +FF +10 +10 +10 +10 +10 +10 +10 +ENDCHAR +STARTCHAR SF530000 +ENCODING 9579 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +28 +28 +28 +28 +28 +28 +28 +FF +28 +28 +28 +28 +28 +28 +28 +28 +ENDCHAR +STARTCHAR SF440000 +ENCODING 9580 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +28 +28 +28 +28 +28 +28 +EF +00 +EF +28 +28 +28 +28 +28 +28 +28 +ENDCHAR +STARTCHAR uni256D +ENCODING 9581 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +07 +08 +10 +10 +10 +10 +10 +10 +10 +ENDCHAR +STARTCHAR uni256E +ENCODING 9582 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +C0 +20 +10 +10 +10 +10 +10 +10 +10 +ENDCHAR +STARTCHAR uni256F +ENCODING 9583 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +10 +10 +10 +10 +20 +C0 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2570 +ENCODING 9584 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +10 +10 +10 +10 +08 +07 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2571 +ENCODING 9585 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +01 +01 +02 +02 +04 +04 +08 +08 +10 +10 +20 +20 +40 +40 +80 +80 +ENDCHAR +STARTCHAR uni2572 +ENCODING 9586 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +80 +80 +40 +40 +20 +20 +10 +10 +08 +08 +04 +04 +02 +02 +01 +01 +ENDCHAR +STARTCHAR uni2573 +ENCODING 9587 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +81 +81 +42 +42 +24 +24 +18 +18 +18 +18 +24 +24 +42 +42 +81 +81 +ENDCHAR +STARTCHAR uni2574 +ENCODING 9588 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +F0 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2575 +ENCODING 9589 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +10 +10 +10 +10 +10 +10 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2576 +ENCODING 9590 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +1F +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2577 +ENCODING 9591 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +10 +10 +10 +10 +10 +10 +10 +10 +10 +ENDCHAR +STARTCHAR uni2578 +ENCODING 9592 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +F0 +F0 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2579 +ENCODING 9593 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +18 +18 +18 +18 +18 +18 +18 +18 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni257A +ENCODING 9594 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +1F +1F +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni257B +ENCODING 9595 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +18 +18 +18 +18 +18 +18 +18 +18 +18 +ENDCHAR +STARTCHAR uni257C +ENCODING 9596 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +FF +1F +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni257D +ENCODING 9597 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +10 +10 +10 +10 +10 +10 +10 +18 +18 +18 +18 +18 +18 +18 +18 +18 +ENDCHAR +STARTCHAR uni257E +ENCODING 9598 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +FF +F0 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni257F +ENCODING 9599 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +18 +18 +18 +18 +18 +18 +18 +18 +10 +10 +10 +10 +10 +10 +10 +10 +ENDCHAR +STARTCHAR upblock +ENCODING 9600 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +FF +FF +FF +FF +FF +FF +FF +FF +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2581 +ENCODING 9601 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +FF +FF +ENDCHAR +STARTCHAR uni2582 +ENCODING 9602 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +FF +FF +FF +FF +ENDCHAR +STARTCHAR uni2583 +ENCODING 9603 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +FF +FF +FF +FF +FF +FF +ENDCHAR +STARTCHAR dnblock +ENCODING 9604 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +FF +FF +FF +FF +FF +FF +FF +FF +ENDCHAR +STARTCHAR uni2585 +ENCODING 9605 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +FF +FF +FF +FF +FF +FF +FF +FF +FF +FF +ENDCHAR +STARTCHAR uni2586 +ENCODING 9606 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +FF +FF +FF +FF +FF +FF +FF +FF +FF +FF +FF +FF +ENDCHAR +STARTCHAR uni2587 +ENCODING 9607 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +FF +FF +FF +FF +FF +FF +FF +FF +FF +FF +FF +FF +FF +FF +ENDCHAR +STARTCHAR block +ENCODING 9608 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +FF +FF +FF +FF +FF +FF +FF +FF +FF +FF +FF +FF +FF +FF +FF +FF +ENDCHAR +STARTCHAR uni2589 +ENCODING 9609 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +FE +FE +FE +FE +FE +FE +FE +FE +FE +FE +FE +FE +FE +FE +FE +FE +ENDCHAR +STARTCHAR uni258A +ENCODING 9610 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +FC +FC +FC +FC +FC +FC +FC +FC +FC +FC +FC +FC +FC +FC +FC +FC +ENDCHAR +STARTCHAR uni258B +ENCODING 9611 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +F8 +F8 +F8 +F8 +F8 +F8 +F8 +F8 +F8 +F8 +F8 +F8 +F8 +F8 +F8 +F8 +ENDCHAR +STARTCHAR lfblock +ENCODING 9612 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +F0 +F0 +F0 +F0 +F0 +F0 +F0 +F0 +F0 +F0 +F0 +F0 +F0 +F0 +F0 +F0 +ENDCHAR +STARTCHAR uni258D +ENCODING 9613 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +E0 +E0 +E0 +E0 +E0 +E0 +E0 +E0 +E0 +E0 +E0 +E0 +E0 +E0 +E0 +E0 +ENDCHAR +STARTCHAR uni258E +ENCODING 9614 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +C0 +C0 +C0 +C0 +C0 +C0 +C0 +C0 +C0 +C0 +C0 +C0 +C0 +C0 +C0 +C0 +ENDCHAR +STARTCHAR uni258F +ENCODING 9615 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +80 +80 +80 +80 +80 +80 +80 +80 +80 +80 +80 +80 +80 +80 +80 +80 +ENDCHAR +STARTCHAR rtblock +ENCODING 9616 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +0F +0F +0F +0F +0F +0F +0F +0F +0F +0F +0F +0F +0F +0F +0F +0F +ENDCHAR +STARTCHAR ltshade +ENCODING 9617 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +88 +22 +88 +22 +88 +22 +88 +22 +88 +22 +88 +22 +88 +22 +88 +22 +ENDCHAR +STARTCHAR shade +ENCODING 9618 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +AA +55 +AA +55 +AA +55 +AA +55 +AA +55 +AA +55 +AA +55 +AA +55 +ENDCHAR +STARTCHAR dkshade +ENCODING 9619 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +EE +BB +EE +BB +EE +BB +EE +BB +EE +BB +EE +BB +EE +BB +EE +BB +ENDCHAR +STARTCHAR uni2596 +ENCODING 9622 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +F0 +F0 +F0 +F0 +F0 +F0 +F0 +F0 +ENDCHAR +STARTCHAR uni2597 +ENCODING 9623 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +0F +0F +0F +0F +0F +0F +0F +0F +ENDCHAR +STARTCHAR uni2598 +ENCODING 9624 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +F0 +F0 +F0 +F0 +F0 +F0 +F0 +F0 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2599 +ENCODING 9625 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +F0 +F0 +F0 +F0 +F0 +F0 +F0 +F0 +FF +FF +FF +FF +FF +FF +FF +FF +ENDCHAR +STARTCHAR uni259A +ENCODING 9626 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +F0 +F0 +F0 +F0 +F0 +F0 +F0 +F0 +0F +0F +0F +0F +0F +0F +0F +0F +ENDCHAR +STARTCHAR uni259B +ENCODING 9627 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +FF +FF +FF +FF +FF +FF +FF +FF +F0 +F0 +F0 +F0 +F0 +F0 +F0 +F0 +ENDCHAR +STARTCHAR uni259C +ENCODING 9628 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +FF +FF +FF +FF +FF +FF +FF +FF +0F +0F +0F +0F +0F +0F +0F +0F +ENDCHAR +STARTCHAR uni259D +ENCODING 9629 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +0F +0F +0F +0F +0F +0F +0F +0F +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni259E +ENCODING 9630 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +0F +0F +0F +0F +0F +0F +0F +0F +F0 +F0 +F0 +F0 +F0 +F0 +F0 +F0 +ENDCHAR +STARTCHAR uni259F +ENCODING 9631 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +0F +0F +0F +0F +0F +0F +0F +0F +FF +FF +FF +FF +FF +FF +FF +FF +ENDCHAR +STARTCHAR filledbox +ENCODING 9632 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +3C +3C +3C +3C +3C +3C +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR filledrect +ENCODING 9644 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +7E +7E +7E +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni25AE +ENCODING 9646 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7E +7E +7E +7E +7E +7E +7E +7E +7E +7E +00 +00 +00 +00 +ENDCHAR +STARTCHAR triagup +ENCODING 9650 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +10 +10 +38 +38 +7C +7C +FE +FE +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni25B6 +ENCODING 9654 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +C0 +F0 +FC +FF +FC +F0 +C0 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR triagrt +ENCODING 9658 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +C0 +F0 +FC +FF +FC +F0 +C0 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR triagdn +ENCODING 9660 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +FE +FE +7C +7C +38 +38 +10 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni25C0 +ENCODING 9664 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +03 +0F +3F +FF +3F +0F +03 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR triaglf +ENCODING 9668 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +03 +0F +3F +FF +3F +0F +03 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR blackdiamond +ENCODING 9670 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +10 +38 +7C +FE +7C +38 +10 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR lozenge +ENCODING 9674 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +10 +28 +44 +82 +44 +28 +10 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR circle +ENCODING 9675 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +18 +24 +24 +18 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR H18533 +ENCODING 9679 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +18 +3C +3C +18 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR invbullet +ENCODING 9688 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +FF +FF +FF +FF +FF +FF +E7 +C3 +C3 +E7 +FF +FF +FF +FF +FF +FF +ENDCHAR +STARTCHAR invcircle +ENCODING 9689 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +FF +FF +FF +FF +FF +FF +E7 +DB +DB +E7 +FF +FF +FF +FF +FF +FF +ENDCHAR +STARTCHAR smileface +ENCODING 9786 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7C +82 +AA +82 +82 +BA +92 +82 +82 +7C +00 +00 +00 +00 +ENDCHAR +STARTCHAR invsmileface +ENCODING 9787 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7C +FE +D6 +FE +FE +C6 +EE +FE +FE +7C +00 +00 +00 +00 +ENDCHAR +STARTCHAR sun +ENCODING 9788 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +10 +92 +54 +38 +EE +38 +54 +92 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR female +ENCODING 9792 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +38 +44 +44 +44 +44 +38 +10 +7C +10 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR male +ENCODING 9794 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +1E +06 +0A +12 +38 +44 +44 +44 +44 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR spade +ENCODING 9824 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +10 +10 +38 +7C +FE +FE +7C +10 +10 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR club +ENCODING 9827 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +10 +38 +38 +10 +54 +FE +FE +54 +10 +38 +00 +00 +00 +00 +ENDCHAR +STARTCHAR heart +ENCODING 9829 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +6C +FE +FE +FE +FE +7C +38 +10 +00 +00 +00 +00 +ENDCHAR +STARTCHAR diamond +ENCODING 9830 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +10 +38 +7C +FE +7C +38 +10 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR musicalnote +ENCODING 9834 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +3E +22 +3E +20 +20 +20 +20 +20 +20 +C0 +00 +00 +00 +00 +ENDCHAR +STARTCHAR musicalnotedbl +ENCODING 9835 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7E +42 +7E +42 +42 +42 +42 +42 +42 +44 +80 +00 +00 +00 +ENDCHAR +STARTCHAR uni2713 +ENCODING 10003 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +02 +02 +04 +04 +88 +88 +50 +50 +20 +20 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2714 +ENCODING 10004 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +03 +03 +06 +06 +CC +CC +78 +78 +30 +30 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2717 +ENCODING 10007 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +04 +44 +28 +18 +18 +14 +22 +20 +40 +40 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2718 +ENCODING 10008 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +0C +CC +78 +38 +38 +3C +66 +60 +C0 +C0 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni27E8 +ENCODING 10216 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +08 +08 +10 +10 +20 +20 +10 +10 +08 +08 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni27E9 +ENCODING 10217 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +20 +20 +10 +10 +08 +08 +10 +10 +20 +20 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni27EA +ENCODING 10218 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +12 +12 +24 +24 +48 +48 +24 +24 +12 +12 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni27EB +ENCODING 10219 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +48 +48 +24 +24 +12 +12 +24 +24 +48 +48 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2800 +ENCODING 10240 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2801 +ENCODING 10241 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2802 +ENCODING 10242 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +40 +40 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2803 +ENCODING 10243 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +40 +40 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2804 +ENCODING 10244 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +40 +40 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2805 +ENCODING 10245 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +00 +00 +00 +00 +40 +40 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2806 +ENCODING 10246 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +40 +40 +00 +00 +40 +40 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2807 +ENCODING 10247 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +40 +40 +00 +00 +40 +40 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2808 +ENCODING 10248 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2809 +ENCODING 10249 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni280A +ENCODING 10250 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +40 +40 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni280B +ENCODING 10251 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +40 +40 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni280C +ENCODING 10252 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +00 +00 +00 +00 +40 +40 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni280D +ENCODING 10253 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +00 +00 +00 +00 +40 +40 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni280E +ENCODING 10254 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +40 +40 +00 +00 +40 +40 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni280F +ENCODING 10255 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +40 +40 +00 +00 +40 +40 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2810 +ENCODING 10256 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +04 +04 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2811 +ENCODING 10257 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +04 +04 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2812 +ENCODING 10258 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +44 +44 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2813 +ENCODING 10259 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +44 +44 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2814 +ENCODING 10260 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +04 +04 +00 +00 +40 +40 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2815 +ENCODING 10261 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +04 +04 +00 +00 +40 +40 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2816 +ENCODING 10262 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +44 +44 +00 +00 +40 +40 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2817 +ENCODING 10263 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +44 +44 +00 +00 +40 +40 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2818 +ENCODING 10264 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +04 +04 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2819 +ENCODING 10265 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +04 +04 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni281A +ENCODING 10266 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +44 +44 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni281B +ENCODING 10267 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +44 +44 +00 +00 +00 +00 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni281C +ENCODING 10268 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +04 +04 +00 +00 +40 +40 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni281D +ENCODING 10269 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +04 +04 +00 +00 +40 +40 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni281E +ENCODING 10270 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +44 +44 +00 +00 +40 +40 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni281F +ENCODING 10271 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +44 +44 +00 +00 +40 +40 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2820 +ENCODING 10272 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +04 +04 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2821 +ENCODING 10273 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +00 +00 +00 +00 +04 +04 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2822 +ENCODING 10274 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +40 +40 +00 +00 +04 +04 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2823 +ENCODING 10275 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +40 +40 +00 +00 +04 +04 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2824 +ENCODING 10276 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +44 +44 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2825 +ENCODING 10277 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +00 +00 +00 +00 +44 +44 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2826 +ENCODING 10278 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +40 +40 +00 +00 +44 +44 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2827 +ENCODING 10279 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +40 +40 +00 +00 +44 +44 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2828 +ENCODING 10280 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +00 +00 +00 +00 +04 +04 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2829 +ENCODING 10281 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +00 +00 +00 +00 +04 +04 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni282A +ENCODING 10282 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +40 +40 +00 +00 +04 +04 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni282B +ENCODING 10283 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +40 +40 +00 +00 +04 +04 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni282C +ENCODING 10284 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +00 +00 +00 +00 +44 +44 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni282D +ENCODING 10285 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +00 +00 +00 +00 +44 +44 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni282E +ENCODING 10286 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +40 +40 +00 +00 +44 +44 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni282F +ENCODING 10287 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +40 +40 +00 +00 +44 +44 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2830 +ENCODING 10288 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +04 +04 +00 +00 +04 +04 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2831 +ENCODING 10289 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +04 +04 +00 +00 +04 +04 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2832 +ENCODING 10290 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +44 +44 +00 +00 +04 +04 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2833 +ENCODING 10291 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +44 +44 +00 +00 +04 +04 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2834 +ENCODING 10292 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +04 +04 +00 +00 +44 +44 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2835 +ENCODING 10293 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +04 +04 +00 +00 +44 +44 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2836 +ENCODING 10294 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +44 +44 +00 +00 +44 +44 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2837 +ENCODING 10295 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +44 +44 +00 +00 +44 +44 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2838 +ENCODING 10296 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +04 +04 +00 +00 +04 +04 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2839 +ENCODING 10297 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +04 +04 +00 +00 +04 +04 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni283A +ENCODING 10298 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +44 +44 +00 +00 +04 +04 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni283B +ENCODING 10299 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +44 +44 +00 +00 +04 +04 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni283C +ENCODING 10300 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +04 +04 +00 +00 +44 +44 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni283D +ENCODING 10301 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +04 +04 +00 +00 +44 +44 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni283E +ENCODING 10302 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +44 +44 +00 +00 +44 +44 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni283F +ENCODING 10303 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +44 +44 +00 +00 +44 +44 +00 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uni2840 +ENCODING 10304 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni2841 +ENCODING 10305 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni2842 +ENCODING 10306 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +40 +40 +00 +00 +00 +00 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni2843 +ENCODING 10307 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +40 +40 +00 +00 +00 +00 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni2844 +ENCODING 10308 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +40 +40 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni2845 +ENCODING 10309 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +00 +00 +00 +00 +40 +40 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni2846 +ENCODING 10310 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +40 +40 +00 +00 +40 +40 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni2847 +ENCODING 10311 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +40 +40 +00 +00 +40 +40 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni2848 +ENCODING 10312 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni2849 +ENCODING 10313 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni284A +ENCODING 10314 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +40 +40 +00 +00 +00 +00 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni284B +ENCODING 10315 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +40 +40 +00 +00 +00 +00 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni284C +ENCODING 10316 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +00 +00 +00 +00 +40 +40 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni284D +ENCODING 10317 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +00 +00 +00 +00 +40 +40 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni284E +ENCODING 10318 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +40 +40 +00 +00 +40 +40 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni284F +ENCODING 10319 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +40 +40 +00 +00 +40 +40 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni2850 +ENCODING 10320 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +04 +04 +00 +00 +00 +00 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni2851 +ENCODING 10321 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +04 +04 +00 +00 +00 +00 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni2852 +ENCODING 10322 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +44 +44 +00 +00 +00 +00 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni2853 +ENCODING 10323 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +44 +44 +00 +00 +00 +00 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni2854 +ENCODING 10324 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +04 +04 +00 +00 +40 +40 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni2855 +ENCODING 10325 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +04 +04 +00 +00 +40 +40 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni2856 +ENCODING 10326 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +44 +44 +00 +00 +40 +40 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni2857 +ENCODING 10327 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +44 +44 +00 +00 +40 +40 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni2858 +ENCODING 10328 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +04 +04 +00 +00 +00 +00 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni2859 +ENCODING 10329 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +04 +04 +00 +00 +00 +00 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni285A +ENCODING 10330 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +44 +44 +00 +00 +00 +00 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni285B +ENCODING 10331 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +44 +44 +00 +00 +00 +00 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni285C +ENCODING 10332 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +04 +04 +00 +00 +40 +40 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni285D +ENCODING 10333 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +04 +04 +00 +00 +40 +40 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni285E +ENCODING 10334 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +44 +44 +00 +00 +40 +40 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni285F +ENCODING 10335 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +44 +44 +00 +00 +40 +40 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni2860 +ENCODING 10336 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +04 +04 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni2861 +ENCODING 10337 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +00 +00 +00 +00 +04 +04 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni2862 +ENCODING 10338 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +40 +40 +00 +00 +04 +04 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni2863 +ENCODING 10339 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +40 +40 +00 +00 +04 +04 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni2864 +ENCODING 10340 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +44 +44 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni2865 +ENCODING 10341 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +00 +00 +00 +00 +44 +44 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni2866 +ENCODING 10342 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +40 +40 +00 +00 +44 +44 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni2867 +ENCODING 10343 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +40 +40 +00 +00 +44 +44 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni2868 +ENCODING 10344 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +00 +00 +00 +00 +04 +04 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni2869 +ENCODING 10345 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +00 +00 +00 +00 +04 +04 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni286A +ENCODING 10346 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +40 +40 +00 +00 +04 +04 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni286B +ENCODING 10347 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +40 +40 +00 +00 +04 +04 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni286C +ENCODING 10348 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +00 +00 +00 +00 +44 +44 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni286D +ENCODING 10349 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +00 +00 +00 +00 +44 +44 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni286E +ENCODING 10350 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +40 +40 +00 +00 +44 +44 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni286F +ENCODING 10351 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +40 +40 +00 +00 +44 +44 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni2870 +ENCODING 10352 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +04 +04 +00 +00 +04 +04 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni2871 +ENCODING 10353 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +04 +04 +00 +00 +04 +04 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni2872 +ENCODING 10354 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +44 +44 +00 +00 +04 +04 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni2873 +ENCODING 10355 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +44 +44 +00 +00 +04 +04 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni2874 +ENCODING 10356 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +04 +04 +00 +00 +44 +44 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni2875 +ENCODING 10357 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +04 +04 +00 +00 +44 +44 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni2876 +ENCODING 10358 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +44 +44 +00 +00 +44 +44 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni2877 +ENCODING 10359 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +44 +44 +00 +00 +44 +44 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni2878 +ENCODING 10360 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +04 +04 +00 +00 +04 +04 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni2879 +ENCODING 10361 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +04 +04 +00 +00 +04 +04 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni287A +ENCODING 10362 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +44 +44 +00 +00 +04 +04 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni287B +ENCODING 10363 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +44 +44 +00 +00 +04 +04 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni287C +ENCODING 10364 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +04 +04 +00 +00 +44 +44 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni287D +ENCODING 10365 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +04 +04 +00 +00 +44 +44 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni287E +ENCODING 10366 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +44 +44 +00 +00 +44 +44 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni287F +ENCODING 10367 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +44 +44 +00 +00 +44 +44 +00 +00 +40 +40 +00 +ENDCHAR +STARTCHAR uni2880 +ENCODING 10368 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni2881 +ENCODING 10369 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni2882 +ENCODING 10370 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +40 +40 +00 +00 +00 +00 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni2883 +ENCODING 10371 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +40 +40 +00 +00 +00 +00 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni2884 +ENCODING 10372 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +40 +40 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni2885 +ENCODING 10373 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +00 +00 +00 +00 +40 +40 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni2886 +ENCODING 10374 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +40 +40 +00 +00 +40 +40 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni2887 +ENCODING 10375 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +40 +40 +00 +00 +40 +40 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni2888 +ENCODING 10376 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni2889 +ENCODING 10377 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni288A +ENCODING 10378 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +40 +40 +00 +00 +00 +00 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni288B +ENCODING 10379 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +40 +40 +00 +00 +00 +00 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni288C +ENCODING 10380 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +00 +00 +00 +00 +40 +40 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni288D +ENCODING 10381 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +00 +00 +00 +00 +40 +40 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni288E +ENCODING 10382 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +40 +40 +00 +00 +40 +40 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni288F +ENCODING 10383 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +40 +40 +00 +00 +40 +40 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni2890 +ENCODING 10384 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +04 +04 +00 +00 +00 +00 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni2891 +ENCODING 10385 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +04 +04 +00 +00 +00 +00 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni2892 +ENCODING 10386 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +44 +44 +00 +00 +00 +00 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni2893 +ENCODING 10387 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +44 +44 +00 +00 +00 +00 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni2894 +ENCODING 10388 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +04 +04 +00 +00 +40 +40 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni2895 +ENCODING 10389 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +04 +04 +00 +00 +40 +40 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni2896 +ENCODING 10390 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +44 +44 +00 +00 +40 +40 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni2897 +ENCODING 10391 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +44 +44 +00 +00 +40 +40 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni2898 +ENCODING 10392 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +04 +04 +00 +00 +00 +00 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni2899 +ENCODING 10393 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +04 +04 +00 +00 +00 +00 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni289A +ENCODING 10394 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +44 +44 +00 +00 +00 +00 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni289B +ENCODING 10395 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +44 +44 +00 +00 +00 +00 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni289C +ENCODING 10396 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +04 +04 +00 +00 +40 +40 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni289D +ENCODING 10397 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +04 +04 +00 +00 +40 +40 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni289E +ENCODING 10398 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +44 +44 +00 +00 +40 +40 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni289F +ENCODING 10399 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +44 +44 +00 +00 +40 +40 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni28A0 +ENCODING 10400 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +04 +04 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni28A1 +ENCODING 10401 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +00 +00 +00 +00 +04 +04 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni28A2 +ENCODING 10402 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +40 +40 +00 +00 +04 +04 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni28A3 +ENCODING 10403 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +40 +40 +00 +00 +04 +04 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni28A4 +ENCODING 10404 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +44 +44 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni28A5 +ENCODING 10405 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +00 +00 +00 +00 +44 +44 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni28A6 +ENCODING 10406 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +40 +40 +00 +00 +44 +44 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni28A7 +ENCODING 10407 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +40 +40 +00 +00 +44 +44 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni28A8 +ENCODING 10408 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +00 +00 +00 +00 +04 +04 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni28A9 +ENCODING 10409 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +00 +00 +00 +00 +04 +04 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni28AA +ENCODING 10410 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +40 +40 +00 +00 +04 +04 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni28AB +ENCODING 10411 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +40 +40 +00 +00 +04 +04 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni28AC +ENCODING 10412 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +00 +00 +00 +00 +44 +44 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni28AD +ENCODING 10413 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +00 +00 +00 +00 +44 +44 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni28AE +ENCODING 10414 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +40 +40 +00 +00 +44 +44 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni28AF +ENCODING 10415 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +40 +40 +00 +00 +44 +44 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni28B0 +ENCODING 10416 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +04 +04 +00 +00 +04 +04 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni28B1 +ENCODING 10417 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +04 +04 +00 +00 +04 +04 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni28B2 +ENCODING 10418 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +44 +44 +00 +00 +04 +04 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni28B3 +ENCODING 10419 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +44 +44 +00 +00 +04 +04 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni28B4 +ENCODING 10420 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +04 +04 +00 +00 +44 +44 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni28B5 +ENCODING 10421 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +04 +04 +00 +00 +44 +44 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni28B6 +ENCODING 10422 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +44 +44 +00 +00 +44 +44 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni28B7 +ENCODING 10423 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +44 +44 +00 +00 +44 +44 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni28B8 +ENCODING 10424 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +04 +04 +00 +00 +04 +04 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni28B9 +ENCODING 10425 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +04 +04 +00 +00 +04 +04 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni28BA +ENCODING 10426 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +44 +44 +00 +00 +04 +04 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni28BB +ENCODING 10427 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +44 +44 +00 +00 +04 +04 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni28BC +ENCODING 10428 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +04 +04 +00 +00 +44 +44 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni28BD +ENCODING 10429 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +04 +04 +00 +00 +44 +44 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni28BE +ENCODING 10430 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +44 +44 +00 +00 +44 +44 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni28BF +ENCODING 10431 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +44 +44 +00 +00 +44 +44 +00 +00 +04 +04 +00 +ENDCHAR +STARTCHAR uni28C0 +ENCODING 10432 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28C1 +ENCODING 10433 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28C2 +ENCODING 10434 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +40 +40 +00 +00 +00 +00 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28C3 +ENCODING 10435 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +40 +40 +00 +00 +00 +00 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28C4 +ENCODING 10436 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +40 +40 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28C5 +ENCODING 10437 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +00 +00 +00 +00 +40 +40 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28C6 +ENCODING 10438 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +40 +40 +00 +00 +40 +40 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28C7 +ENCODING 10439 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +40 +40 +00 +00 +40 +40 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28C8 +ENCODING 10440 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28C9 +ENCODING 10441 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28CA +ENCODING 10442 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +40 +40 +00 +00 +00 +00 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28CB +ENCODING 10443 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +40 +40 +00 +00 +00 +00 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28CC +ENCODING 10444 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +00 +00 +00 +00 +40 +40 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28CD +ENCODING 10445 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +00 +00 +00 +00 +40 +40 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28CE +ENCODING 10446 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +40 +40 +00 +00 +40 +40 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28CF +ENCODING 10447 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +40 +40 +00 +00 +40 +40 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28D0 +ENCODING 10448 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +04 +04 +00 +00 +00 +00 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28D1 +ENCODING 10449 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +04 +04 +00 +00 +00 +00 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28D2 +ENCODING 10450 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +44 +44 +00 +00 +00 +00 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28D3 +ENCODING 10451 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +44 +44 +00 +00 +00 +00 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28D4 +ENCODING 10452 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +04 +04 +00 +00 +40 +40 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28D5 +ENCODING 10453 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +04 +04 +00 +00 +40 +40 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28D6 +ENCODING 10454 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +44 +44 +00 +00 +40 +40 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28D7 +ENCODING 10455 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +44 +44 +00 +00 +40 +40 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28D8 +ENCODING 10456 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +04 +04 +00 +00 +00 +00 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28D9 +ENCODING 10457 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +04 +04 +00 +00 +00 +00 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28DA +ENCODING 10458 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +44 +44 +00 +00 +00 +00 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28DB +ENCODING 10459 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +44 +44 +00 +00 +00 +00 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28DC +ENCODING 10460 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +04 +04 +00 +00 +40 +40 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28DD +ENCODING 10461 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +04 +04 +00 +00 +40 +40 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28DE +ENCODING 10462 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +44 +44 +00 +00 +40 +40 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28DF +ENCODING 10463 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +44 +44 +00 +00 +40 +40 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28E0 +ENCODING 10464 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +04 +04 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28E1 +ENCODING 10465 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +00 +00 +00 +00 +04 +04 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28E2 +ENCODING 10466 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +40 +40 +00 +00 +04 +04 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28E3 +ENCODING 10467 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +40 +40 +00 +00 +04 +04 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28E4 +ENCODING 10468 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +00 +00 +00 +00 +44 +44 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28E5 +ENCODING 10469 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +00 +00 +00 +00 +44 +44 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28E6 +ENCODING 10470 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +40 +40 +00 +00 +44 +44 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28E7 +ENCODING 10471 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +40 +40 +00 +00 +44 +44 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28E8 +ENCODING 10472 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +00 +00 +00 +00 +04 +04 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28E9 +ENCODING 10473 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +00 +00 +00 +00 +04 +04 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28EA +ENCODING 10474 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +40 +40 +00 +00 +04 +04 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28EB +ENCODING 10475 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +40 +40 +00 +00 +04 +04 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28EC +ENCODING 10476 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +00 +00 +00 +00 +44 +44 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28ED +ENCODING 10477 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +00 +00 +00 +00 +44 +44 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28EE +ENCODING 10478 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +40 +40 +00 +00 +44 +44 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28EF +ENCODING 10479 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +40 +40 +00 +00 +44 +44 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28F0 +ENCODING 10480 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +04 +04 +00 +00 +04 +04 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28F1 +ENCODING 10481 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +04 +04 +00 +00 +04 +04 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28F2 +ENCODING 10482 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +44 +44 +00 +00 +04 +04 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28F3 +ENCODING 10483 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +44 +44 +00 +00 +04 +04 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28F4 +ENCODING 10484 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +04 +04 +00 +00 +44 +44 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28F5 +ENCODING 10485 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +04 +04 +00 +00 +44 +44 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28F6 +ENCODING 10486 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +44 +44 +00 +00 +44 +44 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28F7 +ENCODING 10487 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +40 +40 +00 +00 +44 +44 +00 +00 +44 +44 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28F8 +ENCODING 10488 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +04 +04 +00 +00 +04 +04 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28F9 +ENCODING 10489 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +04 +04 +00 +00 +04 +04 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28FA +ENCODING 10490 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +44 +44 +00 +00 +04 +04 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28FB +ENCODING 10491 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +44 +44 +00 +00 +04 +04 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28FC +ENCODING 10492 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +04 +04 +00 +00 +44 +44 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28FD +ENCODING 10493 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +04 +04 +00 +00 +44 +44 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28FE +ENCODING 10494 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +04 +04 +00 +00 +44 +44 +00 +00 +44 +44 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni28FF +ENCODING 10495 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +44 +44 +00 +00 +44 +44 +00 +00 +44 +44 +00 +00 +44 +44 +00 +ENDCHAR +STARTCHAR uni2E2C +ENCODING 11820 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +42 +42 +00 +00 +00 +42 +42 +00 +00 +00 +00 +ENDCHAR +STARTCHAR uniE0A0 +ENCODING 57504 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +80 +80 +88 +9C +AA +88 +88 +88 +10 +20 +40 +80 +80 +80 +80 +80 +ENDCHAR +STARTCHAR uniE0A1 +ENCODING 57505 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +80 +80 +80 +80 +80 +F8 +00 +11 +19 +15 +13 +11 +11 +00 +00 +ENDCHAR +STARTCHAR uniE0A2 +ENCODING 57506 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +38 +44 +44 +44 +44 +FE +FE +EE +C6 +EE +FE +FE +FE +00 +00 +ENDCHAR +STARTCHAR uniE0B0 +ENCODING 57520 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +80 +C0 +E0 +F0 +F8 +FC +FE +FF +FF +FE +FC +F8 +F0 +E0 +C0 +80 +ENDCHAR +STARTCHAR uniE0B1 +ENCODING 57521 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +80 +40 +20 +10 +08 +04 +02 +01 +01 +02 +04 +08 +10 +20 +40 +80 +ENDCHAR +STARTCHAR uniE0B2 +ENCODING 57522 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +01 +03 +07 +0F +1F +3F +7F +FF +FF +7F +3F +1F +0F +07 +03 +01 +ENDCHAR +STARTCHAR uniE0B3 +ENCODING 57523 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +01 +02 +04 +08 +10 +20 +40 +80 +80 +40 +20 +10 +08 +04 +02 +01 +ENDCHAR +STARTCHAR uniF6BE +ENCODING 63166 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +00 +00 +00 +0C +04 +04 +04 +04 +04 +04 +44 +44 +38 +00 +ENDCHAR +STARTCHAR uniFFFD +ENCODING 65533 +SWIDTH 500 0 +DWIDTH 8 0 +BBX 8 16 0 -4 +BITMAP +00 +00 +7E +42 +42 +42 +42 +42 +42 +42 +42 +7E +00 +00 +00 +00 +ENDCHAR +ENDFONT diff --git a/assets/hiphop-pack/BASS/00_E1.wav b/assets/hiphop-pack/BASS/00_E1.wav new file mode 100644 index 0000000..a1f59ab Binary files /dev/null and b/assets/hiphop-pack/BASS/00_E1.wav differ diff --git a/assets/hiphop-pack/BASS/01_As1.wav b/assets/hiphop-pack/BASS/01_As1.wav new file mode 100644 index 0000000..8bb32fe Binary files /dev/null and b/assets/hiphop-pack/BASS/01_As1.wav differ diff --git a/assets/hiphop-pack/BASS/02_D2.wav b/assets/hiphop-pack/BASS/02_D2.wav new file mode 100644 index 0000000..301db20 Binary files /dev/null and b/assets/hiphop-pack/BASS/02_D2.wav differ diff --git a/assets/hiphop-pack/BASS/03_Fs2.wav b/assets/hiphop-pack/BASS/03_Fs2.wav new file mode 100644 index 0000000..cb11a8a Binary files /dev/null and b/assets/hiphop-pack/BASS/03_Fs2.wav differ diff --git a/assets/hiphop-pack/BASS/04_A2.wav b/assets/hiphop-pack/BASS/04_A2.wav new file mode 100644 index 0000000..e707110 Binary files /dev/null and b/assets/hiphop-pack/BASS/04_A2.wav differ diff --git a/assets/hiphop-pack/BASS/05_Cs3.wav b/assets/hiphop-pack/BASS/05_Cs3.wav new file mode 100644 index 0000000..a915b20 Binary files /dev/null and b/assets/hiphop-pack/BASS/05_Cs3.wav differ diff --git a/assets/hiphop-pack/CREDITS.txt b/assets/hiphop-pack/CREDITS.txt new file mode 100644 index 0000000..3ad0ea9 --- /dev/null +++ b/assets/hiphop-pack/CREDITS.txt @@ -0,0 +1,19 @@ +SLOOP HIP-HOP PACK - free sounds for the user sample slots USR1..USR3 +Made by tools/gen_hiphop_pack.py: retuned, cut and processed ("dusty" chain) from: + + E.PIANO Wurlitzer EP200 samples by Greg Sullivan (http://www.sullivang.net/), + mapped by kinwie: https://github.com/sfzinstruments/GregSullivan.E-Pianos + Licence: Creative Commons Attribution 3.0 (CC BY 3.0). Credit: Greg Sullivan. + BASS VSCO-2 Community Edition (Versilian Studios), Solo Contrabass pizzicato. CC0 1.0. + HORNS VSCO-2 Community Edition, Trumpet and Tenor Trombone staccato. CC0 1.0. + STRINGS VSCO-2 Community Edition, Violin and Viola sections spiccato. CC0 1.0. + https://github.com/sgossner/VSCO-2-CE + VIBES VCSL (Versilian Community Sample Library), Vibraphone, hard mallets. CC0 1.0. + UPRIGHT VCSL, Upright Piano (Knight). CC0 1.0. https://github.com/sgossner/VCSL + SCRATCH Sonic Pi sample set, CC0 1.0 (freesound.org): vinyl_scratch (hello_flowers), + vinyl_backspin (il112), vinyl_rewind (TasmanianPower), perc_snap (SoundCollectah). + https://github.com/sonic-pi-net/sonic-pi/tree/main/etc/samples + +CC0 sounds: no conditions. E.PIANO: keep the credit to Greg Sullivan when you share the +samples themselves; music you make with any of them is yours. +No sound here comes from a commercial record. diff --git a/assets/hiphop-pack/EPIANO/00_A2.wav b/assets/hiphop-pack/EPIANO/00_A2.wav new file mode 100644 index 0000000..1261719 Binary files /dev/null and b/assets/hiphop-pack/EPIANO/00_A2.wav differ diff --git a/assets/hiphop-pack/EPIANO/01_Ds3.wav b/assets/hiphop-pack/EPIANO/01_Ds3.wav new file mode 100644 index 0000000..73bd82b Binary files /dev/null and b/assets/hiphop-pack/EPIANO/01_Ds3.wav differ diff --git a/assets/hiphop-pack/EPIANO/02_Cs4.wav b/assets/hiphop-pack/EPIANO/02_Cs4.wav new file mode 100644 index 0000000..62a5efb Binary files /dev/null and b/assets/hiphop-pack/EPIANO/02_Cs4.wav differ diff --git a/assets/hiphop-pack/EPIANO/03_B4.wav b/assets/hiphop-pack/EPIANO/03_B4.wav new file mode 100644 index 0000000..59db77e Binary files /dev/null and b/assets/hiphop-pack/EPIANO/03_B4.wav differ diff --git a/assets/hiphop-pack/HORNS/00_F3.wav b/assets/hiphop-pack/HORNS/00_F3.wav new file mode 100644 index 0000000..948cb7f Binary files /dev/null and b/assets/hiphop-pack/HORNS/00_F3.wav differ diff --git a/assets/hiphop-pack/HORNS/01_A3.wav b/assets/hiphop-pack/HORNS/01_A3.wav new file mode 100644 index 0000000..47b5092 Binary files /dev/null and b/assets/hiphop-pack/HORNS/01_A3.wav differ diff --git a/assets/hiphop-pack/HORNS/02_C4.wav b/assets/hiphop-pack/HORNS/02_C4.wav new file mode 100644 index 0000000..ecaa8c8 Binary files /dev/null and b/assets/hiphop-pack/HORNS/02_C4.wav differ diff --git a/assets/hiphop-pack/HORNS/03_Ds4.wav b/assets/hiphop-pack/HORNS/03_Ds4.wav new file mode 100644 index 0000000..3be38fb Binary files /dev/null and b/assets/hiphop-pack/HORNS/03_Ds4.wav differ diff --git a/assets/hiphop-pack/HORNS/04_G4.wav b/assets/hiphop-pack/HORNS/04_G4.wav new file mode 100644 index 0000000..ac28599 Binary files /dev/null and b/assets/hiphop-pack/HORNS/04_G4.wav differ diff --git a/assets/hiphop-pack/HORNS/05_As4.wav b/assets/hiphop-pack/HORNS/05_As4.wav new file mode 100644 index 0000000..1ec15bb Binary files /dev/null and b/assets/hiphop-pack/HORNS/05_As4.wav differ diff --git a/assets/hiphop-pack/HORNS/06_D5.wav b/assets/hiphop-pack/HORNS/06_D5.wav new file mode 100644 index 0000000..f8db6bc Binary files /dev/null and b/assets/hiphop-pack/HORNS/06_D5.wav differ diff --git a/assets/hiphop-pack/SCRATCH/00_vinyl_scratch.wav b/assets/hiphop-pack/SCRATCH/00_vinyl_scratch.wav new file mode 100644 index 0000000..768f66a Binary files /dev/null and b/assets/hiphop-pack/SCRATCH/00_vinyl_scratch.wav differ diff --git a/assets/hiphop-pack/SCRATCH/01_vinyl_backspin.wav b/assets/hiphop-pack/SCRATCH/01_vinyl_backspin.wav new file mode 100644 index 0000000..434e40c Binary files /dev/null and b/assets/hiphop-pack/SCRATCH/01_vinyl_backspin.wav differ diff --git a/assets/hiphop-pack/SCRATCH/02_vinyl_rewind.wav b/assets/hiphop-pack/SCRATCH/02_vinyl_rewind.wav new file mode 100644 index 0000000..6744555 Binary files /dev/null and b/assets/hiphop-pack/SCRATCH/02_vinyl_rewind.wav differ diff --git a/assets/hiphop-pack/SCRATCH/03_perc_snap.wav b/assets/hiphop-pack/SCRATCH/03_perc_snap.wav new file mode 100644 index 0000000..cf030d6 Binary files /dev/null and b/assets/hiphop-pack/SCRATCH/03_perc_snap.wav differ diff --git a/assets/hiphop-pack/STRINGS/00_G3.wav b/assets/hiphop-pack/STRINGS/00_G3.wav new file mode 100644 index 0000000..0537854 Binary files /dev/null and b/assets/hiphop-pack/STRINGS/00_G3.wav differ diff --git a/assets/hiphop-pack/STRINGS/01_B3.wav b/assets/hiphop-pack/STRINGS/01_B3.wav new file mode 100644 index 0000000..6472853 Binary files /dev/null and b/assets/hiphop-pack/STRINGS/01_B3.wav differ diff --git a/assets/hiphop-pack/STRINGS/02_D4.wav b/assets/hiphop-pack/STRINGS/02_D4.wav new file mode 100644 index 0000000..ba82d07 Binary files /dev/null and b/assets/hiphop-pack/STRINGS/02_D4.wav differ diff --git a/assets/hiphop-pack/STRINGS/03_Fs4.wav b/assets/hiphop-pack/STRINGS/03_Fs4.wav new file mode 100644 index 0000000..6f8644d Binary files /dev/null and b/assets/hiphop-pack/STRINGS/03_Fs4.wav differ diff --git a/assets/hiphop-pack/STRINGS/04_A4.wav b/assets/hiphop-pack/STRINGS/04_A4.wav new file mode 100644 index 0000000..46624a8 Binary files /dev/null and b/assets/hiphop-pack/STRINGS/04_A4.wav differ diff --git a/assets/hiphop-pack/STRINGS/05_C5.wav b/assets/hiphop-pack/STRINGS/05_C5.wav new file mode 100644 index 0000000..a5a0a2c Binary files /dev/null and b/assets/hiphop-pack/STRINGS/05_C5.wav differ diff --git a/assets/hiphop-pack/STRINGS/06_E5.wav b/assets/hiphop-pack/STRINGS/06_E5.wav new file mode 100644 index 0000000..946f30c Binary files /dev/null and b/assets/hiphop-pack/STRINGS/06_E5.wav differ diff --git a/assets/hiphop-pack/UPRIGHT/00_F3.wav b/assets/hiphop-pack/UPRIGHT/00_F3.wav new file mode 100644 index 0000000..f9c248b Binary files /dev/null and b/assets/hiphop-pack/UPRIGHT/00_F3.wav differ diff --git a/assets/hiphop-pack/UPRIGHT/01_B3.wav b/assets/hiphop-pack/UPRIGHT/01_B3.wav new file mode 100644 index 0000000..d0e0cd9 Binary files /dev/null and b/assets/hiphop-pack/UPRIGHT/01_B3.wav differ diff --git a/assets/hiphop-pack/UPRIGHT/02_F4.wav b/assets/hiphop-pack/UPRIGHT/02_F4.wav new file mode 100644 index 0000000..0360540 Binary files /dev/null and b/assets/hiphop-pack/UPRIGHT/02_F4.wav differ diff --git a/assets/hiphop-pack/UPRIGHT/03_Cs5.wav b/assets/hiphop-pack/UPRIGHT/03_Cs5.wav new file mode 100644 index 0000000..65bb91e Binary files /dev/null and b/assets/hiphop-pack/UPRIGHT/03_Cs5.wav differ diff --git a/assets/hiphop-pack/VIBES/00_F3.wav b/assets/hiphop-pack/VIBES/00_F3.wav new file mode 100644 index 0000000..61d5b70 Binary files /dev/null and b/assets/hiphop-pack/VIBES/00_F3.wav differ diff --git a/assets/hiphop-pack/VIBES/01_C4.wav b/assets/hiphop-pack/VIBES/01_C4.wav new file mode 100644 index 0000000..fdcdd4e Binary files /dev/null and b/assets/hiphop-pack/VIBES/01_C4.wav differ diff --git a/assets/hiphop-pack/VIBES/02_G4.wav b/assets/hiphop-pack/VIBES/02_G4.wav new file mode 100644 index 0000000..408a542 Binary files /dev/null and b/assets/hiphop-pack/VIBES/02_G4.wav differ diff --git a/assets/hiphop-pack/VIBES/03_D5.wav b/assets/hiphop-pack/VIBES/03_D5.wav new file mode 100644 index 0000000..efb0b06 Binary files /dev/null and b/assets/hiphop-pack/VIBES/03_D5.wav differ diff --git a/assets/hiphop-pack/pack.json b/assets/hiphop-pack/pack.json new file mode 100644 index 0000000..2c16a16 --- /dev/null +++ b/assets/hiphop-pack/pack.json @@ -0,0 +1,220 @@ +{ + "format": "sloop-pack", + "version": 1, + "rate": 22050, + "default": [ + "E.PIANO", + "BASS", + "HORNS" + ], + "sounds": [ + { + "name": "E.PIANO", + "title": "Electric piano (Wurlitzer 200)", + "desc": "Soul chords, the warm bark of a Wurlitzer through a dusty sampler.", + "license": "CC BY 3.0 - Greg Sullivan (Wurlitzer EP200 samples)", + "zones": [ + { + "file": "EPIANO/00_A2.wav", + "root": 45 + }, + { + "file": "EPIANO/01_Ds3.wav", + "root": 51 + }, + { + "file": "EPIANO/02_Cs4.wav", + "root": 61 + }, + { + "file": "EPIANO/03_B4.wav", + "root": 71 + } + ] + }, + { + "name": "BASS", + "title": "Upright bass (pizzicato)", + "desc": "A jazz upright bass. Plays two octaves under the keys: F3 on the keyboard is F1.", + "license": "CC0 - VSCO-2 Community Edition (Versilian Studios)", + "zones": [ + { + "file": "BASS/00_E1.wav", + "root": 52 + }, + { + "file": "BASS/01_As1.wav", + "root": 58 + }, + { + "file": "BASS/02_D2.wav", + "root": 62 + }, + { + "file": "BASS/03_Fs2.wav", + "root": 66 + }, + { + "file": "BASS/04_A2.wav", + "root": 69 + }, + { + "file": "BASS/05_Cs3.wav", + "root": 73 + } + ] + }, + { + "name": "HORNS", + "title": "Horn section stabs", + "desc": "Trumpet and trombone an octave apart: the stab of a funk record.", + "license": "CC0 - VSCO-2 Community Edition (Versilian Studios)", + "zones": [ + { + "file": "HORNS/00_F3.wav", + "root": 53 + }, + { + "file": "HORNS/01_A3.wav", + "root": 57 + }, + { + "file": "HORNS/02_C4.wav", + "root": 60 + }, + { + "file": "HORNS/03_Ds4.wav", + "root": 63 + }, + { + "file": "HORNS/04_G4.wav", + "root": 67 + }, + { + "file": "HORNS/05_As4.wav", + "root": 70 + }, + { + "file": "HORNS/06_D5.wav", + "root": 74 + } + ] + }, + { + "name": "STRINGS", + "title": "String stabs", + "desc": "Violins and violas, short and hard: the orchestra stab of '90s rap.", + "license": "CC0 - VSCO-2 Community Edition (Versilian Studios)", + "zones": [ + { + "file": "STRINGS/00_G3.wav", + "root": 55 + }, + { + "file": "STRINGS/01_B3.wav", + "root": 59 + }, + { + "file": "STRINGS/02_D4.wav", + "root": 62 + }, + { + "file": "STRINGS/03_Fs4.wav", + "root": 66 + }, + { + "file": "STRINGS/04_A4.wav", + "root": 69 + }, + { + "file": "STRINGS/05_C5.wav", + "root": 72 + }, + { + "file": "STRINGS/06_E5.wav", + "root": 76 + } + ] + }, + { + "name": "VIBES", + "title": "Vibraphone", + "desc": "Hard mallets, jazz-rap vibes.", + "license": "CC0 - VCSL (Versilian Studios)", + "zones": [ + { + "file": "VIBES/00_F3.wav", + "root": 53 + }, + { + "file": "VIBES/01_C4.wav", + "root": 60 + }, + { + "file": "VIBES/02_G4.wav", + "root": 67 + }, + { + "file": "VIBES/03_D5.wav", + "root": 74 + } + ] + }, + { + "name": "UPRIGHT", + "title": "Dusty upright piano", + "desc": "An old upright, filtered like a loop off a jazz record.", + "license": "CC0 - VCSL (Versilian Studios)", + "zones": [ + { + "file": "UPRIGHT/00_F3.wav", + "root": 53 + }, + { + "file": "UPRIGHT/01_B3.wav", + "root": 59 + }, + { + "file": "UPRIGHT/02_F4.wav", + "root": 65 + }, + { + "file": "UPRIGHT/03_Cs5.wav", + "root": 73 + } + ] + }, + { + "name": "SCRATCH", + "title": "DJ scratches", + "desc": "Scratch, backspin, rewind and a finger snap, each on its own keys.", + "license": "CC0 - Sonic Pi sample set (freesound.org CC0 recordings)", + "zones": [ + { + "file": "SCRATCH/00_vinyl_scratch.wav", + "root": 57, + "lo": 0, + "hi": 60 + }, + { + "file": "SCRATCH/01_vinyl_backspin.wav", + "root": 64, + "lo": 61, + "hi": 67 + }, + { + "file": "SCRATCH/02_vinyl_rewind.wav", + "root": 70, + "lo": 68, + "hi": 73 + }, + { + "file": "SCRATCH/03_perc_snap.wav", + "root": 77, + "lo": 74, + "hi": 127 + } + ] + } + ] +} diff --git a/assets/icons.json b/assets/icons.json new file mode 100644 index 0000000..f39a788 --- /dev/null +++ b/assets/icons.json @@ -0,0 +1,92 @@ +{ + "cell": 12, + "cols": 16, + "names": [ + "generic", + "attack", + "decay", + "sustain", + "release", + "env", + "cutoff", + "reso", + "rate", + "lfo_wave", + "wave", + "pulse", + "shape", + "pitch", + "tune", + "detune", + "transpose", + "octave", + "level", + "pan", + "mute", + "dist", + "drive", + "fold", + "bits", + "chorus", + "delay", + "reverb", + "feedback", + "arp", + "gate", + "swing", + "tempo", + "scale", + "quantize", + "glide", + "slide", + "voice", + "mod", + "noise", + "sub", + "ratio", + "algorithm", + "sample", + "steps", + "accent", + "time", + "phase", + "fade", + "mix", + "keytrack", + "size", + "damp", + "tone", + "sweep", + "vibrato", + "loop", + "hold", + "order", + "prob", + "length", + "division", + "chip", + "midi", + "save", + "load", + "clear", + "w_sin", + "w_tri", + "w_saw", + "w_sqr", + "w_pls", + "w_pwm", + "w_sh", + "w_dsin", + "w_spls", + "w_rsaw", + "w_rtri", + "w_rtrp", + "tape", + "drum", + "mouth", + "trio", + "drawbar", + "slice", + "grain" + ] +} diff --git a/assets/icons.png b/assets/icons.png new file mode 100644 index 0000000..e1ae8ac Binary files /dev/null and b/assets/icons.png differ diff --git a/assets/logo/sloop-icon.png b/assets/logo/sloop-icon.png new file mode 100644 index 0000000..9432dd5 Binary files /dev/null and b/assets/logo/sloop-icon.png differ diff --git a/assets/logo/sloop-icon.svg b/assets/logo/sloop-icon.svg new file mode 100644 index 0000000..4151992 --- /dev/null +++ b/assets/logo/sloop-icon.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/assets/logo/sloop-logo.png b/assets/logo/sloop-logo.png new file mode 100644 index 0000000..d5cad7d Binary files /dev/null and b/assets/logo/sloop-logo.png differ diff --git a/assets/logo/sloop-logo.svg b/assets/logo/sloop-logo.svg new file mode 100644 index 0000000..42a4fd7 --- /dev/null +++ b/assets/logo/sloop-logo.svg @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/assets/logo/sloop-splash.png b/assets/logo/sloop-splash.png new file mode 100644 index 0000000..c365954 Binary files /dev/null and b/assets/logo/sloop-splash.png differ diff --git a/assets/samples-cc0/ATTRIBUTION.txt b/assets/samples-cc0/ATTRIBUTION.txt new file mode 100644 index 0000000..b869bc9 --- /dev/null +++ b/assets/samples-cc0/ATTRIBUTION.txt @@ -0,0 +1,38 @@ +SLOOP SAMPLE engine - built-in sets: source material +Licence: CC0 1.0 Universal (public domain dedication) + https://creativecommons.org/publicdomain/zero/1.0/ +Sources: + VSCO-2 Community Edition https://github.com/sgossner/VSCO-2-CE (Versilian Studios, CC0-1.0) + VCSL https://github.com/sgossner/VCSL (Versilian Studios, CC0-1.0) + Sonic Pi sample set https://github.com/sonic-pi-net/sonic-pi/tree/main/etc/samples (CC0, freesound.org) +Each file is retuned, cut and coloured (tools/gen_builtin_hiphop.py) from: + +DUSTY/00_C3_m48.wav <- sgossner/VCSL/master/Chordophones/Zithers/Upright Piano, Knight/Sustains/Player_vl2_rr1_F2.wav +DUSTY/01_A3_m57.wav <- sgossner/VCSL/master/Chordophones/Zithers/Upright Piano, Knight/Sustains/Player_vl2_rr1_A2.wav +DUSTY/02_Fs4_m66.wav <- sgossner/VCSL/master/Chordophones/Zithers/Upright Piano, Knight/Sustains/Player_vl2_rr1_F3.wav +DUSTY/03_Ds5_m75.wav <- sgossner/VCSL/master/Chordophones/Zithers/Upright Piano, Knight/Sustains/Player_vl2_rr1_D#4.wav +BASS/00_E1_m52.wav <- sgossner/VSCO-2-CE/master/Strings/Solo Contrabass/Pizz/BKCtbss_Pizz_E0_v3_rr1.wav +BASS/01_B1_m59.wav <- sgossner/VSCO-2-CE/master/Strings/Solo Contrabass/Pizz/BKCtbss_Pizz_A#0_v3_rr1.wav +BASS/02_Fs2_m66.wav <- sgossner/VSCO-2-CE/master/Strings/Solo Contrabass/Pizz/BKCtbss_Pizz_F#1_v1_rr1.wav +BASS/03_Cs3_m73.wav <- sgossner/VSCO-2-CE/master/Strings/Solo Contrabass/Pizz/BKCtbss_Pizz_C#2_v1_rr1.wav +VIBES/00_F3_m53.wav <- sgossner/VCSL/master/Idiophones/Struck Idiophones/Vibraphone/Hard Mallets/Vibes_hard_F2_v3_rr1_Main.wav +VIBES/01_D4_m62.wav <- sgossner/VCSL/master/Idiophones/Struck Idiophones/Vibraphone/Hard Mallets/Vibes_hard_C3_v3_rr1_Main.wav +VIBES/02_B4_m71.wav <- sgossner/VCSL/master/Idiophones/Struck Idiophones/Vibraphone/Hard Mallets/Vibes_hard_B3_v3_rr1_Main.wav +HORNS/00_G3_m55.wav <- sgossner/VSCO-2-CE/master/Brass/Trumpet/stac/Sum_SHTrumpet_stac_F2_v3_rr1.wav + sgossner/VSCO-2-CE/master/Brass/Tenor Trombone/stac/tenortbn_stac_F1_v3_rr1.wav +HORNS/01_D4_m62.wav <- sgossner/VSCO-2-CE/master/Brass/Trumpet/stac/Sum_SHTrumpet_stac_D#3_v3_rr1.wav + sgossner/VSCO-2-CE/master/Brass/Tenor Trombone/stac/tenortbn_stac_F2_v3_rr1.wav +HORNS/02_A4_m69.wav <- sgossner/VSCO-2-CE/master/Brass/Trumpet/stac/Sum_SHTrumpet_stac_A#3_v3_rr1.wav + sgossner/VSCO-2-CE/master/Brass/Tenor Trombone/stac/tenortbn_stac_A#2_v3_rr1.wav +HORNS/03_E5_m76.wav <- sgossner/VSCO-2-CE/master/Brass/Trumpet/stac/Sum_SHTrumpet_stac_F4_v3_rr1.wav + sgossner/VSCO-2-CE/master/Brass/Tenor Trombone/stac/tenortbn_stac_F3_v3_rr1.wav +STRGS/00_G3_m55.wav <- sgossner/VSCO-2-CE/master/Strings/Violin Section/Spic/VlnEns_Spic_G2_v2_rr1.wav + sgossner/VSCO-2-CE/master/Strings/Viola Section/spic/Violas_spic_C2_v2_rr1.wav +STRGS/01_E4_m64.wav <- sgossner/VSCO-2-CE/master/Strings/Violin Section/Spic/VlnEns_Spic_D3_v2_rr1.wav + sgossner/VSCO-2-CE/master/Strings/Viola Section/spic/Violas_spic_E2_v2_rr1.wav +STRGS/02_Cs5_m73.wav <- sgossner/VSCO-2-CE/master/Strings/Violin Section/Spic/VlnEns_Spic_C4_v2_rr1.wav + sgossner/VSCO-2-CE/master/Strings/Viola Section/spic/Violas_spic_D3_v2_rr1.wav +SCRCH/00_vinyl_scratch_m57.wav <- sonic-pi-net/sonic-pi/main/etc/samples/vinyl_scratch.flac +SCRCH/01_vinyl_backspin_m65.wav <- sonic-pi-net/sonic-pi/main/etc/samples/vinyl_backspin.flac +SCRCH/02_vinyl_rewind_m72.wav <- sonic-pi-net/sonic-pi/main/etc/samples/vinyl_rewind.flac +FLUTE/00_LDFlute_susvib_C4_v1_1.wav <- sgossner/VSCO-2-CE: Woodwinds/Flute/susvib/LDFlute_susvib_C4_v1_1.wav +FLUTE/01_LDFlute_susvib_C5_v1_1.wav <- sgossner/VSCO-2-CE: Woodwinds/Flute/susvib/LDFlute_susvib_C5_v1_1.wav +FLUTE/02_LDFlute_susvib_C6_v1_1.wav <- sgossner/VSCO-2-CE: Woodwinds/Flute/susvib/LDFlute_susvib_C6_v1_1.wav +KIT/00_Tamb1_Hit_v2_rr1_Mid.wav <- sgossner/VCSL: Idiophones/Struck Idiophones/Tambourine 1/Tamb1_Hit_v2_rr1_Mid.wav +KIT/01_Mid_ShakerDouble_Down_rr1.wav <- sgossner/VCSL: Idiophones/Struck Idiophones/Shaker, Small/Mid_ShakerDouble_Down_rr1.wav +KIT/02_Conga_HitN_v2_rr1_Sum.wav <- sgossner/VCSL: Membranophones/Struck Membranophones/Conga/Conga_HitN_v2_rr1_Sum.wav +KIT/03_Claves1_Hit_v2_rr1_Mid.wav <- sgossner/VCSL: Idiophones/Struck Idiophones/Claves/Claves1_Hit_v2_rr1_Mid.wav +KIT/04_wood_click_mp.wav <- sgossner/VCSL: Idiophones/Struck Idiophones/Woodblock/wood_click_mp.wav diff --git a/assets/samples-cc0/BASS/00_E1_m52.wav b/assets/samples-cc0/BASS/00_E1_m52.wav new file mode 100644 index 0000000..a007dd3 Binary files /dev/null and b/assets/samples-cc0/BASS/00_E1_m52.wav differ diff --git a/assets/samples-cc0/BASS/01_B1_m59.wav b/assets/samples-cc0/BASS/01_B1_m59.wav new file mode 100644 index 0000000..19b10f2 Binary files /dev/null and b/assets/samples-cc0/BASS/01_B1_m59.wav differ diff --git a/assets/samples-cc0/BASS/02_Fs2_m66.wav b/assets/samples-cc0/BASS/02_Fs2_m66.wav new file mode 100644 index 0000000..7965bd5 Binary files /dev/null and b/assets/samples-cc0/BASS/02_Fs2_m66.wav differ diff --git a/assets/samples-cc0/BASS/03_Cs3_m73.wav b/assets/samples-cc0/BASS/03_Cs3_m73.wav new file mode 100644 index 0000000..52b6fce Binary files /dev/null and b/assets/samples-cc0/BASS/03_Cs3_m73.wav differ diff --git a/assets/samples-cc0/CREDITS.txt b/assets/samples-cc0/CREDITS.txt new file mode 100644 index 0000000..1448166 --- /dev/null +++ b/assets/samples-cc0/CREDITS.txt @@ -0,0 +1,15 @@ +Samples in the SAMPLE engine's built-in sets. All CC0 1.0 (public domain). + +DUSTY VCSL (Versilian Community Sample Library), Upright Piano (Knight) +VIBES VCSL, Vibraphone (hard mallets) https://github.com/sgossner/VCSL +BASS VSCO-2 Community Edition, Solo Contrabass pizzicato +HORNS VSCO-2 Community Edition, Trumpet + Tenor Trombone staccato +STRGS VSCO-2 Community Edition, Violin + Viola sections spiccato +FLUTE VSCO-2 Community Edition, Flute (susvib) https://github.com/sgossner/VSCO-2-CE +SCRCH Sonic Pi sample set (freesound.org CC0 recordings): vinyl_scratch (hello_flowers), + vinyl_backspin (il112), vinyl_rewind (TasmanianPower) + https://github.com/sonic-pi-net/sonic-pi/tree/main/etc/samples +KIT VCSL hand percussion (tambourine, shaker, conga, claves, woodblock) for the GM kit + +Thanks to Versilian Studios / Sam Gossner and to the Sonic Pi project. +Retuned, cut and coloured by tools/gen_builtin_hiphop.py (gen_hiphop_pack.py's chain). diff --git a/assets/samples-cc0/DUSTY/00_C3_m48.wav b/assets/samples-cc0/DUSTY/00_C3_m48.wav new file mode 100644 index 0000000..d60412c Binary files /dev/null and b/assets/samples-cc0/DUSTY/00_C3_m48.wav differ diff --git a/assets/samples-cc0/DUSTY/01_A3_m57.wav b/assets/samples-cc0/DUSTY/01_A3_m57.wav new file mode 100644 index 0000000..6e93299 Binary files /dev/null and b/assets/samples-cc0/DUSTY/01_A3_m57.wav differ diff --git a/assets/samples-cc0/DUSTY/02_Fs4_m66.wav b/assets/samples-cc0/DUSTY/02_Fs4_m66.wav new file mode 100644 index 0000000..c932d2d Binary files /dev/null and b/assets/samples-cc0/DUSTY/02_Fs4_m66.wav differ diff --git a/assets/samples-cc0/DUSTY/03_Ds5_m75.wav b/assets/samples-cc0/DUSTY/03_Ds5_m75.wav new file mode 100644 index 0000000..ad0c4e4 Binary files /dev/null and b/assets/samples-cc0/DUSTY/03_Ds5_m75.wav differ diff --git a/assets/samples-cc0/FLUTE/00_LDFlute_susvib_C4_v1_1.wav b/assets/samples-cc0/FLUTE/00_LDFlute_susvib_C4_v1_1.wav new file mode 100644 index 0000000..f40bfde Binary files /dev/null and b/assets/samples-cc0/FLUTE/00_LDFlute_susvib_C4_v1_1.wav differ diff --git a/assets/samples-cc0/FLUTE/01_LDFlute_susvib_C5_v1_1.wav b/assets/samples-cc0/FLUTE/01_LDFlute_susvib_C5_v1_1.wav new file mode 100644 index 0000000..f44a6a5 Binary files /dev/null and b/assets/samples-cc0/FLUTE/01_LDFlute_susvib_C5_v1_1.wav differ diff --git a/assets/samples-cc0/FLUTE/02_LDFlute_susvib_C6_v1_1.wav b/assets/samples-cc0/FLUTE/02_LDFlute_susvib_C6_v1_1.wav new file mode 100644 index 0000000..ff30bf5 Binary files /dev/null and b/assets/samples-cc0/FLUTE/02_LDFlute_susvib_C6_v1_1.wav differ diff --git a/assets/samples-cc0/HORNS/00_G3_m55.wav b/assets/samples-cc0/HORNS/00_G3_m55.wav new file mode 100644 index 0000000..077e525 Binary files /dev/null and b/assets/samples-cc0/HORNS/00_G3_m55.wav differ diff --git a/assets/samples-cc0/HORNS/01_D4_m62.wav b/assets/samples-cc0/HORNS/01_D4_m62.wav new file mode 100644 index 0000000..45c3528 Binary files /dev/null and b/assets/samples-cc0/HORNS/01_D4_m62.wav differ diff --git a/assets/samples-cc0/HORNS/02_A4_m69.wav b/assets/samples-cc0/HORNS/02_A4_m69.wav new file mode 100644 index 0000000..7f5373d Binary files /dev/null and b/assets/samples-cc0/HORNS/02_A4_m69.wav differ diff --git a/assets/samples-cc0/HORNS/03_E5_m76.wav b/assets/samples-cc0/HORNS/03_E5_m76.wav new file mode 100644 index 0000000..c5fd61c Binary files /dev/null and b/assets/samples-cc0/HORNS/03_E5_m76.wav differ diff --git a/assets/samples-cc0/KIT/00_Tamb1_Hit_v2_rr1_Mid.wav b/assets/samples-cc0/KIT/00_Tamb1_Hit_v2_rr1_Mid.wav new file mode 100644 index 0000000..aad9558 Binary files /dev/null and b/assets/samples-cc0/KIT/00_Tamb1_Hit_v2_rr1_Mid.wav differ diff --git a/assets/samples-cc0/KIT/01_Mid_ShakerDouble_Down_rr1.wav b/assets/samples-cc0/KIT/01_Mid_ShakerDouble_Down_rr1.wav new file mode 100644 index 0000000..f993414 Binary files /dev/null and b/assets/samples-cc0/KIT/01_Mid_ShakerDouble_Down_rr1.wav differ diff --git a/assets/samples-cc0/KIT/02_Conga_HitN_v2_rr1_Sum.wav b/assets/samples-cc0/KIT/02_Conga_HitN_v2_rr1_Sum.wav new file mode 100644 index 0000000..9a0630a Binary files /dev/null and b/assets/samples-cc0/KIT/02_Conga_HitN_v2_rr1_Sum.wav differ diff --git a/assets/samples-cc0/KIT/03_Claves1_Hit_v2_rr1_Mid.wav b/assets/samples-cc0/KIT/03_Claves1_Hit_v2_rr1_Mid.wav new file mode 100644 index 0000000..4b5fd31 Binary files /dev/null and b/assets/samples-cc0/KIT/03_Claves1_Hit_v2_rr1_Mid.wav differ diff --git a/assets/samples-cc0/KIT/04_wood_click_mp.wav b/assets/samples-cc0/KIT/04_wood_click_mp.wav new file mode 100644 index 0000000..f625cb9 Binary files /dev/null and b/assets/samples-cc0/KIT/04_wood_click_mp.wav differ diff --git a/assets/samples-cc0/SCRCH/00_vinyl_scratch_m57.wav b/assets/samples-cc0/SCRCH/00_vinyl_scratch_m57.wav new file mode 100644 index 0000000..768f66a Binary files /dev/null and b/assets/samples-cc0/SCRCH/00_vinyl_scratch_m57.wav differ diff --git a/assets/samples-cc0/SCRCH/01_vinyl_backspin_m65.wav b/assets/samples-cc0/SCRCH/01_vinyl_backspin_m65.wav new file mode 100644 index 0000000..f8d35b9 Binary files /dev/null and b/assets/samples-cc0/SCRCH/01_vinyl_backspin_m65.wav differ diff --git a/assets/samples-cc0/SCRCH/02_vinyl_rewind_m72.wav b/assets/samples-cc0/SCRCH/02_vinyl_rewind_m72.wav new file mode 100644 index 0000000..178e23e Binary files /dev/null and b/assets/samples-cc0/SCRCH/02_vinyl_rewind_m72.wav differ diff --git a/assets/samples-cc0/STRGS/00_G3_m55.wav b/assets/samples-cc0/STRGS/00_G3_m55.wav new file mode 100644 index 0000000..676de33 Binary files /dev/null and b/assets/samples-cc0/STRGS/00_G3_m55.wav differ diff --git a/assets/samples-cc0/STRGS/01_E4_m64.wav b/assets/samples-cc0/STRGS/01_E4_m64.wav new file mode 100644 index 0000000..76ac5df Binary files /dev/null and b/assets/samples-cc0/STRGS/01_E4_m64.wav differ diff --git a/assets/samples-cc0/STRGS/02_Cs5_m73.wav b/assets/samples-cc0/STRGS/02_Cs5_m73.wav new file mode 100644 index 0000000..98d31ec Binary files /dev/null and b/assets/samples-cc0/STRGS/02_Cs5_m73.wav differ diff --git a/assets/samples-cc0/VIBES/00_F3_m53.wav b/assets/samples-cc0/VIBES/00_F3_m53.wav new file mode 100644 index 0000000..59026c9 Binary files /dev/null and b/assets/samples-cc0/VIBES/00_F3_m53.wav differ diff --git a/assets/samples-cc0/VIBES/01_D4_m62.wav b/assets/samples-cc0/VIBES/01_D4_m62.wav new file mode 100644 index 0000000..a546a33 Binary files /dev/null and b/assets/samples-cc0/VIBES/01_D4_m62.wav differ diff --git a/assets/samples-cc0/VIBES/02_B4_m71.wav b/assets/samples-cc0/VIBES/02_B4_m71.wav new file mode 100644 index 0000000..d135775 Binary files /dev/null and b/assets/samples-cc0/VIBES/02_B4_m71.wav differ diff --git a/build-sloop.ps1 b/build-sloop.ps1 new file mode 100644 index 0000000..3edf954 --- /dev/null +++ b/build-sloop.ps1 @@ -0,0 +1,21 @@ +# SLOOP: build the firmware, then open the browser installer. +# Needs a WSL distribution with the JieLi toolchain and the SDK files in build/deps/ac79 (BUILDING.md). +$ErrorActionPreference = 'Stop' +Set-Location $PSScriptRoot +$Distro = if ($env:SLOOP_WSL_DISTRO) { $env:SLOOP_WSL_DISTRO } else { 'Ubuntu' } +$Toolchain = if ($env:SLOOP_TOOLCHAIN) { $env:SLOOP_TOOLCHAIN } else { '/root/.jieli/toolchain' } +Write-Host "" +Write-Host " S L O O P 2.0" -ForegroundColor White +Write-Host " ---- ---- ---- ----" -ForegroundColor DarkGray +Write-Host "== Building the firmware (WSL $Distro)" -ForegroundColor Cyan +python tools/build_windows.py --distro $Distro --toolchain $Toolchain --sdk build/deps/ac79 +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.0 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 +Write-Host "Editor: http://localhost:8766/webapp/editor/" -ForegroundColor Green +Write-Host "Keep this window open during the install. Ctrl+C stops the server." +Start-Process "http://localhost:8766/webapp/installer/" +python -m http.server 8766 --bind 127.0.0.1 --directory build/sloop-site diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..dda5a5d --- /dev/null +++ b/build.sh @@ -0,0 +1,20 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-3.0-only +# Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments +# Build Felucca on macOS (see BUILDING.md). +# ./build.sh [--release X.Y] +# JIELI_TOOLCHAIN JieLi Linux toolchain (default: ~/.jieli/toolchain) +# AC79_SDK JieLi AC79 SDK checkout (default: ~/fw-AC79_AIoT_SDK) +set -e +cd "$(dirname "$0")" +export JIELI_TOOLCHAIN="${JIELI_TOOLCHAIN:-$HOME/.jieli/toolchain}" +export AC79_SDK="${AC79_SDK:-$HOME/fw-AC79_AIoT_SDK}" +PY="${PYTHON:-python3}" + +"$PY" -c 'import PIL' 2>/dev/null || { echo "build.sh: $PY has no Pillow (pip3 install Pillow)"; exit 1; } +[ -x "$JIELI_TOOLCHAIN/pi32v2/bin/clang" ] || { echo "build.sh: no toolchain in $JIELI_TOOLCHAIN (run tools/get_toolchain.sh)"; exit 1; } +[ -f "$AC79_SDK/cpu/wl82/tools/uboot.boot" ] || { echo "build.sh: no JieLi AC79 SDK in $AC79_SDK"; exit 1; } +if [ "$(uname -s)" != Linux ] || [ "$(uname -m)" != x86_64 ]; then + docker info >/dev/null 2>&1 || { echo "build.sh: Docker is not running"; exit 1; } +fi +exec "$PY" tools/build.py "$@" diff --git a/firmware/app.ld b/firmware/app.ld new file mode 100644 index 0000000..3e142e0 --- /dev/null +++ b/firmware/app.ld @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* Felucca memory map. + * Code + constants execute in place from XIP (app.bin offset 0 = 0x02000120). + * 0x01C00000..0x01C06000 holds .ram_text (code that must run while the flash + * is busy: the flash driver); 0x01C06000..0x01C08000 stays for RAM-run debug. + * RAM : .data/.bss (96 KiB) + * POOL : big zero-initialised buffers (FX lines, canvases), section .pool + * STACKS with 256-byte guard bands; NOINIT survives resets and UBOOT entry. + * 0x01C7FD50.. is reserved: boot_info, boot-state mailbox, vector table. */ +MEMORY +{ + XIP (rx) : ORIGIN = 0x02000120, LENGTH = 0x8DFBC + RAMTEXT (rwx): ORIGIN = 0x01C00000, LENGTH = 0x6000 + RAM (rwx) : ORIGIN = 0x01C08000, LENGTH = 96K + POOL (rw) : ORIGIN = 0x01C20000, LENGTH = 0x54000 + NOINIT (rw) : ORIGIN = 0x01C7C000, LENGTH = 0x3D50 +} +SECTIONS +{ + .text : { KEEP(*(.text.crt0)) *(.text*) *(.rodata*) . = ALIGN(4); _etext = .; } > XIP + .ram_text : { _rt_start = .; KEEP(*(.ram_text*)) . = ALIGN(4); _rt_end = .; } > RAMTEXT AT > XIP + _rt_load = LOADADDR(.ram_text); + .data : { . = ALIGN(4); _data_start = .; *(.data*) *(.sdata*) . = ALIGN(4); _data_end = .; } > RAM AT > XIP + _data_load = LOADADDR(.data); + .bss (NOLOAD) : { _bss_start = .; *(.bss*) *(.sbss*) *(COMMON) . = ALIGN(4); _bss_end = .; } > RAM + .pool (NOLOAD) : { _pool_start = .; *(.pool*) . = ALIGN(4); _pool_end = .; } > POOL + .noinit (NOLOAD) : { *(.noinit*) } > NOINIT + _guard0 = 0x01C74000; _ustack_lo = 0x01C74100; _ustack_top = 0x01C7A000; + _guard1 = 0x01C7A000; _sstack_lo = 0x01C7A100; _sstack_top = 0x01C7C000; + /DISCARD/ : { *(.comment) *(.note*) } +} diff --git a/firmware/crt0.S b/firmware/crt0.S new file mode 100644 index 0000000..5176548 --- /dev/null +++ b/firmware/crt0.S @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* App entry. The SPL maps app.bin at XIP 0x02000120 and jumps to its first + * byte with r0 = boot-parameter block (0x01C7FE08, inside the vector table). + * The SPL expects `goto +4; rts` as the first instruction. The core state + * the SPL left is saved first; then interrupts off and our stacks. */ + .section .text.crt0,"ax",@progbits + .globl _start +_start: + goto 1f + rts +1: r1 = icfg + r2 = psr + cli + r3 = 0x1C07F00 /* STATUS (debug area) */ + [r3 + 0x20] = r1 /* icfg as handed over */ + [r3 + 0x24] = r2 /* psr */ + [r3 + 0x28] = r0 /* boot-parameter pointer */ + r1 = sp + [r3 + 0x2C] = r1 + r1 = ssp + [r3 + 0x30] = r1 + sp = _ustack_top + ssp = _sstack_top + call fm1_cstart + goto . diff --git a/firmware/hal/fm1_adc.h b/firmware/hal/fm1_adc.h new file mode 100644 index 0000000..19b2536 --- /dev/null +++ b/firmware/hal/fm1_adc.h @@ -0,0 +1,45 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* FM-1 SARADC: PB6 = MASTER pot (ch4), + * PB1 = battery divider (ch3). Polled, 10 bit, from the main loop. + * + * fm1_adc_init() both pins analog inputs, no pulls + * fm1_adc_read(ch) 0..1023, -1 on timeout + */ +#pragma once +#include +#include "fm1_gpio.h" + +#define FM1_ADC_CON (*(volatile uint32_t *)0x13100u) +#define FM1_ADC_RES (*(volatile uint32_t *)0x13104u) +#define FM1_WLA_CON0 (*(volatile uint32_t *)0x11900u) +enum { FM1_ADC_BATT = 3, FM1_ADC_MASTER = 4 }; + +/* Both are only ever analog inputs: PB1 held low for 8 s would reset the + * chip (isd_config). */ +static void fm1_adc_init(void) +{ + uint32_t m = (1u << 6) | (1u << 1); + FM1_PR(FM1_PB, FM1_DIE) &= ~m; + FM1_PR(FM1_PB, FM1_PU) &= ~m; + FM1_PR(FM1_PB, FM1_PD) &= ~m; + FM1_PR(FM1_PB, FM1_DIR) |= m; +} + +static int32_t fm1_adc_read(uint32_t ch) +{ + uint32_t t, v; + FM1_ADC_CON = 0; + if (FM1_WLA_CON0 & (1u << 14)) + FM1_WLA_CON0 &= ~(1u << 14); + FM1_ADC_CON = 0xF04Eu | ((ch & 0xFu) << 8); + FM1_ADC_CON |= 0x10u; + FM1_ADC_CON |= 0x40u; + for (t = 0; t < 20000u; t++) + if (FM1_ADC_CON & 0x80u) + break; + v = FM1_ADC_RES & 0x3FFu; + FM1_ADC_CON = 0x40u; + FM1_ADC_CON = 0; + return t == 20000u ? -1 : (int32_t)v; +} diff --git a/firmware/hal/fm1_audio.h b/firmware/hal/fm1_audio.h new file mode 100644 index 0000000..02e2cc3 --- /dev/null +++ b/firmware/hal/fm1_audio.h @@ -0,0 +1,89 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* FM-1 audio out: ALNK0 I2S -> external codec, double-buffered DMA + * The application owns the buffer: two halves + * of half_words int32 (L, R, 24-bit left-justified), zeroed before init. + * + * fm1_audio_init(buf, half_words, isr, prio) codec and ALNK0 bring-up; + * isr = asm wrapper (fm1_isr.S) for FM1_IRQ_ALNK0 + * in the ISR: p = fm1_audio_pending(); fm1_audio_ack_aux(p); + * if (p & FM1_AUDIO_HALF) { fill fm1_audio_free_half(); + * fm1_audio_ack_half(); } + * fm1_audio_stop() DMA off (crash screen, UBOOT): no looping buzz + */ +#pragma once +#include +#include "fm1_cc.h" +#include "fm1_time.h" +#include "fm1_irq.h" +#include "fm1_gpio.h" + +#define FM1_ALNK 0x12E00u +#define FM1_ALNK_CON0 (*(volatile uint16_t *)(FM1_ALNK + 0x00u)) +#define FM1_ALNK_CON1 (*(volatile uint16_t *)(FM1_ALNK + 0x04u)) +#define FM1_ALNK_CON2 (*(volatile uint8_t *)(FM1_ALNK + 0x08u)) +#define FM1_ALNK_CON3 (*(volatile uint8_t *)(FM1_ALNK + 0x0Cu)) +#define FM1_ALNK_ADR3 (*(volatile uint32_t *)(FM1_ALNK + 0x1Cu)) +#define FM1_ALNK_LEN (*(volatile uint16_t *)(FM1_ALNK + 0x20u)) +#define FM1_CLK_CON2 (*(volatile uint32_t *)0x10014u) +#define FM1_IOMAP_CON5 (*(volatile uint32_t *)0x51030u) +#define FM1_AUDIO_HALF 0x80u /* CON2 pending: a half buffer is free */ + +static void fm1__pc_out(uint32_t bit, int v) /* codec control lines on PC0/1/2/6 */ +{ + uint32_t m = 1u << bit; + FM1_PR(FM1_PC, FM1_DIE) |= m; + if (v) + FM1_PR(FM1_PC, FM1_OUT) |= m; + else + FM1_PR(FM1_PC, FM1_OUT) &= ~m; + FM1_PR(FM1_PC, FM1_DIR) &= ~m; +} + +FM1_INLINE void fm1_audio_init(int32_t *buf, uint32_t half_words, void (*isr)(void), uint32_t prio) +{ + fm1__pc_out(6, 0); + fm1_delay_ms(5); + FM1_ALNK_CON0 = 0; + FM1_ALNK_CON1 = 0; + FM1_ALNK_CON2 = 0; + FM1_ALNK_CON3 = 0; + FM1_IOMAP_CON5 &= ~0xC0u; + FM1_ALNK_CON3 |= 3u; + fm1__pc_out(0, 1); + FM1_ALNK_CON0 |= 0x100u; + fm1__pc_out(2, 1); + fm1__pc_out(1, 1); + FM1_ALNK_CON0 |= 0x80u; + FM1_ALNK_CON0 &= ~0x40u; + FM1_ALNK_LEN = half_words; + FM1_ALNK_CON0 &= ~0x400u; + FM1_ALNK_CON0 &= ~0x200u; + FM1_CLK_CON2 &= 0xFFFFF0FFu; + FM1_ALNK_CON3 &= ~0x1Cu; + FM1_ALNK_CON3 = (uint8_t)((FM1_ALNK_CON3 & 0x1Fu) | 0x80u); + FM1_ALNK_CON1 |= 1u << 12; + FM1_ALNK_CON1 |= 1u << 14; + FM1_ALNK_ADR3 = (uint32_t)(uintptr_t)buf; + fm1__pc_out(6, 1); + FM1_ALNK_CON1 &= ~(1u << 15); + FM1_ALNK_CON2 = 0x0Fu; + fm1_irq_attach(FM1_IRQ_ALNK0, isr, prio); + FM1_ALNK_CON0 |= 0x800u; + fm1_delay_ms(5); + fm1__pc_out(6, 1); +} + +FM1_INLINE uint8_t fm1_audio_pending(void) { return FM1_ALNK_CON2; } +FM1_INLINE void fm1_audio_ack_aux(uint8_t p) /* the other three pendings */ +{ + if (p & 0x10u) + FM1_ALNK_CON2 |= 1u; + if (p & 0x20u) + FM1_ALNK_CON2 |= 2u; + if (p & 0x40u) + FM1_ALNK_CON2 |= 4u; +} +FM1_INLINE uint32_t fm1_audio_free_half(void) { return ((FM1_ALNK_CON0 >> 15) & 1u) ^ 1u; } /* 0 / 1 */ +FM1_INLINE void fm1_audio_ack_half(void) { FM1_ALNK_CON2 |= 0x08u; } +FM1_INLINE void fm1_audio_stop(void) { FM1_ALNK_CON0 &= ~0x800u; } diff --git a/firmware/hal/fm1_cc.h b/firmware/hal/fm1_cc.h new file mode 100644 index 0000000..948e81d --- /dev/null +++ b/firmware/hal/fm1_cc.h @@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* FM1_INLINE: register helpers that must inline into their caller, so the + * SFR access sequence (and its timing, in ISRs and IRQ-off sections) is the + * one written at the call site; -Os would otherwise out-line a helper with + * several callers. RAM-resident code (.ram_text) may only use these, never + * a called helper (build.py checks .ram_text for calls). */ +#pragma once + +#define FM1_INLINE static inline __attribute__((always_inline)) diff --git a/firmware/hal/fm1_flash.h b/firmware/hal/fm1_flash.h new file mode 100644 index 0000000..18ec13e --- /dev/null +++ b/firmware/hal/fm1_flash.h @@ -0,0 +1,263 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* FM-1 SPI NOR at runtime: erase / program / read. Used only when + * FELUCCA_FLASH is 1. + * + * Everything that executes while the SFC (XIP) is switched off lives in + * .ram_text and touches only SFRs, the stack and RAM buffers: no .rodata, no + * libcalls, no XIP-resident helpers. Call the fl_*_ram() entry points with + * interrupts disabled. Same sequence as the AC79 SDK flash driver + * (enter_spi_code, norflash_erase, norflash_wait_ok, exit_spi_code). + */ +#pragma once +#include +#include "fm1_xip.h" + +#define RAMFN __attribute__((section(".ram_text"), noinline, used)) +#define RAMINL static inline __attribute__((always_inline)) + +/* XIP (0x02xxxxxx) -> RAM (0x01C0xxxx) is beyond the 23-bit call range: + * call RAM code through a pointer the compiler cannot fold back. */ +static inline void *fl_far(void *p) { void *volatile q = p; return q; } +#define FL_FAR(fn) ((__typeof__(&fn))fl_far((void *)&fn)) + +#define REG32(a) (*(volatile uint32_t *)(a)) +#define SFC_CON REG32(0x40200u) /* bit31 busy; [11:8] read mode */ +#define SFCENC_CON (*(volatile uint8_t *)0x40300u) /* b0 decrypt, b1 plain window */ +#define SFCENC_UNENC_H REG32(0x40308u) /* WO, XIP (CPU) address */ +#define SFCENC_UNENC_L REG32(0x4030Cu) /* WO, XIP (CPU) address */ +#define SPI0_CON REG32(0x11C00u) /* b15 PND, b14 PCLR, b12 DIR=rx */ +#define SPI0_BUF REG32(0x11C08u) +#define IOMAP_CON0 REG32(0x5101Cu) /* b5: 1 = SFC owns the flash pins */ +#define PORTD_OUT REG32(0x500C0u) /* PD0 = flash CS# */ +#define PORTD_DIR REG32(0x500C8u) +#define CACHE_CON REG32(0x1EEE008u) /* b14 = cache idle */ +#define T4_CNT REG32(0x10804u) /* TIMER4, 24 MHz free-running */ + +#define FL_XIP(off) FM1_XIP(off) /* fm1_xip.h */ +#define FL_DATA_LO 0x00097000u /* Felucca main store */ +#define FL_DATA_HI 0x000E0000u +#define FL_GLOB_LO 0x000FC000u /* Felucca superblock / globals */ +#define FL_GLOB_HI 0x000FF000u +#define FL_OTA_LO 0x000E0000u /* M-UPGRADE loader staging, ota.c */ +#define FL_OTA_HI 0x000E5000u +/* [off, off + n) inside [lo, hi), without wrapping: off + n can overflow, and + * the 1 MiB part ignores the high address bits, so a wrapped range lands low. */ +#define FL_IN(off, n, lo, hi) ((uint32_t)(off) >= (lo) && (uint32_t)(off) <= (hi) && \ + (uint32_t)(n) <= (hi) - (uint32_t)(off)) +/* Felucca's own store (projects, user samples; settings) */ +#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)) +/* Where the RAM driver may erase / program. The app build allows only its own + * data regions; the update loader (firmware/loader) defines its own window. */ +#ifndef FL_RANGE_OK +#define FL_RANGE_OK(off, n) (FL_STORE_OK(off, n) || FL_IN(off, n, FL_OTA_LO, FL_OTA_HI)) +#endif + +typedef struct { uint32_t sfc_con, spi_con; } fl_saved_t; + +RAMINL void fl_csync(void) { __asm__ volatile("csync" ::: "memory"); } +RAMINL void fl_cache_idle(void) { while (!(CACHE_CON & 0x4000u)) ; } +RAMINL void fl_delay(uint32_t n) { volatile uint32_t i = n; while (i--) ; } + +RAMINL void fl_cs(int high) +{ + PORTD_DIR &= ~1u; + if (high) PORTD_OUT |= 1u; else PORTD_OUT &= ~1u; + fl_delay(10); +} +RAMINL int fl_spi_wait(void) +{ + uint32_t n = 50000000u; + fl_csync(); + while (!(SPI0_CON & 0x8000u)) + if (--n == 0) break; + SPI0_CON |= 0x4000u; + return n ? 0 : -1; +} +RAMINL void fl_tx(uint8_t b) +{ + SPI0_CON |= 8u; SPI0_CON &= ~0x1000u; + SPI0_BUF = b; fl_spi_wait(); + SPI0_CON &= ~8u; +} +RAMINL uint8_t fl_rx(void) +{ + uint8_t v; + SPI0_CON |= 8u; SPI0_CON |= 0x1000u; + SPI0_BUF = 0xFFu; fl_spi_wait(); + v = (uint8_t)SPI0_BUF; + SPI0_CON &= ~8u; + return v; +} +RAMINL void fl_addr(uint32_t a) { fl_tx((uint8_t)(a >> 16)); fl_tx((uint8_t)(a >> 8)); fl_tx((uint8_t)a); } +RAMINL uint8_t fl_rdsr(uint8_t cmd) { uint8_t v; fl_cs(0); fl_tx(cmd); v = fl_rx(); fl_cs(1); return v; } +RAMINL void fl_wren(void) { fl_cs(0); fl_tx(0x06); fl_cs(1); } + +RAMINL int fl_enter(fl_saved_t *s) +{ + uint32_t mode; + fl_cache_idle(); + s->sfc_con = SFC_CON; + s->spi_con = SPI0_CON; + mode = (s->sfc_con >> 8) & 0xFu; + if (mode == 6u || mode == 7u) /* continuous-read XIP: not handled here */ + return -1; + fl_csync(); + while ((int32_t)SFC_CON < 0) ; /* SFC idle */ + SFC_CON = 0; /* XIP OFF from here on */ + IOMAP_CON0 &= ~0x20u; /* pins -> SPI0 / GPIO */ + SPI0_CON = 0; + SPI0_CON = 0x1029u; /* SDK default */ + fl_csync(); + return 0; +} +RAMINL void fl_exit(const fl_saved_t *s) +{ + SPI0_CON = s->spi_con; + IOMAP_CON0 |= 0x20u; + fl_csync(); + while ((int32_t)SFC_CON < 0) ; + SFC_CON = s->sfc_con; /* XIP back on */ + fl_csync(); +} +RAMINL void fl_inval(uint32_t off, uint32_t len) +{ + uint32_t a = FL_XIP(off) & ~31u, e = FL_XIP(off) + len; + fl_cache_idle(); + for (; a < e; a += 32u) { + fl_csync(); + __asm__ volatile("flushinv [%0]" :: "r"(a) : "memory"); + fl_csync(); + fl_cache_idle(); + } +} +RAMINL int fl_wait_ready(uint32_t max_us, uint32_t *took_us) +{ + uint32_t t0 = T4_CNT, dt; + for (;;) { + dt = (T4_CNT - t0) / 24u; + if (!(fl_rdsr(0x05) & 1u)) { *took_us = dt; return 0; } + if (dt > max_us) { *took_us = dt; return -4; } + } +} + +/* ---- entry points: IRQs OFF, args/buffers in RAM ---- */ + +static RAMFN uint32_t fl_jedec_ram(void) /* expect 0x856014 */ +{ + fl_saved_t s; uint32_t id; + if (fl_enter(&s)) return 0; + fl_cs(0); fl_tx(0x9F); + id = (uint32_t)fl_rx() << 16; id |= (uint32_t)fl_rx() << 8; id |= fl_rx(); + fl_cs(1); + fl_exit(&s); + return id; +} + +static RAMFN uint32_t fl_status_ram(void) /* SR1 | SR2 << 8 */ +{ + fl_saved_t s; uint32_t v; + if (fl_enter(&s)) return 0xFFFFFFFFu; + v = fl_rdsr(0x05) | ((uint32_t)fl_rdsr(0x35) << 8); + fl_exit(&s); + return v; +} + +static RAMFN int fl_erase4k_ram(uint32_t off, uint32_t *took_us) +{ + fl_saved_t s; int rc; + if (!FL_RANGE_OK(off, 0x1000u) || (off & 0xFFFu)) + return -1; + if (fl_enter(&s)) return -2; + fl_wren(); + if (!(fl_rdsr(0x05) & 2u)) rc = -3; /* WEL did not set */ + else { + fl_cs(0); fl_tx(0x20); fl_addr(off); fl_cs(1); + fl_inval(off, 4096u); + rc = fl_wait_ready(500000u, took_us); /* generic NOR max 400 ms */ + } + fl_exit(&s); + return rc; +} + +static RAMFN int fl_prog_ram(uint32_t off, const uint8_t *src, uint32_t n, uint32_t *took_us) +{ + fl_saved_t s; int rc; uint32_t i; + if (!FL_RANGE_OK(off, n) || + n == 0 || n > 256u || ((off & 0xFFu) + n) > 256u) return -1; /* one page, no wrap */ + if (fl_enter(&s)) return -2; + fl_wren(); + if (!(fl_rdsr(0x05) & 2u)) rc = -3; + else { + fl_cs(0); fl_tx(0x02); fl_addr(off); + for (i = 0; i < n; i++) fl_tx(src[i]); + fl_cs(1); + fl_inval(off, n); + rc = fl_wait_ready(10000u, took_us); /* generic NOR max 3 ms */ + } + fl_exit(&s); + return rc; +} + +static RAMFN int fl_read_ram(uint32_t off, uint8_t *dst, uint32_t n) /* 0x0B fast read */ +{ + fl_saved_t s; uint32_t i; + if (fl_enter(&s)) return -2; + fl_cs(0); fl_tx(0x0B); fl_addr(off); fl_tx(0xFF); + for (i = 0; i < n; i++) dst[i] = fl_rx(); + fl_cs(1); + fl_exit(&s); + return 0; +} + +/* ---- XIP side (normal .text) ---- */ + +/* Once at boot, before any XIP read of the data region: map the data area + * as an unencrypted XIP window (as the SDK's IOCTL_SET_VM_INFO does). */ +static void fl_plain_window_init(void) +{ + SFCENC_CON &= (uint8_t)~2u; + SFCENC_UNENC_L = FL_XIP(0x93000u); /* 0x0208F000 */ + SFCENC_UNENC_H = 0x07FFFFFFu; + SFCENC_CON |= 2u; + __asm__ volatile("cli" ::: "memory"); + fl_inval(0x93000u, 0x100000u - 0x93000u); /* drop any decrypted lines */ + __asm__ volatile("csync\n\tsti" ::: "memory"); +} + +static inline uint32_t irq_save(void) { __asm__ volatile("cli" ::: "memory"); return 0; } +static inline void irq_restore(uint32_t f) { (void)f; __asm__ volatile("csync\n\tsti" ::: "memory"); } + +static int fl_erase4k(uint32_t off, uint32_t *took_us) +{ + uint32_t f = irq_save(); + int rc = FL_FAR(fl_erase4k_ram)(off, took_us); + irq_restore(f); + return rc; +} + +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; + uint32_t f; + if (chunk > n) chunk = n; + f = irq_save(); + rc = FL_FAR(fl_prog_ram)(off, src_ram, chunk, &took); + irq_restore(f); + if (rc) return rc; + off += chunk; src_ram += chunk; n -= chunk; + } + return 0; +} + +/* Read back through XIP (needs fl_plain_window_init) and compare. */ +static int fl_verify_xip(uint32_t off, const uint8_t *ref, uint32_t n) +{ + const volatile uint8_t *p = (const volatile uint8_t *)FL_XIP(off); + uint32_t i; + for (i = 0; i < n; i++) if (p[i] != ref[i]) return -(int)(i + 1); + return 0; +} diff --git a/firmware/hal/fm1_gpio.h b/firmware/hal/fm1_gpio.h new file mode 100644 index 0000000..cb7db8c --- /dev/null +++ b/firmware/hal/fm1_gpio.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* FM-1 GPIO port registers: one 0x40 block per + * port at 0x50000 + p * 0x40. HAL-internal: src/ uses the per-driver + * helpers (fm1_input.h, fm1_audio.h, fm1_adc.h, fm1_lcd_hw.h). */ +#pragma once +#include + +#define FM1_PORT(p) (0x50000u + (p) * 0x40u) +#define FM1_PR(p, r) (*(volatile uint32_t *)(FM1_PORT(p) + (r))) +enum { FM1_PA = 0, FM1_PB = 1, FM1_PC = 2, FM1_PH = 7 }; +enum { FM1_OUT = 0x00, FM1_IN = 0x04, FM1_DIR = 0x08, FM1_DIE = 0x0C, FM1_PU = 0x10, + FM1_PD = 0x14, FM1_HD0 = 0x18, FM1_HD = 0x1C }; diff --git a/firmware/hal/fm1_guard.h b/firmware/hal/fm1_guard.h new file mode 100644 index 0000000..8231e31 --- /dev/null +++ b/firmware/hal/fm1_guard.h @@ -0,0 +1,105 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* FM-1 hardware guards. Every violation raises the CPU exception (vector 1) and + * ends in the fault report of fm1_irq.h, so install that first. + * + * EMU stack limit sp outside [_ustack_lo, _sstack_top] -> EMU_MSG bit 3. + * One window for both stacks: which of EMU_SSP/EMU_USP + * the core applies to our supervisor-mode main loop is + * not known, so both get the same range. + * write limits CPU0 writes into the two 256-byte stack guard bands and + * into 0x01C7FD50..0x01C7FFFF (boot info, mailbox, vectors) + * -> DBG_MSG bit 13. The top window is armed separately + * with fm1_guard_lock_top() once every vector is + * attached; fm1_guard_unlock_top() reopens it. + * bus-invalid fetch/read/write of unmapped space (NULL page, XIP + * writes) -> DBG_MSG bits 4, 5, 16..21. + * PC limit instruction fetch outside [0x02000120, _etext] + * -> DBG_MSG bit 12. + */ +#pragma once +#include +#include "fm1_irq.h" + +#define FM1_X2(off) (*(volatile uint32_t *)(0x1EEE000u + (off))) +#define FM1_WR_LIMIT_H(n) FM1_X2(0x280u + 4u * (n)) +#define FM1_WR_LIMIT_L(n) FM1_X2(0x2C0u + 4u * (n)) +#define FM1_C0_WR_LIMIT_EN FM1_X2(0x348u) +#define FM1_PC_LIMIT0_H FM1_X2(0x380u) +#define FM1_PC_LIMIT0_L FM1_X2(0x384u) +#define FM1_PC_LIMIT1_H FM1_X2(0x388u) +#define FM1_PC_LIMIT1_L FM1_X2(0x38Cu) +#define FM1_EMU_SSP_H (*(volatile uint32_t *)0x1EEF0D8u) +#define FM1_EMU_SSP_L (*(volatile uint32_t *)0x1EEF0DCu) +#define FM1_EMU_USP_H (*(volatile uint32_t *)0x1EEF0E0u) +#define FM1_EMU_USP_L (*(volatile uint32_t *)0x1EEF0E4u) + +extern char _guard0[], _ustack_lo[], _guard1[], _sstack_lo[], _sstack_top[], _etext[]; +extern uint32_t _rt_start[], _rt_end[]; + +enum { FM1_GUARD_STACK = 1, FM1_GUARD_WRITE = 2, FM1_GUARD_BUS = 4, FM1_GUARD_PC = 8 }; + +static void fm1__dbg_unlock(void) +{ + if (!(FM1_DBG_WR_EN & 1u)) + FM1_DBG_WR_EN = 0xE7u; +} + +static void fm1__dbg_lock(void) +{ + if (FM1_DBG_WR_EN & 1u) + FM1_DBG_WR_EN = 0xE7u; +} + +static void fm1_guard_enable(uint32_t which) +{ + fm1__dbg_unlock(); + FM1_DBG_MSG_CLR = 0xFFFFFFFFu; + if (which & FM1_GUARD_STACK) { + FM1_EMU_CON &= ~(1u << 3); + FM1_EMU_SSP_L = (uint32_t)(uintptr_t)_ustack_lo; + FM1_EMU_SSP_H = (uint32_t)(uintptr_t)_sstack_top; + FM1_EMU_USP_L = (uint32_t)(uintptr_t)_ustack_lo; + FM1_EMU_USP_H = (uint32_t)(uintptr_t)_sstack_top; + FM1_EMU_CON |= 1u << 3; + } + if (which & FM1_GUARD_WRITE) { + FM1_WR_LIMIT_L(0) = (uint32_t)(uintptr_t)_guard0; + FM1_WR_LIMIT_H(0) = (uint32_t)(uintptr_t)_ustack_lo - 1u; + FM1_WR_LIMIT_L(1) = (uint32_t)(uintptr_t)_guard1; + FM1_WR_LIMIT_H(1) = (uint32_t)(uintptr_t)_sstack_lo - 1u; + FM1_C0_WR_LIMIT_EN |= 3u; + } + if (which & FM1_GUARD_BUS) + FM1_DBG_EN |= (0x3Fu << 16) | (0x3u << 4); + if (which & FM1_GUARD_PC) { + FM1_PC_LIMIT0_L = 0x02000120u; + FM1_PC_LIMIT0_H = (uint32_t)(uintptr_t)_etext; + { /* RAM code (.ram_text); with none, repeat the XIP window */ + volatile uint32_t rs = (uint32_t)(uintptr_t)_rt_start, re = (uint32_t)(uintptr_t)_rt_end; + FM1_PC_LIMIT1_L = re > rs ? rs : 0x02000120u; + FM1_PC_LIMIT1_H = re > rs ? re - 1u : (uint32_t)(uintptr_t)_etext; + } + } + fm1__dbg_lock(); +} + +/* write-protect 0x01C7FD50..0x01C7FFFF (boot info, mailbox, vectors): + * call after the last fm1_irq_attach */ +static void fm1_guard_lock_top(void) +{ + fm1__dbg_unlock(); + FM1_DBG_MSG_CLR = 0xFFFFFFFFu; + FM1_WR_LIMIT_L(2) = 0x01C7FD50u; + FM1_WR_LIMIT_H(2) = 0x01C7FFFFu; + FM1_C0_WR_LIMIT_EN |= 4u; + fm1__dbg_lock(); +} + +/* reopen the reserved top of RAM (mailbox write before a UBOOT reset) */ +static void fm1_guard_unlock_top(void) +{ + fm1__dbg_unlock(); + FM1_C0_WR_LIMIT_EN &= ~4u; + fm1__dbg_lock(); +} diff --git a/firmware/hal/fm1_input.h b/firmware/hal/fm1_input.h new file mode 100644 index 0000000..806d1c8 --- /dev/null +++ b/firmware/hal/fm1_input.h @@ -0,0 +1,323 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* FM-1 input HAL: key/button/encoder matrix and LEDs. + * + * One 11-column x 6-row diode matrix behind a 2x74HC595 chain (PA4 SER, PA3 + * SRCLK, PA1 RCLK), bit-banged and polled; rows PA0, PA5..PA8, PB7 with + * pull-ups (low = closed). LED lines PH6/PH9/PA9/PA10 light the LED on the + * same column, row PA7/PA8/PA5/PA6 respectively. + * + * fm1_input_init(); + * polled: for (;;) { fm1_input_scan(); ... } + * IRQ: call fm1_input_tick() from a ~10 kHz timer ISR; it advances one + * column per call (rows are sampled one tick after the column was + * latched, LEDs stay lit in between) and processes a frame every + * FM1_NCOL ticks. The main loop reads fm1_in.notes / buttons and + * takes edges/steps with fm1_input_edges() / fm1_enc_take(). + * + * fm1_input_scan() runs one full frame (11 columns, ~0.6 ms) and calls + * FM1_INPUT_IDLE() while it waits. + * Keys/buttons: integrating debounce, asymmetric: a press counts after FM1_PRESS closed + * frames (~3 ms: notes are played in time), a release once the count is back to 0 (up to + * FM1_DEBOUNCE frames), so contact bounce never retriggers. + * Encoders: quadrature decoder (2-sample filter, + = clockwise) with detent + * counting: states an encoder rests in for >= FM1_REST_FRAMES are learned, and + * a step is emitted only on reaching a rest state after >= 2 net transitions. + * One click = one step at any speed, whether a detent is a half or a full + * quadrature cycle. fm1_enc_take() returns the steps. + * LEDs: set fm1_led[col] (packed row bits, bit1 PA5..bit4 PA8); they are lit + * while that column is selected. fm1_led_key/btn helpers address them by id. + */ +#pragma once +#include +#include "fm1_time.h" +#include "fm1_gpio.h" + +#ifndef FM1_INPUT_IDLE +#define FM1_INPUT_IDLE() ((void)0) +#endif +#ifndef FM1_LED_US +#define FM1_LED_US 40u /* LED on-time per column (brightness vs scan rate) */ +#endif +#define FM1_DEBOUNCE 8u /* frames (~1.1 ms each in the IRQ scan): a release */ +#define FM1_PRESS 3u /* a press: fast (keys are played in time), still 3 frames sure */ +#define FM1_SETTLE_US 10u +#define FM1_REST_FRAMES 40u /* ~25 ms still = a detent position */ +#define FM1_NCOL 11u +#define FM1_NKEY 41u /* ids: 0..13 buttons, 14..40 note keys */ +#define FM1_NENC 7u + + +/* key id at (physical column, packed row bit), -1 = none */ +static const int8_t FM1_KEYMAP[6][FM1_NCOL] = { + {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, /* PA0: encoders */ + { 5, 11, 4, 10, 3, 9, 2, 8, -1, -1, -1}, /* PA5 */ + {34, 35, 36, 37, 38, 40, 39, 13, 7, 6, 12}, /* PA6 */ + {23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33}, /* PA7 */ + { 0, 1, 15, 14, 17, 16, 19, 18, 20, 21, 22}, /* PA8 */ + {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, /* PB7: encoder 6 */ +}; +/* encoder i: A at (col, row bit), B at (col, row bit) */ +static const uint8_t FM1_ENC[FM1_NENC][4] = { + {0, 0, 1, 0}, {2, 0, 3, 0}, {8, 1, 9, 1}, {8, 0, 9, 0}, {6, 0, 7, 0}, {4, 0, 5, 0}, {0, 5, 1, 5}, +}; +enum { FM1_BTN_OCT_DOWN = 0, FM1_BTN_OCT_UP = 1 }; + +static const int8_t FM1_LED_PORT[6] = {-1, FM1_PA, FM1_PA, FM1_PH, FM1_PH, -1}; +static const uint8_t FM1_LED_BIT[6] = {0, 9, 10, 6, 9, 0}; + +static volatile struct { + uint32_t notes; /* debounced: bit n = note key n (0 = F3 .. 26 = G5) */ + uint32_t buttons; /* debounced: bit i = button i (0..13) */ + uint32_t pressed, released; /* button edges since the last fm1_input_edges() */ + uint32_t notes_pressed; /* note-key press edges since the last fm1_input_note_edges() */ + uint8_t raw[FM1_NCOL]; /* last frame, packed rows, 1 = closed */ + uint8_t cnt[FM1_NKEY]; + uint8_t enc_prev[FM1_NENC], enc_last[FM1_NENC]; + uint8_t enc_rest[FM1_NENC]; /* learned rest (detent) states, bit per state */ + uint8_t enc_still[FM1_NENC]; /* frames since the last state change */ + int8_t enc_sub[FM1_NENC]; /* net transitions since the last rest state */ + int16_t enc_steps[FM1_NENC]; /* + = clockwise */ + uint32_t frames; +} fm1_in; +static uint8_t fm1_led[FM1_NCOL]; + +static void fm1__led_lines(uint32_t rowmask) +{ + uint32_t r; + for (r = 1; r < 5u; r++) { + if (rowmask & (1u << r)) + FM1_PR(FM1_LED_PORT[r], FM1_OUT) |= 1u << FM1_LED_BIT[r]; + else + FM1_PR(FM1_LED_PORT[r], FM1_OUT) &= ~(1u << FM1_LED_BIT[r]); + } +} + +static void fm1__sr_word(uint32_t w) +{ + uint32_t i; + for (i = 0; i < 16u; i++) { + if (w & (0x8000u >> i)) + FM1_PR(FM1_PA, FM1_OUT) |= 1u << 4; + else + FM1_PR(FM1_PA, FM1_OUT) &= ~(1u << 4); + FM1_PR(FM1_PA, FM1_OUT) |= 1u << 3; /* each SFR write is far slower than the 595 needs */ + FM1_PR(FM1_PA, FM1_OUT) &= ~(1u << 3); + } + FM1_PR(FM1_PA, FM1_OUT) |= 1u << 1; + FM1_PR(FM1_PA, FM1_OUT) &= ~(1u << 1); +} + +static uint32_t fm1__rows(void) +{ + uint32_t a = FM1_PR(FM1_PA, FM1_IN), b = FM1_PR(FM1_PB, FM1_IN); + return (~((a & 1u) | ((a >> 4) & 0x1Eu) | ((b >> 2) & 0x20u))) & 0x3Fu; +} + +static void fm1__wait(uint32_t us) +{ + uint32_t t0 = fm1_ticks(), span = us * FM1_TICKS_PER_US; + while ((uint32_t)(fm1_ticks() - t0) < span) + FM1_INPUT_IDLE(); +} + +static void fm1_input_init(void) +{ + static const uint8_t LEDP[4][2] = {{FM1_PH, 6}, {FM1_PH, 9}, {FM1_PA, 9}, {FM1_PA, 10}}; + const uint32_t rows_a = (1u << 0) | (1u << 5) | (1u << 6) | (1u << 7) | (1u << 8); + const uint32_t sr = (1u << 1) | (1u << 3) | (1u << 4), row_b = 1u << 7; + uint32_t i; + for (i = 0; i < 4u; i++) { + uint32_t p = LEDP[i][0], m = 1u << LEDP[i][1]; + FM1_PR(p, FM1_DIE) |= m; + FM1_PR(p, FM1_OUT) &= ~m; + FM1_PR(p, FM1_DIR) &= ~m; + FM1_PR(p, FM1_HD0) |= m; + FM1_PR(p, FM1_HD) |= m; + } + FM1_PR(FM1_PA, FM1_DIE) |= rows_a; + FM1_PR(FM1_PA, FM1_DIR) |= rows_a; + FM1_PR(FM1_PA, FM1_PD) &= ~rows_a; + FM1_PR(FM1_PA, FM1_PU) |= rows_a; + FM1_PR(FM1_PB, FM1_DIE) |= row_b; + FM1_PR(FM1_PB, FM1_DIR) |= row_b; + FM1_PR(FM1_PB, FM1_PD) &= ~row_b; + FM1_PR(FM1_PB, FM1_PU) |= row_b; + FM1_PR(FM1_PA, FM1_DIE) |= sr; + FM1_PR(FM1_PA, FM1_PU) &= ~sr; + FM1_PR(FM1_PA, FM1_PD) &= ~sr; + FM1_PR(FM1_PA, FM1_OUT) &= ~sr; + FM1_PR(FM1_PA, FM1_DIR) &= ~sr; + fm1__sr_word(0xFFFFu); + for (i = 0; i < FM1_NENC; i++) + fm1_in.enc_prev[i] = fm1_in.enc_last[i] = 0xFF; /* seeded by the first frame */ +} + +static void fm1__key(uint32_t id, uint32_t closed) +{ + volatile uint8_t *c = &fm1_in.cnt[id]; + uint32_t on; + if (closed) { + if (*c < FM1_DEBOUNCE) + (*c)++; + } else if (*c) { + (*c)--; + } + if (closed && *c >= FM1_PRESS) + on = 1; + else if (*c == 0) + on = 0; + else + return; + if (id >= 14u) { + if (on) { + if (!(fm1_in.notes & (1u << (id - 14u)))) + fm1_in.notes_pressed |= 1u << (id - 14u); + fm1_in.notes |= 1u << (id - 14u); + } + else + fm1_in.notes &= ~(1u << (id - 14u)); + } else if (on != ((fm1_in.buttons >> id) & 1u)) { + fm1_in.buttons ^= 1u << id; + if (on) + fm1_in.pressed |= 1u << id; + else + fm1_in.released |= 1u << id; + } +} + +static void fm1__frame(void); + +static void fm1_input_scan(void) +{ + uint32_t p; + for (p = 0; p < FM1_NCOL; p++) { + fm1__led_lines(0); + fm1__sr_word(0xFFFFu ^ (1u << p) ^ (p < 2u ? 1u << (11u + p) : 0u)); + fm1__wait(FM1_SETTLE_US); + fm1_in.raw[p] = (uint8_t)fm1__rows(); + fm1__led_lines(fm1_led[p]); + fm1__wait(FM1_LED_US); + } + fm1__led_lines(0); + fm1__frame(); +} + +static void fm1__frame(void) +{ + uint32_t p, r, e; + for (p = 0; p < FM1_NCOL; p++) + for (r = 1; r < 5u; r++) + if (FM1_KEYMAP[r][p] >= 0) + fm1__key((uint32_t)FM1_KEYMAP[r][p], (fm1_in.raw[p] >> r) & 1u); + for (e = 0; e < FM1_NENC; e++) { /* quadrature decoder + detents */ + const uint8_t *m = FM1_ENC[e]; + uint32_t cur = ((fm1_in.raw[m[0]] >> m[1]) & 1u) << 1 | ((fm1_in.raw[m[2]] >> m[3]) & 1u); + uint32_t idx; + volatile int8_t *sub = &fm1_in.enc_sub[e]; + if (cur != fm1_in.enc_last[e]) { + fm1_in.enc_last[e] = (uint8_t)cur; + fm1_in.enc_still[e] = 0; + continue; + } + if (fm1_in.enc_prev[e] == 0xFF) { /* first frame: the knob rests here */ + fm1_in.enc_prev[e] = (uint8_t)cur; + fm1_in.enc_rest[e] = (uint8_t)(1u << cur); + } + if (fm1_in.enc_still[e] < 255u && ++fm1_in.enc_still[e] == FM1_REST_FRAMES) { + /* learn detent states: one state, or a complementary pair (00/11 or + * 01/10). Anything else restarts the set; with 3-4 rest states every + * arrival would look like a detent with |sub| < 2. */ + uint32_t r = fm1_in.enc_rest[e], bit = 1u << cur, comp = 1u << (cur ^ 3u); + if (!(r & bit)) + fm1_in.enc_rest[e] = (uint8_t)(r == comp ? (r | bit) : bit); + } + if (cur == fm1_in.enc_prev[e]) + continue; + idx = (uint32_t)fm1_in.enc_prev[e] << 2 | cur; + if ((0x4182u >> idx) & 1u) + (*sub)++; + else if ((0x2814u >> idx) & 1u) + (*sub)--; + fm1_in.enc_prev[e] = (uint8_t)cur; + if ((fm1_in.enc_rest[e] >> cur) & 1u) { /* back on a detent */ + if (*sub >= 2) + fm1_in.enc_steps[e]++; + else if (*sub <= -2) + fm1_in.enc_steps[e]--; + *sub = 0; + } + } + fm1_in.frames++; +} + +/* one column per call, from a timer ISR (see top) */ +static uint8_t fm1__tick_col; +static void fm1_input_tick(void) +{ + uint32_t p = fm1__tick_col, n = p + 1u == FM1_NCOL ? 0u : p + 1u; + fm1__led_lines(0); + fm1_in.raw[p] = (uint8_t)fm1__rows(); /* column p has been latched one tick */ + fm1__sr_word(0xFFFFu ^ (1u << n) ^ (n < 2u ? 1u << (11u + n) : 0u)); + fm1__led_lines(fm1_led[n]); + fm1__tick_col = (uint8_t)n; + if (n == 0u) + fm1__frame(); +} + +/* main-loop critical section against fm1_input_tick (main loop only: it + * re-enables interrupts unconditionally) */ +static inline uint32_t fm1__lock(void) +{ + __asm__ volatile("cli" ::: "memory"); + return 0; +} +static inline void fm1__unlock(uint32_t v) +{ + (void)v; + __asm__ volatile("csync\n\tsti" ::: "memory"); +} + +/* detent steps turned since the last call, + = clockwise */ +static int32_t fm1_enc_take(uint32_t e) +{ + uint32_t k = fm1__lock(); + int32_t s = fm1_in.enc_steps[e]; + fm1_in.enc_steps[e] = 0; + fm1__unlock(k); + return s; +} + +static uint32_t fm1_input_edges(uint32_t *released) +{ + uint32_t k = fm1__lock(); + uint32_t p = fm1_in.pressed; + if (released) + *released = fm1_in.released; + fm1_in.pressed = fm1_in.released = 0; + fm1__unlock(k); + return p; +} + +static uint32_t fm1_input_note_edges(void) +{ + uint32_t k = fm1__lock(); + uint32_t p = fm1_in.notes_pressed; + fm1_in.notes_pressed = 0; + fm1__unlock(k); + return p; +} + +/* LED of key id (button 0..13 or note key 14..40) */ +static void fm1_led_key(uint32_t id, int on) +{ + uint32_t p, r; + for (p = 0; p < FM1_NCOL; p++) + for (r = 1; r < 5u; r++) + if (FM1_KEYMAP[r][p] == (int8_t)id) { + if (on) + fm1_led[p] |= (uint8_t)(1u << r); + else + fm1_led[p] &= (uint8_t)~(1u << r); + } +} diff --git a/firmware/hal/fm1_irq.h b/firmware/hal/fm1_irq.h new file mode 100644 index 0000000..bf5f011 --- /dev/null +++ b/firmware/hal/fm1_irq.h @@ -0,0 +1,113 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* FM-1 interrupt / exception HAL. + * + * fm1_irq_init() first thing in cstart: all ICFG off, pendings and + * exception causes cleared, all 128 vectors -> fatal + * stubs (fm1_vec.S), vector 1 (CPU + * exception) enabled at prio 7, div0 trap + ETM on. + * fm1_irq_attach(n, h, prio) h = asm wrapper (fm1_isr.S), prio 0..7 + * fm1_irq_enable_all() icfg bit 8 + sti, after every source is set up + * + * The application supplies fm1_fault(const fm1_crash_t *) which reports the + * crash (LCD) and resets; the record survives in .noinit for the next boot. + */ +#pragma once +#include + +#define FM1_VEC ((volatile uint32_t *)0x01C7FE00u) +#define FM1_ICFG(n) (*(volatile uint32_t *)(0x1EEF100u + 4u * ((n) >> 3))) +#define FM1_IPND(i) (*(volatile uint32_t *)(0x1EEF180u + 4u * (i))) +#define FM1_ILAT_SET (*(volatile uint32_t *)0x1EEF1A0u) +#define FM1_ILAT_CLR (*(volatile uint32_t *)0x1EEF1A4u) +#define FM1_EMU_CON (*(volatile uint32_t *)0x1EEF0D0u) +#define FM1_EMU_MSG (*(volatile uint32_t *)0x1EEF0D4u) +#define FM1_ETM_CON (*(volatile uint32_t *)0x1EEF1C0u) +#define FM1_ETM_PC(i) (*(volatile uint32_t *)(0x1EEF1C4u + 4u * (i))) +#define FM1_DBG_WR_EN (*(volatile uint32_t *)0x1EEE240u) +#define FM1_DBG_MSG (*(volatile uint32_t *)0x1EEE244u) +#define FM1_DBG_MSG_CLR (*(volatile uint32_t *)0x1EEE248u) +#define FM1_DBG_EN (*(volatile uint32_t *)0x1EEE340u) + +enum { FM1_IRQ_EXCEPTION = 1, FM1_IRQ_ALNK0 = 11, FM1_IRQ_SPI1 = 16, FM1_IRQ_UART1 = 20, + FM1_IRQ_SARADC = 24, FM1_IRQ_SPI2 = 37, FM1_IRQ_TIMER5 = 63, FM1_IRQ_SOFT0 = 120 }; + +static inline uint32_t fm1_icfg(void) { uint32_t v; __asm__ volatile("%0 = icfg" : "=r"(v)); return v; } +static inline void fm1_icfg_set(uint32_t v) { __asm__ volatile("icfg = %0" ::"r"(v) : "memory"); } +static inline void fm1_irq_off(void) { __asm__ volatile("cli" ::: "memory"); } +static inline void fm1_irq_on(void) { __asm__ volatile("csync\n\tsti" ::: "memory"); } + +#define FM1_CRASH_MAGIC 0x43525348u /* "CRSH" */ +typedef struct { + uint32_t magic, count, vec, pc, rets, emu, dbg, sp, psr, icfg, uptime_ms; + uint32_t etm[4]; + uint32_t early; /* consecutive crashes < 3 s after boot */ +} fm1_crash_t; +/* Not static: .noinit holds whatever the last run (or power-on) left, and a + * file-local object would let the compiler assume its zero initial value and + * fold the magic check away. */ +fm1_crash_t fm1_crash __attribute__((section(".noinit"))); + +extern const char fm1_fatal_stubs[]; +static void fm1_fault(const fm1_crash_t *c); /* application: report, then reset */ + +static void fm1_irq_init(void) +{ + uint32_t i; + for (i = 0; i < 32u; i++) + *(volatile uint32_t *)(0x1EEF100u + 4u * i) = 0; /* every source off (CPU0 bank) */ + FM1_ILAT_CLR = 0xFFu; + FM1_EMU_MSG = 0xFFFFFFFFu; + if (!(FM1_DBG_WR_EN & 1u)) + FM1_DBG_WR_EN = 0xE7u; /* unlock */ + FM1_DBG_MSG_CLR = 0xFFFFFFFFu; + for (i = 0; i < 128u; i++) + FM1_VEC[i] = (uint32_t)(uintptr_t)(fm1_fatal_stubs + 6u * i); + FM1_ICFG(1) = (FM1_ICFG(1) & ~0xF0u) | 0xF0u; /* exception: enable, prio 7 */ + FM1_EMU_CON |= 1u << 2; /* div0 traps */ + FM1_ETM_CON |= 1u; /* branch trace for the report */ +} + +static void fm1_irq_attach(uint32_t n, void (*h)(void), uint32_t prio) /* IRQs off */ +{ + uint32_t sh = (n & 7u) * 4u; + FM1_VEC[n] = (uint32_t)(uintptr_t)h; + FM1_ICFG(n) = (FM1_ICFG(n) & ~(0xFu << sh)) | ((((prio & 7u) << 1) | 1u) << sh); +} +static void fm1_irq_mask(uint32_t n) { FM1_ICFG(n) &= ~(1u << ((n & 7u) * 4u)); } + +static void fm1_irq_enable_all(void) +{ + fm1_icfg_set(fm1_icfg() | 0x100u); + fm1_irq_on(); +} + +/* called from fm1_fatal_common (fm1_vec.S) with the saved frame: + * f[0..15] r0..r15, f[16] reti, f[17] rete, f[18] retx, f[19] stub+6, + * f[20] psr, f[21] icfg, f[22] usp, f[23] ssp, f[24] sp, f[25] interrupted rets */ +void fm1_fault_c(uint32_t *f) +{ + static volatile uint32_t in_fault; + uint32_t i, count = fm1_crash.magic == FM1_CRASH_MAGIC ? fm1_crash.count : 0; + uint32_t early = fm1_crash.magic == FM1_CRASH_MAGIC ? fm1_crash.early : 0; + fm1_irq_off(); + if (in_fault++) /* fault while reporting: reset at once */ + *(volatile uint32_t *)0x10000u |= 1u << 4; + fm1_crash.magic = FM1_CRASH_MAGIC; + fm1_crash.count = count + 1u; + fm1_crash.vec = (f[19] - (uint32_t)(uintptr_t)fm1_fatal_stubs) / 6u - 1u; + fm1_crash.pc = f[16]; + fm1_crash.rets = f[25]; + fm1_crash.emu = FM1_EMU_MSG; + fm1_crash.dbg = FM1_DBG_MSG; + fm1_crash.sp = f[24]; + fm1_crash.psr = f[20]; + fm1_crash.icfg = f[21]; + fm1_crash.uptime_ms = *(volatile uint32_t *)0x10804u / 24000u; /* TIMER4 since boot */ + for (i = 0; i < 4u; i++) + fm1_crash.etm[i] = FM1_ETM_PC(i); + fm1_crash.early = fm1_crash.uptime_ms < 3000u ? early + 1u : 0u; + fm1_fault(&fm1_crash); + for (;;) + ; +} diff --git a/firmware/hal/fm1_isr.S b/firmware/hal/fm1_isr.S new file mode 100644 index 0000000..7bf3583 --- /dev/null +++ b/firmware/hal/fm1_isr.S @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* IRQ entry wrappers: save what a C call may clobber, call the C body, + * restore, csync, rti. clang does not emit the csync needed before rti, + * so ISRs are not written in C directly. */ + .macro FM1_ISR name, body + .section .text.\name,"ax",@progbits + .globl \name +\name: + [--sp] = {psr, rets, reti} + [--sp] = {r3-r0} + call \body + {r3-r0} = [sp++] + {psr, rets, reti} = [sp++] + csync + rti + .endm + + FM1_ISR isr_timer5, fm1_timer5_irq + FM1_ISR isr_alnk0, fm1_alnk0_irq diff --git a/firmware/hal/fm1_lcd_hw.h b/firmware/hal/fm1_lcd_hw.h new file mode 100644 index 0000000..72e0f2d --- /dev/null +++ b/firmware/hal/fm1_lcd_hw.h @@ -0,0 +1,76 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* FM-1 LCD wiring: SPI1 on PC9 CLK, PC10 DO, PC7 CS, + * PC8 D/C; backlight PA2, active low. The panel protocol is src/lcd.c. + * + * fm1_lcd_hw_init() pins, backlight on, SPI1 master at BAUD 4 + * fm1_lcd_baud(b) SPI1 clock = lsb / (b + 1) + * fm1_lcd_send_cmd(c) D/C low, CS low, one byte (then fm1_lcd_wait) + * fm1_lcd_send_data(p, n) D/C high, CS low, DMA n bytes from RAM p + * fm1_lcd_wait() SPI done (or timeout, counted), pending cleared + * fm1_lcd_deselect() CS high + */ +#pragma once +#include +#include "fm1_cc.h" + +#define FM1_LCD_PC_OUT (*(volatile uint32_t *)0x50080u) +#define FM1_LCD_PC_DIR (*(volatile uint32_t *)0x50088u) +#define FM1_LCD_IOMAP_CON1 (*(volatile uint32_t *)0x51020u) +#define FM1_LCD_SPI_CON (*(volatile uint32_t *)0x11D00u) +#define FM1_LCD_SPI_BAUD (*(volatile uint32_t *)0x11D04u) +#define FM1_LCD_SPI_BUF (*(volatile uint32_t *)0x11D08u) +#define FM1_LCD_SPI_ADR (*(volatile uint32_t *)0x11D0Cu) +#define FM1_LCD_SPI_CNT (*(volatile uint32_t *)0x11D10u) +#define FM1_LCD_PA_OUT (*(volatile uint32_t *)0x50000u) +#define FM1_LCD_PA_DIR (*(volatile uint32_t *)0x50008u) +#define FM1_LCD_BL (1u << 2) +#define FM1_LCD_CS (1u << 7) +#define FM1_LCD_DC (1u << 8) +#define FM1_LCD_CLK (1u << 9) +#define FM1_LCD_DO (1u << 10) + +static uint32_t fm1_lcd_timeouts; + +FM1_INLINE void fm1_lcd_hw_init(void) +{ + FM1_LCD_PA_OUT &= ~FM1_LCD_BL; + FM1_LCD_PA_DIR &= ~FM1_LCD_BL; + FM1_LCD_IOMAP_CON1 |= 0x10u; + FM1_LCD_PC_OUT |= FM1_LCD_CS; + FM1_LCD_PC_OUT &= ~(FM1_LCD_DC | FM1_LCD_CLK | FM1_LCD_DO); + FM1_LCD_PC_DIR &= ~(FM1_LCD_CS | FM1_LCD_DC | FM1_LCD_CLK | FM1_LCD_DO); + FM1_LCD_SPI_CON = 0x4021u; + FM1_LCD_SPI_BAUD = 4u; +} + +FM1_INLINE void fm1_lcd_baud(uint32_t b) { FM1_LCD_SPI_BAUD = b; } + +static void fm1_lcd_wait(void) +{ + uint32_t n; + for (n = 0; n < 4000000u && !(FM1_LCD_SPI_CON & 0x8000u); n++) + ; + if (n == 4000000u) + fm1_lcd_timeouts++; + FM1_LCD_SPI_CON |= 0x4000u; +} + +FM1_INLINE void fm1_lcd_deselect(void) { FM1_LCD_PC_OUT |= FM1_LCD_CS; } + +FM1_INLINE void fm1_lcd_send_cmd(uint8_t c) +{ + FM1_LCD_PC_OUT &= ~FM1_LCD_DC; + FM1_LCD_PC_OUT &= ~FM1_LCD_CS; + FM1_LCD_SPI_CON |= 0x4000u; + FM1_LCD_SPI_BUF = c; +} + +FM1_INLINE void fm1_lcd_send_data(const void *p, uint32_t n) +{ + FM1_LCD_PC_OUT |= FM1_LCD_DC; + FM1_LCD_PC_OUT &= ~FM1_LCD_CS; + FM1_LCD_SPI_CON |= 0x4000u; + FM1_LCD_SPI_ADR = (uint32_t)(uintptr_t)p; + FM1_LCD_SPI_CNT = n; +} diff --git a/firmware/hal/fm1_sys.h b/firmware/hal/fm1_sys.h new file mode 100644 index 0000000..f1bccda --- /dev/null +++ b/firmware/hal/fm1_sys.h @@ -0,0 +1,172 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* FM-1 system HAL: P33 access, watchdog, reset reason, reboot / UBOOT entry. + * Call with interrupts off so nothing else touches P33. + * + * fm1_reset_reason() snapshot P3_RST_SRC / RST_SRC (call first thing) + * fm1_wdt_arm(t) reset-mode watchdog, t = 0xA 1 s .. 0xF 32 s + * fm1_wdt_feed() in the main loop + * fm1_reboot() chip reset through P33 (P3_PR_PWR bit 4) + * fm1_enter_uboot() "usb_update_mode" at 0x01C7FD80 + chip reset + * fm1_enter_update(p) 112-byte UPDATA_PARM record at 0x01C7FD88 + core reset + * (the SPL then runs the staged update loader) + * fm1_core_reset() PWR_CON core reset + * fm1_updata_parm_clear() zero the record (CRC 0: ignored on a warm reset) + * fm1_mailbox_clear() zero 0x01C7FD80..0x01C7FDFF (boot info, mailbox) at cold start + * fm1_mem_readable(a, n) / fm1_peek8(a) debug reads of RAM / XIP only + */ +#pragma once +#include +#include "fm1_cc.h" + +#define FM1_P33_CON (*(volatile uint32_t *)0x13E08u) +#define FM1_P33_DAT (*(volatile uint32_t *)0x13E0Cu) +#define FM1_RST_SRC (*(volatile uint32_t *)0x100C0u) +#define FM1_BOOT_STATE ((volatile uint8_t *)0x01C7FD80u) +#define FM1_PWR_CON (*(volatile uint32_t *)0x10000u) +#define FM1_UPDATA_PARM ((volatile uint8_t *)0x01C7FD88u) +#define FM1_UPDATA_PARM_LEN 112u + +static uint32_t fm1_p33_timeouts; + +static uint8_t fm1__p33_xfer(uint8_t b) +{ + uint32_t n = 100000u; + FM1_P33_DAT = b; + FM1_P33_CON |= 1u << 4; + (void)FM1_P33_CON; /* stands in for csync */ + while (FM1_P33_CON & (1u << 1)) + if (--n == 0) { + fm1_p33_timeouts++; + break; + } + return (uint8_t)FM1_P33_DAT; +} + +static void fm1__p33_cs(uint32_t a) +{ + if (a & 0x8000u) { + FM1_P33_CON |= (1u << 0) | (1u << 8); /* R3 (RTC) domain */ + } else { + FM1_P33_CON &= ~(1u << 8); + FM1_P33_CON |= 1u << 0; + } +} + +static void fm1__p33_op(uint32_t op, uint32_t a, uint8_t d) /* 0 wr, 1 or, 2 and, 3 xor */ +{ + fm1__p33_cs(a); + fm1__p33_xfer((uint8_t)((op << 5) | ((a >> 8) & 3u))); + fm1__p33_xfer((uint8_t)a); + fm1__p33_xfer(d); + FM1_P33_CON &= ~((1u << 0) | (1u << 8)); +} + +static uint8_t fm1_p33_read(uint32_t a) +{ + uint8_t v; + fm1__p33_cs(a); + fm1__p33_xfer((uint8_t)(0x80u | ((a >> 8) & 3u))); + fm1__p33_xfer((uint8_t)a); + v = fm1__p33_xfer(0x5E); + FM1_P33_CON &= ~((1u << 0) | (1u << 8)); + return v; +} +static void fm1_p33_write(uint32_t a, uint8_t d) { fm1__p33_op(0, a, d); } +static void fm1_p33_or(uint32_t a, uint8_t d) { fm1__p33_op(1, a, d); } +static void fm1_p33_and(uint32_t a, uint8_t d) { fm1__p33_op(2, a, d); } + +/* ------------------------------------------------------------ watchdog --- */ +#define FM1_P3_WDT_CON 0x80u +#define FM1_P3_VLD_KEEP 0x17u +#define FM1_P3_RST_SRC 0x12u +#define FM1_P3_PR_PWR 0xA0u + +static void fm1_wdt_arm(uint8_t t) +{ + fm1_p33_write(FM1_P3_WDT_CON, 0); + fm1_p33_and(FM1_P3_VLD_KEEP, (uint8_t)~0x40u); /* WDT_EXPT_EN = 0: plain reset */ + fm1_p33_write(FM1_P3_WDT_CON, (uint8_t)((t & 0x0Fu) | 0x40u)); /* timeout, reset mode, clear */ + fm1_p33_or(FM1_P3_WDT_CON, 0x10); /* enable */ +} +static void fm1_wdt_feed(void) { fm1_p33_or(FM1_P3_WDT_CON, 0x40); } +static void fm1_wdt_stop(void) { fm1_p33_write(FM1_P3_WDT_CON, 0); } + +/* ---------------------------------------------------- reset and reboot --- */ +static struct { + uint8_t p3_rst; /* bit0 power-on, 1 VDDIO low, 2 WDT, 3 VCM, 4 long press, 5 1.2 V, 6 soft (P33) */ + uint32_t rst_src; /* bit5 soft (PWR_CON) */ + uint8_t wdt_con; /* as found at boot */ +} fm1_boot; + +static void fm1_reset_reason(void) +{ + fm1_boot.p3_rst = fm1_p33_read(FM1_P3_RST_SRC); + fm1_boot.rst_src = FM1_RST_SRC; + fm1_boot.wdt_con = fm1_p33_read(FM1_P3_WDT_CON); +} + +static void fm1_reboot(void) +{ + __asm__ volatile("cli"); + fm1_p33_or(FM1_P3_PR_PWR, 0x10); + for (;;) + ; +} + +static void fm1_enter_uboot(void) +{ + static const char k[16] = "usb_update_mode"; + uint32_t i; + __asm__ volatile("cli"); + /* CPU0 write limits (fm1_guard.h) may cover the mailbox: drop them all */ + if (!(*(volatile uint32_t *)0x1EEE240u & 1u)) + *(volatile uint32_t *)0x1EEE240u = 0xE7u; + *(volatile uint32_t *)0x1EEE348u = 0; + for (i = 0; i < 16u; i++) + FM1_BOOT_STATE[i] = (uint8_t)k[i]; + fm1_p33_or(FM1_P3_PR_PWR, 0x10); + for (;;) + ; +} + +FM1_INLINE void fm1_core_reset(void) +{ + FM1_PWR_CON |= 0x10u; + for (;;) + ; +} + +FM1_INLINE void fm1_enter_update(const uint8_t *parm) +{ + uint32_t i; + __asm__ volatile("cli"); + if (!(*(volatile uint32_t *)0x1EEE240u & 1u)) /* drop CPU0 write limits, as fm1_enter_uboot */ + *(volatile uint32_t *)0x1EEE240u = 0xE7u; + *(volatile uint32_t *)0x1EEE348u = 0; + for (i = 0; i < FM1_UPDATA_PARM_LEN; i++) + FM1_UPDATA_PARM[i] = parm[i]; + fm1_core_reset(); +} + +FM1_INLINE void fm1_updata_parm_clear(void) +{ + uint32_t i; + for (i = 0; i < FM1_UPDATA_PARM_LEN; i++) + FM1_UPDATA_PARM[i] = 0; +} + +FM1_INLINE void fm1_mailbox_clear(void) /* before fm1_guard_enable (it write-protects the top) */ +{ + uint32_t *s; + for (s = (uint32_t *)0x01C7FD80u; s < (uint32_t *)0x01C7FE00u; s++) + *s = 0; +} + +/* RAM and the XIP window only: SFR reads can have side effects */ +static int fm1_mem_readable(uint32_t a, uint32_t n) +{ + return (a >= 0x01C00000u && a + n <= 0x01C80000u && a + n >= a) || + (a >= 0x02000000u && a + n <= 0x02100000u && a + n >= a); +} +FM1_INLINE uint8_t fm1_peek8(uint32_t a) { return *(const volatile uint8_t *)a; } diff --git a/firmware/hal/fm1_time.h b/firmware/hal/fm1_time.h new file mode 100644 index 0000000..d62920d --- /dev/null +++ b/firmware/hal/fm1_time.h @@ -0,0 +1,46 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* FM-1 time base: TIMER4 free-running from the 24 MHz crystal. + * TIMER4 is not used by the ROM or the SPL. No interrupts, no ROM calls. + * + * JL_TIMER4 = 0x10800: CON [1:0]=1 run, [3:2]=2 OSC source, [7:4]=0 /1, + * bit14 = clear pending; CNT +4; PRD +8 (32-bit, set to 0xFFFFFFFF). + * The counter wraps every 178.9 s; use differences (unsigned arithmetic). + */ +#pragma once +#include + +#define FM1_T4_CON (*(volatile uint32_t *)0x10800u) +#define FM1_T4_CNT (*(volatile uint32_t *)0x10804u) +#define FM1_T4_PRD (*(volatile uint32_t *)0x10808u) +#define FM1_TICKS_PER_US 24u + +/* Start TIMER4 unless it already runs, so time stays continuous across + * RAM-run jumps. */ +static inline void fm1_time_init(void) +{ + if ((FM1_T4_CON & 0xFu) == ((2u << 2) | 1u)) + return; + FM1_T4_CON = 0; + FM1_T4_PRD = 0xFFFFFFFFu; + FM1_T4_CNT = 0; + FM1_T4_CON = (2u << 2) | 1u | (1u << 14); +} + +static inline uint32_t fm1_ticks(void) { return FM1_T4_CNT; } + +/* Microseconds, wrapping every ~178.9 s. */ +static inline uint32_t fm1_micros(void) { return FM1_T4_CNT / FM1_TICKS_PER_US; } + +static inline void fm1_delay_us(uint32_t us) +{ + uint32_t start = FM1_T4_CNT, span = us * FM1_TICKS_PER_US; + while ((uint32_t)(FM1_T4_CNT - start) < span) + ; +} + +static inline void fm1_delay_ms(uint32_t ms) +{ + while (ms--) + fm1_delay_us(1000u); +} diff --git a/firmware/hal/fm1_timer.h b/firmware/hal/fm1_timer.h new file mode 100644 index 0000000..c20e10f --- /dev/null +++ b/firmware/hal/fm1_timer.h @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* FM-1 TIMER5: the 10 kHz system tick (input scan, USB poll, ms count). + * TIMER4 is the free-running time base (fm1_time.h); the ROM and the SPL + * leave both free. JL_TIMER5 = 0x10900: CON, CNT +4, PRD +8. + * + * fm1_timer5_start(isr, prio) OSC /4 = 6 MHz, PRD 600 -> 10 kHz, IRQ 63 + * fm1_timer5_ack() first thing in the ISR + */ +#pragma once +#include +#include "fm1_cc.h" +#include "fm1_irq.h" + +#define FM1_T5_CON (*(volatile uint32_t *)0x10900u) +#define FM1_T5_CNT (*(volatile uint32_t *)0x10904u) +#define FM1_T5_PRD (*(volatile uint32_t *)0x10908u) + +FM1_INLINE void fm1_timer5_start(void (*isr)(void), uint32_t prio) /* IRQs off */ +{ + FM1_T5_CON = 0x4000u; + FM1_T5_CNT = 0; + FM1_T5_PRD = 600u; + fm1_irq_attach(FM1_IRQ_TIMER5, isr, prio); + FM1_T5_CON = 0x4019u; +} + +FM1_INLINE void fm1_timer5_ack(void) { FM1_T5_CON |= 0x4000u; } diff --git a/firmware/hal/fm1_uart.h b/firmware/hal/fm1_uart.h new file mode 100644 index 0000000..3642b0f --- /dev/null +++ b/firmware/hal/fm1_uart.h @@ -0,0 +1,60 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* FM-1 UART1 as MIDI IN: PH8 -> input + * channel 1 -> UART1 RX, 31250 baud, RX DMA into a ring, polled (no IRQ). + * The MIDI parser is src/midi_uart.c. Untested on hardware. + * + * fm1_uart1_midi_init(ring, len) len a power of two, ring aligned 16; + * before TIMER5 starts (PORTH RMW) + * fm1_uart1_rx_take() bytes DMA'd since the last call + */ +#pragma once +#include +#include "fm1_cc.h" + +#define FM1_UT1_CON0 (*(volatile uint32_t *)0x12100u) +#define FM1_UT1_CON1 (*(volatile uint32_t *)0x12104u) +#define FM1_UT1_BAUD (*(volatile uint32_t *)0x12108u) +#define FM1_UT1_OTCNT (*(volatile uint32_t *)0x12110u) +#define FM1_UT1_RXSADR (*(volatile uint32_t *)0x1211Cu) +#define FM1_UT1_RXEADR (*(volatile uint32_t *)0x12120u) +#define FM1_UT1_RXCNT (*(volatile uint32_t *)0x12124u) +#define FM1_UT1_HRXCNT (*(volatile uint32_t *)0x12128u) +#define FM1_UM_CLK_CON1 (*(volatile uint32_t *)0x10010u) /* [11:10] UART clock: 1 = PLL48M */ +#define FM1_UM_IOMAP2 (*(volatile uint32_t *)0x51024u) /* input ch1 source [13:8] */ +#define FM1_UM_IOMAP3 (*(volatile uint32_t *)0x51028u) /* UT1: b7 fixed IO, [6:4] RX select */ +#define FM1_UM_PH_DIR (*(volatile uint32_t *)0x501C8u) +#define FM1_UM_PH_DIE (*(volatile uint32_t *)0x501CCu) +#define FM1_UM_PH_PU (*(volatile uint32_t *)0x501D0u) +#define FM1_UM_PH_PD (*(volatile uint32_t *)0x501D4u) + +FM1_INLINE void fm1_uart1_midi_init(volatile uint8_t *ring, uint32_t len) +{ + FM1_UT1_CON0 = 0x3400u; /* off, pendings cleared */ + FM1_UT1_CON1 = 0; + FM1_UM_CLK_CON1 = (FM1_UM_CLK_CON1 & ~(3u << 10)) | (1u << 10); + FM1_UM_IOMAP3 &= ~0x80u; + FM1_UM_IOMAP3 = (FM1_UM_IOMAP3 & ~0x70u) | (5u << 4); /* UT1 RX = input ch 1 */ + FM1_UM_IOMAP2 = (FM1_UM_IOMAP2 & ~0x3F00u) | (49u << 8);/* ch 1 = PH8 */ + FM1_UM_PH_PD &= ~(1u << 8); + FM1_UM_PH_DIE |= 1u << 8; + FM1_UM_PH_DIR |= 1u << 8; + FM1_UM_PH_PU |= 1u << 8; + FM1_UT1_RXSADR = (uint32_t)(uintptr_t)ring; + FM1_UT1_RXEADR = (uint32_t)(uintptr_t)ring + len; + FM1_UT1_RXCNT = len; + FM1_UT1_BAUD = 48000000u / 31250u / 4u - 1u; /* 383 */ + FM1_UT1_OTCNT = 60000u; + __asm__ volatile("csync" ::: "memory"); + FM1_UT1_CON0 = 0x40u | 0x80u | 0x1000u | 0x400u; /* RXDMA, RDC, clear R/OT; no IEs */ + __asm__ volatile("csync" ::: "memory"); + FM1_UT1_CON0 |= 1u; /* UTEN last */ +} + +FM1_INLINE uint32_t fm1_uart1_rx_take(void) +{ + FM1_UT1_CON0 |= 0x80u; /* RDC: latch the count */ + __asm__ volatile("csync" ::: "memory"); + FM1_UT1_CON0 |= 0x1400u; /* clear RPND / OTPND */ + return FM1_UT1_HRXCNT & 0xFFFFu; +} diff --git a/firmware/hal/fm1_usb.h b/firmware/hal/fm1_usb.h new file mode 100644 index 0000000..33766e4 --- /dev/null +++ b/firmware/hal/fm1_usb.h @@ -0,0 +1,104 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* FM-1 USB0 full-speed device controller, register level only. + * The protocol (descriptors, EP0 requests, + * MIDI / CDC / SysEx) is the driver src/usb.c, shared with the update loader + * and the host tests; this header is every USB register access it makes. + * + * fm1_usb_reset() CON0 = CON1 = 0, pads detached; wait >= 20 ms + * fm1_usb_attach(ep0) clock, EP DMA defaults, PHY on, D+ pull-up + * fm1_usb_off() detach: controller off, pads inputs + * SIE (MUSB byte map): fm1_usb_sie_on, _wr_start / _rd_start, _done, _data + * EP DMA: fm1_usb_ep0_buf, fm1_usb_ep_txbuf / _rxbuf, + * fm1_usb_ep0_send / fm1_usb_ep_send (csync first), + * fm1_usb_rx_sync (ssync before reading an RX buffer) + * fm1_usb_ep_enable(m) CON0 &= ~(m << 19), m = bit per endpoint + * fm1_usb_sof_take() SOF pending -> clear, 1 + * No IRQ: everything is polled (usb_poll from the TIMER5 ISR). */ +#pragma once +#include +#include "fm1_cc.h" + +#define FM1_USB_CON0 (*(volatile uint32_t *)0x11800u) +#define FM1_USB_CON1 (*(volatile uint32_t *)0x11804u) +#define FM1_USB_EP_CNT(n) (*(volatile uint32_t *)(0x11808u + 4u * (n))) /* EP0..3 */ +#define FM1_USB_EP0_ADR (*(volatile uint32_t *)0x11818u) +#define FM1_USB_EP_TADR(n) (*(volatile uint32_t *)(0x1181Cu + 8u * ((n) - 1u))) /* EP1..3 */ +#define FM1_USB_EP_RADR(n) (*(volatile uint32_t *)(0x11820u + 8u * ((n) - 1u))) /* EP1..3 */ +#define FM1_USB_EP4_RADR (*(volatile uint32_t *)0x1183Cu) +#define FM1_USB_IO_CON0 (*(volatile uint32_t *)0x51000u) +#define FM1_CLK_CON1 (*(volatile uint32_t *)0x10010u) + +FM1_INLINE void fm1_usb_reset(void) +{ + FM1_USB_CON0 = 0; + FM1_USB_CON1 = 0; + FM1_USB_IO_CON0 = 0x0Cu; +} + +FM1_INLINE void fm1_usb_attach(void *ep0) +{ + uint32_t n; + FM1_CLK_CON1 &= ~3u; /* USB clock = PLL48M */ + FM1_USB_EP0_ADR = (uint32_t)(uintptr_t)ep0; + for (n = 1; n <= 3u; n++) + FM1_USB_EP_RADR(n) = (uint32_t)(uintptr_t)ep0; + FM1_USB_EP4_RADR = (uint32_t)(uintptr_t)ep0; + FM1_USB_IO_CON0 |= (1u << 10) | (1u << 9); + FM1_USB_IO_CON0 &= ~(1u << 11); + FM1_USB_IO_CON0 |= 1u << 12; + FM1_USB_CON0 &= ~0x4035u; + FM1_USB_CON1 = 0; + FM1_USB_CON0 |= 1u; + FM1_USB_IO_CON0 &= ~0xF0u; + FM1_USB_IO_CON0 |= 0x40u; /* D+ pull-up: attach */ + FM1_USB_CON0 |= 0x3Cu; +} + +FM1_INLINE void fm1_usb_off(void) +{ + FM1_USB_CON0 = 0; + FM1_USB_IO_CON0 = 0x0Cu; +} + +/* SIE access through CON1: only while CON0.bit2 (USB_NRST) is set */ +FM1_INLINE uint32_t fm1_usb_sie_on(void) { return FM1_USB_CON0 & 4u; } +FM1_INLINE void fm1_usb_sie_wr_start(uint32_t r, uint32_t v) +{ + FM1_USB_CON1 = ((r << 8) & 0xFFFF00u) | (v & 0xFFu); + __asm__ volatile("csync" ::: "memory"); +} +FM1_INLINE void fm1_usb_sie_rd_start(uint32_t r) +{ + FM1_USB_CON1 = ((r << 8) & 0xFFBF00u) | 0x4000u; + __asm__ volatile("csync" ::: "memory"); +} +FM1_INLINE uint32_t fm1_usb_sie_done(void) { return FM1_USB_CON1 & 0x8000u; } +FM1_INLINE uint32_t fm1_usb_sie_data(void) { return FM1_USB_CON1 & 0xFFu; } + +FM1_INLINE void fm1_usb_ep0_buf(void *p) { FM1_USB_EP0_ADR = (uint32_t)(uintptr_t)p; } +FM1_INLINE void fm1_usb_ep_txbuf(uint32_t ep, void *p) { FM1_USB_EP_TADR(ep) = (uint32_t)(uintptr_t)p; } +FM1_INLINE void fm1_usb_ep_rxbuf(uint32_t ep, void *p) { FM1_USB_EP_RADR(ep) = (uint32_t)(uintptr_t)p; } +FM1_INLINE void fm1_usb_ep0_send(void *p, uint32_t n) +{ + __asm__ volatile("csync" ::: "memory"); /* the buffer is written before the DMA starts */ + FM1_USB_EP0_ADR = (uint32_t)(uintptr_t)p; + FM1_USB_EP_CNT(0) = n; +} +FM1_INLINE void fm1_usb_ep_send(uint32_t ep, void *p, uint32_t n) +{ + __asm__ volatile("csync" ::: "memory"); + FM1_USB_EP_TADR(ep) = (uint32_t)(uintptr_t)p; + FM1_USB_EP_CNT(ep) = n; +} +FM1_INLINE void fm1_usb_rx_sync(void) { __asm__ volatile("ssync" ::: "memory"); } + +FM1_INLINE void fm1_usb_ep_enable(uint32_t eps) { FM1_USB_CON0 &= ~(eps << 19); } + +FM1_INLINE uint32_t fm1_usb_sof_take(void) +{ + if (!(FM1_USB_CON0 & (1u << 13))) + return 0; + FM1_USB_CON0 |= 1u << 12; + return 1; +} diff --git a/firmware/hal/fm1_vec.S b/firmware/hal/fm1_vec.S new file mode 100644 index 0000000..a0a7643 --- /dev/null +++ b/firmware/hal/fm1_vec.S @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* 128 fatal-vector stubs, 6 bytes each: VEC[n] = fm1_fatal_stubs + 6*n. + * The call leaves rets = stub + 6, so common code recovers n. */ + .section .text.fm1vec,"ax",@progbits + .globl fm1_fatal_stubs + .balign 2 +fm1_fatal_stubs: + .rept 128 + [--sp] = {rets} + call fm1_fatal_common + .endr + + .section .text.fm1vec_common,"ax",@progbits + .globl fm1_fatal_common +fm1_fatal_common: + trigger + [--sp] = {sp, ssp, usp, icfg, psr, rets, retx, rete, reti} + [--sp] = {r15-r0} + r0 = sp /* frame: r0..r15, reti, rete, retx, rets(stub+6), psr, icfg, usp, ssp, sp, rets(orig) */ + call fm1_fault_c +1: goto 1b diff --git a/firmware/hal/fm1_xip.h b/firmware/hal/fm1_xip.h new file mode 100644 index 0000000..45830c0 --- /dev/null +++ b/firmware/hal/fm1_xip.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* FM-1 XIP window: flash offset off (>= 0x4000, the app area start) reads + * at CPU address 0x02000000 + off - 0x4000 through the SFC/cache. Data + * outside the plain (unencrypted) window reads decrypted: see + * fm1_flash.h fl_plain_window_init. */ +#pragma once +#include +#include "fm1_cc.h" + +#define FM1_XIP(off) (0x02000000u + (uint32_t)(off) - 0x4000u) + +FM1_INLINE const uint8_t *fm1_xip_ptr(uint32_t off) { return (const uint8_t *)FM1_XIP(off); } diff --git a/firmware/loader/crt0_ldr.S b/firmware/loader/crt0_ldr.S new file mode 100644 index 0000000..3d88766 --- /dev/null +++ b/firmware/loader/crt0_ldr.S @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* Felucca update loader entry. The SPL decompresses the loader to its load + * address (0x01C0A800) and calls its first byte. Interrupts off, + * our own stacks, clear .bss, then C. Never returns. */ + .section .text.crt0,"ax",@progbits + .globl _start +_start: + goto 1f + .ascii "FELUCCA-LOADER-1" /* 16 bytes: Felucca recognises its loader in a package by this */ + .balign 2 +1: cli + sp = _stack_top + ssp = _sstack_top + call ldr_cstart + goto . diff --git a/firmware/loader/ldr_core.c b/firmware/loader/ldr_core.c new file mode 100644 index 0000000..e69d430 --- /dev/null +++ b/firmware/loader/ldr_core.c @@ -0,0 +1,189 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* Felucca update loader, the portable part (step 2 of the M-UPGRADE update + * protocol). + * + * The host serves the package ("logical image") with cmd 0x30 reads (ota.c). + * The loader: + * 1. reads the UFW header and finds flash.bin; + * 2. checks that the package's app area decrypts with THIS chip's key + * (taken from isd_config.ini in the device's own flash head), so a + * package for another key is refused before anything is erased; + * 3. writes ONLY the app area [0x4000, 0x93000), sector by sector, skipping + * sectors that are already equal, and verifies each one; the flash head + * (SPL, isd_config) is never written; + * 4. checks the CRC16 the package stores for flash.bin against everything it + * was served (the head too, which it never writes; a mismatch: up to two + * more passes, rewriting what differs), asks 0xF0000000 ("success"), then + * invalidates the update record (RAM and flash) so the SPL boots the new + * app, and resets. A damaged package or no "success" leaves the record: + * the loader stays (also after a power cycle) and the host can resume. + * Power loss during 3: the record is still there, the SPL runs the loader + * again on the next power-on and the host can resume. + * + * Hooks from the platform (loader.c, tests/ldr_test.c): + * ldr_fread(off, p, n) ldr_erase(off) ldr_prog(off, p, n) flash, 0 = ok + * ldr_record_clear() forget the RAM update record + * ldr_flash_known() the flash chip is the 1 MiB part SLOOP's storage expects (else nothing is + * written: the update records go and the old firmware starts again) + * ldr_progress(done, total) + * plus the ota.c hooks (frames, time, idle). */ +#define LDR_APP_LO 0x4000u +#define LDR_APP_HI 0x93000u +#define LDR_REC_LO 0x93000u /* update records live above the app ... */ +#define LDR_REC_HI 0xFC000u /* ... and below Felucca's globals */ + +static int ldr_fread(uint32_t off, void *p, uint32_t n); +static int ldr_erase(uint32_t off); +static int ldr_prog(uint32_t off, const void *p, uint32_t n); +static void ldr_record_clear(void); +static int ldr_flash_known(void); +static void ldr_progress(uint32_t done, uint32_t total); + +/* SFC cipher: per 32-byte block, key ^ (block offset >> 2) */ +static void ldr_sfc(uint8_t *p, uint32_t n, uint32_t base_off, uint32_t key) +{ + uint32_t i, j; + for (i = 0; i < n; i += 32u) { + uint32_t k = key ^ ((base_off + i) >> 2); + for (j = 0; j < 32u && i + j < n; j++) { + p[i + j] ^= (uint8_t)k; + k = ((k << 1) ^ (k & 0x8000u ? 0x1021u : 0u)) & 0xFFFFu; + } + } +} + +/* chip key from the device's flash head: JLFS top entries (ENC 0xFFFF) -> isd_config.ini blob */ +static int ldr_chip_key(uint32_t *key) +{ + uint8_t e[32], blob[34]; + uint32_t off, i, sum, k; + for (off = 32; off < 0x400u; off += 32u) { + if (ldr_fread(off, e, 32)) + return -1; + ota_jl_enc(e, 32); + if (ota_crc16(e + 2, 30, 0) != ota_rd16(e)) + return -2; + if (!ota_memeq(e + 16, (const uint8_t *)"isd_config.ini", 15)) { + if (ota_rd16(e + 14)) + return -3; /* last entry, not found */ + continue; + } + if (ldr_fread(ota_rd32(e + 4), blob, 34) || ota_crc16(blob, 32, 0) != ota_rd16(blob + 32)) + return -4; + for (i = 0, sum = 0; i < 16u; i++) + sum += blob[i]; + sum &= 0xFFu; + sum = sum >= 0xE0u ? 0xAAu : sum <= 0x10u ? 0x55u : sum; + for (i = 0, k = 0; i < 16u; i++) + if ((uint32_t)(blob[16 + i] ^ blob[15 - i]) < sum) + k |= 1u << i; + *key = k; + return 0; + } + return -3; +} + +#define LDR_EBADPKG (-12) /* flash.bin as served does not match the package's CRC16 */ +#define LDR_ENOFIN (-13) /* no "success" from the host */ +#define LDR_EFLASH (-14) /* another flash chip: nothing written, the records dropped */ + +/* the update records (RAM, and flash: a 4K boundary - 256) go: the SPL boots the app */ +static void ldr_records_drop(void) +{ + uint32_t s; + ldr_record_clear(); + for (s = LDR_REC_HI; s > LDR_REC_LO; s -= 0x1000u) { + uint8_t r[80]; + if (ldr_fread(s - 0x100u, r, 80)) + break; + if (ota_rd16(r + 6) == 0x5441u && ota_rd16(r) && ota_rd16(r) == ota_crc16(r + 2, 78, 0)) + ldr_erase(s - 0x1000u); + } +} + +static int ldr_pass(void) +{ + static uint8_t hdr[0x400], sec[0x1000], cur[0x1000]; + uint32_t i, k, fl_off, fl_size, ota_off, ota_len, key, s, n, want, crc = 0, done = 0; + int rc; + /* 1. UFW header + entry list (ota.c) */ + if ((rc = ota_ufw(hdr, &fl_off, &fl_size, &ota_off, &ota_len, &want)) != 0) + return rc; + if (!fl_off || fl_size < LDR_APP_HI) + return -3; + /* 2. the package's app area must decrypt with this chip's key */ + if ((rc = ldr_chip_key(&key)) != 0) + return -40 + rc; + if (ota_read(fl_off + LDR_APP_LO, sec, 32)) + return -5; + ldr_sfc(sec, 32, 0, key); + if (ota_crc16(sec + 2, 30, 0) != ota_rd16(sec)) + return -6; /* package for another chip key */ + if (!ldr_flash_known()) { /* SLOOP would run without its storage and could not */ + ldr_records_drop(); /* be updated again: keep the firmware there is */ + return LDR_EFLASH; + } + /* the head of flash.bin is never written, but it is part of the package's CRC */ + for (s = 0; s < LDR_APP_LO; s += 512u) { + if (ota_read(fl_off + s, sec, 512)) + return -7; + crc = ota_crc16(sec, 512, crc); + } + /* 3. app area, sector by sector */ + for (s = LDR_APP_LO; s < LDR_APP_HI; s += 0x1000u) { + for (k = 0; k < 0x1000u; k += 512u) + if (ota_read(fl_off + s + k, sec + k, 512)) + return -7; + crc = ota_crc16(sec, 0x1000u, crc); + if (ldr_fread(s, cur, 0x1000u)) + return -8; + if (!ota_memeq(sec, cur, 0x1000u)) { + uint32_t tries; + for (tries = 0; tries < 2u; tries++) { + if (ldr_erase(s)) + return -9; + for (k = 0; k < 0x1000u; k += 256u) + if (ldr_prog(s + k, sec + k, 256)) + return -10; + if (ldr_fread(s, cur, 0x1000u)) + return -8; + if (ota_memeq(sec, cur, 0x1000u)) + break; + } + if (tries == 2u) + return -11; /* verify failed twice */ + } + done += 0x1000u; + ldr_progress(done, LDR_APP_HI - LDR_APP_LO); + } + for (s = LDR_APP_HI; s < fl_size; s += n) { /* (a flash.bin longer than the app area) */ + n = fl_size - s < 512u ? fl_size - s : 512u; + if (ota_read(fl_off + s, sec, n)) + return -7; + crc = ota_crc16(sec, n, crc); + } + /* 4. finish: the whole package arrived as it was built, the host confirms, the record goes, + * the SPL boots the app */ + if (crc != want) + return LDR_EBADPKG; + for (i = 0; i < 4u; i++) + if (!ota_read(0xF0000000u, sec, 8)) + break; + if (i == 4u) + return LDR_ENOFIN; + ldr_records_drop(); + return 0; +} + +/* a pass that does not add up (a byte damaged on the way) is run again: the host answers any read, so it + * just serves the image once more and the sectors that differ are rewritten; a package that is damaged + * itself fails every pass and the record stays */ +static int ldr_session(void) +{ + int rc = LDR_EBADPKG; + uint32_t pass; + for (pass = 0; pass < 3u && rc == LDR_EBADPKG; pass++) + rc = ldr_pass(); + return rc; +} diff --git a/firmware/loader/loader.c b/firmware/loader/loader.c new file mode 100644 index 0000000..ad1ffed --- /dev/null +++ b/firmware/loader/loader.c @@ -0,0 +1,116 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* Felucca update loader (device side). Runs from RAM, started by the SPL from + * an update record, with interrupts off: USB is polled from the main loop. + * It is a USB-MIDI device "Felucca Update" (1209:0002) that answers the + * M-UPGRADE update protocol as "ota-FM-1_900" (hosts look for "ota-"), and + * writes the app area only (ldr_core.c). The UBOOT soft key works here too. + * Single compilation unit. */ +#include +#define FELUCCA_LOADER 1 +#define FELUCCA_CDC 0 +#define FELUCCA_OTA 1 +#define FELUCCA_OTA_DRYRUN 0 +#define FELUCCA_USB_PID 0x0002 +#define FELUCCA_ID "ota-FM-1_900" +#define RING_PUBLISH() __asm__ volatile("" ::: "memory") +#include "fm1_time.h" +#include "fm1_sys.h" +/* the loader may write the app area and erase update records; never the head */ +#define FL_RANGE_OK(off, n) (FL_IN(off, n, 0x4000u, 0x93000u) || FL_IN(off, n, 0x93000u, 0xFC000u)) +#include "fm1_flash.h" +#include "../src/libc.c" +#include "../src/usb.c" + +static uint32_t ldr_ms(void) /* monotonic ms; survives the TIMER4 wrap (178.9 s) */ +{ + static uint32_t last, acc, ms; + uint32_t now = fm1_ticks(); + acc += now - last; + last = now; + ms += acc / (1000u * FM1_TICKS_PER_US); + acc %= 1000u * FM1_TICKS_PER_US; + return ms; +} + +static void ldr_poll(void) /* USB at ~2 kHz, watchdog */ +{ + static uint32_t last; + uint32_t now = fm1_ticks(); + fm1_wdt_feed(); + if (now - last >= 500u * FM1_TICKS_PER_US) { + last = now; + usb_poll(); + } +} + +/* ---- ota.c hooks (the SysEx frame hooks are in usb.c) ---- */ +static uint32_t ota_now_ms(void) { return ldr_ms(); } +static void ota_idle(void) { ldr_poll(); } +/* step-1 hooks of ota.c: not used by the loader */ +static int ota_erase(uint32_t off) { (void)off; return -1; } +static int ota_prog(uint32_t off, const void *p, uint32_t n) { (void)off; (void)p; (void)n; return -1; } +static int ota_fread(uint32_t off, void *p, uint32_t n) { return fl_read_ram(off, p, n); } +static void ota_show(uint32_t step, int32_t code) { (void)step; (void)code; } +static void ota_commit(const uint8_t *parm) { (void)parm; } +#include "../src/ota.c" + +/* ---- ldr_core.c hooks: interrupts are off for the whole loader ---- */ +static int ldr_fread(uint32_t off, void *p, uint32_t n) { return fl_read_ram(off, p, n); } +static int ldr_erase(uint32_t off) +{ + uint32_t took; + return fl_erase4k_ram(off, &took); +} +static int ldr_prog(uint32_t off, const void *p, uint32_t n) +{ + uint32_t took; + return fl_prog_ram(off, p, n, &took); +} +static void ldr_record_clear(void) +{ + fm1_updata_parm_clear(); /* CRC 0: the SPL ignores it on a warm reset */ +} +static int ldr_flash_known(void) { return fl_jedec_ram() == 0x856014u; } /* as the app (project.c) */ +static void ldr_progress(uint32_t done, uint32_t total) { (void)done; (void)total; ldr_poll(); } +#include "ldr_core.c" + +extern uint32_t _bss_start[], _bss_end[]; + +void ldr_main(void) +{ + fm1_wdt_arm(0x0D); /* ~8 s, fed by ldr_poll */ + fm1_time_init(); + usb_start(); + for (;;) { + ldr_poll(); + usb_retry(ldr_ms()); + if (usb.uboot_req) { /* soft key: mask-ROM UBOOT, as in Felucca */ + usb_detach(); + fm1_delay_ms(30); + fm1_enter_uboot(); + } + ota_service(); /* handshake */ + if (usb.ota_req) { + int rc; + usb.ota_req = 0; + rc = ldr_session(); + if (rc == 0 || rc == LDR_EFLASH) { /* done, or another flash chip: the old firmware again */ + fm1_delay_ms(200); /* the "success" reply leaves */ + usb_detach(); + fm1_delay_ms(30); + fm1_core_reset(); /* the SPL boots the new app */ + } + } + } +} + +void ldr_cstart(void) +{ + uint32_t *p; + ldr_record_clear(); /* first thing: a crash below cannot loop through a + * warm reset; resume after power loss uses the flash record */ + for (p = _bss_start; p < _bss_end; p++) + *p = 0; + ldr_main(); +} diff --git a/firmware/loader/loader.ld b/firmware/loader/loader.ld new file mode 100644 index 0000000..acadd26 --- /dev/null +++ b/firmware/loader/loader.ld @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* Felucca update loader: one RAM image at the address the SPL loads it to. + * Everything (code, constants, data) lives in RAM: the loader rewrites the + * flash, so nothing may execute from XIP. Stacks far above, clear of the + * update record (0x01C7FD88) and the crash record (0x01C7C000). */ +MEMORY +{ + LDR (rwx) : ORIGIN = 0x01C0A800, LENGTH = 0x14000 +} +SECTIONS +{ + .text : { + KEEP(*(.text.crt0)) *(.text*) *(.ram_text*) *(.rodata*) *(.data*) *(.sdata*) + . = ALIGN(4); _image_end = .; + } > LDR + .bss (NOLOAD) : { _bss_start = .; *(.bss*) *(.sbss*) *(COMMON) . = ALIGN(4); _bss_end = .; } > LDR + _stack_top = 0x01C70000; + _sstack_top = 0x01C72000; + /DISCARD/ : { *(.comment) *(.note*) *(.noinit*) } +} diff --git a/firmware/src/arranger.c b/firmware/src/arranger.c new file mode 100644 index 0000000..de3efbf --- /dev/null +++ b/firmware/src/arranger.c @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-3.0-only */ +/* Firmware adapter. Scene snapshots are already resident in RAM. No flash + * operation, UI draw or allocation is allowed from these audio callbacks. */ +#include "arranger.h" +static arr_config_t arrangement; +static arr_clock_t arrangement_clock; +static uint8_t arrangement_enabled; +static uint32_t arrangement_ready(void); /* project.c */ +static void arrangement_apply(uint32_t scene); /* project.c */ + +static int arrangement_start(void) +{ + int scene; + if (!arrangement_enabled) return 1; + scene = arr_begin(&arrangement_clock, &arrangement, arrangement_ready()); + if (scene < 0) return 0; + arrangement_apply((uint32_t)scene); + song.rec = 0; /* song playback does not overwrite patterns */ + return 1; +} diff --git a/firmware/src/arranger.h b/firmware/src/arranger.h new file mode 100644 index 0000000..b6b4cf1 --- /dev/null +++ b/firmware/src/arranger.h @@ -0,0 +1,72 @@ +/* SPDX-License-Identifier: GPL-3.0-only */ +/* Song order, independent of UI/flash/audio drivers. Durations are 4/4 bars. + * Audio calls next BEFORE rendering a block, then elapse AFTER it. The clock + * accumulates samples * BPM, keeping the remainder at every bar boundary. */ +#ifndef FM1_ARRANGER_H +#define FM1_ARRANGER_H +#include +#define ARR_STEPS 16u +#define ARR_SCENES 4u +#define ARR_NONE (-1) +#define ARR_DONE (-2) +#define ARR_INVALID (-3) +typedef struct { uint8_t scene, bars; } arr_entry_t; +typedef struct { + uint8_t count, loop, reserved[2]; + arr_entry_t entry[ARR_STEPS]; +} arr_config_t; +typedef struct { + uint32_t phase; + uint8_t running, index, bar, error; +} arr_clock_t; + +static void arr_defaults(arr_config_t *c) +{ + uint32_t i; + c->count = 4; c->loop = 0; c->reserved[0] = c->reserved[1] = 0; + for (i = 0; i < ARR_STEPS; i++) { + c->entry[i].scene = (uint8_t)(i % ARR_SCENES); + c->entry[i].bars = 4; + } +} +static int arr_valid(const arr_config_t *c, uint32_t ready) +{ + uint32_t i; + if (!c->count || c->count > ARR_STEPS || c->loop > 1u) return 0; + for (i = 0; i < c->count; i++) { + const arr_entry_t *e = &c->entry[i]; + if (e->scene >= ARR_SCENES || !e->bars || e->bars > 64u || + !(ready & (1u << e->scene))) return 0; + } + return 1; +} +static int arr_begin(arr_clock_t *r, const arr_config_t *c, uint32_t ready) +{ + r->phase = 0; r->index = 0; r->bar = 0; r->running = 0; + r->error = (uint8_t)!arr_valid(c, ready); + if (r->error) return ARR_INVALID; + r->running = 1; + return c->entry[0].scene; +} +static int arr_next(arr_clock_t *r, const arr_config_t *c, uint32_t sample_rate) +{ + int result = ARR_NONE; + uint32_t period = sample_rate * 240u; + if (!r->running || !period) return ARR_NONE; + while (r->phase >= period) { + r->phase -= period; + if (++r->bar < c->entry[r->index].bars) continue; + r->bar = 0; + if (++r->index >= c->count) { + if (!c->loop) { r->running = 0; return ARR_DONE; } + r->index = 0; + } + result = c->entry[r->index].scene; + } + return result; +} +static void arr_elapse(arr_clock_t *r, uint32_t samples, uint32_t bpm) +{ + if (r->running) r->phase += samples * bpm; +} +#endif diff --git a/firmware/src/arranger_scene.c b/firmware/src/arranger_scene.c new file mode 100644 index 0000000..b53c292 --- /dev/null +++ b/firmware/src/arranger_scene.c @@ -0,0 +1,52 @@ +/* SPDX-License-Identifier: GPL-3.0-only */ +/* Shared scene application for firmware and host audio integration tests. */ +static uint32_t arrangement_ready(void) +{ + uint32_t i, ready = 0; + for (i = 0; i < ARR_SCENES; i++) + if (proj_ok(&proj_slot[i])) ready |= 1u << i; + return ready; +} + +/* Called only at an audio-block boundary, after validation of all slots at + * start. The song keeps one tempo and global FX across every section (only the drum + * level and reverb come from it). */ +static void arrangement_apply(uint32_t scene) +{ + uint32_t k; + for (k = 0; k < NTRK; k++) { + track_t *t = &trk[k]; + seq_release(t); + trk_all_off(t); + t->nheld = t->arp_phys = t->arp_note = t->rh_n = t->rskip_n = 0; + t->rskip_lanes = 0; + } + proj_apply(&proj_slot[scene], 0); + sync_reload = 1; + ui.force = 1; +} + +/* ---- song mode keeps the loop you made: PLAY in song mode puts it aside (each section then plays + * over the tracks), STOP (or the song's end) brings it back */ +static project_t song_keep __attribute__((section(".pool"))); +static uint8_t song_kept; +static void song_backup(void) /* (audio ISR: seq_start) */ +{ + proj_capture(&song_keep); + song_kept = 1; +} +static void song_restore(void) /* (audio ISR: seq_stop) */ +{ + uint32_t i; + if (!song_kept) + return; + song_kept = 0; + for (i = 0; i < NTRK; i++) { + trk_all_off(&trk[i]); + trk[i].nheld = trk[i].arp_phys = trk[i].arp_note = 0; + } + proj_apply(&song_keep, 1); + song.sel = (uint8_t)(song_keep.sel < NTRK ? song_keep.sel : 0u); + sync_reload = 1; + ui.force = 1; +} diff --git a/firmware/src/audio.c b/firmware/src/audio.c new file mode 100644 index 0000000..2ef77ef --- /dev/null +++ b/firmware/src/audio.c @@ -0,0 +1,117 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* I2S output (ALNK0 -> external codec) and the audio ISR: each half buffer is + * rendered in blocks of CTL samples by mix_block (fx.c: events -> each synth part + * -> dist -> level / pan -> sends -> drums -> buses -> master), then scaled to 24-bit stereo. */ +/* registers: hal/fm1_audio.h */ +#define HALF_WORDS (HALF_FRAMES * 2u) +#define OUT_SHIFT 7 /* Q15 -> 24-bit, -6 dBFS ceiling */ + +static int32_t abuf[2u * HALF_WORDS] __attribute__((aligned(4))); + +/* diagnostics, kept across resets and UBOOT entry: read with `fm1t memr` */ +#define DBG_MAGIC 0x44424731u /* "DBG1" */ +struct felucca_dbg { + uint32_t magic, halves, max_us, nested, in_audio, late, timer_irqs, ui_frames; + uint32_t last_us, cpu_q8, boots; + uint32_t stage, page, home; /* where the main loop is (breadcrumbs) */ + uint32_t prev_stage, prev_page, prev_home, prev_rst, prev_frames; /* as found at boot */ +} felucca_dbg __attribute__((section(".noinit"))); +static volatile uint32_t audio_halves, audio_max_us; +#define SCOPE_N 512u +static int16_t scope_buf[SCOPE_N]; +static uint32_t scope_w; + +static void audio_block(int32_t *out, uint32_t n) /* mix (fx.c), then Q15 -> 24 bit */ +{ + uint32_t i; + mix_block(out, n); + for (i = 0; i < n; i++) { + if (i & 1u) + scope_buf[scope_w++ & (SCOPE_N - 1u)] = (int16_t)out[2u * i]; + out[2u * i] <<= OUT_SHIFT; + out[2u * i + 1u] <<= OUT_SHIFT; + } +} + +/* overload: a half that took > 85 % of its time sheds one voice before the + * next one, over all parts: the quietest releasing voice fades out over the next + * block (voice_kill), else the oldest held one goes into its release (stopped by + * a later shed if still needed). The only held voice is never touched, so a dense + * chord on a heavy engine thins out instead of starving the CPU. */ +static volatile uint8_t shed_req; +static uint32_t shed_count; + +static void shed_voice(void) +{ + uint32_t p, i, ngate = 0; + voice_t *best = 0; + for (p = 0; p < NPART; p++) + for (i = 0; i < NVOICE; i++) { + voice_t *v = &trk[p].v[i]; + if (v->active && !v->gate && v->stage != 4u && (!best || v->env < best->env)) + best = v; + } + if (best) { + voice_kill(best); + shed_count++; + return; + } + for (p = 0; p < NPART; p++) + for (i = 0; i < NVOICE; i++) { + voice_t *v = &trk[p].v[i]; + if (v->active && v->gate) { + ngate++; + if (!best || v->age < best->age) + best = v; + } + } + if (ngate > 1u) { + best->gate = 0; + best->stage = 3; + shed_count++; + } +} + +void fm1_alnk0_irq(void) /* via isr_alnk0 (hal/fm1_isr.S) */ +{ + uint8_t p = fm1_audio_pending(); + uint32_t t0 = fm1_ticks(); + fm1_audio_ack_aux(p); + felucca_dbg.in_audio = 1; + if (p & FM1_AUDIO_HALF) { + uint32_t half = fm1_audio_free_half(), b, us; + int32_t *o = &abuf[half * HALF_WORDS]; + if (shed_req) { + shed_req = 0; + shed_voice(); + } + for (b = 0; b < HALF_FRAMES; b += CTL) + audio_block(o + 2u * b, CTL); + fm1_audio_ack_half(); + audio_halves++; + us = (fm1_ticks() - t0) / FM1_TICKS_PER_US; + if (us > audio_max_us) + audio_max_us = us; + if (us * 100u > (HALF_FRAMES * 1000000u / FS) * 85u) + shed_req = 1; + song.cpu_q8 = (song.cpu_q8 * 15u + (us * 256u) / (HALF_FRAMES * 1000000u / FS)) / 16u; + if (fm1_audio_free_half() != half) + felucca_dbg.late++; /* the DMA moved on while we rendered */ + felucca_dbg.halves++; + felucca_dbg.last_us = us; + if (us > felucca_dbg.max_us) + felucca_dbg.max_us = us; + felucca_dbg.cpu_q8 = song.cpu_q8; + } + felucca_dbg.in_audio = 0; +} +extern void isr_alnk0(void); + +static void audio_init(void) /* hal/fm1_audio.h */ +{ + uint32_t i; + for (i = 0; i < 2u * HALF_WORDS; i++) + abuf[i] = 0; + fm1_audio_init(abuf, HALF_WORDS, isr_alnk0, 3); +} diff --git a/firmware/src/bootguard.h b/firmware/src/bootguard.h new file mode 100644 index 0000000..193d985 --- /dev/null +++ b/firmware/src/bootguard.h @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-3.0-only */ +/* Warm-reset guard, retained in RAM only. Never writes the bootloader/flash. + * This cannot rescue an image that fails before reaching the application. */ +#ifndef FELUCCA_BOOTGUARD_H +#define FELUCCA_BOOTGUARD_H +#include +#define BOOTGUARD_MAGIC 0x42475232u +typedef struct { uint32_t magic, failed, pending; } bootguard_t; +enum { BOOT_NORMAL, BOOT_RECOVERY, BOOT_ROM }; +static void bootguard_clear(bootguard_t *b) +{ + b->magic = BOOTGUARD_MAGIC; + b->failed = b->pending = 0; +} +static uint32_t bootguard_begin(bootguard_t *b) +{ + if (b->magic != BOOTGUARD_MAGIC || b->failed > 2u || b->pending > 2u) + bootguard_clear(b); + if (b->pending == 2u) { /* recovery itself reset: keep ROM fallback */ + bootguard_clear(b); + return BOOT_ROM; + } + if (b->pending && b->failed < 2u) b->failed++; + b->pending = b->failed >= 2u ? 2u : 1u; + return b->pending == 2u ? BOOT_RECOVERY : BOOT_NORMAL; +} +static int bootguard_manual(uint32_t buttons) +{ + return (buttons & 3u) == 1u; /* physical OCT- alone; both keep calibration */ +} +#endif diff --git a/firmware/src/console.c b/firmware/src/console.c new file mode 100644 index 0000000..f2bc6c5 --- /dev/null +++ b/firmware/src/console.c @@ -0,0 +1,308 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* Serial console on the CDC-ACM function (FELUCCA_CDC=1): read-only + * diagnostics. Runs in the main loop (cdc_task); usb_poll moves the bytes. + * The baud rate is ignored. Nothing here writes memory or flash; `uboot` + * does what the SysEx soft key does. */ +#define CON_LINE 64u + +static struct { + char line[CON_LINE]; + uint32_t len; + uint8_t dtr_seen, stalled; /* stalled: the host stopped reading, drop the rest of this reply */ +} con; + +static void con_putc(char c) +{ + uint32_t t0 = fm1_ms; + while (co_w - co_r >= CO_N) { /* full: wait for usb_poll, briefly */ + if (!cdc.dtr || con.stalled || fm1_ms - t0 > 20u) { + con.stalled = 1; + return; + } + fm1_wdt_feed(); + } + cdc_out[co_w % CO_N] = (uint8_t)c; + RING_PUBLISH(); + co_w++; +} + +static void con_puts(const char *s) +{ + while (*s) + con_putc(*s++); +} + +static void con_hex(uint32_t v, uint32_t digits) +{ + while (digits--) + con_putc("0123456789ABCDEF"[(v >> (digits * 4u)) & 15u]); +} + +static void con_dec(int32_t v) +{ + char b[12]; + uint32_t n = 0, u = v < 0 ? (uint32_t)-v : (uint32_t)v; + if (v < 0) + con_putc('-'); + do + b[n++] = (char)('0' + u % 10u); + while ((u /= 10u) != 0 && n < sizeof b); + while (n) + con_putc(b[--n]); +} + +static void con_kv(const char *k, int32_t v) /* "key value\r\n" */ +{ + con_puts(k); + con_putc(' '); + con_dec(v); + con_puts("\r\n"); +} + +static void con_kx(const char *k, uint32_t v) +{ + con_puts(k); + con_puts(" 0x"); + con_hex(v, 8); + con_puts("\r\n"); +} + +static uint32_t con_num(const char **p, int *ok) /* decimal or 0x hex */ +{ + const char *s = *p; + uint32_t v = 0, base = 10, d, n = 0; + while (*s == ' ') + s++; + if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X')) + s += 2, base = 16; + for (;; s++, n++) { + char c = *s; + if (c >= '0' && c <= '9') + d = (uint32_t)(c - '0'); + else if (base == 16 && c >= 'a' && c <= 'f') + d = (uint32_t)(c - 'a' + 10); + else if (base == 16 && c >= 'A' && c <= 'F') + d = (uint32_t)(c - 'A' + 10); + else + break; + v = v * base + d; + } + *ok = n > 0; + *p = s; + return v; +} + +static int con_word(const char **p, const char *w) /* match a whole word */ +{ + const char *s = *p; + while (*s == ' ') + s++; + while (*w && *s == *w) + s++, w++; + if (*w || (*s && *s != ' ')) + return 0; + *p = s; + return 1; +} + +static void con_memr(const char *p) +{ + int ok, ok2; + uint32_t a = con_num(&p, &ok), n = con_num(&p, &ok2), i; + if (!ok) { + con_puts("usage: memr ADDR [LEN<=256]\r\n"); + return; + } + if (!ok2 || !n) + n = 64; + if (n > 256u) + n = 256; + if (!fm1_mem_readable(a, n)) { + con_puts("only RAM 01C00000-01C80000 and XIP 02000000-02100000\r\n"); + return; + } + for (i = 0; i < n; i++) { + if (i % 16u == 0) { + con_hex(a + i, 8); + con_putc(':'); + } + con_putc(' '); + con_hex(fm1_peek8(a + i), 2); + if (i % 16u == 15u || i + 1u == n) + con_puts("\r\n"); + } +} + +#if FELUCCA_FLASH +static void con_flr(const char *p) /* flash read over SPI (no XIP decryption) */ +{ + static uint8_t b[256]; + int ok, ok2; + uint32_t a = con_num(&p, &ok), n = con_num(&p, &ok2), i; + if (!ok || a < 0x93000u || a >= 0x100000u) { + con_puts("usage: flr OFFSET [LEN<=256] (0x93000..0xFFFFF)\r\n"); + return; + } + if (!ok2 || !n) + n = 64; + if (n > 256u) + n = 256; + if (a + n > 0x100000u) + n = 0x100000u - a; + if (!flash_ok || st_read(a, b, n)) { + con_puts("flash not available\r\n"); + return; + } + for (i = 0; i < n; i++) { + if (i % 16u == 0) { + con_hex(a + i, 6); + con_putc(':'); + } + con_putc(' '); + con_hex(b[i], 2); + if (i % 16u == 15u || i + 1u == n) + con_puts("\r\n"); + } +} +#endif + +static void con_status(void) +{ + const engine_t *e = ENGINES[TSEL->eng_req % NENGINES]; + con_puts("felucca "); + con_puts(FELUCCA_VERSION); + con_puts("\r\n"); + con_kv("uptime_ms", (int32_t)fm1_ms); + con_kv("cpu_pct", (int32_t)(song.cpu_q8 * 100u / 256u)); + con_kv("audio_max_us", (int32_t)felucca_dbg.max_us); + con_kv("voices_shed", (int32_t)shed_count); + con_kv("voices_given_up", (int32_t)voice_kills); + con_kv("track", (int32_t)song.sel + 1); + con_kv("batt_raw", song.batt_raw); + con_puts("engine "); + con_puts(e->name); + con_puts("\r\n"); + con_puts("preset "); + con_puts(TSEL->preset < e->npresets ? e->presets[TSEL->preset].name : "-"); + con_puts("\r\n"); + con_kv("bpm", song.g[G_BPM]); + con_kv("playing", song.playing); + con_kv("boots", (int32_t)felucca_dbg.boots); + con_kv("usb_resets", (int32_t)usb.resets); + con_kv("usb_sof", (int32_t)usb.sof_seen); + con_kv("usb_suspends", (int32_t)usb.suspends); + con_kv("usb_retries", (int32_t)usb.retries); + con_kv("usb_frame", (int32_t)usb.frame); + con_kv("usb_frame_stalls", (int32_t)usb.frame_stalls); + con_kv("usb_max_gap_polls", (int32_t)usb.max_gap); + con_kv("midi_rx_pkts", (int32_t)usb.rx_pkts); + con_kv("midi_tx_pkts", (int32_t)usb.tx_pkts); +#if FELUCCA_FLASH + con_kv("flash", flash_ok); +#endif +} + +static void con_dbg(void) +{ + const uint32_t *w = (const uint32_t *)&felucca_dbg; + static const char *const NAMES[] = {"magic", "halves", "max_us", "nested", "in_audio", "late", + "timer_irqs", "ui_frames", "last_us", "cpu_q8", "boots", + "stage", "page", "home", "prev_stage", "prev_page", + "prev_home", "prev_rst", "prev_frames"}; + uint32_t i; + for (i = 0; i < sizeof NAMES / sizeof NAMES[0] && i < sizeof felucca_dbg / 4u; i++) + con_kx(NAMES[i], w[i]); +} + +static void con_crash(void) +{ + if (fm1_crash.magic != FM1_CRASH_MAGIC) { + con_puts("no crash record\r\n"); + return; + } + con_kv("count", (int32_t)fm1_crash.count); + con_kx("vec", fm1_crash.vec); + con_kx("pc", fm1_crash.pc); + con_kx("rets", fm1_crash.rets); + con_kx("emu", fm1_crash.emu); + con_kx("sp", fm1_crash.sp); + con_kx("psr", fm1_crash.psr); + con_kv("uptime_ms", (int32_t)fm1_crash.uptime_ms); + con_kv("early", (int32_t)fm1_crash.early); +} + +static void con_params(void) +{ + uint32_t i; + for (i = 0; i < P_COUNT; i++) { + con_dec((int32_t)i); + con_putc('='); + con_dec(TSEL->p[i]); + con_puts(i % 8u == 7u || i + 1u == P_COUNT ? "\r\n" : " "); + } +} + +static void con_exec(const char *p) +{ + if (con_word(&p, "help") || con_word(&p, "?")) + con_puts("status dbg crash params memr ADDR [LEN] flr OFF [LEN] uboot yes\r\n"); + else if (con_word(&p, "status")) + con_status(); + else if (con_word(&p, "dbg")) + con_dbg(); + else if (con_word(&p, "crash")) + con_crash(); + else if (con_word(&p, "params")) + con_params(); + else if (con_word(&p, "memr")) + con_memr(p); +#if FELUCCA_FLASH + else if (con_word(&p, "flr")) + con_flr(p); +#endif + else if (con_word(&p, "uboot")) { + if (con_word(&p, "yes")) { + con_puts("entering UBOOT\r\n"); + usb.uboot_req = 1; /* main loop: same path as the SysEx key */ + } else { + con_puts("type 'uboot yes'\r\n"); + } + } else if (*p) + con_puts("? (help)\r\n"); +} + +static void cdc_task(void) /* main loop */ +{ + if (cdc.dtr && !con.dtr_seen) { + con_puts("\r\nFelucca "); + con_puts(FELUCCA_VERSION); + con_puts(" console - 'help'\r\n> "); + } + con.dtr_seen = cdc.dtr; + while (ci_r != ci_w) { + char c; + RING_PUBLISH(); /* usb_poll (producer) can preempt us */ + c = (char)cdc_in[ci_r % CI_N]; + RING_PUBLISH(); + ci_r++; + if (c == '\r' || c == '\n') { + if (c == '\n' && con.len == 0) + continue; /* the LF of a CR LF */ + con_puts("\r\n"); + con.line[con.len] = 0; + con.stalled = 0; + con_exec(con.line); + con.len = 0; + con_puts("> "); + } else if (c == 0x7F || c == 0x08) { + if (con.len) { + con.len--; + con_puts("\b \b"); + } + } else if (c >= ' ' && c < 0x7F && con.len + 1u < CON_LINE) { + con.line[con.len++] = c; + con_putc(c); + } + } +} diff --git a/firmware/src/core.h b/firmware/src/core.h new file mode 100644 index 0000000..a2036ee --- /dev/null +++ b/firmware/src/core.h @@ -0,0 +1,279 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* Felucca core types: tracks, voices, engines, parameters. + * Four tracks: tracks 1..3 are synth parts (each its own engine, preset, parameters, + * voices and 64-step pattern), track 4 is the GM drum part (drums.c; its own voices, + * pattern and the pattern parameters of its track_t). The parts share one budget of + * NVOICE sounding voices (voice.c). */ +#include +#define NVOICE 8 /* voices per part, and the budget shared by all parts */ +#define NPOLY 8 +#define NPART 3 /* synth parts: tracks 1..3 */ +#define NTRK 4 /* + the drum track */ +#define TRK_DRUM 3 +enum { V_POLY, V_MONO, V_LEGATO, V_UNISON }; /* P_VOICE */ +#define NSTEP 64 +#define HALF_FRAMES 256 /* I2S half buffer: 5.8 ms at 44.1 kHz */ +#ifndef FELUCCA_SLICE +#define FELUCCA_SLICE 0 /* the SLICE engine (eng_slice.c): kept in the tree, not built by default */ +#endif +#define NENGINES (9 + FELUCCA_SLICE) /* SLICE, when built, comes last: the other engines keep their numbers */ +#define UP_SLOTS 32u /* user presets (upreset.c) */ + +/* ------------------------------------------------------- parameters --- */ +enum { + F_INT, F_PCT, F_BIPCT, F_TIME, F_LFOHZ, F_CUTOFF, F_DB, F_SEMI, F_ENUM, F_BPM, F_NOTE, + F_ONOFF, F_OCT, F_STEPS, + F_SWING, /* 0..100: MPC swing, 50 % (straight) .. 75 % */ + F_FILT /* -64..63: the DJ filter, LP <- OFF -> HP */ +}; + +typedef struct { + const char *label; + uint8_t fmt; + int16_t min, max, def; + const char *const *names; /* F_ENUM */ + const char *unit; /* F_INT / F_ENUM optional unit */ +} param_desc_t; + +enum { /* per-track parameters */ + P_LEVEL, + P_ATK, P_DEC, P_SUS, P_REL, + P_ED_FLT, P_ED_PIT, P_ED_SHP, P_ED_FX, /* P_ED_FX: unused, kept for the formats / protocol */ + P_LRATE, P_LWAVE, P_LPHASE, P_LFADE, + P_LD_PIT, P_LD_FLT, P_LD_SHP, P_LD_AMP, + P_AMODE, P_ARATE, P_AOCT, P_AGATE, + P_ASWING, P_APROB, P_AHOLD, P_AORDER, + P_ROOT, P_SCALE, P_QUANT, P_TRANS, + P_SLEN, P_SDIV, P_SSWING, P_SGATE, + P_DIST, P_CHOR, P_DLY, P_REV, + P_VOICE, P_GLIDE, P_PAN, P_MUTE, + P_GLMODE, P_PRIO, P_ALLOC, P_DETUNE, + P_SLCR, P_SLPAT, P_SLRATE, P_SLDEPTH, /* SLICER insert (slicer.c); new common parameters go just + * before P_E0 (user presets and projects map by count) */ + P_CHORD, /* chord mode: one key plays a chord of the scale (seq.c) */ + P_E0, P_E1, P_E2, P_E3, P_E4, P_E5, P_E6, P_E7, + P_COUNT +}; + +enum { /* global parameters */ + G_BPM, G_SWING, G_CLOCK, G_TUNE, + G_DTIME, G_DFDBK, G_DCOLOR, G_DMIX, + G_RSIZE, G_RDAMP, G_CRATE, G_CDEPTH, + G_MIDI, G_SYNC, G_ROUTE, G_INFO, + G_SLOT, G_NAME, G_LOAD, G_SAVE, + G_ENGSEL, G_ENGGO, /* no page (the ENGINE page is gone); a SET of G_ENGSEL switches the engine (editor) */ + G_CLRSEQ, G_INITSND, + G_DRCH, G_DRLVL, G_DRREV, + G_DUST, G_DUCK, G_FILT, /* the master bus: lo-fi / vinyl, the kick ducking the parts, the DJ filter (fx.c) */ + G_ROLL, /* note repeat rate (ARP + key, seq.c) */ + G_NEWPRJ, /* TOOLS > NEW: a new project (GO) */ + G_COUNT +}; + +/* ----------------------------------------------------------- voices --- */ +typedef struct { + uint8_t note, vel, gate, active; + uint8_t stage; /* env: 0 off, 1 attack, 2 decay/sustain, 3 release, 4 fading out (given up) */ + uint8_t kill; /* stage 4: blocks of the fade left */ + uint8_t pitch_frac; /* the glide between 1/16 semitones: pitch_cur + pitch_frac / 256 */ + int16_t penv; /* the pitch envelope (ENV > PIT): Q15, a fast fall from the note's start */ + int32_t env; /* Q24 */ + int32_t env_out; /* last control-rate amplitude, Q15 */ + int32_t pitch16, pitch_cur; /* 1/16 semitone, with glide */ + int32_t gstep; /* glide: 1/4096 semitone per control tick, 0 = RATE (GLIDE: the time an octave takes) */ + int32_t fine; /* unison detune: phase increment * (1 + fine / 4096) */ + uint32_t ph[3]; + int32_t s[8]; /* engine state (filters, envs) */ + uint32_t age; +} voice_t; + +typedef struct { /* per-voice control-rate modulation, computed in voice.c */ + uint32_t inc; /* phase increment of the base pitch */ + int32_t pitch16; + int32_t amp0, amp1; /* Q15 ramp over the block */ + int32_t cutoff; /* 0..127 << 8 */ + int32_t shape; /* 0..127 << 8 */ + int32_t envq15; /* env value (for engines that use it as a mod source) */ +} vmod_t; + +typedef struct { + const char *name; + int8_t e[8]; /* P_E0..P_E7 (signed: an interval below the note; every value fits) */ + uint8_t env[4]; /* ATK DEC SUS REL */ + int8_t fenv; /* ENV -> FILTER amount (-64..63) */ + uint8_t mono; /* 1 = MONO (bass / lead), 0 = POLY */ + /* the rest of the patch; each value is stored + 1, 0 = the default */ + uint8_t fx[4]; /* DIST, CHORUS, DELAY, REVERB sends */ + uint8_t arp[4]; /* MODE, RATE, OCT, GATE */ + uint8_t pat; /* sequence pattern (PATTERNS[pat - 1]), loaded only into an empty sequencer */ + int8_t x[8]; /* more of the patch: up to 4 (track parameter id + 1, value) pairs, 0 = none + * (glide, pitch / LFO modulation, voice mode...: preset_extras) */ +} preset_t; +#define FX(d, c, dl, r) .fx = {(d) + 1, (c) + 1, (dl) + 1, (r) + 1} +#define ARP(m, rt, o, g) .arp = {(m) + 1, (rt) + 1, (o) + 1, (g) + 1} +#define PAT(n) .pat = (n) +#define XP(...) .x = {__VA_ARGS__} /* XP(P_GLIDE + 1, 30, P_ED_PIT + 1, 8): parameter id + 1, value */ + +struct track; +typedef struct { + const char *name; /* "VA" */ + const char *page_title[2]; + param_desc_t edit[8]; /* P_E0..P_E7 */ + const preset_t *presets; + uint8_t npresets; + int8_t fil_page; /* EDIT page that holds the filter, -1 = none */ + void (*note_on)(struct track *t, voice_t *v); + void (*render)(struct track *t, voice_t *v, int32_t *out, uint32_t n, const vmod_t *m); + uint16_t color; /* accent colour of the engine (RGB565) */ + uint8_t macro[4]; /* HOME: the four parameters on KNOB 1..4 */ + uint8_t poly; /* voice cap for POLY and UNISON, 0 = NVOICE */ + /* optional (0 = none): the voice amplitude instead of the ADSR curve, once per control tick; + * gets the ADSR value (Q15, env_tick already ran: it still gates the voice), returns Q15 */ + int32_t (*amp)(struct track *t, voice_t *v, int32_t adsr); + /* optional: a mode-dependent descriptor of EDIT k (the same range and default as edit[k], + * another label / value names), 0 = edit[k] */ + const param_desc_t *(*desc)(const struct track *t, uint32_t k); + /* optional: once per block and part, before its voices (also with no voice sounding) */ + void (*block)(struct track *t); +} engine_t; + +/* ------------------------------------------------------------ track --- */ +enum { ST_NOTE, ST_TIE, ST_REST }; +#define SF_ACCENT 1u +#define SF_SLIDE 2u +/* the dynamics of a note or a drum hit (2 bits each in the steps): played without velocity + * (OCT- / OCT+ held on the drum track, the step page) or from a MIDI velocity */ +enum { LV_NORM, LV_GHOST, LV_SOFT, LV_HARD }; +typedef struct { /* a step of a synth part (10 bytes): up to 4 notes (POLY), time, accent, slide */ + uint8_t note[4]; + uint8_t n; /* notes in use, 0 = empty */ + uint8_t time; /* ST_NOTE / ST_TIE / ST_REST */ + uint8_t flags; /* SF_ACCENT | SF_SLIDE */ + uint8_t vel; + uint8_t lvl; /* 2 bits per note (note k: bits 2k..2k+1): LV_* */ + uint8_t rat; /* 2 bits per note: the hits it plays in its step - 1 (ratchet x1..x4) */ +} step_t; +#define DRUM_LANES 16 /* the drum track: 16 sounds, one per white key (drums.c LANE_*) */ +typedef struct { /* a step of the drum track (10 bytes, the size of a step_t) */ + uint8_t on[2]; /* bit per lane */ + uint8_t lvl[4]; /* 2 bits per lane (lane k: byte k / 4, bits 2 (k % 4)..): LV_* */ + uint8_t rat[4]; /* 2 bits per lane: ratchet */ +} dstep_t; +_Static_assert(sizeof(step_t) == 10 && sizeof(dstep_t) == 10, "a step is 10 bytes on every track"); + +typedef struct track { + int16_t p[P_COUNT]; + uint8_t engine, preset; /* engine: what the audio ISR renders */ + uint8_t eng_req; /* engine the UI asked for (the ISR switches at a block start) */ + uint8_t user; /* user preset slot + 1 the sound came from (UI), 0 = none */ + voice_t v[NVOICE]; + /* LFO */ + uint32_t lfo_ph; + int32_t lfo_val; /* Q15 */ + int32_t lfo_fade; /* Q15 ramp after note-on */ + uint32_t lfo_rnd; + /* keyboard / arp input: held notes in press order */ + uint8_t held[16]; + uint8_t nheld; + uint8_t arp_phys; /* keys physically held for the arp */ + uint8_t latched; /* HOLD: keep notes after release */ + /* arp runtime (clock units: samples x BPM, fx.c BEAT_U) */ + uint32_t arp_pos; /* stopped: units into the current arp step */ + uint32_t arp_abs; /* playing: the arp step of the transport grid last played */ + uint32_t arp_idx; + uint8_t arp_note; /* sounding arp note, 0 = none */ + uint8_t arp_new; /* a chord just started: its first note now */ + uint32_t arp_off; /* units to its note-off */ + /* sequencer: synth parts step[], the drum track dstep[] (16 lanes) */ + union { + step_t step[NSTEP]; + dstep_t dstep[NSTEP]; + }; + uint32_t seq_abs; /* the step of the transport grid last played (seq.c trk_grid), SEQ_NONE */ + uint16_t seq_idx; /* its index in the pattern */ + uint8_t seq_notes[4]; /* sounding seq notes */ + uint8_t seq_n; + uint8_t seq_hold; /* last step slides: keep the notes until the next step */ + uint8_t slide_glide; /* next legato note glides (slide) */ + uint32_t seq_off; /* units to the note-off of the step's notes */ + uint8_t seq_active; /* any step programmed */ + uint8_t rat_done[4]; /* ratchet hits played in this step: per note (synth) */ + uint32_t rat_lanes; /* .. per lane (drums): 2 bits each */ + uint32_t rskip_abs; /* live recording put notes into the step about to play: */ + uint8_t rskip_n, rskip[4]; /* do not trigger them again there (they sound already) */ + uint16_t rskip_lanes; /* (the drum track: lanes) */ + /* live recording of held notes (seq.c rec_hold): the steps they are held into become TIEs */ + uint8_t rh_n, rh_note[4]; /* recorded notes still held, 0 = none */ + uint8_t rh_start; /* the step they were recorded into */ + uint8_t rh_ties; /* TIE steps written after it */ + uint8_t rh_last; /* the last of them; rh_bak: what it held (an early release puts it back) */ + uint32_t rh_last_abs; /* (its step of the transport grid) */ + step_t rh_bak; + uint32_t pass; /* loops played since PLAY (a recording pass: one undo) */ + /* mono */ + uint8_t mono_stack[8]; + uint8_t nmono; + uint8_t mono_note; /* note the MONO / LEGATO / UNISON voice(s) play, 0 = none */ + uint8_t rr; /* POLY ROTATE: next voice to try */ + /* mix runtime */ + int32_t peak; + int32_t dist_hp, dist_lp1, dist_lp2; /* DIST insert state (fx.c) */ + int32_t att; /* mute / solo fade: attenuation, Q15 (0 = heard; fx.c mix_part, drums_mix) */ + uint8_t dist_on; /* DIST was on in the last block (its states restart when it comes on) */ + uint8_t tail; /* blocks to mix after the last voice (the DIST tail) */ + int16_t armp, aholdp; /* P_AMODE / P_AHOLD as last seen by the ISR */ + /* engine switch (voice.c engine_block): the old engine's voices fade out, then it switches */ + uint8_t xf_on, xf; /* fading; blocks of the fade still to render */ + int16_t pe_old[8]; /* P_E0..P_E7 of the sounding engine: the fade renders with these */ + uint8_t xp_n, xp_note[4], xp_vel[4]; /* note-ons during the fade, played on the new engine */ +} track_t; + +typedef struct { + int16_t g[G_COUNT]; + uint8_t playing, seq_mode; + uint8_t rec; /* live recording armed: bit per track */ + uint8_t sel; /* selected track 0..NTRK-1: keys, pages, editor */ + int8_t octave; + volatile uint8_t solo; /* bit per track soloed (GLO + key), 0 = none: the others are silent */ + uint32_t tick; /* sub-blocks since play */ + uint32_t cpu_q8; /* audio ISR load, 1/256 */ + uint32_t master_q12; + int32_t batt_raw; /* smoothed ADC ch3 (battery divider), 0 = not read yet */ +} song_t; + +static track_t trk[NTRK]; /* the instrument: three parts and the drum track */ +static song_t song; + +/* The transport clock (seq.c runs it). One unit = one sample at 1 BPM: a beat is BEAT_U units at any + * tempo, and every division of it (1/4 .. 1/64, the triplets) is a whole number of units. The steps + * of every track, the arp, the rolls, the click, the SLICER and the song arranger (which counts the + * same units) all follow it: no rounding, no drift between them, a tempo change moves them together. + * clk_beat: beats since PLAY, clk_pos: units into that beat, at the start of the block being rendered + * (events_block advances it by CTL x BPM after the block's events). */ +#ifndef FS +#define FS 44100 /* (as build/gen/felucca_tables.h: tools/gen_tables.py) */ +#endif +#define BEAT_U ((uint32_t)FS * 60u) +static volatile uint32_t clk_beat, clk_pos; +static const uint8_t DIV_DEN[6] = {1, 2, 4, 8, 3, 6}; /* N_DIV: beats = 1 / DEN */ +static uint32_t div_units(uint32_t div) { return BEAT_U / DIV_DEN[div % 6u]; } +/* length of one division (N_DIV order) in samples at the song tempo (rounded down) */ +static uint32_t div_samples(uint32_t div) +{ + return div_units(div) / (uint32_t)song.g[G_BPM]; +} +#define TSEL (&trk[song.sel]) /* the selected track */ +#define TDRUM (&trk[TRK_DRUM]) +static int is_drum(const track_t *t) { return t == TDRUM; } +/* silent: MUTE, or another track is soloed */ +static int trk_silent(const track_t *t) +{ + uint32_t i = (uint32_t)(t - trk); + return t->p[P_MUTE] || (song.solo && !((song.solo >> i) & 1u)); +} +#define RING_PUBLISH() __asm__ volatile("" ::: "memory") /* slot store before the index update */ +static volatile uint32_t fm1_ms; /* milliseconds since boot (TIMER4-based, TIMER5 ISR in main.c) */ +/* Two early failed boots -> USB recovery; recovery reset -> mask-ROM UBOOT. */ +#include "bootguard.h" +bootguard_t bootguard __attribute__((section(".noinit"))); diff --git a/firmware/src/drum_synth.c b/firmware/src/drum_synth.c new file mode 100644 index 0000000..508ee44 --- /dev/null +++ b/firmware/src/drum_synth.c @@ -0,0 +1,235 @@ +/* SPDX-License-Identifier: GPL-3.0-only */ +/* Synthesised drum kits (drums.c kits DRUM_SAMPLED..): analogue-style models in fixed + * point, in the spirit of the classic drum machines and the PO-32. Every sound of a kit + * is one dsnd_t (tools/gen_drumkits.py writes the kits into felucca_drumkits.h): + * tone SINE / TRI / SQUARE / FM / BELL (two squares 1 : 1.48) with an exponential + * pitch drop (BEND semitones, over BTIME) and its own decay + * noise WHITE / METAL (six squares at the 808 cymbal ratios) / CYM (metal + white) / + * CHIP (15-bit LFSR, clocked by LPF) with its own decay; CLAP: 3 bursts, then the tail + * filter one-pole low-pass, two one-pole high-passes (on the noise; BELL: on the tone too) + * drive tanh; the kit's crush: bit depth and sample-and-hold + * Costs ~40 integer ops per voice and sample (METAL: +6 adds); envelopes and the pitch + * run at the control rate (CTL) and are ramped per sample. */ +enum { DW_NONE, DW_SINE, DW_TRI, DW_SQUARE, DW_FM, DW_BELL }; +enum { DN_NONE, DN_WHITE, DN_METAL, DN_CYM, DN_CHIP, DN_CLAP = 0x10 }; +typedef struct { + uint8_t wave, src; /* DW_*, DN_* (| DN_CLAP) */ + uint8_t pitch; /* MIDI note of the tone (METAL / CYM: their base) */ + uint8_t bend, btime; /* pitch drop: semitones at the hit, DECAY_K index of its fall */ + uint8_t decay, tlev; /* tone: DECAY_K index, level 0..127 */ + uint8_t nlev, ndec; /* noise: level 0..127, DECAY_K index */ + uint8_t lpf, hpf; /* CUTOFF_HZ index; lpf 127 / hpf 0 = off; CHIP: lpf = clock */ + uint8_t drive; /* 0..127 */ +} dsnd_t; +#define DS_LANES 14 /* the synthesised sounds (DS_NOTE): kick .. cowbell, clave */ +typedef struct { + const char *name, *style; + uint8_t crush; /* low nibble: bits dropped, high nibble: sample-and-hold - 1 */ + dsnd_t s[DS_LANES]; +} dkit_t; +#include "felucca_drumkits.h" /* DS_KITS[], DS_NKITS (tools/gen_drumkits.py) */ + +/* GM note -> synth lane (low nibble + 16 * ...) and a pitch offset in semitones */ +static const struct { uint8_t lane; int8_t semi; } DS_MAP[128 - 35] = { + /* 35 */ {0, -2}, {0, 0}, {11, 0}, {1, 0}, {2, 0}, {1, 1}, {5, -3}, {3, 0}, {5, 0}, {3, -1}, + /* 45 */ {5, 3}, {4, 0}, {6, -3}, {6, 0}, {7, 0}, {6, 3}, {8, 0}, {7, 3}, {8, 6}, {9, 4}, + /* 55 */ {7, 5}, {12, 0}, {7, 1}, {9, -5}, {8, 1}, {10, 9}, {10, 6}, {10, 3}, {10, 0}, {10, -5}, + /* 65 */ {6, 5}, {6, 1}, {12, 7}, {12, 3}, {9, -3}, {9, 0}, {13, 9}, {13, 6}, {9, -7}, {9, -9}, + /* 75 */ {13, 0}, {13, 4}, {13, -1}, {10, 12}, {10, 8}, {8, 24}, {8, 20}, {9, 2}, + /* 83..127: shaker */ +}; +static uint32_t ds_lane(uint32_t note, int32_t *semi) +{ + *semi = 0; + if (note < 35u) + return 0; + if (note >= 83u) + return 9; + *semi = DS_MAP[note - 35u].semi; + return DS_MAP[note - 35u].lane; +} + +typedef struct { + const dsnd_t *d; + uint32_t ph, inc, inc_to; /* tone phase; increment now and at the end of the block */ + uint32_t ph2, mph[6]; /* BELL / FM second oscillator, the six metal squares */ + uint32_t minc[6]; + int32_t pe; /* pitch envelope Q15 (32767 = BEND semitones) */ + int32_t amp, amp_to; /* tone envelope Q15, now and at the end of the block */ + int32_t nz, nz_to; /* noise envelope Q15 */ + uint32_t kpe, ka, kn; /* per-block decay factors Q16 */ + uint32_t t; /* samples since the hit (CLAP bursts) */ + int32_t base16; /* pitch in 1/16 semitones */ + int32_t lp, hp1, hp2, hpx1, hpx2; /* filter states */ + int32_t alp, ahp; /* one-pole coefficients Q15, 0 = off */ + int32_t rnd; /* white noise state */ + uint32_t lfsr, cacc, cinc; /* CHIP noise */ + int32_t cval; + int32_t gain; /* velocity Q15 */ + int32_t held, holdn; /* crush: sample-and-hold */ + uint8_t crush, bursts; +} dsv_t; + +/* per-sample DECAY_K (Q16) -> per-block (CTL = 32 samples) by squaring five times */ +static uint32_t ds_k32(uint32_t idx) +{ + uint32_t k = DECAY_K[idx & 127u], i; + for (i = 0; i < 5u; i++) + k = (k * k) >> 16; + return k; +} +static int32_t ds_onepole(uint32_t cut) /* CUTOFF_HZ index -> a = g / (1 + g), Q15 */ +{ + uint32_t g = SVF_G[cut & 127u]; + return (int32_t)((g << 15) / (4096u + g)); +} +static uint32_t ds_inc(int32_t p16) { return PITCH_INC[clamp(p16, 0, 127 * 16 + 15)]; } + +/* the 808 cymbal oscillators (205.3 304.4 369.6 522.7 540 800 Hz) as 1/16 semitones above the first */ +static const int16_t DS_METAL[6] = {0, 109, 163, 259, 268, 377}; + +static void ds_on(dsv_t *s, const dkit_t *kit, uint32_t note, uint32_t vel) +{ + int32_t semi; + uint32_t lane = ds_lane(note, &semi), i; + const dsnd_t *d = &kit->s[lane]; + memset(s, 0, sizeof *s); + s->d = d; + s->crush = kit->crush; + s->gain = (int32_t)vel * 258; + s->base16 = ((int32_t)d->pitch + semi) * 16; + s->pe = d->bend ? 32767 : 0; + s->kpe = ds_k32(d->btime); + s->inc = s->inc_to = ds_inc(s->base16 + ((s->pe * (int32_t)d->bend * 16) >> 15)); + s->amp = s->amp_to = d->wave ? (int32_t)d->tlev * 258 : 0; + s->ka = ds_k32(d->decay); + s->nz = s->nz_to = (d->src & 15u) ? (int32_t)d->nlev * 258 : 0; + s->kn = (d->src & DN_CLAP) ? ds_k32(12) : ds_k32(d->ndec); /* CLAP: short bursts first */ + s->bursts = 1; + s->alp = d->lpf < 127u && (d->src & 15u) != DN_CHIP ? ds_onepole(d->lpf) : 0; + s->ahp = d->hpf ? ds_onepole(d->hpf) : 0; + s->rnd = (int32_t)(0x9E3779B9u ^ (note * 2654435761u) ^ rng()); + s->lfsr = 0x4001u; + { /* CHIP clock: 8x that note; saturated (the top notes would wrap 32 bits: a dull noise) */ + uint32_t ci = PITCH_INC[clamp((int32_t)d->lpf, 0, 127) * 16]; + s->cinc = ci >= 0x20000000u ? 0xFFFFFFFFu : ci << 3; + } + for (i = 0; i < 6u; i++) + s->minc[i] = ds_inc(s->base16 + DS_METAL[i]); +} + +/* one CTL block of control: the envelopes' targets at its end */ +static void ds_control(dsv_t *s) +{ + const dsnd_t *d = s->d; + s->amp = s->amp_to; + s->nz = s->nz_to; + s->inc = s->inc_to; + s->amp_to = (int32_t)(((uint32_t)s->amp * s->ka) >> 16); + if ((d->src & DN_CLAP) && s->bursts < 4u && s->t >= s->bursts * 400u) { + s->nz = (int32_t)d->nlev * 258; /* bursts at 0, 9, 18 ms; the 4th is the tail */ + if (++s->bursts == 4u) + s->kn = ds_k32(d->ndec); + } + s->nz_to = (int32_t)(((uint32_t)s->nz * s->kn) >> 16); + s->pe = (int32_t)(((uint32_t)s->pe * s->kpe) >> 16); + s->inc_to = ds_inc(s->base16 + ((s->pe * (int32_t)d->bend * 16) >> 15)); +} + +static int ds_alive(const dsv_t *s) +{ + if ((s->d->src & DN_CLAP) && s->bursts < 4u) + return 1; /* bursts still to come */ + return s->amp > 8 || s->amp_to > 8 || s->nz > 8 || s->nz_to > 8; +} + +/* n (<= CTL) samples of voice s into out[] (Q15-ish, peak ~ 32767); returns 0 when it ended */ +static int ds_render(dsv_t *s, int32_t *out, uint32_t n) +{ + const dsnd_t *d = s->d; + uint32_t i, src = d->src & 15u, wave = d->wave; + int32_t da = (s->amp_to - s->amp) >> CTL_LOG2, dn = (s->nz_to - s->nz) >> CTL_LOG2; /* (no divide) */ + int32_t di = (int32_t)(s->inc_to - s->inc) >> CTL_LOG2; + int32_t a = s->amp, z = s->nz, inc = (int32_t)s->inc; + int32_t drive = 16 + d->drive, bits = s->crush & 15, hold = (s->crush >> 4) + 1; + for (i = 0; i < n; i++) { + int32_t tone = 0, nz = 0, x; + if (wave) { + switch (wave) { + case DW_SINE: tone = sine_i(s->ph); break; + case DW_TRI: tone = osc_tri(s->ph); break; + case DW_SQUARE: tone = (int32_t)s->ph < 0 ? -24000 : 24000; break; + case DW_FM: /* ratio 1.41: metallic, index follows the tone */ + tone = sine_i(s->ph + ((uint32_t)(sine_i(s->ph2) * a) << 1)); + s->ph2 += (uint32_t)inc + ((uint32_t)inc >> 2) + ((uint32_t)inc >> 3) + ((uint32_t)inc >> 5); + break; + default: /* BELL: two squares */ + tone = ((int32_t)s->ph < 0 ? -12000 : 12000) + ((int32_t)s->ph2 < 0 ? -12000 : 12000); + s->ph2 += (uint32_t)inc + ((uint32_t)inc >> 1) - ((uint32_t)inc >> 6); + break; + } + s->ph += (uint32_t)inc; + tone = mulq15(tone, a); + } + if (src) { + if (src == DN_WHITE) { + nz = (int32_t)noise32(&s->rnd) >> 17; + } else if (src == DN_CHIP) { + s->cacc += s->cinc; + if (s->cacc < s->cinc) { /* wrapped: clock the LFSR */ + uint32_t b = (s->lfsr ^ (s->lfsr >> 1)) & 1u; + s->lfsr = (s->lfsr >> 1) | (b << 14); + } + nz = (s->lfsr & 1u) ? 20000 : -20000; + } else { /* METAL / CYM: six squares (+ white) */ + s->mph[0] += s->minc[0]; /* unrolled: one sign bit each */ + s->mph[1] += s->minc[1]; + s->mph[2] += s->minc[2]; + s->mph[3] += s->minc[3]; + s->mph[4] += s->minc[4]; + s->mph[5] += s->minc[5]; + nz = (int32_t)(((s->mph[0] >> 31) + (s->mph[1] >> 31) + (s->mph[2] >> 31) + + (s->mph[3] >> 31) + (s->mph[4] >> 31) + (s->mph[5] >> 31)) * 9600u) - 28800; + if (src == DN_CYM) + nz += (int32_t)noise32(&s->rnd) >> 18; + } + if (wave == DW_BELL) + nz += tone, tone = 0; + if (s->alp) { + s->lp += mulq15(nz - s->lp, s->alp); + nz = s->lp; + } + if (s->ahp) { /* two one-pole high-passes: 12 dB / oct */ + s->hp1 += mulq15(nz - s->hp1, s->ahp); + nz -= s->hp1; + s->hp2 += mulq15(nz - s->hp2, s->ahp); + nz -= s->hp2; + } + nz = mulq15(nz, z); + if (d->src & DN_CLAP) + nz <<= 1; /* band-passed: as loud as the others */ + } else if (wave == DW_BELL && (s->alp || s->ahp)) { + x = tone; + if (s->alp) { s->lp += mulq15(x - s->lp, s->alp); x = s->lp; } + if (s->ahp) { s->hp1 += mulq15(x - s->hp1, s->ahp); x -= s->hp1; } + tone = x; + } + x = tone + nz; + if (d->drive) + x = softclip((x * drive) >> 4); + if (s->crush) { + if (--s->holdn <= 0) { + s->holdn = hold; + s->held = (x >> bits) << bits; + } + x = s->held; + } + out[i] = mulq15(x, s->gain); + a += da; + z += dn; + inc += di; + } + s->t += n; + ds_control(s); + return ds_alive(s); +} diff --git a/firmware/src/drums.c b/firmware/src/drums.c new file mode 100644 index 0000000..95e96ba --- /dev/null +++ b/firmware/src/drums.c @@ -0,0 +1,297 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* GM drum part (track 4): the SAMPLE engine's KIT set (General MIDI percussion map, + * tools/gen_samples.py GM_KIT), played by its step pattern, the keys when track 4 + * is selected, and its own MIDI channel (GLO -> DRUMS, default 10). Its own voices + * (outside the parts' voice budget). One-shots: note-offs are ignored; a closed or + * pedal hi-hat chokes the open one. LEVEL / REV: GLO > DRUMS (G_DRLVL, G_DRREV); + * PAN and MUTE: the drum track's P_PAN / P_MUTE. Rendered from the audio ISR. */ +#define NDRUM 6 +#include "drum_synth.c" /* synthesised kits (DS_KITS) */ +/* P_E0 was unused on the drum track: it holds the kit. 0..4: the GM sample kit and its four + * treatments (as before: old projects keep their kit), 5..: the synthesised kits. */ +#define DRUM_SAMPLED 5u +#define DRUM_KITS (DRUM_SAMPLED + DS_NKITS) +static const char *const DRUM_KIT_NAMES[] = {"ORIGINAL", "DEEP", "TIGHT", "BRIGHT", "DUST", DS_KIT_NAME_LIST}; +static const char *const DRUM_KIT_STYLES[] = {"ACOUSTIC", "SOFT", "PUNCHY", "BRIGHT", "DUSTY", DS_KIT_STYLE_LIST}; +static uint32_t drum_kit(void) { return (uint32_t)clamp(TDRUM->p[P_E0], 0, DRUM_KITS - 1); } +#define DRUM_DEFAULT_KIT DRUM_SAMPLED /* power-on: 808 */ + +static struct { + voice_t v[NDRUM]; + uint32_t age; + int16_t set; /* SMP_SETS index of "PERC" (GM map), -1 = none */ + int32_t tail; /* declick: the last output of cut voices, decaying */ + int32_t peak; /* largest |output| since the UI last looked (TRACKS meter) */ + uint8_t kit[NDRUM]; + int32_t filter[NDRUM], env[NDRUM]; + uint8_t synth[NDRUM]; /* the voice plays a synthesised kit (ds[]) */ + dsv_t ds[NDRUM]; + volatile uint16_t hits; /* bit per lane hit since the UI last looked (pads, key LEDs) */ + volatile uint8_t kick; /* a kick was hit (fx.c DUCK) */ + int32_t a0, a1; /* the drum track's mute / solo attenuation over this block (fx.c), Q15, 0 = heard */ +} drums = {.set = -2}; + +static int32_t ds_buf[CTL]; + +static int32_t drum_set(void) +{ + uint32_t i; + if (drums.set == -2) { + drums.set = -1; + for (i = 0; i < SMP_NSETS; i++) + if (str_eq(SMP_SETS[i].name, "PERC")) + drums.set = (int16_t)i; + } + return drums.set; +} + +/* ------------------------------------------------------------ lanes --- */ +/* The drum track's 16 sounds, one per white key, F3 (kick) .. G5 (cowbell): kicks, snare and clap, + * the hi-hats, rim and a second snare, the toms, the cymbals, the percussion. Each plays a GM note + * (the sampled kits: their samples; the synthesised kits: drum_synth.c DS_MAP). A black key plays + * the lane of the white key left of it (two fingers on one sound). */ +static const uint8_t LANE_NOTE[DRUM_LANES] = {36, 35, 38, 39, 42, 46, 44, 37, 40, 43, 48, 49, 51, 70, 63, 56}; +static const char *const LANE_NAME[DRUM_LANES] = { + "KICK", "KICK 2", "SNARE", "CLAP", "HAT", "OPEN HAT", "PEDAL", "RIM", + "SNARE 2", "LOW TOM", "HI TOM", "CRASH", "RIDE", "SHAKER", "CONGA", "COWBELL"}; +static const char *const LANE_SHORT[DRUM_LANES] = { /* 5 characters: tiles, dials */ + "kick", "kick2", "snare", "clap", "hat", "open", "pedal", "rim", + "snr 2", "tom l", "tom h", "crash", "ride", "shake", "conga", "bell"}; +/* a GM note (MIDI in, old projects) -> its lane: the nearest sound of the 16 (35..81; below: kick, above: shaker) */ +static const uint8_t LANE_OF_GM[81 - 35 + 1] = { + /* 35 */ 1, 0, 7, 2, 3, 8, 9, 4, 9, 6, + /* 45 */ 9, 5, 10, 10, 11, 10, 12, 11, 12, 13, + /* 55 */ 11, 15, 11, 13, 12, 14, 14, 14, 14, 14, + /* 65 */ 14, 14, 15, 15, 13, 13, 15, 15, 13, 13, + /* 75 */ 7, 7, 7, 14, 14, 15, 15}; +static uint32_t lane_of_note(uint32_t note) +{ + return note < 35u ? 0u : note > 81u ? 13u : LANE_OF_GM[note - 35u]; +} +/* the lane of key k (0 = F3 .. 26 = G5): white keys in order, a black key the white key left of it */ +static uint32_t lane_of_key(uint32_t k) +{ + static const int8_t W[12] = {0, -1, 1, -1, 2, -1, 3, 4, -1, 5, -1, 6}; /* from F */ + int32_t i = W[k % 12u]; + if (i < 0) + i = W[(k - 1u) % 12u]; + return (uint32_t)((int32_t)(k / 12u) * 7 + i) & 15u; +} +/* the white key of lane l (key index), for the key LEDs */ +static uint32_t key_of_lane(uint32_t l) +{ + static const uint8_t K[7] = {0, 2, 4, 6, 7, 9, 11}; /* F G A B C D E */ + return (l / 7u) * 12u + K[l % 7u]; +} + +/* drum steps: a lane's bit, level, ratchet */ +static int dstep_has(const dstep_t *s, uint32_t l) { return (s->on[(l >> 3) & 1u] >> (l & 7u)) & 1u; } +static uint32_t dstep_lvl(const dstep_t *s, uint32_t l) { return (s->lvl[(l >> 2) & 3u] >> ((l & 3u) * 2u)) & 3u; } +static uint32_t dstep_rat(const dstep_t *s, uint32_t l) { return (s->rat[(l >> 2) & 3u] >> ((l & 3u) * 2u)) & 3u; } +static uint32_t dstep_mask(const dstep_t *s) { return (uint32_t)s->on[0] | (uint32_t)s->on[1] << 8; } +static void dstep_set(dstep_t *s, uint32_t l, uint32_t lvl, uint32_t rat) /* lane on, with its level and ratchet */ +{ + uint32_t sh = (l & 3u) * 2u, b = (l >> 2) & 3u; + s->on[(l >> 3) & 1u] |= (uint8_t)(1u << (l & 7u)); + s->lvl[b] = (uint8_t)((s->lvl[b] & ~(3u << sh)) | (lvl & 3u) << sh); + s->rat[b] = (uint8_t)((s->rat[b] & ~(3u << sh)) | (rat & 3u) << sh); +} +static void dstep_clr(dstep_t *s, uint32_t l) /* lane off */ +{ + uint32_t sh = (l & 3u) * 2u, b = (l >> 2) & 3u; + s->on[(l >> 3) & 1u] &= (uint8_t)~(1u << (l & 7u)); + s->lvl[b] &= (uint8_t)~(3u << sh); + s->rat[b] &= (uint8_t)~(3u << sh); +} + +/* the velocity of a level: as played (LV_NORM: vel), ghost, soft, hard */ +static uint32_t lvl_vel(uint32_t lvl, uint32_t vel) +{ + static const uint8_t V[4] = {0, 42, 72, 127}; + return lvl & 3u ? V[lvl & 3u] : vel; +} +/* a MIDI velocity -> the level it records as (keys play 100: LV_NORM) */ +static uint32_t vel_lvl(uint32_t vel) +{ + return vel < 56u ? LV_GHOST : vel < 88u ? LV_SOFT : vel < 116u ? LV_NORM : LV_HARD; +} + +static void drum_on(uint32_t note, uint32_t vel) +{ + int32_t si = drum_set(); + const smp_set_t *set; + voice_t *v = &drums.v[0]; + uint32_t i, zi = 0xFFFFu, kit = drum_kit(); + if (note != 76u && note != 77u) /* the pads and key LEDs (not the click's wood block) */ + drums.hits |= (uint16_t)(1u << lane_of_note(note)); + if (note == 35u || note == 36u) + drums.kick = 1; /* (DUCK) */ + if (kit >= DRUM_SAMPLED) { /* synthesised kit */ + if (note == 42u || note == 44u) /* hi-hat choke */ + for (i = 0; i < NDRUM; i++) + if (drums.v[i].active && drums.v[i].note == 46u) { + drums.v[i].active = 0; + drums.tail += drums.v[i].s[7]; + } + for (i = 0; i < NDRUM; i++) { + if (!drums.v[i].active) { + v = &drums.v[i]; + break; + } + if (drums.v[i].age < v->age) + v = &drums.v[i]; + } + if (v->active) + drums.tail += v->s[7]; + i = (uint32_t)(v - drums.v); + v->note = (uint8_t)note; + v->vel = (uint8_t)vel; + v->active = 1; + v->s[7] = 0; + v->age = ++drums.age; + drums.synth[i] = 1; + drums.kit[i] = (uint8_t)kit; + ds_on(&drums.ds[i], &DS_KITS[kit - DRUM_SAMPLED], note, vel); + return; + } + if (si < 0) + return; + set = &SMP_SETS[si]; + for (i = 0; i < set->nz; i++) + if (note >= SMP_ZONES[set->z0 + i].lo && note <= SMP_ZONES[set->z0 + i].hi) + zi = set->z0 + i; + if (zi == 0xFFFFu) + return; + if (note == 42u || note == 44u) /* hi-hat choke */ + for (i = 0; i < NDRUM; i++) + if (drums.v[i].active && drums.v[i].note == 46u) { + drums.v[i].active = 0; + drums.tail += drums.v[i].s[7]; /* fade what it was playing, not a step */ + } + for (i = 0; i < NDRUM; i++) { /* free voice, else the oldest */ + if (!drums.v[i].active) { + v = &drums.v[i]; + break; + } + if (drums.v[i].age < v->age) + v = &drums.v[i]; + } + if (v->active) + drums.tail += v->s[7]; /* stolen voice: fade its last value */ + v->note = (uint8_t)note; + v->vel = (uint8_t)vel; + v->active = 1; + v->s[7] = 0; + v->age = ++drums.age; + v->s[4] = (int32_t)zi; + v->ph[0] = v->ph[1] = 0; + v->s[0] = v->s[1] = v->s[2] = 0; + v->s[3] = sample_next(&SMP_ZONES[zi], v, 0); + v->s[5] = (int32_t)((pow2_q16((int32_t)note * 16 - SMP_ZONES[zi].root16) >> 8) * (SMP_ZONES[zi].rate >> 8)); + { + uint32_t vi = (uint32_t)(v - drums.v); + int32_t shift = kit == 1u ? (note <= 36u ? -5 : -2) : kit == 3u ? 2 : kit == 4u ? -1 : 0; + drums.kit[vi] = (uint8_t)kit; + drums.synth[vi] = 0; + drums.filter[vi] = 0; + drums.env[vi] = 32767; + if (shift) v->s[5] = (int32_t)((pow2_q16((int32_t)note * 16 + shift * 16 - SMP_ZONES[zi].root16) >> 8) * (SMP_ZONES[zi].rate >> 8)); + } +} + +/* adds the drums into the dry mix and the reverb send; mono != 0: into mono instead, before the + * pan and the send (the SLICER, slicer.c slicer_drums, does those after it) */ +static inline void drums_mix(int32_t *ml, int32_t *mr, int32_t *rev, int32_t *mono, uint32_t n) +{ + uint32_t k, i; + int32_t lvl = song.g[G_DRLVL] * 200, send = song.g[G_DRREV] * 258, pk = drums.peak; + int32_t pan = trk[TRK_DRUM].p[P_PAN], gl = 4096 - (pan > 0 ? pan * 64 : 0), gr = 4096 + (pan < 0 ? pan * 64 : 0); + for (i = 0; i < n && drums.tail; i++) { /* declick tail, ~0.4 ms */ + if (mono) { + mono[i] += drums.tail; + } else { + ml[i] += drums.tail; + mr[i] += drums.tail; + } + drums.tail -= drums.tail / 16 + (drums.tail > 0 ? 1 : drums.tail < 0 ? -1 : 0); + } + for (k = 0; k < NDRUM; k++) { /* synthesised voices: render, then as below */ + voice_t *v = &drums.v[k]; + uint32_t m = n < CTL ? n : CTL; /* (the mix runs in blocks of CTL) */ + if (!v->active || !drums.synth[k]) + continue; + if (!ds_render(&drums.ds[k], ds_buf, m)) + v->active = 0; + for (i = 0; i < m; i++) { + int32_t s = mulq15(ds_buf[i], mulq15(lvl, 32767 - drums.a0 - (((drums.a1 - drums.a0) * (int32_t)i) >> CTL_LOG2))); + v->s[7] = s; + if (s > pk || -s > pk) + pk = s < 0 ? -s : s; + if (mono) { + mono[i] += s; + continue; + } + ml[i] += (s * gl) >> 12; + mr[i] += (s * gr) >> 12; + if (send) + rev[i] += mulq15(s, send); + } + if (!v->active) { + drums.tail += v->s[7]; /* ended: no step at the end */ + v->s[7] = 0; + } + } + for (k = 0; k < NDRUM; k++) { + voice_t *v = &drums.v[k]; + const smp_zone_t *z = &SMP_ZONES[v->s[4]]; + if (drums.synth[k]) + continue; + uint32_t frac = v->ph[1], stepq = (uint32_t)v->s[5]; /* Q16 source samples per output (drum_on) */ + int32_t g; + if (!v->active) + continue; + g = mulq15(lvl, v->vel * 258); + for (i = 0; i < n; i++) { + int32_t s; + frac += stepq; + while (frac >= 65536u) { + frac -= 65536u; + v->s[2] = v->s[3]; + if (v->ph[0] >= z->n) { + v->active = 0; + break; + } + v->s[3] = sample_next(z, v, 0); + } + if (!v->active) + break; + s = v->s[2] + (((v->s[3] - v->s[2]) * (int32_t)(frac >> 1)) >> 15); + s = mulq15(s, mulq15(g, 32767 - drums.a0 - (((drums.a1 - drums.a0) * (int32_t)i) >> CTL_LOG2))); + if (drums.kit[k] == 1u || drums.kit[k] == 4u) { + drums.filter[k] += (s - drums.filter[k]) >> (drums.kit[k] == 1u ? 2 : 1); + s = drums.filter[k]; + if (drums.kit[k] == 4u) s = (s >> 8) * 256; + } else if (drums.kit[k] == 2u) { + s = mulq15(s, drums.env[k]); + drums.env[k] -= (drums.env[k] >> 11) + 1; + if (drums.env[k] <= 0) v->active = 0; + } + v->s[7] = s; + if (s > pk || -s > pk) + pk = s < 0 ? -s : s; + if (mono) { + mono[i] += s; + continue; + } + ml[i] += (s * gl) >> 12; + mr[i] += (s * gr) >> 12; + if (send) + rev[i] += mulq15(s, send); + } + v->ph[1] = frac; + } + drums.peak = pk; +} +static void drums_render(int32_t *ml, int32_t *mr, int32_t *rev, uint32_t n) { drums_mix(ml, mr, rev, 0, n); } +static void drums_render_mono(int32_t *mono, uint32_t n) { drums_mix(0, 0, 0, mono, n); } diff --git a/firmware/src/dsp.c b/firmware/src/dsp.c new file mode 100644 index 0000000..9042a9b --- /dev/null +++ b/firmware/src/dsp.c @@ -0,0 +1,118 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* Shared DSP building blocks for the Felucca engines (all fixed point). + * Voice output convention: add sample * amp to out[], where a full-scale + * oscillator at amp = 1.0 (Q15 32767) contributes VOICE_FS. */ +#define VOICE_FS 24000 /* per-voice level: one voice peaks near -6 dBFS before the master */ + +static inline int32_t mulq15(int32_t a, int32_t b) { return (a * b) >> 15; } +/* a * k / 65536 without 64-bit: a up to 2^31, k Q16 */ +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; } + +/* sine, linearly interpolated between the 1024 table points (plain lookup: THD -55 dB) */ +static inline int32_t sine_i(uint32_t ph) +{ + uint32_t i = ph >> 22; + int32_t a = SINE[i], b = SINE[(i + 1u) & 1023u]; + return a + (((b - a) * (int32_t)((ph >> 7) & 0x7FFFu)) >> 15); +} +static inline int32_t osc_sine(uint32_t ph) { return sine_i(ph); } + +/* polyBLEP residual (Q15) around a wrap of a phase accumulator */ +static inline int32_t blep(uint32_t ph, uint32_t inc) +{ + uint32_t d = inc >> 15; + int32_t x; + if (!d) + return 0; + if (ph < inc) { + x = (int32_t)(ph / d); /* 0..32767 */ + return x + x - ((x * x) >> 15) - 32768; + } + if (ph > 0xFFFFFFFFu - inc) { + x = -(int32_t)((0xFFFFFFFFu - ph) / d); /* -32767..0 */ + return ((x * x) >> 15) + x + x + 32768; + } + return 0; +} + +static inline int32_t osc_saw(uint32_t ph, uint32_t inc) +{ + return ((int32_t)(ph >> 16) - 32768) - blep(ph, inc); +} + +static inline int32_t osc_pulse(uint32_t ph, uint32_t inc, uint32_t pw) +{ + return (osc_saw(ph, inc) - osc_saw(ph + pw, inc)) >> 1; +} + +static inline int32_t osc_tri(uint32_t ph) +{ + int32_t s = (int32_t)(ph >> 15); /* 0..131071 */ + return s < 65536 ? s - 32768 : 98303 - s; +} + +/* tanh(x / 32768) * 32767, linearly interpolated (a plain lookup gives + * 256-unit steps, audible on quiet signals) */ +static inline int32_t softclip(int32_t x) +{ + int32_t a = x < 0 ? -x : x, i = a >> 8, y; + if (i >= 256) + y = TANH_Q15[256]; /* continuous with the table */ + else + y = TANH_Q15[i] + (((TANH_Q15[i + 1] - TANH_Q15[i]) * (a & 255)) >> 8); + return x < 0 ? -y : y; +} + +static inline uint32_t noise32(int32_t *st) +{ + uint32_t s = (uint32_t)*st; + s ^= s << 13; + s ^= s >> 17; + s ^= s << 5; + *st = (int32_t)s; + return s; +} + +/* Trapezoidal SVF (A. Simper), unconditionally stable. Coefficients per + * block in Q13; signals stay within +-150000 so products fit in 32 bits. */ +typedef struct { int32_t a1, a2, a3; } tsvf_t; +static inline void tsvf_coef(tsvf_t *c, int32_t cut, int32_t reso) /* cut: 0..127 << 8 */ +{ + int32_t i, g, den, k = 8192 - reso * 7600 / 127; /* damping 2.0 .. ~0.15 (Q12) */ + cut = clamp(cut, 0, 127 << 8); + i = cut >> 8; + g = SVF_G[i]; + if (i < 127) /* between table points: sweeps without 128 steps */ + g += ((SVF_G[i + 1] - g) * (cut & 255)) >> 8; + den = 4096 + ((g * (g + k)) >> 12); + c->a1 = (int32_t)((4096u << 13) / (uint32_t)den); + c->a2 = (c->a1 * g) >> 12; + c->a3 = (c->a2 * g) >> 12; +} + +static inline int32_t tsvf_lp(const tsvf_t *c, int32_t in, int32_t *ic1, int32_t *ic2) +{ + int32_t v3 = in - *ic2; + int32_t v1 = (c->a1 * *ic1 + c->a2 * v3) >> 13; + int32_t v2 = *ic2 + ((c->a2 * *ic1 + c->a3 * v3) >> 13); + *ic1 = clamp(2 * v1 - *ic1, -150000, 150000); + *ic2 = clamp(2 * v2 - *ic2, -150000, 150000); + return v2; +} + +/* amplitude ramp over the block. Blocks are always CTL long, so x / CTL is a + * shift rounded towards zero (-Os would keep a hardware divide per sample) */ +#define CTL_LOG2 5 +#if (1 << CTL_LOG2) != CTL +#error "CTL_LOG2 does not match CTL" +#endif +static inline int32_t amp_at(const vmod_t *m, uint32_t i) +{ + int32_t x = (m->amp1 - m->amp0) * (int32_t)i; + return m->amp0 + ((x + ((x >> 31) & (CTL - 1))) >> CTL_LOG2); +} diff --git a/firmware/src/editor.c b/firmware/src/editor.c new file mode 100644 index 0000000..af2fab8 --- /dev/null +++ b/firmware/src/editor.c @@ -0,0 +1,780 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* Editor protocol: SysEx for the web editor (web/EDITOR_PROTOCOL.md; v2 = user presets + live sync, + * v3 = four tracks: the v1 / v2 commands act on the selected track, cmds 27-30 reach any track; + * v4 = TRACK_PARAM (31) and the TRACK_CHANGED push (32), enabled by WATCH bit 1; + * v5 = SLOOP 2.0: INFO ends with the protocol version (5), steps carry level / ratchet bytes, + * DRUM_STEP (33) reads / writes the drum track's 16 lanes, TRACK ends with the solo mask). + * F0 7D 46 4C cmd args.. F7 (7D = non-commercial ID, "FL") + * Values are 14 bit, two 7-bit bytes LSB first, offset by 8192 (so -8192..8191). + * Every request gets a reply with the same cmd; 23/24/26 are also pushed + * while watched. Frames arrive through sx_frame (usb.c), replies leave + * through ota_wire_send(). */ +#define ED_HDR0 0x7D +#define ED_HDR1 0x46 +#define ED_HDR2 0x4C +enum { ED_INFO = 1, 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, /* v2: user presets */ + ED_WATCH, ED_CHANGED, ED_RELOAD, ED_PING, ED_STEP_CHANGED, /* v2: live sync */ + ED_TRACK, ED_TRACK_MIX, ED_TRACK_DUMP, ED_TRACK_STEP, /* v3: tracks */ + ED_TRACK_PARAM, ED_TRACK_CHANGED, /* v4: any track's parameters */ + ED_DRUM_STEP }; /* v5: the 16 drum lanes */ + +static uint8_t ed_out[600]; +static uint32_t ed_n; + +static void ed_begin(uint32_t cmd) +{ + ed_out[0] = 0xF0; + ed_out[1] = ED_HDR0; + ed_out[2] = ED_HDR1; + ed_out[3] = ED_HDR2; + ed_out[4] = (uint8_t)cmd; + ed_n = 5; +} +static void ed_b(uint32_t v) +{ + if (ed_n < sizeof ed_out - 1u) + ed_out[ed_n++] = (uint8_t)(v & 0x7Fu); +} +static void ed_v(int32_t v) +{ + uint32_t u = (uint32_t)(clamp(v, -8192, 8191) + 8192); + ed_b(u); + ed_b(u >> 7); +} +static void ed_str(const char *s, uint32_t max) /* ASCII, 0-terminated */ +{ + uint32_t i; + for (i = 0; s && s[i] && i < max; i++) + ed_b((uint8_t)s[i] & 0x7Fu); + ed_b(0); +} +static void ed_send(void) +{ + ed_out[ed_n++] = 0xF7; + ota_wire_send(ed_out, ed_n); +} +static int32_t ed_rv(const uint8_t *p) { return (int32_t)(p[0] | p[1] << 7) - 8192; } + +/* ---- user sample slots (eng_sample.c): flash SMP_USER_BASE + k * SMP_USER_SIZE ---- + * BEGIN erases the header sector (the slot is invalid from then on), WRITE fills the data + * (offset >= 512, erasing each further sector when the write reaches its start), END sends + * the header: the device checks the data CRC and writes the header last. */ +static uint32_t ed_unpack7(const uint8_t *a, uint32_t na, uint8_t *out, uint32_t max) +{ + uint32_t n = 0; /* groups: msb byte, then up to 7 bytes */ + while (na && n < max) { + uint32_t m = *a++, j; + na--; + for (j = 0; j < 7u && na && n < max; j++, na--) + out[n++] = (uint8_t)(*a++ | ((m >> j) & 1u) << 7); + } + return n; +} +static uint8_t ed_smp_buf[512] __attribute__((aligned(4))); +static uint8_t ed_smp_open[SMP_USER_SLOTS]; /* SMP_BEGIN done, END not yet: WRITE / END may act */ +static uint32_t ed_smp_slot(uint32_t k) { return SMP_USER_BASE + k * SMP_USER_SIZE; } +static void ed_smp_inval(uint32_t k) +{ + fm1_irq_off(); + fl_inval(ed_smp_slot(k), SMP_USER_SIZE); + fm1_irq_on(); +} +static int ed_smp_erase(uint32_t k, uint32_t all) /* header sector, or the whole slot */ +{ + uint32_t i, took; + int rc = 0; + usr_nz[k] = 0; + for (i = 0; i < 16u; i++) + usr_zone[k][i].n = 0; /* a sounding voice ends instead of reading 0xFF */ + for (i = 0; i < (all ? SMP_USER_SIZE / 0x1000u : 1u) && !rc; i++) { + rc = fl_erase4k_quiet(ed_smp_slot(k) + i * 0x1000u, &took); + fm1_wdt_feed(); + } + ed_smp_inval(k); + return rc; +} +static int ed_smp_end(uint32_t k, const uint8_t *a, uint32_t na) +{ + const smp_user_hdr_t *h = (const smp_user_hdr_t *)ed_smp_buf; + uint32_t i; + if (!ed_smp_open[k] || usr_nz[k]) + return 6; /* no BEGIN first (a header over a header: flash ANDs them) */ + if (ed_unpack7(a, na, ed_smp_buf, sizeof(smp_user_hdr_t)) != sizeof(smp_user_hdr_t)) + return 1; + if (h->magic != SMP_USER_MAGIC || h->version != 1 || !h->nz || h->nz > 16u || + h->data_len > SMP_USER_SIZE - SMP_USER_DATA) + return 2; + for (i = 0; i < h->nz; i++) /* the zones checked before anything is written */ + if (!smp_zone_ok(&h->zone[i], h->data_len)) + return 2; + ed_smp_open[k] = 0; + ed_smp_inval(k); + if (st_crc32(smp_user_xip(k) + SMP_USER_DATA, h->data_len) != h->crc) + return 3; + if (fl_write(ed_smp_slot(k), ed_smp_buf, sizeof(smp_user_hdr_t))) + return 4; + ed_smp_inval(k); + smp_user_scan(k); + return usr_nz[k] ? 0 : 5; +} + +/* the engine byte of DUMP / RELOAD / TRACK: NENGINES = the drum track (no engine) */ +static uint32_t ed_eng(const track_t *t) { return is_drum(t) ? NENGINES : t->eng_req % NENGINES; } + +/* ---- live sync (v2): while the editor WATCHes, device-side changes are pushed. + * Shadows of the selected track's p[] + song.g[] and of its steps are kept in step + * with what the editor knows (its own SET / STEP_SET update them); the main loop + * compares and pushes CHANGED / STEP_CHANGED, or RELOAD after a load or when another + * track was selected (v3: RELOAD and STEP_CHANGED carry the selected track). Pushes + * go out only into a half-empty SysEx ring, so they never wait. */ +#define ED_PUSH_MAX 4u /* frames per pass */ +#define ED_NV (P_COUNT + G_COUNT) +/* v4: the parameters of the tracks that are not selected which TRACK_CHANGED follows (the mixer) */ +static const uint8_t ED_TIDS[3] = {P_LEVEL, P_PAN, P_MUTE}; +#define ED_NT (NTRK * 3u) +static struct { + uint8_t on, eng, preset, sel; + uint8_t v4; /* WATCH bit 1: TRACK_CHANGED pushes too */ + uint32_t pos, last_ms, run_ms, resets; + int16_t v[ED_NV]; /* TSEL->p[], then song.g[] */ + uint16_t t[ED_NV]; /* ms (low 16 bits) of the last push */ + uint32_t st[NSTEP]; /* step signatures */ + int16_t tv[ED_NT]; /* v4: trk[k].p[ED_TIDS[j]] at k * 3 + j */ + uint16_t tt[ED_NT]; + uint32_t tpos; +} ed_w; + +static int16_t *ed_val(uint32_t i) { return i < P_COUNT ? &TSEL->p[i] : &song.g[i - P_COUNT]; } +static uint32_t ed_step_sig(const step_t *s) /* all 10 bytes (a drum step's lanes too) */ +{ + const uint8_t *b = (const uint8_t *)s; + uint32_t i, h = 0x811C9DC5u; + for (i = 0; i < sizeof *s; i++) + h = (h ^ b[i]) * 16777619u; + return h; +} +/* the drum track's step as a v1..v4 step (old editors): its first 4 lanes as GM notes, ACC when one is hard */ +static void ed_dstep_old(const dstep_t *d, uint32_t *n, uint8_t *notes, uint32_t *time, uint32_t *flags, uint32_t *vel) +{ + uint32_t l, k = 0, hard = 0; + for (l = 0; l < DRUM_LANES && k < 4u; l++) + if (dstep_has(d, l)) { + notes[k++] = LANE_NOTE[l]; + hard |= dstep_lvl(d, l) == LV_HARD; + } + *n = k; + while (k < 4u) + notes[k++] = 0; + *time = *n ? ST_NOTE : ST_REST; + *flags = hard ? SF_ACCENT : 0u; + *vel = *n ? 100u : 0u; +} +/* a v1..v4 step written into the drum track: its notes onto their lanes */ +static void ed_dstep_from_old(dstep_t *d, const uint8_t *a) +{ + uint32_t i, n = a[0] > 4u ? 4u : a[0]; + memset(d, 0, sizeof *d); + if (a[5] != ST_NOTE) + return; + for (i = 0; i < n; i++) + dstep_set(d, lane_of_note(a[1 + i] & 0x7Fu), (a[6] & SF_ACCENT) ? LV_HARD : LV_NORM, 0); +} +/* a step's bytes, as STEP_GET sends them (v5: + level, ratchet) */ +static void ed_step_out(const track_t *t, uint32_t i) +{ + uint32_t k; + if (is_drum(t)) { + uint32_t n, time, flags, vel; + uint8_t nt[4]; + ed_dstep_old(&t->dstep[i], &n, nt, &time, &flags, &vel); + ed_b(n); + for (k = 0; k < 4u; k++) + ed_b(nt[k]); + ed_b(time); + ed_b(flags); + ed_b(vel); + ed_b(0); /* v5: lvl, hi, rat (DRUM_STEP has the lanes' own) */ + ed_b(0); + ed_b(0); + return; + } + { + const step_t *st = &t->step[i]; + ed_b(st->n); + for (k = 0; k < 4u; k++) + ed_b(st->note[k]); + ed_b(st->time); + ed_b(st->flags); + ed_b(st->vel); + ed_b(st->lvl); /* v5 (7 bits each: 4 x 2-bit fields, the top 1 below) */ + ed_b(st->lvl >> 7 | (st->rat >> 7) << 1); + ed_b(st->rat); + } +} +/* a step written: n, 4 notes, time, flags, vel [, lvl, hi, rat] */ +static void ed_step_in(track_t *t, uint32_t i, const uint8_t *a, uint32_t na) +{ + uint32_t k; + if (is_drum(t)) { + ed_dstep_from_old(&t->dstep[i], a); + return; + } + { + step_t *st = &t->step[i]; + st->n = (uint8_t)(a[0] > 4u ? 4u : a[0]); + for (k = 0; k < 4u; k++) + st->note[k] = a[1 + k] & 0x7Fu; + st->time = (uint8_t)(a[5] > ST_REST ? ST_REST : a[5]); + st->flags = a[6] & (SF_ACCENT | SF_SLIDE); + st->vel = a[7] & 0x7Fu; + if (na >= 11u) { + st->lvl = (uint8_t)((a[8] & 0x7Fu) | (a[9] & 1u) << 7); + st->rat = (uint8_t)((a[10] & 0x7Fu) | ((a[9] >> 1) & 1u) << 7); + } else { + st->lvl = st->rat = 0; + } + } +} +static void ed_shadow(void) /* the editor is in sync */ +{ + uint32_t i; + for (i = 0; i < ED_NV; i++) + ed_w.v[i] = *ed_val(i); + for (i = 0; i < NSTEP; i++) + ed_w.st[i] = ed_step_sig(&TSEL->step[i]); + for (i = 0; i < ED_NT; i++) + ed_w.tv[i] = trk[i / 3u].p[ED_TIDS[i % 3u]]; + ed_w.eng = (uint8_t)ed_eng(TSEL); + ed_w.preset = TSEL->preset; + ed_w.sel = song.sel; + sync_reload = 0; +} +static int ed_room(void) { return so_w - so_r + 8u <= SXQ / 2u; } +static void ed_known(uint32_t k, uint32_t id) /* the editor's own change of trk[k].p[id]: no push */ +{ + uint32_t j; + if (k == song.sel) { + ed_w.v[id] = trk[k].p[id]; + return; + } + for (j = 0; j < 3u; j++) + if (ED_TIDS[j] == id) + ed_w.tv[k * 3u + j] = trk[k].p[id]; +} + +static void ed_sync(void) /* main loop */ +{ + uint32_t i, n = 0, now = fm1_ms; + if (!ed_w.on || now - ed_w.run_ms < 5u) + return; + ed_w.run_ms = now; + if (!usb.config || usb.resets != ed_w.resets || now - ed_w.last_ms > 3000u) { + ed_w.on = 0; /* no host, USB reset, or 3 s without a request */ + return; + } + if (sync_reload || ed_eng(TSEL) != ed_w.eng || TSEL->preset != ed_w.preset || song.sel != ed_w.sel) { + if (!ed_room()) + return; + ed_shadow(); + ed_begin(ED_RELOAD); + ed_b(ed_eng(TSEL)); + ed_b(TSEL->preset); + ed_b(song.sel); + ed_send(); + return; + } + for (i = 0; i < NSTEP && n < ED_PUSH_MAX; i++) { + uint32_t h = ed_step_sig(&TSEL->step[i]); + if (h == ed_w.st[i]) + continue; + if (!ed_room()) + return; + ed_w.st[i] = h; + ed_begin(ED_STEP_CHANGED); + ed_b(i); + ed_b(song.sel); + ed_send(); + n++; + } + for (i = 0; i < ED_NV && n < ED_PUSH_MAX; i++) { /* round robin: nothing starves */ + uint32_t k = (ed_w.pos + i) % ED_NV; + int16_t v = *ed_val(k); + if (v == ed_w.v[k] || (uint16_t)(now - ed_w.t[k]) < 20u) + continue; /* coalesced: the latest value goes out later */ + if (!ed_room()) + return; + ed_w.v[k] = v; + ed_w.t[k] = (uint16_t)now; + ed_begin(ED_CHANGED); + ed_b(k < P_COUNT ? 0u : 1u); + ed_b(k < P_COUNT ? k : k - P_COUNT); + ed_v(v); + ed_send(); + n++; + ed_w.pos = k + 1u; + } + for (i = 0; ed_w.v4 && i < ED_NT && n < ED_PUSH_MAX; i++) { /* v4: the other tracks' mix */ + uint32_t k = (ed_w.tpos + i) % ED_NT, tr = k / 3u, id = ED_TIDS[k % 3u]; + int16_t v = trk[tr].p[id]; + if (tr == song.sel || v == ed_w.tv[k] || (uint16_t)(now - ed_w.tt[k]) < 20u) + continue; /* (the selected track: CHANGED above) */ + if (!ed_room()) + return; + ed_w.tv[k] = v; + ed_w.tt[k] = (uint16_t)now; + ed_begin(ED_TRACK_CHANGED); + ed_b(tr); + ed_b(id); + ed_v(v); + ed_send(); + n++; + ed_w.tpos = k + 1u; + } +} + +/* descriptor of parameter id of track t: the engine parameters of the engine it asked for + * (t->engine follows in the audio ISR, after a short fade) */ +static const param_desc_t *ed_tdesc(const track_t *t, uint32_t id) /* the static ones: an engine's */ +{ /* desc hook is the device display only */ + if(is_drum(t) && id==P_E0) return &DRUM_KIT_DESC; + if (id >= P_E0 && id <= P_E7) + return &ENGINES[t->eng_req % NENGINES]->edit[id - P_E0]; + return &TP[id]; +} +/* descriptor and value slot of (scope, id): scope 0 = the selected track, 1 = global */ +static const param_desc_t *ed_desc(uint32_t scope, uint32_t id, int16_t **vp) +{ + if (scope == 0 && id < P_COUNT) { + *vp = &TSEL->p[id]; + return ed_tdesc(TSEL, id); + } + if (scope == 1 && id < G_COUNT) { + *vp = &song.g[id]; + return &GP[id]; + } + return 0; +} + +static void ed_handle(const uint8_t *f, uint32_t n) /* f: the bytes between F0 and F7 */ +{ + uint32_t cmd = f[3], i; + const uint8_t *a = f + 4; + uint32_t na = n - 4u; + int16_t *vp; + const param_desc_t *d; + ed_begin(cmd); + switch (cmd) { + case ED_INFO: + ed_str("FELUCCA " FELUCCA_VERSION, 24); + ed_b(NENGINES); + ed_b(P_COUNT); + ed_b(G_COUNT); + ed_b(NSTEP); + ed_b(P_E0); + for (i = 0; i < NENGINES; i++) + ed_str(ENGINES[i]->name, 8); + ed_b(NTRK); /* v3 */ + ed_b(5); /* v5: the protocol version */ + break; + case ED_GET: + case ED_SET: + if (na < 2u || !(d = ed_desc(a[0], a[1], &vp))) + return; + if (cmd == ED_SET && na >= 4u) { + if (a[0] == 1 && a[1] == G_ENGSEL) { /* engine change: the safe path */ + set_engine((uint32_t)clamp(ed_rv(a + 2), 0, NENGINES - 1)); + } else if (d->max > d->min) { + *vp = (int16_t)clamp(ed_rv(a + 2), d->min, d->max); + } + ui.force = 1; + ed_w.v[a[0] ? P_COUNT + a[1] : a[1]] = *vp; /* the editor's own change: no push */ + } + ed_b(a[0]); + ed_b(a[1]); + ed_v(*vp); + break; + case ED_DUMP: + for (i = 0; i < ED_NV; i++) /* the editor gets them all here */ + ed_w.v[i] = *ed_val(i); + ed_b(ed_eng(TSEL)); + ed_b(TSEL->preset); + for (i = 0; i < P_COUNT; i++) + ed_v(TSEL->p[i]); + for (i = 0; i < G_COUNT; i++) + ed_v(song.g[i]); + break; + case ED_DESC: + if (na < 2u || !(d = ed_desc(a[0], a[1], &vp))) + return; + ed_b(a[0]); + ed_b(a[1]); + ed_b(d->fmt); + ed_v(d->min); + ed_v(d->max); + ed_v(d->def); + ed_str(d->label, 8); + ed_str(d->unit, 8); + if (d->fmt == F_ENUM && d->names) + for (i = 0; i <= (uint32_t)(d->max - d->min) && i < 64u; i++) /* (the 34 drum kits) */ + ed_str(d->names[i], 8); + break; + case ED_STEP_GET: + case ED_STEP_SET: + if (na < 1u || a[0] >= NSTEP) + return; + if (cmd == ED_STEP_SET && na >= 9u) { + fm1_irq_off(); + ed_step_in(TSEL, a[0], a + 1, na - 1u); + fm1_irq_on(); + ui.force = 1; + } + ed_w.st[a[0]] = ed_step_sig(&TSEL->step[a[0]]); + ed_b(a[0]); + ed_step_out(TSEL, a[0]); + break; + case ED_PRESET: /* engine, preset */ + if (na < 2u || a[0] >= NENGINES) + return; + if (a[0] != TSEL->eng_req) + set_engine(a[0]); + apply_preset(a[1]); + ui.force = 1; + ed_b(ed_eng(TSEL)); + ed_b(TSEL->preset); + break; + case ED_PROJECT: /* 0 = load, 1 = save, 2 = query; slot 0..3 */ + if (na < 2u || a[0] > 2u) + return; +#if FELUCCA_ARRANGER + if (a[0] < 2u && (song.playing || transport_req)) { + ed_b(a[0]); ed_b(a[1] & 3u); ed_b(project_used(a[1] & 3u)); + ed_b(1); /* optional status: transport busy */ + break; + } +#endif + if (a[0] == 1u) + project_save(a[1] & 3u); + else if (a[0] == 0u) + project_load(a[1] & 3u); + ed_b(a[0]); + ed_b(a[1] & 3u); + ed_b(project_used(a[1] & 3u)); + break; + case ED_NAMES: /* preset names of an engine */ + if (na < 1u || a[0] >= NENGINES) + return; + ed_b(a[0]); + ed_b(ENGINES[a[0]]->npresets); + for (i = 0; i < ENGINES[a[0]]->npresets; i++) + ed_str(ENGINES[a[0]]->presets[i].name, 12); + for (i = 0; i < 2u; i++) /* then the two edit-page titles */ + ed_str(ENGINES[a[0]]->page_title[i], 8); + break; + case ED_SMP_BEGIN: /* slot -> slot, rc */ + case ED_SMP_ERASE: { + uint32_t rc; + if (na < 1u || a[0] >= SMP_USER_SLOTS || !flash_ok) + return; + rc = ed_smp_erase(a[0], cmd == ED_SMP_ERASE) ? 1u : 0u; + ed_smp_open[a[0]] = (uint8_t)(cmd == ED_SMP_BEGIN && !rc); + ed_b(a[0]); + ed_b(rc); + break; + } + case ED_SMP_WRITE: { /* slot, off (3 x 7 bit), pack7 data -> slot, off, rc */ + uint32_t off, len, rc = 0, took; + if (na < 5u || a[0] >= SMP_USER_SLOTS || !flash_ok) + return; + off = (uint32_t)a[1] | (uint32_t)a[2] << 7 | (uint32_t)a[3] << 14; + len = ed_unpack7(a + 4, na - 4u, ed_smp_buf, 256u); + if (off < SMP_USER_DATA || (off & 0xFFu) || !len || off + len > SMP_USER_SIZE) + rc = 1; + else if (usr_nz[a[0]] || !ed_smp_open[a[0]]) + rc = 4; /* slot in use: SMP_BEGIN first (voices read it) */ + else { + if (!(off & 0xFFFu)) /* first write into a sector: erase it */ + rc = fl_erase4k_quiet(ed_smp_slot(a[0]) + off, &took) ? 2u : 0u; + if (!rc && fl_write(ed_smp_slot(a[0]) + off, ed_smp_buf, len)) + rc = 3; + } + ed_b(a[0]); + ed_b(off); + ed_b(off >> 7); + ed_b(off >> 14); + ed_b(rc); + break; + } + case ED_SMP_END: /* slot, pack7 header -> slot, rc */ + if (na < 2u || a[0] >= SMP_USER_SLOTS || !flash_ok) + return; + ed_b(a[0]); + ed_b((uint32_t)ed_smp_end(a[0], a + 1, na - 1u)); + break; + case ED_SMP_INFO: /* -> per slot: zones (0 = empty), name, data KiB */ + ed_b(SMP_USER_SLOTS); + ed_b(SMP_USER_SIZE / 1024u); + for (i = 0; i < SMP_USER_SLOTS; i++) { + const smp_user_hdr_t *h = (const smp_user_hdr_t *)smp_user_xip(i); + char nm[9] = {0}; + uint32_t j; + ed_b(usr_nz[i]); + for (j = 0; usr_nz[i] && j < 8u; j++) + nm[j] = h->name[j] >= 32 && h->name[j] < 127 ? h->name[j] : 0; + ed_str(nm, 8); + ed_b(usr_nz[i] ? (h->data_len + 1023u) / 1024u : 0u); + } + break; + case ED_UP_LIST: { /* start, count -> start, count, total, per slot: used, engine, name */ + uint32_t s0, cnt; + if (na < 2u) + return; + s0 = a[0]; + cnt = a[1] > 16u ? 16u : a[1]; + if (s0 >= UP_SLOTS) + cnt = 0; + else if (s0 + cnt > UP_SLOTS) + cnt = UP_SLOTS - s0; + ed_b(s0); + ed_b(cnt); + ed_b(UP_SLOTS); + for (i = s0; i < s0 + cnt; i++) { + char nm[13] = {0}; + uint32_t j, u = (uint32_t)up_used(i); + for (j = 0; u && j < 12u; j++) + nm[j] = up_rec(i)->name[j]; + ed_b(u); + ed_b(u ? up_rec(i)->engine : 0u); + ed_str(nm, 12); + } + break; + } + case ED_UP_GET: { /* slot -> slot, used, engine, name, P_COUNT x v14, 16 x (note, flags) */ + int16_t v[P_COUNT]; + char nm[13] = {0}; + const up_rec_t *r; + uint32_t u; + if (na < 1u || a[0] >= UP_SLOTS) + return; + r = up_rec(a[0]); + u = (uint32_t)up_used(a[0]); + if (u) + up_values(r, v); /* today's P_* order, clamped */ + for (i = 0; u && i < 12u; i++) + nm[i] = r->name[i]; + ed_b(a[0]); + ed_b(u); + ed_b(u ? r->engine : 0u); + ed_str(nm, 12); + for (i = 0; i < P_COUNT; i++) + ed_v(u ? v[i] : 0); + for (i = 0; i < 16u; i++) { + ed_b(u ? r->note[i] : 0u); + ed_b(u ? r->flags[i] : 0u); + } + break; + } + case ED_UP_PUT: { /* slot, engine, name, values, pattern -> slot, rc */ + static up_rec_t r; + uint32_t slot = 0, rc; + if (na < 1u) + return; + rc = (uint32_t)up_parse(a, na, &r, &slot); + if (!rc) { + int16_t v[P_COUNT]; + up_values(&r, v); /* each value inside its range */ + for (i = 0; i < P_COUNT; i++) + r.p[i] = v[i]; + rc = up_put(slot, &r) ? 2u : 0u; + } + ed_b(a[0]); + ed_b(rc); + break; + } + case ED_UP_STORE: { /* slot, name -> slot, rc */ + char nm[13] = {0}; + uint32_t n0, rc = 1; + if (na < 1u) + return; + for (n0 = 0; 1u + n0 < na && a[1 + n0] && n0 < 13u; n0++) + ; + if (a[0] < UP_SLOTS && (!n0 || up_name_ok(a + 1, n0))) { /* "" = automatic name */ + for (i = 0; i < n0; i++) + nm[i] = (char)a[1 + i]; + int r = up_store(a[0], nm); + rc = r == 1 ? 1u : r ? 2u : 0u; /* 1: the drum track is selected */ + } + ed_b(a[0]); + ed_b(rc); + break; + } + case ED_UP_LOAD: /* slot -> slot, rc */ + if (na < 1u) + return; + ed_b(a[0]); + ed_b(a[0] < UP_SLOTS && !up_load(a[0]) ? 0u : 1u); + break; + case ED_UP_ERASE: + if (na < 1u) + return; + ed_b(a[0]); + ed_b(a[0] >= UP_SLOTS ? 1u : up_put(a[0], 0) ? 2u : 0u); + break; + case ED_WATCH: /* on -> on */ + if (na < 1u) + return; + ed_w.on = a[0] & 1u; + ed_w.v4 = (uint8_t)(ed_w.on && (a[0] & 2u)); /* v4: also TRACK_CHANGED; the reply says it is known */ + ed_w.resets = usb.resets; + if (ed_w.on) + ed_shadow(); + ed_b(ed_w.on | ed_w.v4 << 1); + break; + case ED_PING: + ed_b(0); + break; + case ED_TRACK: /* [track] -> selected, NTRK, per track: engine, preset, level, mute, armed */ + if (na >= 1u && a[0] < NTRK && a[0] != song.sel) { + track_select(a[0]); + if (ed_w.on) + ed_shadow(); /* the editor re-reads it: no RELOAD for this */ + } + ed_b(song.sel); + ed_b(NTRK); + for (i = 0; i < NTRK; i++) { + ed_b(ed_eng(&trk[i])); + ed_b(trk[i].preset); + ed_v(i == TRK_DRUM ? song.g[G_DRLVL] : trk[i].p[P_LEVEL]); + ed_b(trk[i].p[P_MUTE] != 0); + ed_b((song.rec >> i) & 1u); + } + ed_b(song.solo & 15u); /* v5: the tracks soloed */ + break; + case ED_TRACK_MIX: { /* track [, level v14, mute] -> track, level, mute */ + track_t *t; + int16_t *lv; + if (na < 1u || a[0] >= NTRK) + return; + t = &trk[a[0]]; + lv = a[0] == TRK_DRUM ? &song.g[G_DRLVL] : &t->p[P_LEVEL]; + if (na >= 4u) { + *lv = (int16_t)clamp(ed_rv(a + 1), 0, 127); + t->p[P_MUTE] = (int16_t)(a[3] ? 1 : 0); + if (a[0] == TRK_DRUM) /* the editor's own change: no push */ + ed_w.v[P_COUNT + G_DRLVL] = *lv; + else + ed_known(a[0], P_LEVEL); + ed_known(a[0], P_MUTE); + ui.force = 1; + } + ed_b(a[0]); + ed_v(*lv); + ed_b(t->p[P_MUTE] != 0); + break; + } + case ED_TRACK_DUMP: /* track -> track, engine, preset, P_COUNT x v14 */ + if (na < 1u || a[0] >= NTRK) + return; + ed_b(a[0]); + ed_b(ed_eng(&trk[a[0]])); + ed_b(trk[a[0]].preset); + for (i = 0; i < P_COUNT; i++) + ed_v(trk[a[0]].p[i]); + break; + case ED_TRACK_STEP: /* track, index [, step] -> track, index, step (as STEP_GET) */ + if (na < 2u || a[0] >= NTRK || a[1] >= NSTEP) + return; + if (na >= 10u) { + fm1_irq_off(); + ed_step_in(&trk[a[0]], a[1], a + 2, na - 2u); + fm1_irq_on(); + ui.force = 1; + } + if (a[0] == song.sel) + ed_w.st[a[1]] = ed_step_sig(&trk[a[0]].step[a[1]]); + ed_b(a[0]); + ed_b(a[1]); + ed_step_out(&trk[a[0]], a[1]); + break; + case ED_DRUM_STEP: { /* index [, on 16 bits, lvl 32 bits, rat 32 bits as 7-bit groups] + * -> index, on (3), lvl (5), rat (5): the drum track's 16 lanes */ + dstep_t *d; + uint32_t on, lv, rt; + if (na < 1u || a[0] >= NSTEP) + return; + d = &TDRUM->dstep[a[0]]; + if (na >= 14u) { + on = (uint32_t)a[1] | (uint32_t)a[2] << 7 | (uint32_t)(a[3] & 3u) << 14; + lv = (uint32_t)a[4] | (uint32_t)a[5] << 7 | (uint32_t)a[6] << 14 | (uint32_t)a[7] << 21 | (uint32_t)(a[8] & 15u) << 28; + rt = (uint32_t)a[9] | (uint32_t)a[10] << 7 | (uint32_t)a[11] << 14 | (uint32_t)a[12] << 21 | (uint32_t)(a[13] & 15u) << 28; + fm1_irq_off(); + memset(d, 0, sizeof *d); + for (i = 0; i < DRUM_LANES; i++) + if ((on >> i) & 1u) + dstep_set(d, i, (lv >> (2u * i)) & 3u, (rt >> (2u * i)) & 3u); + fm1_irq_on(); + ui.force = 1; + if (song.sel == TRK_DRUM) + ed_w.st[a[0]] = ed_step_sig(&TDRUM->step[a[0]]); + } + on = dstep_mask(d); + lv = (uint32_t)d->lvl[0] | (uint32_t)d->lvl[1] << 8 | (uint32_t)d->lvl[2] << 16 | (uint32_t)d->lvl[3] << 24; + rt = (uint32_t)d->rat[0] | (uint32_t)d->rat[1] << 8 | (uint32_t)d->rat[2] << 16 | (uint32_t)d->rat[3] << 24; + ed_b(a[0]); + ed_b(on); + ed_b(on >> 7); + ed_b(on >> 14); + for (i = 0; i < 5u; i++) + ed_b(lv >> (7u * i)); + for (i = 0; i < 5u; i++) + ed_b(rt >> (7u * i)); + break; + } + case ED_TRACK_PARAM: { /* track, id [, v14] -> track, id, v14 */ + track_t *t; + if (na < 2u || a[0] >= NTRK || a[1] >= P_COUNT) + return; + t = &trk[a[0]]; + d = ed_tdesc(t, a[1]); + if (na >= 4u) { + if (d->max > d->min) /* as SET: clamped; a fixed value stays */ + t->p[a[1]] = (int16_t)clamp(ed_rv(a + 2), d->min, d->max); + ed_known(a[0], a[1]); + ui.force = 1; + } + ed_b(a[0]); + ed_b(a[1]); + ed_v(t->p[a[1]]); + break; + } + default: + return; + } + ed_send(); +} + +/* main loop: editor frames first; anything else stays for ota_service() */ +static void ed_service(void) +{ + const uint8_t *p; + uint32_t n; + ed_sync(); /* v2 pushes (while watched) */ + if (!ota_frame_get(&p, &n) || n < 4u || p[0] != ED_HDR0 || p[1] != ED_HDR1 || p[2] != ED_HDR2) + return; + ed_w.last_ms = fm1_ms; /* any request keeps WATCH alive */ + if (p[3] >= ED_SMP_BEGIN) { /* large frames: handled in place, then freed */ + ed_handle(p, n); + ota_frame_done(); + return; + } + { + static uint8_t f[64]; + uint32_t k = n > sizeof f ? sizeof f : n, i; + for (i = 0; i < k; i++) + f[i] = p[i]; + ota_frame_done(); /* free the frame buffer before replying */ + ed_handle(f, k); + } +} diff --git a/firmware/src/eng_analog.c b/firmware/src/eng_analog.c new file mode 100644 index 0000000..4a976cd --- /dev/null +++ b/firmware/src/eng_analog.c @@ -0,0 +1,127 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* ANALOG: two band-limited oscillators (saw / square / tri / sine / PWM), + * noise, drive and a trapezoidal low-pass. */ +static const char *const N_ANALOG_WAVE[] = {"SAW", "SQR", "TRI", "SIN", "PWM"}; + +static void analog_note_on(track_t *t, voice_t *v) +{ + (void)t; + if (!v->env && !v->env_out) + v->ph[0] = 0; /* a fresh note: from phase 0 (an 808 starts the same every time) */ + v->ph[1] = v->ph[0] + 0x40000000u; + v->s[0] = v->s[1] = 0; /* filter */ + if (!v->s[2]) + v->s[2] = 0x1234567 + (int32_t)v->age; /* noise state */ +} + +static void analog_render(track_t *t, voice_t *v, int32_t *out, uint32_t n, const vmod_t *m) +{ + const int16_t *p = t->p; + uint32_t wave = (uint32_t)p[P_E0], i; + int32_t det = p[P_E1], mix = p[P_E2], noise = p[P_E3]; + int32_t cut = (p[P_E4] << 8) + m->cutoff + (p[P_E7] * (v->pitch16 - 60 * 16) >> 4); + tsvf_t flt; + int32_t drive = 32768 + p[P_E6] * 768; /* 1x .. 4x */ + int32_t dw = p[P_E6] * 258; /* DRV: dry -> driven (a clean range low) */ + uint32_t inc1 = m->inc; + /* DTN in cents: whole 1/16 semitones from the table, the rest as a fine factor */ + int32_t d16 = det * 16 / 100, rem = det * 16 - d16 * 100; /* rem: 1/1600 semitone */ + uint32_t inc2 = PITCH_INC[clamp(m->pitch16 + d16, 0, 2047)]; + inc2 += (uint32_t)((int32_t)(inc2 >> 12) * (rem * 2367 / 16000)); + uint32_t pw = 0x80000000u + (uint32_t)((m->shape - (64 << 8)) << 15); + int32_t m2 = mix * 258, m1 = 32767 - m2; /* osc mix Q15 */ + int32_t nz = noise * 200, drv = p[P_E6]; + uint32_t ph0 = v->ph[0], ph1 = v->ph[1]; /* state in locals: out[] may alias v->s[] */ + int32_t ic1 = v->s[0], ic2 = v->s[1], nst = v->s[2]; + tsvf_coef(&flt, cut, p[P_E5]); + if (det == 0) + inc2 = inc1; + for (i = 0; i < n; i++) { + int32_t a, b = 0, s; + switch (wave) { + case 1: + a = osc_pulse(ph0, inc1, 0x80000000u); + if (m2) + b = osc_pulse(ph1, inc2, 0x80000000u); + break; + case 2: + a = osc_tri(ph0); + if (m2) + b = osc_tri(ph1); + break; + case 3: + a = osc_sine(ph0); + if (m2) + b = osc_sine(ph1); + break; + case 4: + a = osc_pulse(ph0, inc1, pw); + if (m2) + b = osc_pulse(ph1, inc2, pw); + break; + default: + a = osc_saw(ph0, inc1); + if (m2) + b = osc_saw(ph1, inc2); + break; + } + ph0 += inc1; + ph1 += inc2; + s = m2 ? mulq15(a, m1) + mulq15(b, m2) : a; /* (MIX 0, the 808s and subs: one oscillator) */ + if (nz) + s += mulq15((int32_t)(noise32(&nst) >> 17) - 16384, nz); + if (drv) /* pre-shifts: drive is up to 4x, no overflow */ + s += mulq15(softclip(((s >> 2) * (drive >> 2)) >> 11) - s, dw); + { /* filter: linear up to half scale, then a soft knee (only resonance peaks saturate) */ + int32_t y = tsvf_lp(&flt, s >> 1, &ic1, &ic2), a = y < 0 ? -y : y; + if (a > 16000) { + a = 16000 + (softclip((a - 16000) * 2) >> 1); + y = y < 0 ? -a : a; + } + s = y << 1; + } + out[i] += mulq15(mulq15(s, amp_at(m, i)), VOICE_FS) << 1; + } + v->ph[0] = ph0; + v->ph[1] = ph1; + v->s[0] = ic1; + v->s[1] = ic2; + v->s[2] = nst; +} + +static const preset_t ANALOG_PRESETS[] = { + /* SLOOP hip-hop / drum & bass bank. {WAVE, DTN, MIX, NOIS, CUT, RES, DRV, KTR}, {A D S R}, fenv, mono */ + /* 808s: a sine that decays (SUS 0) with a little pitch drop (ENV -> PITCH) and slides (GLIDE, legato) */ + {"808 BOOM", {3, 0, 0, 0, 127, 0, 48, 0}, {0, 112, 0, 52}, 0, 1, FX(0, 0, 0, 0), XP(P_GLIDE + 1, 59, P_GLMODE + 1, 1, P_ED_PIT + 1, 18, P_TRANS + 1, -24)}, + {"808 DIRTY", {3, 0, 0, 0, 96, 12, 118, 30}, {0, 108, 0, 46}, 0, 1, FX(24, 0, 0, 0), XP(P_GLIDE + 1, 56, P_GLMODE + 1, 1, P_ED_PIT + 1, 24, P_TRANS + 1, -24)}, + {"SUB BASS", {3, 0, 0, 0, 127, 0, 10, 0}, {0, 60, 118, 24}, 0, 1, FX(0, 0, 0, 0), XP(P_GLIDE + 1, 40, P_TRANS + 1, -24)}, + /* drum & bass: two detuned saws, slowly moving filter */ + {"REESE", {0, 22, 64, 0, 56, 22, 36, 40}, {0, 70, 118, 28}, 0, 1, FX(0, 22, 0, 6), XP(P_LRATE + 1, 22, P_LD_FLT + 1, 10, P_TRANS + 1, -24)}, + {"WOBBLE", {0, 9, 64, 0, 38, 72, 62, 30}, {0, 64, 127, 22}, 0, 1, FX(10, 0, 0, 4), XP(P_LRATE + 1, 74, P_LD_FLT + 1, 40, P_TRANS + 1, -24)}, + /* west coast: a square bass that slides, the high sine-ish lead with a delayed vibrato */ + {"FUNK BASS", {1, 6, 50, 0, 50, 30, 22, 64}, {0, 55, 62, 20}, 30, 1, FX(0, 0, 0, 4), XP(P_GLIDE + 1, 50, P_GLMODE + 1, 1, P_TRANS + 1, -24)}, + {"G-FUNK LD", {2, 0, 0, 0, 92, 0, 10, 64}, {6, 70, 112, 46}, 0, 1, FX(0, 0, 28, 30), + XP(P_GLIDE + 1, 74, P_LD_PIT + 1, 2, P_LRATE + 1, 89, P_LFADE + 1, 50)}, + {"TRAP PLUCK", {0, 8, 64, 0, 30, 35, 0, 64}, {0, 58, 0, 45}, 45, 0, FX(0, 15, 34, 26)}, + {"SYN BRASS", {0, 10, 64, 0, 45, 20, 16, 64}, {12, 70, 96, 35}, 34, 0, FX(0, 15, 12, 24)}, + {"WARM PAD", {4, 12, 64, 6, 52, 8, 0, 32}, {75, 90, 115, 90}, 0, 0, FX(0, 55, 20, 55), XP(P_LRATE + 1, 30, P_LD_SHP + 1, 20)}, + {"DARK STR", {0, 18, 64, 0, 48, 6, 0, 32}, {60, 90, 118, 85}, 0, 0, FX(0, 50, 18, 60)}, + {"ATMOS PAD", {4, 25, 64, 20, 60, 15, 0, 32}, {90, 100, 120, 100}, 0, 0, FX(0, 60, 30, 75), XP(P_LRATE + 1, 18, P_LD_PIT + 1, 1)}, +}; + +static const engine_t ENG_ANALOG = { + "ANALOG", {"OSC", "FLT"}, + { + {"WAVE", F_ENUM, 0, 4, 0, N_ANALOG_WAVE, 0}, + {"DTN", F_INT, 0, 127, 10, 0, "ct"}, + {"MIX", F_PCT, 0, 127, 64, 0, 0}, + {"NOIS", F_PCT, 0, 127, 0, 0, 0}, + {"CUT", F_CUTOFF, 0, 127, 90, 0, 0}, + {"RES", F_PCT, 0, 127, 30, 0, 0}, + {"DRV", F_PCT, 0, 127, 0, 0, 0}, + {"KTR", F_PCT, 0, 127, 64, 0, 0}, + }, + ANALOG_PRESETS, sizeof(ANALOG_PRESETS) / sizeof(ANALOG_PRESETS[0]), 1, analog_note_on, analog_render, + 0xF986, {P_E4, P_E5, P_ATK, P_REL}, +}; diff --git a/firmware/src/eng_digital.c b/firmware/src/eng_digital.c new file mode 100644 index 0000000..8c53d31 --- /dev/null +++ b/firmware/src/eng_digital.c @@ -0,0 +1,141 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* DIGITAL: four-operator FM. */ +/* Four sine operators, eight classic 4-operator algorithms (ALG = P_E0, EDIT 1 KNOB 1), + * op 4 with feedback, one modulation INDEX shaped by a modulator envelope. + * Phase modulation wraps naturally in the 32-bit phase. */ +static const char *const N_FMALG[] = {"1", "2", "3", "4", "5", "6", "7", "8"}; +static const char *const N_RATIO[] = {".5", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "14", "16"}; +static const uint16_t RATIO_Q8[15] = {128, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 2816, + 3072, 3584, 4096}; + +static void digital_note_on(track_t *t, voice_t *v) +{ + (void)t; + v->ph[0] = v->ph[1] = v->ph[2] = 0; + v->s[7] = 0; /* op 4 phase */ + v->s[4] = 1 << 24; /* modulator envelope, Q24 */ + v->s[5] = v->s[6] = 0; /* feedback history */ +} + +/* operator increment = carrier * ratio (Q8) without 32-bit overflow; kept below Nyquist */ +static inline uint32_t fm_ratio_inc(uint32_t inc, uint32_t r) +{ + uint32_t lim = 0x73000000u / r; /* (inc >> 8) * r must stay < 0x73000000 */ + return (inc >> 8) > lim ? 0x73000000u : (inc >> 8) * r; +} + +static inline uint32_t digital_mod(int32_t x, int32_t idx) { return (uint32_t)(x * idx) * 2065u; } + +static void digital_render(track_t *t, voice_t *v, int32_t *out, uint32_t n, const vmod_t *m) +{ + const int16_t *p = t->p; + uint32_t alg = (uint32_t)p[P_E0] & 7u, i; + uint32_t i1 = m->inc; + uint32_t i2 = fm_ratio_inc(m->inc, RATIO_Q8[p[P_E1] % 15]), i3 = fm_ratio_inc(m->inc, RATIO_Q8[p[P_E2] % 15]); + uint32_t i4 = fm_ratio_inc(m->inc, RATIO_Q8[p[P_E3] % 15]); + int32_t me, idx, fb = p[P_E6], fb1, fb2; /* fb1, fb2: op 4 feedback history */ + uint32_t ph0, ph1, ph2, ph4; + /* modulator envelope: decays (MODDEC) towards 25 %, per block */ + v->s[4] += mulq16((1 << 22) - v->s[4], ENV_EXP[p[P_E5] & 127]); + me = v->s[4] >> 9; /* Q15 */ + idx = (p[P_E4] * me) >> 15; /* 0..127 */ + idx = clamp(idx + ((m->cutoff + m->shape - (64 << 8)) >> 8) + (v->vel - 96) / 4, 0, 127); + ph0 = v->ph[0]; /* state in locals: out[] may alias v->s[] */ + ph1 = v->ph[1]; + ph2 = v->ph[2]; + ph4 = (uint32_t)v->s[7]; + fb1 = v->s[5]; + fb2 = v->s[6]; + for (i = 0; i < n; i++) { + int32_t o1, o2, o3, o4, s; + o4 = sine_i((ph4 + digital_mod((fb1 + fb2) >> 1, fb))); + fb2 = fb1; + fb1 = o4; + switch (alg) { + case 0: + o3 = sine_i((ph2 + digital_mod(o4, idx))); + o2 = sine_i((ph1 + digital_mod(o3, idx))); + s = sine_i((ph0 + digital_mod(o2, idx))); + break; + case 1: + o3 = sine_i(ph2); + o2 = sine_i((ph1 + digital_mod((o3 + o4) >> 1, idx))); + s = sine_i((ph0 + digital_mod(o2, idx))); + break; + case 2: + o3 = sine_i(ph2); + o2 = sine_i((ph1 + digital_mod(o3, idx))); + s = sine_i((ph0 + digital_mod((o2 + o4) >> 1, idx))); + break; + case 3: + o3 = sine_i((ph2 + digital_mod(o4, idx))); + o2 = sine_i(ph1); + s = sine_i((ph0 + digital_mod((o2 + o3) >> 1, idx))); + break; + case 4: + o3 = sine_i((ph2 + digital_mod(o4, idx))); + o2 = sine_i(ph1); + o1 = sine_i((ph0 + digital_mod(o2, idx))); + s = (o1 + o3) >> 1; + break; + case 5: + o3 = sine_i((ph2 + digital_mod(o4, idx))); + o2 = sine_i((ph1 + digital_mod(o4, idx))); + o1 = sine_i((ph0 + digital_mod(o4, idx))); + s = mulq15(o1 + o2 + o3, 10923); /* / 3 without a divide */ + break; + case 6: + o3 = sine_i((ph2 + digital_mod(o4, idx))); + o2 = sine_i(ph1); + o1 = sine_i(ph0); + s = mulq15(o1 + o2 + o3, 10923); /* / 3 without a divide */ + break; + default: + o3 = sine_i(ph2); + o2 = sine_i(ph1); + o1 = sine_i(ph0); + s = (o1 + o2 + o3 + o4) >> 2; + break; + } + ph0 += i1; + ph1 += i2; + ph2 += i3; + ph4 += i4; + out[i] += mulq15(mulq15(s, amp_at(m, i)), VOICE_FS); /* full-scale sines: 6 dB below the others */ + } + v->ph[0] = ph0; + v->ph[1] = ph1; + v->ph[2] = ph2; + v->s[7] = (int32_t)ph4; + v->s[5] = fb1; + v->s[6] = fb2; +} + +static const preset_t DIGITAL_PRESETS[] = { + /* ALG R2 R3 R4 INDEX MODDEC FDBK - ; ALG 5 (4 here) = two stacks: 2 -> 1 and 4 -> 3 (the tine) */ + {"RHODES", {4, 1, 1, 14, 26, 35, 0, 0}, {0, 85, 35, 55}, 0, 0, FX(0, 30, 12, 26), XP(P_LD_AMP + 1, 26, P_LRATE + 1, 84)}, + {"DX RHODES", {4, 1, 1, 14, 85, 45, 0, 0}, {0, 82, 40, 55}, 0, 0, FX(0, 45, 20, 30)}, + {"WURLI", {4, 1, 2, 3, 62, 35, 8, 0}, {0, 75, 30, 45}, 0, 0, FX(10, 20, 10, 20), XP(P_LD_AMP + 1, 16, P_LRATE + 1, 89)}, + {"CLAV", {3, 1, 3, 5, 90, 25, 20, 0}, {0, 50, 20, 18}, 0, 0, FX(10, 10, 6, 10)}, + {"TRAP BELL", {4, 8, 1, 4, 80, 70, 0, 0}, {0, 92, 0, 70}, 0, 0, FX(0, 0, 30, 40)}, + {"MUSIC BOX", {4, 4, 3, 9, 45, 75, 0, 0}, {0, 90, 0, 75}, 0, 0, FX(0, 10, 32, 45)}, + {"MARIMBA", {4, 4, 1, 1, 60, 30, 0, 0}, {0, 80, 0, 60}, 0, 0, FX(0, 0, 22, 30)}, + {"FM BASS", {0, 1, 1, 1, 34, 40, 8, 0}, {0, 60, 70, 25}, 0, 1, FX(0, 0, 0, 6), XP(P_GLIDE + 1, 36, P_TRANS + 1, -24)}, +}; + +static const engine_t ENG_DIGITAL = { + "DIGITAL", {"OPS", "MOD"}, + { + {"ALG", F_ENUM, 0, 7, 0, N_FMALG, 0}, + {"R2", F_ENUM, 0, 14, 1, N_RATIO, 0}, + {"R3", F_ENUM, 0, 14, 1, N_RATIO, 0}, + {"R4", F_ENUM, 0, 14, 1, N_RATIO, 0}, + {"IDX", F_PCT, 0, 127, 60, 0, 0}, + {"MDEC", F_TIME, 0, 127, 60, 0, 0}, + {"FB", F_PCT, 0, 127, 0, 0, 0}, + {"-", F_INT, 0, 0, 0, 0, 0}, + }, + DIGITAL_PRESETS, sizeof(DIGITAL_PRESETS) / sizeof(DIGITAL_PRESETS[0]), -1, digital_note_on, digital_render, + 0xFD20, {P_E4, P_E5, P_E6, P_REL}, +}; diff --git a/firmware/src/eng_drawbar.c b/firmware/src/eng_drawbar.c new file mode 100644 index 0000000..74e27c3 --- /dev/null +++ b/firmware/src/eng_drawbar.c @@ -0,0 +1,291 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* DRAWBAR: a tonewheel-style additive organ. Felucca's own design. + * + * Partials: nine sines per voice at the classic drawbar footages, 16' 5 1/3' 8' 4' 2 2/3' 2' + * 1 3/5' 1 1/3' 1' (0.5, 1.5, 1, 2, 3, 4, 5, 6, 8 times the note), each with a level 0..8 + * (about 3 dB a step). One shared sine table (plain lookup), one free-running integer phase + * per partial: a note starts wherever its wheels are, as on the real generators. A partial + * above ~6 kHz folds back an octave (as the top of a tonewheel set does), so nothing aliases. + * Partials at level 0 are skipped (their phase still runs). + * + * Registration: 8 knobs cannot hold 9 drawbars, so REG picks one of 16 drawbar settings + * (DRW_REG: our list of common registrations) and SUB / BODY / TOP add -8..+8 to its sub + * bars (16', 5 1/3'), its body (8', 4') and its upper bars (2 2/3' .. 1'). The louder the + * registration, the less each bar gets (a soft normalisation: full bars are louder than one + * bar, but they do not stack up to clipping). + * + * PERC: a decaying partial on the 2nd (4') or 3rd (2 2/3') harmonic, normal or soft, fast + * or slow. Single trigger: it only strikes on a note that starts while no other key of the + * part is held (legato playing gets none). With PERC on the 1' bar is silent and, at normal + * level, the bars drop by ~3 dB, as on the real circuit. + * CLICK: a short burst of high-passed noise at the key contact (half as loud at the release). + * DRIVE: a per-voice soft overdrive (tanh); for chord growl add the track's DIST. + * ROTR: a cheap rotary speaker effect: two rotors (a low one and a high one, split by partial + * frequency at ~800 Hz) that spin SLOW or FAST and ramp between the speeds (the high rotor in + * ~1 s, the low one in ~4 s); each gives its partials an amplitude and a pitch (Doppler) + * modulation whose depth follows its speed. All of it is folded into the per-block partial + * gains and increments: no delay line, no per-sample cost. OFF fades it out and stops them. + * + * Envelope: an organ gate (the presets set A 0, S 127, a short R); the track ADSR still applies. + * Cost: per sample and partial one table lookup and a multiply-add (a gain ramp only for the + * partials whose gain moved: percussion, rotary, knobs); the bar levels, the rotor and the + * percussion run once per block. State: the per-track rotor and bar gains (drw_trk) and the + * per-voice phases / gains (drw_vc) live here, indexed by part and voice; voice_t is unused. */ +#define DRW_NP 9 /* partials */ +#define DRW_FOLD 584366000u /* ~6 kHz as a phase increment: partials above fold down an octave */ +#define DRW_XOVER 77915000u /* ~800 Hz: below the low rotor, above the high rotor */ + +/* drawbar level 0..8 -> Q15, 3 dB a step */ +static const uint16_t DRW_LV[9] = {0, 2920, 4125, 5827, 8231, 11627, 16423, 23198, 32767}; + +/* the 16 registrations, one digit per bar: 16' 5 1/3' 8' 4' 2 2/3' 2' 1 3/5' 1 1/3' 1' */ +static const char *const N_DRW_REG[] = {"FLUTE", "MELLO", "HOLLW", "SMOOT", "3BAR", "BLUES", "GOSPL", "ROCK", + "TOPS", "CLARI", "REED", "STRNG", "CHAPL", "BRITE", "BASS", "FULL"}; +static const char DRW_REG[16][DRW_NP + 1] = { + "008000000", /* FLUTE one soft flute */ + "008400000", /* MELLO flute and octave */ + "800800000", /* HOLLW sub and octave, hollow */ + "838000000", /* SMOOT smooth comping */ + "888000000", /* 3BAR the first three bars out */ + "888800000", /* BLUES three bars and the octave */ + "888600006", /* GOSPL body with a little shimmer */ + "888000888", /* ROCK body and the top three */ + "800000888", /* TOPS sub and the top only */ + "008080800", /* CLARI odd harmonics, reedy-hollow */ + "008765432", /* REED a falling slope, brassy */ + "006876540", /* STRNG bright and thin */ + "004432000", /* CHAPL soft, churchy */ + "008888000", /* BRITE even bars, bright */ + "858000000", /* BASS for the left hand */ + "888888888", /* FULL everything */ +}; +static const char *const N_DRW_PERC[] = {"OFF", "2ND", "3RD", "2SOFT", "3SOFT", "2SLOW", "3SLOW"}; +static const char *const N_DRW_ROTR[] = {"OFF", "SLOW", "FAST"}; + +/* partial frequency / note frequency, as a shift-and-add of the note's increment; FOLD_LIM: + * the note increment above which the partial would pass DRW_FOLD */ +static const uint32_t DRW_FOLD_LIM[DRW_NP] = { + DRW_FOLD * 2u, DRW_FOLD / 3u * 2u, DRW_FOLD, DRW_FOLD / 2u, DRW_FOLD / 3u, DRW_FOLD / 4u, DRW_FOLD / 5u, + DRW_FOLD / 6u, DRW_FOLD / 8u, +}; +static inline uint32_t drw_ratio(uint32_t k, uint32_t x) +{ + switch (k) { + case 0: return x >> 1; + case 1: return x + (x >> 1); + case 2: return x; + case 3: return x << 1; + case 4: return x * 3u; + case 5: return x << 2; + case 6: return x * 5u; + case 7: return x * 6u; + default: return x << 3; + } +} + +/* rotor speeds as phase increments per block (CTL samples): Hz * CTL / FS * 2^32 */ +#define DRW_HZ(h) ((int32_t)((h) * 3116457.0)) +static const int32_t DRW_ROT_SPD[2][3] = { + {0, DRW_HZ(0.8), DRW_HZ(6.7)}, /* high rotor: OFF (stops), SLOW, FAST */ + {0, DRW_HZ(0.7), DRW_HZ(5.8)}, /* low rotor */ +}; + +typedef struct { /* per part, once per block (drawbar_block) */ + int32_t g[DRW_NP]; /* bar gains, Q15, normalised */ + int32_t pk, plev; /* percussion: partial (DRW_NP = off), level Q15 */ + uint32_t pdec; /* its decay per block, Q16 */ + int32_t clk; /* click level Q15 */ + int32_t dg, dcomp; /* drive gain, Q8; output compensation, Q8 (0 = no drive) */ + uint32_t rph[2]; /* rotor phases (0 high, 1 low) */ + int32_t rsp[2]; /* rotor speeds (phase increment per block) */ + int32_t rwet; /* rotary amount, Q15 (ramps on / off) */ + int32_t am[2]; /* this block's amplitude, Q15, per rotor */ + int32_t fm[2]; /* this block's pitch offset, Q16 of the increment, per rotor */ +} drw_trk_t; + +typedef struct { /* per voice */ + uint32_t ph[DRW_NP]; + int32_t gp[DRW_NP]; /* each partial's gain at the end of the last block (the ramp start) */ + int32_t perc; /* percussion envelope, Q15 */ + int32_t clk; /* click envelope, Q15 */ + int32_t nz, hp; /* click noise state, its high-pass state */ + uint8_t gate, init; +} drw_vc_t; + +static drw_trk_t drw_t[NPART]; +static drw_vc_t drw_v[NPART][NVOICE]; + +static uint32_t drw_part(const track_t *t) { return (uint32_t)(t - trk) % NPART; } + +/* the bar level 0..8 of partial k: the registration plus SUB / BODY / TOP */ +static int32_t drw_level(const int16_t *p, uint32_t k) +{ + int32_t d = DRW_REG[(uint32_t)p[P_E0] & 15u][k] - '0'; + d += k < 2u ? p[P_E1] : k < 4u ? p[P_E2] : p[P_E3]; + return clamp(d, 0, 8); +} + +/* once per block, before the voices: bar gains, percussion, click, drive, the rotors */ +static void drawbar_block(track_t *t) +{ + drw_trk_t *T = &drw_t[drw_part(t)]; + const int16_t *p = t->p; + uint32_t k, perc = (uint32_t)p[P_E4] % 7u, rot = (uint32_t)p[P_E7] % 3u; + int32_t s = 0, lv[DRW_NP]; + uint32_t norm; + for (k = 0; k < DRW_NP; k++) { + lv[k] = perc && k == DRW_NP - 1u ? 0 : DRW_LV[drw_level(p, k)]; /* PERC on: the 1' bar is off */ + s += lv[k]; + } + /* sum of the gains = 2.4 s / (s + 1.5) (s in units of a full bar): one bar 0.96, three 1.6, + * all nine 2.06 */ + norm = (uint32_t)(2u * 39322u * 32768u) / (uint32_t)(s + 49152); + if (perc == 1u || perc == 2u || perc == 5u || perc == 6u) + norm = (norm * 23170u) >> 15; /* normal percussion: the bars -3 dB */ + for (k = 0; k < DRW_NP; k++) + T->g[k] = (int32_t)(((uint32_t)lv[k] * norm) >> 15); + T->pk = perc ? (int32_t)(3u + ((perc - 1u) & 1u)) : DRW_NP; /* 2ND: 4', 3RD: 2 2/3' */ + T->plev = perc == 3u || perc == 4u ? 12000 : 24000; + T->pdec = perc >= 5u ? 65457u : 65219u; /* tau 0.6 s / 0.15 s */ + T->clk = p[P_E5] * 180; + if (p[P_E6]) { /* y = 6 / (2 + g) tanh(g x / 2) */ + T->dg = 256 + p[P_E6] * 6; /* 1 .. 4 */ + T->dcomp = (6 * 256 * 256) / (512 + T->dg); + } else { + T->dg = 0; + } + /* rotors: each speed eases to its target (high rotor tau ~0.37 s, low ~1.5 s) */ + for (k = 0; k < 2u; k++) { + int32_t sp, c, sn, dep; + T->rsp[k] += (DRW_ROT_SPD[k][rot] - T->rsp[k]) >> (k ? 11 : 9); + sp = T->rsp[k]; + T->rph[k] += (uint32_t)sp; + sn = sine_i(T->rph[k]); + c = sine_i(T->rph[k] + 0x40000000u); + dep = k ? 7000 : 13000; /* AM depth: low rotor 21 %, high 40 % */ + T->am[k] = 32767 - mulq15(dep, (32767 - c) >> 1); + T->fm[k] = (sn * (sp >> (k ? 17 : 16))) >> 15; /* Doppler: +-0.5 % fast (high), +-0.2 % (low) */ + } + T->rwet += ((rot ? 32767 : 0) - T->rwet) >> 5; /* ~25 ms in or out */ + for (k = 0; k < 2u; k++) { + T->am[k] = 32767 - mulq15(T->rwet, 32767 - T->am[k]); + T->fm[k] = mulq15(T->fm[k], T->rwet); + } +} + +static void drawbar_note_on(track_t *t, voice_t *v) +{ + uint32_t vi = (uint32_t)(v - t->v) % NVOICE, k, held = 0; + drw_vc_t *V = &drw_v[drw_part(t)][vi]; + for (k = 0; k < NVOICE; k++) /* single trigger: another key of the part held? */ + if (&t->v[k] != v && t->v[k].active && t->v[k].gate && t->v[k].stage != 4u) + held = 1; + if (!V->init) { /* the wheels: spread start phases, then free running */ + for (k = 0; k < DRW_NP; k++) + V->ph[k] = (k * 0x9E3779B9u) ^ (vi * 0x7F4A7C15u); + V->nz = 0x13579BDF + (int32_t)vi; + V->init = 1; + } + V->perc = held ? 0 : 32767; + V->clk = 32767; + V->hp = 0; + V->gate = 1; +} + +static void drawbar_render(track_t *t, voice_t *v, int32_t *out, uint32_t n, const vmod_t *m) +{ + const drw_trk_t *T = &drw_t[drw_part(t)]; + drw_vc_t *V = &drw_v[drw_part(t)][(uint32_t)(v - t->v) % NVOICE]; + int32_t acc[CTL], perc1, clk0, clk1; + uint32_t i, k; + if (n > CTL) + n = CTL; + for (i = 0; i < n; i++) + acc[i] = 0; + perc1 = (int32_t)(((uint32_t)V->perc * T->pdec) >> 16); + for (k = 0; k < DRW_NP; k++) { + uint32_t x = m->inc, inc, ph = V->ph[k]; + int32_t g1 = T->g[k], g0 = V->gp[k], r; + if ((int32_t)k == T->pk) + g1 += mulq15(T->plev, perc1); + while (x > DRW_FOLD_LIM[k]) /* fold back above ~6 kHz */ + x >>= 1; + inc = drw_ratio(k, x); + r = inc < DRW_XOVER; /* 1: the low rotor */ + g1 = mulq15(g1, T->am[r]); + inc += (uint32_t)((int32_t)(inc >> 16) * T->fm[r]); + V->gp[k] = g1; + if (!g0 && !g1) { + V->ph[k] = ph + inc * n; + continue; + } + if (g0 == g1) { + for (i = 0; i < n; i++) { + ph += inc; + acc[i] += (SINE[ph >> 22] * g1) >> 15; + } + } else { /* gain ramp over the block (CTL = 32) */ + int32_t gq = g0 << 5, dg = g1 - g0; + for (i = 0; i < n; i++) { + ph += inc; + gq += dg; + acc[i] += (SINE[ph >> 22] * (gq >> 5)) >> 15; + } + } + V->ph[k] = ph; + } + V->perc = perc1; + /* key click: high-passed noise, at the key contact and (half) at the release */ + if (V->gate && !v->gate) { + V->gate = 0; + V->clk = 16384; + } + clk0 = mulq15(V->clk, T->clk); + if (clk0 > 16) { + int32_t nst = V->nz, hp = V->hp, dc; + V->clk = (V->clk * 3) >> 2; /* tau ~2.5 ms */ + clk1 = mulq15(V->clk, T->clk); + dc = clk1 - clk0; + clk0 <<= 5; + for (i = 0; i < n; i++) { + int32_t z = (int32_t)(noise32(&nst) >> 17) - 16384, y = z - hp; + hp += y >> 3; + clk0 += dc; + acc[i] += (y * (clk0 >> 5)) >> 15; + } + V->nz = nst; + V->hp = hp; + } + if (T->dg) { /* overdrive */ + int32_t dg = T->dg, dcomp = T->dcomp; + for (i = 0; i < n; i++) + acc[i] = (softclip((acc[i] * dg) >> 9) * dcomp) >> 8; + } + for (i = 0; i < n; i++) /* acc: Q15 with headroom to 4.0 */ + out[i] += mulq15(mulq15(acc[i] >> 1, amp_at(m, i)), VOICE_FS) << 1; +} + +static const preset_t DRAWBAR_PRESETS[] = { + /* name, {REG, SUB, BODY, TOP, PERC, CLICK, DRIVE, ROTR}, {A D S R}, fenv, mono */ + {"SOUL ORGAN", {3, 0, 0, 0, 0, 25, 10, 1}, {0, 64, 127, 40}, 0, 0, FX(0, 0, 0, 22)}, + {"GOSPEL", {6, 0, 0, 0, 1, 60, 40, 2}, {0, 64, 127, 45}, 0, 0, FX(0, 0, 0, 30)}, + {"JAZZ ORGAN", {4, 0, 0, 0, 2, 50, 8, 1}, {0, 64, 127, 40}, 0, 0, FX(0, 0, 0, 22)}, + {"DIRTY B3", {5, 0, 0, 0, 0, 60, 90, 2}, {0, 64, 127, 40}, 0, 0, FX(30, 0, 6, 20)}, +}; + +static const engine_t ENG_DRAWBAR = { + "WHEEL", {"BARS", "TONE"}, + { + {"REG", F_ENUM, 0, 15, 4, N_DRW_REG, 0}, + {"SUB", F_INT, -8, 8, 0, 0, 0}, + {"BODY", F_INT, -8, 8, 0, 0, 0}, + {"TOP", F_INT, -8, 8, 0, 0, 0}, + {"PERC", F_ENUM, 0, 6, 0, N_DRW_PERC, 0}, + {"CLICK", F_PCT, 0, 127, 40, 0, 0}, + {"DRV", F_PCT, 0, 127, 0, 0, 0}, + {"ROTR", F_ENUM, 0, 2, 1, N_DRW_ROTR, 0}, + }, + DRAWBAR_PRESETS, sizeof(DRAWBAR_PRESETS) / sizeof(DRAWBAR_PRESETS[0]), -1, drawbar_note_on, drawbar_render, + 0xBC1F, {P_E0, P_E4, P_E6, P_E7}, 0, 0, 0, drawbar_block, +}; diff --git a/firmware/src/eng_formant.c b/firmware/src/eng_formant.c new file mode 100644 index 0000000..7d68c74 --- /dev/null +++ b/firmware/src/eng_formant.c @@ -0,0 +1,236 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* VOICE: formant oscillator, sung vowels from the keyboard. 4 voices. + * After D. H. Klatt, "Software for a cascade/parallel formant synthesizer", + * JASA 67 (1980): a glottal source (derivative of a Rosenberg (1971) pulse, + * no DC) into four two-pole resonators in cascade, F1 -> F2 -> F3 -> F4. + * Design follows klattsch by Tony Gies (MIT, design reference only, no code + * copied). Formant data from Klatt (1980) and Hillenbrand et al. (1995). + * + * source rising half-sine while opening (Tp), falling quarter-sine while + * closing (Tn), 0 while closed; the closure step goes through blep() + * BUZZ open quotient 0.9 .. 0.35 and a one-pole spectral tilt + * BREATH noise, louder while the glottis is open, mixed before the + * resonators; at the top the voicing fades out (whisper) + * F1..F4 y = A x + B y1 + C y2, C = -r^2, B = 2 r cos(2 pi F / FS), + * A = 1 - B - C (unity gain at DC), Q30 coefficients per block; + * F4 is fixed at 3300 Hz and moves only with SHIFT / key tracking + * PRES out = y + k (y - y[-1]), a first-difference shelf; k follows BUZZ + * + * Voice state: ph[0] glottal phase, ph[1..2] F4 y1 / y2, s[0..5] F1..F3 + * y1 / y2, s[6] tilt, s[7] TALK progress (Q24, bits 0..24) and the note's + * random vowel (bits 25..31). Formant key tracking is fixed at 30 / 127. */ +#define FMT_FOLOW 30 +#define FMT_TALK_MASK 0x01FFFFFF + +/* formants (Hz) of A E I O U: adult male means, Hillenbrand et al., JASA 97 + * (1995) (/a/ hod, /E/ head, /i/ heed, /o/ hoed, /u/ who'd); bandwidths (Hz) + * in the range of Klatt (1980) and of measured vowel bandwidths */ +static const uint16_t VOWEL_F[5][3] = { + {768, 1333, 2522}, {580, 1799, 2605}, {342, 2322, 3000}, {497, 910, 2459}, {378, 997, 2343}, +}; +static const uint8_t VOWEL_B[5][3] = { + {90, 100, 160}, {70, 100, 170}, {50, 120, 200}, {70, 80, 150}, {60, 80, 150}, +}; +/* 2^(k/12), Q16, k = 0..12 */ +static const uint32_t SEMI_Q16[13] = { + 65536, 69433, 73562, 77936, 82570, 87480, 92682, 98193, 104032, 110218, 116772, 123715, 131072, +}; + +/* 2^(st16 / 192) in Q16 (st16 in 1/16 semitone), clamped to 1/16 .. 16. + * Divisions by constants are written as multiplies: -Os keeps them as divides */ +static uint32_t fmt_ratio(int32_t st16) +{ + int32_t o, k; + uint32_t r; + st16 = clamp(st16, -4 * 192, 4 * 192 - 1) + 4 * 192; /* 0 .. 8 octaves */ + o = (st16 * 2731) >> 19; /* / 192, exact for 0 .. 1535 */ + k = st16 - o * 192; + r = SEMI_Q16[k >> 4] + (((SEMI_Q16[(k >> 4) + 1] - SEMI_Q16[k >> 4]) * (uint32_t)(k & 15)) >> 4); + return o >= 4 ? r << (o - 4) : r >> (4 - o); +} + +/* the three formants of vowel position pos (0..127 << 8, A E I O U), Hz * 16 */ +static void vowel_at(int32_t pos, int32_t *f, int32_t *b) +{ + int32_t x = (clamp(pos, 0, 127 << 8) * 33027) >> 20, i = x >> 8, fr = x & 255, j; /* * 4 / 127 */ + if (i >= 4) { + i = 3; + fr = 256; + } + for (j = 0; j < 3; j++) { + f[j] = (VOWEL_F[i][j] << 4) + (((VOWEL_F[i + 1][j] - VOWEL_F[i][j]) * fr) >> 4); + b[j] = (VOWEL_B[i][j] << 4) + (((VOWEL_B[i + 1][j] - VOWEL_B[i][j]) * fr) >> 4); + } +} + +typedef struct { int32_t a, b, c; } fres_t; +static int32_t formant_nz = 0x2545F491; /* breath noise, one xorshift for all voices */ + +/* Klatt resonator coefficients (Q30) for F, BW in Hz * 16 */ +static void fres_coef(fres_t *r, uint32_t f16, uint32_t bw16) +{ + int32_t s = sine_i(f16 * 3044u); /* sin(pi F / FS), Q15 (2^32 / (2 FS) / 16) */ + int32_t x = (int32_t)(bw16 * 4781u); /* pi BW / FS, Q30 (<= 0.2) */ + int32_t x2 = (int32_t)(((int64_t)x * x) >> 30), x3 = (int32_t)(((int64_t)x2 * x) >> 30); + int32_t x4 = (int32_t)(((int64_t)x3 * x) >> 30); + int32_t e = (1 << 30) - x + (x2 >> 1) - (int32_t)(((int64_t)x3 * 178956971) >> 30) /* exp(-x): x^3 / 6, */ + + (int32_t)(((int64_t)x4 * 44739243) >> 30); /* x^4 / 24 */ + int32_t cs = (1 << 30) - 2 * s * s; /* cos(2 pi F / FS) = 1 - 2 sin^2, Q30 */ + r->b = (int32_t)(((int64_t)e * cs) >> 29); /* 2 r cos */ + r->c = -(int32_t)(((int64_t)e * e) >> 30); /* -r^2 */ + r->a = (1 << 30) - r->b - r->c; +} + +static void formant_note_on(track_t *t, voice_t *v) +{ + (void)t; + formant_nz ^= formant_nz << 13; /* a random vowel for this note (RAND) */ + formant_nz ^= (int32_t)((uint32_t)formant_nz >> 17); + formant_nz ^= formant_nz << 5; + v->s[7] = (int32_t)(((uint32_t)formant_nz >> 25) << 25); /* TALK starts over, random vowel kept */ + if (!v->env && !v->env_out) { /* a fresh voice (not a retrigger): from rest */ + uint32_t i; + v->ph[0] = 0; /* the opening starts at zero: no click */ + v->ph[1] = v->ph[2] = 0; + for (i = 0; i < 7u; i++) + v->s[i] = 0; + } +} + +static void formant_render(track_t *t, voice_t *v, int32_t *out, uint32_t n, const vmod_t *m) +{ + const int16_t *p = t->p; + fres_t r1, r2, r3, r4; + int32_t fa[3], ba[3], fb[3], bb[3], k, j, buzz, oq, tilt, gv, gn, og, ogk; + uint32_t inc = m->inc, i, te, tp, rp, rn, ratio, bws, f0; + uint32_t ph = v->ph[0]; + int32_t y1 = v->s[0], y2 = v->s[1], y3 = v->s[2], y4 = v->s[3], y5 = v->s[4], y6 = v->s[5]; + int32_t y7 = (int32_t)v->ph[1], y8 = (int32_t)v->ph[2], lp = v->s[6], nst = formant_nz; + + /* vowel: VOWEL -> VOWL2 over TALK after note-on; ENV / LFO -> FLT move both */ + k = 0; + if (p[P_E2]) { + uint32_t g = ((uint32_t)v->s[7] & FMT_TALK_MASK) + ENV_LIN[p[P_E2] & 127]; + g = g > (1u << 24) ? 1u << 24 : g; + v->s[7] = (int32_t)(((uint32_t)v->s[7] & ~(uint32_t)FMT_TALK_MASK) | g); + k = (int32_t)(g >> 9); /* Q15 */ + k = (k * (65536 - k)) >> 15; /* ease out: the mouth opens fast, then settles */ + } + { /* RAND: both vowels move towards this note's random vowel (0 = off, 127 = fully random) */ + int32_t rv = (int32_t)(((uint32_t)v->s[7] >> 25) << 8), v0 = p[P_E0] << 8, v1 = p[P_E1] << 8; + v0 += ((rv - v0) * p[P_E7] * 258) >> 15; + v1 += ((rv - v1) * p[P_E7] * 258) >> 15; + vowel_at(v0 + m->cutoff, fa, ba); + vowel_at(v1 + m->cutoff, fb, bb); + } + /* SHIFT (semitones) and FOLOW (key tracking around C4, fixed), one ratio for all four */ + ratio = fmt_ratio(p[P_E3] * 16 + ((FMT_FOLOW * (v->pitch_cur - 60 * 16) * 516) >> 16)); /* FOLOW / 127 */ + bws = fmt_ratio((64 - p[P_E6]) * 4); /* Q: bandwidth x2.5 .. x0.4 */ + f0 = (uint32_t)(((uint64_t)inc * 705600u) >> 32); /* F0 in Hz * 16 */ + for (j = 0; j < 3; j++) { + int32_t f = fa[j] + (((fb[j] - fa[j]) * k) >> 15), b = ba[j] + (((bb[j] - ba[j]) * k) >> 15); + f = (int32_t)(((int64_t)f * ratio) >> 16); + b = (int32_t)(((((int64_t)b * ratio) >> 16) * bws) >> 16); + if (j == 0 && (uint32_t)f < f0 + (f0 >> 4) && f > 0) { /* sung high: F1 follows F0 (sopranos do), */ + b = (int32_t)(((int64_t)b * (int32_t)(f0 + (f0 >> 4))) / f); /* same Q: no boom on the fundamental */ + f = (int32_t)(f0 + (f0 >> 4)); + } + fa[j] = clamp(f, 60 * 16, 7000 * 16); + ba[j] = clamp(b, 20 * 16, 1500 * 16); + } + fres_coef(&r1, (uint32_t)fa[0], (uint32_t)ba[0]); + fres_coef(&r2, (uint32_t)fa[1], (uint32_t)ba[1]); + fres_coef(&r3, (uint32_t)fa[2], (uint32_t)ba[2]); + fres_coef(&r4, (uint32_t)clamp((int32_t)((3300u * 16u * (uint64_t)ratio) >> 16), 60 * 16, 7000 * 16), + (uint32_t)clamp((int32_t)((((250u * 16u * (uint64_t)ratio) >> 16) * bws) >> 16), 20 * 16, 1500 * 16)); + + /* source: BUZZ (+ SHP modulation, + velocity) -> open quotient and tilt */ + buzz = clamp((p[P_E4] << 8) + m->shape - (64 << 8) + (v->vel - 96) * 40, 0, 127 << 8); + oq = 58982 - ((buzz * 284) >> 8); /* Q16: 0.90 .. 0.35 */ + tilt = 2500 + ((buzz * 109) >> 8); /* one-pole coefficient Q14: dark .. open */ + te = (uint32_t)oq << 16; /* closure (end of the open phase) */ + tp = (te >> 8) * 166u; /* opening: 65 % of it, closing 35 % */ + rp = (1u << 30) / ((tp >> 16) | 1u); + rn = (1u << 30) / (((te - tp) >> 16) | 1u); + gv = 32767 - p[P_E5] * p[P_E5] * 2; /* BREATH: voicing fades at the top */ + gn = p[P_E5] * 258; /* noise: Q15, up to 1.0 */ + og = 13000 - ((p[P_E6] - 64) * 50); /* output: narrower bands ring louder */ + og = (int32_t)(((int64_t)og * fmt_ratio((60 * 16 - v->pitch_cur) / 4)) >> 16); /* 1.5 dB / oct: low notes are sparse pulses */ + ogk = (og >> 2) * (4 + (buzz >> 10)); /* presence k = 1 .. 4.9 */ + + for (i = 0; i < n; i++) { + int32_t e, x, a, s; + if (ph < tp) /* opening: + sin(pi u) * Tn / Tp */ + e = (sine_i(((ph >> 16) * rp) << 1) * 17644) >> 15; + else if (ph < te) /* closing: - sin(pi / 2 u) */ + e = -sine_i(((ph - tp) >> 16) * rn); + else + e = 0; + e += blep(ph - te, inc) >> 1; /* the closure step, band-limited */ + lp += ((e - lp) * tilt) >> 14; + x = (lp * gv) >> 15; + if (gn) { + int32_t nz = (((int32_t)(noise32(&nst) >> 16) - 32768) * gn) >> 15; + x += ph < te ? nz : nz >> 1; /* aspiration follows the glottal opening */ + } + /* F1 -> F2 -> F3 -> F4, Q30, rounded; the signal x 64 inside: the rounding + * dead band of F1 (+-0.5 / A, ~340 at 270 Hz) stays below 6 LSB */ + a = (int32_t)(((int64_t)r1.a * (x << 6) + (int64_t)r1.b * y1 + (int64_t)r1.c * y2 + (1 << 29)) >> 30); + y2 = y1; + y1 = a; + a = (int32_t)(((int64_t)r2.a * a + (int64_t)r2.b * y3 + (int64_t)r2.c * y4 + (1 << 29)) >> 30); + y4 = y3; + y3 = a; + a = (int32_t)(((int64_t)r3.a * a + (int64_t)r3.b * y5 + (int64_t)r3.c * y6 + (1 << 29)) >> 30); + y6 = y5; + y5 = a; + a = (int32_t)(((int64_t)r4.a * a + (int64_t)r4.b * y7 + (int64_t)r4.c * y8 + (1 << 29)) >> 30); + y8 = y7; + y7 = clamp(a, -(1 << 28), 1 << 28); /* int32 state stays far from overflow */ + s = clamp((int32_t)(((int64_t)y7 * og + (int64_t)(y7 - y8) * ogk) >> 21), -200000, 200000); + a = s < 0 ? -s : s; + if (a > 24000) { /* soft knee: only peaks saturate */ + a = 24000 + (softclip((a - 24000) * 2) >> 1); + s = s < 0 ? -a : a; + } + ph += inc; + out[i] += mulq15(mulq15(s, amp_at(m, i)), VOICE_FS) << 1; + } + v->ph[0] = ph; + v->ph[1] = (uint32_t)y7; + v->ph[2] = (uint32_t)y8; + formant_nz = nst; + v->s[0] = y1; + v->s[1] = y2; + v->s[2] = y3; + v->s[3] = y4; + v->s[4] = y5; + v->s[5] = y6; + v->s[6] = lp; +} + +static const preset_t FORMANT_PRESETS[] = { + /* VOWEL VOWL2 TALK SHIFT | BUZZ BREATH Q RAND ; vowels A E I O U over 0..127 */ + {"CHOIR AAH", {0, 0, 0, 0, 40, 22, 60, 0}, {85, 90, 115, 95}, 0, 0, FX(0, 60, 10, 70)}, + {"SOUL OOH", {110, 0, 0, 0, 30, 30, 55, 0}, {70, 90, 115, 90}, 0, 0, FX(0, 60, 10, 70)}, + {"TALKBOX", {32, 95, 60, 0, 100, 4, 75, 0}, {4, 70, 110, 40}, 0, 1, FX(10, 15, 20, 25), + XP(P_GLIDE + 1, 60, P_LD_PIT + 1, 2, P_LRATE + 1, 89)}, + {"WOW BASS", {95, 0, 68, 0, 100, 0, 80, 0}, {0, 70, 70, 30}, 0, 1, FX(10, 0, 0, 6), XP(P_TRANS + 1, -12)}, +}; + +static const engine_t ENG_FORMANT = { + "VOICE", {"VOWL", "TONE"}, + { + {"VOWL", F_INT, 0, 127, 0, 0, 0}, + {"VOWL2", F_INT, 0, 127, 64, 0, 0}, + {"TALK", F_TIME, 0, 127, 0, 0, 0}, + {"SHIFT", F_SEMI, -12, 12, 0, 0, 0}, + {"BUZZ", F_PCT, 0, 127, 64, 0, 0}, + {"BRTH", F_PCT, 0, 127, 10, 0, 0}, + {"Q", F_PCT, 0, 127, 64, 0, 0}, + {"RAND", F_PCT, 0, 127, 0, 0, 0}, + }, + FORMANT_PRESETS, sizeof(FORMANT_PRESETS) / sizeof(FORMANT_PRESETS[0]), 0, formant_note_on, formant_render, + 0xF81F, {P_E0, P_E4, P_E5, P_E2}, 4, +}; diff --git a/firmware/src/eng_grain.c b/firmware/src/eng_grain.c new file mode 100644 index 0000000..8085360 --- /dev/null +++ b/firmware/src/eng_grain.c @@ -0,0 +1,445 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* GRAIN: a granular engine over the SAMPLE material. Felucca's own design. + * + * Source: the SAMPLE sets (built in, IMA ADPCM in flash) and the user slots USR1..3 (XIP), the + * same zones across the keyboard as SAMPLE: a note picks its zone, its pitch sets the grain + * playback rate against the zone's root. Needs eng_sample.c (zones, ADPCM tables, pow2_q16). + * + * Decoding: no RAM copy of the source. Grains decode the ADPCM on demand from a seek index: the + * decoder state (predictor, step index) every GR_SEG = 256 source samples of every zone of the + * part's SRC, 3 bytes an entry (GR_NIDX entries a part: PERC, the biggest built-in set, needs + * ~1020; a full user slot ~650; zones past the capacity stay silent). A zone always starts at the + * state (0, 0), so zones index independently. The index is built in the block hook, one entry + * (256 decodes) per part and block, the zones of the sounding voices first: a 1 s zone is ready + * in ~60 ms, PERC (24 zones) in ~0.7 s. A grain starts at its exact sample: the state of the + * entry below, then up to 255 decodes skipped. A forward grain then decodes as it plays (one + * decode per source sample); a reverse grain reads a 128-sample window that it refills from the + * index as it moves down (about two decodes per source sample). A SRC change or a new upload into + * the slot (smp_user_gen) rebuilds the index. + * + * Grains: a pool of GR_NG per part, shared by its voices (each voice may hold its share of the + * pool: GR_NG / sounding voices, at least 2), at most GR_POLY voices. A grain: position, length + * (SIZE, 10..390 ms), rate (note, PITCH, a random detune), direction, a Hann window (table, linear + * interpolation) and a level 1 / sqrt(overlap). A voice starts its grains DENS times a second + * (1..98 /s; SPRD also jitters the interval); POS (0..100 % of the zone, + the track's SHP + * modulation: an LFO scans, ENV -> SHP sweeps) is the centre, SPRD the random spread around it + * (SPRD 0: a frozen position). RAND: the random detune (quadratic, up to +-1 octave) and the + * 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 + * (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 + * PHASE WIRE 1510, TRIO CHIP CHOIR 1455, WHEEL FULL ORGAN 1413 (8 keys, no sends). State: per part the grain pool, the reverse windows and the index + * (gr_p, in the pool section); per voice s[0] the zone, s[1] the countdown to the next grain, + * s[2] the low-pass, voice_t's phases are unused. */ +#define GR_POLY 3 /* voices per part */ +#define GR_NG 12 /* grains per part */ +#define GR_SEG_LOG2 8 +#define GR_SEG (1u << GR_SEG_LOG2) /* seek index interval, source samples */ +#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) */ + +/* sin^2(pi i / 256), Q15: the grain window */ +static const int16_t GR_HANN[257] = { + 0, 5, 20, 44, 79, 123, 177, 241, 315, 398, 491, 593, 705, 827, 958, 1098, + 1247, 1406, 1573, 1749, 1935, 2128, 2331, 2542, 2761, 2989, 3224, 3468, 3719, 3978, 4244, 4518, + 4799, 5086, 5381, 5682, 5990, 6304, 6624, 6950, 7281, 7618, 7961, 8308, 8660, 9017, 9379, 9744, + 10114, 10487, 10864, 11244, 11628, 12014, 12403, 12794, 13187, 13583, 13980, 14378, 14778, 15178, 15580, 15981, + 16383, 16786, 17187, 17589, 17989, 18389, 18787, 19184, 19580, 19973, 20364, 20753, 21139, 21523, 21903, 22280, + 22653, 23023, 23388, 23750, 24107, 24459, 24806, 25149, 25486, 25817, 26143, 26463, 26777, 27085, 27386, 27681, + 27968, 28249, 28523, 28789, 29048, 29299, 29543, 29778, 30006, 30225, 30436, 30639, 30832, 31018, 31194, 31361, + 31520, 31669, 31809, 31940, 32062, 32174, 32276, 32369, 32452, 32526, 32590, 32644, 32688, 32723, 32747, 32762, + 32767, 32762, 32747, 32723, 32688, 32644, 32590, 32526, 32452, 32369, 32276, 32174, 32062, 31940, 31809, 31669, + 31520, 31361, 31194, 31018, 30832, 30639, 30436, 30225, 30006, 29778, 29543, 29299, 29048, 28789, 28523, 28249, + 27968, 27681, 27386, 27085, 26777, 26463, 26143, 25817, 25486, 25149, 24806, 24459, 24107, 23750, 23388, 23023, + 22653, 22280, 21903, 21523, 21139, 20753, 20364, 19973, 19580, 19184, 18787, 18389, 17989, 17589, 17187, 16786, + 16384, 15981, 15580, 15178, 14778, 14378, 13980, 13583, 13187, 12794, 12403, 12014, 11628, 11244, 10864, 10487, + 10114, 9744, 9379, 9017, 8660, 8308, 7961, 7618, 7281, 6950, 6624, 6304, 5990, 5682, 5381, 5086, + 4799, 4518, 4244, 3978, 3719, 3468, 3224, 2989, 2761, 2542, 2331, 2128, 1935, 1749, 1573, 1406, + 1247, 1098, 958, 827, 705, 593, 491, 398, 315, 241, 177, 123, 79, 44, 20, 5, + 0, +}; +/* grain level by overlap (grains sounding at once on average): 1 / sqrt(n), Q15 */ +static const int16_t GR_NORM[GR_NG + 1] = {32767, 32767, 23170, 18918, 16384, 14654, 13377, + 12385, 11585, 10922, 10362, 9880, 9459}; + +typedef struct { + const smp_zone_t *z; + uint32_t pos; /* forward: the next sample to decode; reverse: the index of a */ + int32_t frac; /* Q16 between a and b */ + uint32_t step; /* Q16 source samples per output sample */ + uint32_t wph, winc; /* window phase: one turn = the grain */ + uint32_t left; /* output samples to go */ + int32_t a, b; /* the two source samples around the read position */ + int32_t pred, idx; /* ADPCM state (forward) */ + uint32_t rlo; /* reverse: the source index of rb[0] */ + int32_t gain; /* Q15 */ + uint8_t owner; /* voice index + 1, 0 = free */ + uint8_t rev; + uint8_t zl; /* its zone in the set */ +} gr_grain_t; + +typedef struct { + gr_grain_t g[GR_NG]; + int16_t rb[GR_NG][GR_RB]; /* reverse windows */ + int16_t ipred[GR_NIDX]; /* seek index: the state before sample k * GR_SEG of a zone */ + uint8_t iidx[GR_NIDX]; + uint16_t zbase[GR_MAXZ], zcnt[GR_MAXZ], zdone[GR_MAXZ]; /* entries of a zone: first, all, built */ + uint32_t stamp; /* what the index was built for (user slots: smp_user_gen) */ + int32_t rng; + uint8_t src; /* SRC + 1 the index holds, 0 = none */ + uint8_t nz; +} gr_part_t; +static gr_part_t gr_p[NPART] __attribute__((section(".pool"))); + +static uint32_t gr_part(const track_t *t) { return (uint32_t)(t - trk) % NPART; } +static uint32_t gr_nz(uint32_t src) { return src < SMP_NSETS ? SMP_SETS[src].nz : usr_nz[(src - SMP_NSETS) % SMP_USER_SLOTS]; } +static const smp_zone_t *gr_zone(uint32_t src, uint32_t zl) +{ + return src < SMP_NSETS ? &SMP_ZONES[SMP_SETS[src].z0 + zl] : &usr_zone[(src - SMP_NSETS) % SMP_USER_SLOTS][zl & 15u]; +} +static uint32_t gr_stamp(uint32_t src) +{ + return src < SMP_NSETS ? 0u : usr_nz[(src - SMP_NSETS) % SMP_USER_SLOTS] ? smp_user_gen : 0xFFFFFFFFu; +} +static inline uint32_t gr_rnd(gr_part_t *P) { return noise32(&P->rng); } +static inline uint32_t gr_scale(uint32_t n, uint32_t f16) { return (n >> 16) * f16 + (((n & 0xFFFFu) * f16) >> 16); } + +/* one IMA ADPCM sample of zone z at index pos */ +static inline int32_t gr_dec(const smp_zone_t *z, uint32_t pos, int32_t *pred, int32_t *idx) +{ + uint32_t b = SMP_DATA[z->off + (pos >> 1)], code = (pos & 1u) ? (b >> 4) : (b & 15u); + int32_t step = IMA_STEP[*idx], vd = step >> 3; + if (code & 4u) + vd += step; + if (code & 2u) + vd += step >> 1; + if (code & 1u) + vd += step >> 2; + *pred = clamp(*pred + ((code & 8u) ? -vd : vd), -32768, 32767); + *idx = clamp(*idx + IMA_IDX[code & 7u], 0, 88); + return *pred; +} + +/* the zone of a note (as SAMPLE: the last zone that holds it; a built-in set falls back to its + * first zone, a user slot stays silent), -1 = none */ +static int32_t gr_find(uint32_t src, uint32_t note) +{ + uint32_t i, nz = gr_nz(src); + int32_t zl = src < SMP_NSETS ? 0 : -1; + for (i = 0; i < nz && i < GR_MAXZ; i++) { + const smp_zone_t *z = gr_zone(src, i); + if (note >= z->lo && note <= z->hi) + zl = (int32_t)i; + } + return zl; +} + +static void gr_reset(gr_part_t *P, uint32_t src, uint32_t stamp) +{ + uint32_t i, tot = 0, nz = gr_nz(src); + P->src = (uint8_t)(src + 1u); + P->stamp = stamp; + P->nz = (uint8_t)(nz < GR_MAXZ ? nz : GR_MAXZ); + for (i = 0; i < GR_NG; i++) + P->g[i].owner = 0; + for (i = 0; i < P->nz; i++) { + uint32_t c = (gr_zone(src, i)->n + GR_SEG - 1u) >> GR_SEG_LOG2; + if (tot + c > GR_NIDX) + c = 0; /* past the capacity: silent */ + P->zbase[i] = (uint16_t)tot; + P->zcnt[i] = (uint16_t)c; + P->zdone[i] = c ? 1u : 0u; + if (c) { + P->ipred[tot] = 0; /* a zone starts at the state (0, 0) */ + P->iidx[tot] = 0; + } + tot += c; + } +} + +/* one index entry: the zone of a sounding voice first, else the first one not done */ +static void gr_build(gr_part_t *P, const track_t *t) +{ + uint32_t i, zl = GR_MAXZ, k, e, pos; + int32_t pred, idx; + const smp_zone_t *z; + for (i = 0; i < GR_POLY && zl == GR_MAXZ; i++) { + int32_t vz = t->v[i].s[0]; + if (t->v[i].active && vz >= 0 && vz < P->nz && P->zdone[vz] < P->zcnt[vz]) + zl = (uint32_t)vz; + } + for (i = 0; i < P->nz && zl == GR_MAXZ; i++) + if (P->zdone[i] < P->zcnt[i]) + zl = i; + if (zl == GR_MAXZ) + return; + z = gr_zone(P->src - 1u, zl); + k = P->zdone[zl]; + e = P->zbase[zl] + k - 1u; + pred = P->ipred[e]; + idx = P->iidx[e]; + pos = (k - 1u) << GR_SEG_LOG2; + for (i = 0; i < GR_SEG; i++) + gr_dec(z, pos + i, &pred, &idx); + P->ipred[e + 1u] = (int16_t)pred; + P->iidx[e + 1u] = (uint8_t)idx; + P->zdone[zl] = (uint16_t)(k + 1u); +} + +/* the decoder at sample p of zone zl (p's entry must be built) */ +static void gr_seek(const gr_part_t *P, const smp_zone_t *z, uint32_t zl, uint32_t p, int32_t *pred, int32_t *idx) +{ + uint32_t e = P->zbase[zl] + (p >> GR_SEG_LOG2), q; + *pred = P->ipred[e]; + *idx = P->iidx[e]; + for (q = p & ~(GR_SEG - 1u); q < p; q++) + gr_dec(z, q, pred, idx); +} + +/* reverse: decode [hi - GR_RB + 1, hi] into the grain's window */ +static void gr_fill(const gr_part_t *P, gr_grain_t *g, int16_t *rb, uint32_t zl, uint32_t hi) +{ + uint32_t lo = hi >= GR_RB - 1u ? hi - (GR_RB - 1u) : 0u, q; + int32_t pred, idx; + gr_seek(P, g->z, zl, lo, &pred, &idx); + for (q = lo; q <= hi; q++) + rb[q - lo] = (int16_t)gr_dec(g->z, q, &pred, &idx); + g->rlo = lo; +} + +/* 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) +{ + const int16_t *p = t->p; + const smp_zone_t *z = gr_zone(P->src - 1u, zl); + gr_grain_t *g = 0; + uint32_t i, n = z->n, len, step, span, c, sp, r1 = gr_rnd(P), r2 = gr_rnd(P), ov, rev; + int32_t d16, amt, posq, pos; + for (i = 0; i < GR_NG && !g; i++) + if (!P->g[i].owner) + g = &P->g[i]; + if (!g || n < 8u || !P->zcnt[zl]) + return; + /* length: 441 * 2^(SIZE / 24) output samples (10 ms .. 390 ms) */ + len = (441u * pow2_q16(p[P_E2] * 8)) >> 16; + /* 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 = 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 */ + if (span + 3u > n) { /* a short zone: shorter grain */ + span = n - 3u; + len = (span << 8) / (step >> 8); + } + if (len < 16u) + return; + /* position: POS (+ the SHP modulation) is the centre, SPRD the random spread */ + posq = clamp((p[P_E1] << 8) + m->shape - (64 << 8), 0, 127 << 8); + c = gr_scale(n - 1u, (uint32_t)posq * 65535u / (127u << 8)); + sp = gr_scale(n, (uint32_t)p[P_E5] * 516u); + pos = (int32_t)c + (int32_t)gr_scale(sp, r2 & 0xFFFFu) - (int32_t)(sp >> 1); + if (rev) + pos = clamp(pos, (int32_t)span, (int32_t)n - 2); + else + pos = clamp(pos, 0, (int32_t)(n - 3u - span)); + if ((uint32_t)pos >> GR_SEG_LOG2 >= P->zdone[zl]) + return; /* not indexed yet */ + 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) + return; + g->z = z; + g->step = step; + g->frac = 0; + g->wph = 0; + g->winc = 0xFFFFFFFFu / len; + g->left = len; + g->rev = (uint8_t)rev; + g->zl = (uint8_t)zl; + ov = len / (iv ? iv : 1u); + g->gain = GR_NORM[ov < 1u ? 1u : ov > GR_NG ? GR_NG : ov]; + g->owner = (uint8_t)(vi + 1u); + if (rev) { + int16_t *rb = P->rb[g - P->g]; + g->pos = (uint32_t)pos; + gr_fill(P, g, rb, zl, (uint32_t)pos + 1u); + g->a = rb[g->pos - g->rlo]; + g->b = rb[g->pos + 1u - g->rlo]; + } else { + gr_seek(P, z, zl, (uint32_t)pos, &g->pred, &g->idx); + g->a = gr_dec(z, (uint32_t)pos, &g->pred, &g->idx); + g->b = gr_dec(z, (uint32_t)pos + 1u, &g->pred, &g->idx); + g->pos = (uint32_t)pos + 2u; + } +} + +static inline int32_t gr_win(uint32_t wph) /* the Hann window, Q15 */ +{ + uint32_t wi = wph >> 24; + return GR_HANN[wi] + (((GR_HANN[wi + 1u] - GR_HANN[wi]) * (int32_t)((wph >> 9) & 0x7FFFu)) >> 15); +} + +/* one grain into acc; returns 0 when it ended. The window (times the grain's level) is a + * linear ramp over the block between its exact values at the block's ends. */ +static int gr_run(gr_part_t *P, gr_grain_t *g, int32_t *acc, uint32_t n) +{ + uint32_t i, m = n < g->left ? n : g->left, step = g->step, pos = g->pos; + int32_t a = g->a, b = g->b, frac = g->frac, w0, w1, wq, dq; + const smp_zone_t *z = g->z; + w0 = mulq15(gr_win(g->wph), g->gain); + g->wph += g->winc * m; + g->left -= m; + w1 = g->left ? mulq15(gr_win(g->wph), g->gain) : 0; + wq = w0 * 1024; + dq = m == CTL ? ((w1 - w0) * 1024) >> CTL_LOG2 : m ? (w1 - w0) * 1024 / (int32_t)m : 0; + if (!g->rev) { + int32_t pred = g->pred, idx = g->idx; + for (i = 0; i < m; i++) { + int32_t s = a + (((b - a) * (frac >> 1)) >> 15); + acc[i] += (s * (wq >> 10)) >> 15; + wq += dq; + frac += (int32_t)step; + while (frac >= 65536) { + frac -= 65536; + a = b; + b = pos < z->n ? gr_dec(z, pos++, &pred, &idx) : a; + } + } + g->pred = pred; + g->idx = idx; + } else { + int16_t *rb = P->rb[g - P->g]; + for (i = 0; i < m; i++) { + int32_t s = a + (((b - a) * (frac >> 1)) >> 15); + acc[i] += (s * (wq >> 10)) >> 15; + wq += dq; + frac -= (int32_t)step; + while (frac < 0) { + frac += 65536; + b = a; + if (pos) { /* (fitted: always) */ + pos--; + if (pos < g->rlo) + gr_fill(P, g, rb, g->zl, pos); + } + a = rb[pos - g->rlo]; + } + } + } + g->pos = pos; + g->a = a; + g->b = b; + g->frac = frac; + if (!g->left) + g->owner = 0; + return g->left != 0; +} + +static void grain_note_on(track_t *t, voice_t *v) +{ + gr_part_t *P = &gr_p[gr_part(t)]; + uint32_t vi = (uint32_t)(v - t->v) % NVOICE, i; + v->s[0] = gr_find((uint32_t)t->p[P_E0] % SMP_NALL, v->note); + v->s[1] = 0; /* the first grain at once */ + if (!v->env) { /* a fresh voice: no grains left from before */ + for (i = 0; i < GR_NG; i++) + if (P->g[i].owner == vi + 1u) + P->g[i].owner = 0; + v->s[2] = 0; + } +} + +/* per part and block: the index follows SRC (and a new upload), grains of ended voices go, + * one index entry is built */ +static void grain_block(track_t *t) +{ + gr_part_t *P = &gr_p[gr_part(t)]; + uint32_t src = (uint32_t)t->p[P_E0] % SMP_NALL, st = gr_stamp(src), i; + if (!P->rng) + P->rng = 0x2545F491; + if (P->src != src + 1u || P->stamp != st) { + gr_reset(P, src, st); + for (i = 0; i < NVOICE; i++) + if (t->v[i].active) + t->v[i].s[0] = gr_find(src, t->v[i].note); + } + 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; + gr_build(P, t); +} + +static void grain_render(track_t *t, voice_t *v, int32_t *out, uint32_t n, const vmod_t *m) +{ + gr_part_t *P = &gr_p[gr_part(t)]; + const int16_t *p = t->p; + uint32_t vi = (uint32_t)(v - t->v) % NVOICE, i, mine = 0, nact = 0, iv; + int32_t zl = v->s[0], acc[CTL], lp, y = v->s[2]; + if (n > CTL) + n = CTL; + if (zl < 0 || zl >= P->nz || P->src != (uint32_t)p[P_E0] % SMP_NALL + 1u) { + if (zl < 0) + v->active = 0; /* a user slot key with no zone: silent */ + return; + } + for (i = 0; i < n; i++) + acc[i] = 0; + for (i = 0; i < GR_POLY; i++) + nact += t->v[i].active; + for (i = 0; i < GR_NG; i++) + if (P->g[i].owner == vi + 1u) + mine += gr_run(P, &P->g[i], acc, n); + /* the next grain: DENS a second, 1..98 /s (SPRD jitters the interval) */ + iv = (44100u * pow2_q16(-p[P_E3] * 10)) >> 16; + v->s[1] -= (int32_t)n; + if (v->s[1] <= 0) { + uint32_t r = gr_rnd(P); + int32_t j = (((int32_t)(r & 0xFFFFu) - 32768) * p[P_E5]) / 254; /* +-SPRD / 2, Q15 */ + 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)) + gr_spawn(P, t, vi, (uint32_t)zl, iv, m); + } + lp = 4000 + ((clamp((p[P_E7] << 8) + m->cutoff, 0, 127 << 8) * 28767) >> 15); + for (i = 0; i < n; i++) { + y += mulq15(clamp(clamp(acc[i], -65535, 65535) - y, -65535, 65535), lp); + out[i] += mulq15(mulq15(y, amp_at(m, i)), VOICE_FS) << 1; + } + v->s[2] = y; +} + +static const preset_t GRAIN_PRESETS[] = { + /* name, {SRC, POS, SIZE, DENS, PTCH, SPRD, RAND, TONE}, {A D S R}, fenv, mono. + * SRC: the SAMPLE sets (0 DUSTY piano, 2 VIBES, 5 FLUTE...: tools/gen_samples.py CC0_SETS) */ + {"LOFI CLOUD", {0, 45, 95, 85, 0, 35, 12, 80}, {70, 90, 120, 90}, 0, 0, FX(0, 45, 20, 70)}, + {"VIBE HAZE", {2, 30, 100, 90, 0, 25, 10, 90}, {50, 100, 120, 95}, 0, 0, FX(0, 40, 25, 75)}, + {"FLUTE DUST", {5, 50, 108, 72, 0, 10, 10, 85}, {50, 100, 127, 100}, 0, 0, FX(0, 30, 20, 70)}, +}; + +static const engine_t ENG_GRAIN = { + "GRAIN", {"GRAN", "SPRY"}, + { + {"SRC", F_ENUM, 0, SMP_NALL - 1, 0, SMP_ALL_NAMES, 0}, + {"POS", F_PCT, 0, 127, 32, 0, 0}, + {"SIZE", F_PCT, 0, 127, 80, 0, 0}, + {"DENS", F_PCT, 0, 127, 80, 0, 0}, + {"PTCH", F_SEMI, -24, 24, 0, 0, 0}, + {"SPRD", F_PCT, 0, 127, 30, 0, 0}, + {"RAND", F_PCT, 0, 127, 10, 0, 0}, + {"TONE", F_PCT, 0, 127, 127, 0, 0}, + }, + GRAIN_PRESETS, sizeof(GRAIN_PRESETS) / sizeof(GRAIN_PRESETS[0]), 1, grain_note_on, grain_render, + 0x87F0, {P_E1, P_E2, P_E3, P_E5}, GR_POLY, 0, 0, grain_block, +}; diff --git a/firmware/src/eng_lofi.c b/firmware/src/eng_lofi.c new file mode 100644 index 0000000..eb2bc9a --- /dev/null +++ b/firmware/src/eng_lofi.c @@ -0,0 +1,226 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* Chip voice: pulse/triangle/saw/noise/wave RAM, quantised amplitude and a held + * (downsampled) output; SWEEP bends the pitch down after note-on. + * + * WAVE = WRAM plays a 32-sample, 4-bit wave table, read step-wise (no interpolation); + * DUTY then picks one of 16 built-in tables (DUTY / 8, shown as "WAV#" with its name). + * CHIP = STEP: a 4-bit stepped volume envelope with a frame-clock divider replaces the + * ADSR curve (lofi_amp), the triangle becomes a 32-step 4-bit staircase, the pulse + * duties are 12.5 / 25 / 50 / 75 %; CRSH then sets the envelope (shown as "DCY"). */ +static const char *const N_CHIP[] = {"4BIT", "4B/2", "8BIT", "1BIT", "STEP"}; +static const char *const N_RWAVE[] = {"PLS", "TRI", "SAW", "NOIS", "WRAM"}; +static const char *const N_RARP[] = {"OFF", "OCT", "MAJ", "MIN"}; +enum { CHIP_4BIT, CHIP_4B2, CHIP_8BIT, CHIP_1BIT, CHIP_STEP }; +enum { RW_PLS, RW_TRI, RW_SAW, RW_NOIS, RW_WRAM }; + +/* wave RAM: 16 tables x 32 samples x 4 bits, two samples a byte (high nibble first); + * our own shapes, from simple formulas (squares, sine, triangle, saws, harmonic sums, + * one formant peak for the vowels). DC is taken out per table in lofi_render. */ +static const char *const N_WRAM[] = {"SQ50", "SQ25", "SQ12", "SINE", "TRI", "SAW", "SAW2", "BAS1", + "BAS2", "ORGN", "HOLW", "VOXA", "VOXO", "VOXE", "BUZZ", "STAIR", 0}; +static const uint8_t WRAM[16][16] = { + {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* SQ50 */ + {0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* SQ25 */ + {0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* SQ12 */ + {0x89, 0xAC, 0xDE, 0xEF, 0xFF, 0xEE, 0xDC, 0xA9, 0x86, 0x53, 0x21, 0x10, 0x00, 0x11, 0x23, 0x56}, /* SINE */ + {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}, /* TRI */ + {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF}, /* SAW */ + {0x01, 0x12, 0x33, 0x45, 0x56, 0x77, 0x89, 0x9A, 0x56, 0x67, 0x88, 0x9A, 0xAB, 0xCC, 0xDE, 0xEF}, /* SAW2: + its octave */ + {0xEE, 0xEF, 0xFF, 0xFF, 0xFF, 0xEE, 0xED, 0xDC, 0x11, 0x10, 0x00, 0x00, 0x00, 0x11, 0x12, 0x23}, /* BAS1: sloped square */ + {0xCE, 0xFF, 0xED, 0xBA, 0x9A, 0xBD, 0xEF, 0xFE, 0xC9, 0x64, 0x21, 0x00, 0x00, 0x01, 0x24, 0x69}, /* BAS2: 1 + 2 + 3 */ + {0x8B, 0xEF, 0xED, 0xBA, 0x9A, 0xAA, 0x98, 0x77, 0x88, 0x87, 0x65, 0x55, 0x65, 0x42, 0x10, 0x14}, /* ORGN: 1..4 */ + {0x8D, 0xFE, 0xDD, 0xDD, 0xCD, 0xDD, 0xDE, 0xFD, 0x82, 0x01, 0x22, 0x22, 0x32, 0x22, 0x21, 0x02}, /* HOLW: odd */ + {0x8F, 0xFC, 0xA7, 0x67, 0x89, 0x88, 0x88, 0x87, 0x88, 0x77, 0x77, 0x76, 0x78, 0x98, 0x53, 0x00}, /* VOXA: "ah" */ + {0x8F, 0xEE, 0xFD, 0xDB, 0x98, 0x66, 0x66, 0x77, 0x88, 0x89, 0x99, 0x97, 0x64, 0x22, 0x01, 0x10}, /* VOXO: "oh" */ + {0x7F, 0x96, 0xCF, 0xBB, 0xCC, 0xBB, 0xAA, 0x98, 0x77, 0x65, 0x54, 0x43, 0x34, 0x40, 0x39, 0x60}, /* VOXE: "ee" */ + {0xF3, 0x00, 0x12, 0x22, 0x11, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22}, /* BUZZ: spike + ring */ + {0xFF, 0xFF, 0xFF, 0xFF, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0x00, 0x00, 0x00, 0x00}, /* STAIR: 4 levels */ +}; +#define Q4 2184 /* one 4-bit step (2 * 2184 * 7.5 = 32760) */ + +/* CHIP = STEP: CRSH as the envelope, CRSH / 4 = b: 0 constant volume, 1..16 a one-shot decay + * (divider period 0..15), 17..31 a looping one (period 1..15) */ +static const char *const N_DCY[] = {"CONST", "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7", "D8", "D9", "D10", + "D11", "D12", "D13", "D14", "D15", "L1", "L2", "L3", "L4", "L5", "L6", "L7", + "L8", "L9", "L10", "L11", "L12", "L13", "L14", "L15", 0}; +static const param_desc_t LOFI_WAVNUM = {"WAV#", F_INT, 0, 127, 64, N_WRAM, 0}; /* = edit[2] but the names */ +static const param_desc_t LOFI_DCY = {"DCY", F_INT, 0, 127, 0, N_DCY, 0}; /* = edit[3] but the names */ + +static const param_desc_t *lofi_desc(const track_t *t, uint32_t k) +{ + if (k == 2u && t->p[P_E1] == RW_WRAM) + return &LOFI_WAVNUM; + if (k == 3u && t->p[P_E0] == CHIP_STEP) + return &LOFI_DCY; + return 0; +} + +/* the stepped envelope: volume 15..0 in v->s[6] bits 0..3, its divider in bits 4..7, a 240 Hz + * frame clock (Q16 phase in v->s[7]); each frame the divider counts down and, at 0, reloads the + * period and takes one step off the volume (a looping one starts again at 15 after 0) */ +#define FRAME_Q16 ((240u * CTL * 65536u) / FS) /* frames per control tick, Q16 */ +static int32_t step_period(int32_t b) { return b <= 16 ? b - 1 : b - 16; } + +static void lofi_note_on(track_t *t, voice_t *v) +{ + v->s[0] = 0; /* held sample */ + v->s[1] = 0; /* hold counter */ + v->s[2] = 0x7FFF; /* LFSR */ + v->s[3] = 0; /* sweep, 1/16 st */ + v->s[4] = 0; /* 1-pole lp state */ + v->s[5] = 0; /* arp counter */ + v->s[6] = 15 | (step_period(t->p[P_E3] >> 2) & 15) << 4; /* stepped env: every note-on restarts it */ + v->s[7] = 0; +} + +/* CHIP = STEP: the voice amplitude is the stepped envelope, not the ADSR curve. The ADSR only + * gates: held, it is kept at full; after note-off the staircase keeps running (as the chip's + * envelope never sees a note-off) and the voice is cut when the ADSR release has fallen to 1 % + * (about the REL time; REL 0 cuts at once) or a one-shot decay has reached 0. */ +static int32_t lofi_amp(track_t *t, voice_t *v, int32_t adsr) +{ + int32_t b = t->p[P_E3] >> 2, vol = v->s[6] & 15, div = (v->s[6] >> 4) & 15; + if (t->p[P_E0] != CHIP_STEP) + return adsr; + if (!v->active) /* the ADSR ended it (or the voice was given up) */ + return 0; + if (v->stage == 3u) { + if (v->env < (1 << 24) / 100 || (b >= 1 && b <= 16 && !vol)) { + v->env = 0; + v->stage = 0; + v->active = 0; + return 0; + } + } else { + v->env = 1 << 24; /* the release starts from full */ + } + if (!b) + return 15 * Q4; + v->s[7] += (int32_t)FRAME_Q16; + while (v->s[7] >= 65536) { + v->s[7] -= 65536; + if (div) { + div--; + } else { + div = step_period(b); + if (vol) + vol--; + else if (b > 16) + vol = 15; + } + } + v->s[6] = vol | div << 4; + return vol * Q4; +} + +static void lofi_render(track_t *t, voice_t *v, int32_t *out, uint32_t n, const vmod_t *m) +{ + static const uint8_t STEP_DUTY[4] = {1, 2, 4, 6}; /* eighths: 12.5 / 25 / 50 / 75 % */ + const int16_t *p = t->p; + uint32_t chip = (uint32_t)p[P_E0], wave = (uint32_t)p[P_E1], i; + uint32_t stepc = chip == CHIP_STEP; + uint32_t duty = stepc ? 0x20000000u * STEP_DUTY[(p[P_E2] / 32) & 3] + : 0x20000000u * (1u + (uint32_t)p[P_E2] / 32u); /* 12.5 / 25 / 37.5 / 50 % */ + int32_t crush = stepc ? 0 : p[P_E3]; /* STEP: CRSH is the envelope */ + int32_t bits = chip == CHIP_8BIT ? 8 : chip == CHIP_1BIT ? 1 : 4; + int32_t hold = 1 + crush / 8 + (chip == 1u ? 1 : 0); + int32_t lpk = 3000 + (p[P_E7] << 8) + (m->cutoff > 0 ? m->cutoff : 0); + static const int8_t ARPS[4][3] = {{0, 0, 0}, {0, 12, 0}, {0, 4, 7}, {0, 3, 7}}; + int32_t ar = p[P_E6]; + int32_t pitch, held = v->s[0], cnt = v->s[1], lp = v->s[4]; /* state in locals: out[] may alias v->s[] */ + uint32_t inc, ph0 = v->ph[0], lfsr = (uint32_t)v->s[2]; + const uint8_t *wr = WRAM[((uint32_t)p[P_E2] >> 3) & 15u]; + int32_t wdc = 0; + if (wave == RW_WRAM) { /* the table's mean: no DC from lopsided shapes */ + int32_t sum = 0; + for (i = 0; i < 16u; i++) + sum += bits == 1 ? ((wr[i] >> 7) + ((wr[i] >> 3) & 1)) * 2 - 2 : (wr[i] >> 4) + (wr[i] & 15) - 15; + wdc = bits == 1 ? sum * 32767 / 32 : sum * 2 * Q4 / 32; /* (2 v - 15) Q4, or +-32767 at 1 bit */ + } + /* sweep down, vibrato (uses the track LFO through m->pitch16 already) */ + if (v->s[3] < 4096) /* past 2047 + an arp step the pitch is 0 anyway */ + v->s[3] += p[P_E4] / 8; + v->s[5]++; + pitch = m->pitch16 - v->s[3] + ARPS[ar & 3][(v->s[5] / 28) % 3] * 16; /* ~50 Hz, chip-style */ + inc = PITCH_INC[clamp(pitch, 0, 2047)]; + if (p[P_E5]) + inc += (uint32_t)(((int32_t)(inc >> 12) * (((osc_sine(v->ph[1]) >> 8) * p[P_E5]) >> 4)) >> 4); /* no overflow */ + v->ph[1] += 0x01000000u; + if (lpk > 32767) + lpk = 32767; + for (i = 0; i < n; i++) { + int32_t s; + if (--cnt <= 0) { + uint32_t q = bits < 16; /* quantise (the 4-bit tables are already) */ + cnt = hold; + switch (wave) { + case RW_TRI: + if (stepc) { /* 32 steps, 4 bits: 15..0, 0..15 */ + uint32_t k = ph0 >> 27; + s = (int32_t)(k < 16u ? 15u - k : k - 16u) * (2 * Q4) - 15 * Q4; + q = 0; + } else { + s = osc_tri(ph0); + } + break; + case RW_SAW: + s = (int32_t)(ph0 >> 16) - 32768; + break; + case RW_NOIS: { + uint32_t l = lfsr; + if ((ph0 + inc * (uint32_t)hold) < ph0 || chip == 3u) + l = (l >> 1) | (((l ^ (l >> 1)) & 1u) << 14); + lfsr = l; + s = (l & 1u) ? 32767 : -32768; + break; + } + case RW_WRAM: { /* step-wise, no interpolation */ + uint32_t k = ph0 >> 27, b = wr[k >> 1]; + b = (k & 1u) ? b & 15u : b >> 4; + s = (bits == 1 ? (b >= 8u ? 32767 : -32767) : ((int32_t)b * 2 - 15) * Q4) - wdc; + q = 0; + break; + } + default: /* minus its mean: no DC for narrow pulses */ + s = (ph0 < duty ? 32767 : -32768) - ((int32_t)(duty >> 16) - 32768); + break; + } + if (q) /* rounded, not floored (floor = DC) */ + s = ((s + (1 << (15 - bits))) >> (16 - bits)) << (16 - bits); + if (crush > 64) + s = (s >> 12) << 12; + held = s; + } + ph0 += inc; + lp += mulq15(clamp(held - lp, -65535, 65535), lpk); /* (a WAVE / CHIP change mid-note: no wrap) */ + out[i] += mulq15(mulq15(lp, amp_at(m, i)), VOICE_FS); + } + v->ph[0] = ph0; + v->s[0] = held; + v->s[1] = cnt; + v->s[2] = (int32_t)lfsr; + v->s[4] = lp; +} + +static const preset_t LOFI_PRESETS[] = { + {"GAME LEAD", {0, 0, 32, 0, 0, 20, 0, 127}, {0, 60, 90, 30}, 0, 1, FX(0, 0, 36, 18)}, + {"GB BASS", {1, 1, 0, 0, 0, 0, 0, 90}, {0, 50, 70, 20}, 0, 1, FX(0, 0, 6, 0), XP(P_TRANS + 1, -12)}, + {"8BIT ARP", {2, 0, 96, 0, 0, 0, 2, 110}, {0, 60, 80, 40}, 0, 0, FX(0, 0, 30, 20), ARP(1, 2, 2, 40)}, +}; + +static const engine_t ENG_LOFI = { + "LOFI", {"CHIP", "MOTN"}, + { + {"CHIP", F_ENUM, 0, 4, 0, N_CHIP, 0}, + {"WAVE", F_ENUM, 0, 4, 0, N_RWAVE, 0}, + {"DUTY", F_INT, 0, 127, 64, 0, 0}, /* WRAM: the table, DUTY / 8 (lofi_desc) */ + {"CRSH", F_PCT, 0, 127, 0, 0, 0}, /* STEP: the envelope (lofi_desc) */ + {"SWP", F_PCT, 0, 127, 0, 0, 0}, + {"VIB", F_PCT, 0, 127, 0, 0, 0}, + {"ARP", F_ENUM, 0, 3, 0, N_RARP, 0}, + {"TONE", F_PCT, 0, 127, 127, 0, 0}, + }, + LOFI_PRESETS, sizeof(LOFI_PRESETS) / sizeof(LOFI_PRESETS[0]), 1, lofi_note_on, lofi_render, + 0x3F2C, {P_E1, P_E2, P_E3, P_REL}, 0, lofi_amp, lofi_desc, +}; diff --git a/firmware/src/eng_phase.c b/firmware/src/eng_phase.c new file mode 100644 index 0000000..1ec57f1 --- /dev/null +++ b/firmware/src/eng_phase.c @@ -0,0 +1,195 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* Phase distortion. The waveforms are a C port of the oscillator of + * CrispyZebra (Leo Kuroshita, GPL-3.0, github.com/hugelton/CrispyZebra), the + * author's own phase-distortion core: a -cos table read through a bent phase whose + * bend is DCW. WAVE2 alternates with WAVE every other cycle. A second + * line (DTN) can be mixed or ring-modulated; SUB adds a sine an octave down. + * Envelopes are Felucca's own (ADSR, ENV -> DCW). */ +static const char *const N_PD_WAVE[] = {"SAW", "SQR", "PLS", "DSIN", "SPLS", "RSAW", "RTRI", "RTRP"}; +static const char *const N_PD_WAVE2[] = {"-", "SAW", "SQR", "PLS", "DSIN", "SPLS", "RSAW", "RTRI", "RTRP"}; +static const char *const N_PD_LINE[] = {"MIX", "RING"}; + +static inline int32_t pd_cos(uint32_t ph16) /* -cos, Q15, from the 16-bit PD phase */ +{ + return -sine_i(((ph16 & 0xFFFFu) << 16) + 0x40000000u); +} + +/* one wave's bend for a block: break points and the slopes of the bent phase + * (Q16 reciprocals), so a sample costs a multiply instead of a divide (the + * bent phase comes out the same or 1 lower in 65536) */ +typedef struct { + uint32_t w, x, peak, rez; + uint32_t k0, k1; +} pd_t; + +static inline uint32_t pd_slope(uint32_t span, uint32_t len) { return (span << 16) / (len ? len : 1u); } + +static void pd_setup(pd_t *b, uint32_t w, uint32_t dcw) +{ + uint32_t x; + b->w = w; + switch (w) { + case 0: /* SAW */ + x = 32768u + ((dcw * 32767u) >> 16); + b->k0 = pd_slope(32768u, x); + b->k1 = pd_slope(32767u, 65535u - x); + break; + case 1: /* SQUARE */ + x = 32768u - ((dcw * 31120u) >> 16); + b->k0 = pd_slope(32768u, x); + b->k1 = pd_slope(32767u, x); + break; + case 2: /* PULSE */ + x = 65535u - ((dcw * 63487u) >> 16); + b->k0 = pd_slope(65535u, x); + break; + case 3: /* DOUBLE SINE */ + x = 65535u - ((dcw * 49151u) >> 16); + b->k0 = pd_slope(65535u, x); + b->k1 = pd_slope(65535u, 65535u - x); + break; + case 4: /* SAW-PULSE */ + x = 65535u - ((dcw * 32767u) >> 16); + b->peak = (x * (32768u + ((dcw * 29491u) >> 16))) >> 16; + if (!b->peak) + b->peak = 1; + b->k0 = pd_slope(32768u, b->peak); + b->k1 = pd_slope(32767u, x - b->peak); + break; + default: /* RESONANCE */ + x = 0; + b->rez = (dcw * 44000u) >> 16; + break; + } + b->x = x; +} + +/* one sample at phase ph (16 bit): bipolar Q15 */ +static int32_t pd_wave(const pd_t *b, uint32_t ph) +{ + uint32_t pd, x = b->x; + switch (b->w) { + case 0: /* SAW */ + pd = ph < x ? (ph * b->k0) >> 16 : 32768u + (((ph - x) * b->k1) >> 16); + break; + case 1: /* SQUARE */ + if (ph < x) + pd = (ph * b->k0) >> 16; + else if (ph < 32768u) + pd = 32768u; + else if (ph < 32768u + x) + pd = 32768u + (((ph - 32768u) * b->k1) >> 16); + else + pd = 65535u; + break; + case 2: /* PULSE */ + pd = ph < x ? (ph * b->k0) >> 16 : 65535u; + break; + case 3: /* DOUBLE SINE */ + pd = ph < x ? (ph * b->k0) >> 16 : ((ph - x) * b->k1) >> 16; + break; + case 4: /* SAW-PULSE */ + if (ph >= x) + pd = 65535u; + else if (ph < b->peak) + pd = (ph * b->k0) >> 16; + else + pd = 32768u + (((ph - b->peak) * b->k1) >> 16); + break; + default: { /* RESONANCE: windowed sine, rez = pitch of the core */ + uint32_t rp = (ph + ((ph * b->rez) >> 16) * 7u) & 0xFFFFu, win; + int32_t core = (pd_cos(rp) * 5) >> 3; + if (b->w == 5) + win = 65535u - ph; /* saw window */ + else if (b->w == 6) + win = ph < 32768u ? ph << 1 : (65535u - ph) << 1; /* triangle window */ + else + win = ph < 16384u ? ph << 2 : ph > 49152u ? (65535u - ph) << 2 : 65535u; /* trapezoid */ + if (win > 65535u) + win = 65535u; + return (core * (int32_t)win) >> 16; /* |core| <= 20479: fits 32 bits */ + } + } + return pd_cos(pd); +} + +static void phase_note_on(track_t *t, voice_t *v) +{ + (void)t; + v->ph[1] = 0; + v->ph[2] = 0; + v->s[0] = 0; /* WAVE / WAVE2 toggle, line 1 */ + v->s[1] = 0; /* line 2 */ +} + +static void phase_render(track_t *t, voice_t *v, int32_t *out, uint32_t n, const vmod_t *m) +{ + const int16_t *p = t->p; + uint32_t w1 = (uint32_t)p[P_E0] & 7u, w2 = (uint32_t)p[P_E1], i; + int32_t depth = (p[P_E2] << 8) + m->cutoff + mulq15(m->envq15, p[P_E3] * 256); + uint32_t dcw, inc = m->inc, inc2; + int32_t det = p[P_E4], line2 = det != 0 || p[P_E5], ring = p[P_E5], sub = p[P_E6] * 200; + int32_t d16 = det * 16 / 100, rem = det * 16 - d16 * 100; + uint32_t ph0 = v->ph[0], ph1 = v->ph[1], ph2 = v->ph[2]; + int32_t tg0 = v->s[0], tg1 = v->s[1]; /* WAVE / WAVE2 toggles */ + pd_t b1, b2; + depth = clamp(depth + (m->shape - (64 << 8)), 0, 127 << 8); + dcw = (uint32_t)depth * 65535u / (127u << 8); + dcw = (dcw * 56000u) >> 16; /* the classic range of the bend */ + inc2 = PITCH_INC[clamp(m->pitch16 + d16, 0, 2047)]; + inc2 += (uint32_t)((int32_t)(inc2 >> 12) * (rem * 2367 / 16000)); + pd_setup(&b1, w1, dcw); + pd_setup(&b2, w2 ? w2 - 1u : w1, dcw); /* WAVE2 (every other cycle) */ + for (i = 0; i < n; i++) { + uint32_t old = ph0; + int32_t s; + s = pd_wave(tg0 ? &b2 : &b1, ph0 >> 16); + ph0 += inc; + if (ph0 < old) + tg0 ^= 1; + if (line2) { + uint32_t old2 = ph1; + int32_t s2 = pd_wave(tg1 ? &b2 : &b1, ph1 >> 16); + ph1 += inc2; + if (ph1 < old2) + tg1 ^= 1; + s = ring ? mulq15(s, s2) : (s + s2) >> 1; /* both within +-32767 */ + } + if (sub) { + ph2 += inc >> 1; + s += mulq15(osc_sine(ph2), sub); + } + out[i] += mulq15(mulq15(s, amp_at(m, i)), VOICE_FS) << 1; + } + v->ph[0] = ph0; + v->ph[1] = ph1; + v->ph[2] = ph2; + v->s[0] = tg0; + v->s[1] = tg1; +} + +static const preset_t PHASE_PRESETS[] = { + /* name, {WAVE, WAVE2, DCW, ENV, DTN, LINE, SUB, -}, {A D S R}, fenv, mono */ + {"CZ BASS", {5, 0, 28, 70, 0, 0, 40, 0}, {0, 60, 50, 22}, 0, 1, FX(5, 0, 0, 4), XP(P_GLIDE + 1, 36, P_TRANS + 1, -24)}, + {"SOFT KEYS", {3, 0, 40, 70, 0, 0, 0, 0}, {0, 80, 20, 50}, 0, 0, FX(0, 35, 14, 28)}, + {"CZ STRING", {0, 4, 50, 40, 12, 0, 0, 0}, {50, 90, 105, 75}, 0, 0, FX(0, 50, 20, 55)}, + {"RESO PLUCK", {5, 0, 60, 60, 0, 0, 0, 0}, {0, 70, 30, 60}, 0, 0, FX(0, 0, 30, 30)}, + {"CZ BRASS", {0, 0, 30, 90, 0, 0, 0, 0}, {8, 70, 90, 40}, 0, 0, FX(0, 20, 14, 26)}, +}; + +static const engine_t ENG_PHASE = { + "PHASE", {"PHS", "LINE"}, + { + {"WAVE", F_ENUM, 0, 7, 0, N_PD_WAVE, 0}, + {"WAVE2", F_ENUM, 0, 8, 0, N_PD_WAVE2, 0}, + {"DCW", F_PCT, 0, 127, 60, 0, 0}, + {"ENV", F_PCT, 0, 127, 64, 0, 0}, + {"DTN", F_INT, 0, 127, 0, 0, "ct"}, + {"LINE", F_ENUM, 0, 1, 0, N_PD_LINE, 0}, + {"SUB", F_PCT, 0, 127, 0, 0, 0}, + {"-", F_INT, 0, 0, 0, 0, 0}, + }, + PHASE_PRESETS, sizeof(PHASE_PRESETS) / sizeof(PHASE_PRESETS[0]), 0, phase_note_on, phase_render, + 0x05DF, {P_E2, P_E3, P_E4, P_REL}, +}; diff --git a/firmware/src/eng_sample.c b/firmware/src/eng_sample.c new file mode 100644 index 0000000..af86990 --- /dev/null +++ b/firmware/src/eng_sample.c @@ -0,0 +1,216 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* SAMPLE: IMA ADPCM sample sets. */ +static const char *const N_ONOFF_E[] = {"OFF", "ON"}; +/* IMA ADPCM sample sets (tools/gen_samples.py), native rates, zones across + * the keyboard, loops with the ADPCM state stored at the loop start. + * SET is P_E0 (EDIT 1, KNOB 1). */ +typedef struct { + uint32_t off, n, ls, le; /* byte offset, samples, loop start / end (sample index) */ + uint32_t rate; /* source rate / 44100, Q16 */ + int16_t root16; /* root pitch in 1/16 semitone */ + int16_t pred; /* ADPCM state at the loop start */ + uint8_t idx, lo, hi, looped; +} smp_zone_t; +typedef struct { + const char *name; + uint16_t z0, nz; +} smp_set_t; +#include "felucca_samples.h" + +static const int16_t IMA_STEP[89] = { + 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 19, 21, 23, 25, 28, 31, 34, 37, 41, 45, 50, 55, 60, 66, 73, 80, 88, 97, + 107, 118, 130, 143, 157, 173, 190, 209, 230, 253, 279, 307, 337, 371, 408, 449, 494, 544, 598, 658, 724, 796, + 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066, 2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, + 4871, 5358, 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899, 15289, 16818, 18500, 20350, + 22385, 24623, 27086, 29794, 32767}; +static const int8_t IMA_IDX[8] = {-1, -1, -1, -1, 2, 4, 6, 8}; +/* 2^(i/192), Q16: pitch ratios in 1/16 semitones, d16 >= -3072 (16 octaves down) */ +static uint32_t pow2_q16(int32_t d16) +{ + uint32_t u = (uint32_t)(d16 + 192 * 16), oct = u / 192u; /* no loop for negative d16 */ + uint32_t r = PITCH_INC[1600 + u % 192u] / (PITCH_INC[1600] >> 16); /* 2^(d/192) via the pitch table */ + return oct >= 16u ? r << (oct - 16u) : r >> (16u - oct); +} + +/* ---- user sample slots (loaded from the web editor into flash, see web/EDITOR_PROTOCOL.md) + * 3 slots of 80 KiB at flash 0xA0000.. (Felucca data region), read through the plain XIP + * window. Slot = header (magic, count, name, data length, CRC32) + up to 16 zones in the + * smp_zone_t layout (off relative to the slot's data at +512) + IMA ADPCM data. */ +#include "../hal/fm1_xip.h" /* relative: hostsim includes this file too */ +#define SMP_USER_SLOTS 3 +#define SMP_USER_BASE 0xA0000u +#define SMP_USER_SIZE 0x14000u +#define SMP_USER_DATA 512u +#define SMP_USER_MAGIC 0x504D5346u /* "FSMP" */ +#define SMP_NALL (SMP_NSETS + SMP_USER_SLOTS) +typedef struct { + uint32_t magic; + uint16_t version; + uint8_t nz, rsv; + char name[8]; + uint32_t data_len, crc, rsv2[2]; + smp_zone_t zone[16]; +} smp_user_hdr_t; /* 32 + 16 x 28 = 480 B, data at +512 */ +static smp_zone_t usr_zone[SMP_USER_SLOTS][16]; /* RAM copy, off rebased onto SMP_DATA */ +static uint8_t usr_nz[SMP_USER_SLOTS]; +static const char *const SMP_ALL_NAMES[SMP_NALL] = {SMP_SET_NAMES_INIT, "USR1", "USR2", "USR3"}; + +#ifndef SMP_USER_XIP /* host tests: a RAM image of the slots */ +#define SMP_USER_XIP(k) fm1_xip_ptr(SMP_USER_BASE + (k) * SMP_USER_SIZE) +#endif +static const uint8_t *smp_user_xip(uint32_t k) { return SMP_USER_XIP(k); } +#if FELUCCA_SLICE +static void slc_user_scan(uint32_t k, int valid); /* eng_slice.c: SLICE's slice table of the slot */ +#else +#define slc_user_scan(k, valid) ((void)0) +#endif +static uint32_t smp_user_gen; /* + 1 per slot scan (GRAIN: its seek index follows uploads) */ + +/* (re)read slot k from flash: valid header -> zones usable; call after boot and after an upload + * (main loop: SLICE scans the slot's audio here) */ +/* a zone of a slot header usable (inside the slot's data, well formed) */ +static int smp_zone_ok(const smp_zone_t *z, uint32_t data_len) +{ + return z->off <= data_len && z->n <= 2u * SMP_USER_SIZE && z->off + (z->n + 1u) / 2u <= data_len && + z->idx <= 88u && z->rate && z->rate <= 4u << 16 && z->ls <= z->le && z->le < z->n && z->lo <= z->hi; +} +static void smp_user_scan(uint32_t k) +{ + const smp_user_hdr_t *h = (const smp_user_hdr_t *)smp_user_xip(k); + static smp_zone_t zs[16]; + uint32_t i, base; + smp_user_gen++; + usr_nz[k] = 0; /* (from here no new voice takes the slot) */ + slc_user_scan(k, 0); + if (h->magic != SMP_USER_MAGIC || h->version != 1 || !h->nz || h->nz > 16u || + h->data_len > SMP_USER_SIZE - SMP_USER_DATA) + return; + base = (uint32_t)(uintptr_t)(smp_user_xip(k) + SMP_USER_DATA) - (uint32_t)(uintptr_t)SMP_DATA; + for (i = 0; i < h->nz; i++) { /* checked in a copy: a voice still playing the slot */ + zs[i] = h->zone[i]; /* never reads a zone that is not valid */ + if (!smp_zone_ok(&zs[i], h->data_len)) + return; /* zone outside the data or malformed: slot unusable */ + zs[i].off += base; + } + fm1_irq_off(); + for (i = 0; i < h->nz; i++) + usr_zone[k][i] = zs[i]; + usr_nz[k] = h->nz; + fm1_irq_on(); + slc_user_scan(k, 1); +} + +/* zone index in a voice: < 0x8000 built-in, else 0x8000 | slot << 5 | zone */ +static inline const smp_zone_t *smp_zone(uint32_t zi) +{ + return zi < 0x8000u ? &SMP_ZONES[zi] : &usr_zone[(zi >> 5) & 3u][zi & 31u]; +} + +/* 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 */ +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)]; + uint32_t code = (pos & 1u) ? (b >> 4) : (b & 15u); + int32_t step = IMA_STEP[(uint32_t)v->s[1] <= 88u ? v->s[1] : 88], vd = step >> 3; + if (code & 4u) + vd += step; + if (code & 2u) + vd += step >> 1; + if (code & 1u) + vd += step >> 2; + v->s[0] = clamp(v->s[0] + ((code & 8u) ? -vd : vd), -32768, 32767); + v->s[1] = clamp(v->s[1] + IMA_IDX[code & 7u], 0, 88); + pos++; + if (pos > z->le && z->looped && loop) { + pos = z->ls; + v->s[0] = z->pred; + v->s[1] = z->idx; + } + v->ph[0] = pos; + return v->s[0]; +} + +static void sample_note_on(track_t *t, voice_t *v) +{ + uint32_t si = (uint32_t)t->p[P_E0] % SMP_NALL, i, zi = 0xFFFFu; + if (si < SMP_NSETS) { + const smp_set_t *set = &SMP_SETS[si]; + for (i = 0; i < set->nz; i++) + if (v->note >= SMP_ZONES[set->z0 + i].lo && v->note <= SMP_ZONES[set->z0 + i].hi) + zi = set->z0 + i; + v->s[4] = (int32_t)(zi == 0xFFFFu ? set->z0 : zi); + } else { /* user slot: silent if empty */ + uint32_t k = si - SMP_NSETS; + for (i = 0; i < usr_nz[k]; i++) + if (v->note >= usr_zone[k][i].lo && v->note <= usr_zone[k][i].hi) + zi = 0x8000u | k << 5 | i; + v->s[4] = (int32_t)(zi == 0xFFFFu ? 0 : zi); + } + v->ph[0] = 0; + v->ph[1] = 0; + v->s[0] = 0; + v->s[1] = 0; + v->s[2] = v->s[3] = 0; + 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 */ +} + +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 */ + uint32_t r = pow2_q16(d16), stepq = (r >> 8) * (z->rate >> 8); /* Q16 samples per output */ + 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; + if (v->s[6] || !z->n) { + v->active = 0; + return; + } + 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++) { + int32_t s; + frac += stepq; + while (frac >= 65536u) { + frac -= 65536u; + v->s[2] = v->s[3]; + if (v->ph[0] >= z->n) { /* one-shot reached its end */ + v->s[6] = 1; + v->s[3] = 0; + break; + } + v->s[3] = sample_next(z, v, p[P_E3]); + } + s = v->s[2] + (((v->s[3] - v->s[2]) * (int32_t)(frac >> 1)) >> 15); + if (sh) /* BITS: 0 = clean, up to 12 bits removed */ + s = (s >> sh) << sh; + if (drv) + s = softclip(s + (((s >> 2) * (drv * 150)) >> 11)); /* = s * drv * 600 / 32768, no overflow */ + v->s[7] += mulq15(s - v->s[7], lp); /* gentle tone control (CUT) */ + out[i] += mulq15(mulq15(v->s[7], amp_at(m, i)), VOICE_FS) << 1; + if (v->s[6]) + break; + } + v->ph[1] = frac; +} + + +static const engine_t ENG_SAMPLE = { + "SAMPLE", {"SET", "TONE"}, + { + {"SET", F_ENUM, 0, SMP_NALL - 1, 0, SMP_ALL_NAMES, 0}, + {"TUNE", F_SEMI, -24, 24, 0, 0, 0}, + {"BITS", F_INT, 0, 127, 0, 0, 0}, + {"LOOP", F_ENUM, 0, 1, 1, N_ONOFF_E, 0}, + {"CUT", F_INT, 0, 127, 127, 0, 0}, + {"-", F_INT, 0, 0, 0, 0, 0}, + {"DRV", F_PCT, 0, 127, 0, 0, 0}, + {"-", F_INT, 0, 0, 0, 0, 0}, + }, + SMP_PRESET_TABLE, sizeof(SMP_PRESET_TABLE) / sizeof(SMP_PRESET_TABLE[0]), -1, sample_note_on, sample_render, + 0xFFFF, {P_E0, P_E4, P_ATK, P_REL}, +}; diff --git a/firmware/src/eng_slice.c b/firmware/src/eng_slice.c new file mode 100644 index 0000000..2b46aea --- /dev/null +++ b/firmware/src/eng_slice.c @@ -0,0 +1,417 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* SLICE: a sample slicer, played from the keys and the sequencer. Felucca's own design. + * + * Material (SRC): the built-in BREAK (tools/gen_samples.py: one bar of 16ths at 120 BPM arranged + * from Felucca's generated drums, stored after the SAMPLE sets) or a user slot USR1..3 (the same + * slots as SAMPLE's, eng_sample.c), whose zones are played one after the other as one recording + * (a zone that shares its data with an earlier one is skipped). An empty slot plays BREAK. + * + * Slices (DIV): 4 / 8 / 16 / 32 equal ones, or AUTO: one per onset. IMA ADPCM can only be entered + * at a known decoder state, so each source keeps a table (slc_src_t): the states at the 128 grid + * points k * len / 128 (every equal slice starts on one, and they are the reverse checkpoints) and + * up to 32 AUTO starts with their states. BREAK's table is written at build time (its hits are + * the AUTO slices); a user slot's is computed by slc_scan when the slot becomes valid + * (smp_user_scan: boot, upload end; main loop, never the audio ISR): two decoding passes; per hop + * of 32 samples the peak of the first difference (hats, snares, clicks stand out, a kick's tail + * does not) and the plain peak (low hits); an onset is a hop where either rises 1.75x over its + * follower (~23 ms / ~93 ms, so a low tone's cycles are no rises), above 1/12 (1/8) of its + * largest value, at least 50 ms after the last one; the slice starts one hop before the hop that + * rose (1.5..3 ms of pre-roll, never after the hit). RAM: 3 x 972 B of tables, 3 KiB of reverse + * windows; a full 7 s slot scans in ~0.3 M decoder steps. + * + * Playing: note n plays slice (n - 60 - ROOT + START) mod the slice count (the keys: the lowest + * key is slice 0, seq.c kb_map). Slices play at the source rate times PITCH (varispeed: faster is + * higher). MODE: ONE plays the slice to its end (a note-off does not stop it), GATE until the + * note-off (then the ADSR release) or the slice end, LOOP repeats the slice while the note is held. + * REV plays a slice backwards: windows of 64 samples are decoded forwards from the nearest + * checkpoint (grid point or the slice start) into the voice's own buffer and read from the top + * down; it costs about (len / 128) / 128 extra decodes per source sample (BREAK: ~3; a full + * 7 s user slot: ~10). DECAY: an exponential fade per slice (127 = none). TONE: a gentle low-pass + * (SAMPLE's CUT). The last ~1.5 ms of a slice fade out (no click at the cut), a new slice fades in + * over one block (0.7 ms). + * Voice state: ph[0] position (reverse: position + 1), ph[1] fraction Q16, ph[2] slice end (reverse: + * its start), s[0] predictor (reverse: window start), s[1] step index, s[2] / s[3] previous / current + * sample, s[4] source | segment << 2 | reverse << 6 | slice << 8 | DIV << 16, s[5] DECAY level Q15, + * s[6] 0 to prime, 1 playing, 3 fading out, 2 ended, s[7] low-pass. */ +#define SLC_GRID 128u /* grid points: decoder states at k * len / SLC_GRID */ +#define SLC_GRID_LOG2 7 +#define SLC_AUTO 32u /* AUTO slices at most */ +#define SLC_SEGS 16u /* zones of a user slot */ +#define SLC_RB 64u /* reverse: samples decoded per window */ +#define SLC_BASE 60 /* note of slice 0 (+ the track's ROOT) */ +#define SLC_HOP 32u /* AUTO detector: samples per hop */ + +typedef struct { + uint32_t off, at, n; /* data (SMP_DATA index), material position of its first sample, samples */ +} slc_seg_t; +typedef struct { + uint32_t len, rate, nseg, nauto; /* material samples (0 = none), rate (as smp_zone_t), segments, AUTO slices */ + slc_seg_t seg[SLC_SEGS]; + uint32_t grid[SLC_GRID]; /* decoder state before sample k * len / SLC_GRID: */ + /* (uint16_t)predictor | step index << 16 | segment << 24 */ + uint32_t apos[SLC_AUTO], ast[SLC_AUTO]; /* AUTO slice starts (apos[0] = 0) and their states */ +} slc_src_t; + +static const slc_src_t SLC_BREAK = SLC_BREAK_INIT; +static slc_src_t slc_usr[SMP_USER_SLOTS]; +static int16_t slc_rbuf[NPART][NVOICE][SLC_RB]; /* reverse windows, one per part voice */ +static const char *const N_SLC_SRC[] = {"BREAK", "USR1", "USR2", "USR3"}; +static const char *const N_SLC_DIV[] = {"4", "8", "16", "32", "AUTO"}; +static const char *const N_SLC_MODE[] = {"ONE", "GATE", "LOOP"}; +static const char *const N_SLC_REV[] = {"OFF", "ON"}; +enum { SLC_ONE, SLC_GATE, SLC_LOOP }; +#define SLC_DIV_AUTO 4u + +/* source 0 = BREAK, 1..3 = USR1..3; 0 = no material (an empty or erased slot) */ +static const slc_src_t *slc_get(uint32_t src) +{ + if (!src) + return SLC_BREAK.len ? &SLC_BREAK : 0; + src--; + return src < SMP_USER_SLOTS && usr_nz[src] && slc_usr[src].len ? &slc_usr[src] : 0; +} + +/* ---- the ADPCM decoder over the material (segments one after the other, each from 0 / 0) */ +typedef struct { + int32_t pred, idx; + uint32_t pos, seg; +} slc_dec_t; +static inline void slc_dec_at(slc_dec_t *d, uint32_t pos, uint32_t st) +{ + d->pos = pos; + d->pred = (int16_t)(st & 0xFFFFu); + d->idx = (int32_t)((st >> 16) & 127u); + d->seg = st >> 24; +} +static inline uint32_t slc_dec_st(const slc_dec_t *d) +{ + return (uint32_t)(uint16_t)d->pred | (uint32_t)d->idx << 16 | d->seg << 24; +} +/* the sample at d->pos (< len), then the next position */ +static inline int32_t slc_dec_next(const slc_src_t *s, slc_dec_t *d) +{ + const slc_seg_t *g = &s->seg[d->seg]; + uint32_t rel = d->pos - g->at, b, code; + int32_t step, vd; + if (rel >= g->n && d->seg + 1u < s->nseg) { /* into the next zone: its data starts from 0 / 0 */ + d->seg++; + g++; + rel = d->pos - g->at; + d->pred = 0; + d->idx = 0; + } + b = SMP_DATA[g->off + (rel >> 1)]; + code = (rel & 1u) ? (b >> 4) : (b & 15u); + step = IMA_STEP[d->idx]; + vd = step >> 3; + if (code & 4u) + vd += step; + if (code & 2u) + vd += step >> 1; + if (code & 1u) + vd += step >> 2; + d->pred = clamp(d->pred + ((code & 8u) ? -vd : vd), -32768, 32767); + d->idx = clamp(d->idx + IMA_IDX[code & 7u], 0, 88); + d->pos++; + return d->pred; +} + +static inline uint32_t slc_gpos(const slc_src_t *s, uint32_t k) { return (k * s->len) >> SLC_GRID_LOG2; } +static uint32_t slc_count(const slc_src_t *s, uint32_t div) { return div < SLC_DIV_AUTO ? 4u << div : s->nauto; } + +/* slice j of DIV div: [*a, *b), *st the state at *a */ +static void slc_bounds(const slc_src_t *s, uint32_t div, uint32_t j, uint32_t *a, uint32_t *b, uint32_t *st) +{ + if (div < SLC_DIV_AUTO) { + uint32_t w = SLC_GRID >> (2u + div); + *a = slc_gpos(s, j * w); + *b = slc_gpos(s, (j + 1u) * w); + *st = s->grid[j * w]; + } else { + j = j < s->nauto ? j : s->nauto - 1u; + *a = s->apos[j]; + *b = j + 1u < s->nauto ? s->apos[j + 1u] : s->len; + *st = s->ast[j]; + } +} +static void slc_bounds_v(const slc_src_t *s, const voice_t *v, uint32_t *a, uint32_t *b, uint32_t *st) +{ + uint32_t pk = (uint32_t)v->s[4]; + slc_bounds(s, (pk >> 16) & 7u, (pk >> 8) & 63u, a, b, st); +} + +/* ---- the slice table of a user slot (main loop) */ +/* the grid states and the AUTO slices of s (len samples; s->len stays 0 meanwhile): see the top */ +static void slc_scan(slc_src_t *s, uint32_t len) +{ + slc_dec_t d; + uint32_t pos = 0, k = 0, gap = ((s->rate >> 4) * 44100u >> 12) / 20u, last = 0, h0 = 0, st0 = 0; + int32_t prev = 0, pkd = 0, pkr = 0, envd = 0, envr = 0, thd, thr; + slc_dec_at(&d, 0, 0); + while (pos++ < len) { /* pass 1: the largest step and sample */ + int32_t x = slc_dec_next(s, &d), a = x - prev; + a = a < 0 ? -a : a; + pkd = a > pkd ? a : pkd; + a = x < 0 ? -x : x; + pkr = a > pkr ? a : pkr; + prev = x; + } + thd = pkd / 12; + thr = pkr / 8; + s->nauto = 1; + s->apos[0] = 0; + s->ast[0] = 0; + slc_dec_at(&d, 0, 0); + prev = 0; + for (pos = 0; pos < len;) { /* pass 2: grid states, onsets */ + uint32_t hs = pos, hst = slc_dec_st(&d), e = len - pos > SLC_HOP ? pos + SLC_HOP : len; + int32_t hd = 0, hr = 0; + for (; pos < e; pos++) { + int32_t x, a; + while (k < SLC_GRID && ((k * len) >> SLC_GRID_LOG2) == pos) + s->grid[k++] = slc_dec_st(&d); + x = slc_dec_next(s, &d); + a = x - prev; + a = a < 0 ? -a : a; + hd = a > hd ? a : hd; + a = x < 0 ? -x : x; + hr = a > hr ? a : hr; + prev = x; + } + /* a rise of the high-passed peak (hats, snares, clicks) or of the peak (low hits: a slow + * follower, so a low tone's cycles do not look like rises) */ + if (hs && ((hd > thd && hd * 4 > envd * 7) || (hr > thr && hr * 4 > envr * 7)) && h0 >= last + gap && + s->nauto < SLC_AUTO) { + s->apos[s->nauto] = h0; /* from the hop before: pre-roll */ + s->ast[s->nauto++] = st0; + last = h0; + } + envd = hd > envd ? hd : envd - envd / 16; + envr = hr > envr ? hr : envr - envr / 64; + h0 = hs; + st0 = hst; + } +} + +/* smp_user_scan (eng_sample.c): valid 0 = the slot changes (SLICE voices on it stop), 1 = it is valid */ +static void slc_user_scan(uint32_t k, int valid) +{ + slc_src_t *s = &slc_usr[k]; + uint32_t i, j, at = 0; + s->len = 0; + RING_PUBLISH(); + if (!valid) + return; + s->nseg = 0; + for (i = 0; i < usr_nz[k] && i < SLC_SEGS; i++) { + const smp_zone_t *z = &usr_zone[k][i]; + for (j = 0; j < i && usr_zone[k][j].off != z->off; j++) + ; + if (j < i || !z->n) + continue; /* the same data under another key range: once */ + s->seg[s->nseg].off = z->off; + s->seg[s->nseg].at = at; + s->seg[s->nseg++].n = z->n; + at += z->n; + } + if (!s->nseg) + return; + s->rate = usr_zone[k][0].rate; + slc_scan(s, at); + RING_PUBLISH(); + s->len = at; +} + +/* ---- voices */ +static int16_t *slc_rb(track_t *t, voice_t *v) +{ + uint32_t p = (uint32_t)(t - trk), i = (uint32_t)(v - t->v); + return p < NPART && i < NVOICE ? slc_rbuf[p][i] : 0; +} + +static void slice_note_on(track_t *t, voice_t *v) +{ + const int16_t *p = t->p; + uint32_t src = (uint32_t)p[P_E0] & 3u, div = (uint32_t)clamp(p[P_E1], 0, SLC_DIV_AUTO), rev = p[P_E5] != 0; + uint32_t a, b, st, n; + int32_t j; + const slc_src_t *s = slc_get(src); + if (!s) { /* an empty slot: the built-in BREAK */ + src = 0; + s = slc_get(0); + } + v->ph[1] = 0; + v->s[2] = v->s[3] = 0; + v->s[5] = 32767; + v->s[6] = 2; + v->s[7] = 0; + v->env_out = 0; /* a new slice fades in over one block */ + if (!s) + return; + n = slc_count(s, div); + j = ((int32_t)v->note - SLC_BASE - p[P_ROOT] + p[P_E2]) % (int32_t)n; + j += j < 0 ? (int32_t)n : 0; + slc_bounds(s, div, (uint32_t)j, &a, &b, &st); + if (b <= a || (rev && !slc_rb(t, v))) + return; + v->s[4] = (int32_t)(src | (st >> 24) << 2 | rev << 6 | (uint32_t)j << 8 | div << 16); + v->s[6] = 0; + if (rev) { + v->ph[0] = b; + v->ph[2] = a; + v->s[0] = 0x7FFFFFFF; /* no window yet */ + } else { + v->ph[0] = a; + v->ph[2] = b; + v->s[0] = (int16_t)(st & 0xFFFFu); + v->s[1] = (int32_t)((st >> 16) & 127u); + } +} + +/* the reverse window [ws, ws + n): decoded from the nearest checkpoint at or below ws (a grid point, + * or a = the slice start with its state sa) */ +static void slc_fill(const slc_src_t *s, int16_t *rb, uint32_t ws, uint32_t n, uint32_t a, uint32_t sa) +{ + slc_dec_t d; + uint32_t k = (ws << SLC_GRID_LOG2) / s->len, i; + while (k + 1u < SLC_GRID && slc_gpos(s, k + 1u) <= ws) + k++; + if (a <= ws && a > slc_gpos(s, k)) + slc_dec_at(&d, a, sa); + else + slc_dec_at(&d, slc_gpos(s, k), s->grid[k]); + while (d.pos < ws) + slc_dec_next(s, &d); + for (i = 0; i < n; i++) + rb[i] = (int16_t)slc_dec_next(s, &d); +} + +/* the next source sample into *x; 0 = the slice ended */ +static inline int slc_fwd(const slc_src_t *s, voice_t *v, slc_dec_t *d, int loop, int32_t *x) +{ + if (d->pos >= v->ph[2]) { + uint32_t a, b, st; + if (!loop) + return 0; + slc_bounds_v(s, v, &a, &b, &st); + slc_dec_at(d, a, st); + } + *x = slc_dec_next(s, d); + return 1; +} +static inline int slc_rev(const slc_src_t *s, voice_t *v, int16_t *rb, int loop, int32_t *x) +{ + uint32_t q = v->ph[0], ws = (uint32_t)v->s[0], a, b, st; + if (q <= v->ph[2]) { + if (!loop) + return 0; + slc_bounds_v(s, v, &a, &b, &st); + q = b; + } + q--; + if (q < ws || q >= ws + SLC_RB) { + slc_bounds_v(s, v, &a, &b, &st); + ws = q + 1u >= a + SLC_RB ? q + 1u - SLC_RB : a; + slc_fill(s, rb, ws, q + 1u - ws, a, st); + v->s[0] = (int32_t)ws; + } + *x = rb[q - ws]; + v->ph[0] = q; + return 1; +} + +/* the ADSR (ONE: no release), DECAY, the fade at the slice end */ +static int32_t slice_amp(track_t *t, voice_t *v, int32_t adsr) +{ + const int16_t *p = t->p; + if (p[P_E4] == SLC_ONE && v->stage == 3u) + v->stage = 2; /* ONE: the slice plays to its end */ + if (p[P_E6] < 127) { + v->s[5] -= mulq16(v->s[5], ENV_EXP[p[P_E6] & 127]); + if (v->s[5] < 8) + v->s[6] = 2; /* faded out: the voice ends */ + } + return v->s[6] == 3 ? 0 : mulq15(adsr, v->s[5]); +} + +static void slice_render(track_t *t, voice_t *v, int32_t *out, uint32_t n, const vmod_t *m) +{ + const int16_t *p = t->p; + uint32_t pk = (uint32_t)v->s[4], i, frac = v->ph[1], rev = (pk >> 6) & 1u, stepq, rem; + int32_t lp = 4000 + ((clamp((p[P_E7] << 8) + m->cutoff, 0, 127 << 8) * 28767) >> 15), x; + int loop = p[P_E4] == SLC_LOOP && v->gate; + const slc_src_t *s = v->s[6] == 2 ? 0 : slc_get(pk & 3u); + int16_t *rb = slc_rb(t, v); + slc_dec_t d; + if (!s) { /* ended, or its slot was erased */ + v->active = 0; + return; + } + stepq = (pow2_q16(clamp(m->pitch16 - v->pitch_cur + p[P_E3] * 16, -1536, 576)) >> 8) * (s->rate >> 8); + d.pos = v->ph[0]; + d.pred = v->s[0]; + d.idx = v->s[1]; + d.seg = (pk >> 2) & 15u; + if (!v->s[6]) { /* prime the interpolator */ + if (!(rev ? slc_rev(s, v, rb, 0, &x) : slc_fwd(s, v, &d, 0, &x))) { + v->active = 0; + return; + } + v->s[3] = x; + v->s[6] = 1; + } + rem = rev ? v->ph[0] - v->ph[2] : v->ph[2] - d.pos; + if (v->s[6] == 1 && !loop && rem < ((stepq * 3u * n) >> 16)) + v->s[6] = 3; /* the next block fades to 0 (slice_amp) */ + for (i = 0; i < n; i++) { + int32_t y; + frac += stepq; + while (frac >= 65536u) { + frac -= 65536u; + v->s[2] = v->s[3]; + if (!(rev ? slc_rev(s, v, rb, loop, &x) : slc_fwd(s, v, &d, loop, &x))) { + v->s[6] = 2; /* the slice ended */ + v->s[3] = 0; + break; + } + v->s[3] = x; + } + y = v->s[2] + (((v->s[3] - v->s[2]) * (int32_t)(frac >> 1)) >> 15); + v->s[7] += mulq15(y - v->s[7], lp); /* TONE */ + out[i] += mulq15(mulq15(v->s[7], amp_at(m, i)), VOICE_FS) << 1; + if (v->s[6] == 2) + break; + } + v->ph[1] = frac; + if (!rev) { + v->ph[0] = d.pos; + v->s[0] = d.pred; + v->s[1] = d.idx; + v->s[4] = (int32_t)((pk & ~(15u << 2)) | d.seg << 2); + } +} + +/* PATTERNS (ui.c): 9 CHOP (16 slices re-ordered), 10 STUTTER (8 slices, repeats), 11 SLICES (0..15 in order) */ +static const preset_t SLICE_PRESETS[] = { + {"BREAK 16", {0, 2, 0, 0, SLC_ONE, 0, 127, 127}, {0, 127, 127, 30}, 0, 0, FX(0, 0, 0, 12), PAT(9)}, + {"CHOP 8", {0, 1, 0, 0, SLC_GATE, 0, 90, 110}, {0, 127, 127, 12}, 0, 0, FX(10, 0, 20, 10), PAT(10)}, + {"REVERSE", {0, 2, 0, -2, SLC_ONE, 1, 127, 100}, {0, 127, 127, 30}, 0, 0, FX(0, 0, 30, 30), PAT(11)}, + {"USR SLICE", {1, SLC_DIV_AUTO, 0, 0, SLC_ONE, 0, 127, 127}, {0, 127, 127, 30}, 0, 0, FX(0, 0, 0, 12), PAT(11)}, +}; + +static const engine_t ENG_SLICE = { + "SLICE", {"SLCE", "PLAY"}, + { + {"SRC", F_ENUM, 0, 3, 0, N_SLC_SRC, 0}, + {"DIV", F_ENUM, 0, 4, 2, N_SLC_DIV, 0}, + {"START", F_INT, 0, 31, 0, 0, 0}, + {"PTCH", F_SEMI, -24, 24, 0, 0, 0}, + {"MODE", F_ENUM, 0, 2, 0, N_SLC_MODE, 0}, + {"REV", F_ENUM, 0, 1, 0, N_SLC_REV, 0}, + {"DCAY", F_TIME, 0, 127, 127, 0, 0}, + {"TONE", F_INT, 0, 127, 127, 0, 0}, + }, + SLICE_PRESETS, sizeof(SLICE_PRESETS) / sizeof(SLICE_PRESETS[0]), -1, slice_note_on, slice_render, + 0xFB2C, {P_E0, P_E1, P_E3, P_E6}, 0, slice_amp, +}; diff --git a/firmware/src/eng_trio.c b/firmware/src/eng_trio.c new file mode 100644 index 0000000..a8c3bed --- /dev/null +++ b/firmware/src/eng_trio.c @@ -0,0 +1,382 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* TRIO: three oscillators with ring modulation and hard sync into a 12 dB/oct multimode + * filter, in the style of the sound chips of early 8-bit home computers. Felucca's own design. + * + * Oscillators: triangle, saw, pulse (PW), pitched noise (a new random value 16 times a cycle) + * and two combined waves (saw AND triangle, pulse AND saw: the bitwise AND of the 16-bit + * waves, as such chips mix two waveforms). WAVE picks one of 16 sets: the three waves, their + * levels and the interactions: + * RING osc 1's output flips sign with osc 3's top phase bit (the XOR ring of the triangle; + * osc 3 may be silent and only modulate), + * SYNC osc 2 restarts whenever osc 1 starts a cycle. + * EDIT: OSC = WAVE, INT2 / INT3 (osc 2 / osc 3 intervals, semitones), DTN (osc 2 up, osc 3 + * down, cents); TONE = MODE (LP / BP / HP / notch), CUT, RES, PW. The track's ENV / LFO -> FLT + * move CUT, -> SHP move PW. + * + * Band limiting: every step of a saw or a pulse, the sync restarts of osc 2 and the ring + * flips of osc 1 get a polyBLEP correction. The naive waves are computed and each step adds + * its residual to the sample before it and the one after it (the voice runs one sample late + * for that). Triangle and noise have no step correction; the combined waves alias like the + * originals. + * + * Filter: the trapezoidal SVF of dsp.c with LP / BP / HP / notch outputs, a resonance that + * stops short of self-oscillation, an input that saturates above half scale, a compressed + * band-pass state (loud resonance gets gritty instead of ringing) and a slow random drift of + * the cutoff. */ +enum { TW_OFF, TW_TRI, TW_SAW, TW_PLS, TW_NOI, TW_ST, TW_PS }; +#define TRIO_RING 1u +#define TRIO_SYNC 2u +#define TRIO_G3 11000 /* osc level with three oscillators sounding */ +#define TRIO_G2 15000 /* two */ +#define TRIO_G1 24000 /* one */ + +typedef struct { + uint8_t w[3]; /* TW_* of osc 1..3 */ + uint8_t flags; /* TRIO_RING | TRIO_SYNC */ + int16_t g[3]; /* Q15 levels (0: silent; osc 3 still runs for RING) */ +} trio_set_t; + +static const char *const N_TRIO_WAVE[] = {"SAW3", "PLS3", "PPT", "SST", "TRI3", "S&T", "P&S", "P+N", + "NOIS", "SYNC", "SYNCP", "SYNC3", "RING", "RING3", "R+S", "R+SP"}; +static const trio_set_t TRIO_SETS[16] = { + {{TW_SAW, TW_SAW, TW_SAW}, 0, {TRIO_G3, TRIO_G3, TRIO_G3}}, /* SAW3 */ + {{TW_PLS, TW_PLS, TW_PLS}, 0, {TRIO_G3, TRIO_G3, TRIO_G3}}, /* PLS3 */ + {{TW_PLS, TW_PLS, TW_TRI}, 0, {TRIO_G3, TRIO_G3, TRIO_G3 + 3000}}, /* PPT */ + {{TW_SAW, TW_SAW, TW_TRI}, 0, {TRIO_G3, TRIO_G3, TRIO_G3 + 3000}}, /* SST */ + {{TW_TRI, TW_TRI, TW_TRI}, 0, {TRIO_G3 + 2000, TRIO_G3 + 2000, TRIO_G3 + 2000}}, /* TRI3 */ + {{TW_ST, TW_ST, TW_TRI}, 0, {TRIO_G3 + 3000, TRIO_G3 + 3000, TRIO_G3}}, /* S&T */ + {{TW_PS, TW_PS, TW_TRI}, 0, {TRIO_G3 + 3000, TRIO_G3 + 3000, TRIO_G3}}, /* P&S */ + {{TW_PLS, TW_OFF, TW_NOI}, 0, {TRIO_G2, 0, TRIO_G2 - 4000}}, /* P+N */ + {{TW_NOI, TW_OFF, TW_OFF}, 0, {TRIO_G1, 0, 0}}, /* NOIS */ + {{TW_SAW, TW_SAW, TW_OFF}, TRIO_SYNC, {TRIO_G2 - 5000, TRIO_G2 + 5000, 0}}, /* SYNC */ + {{TW_PLS, TW_PLS, TW_OFF}, TRIO_SYNC, {TRIO_G2 - 5000, TRIO_G2 + 5000, 0}}, /* SYNCP */ + {{TW_SAW, TW_SAW, TW_TRI}, TRIO_SYNC, {TRIO_G3 - 3000, TRIO_G3 + 4000, TRIO_G3}}, /* SYNC3 */ + {{TW_TRI, TW_OFF, TW_OFF}, TRIO_RING, {TRIO_G1, 0, 0}}, /* RING */ + {{TW_TRI, TW_OFF, TW_TRI}, TRIO_RING, {TRIO_G2 + 2000, 0, TRIO_G2 - 3000}}, /* RING3 */ + {{TW_TRI, TW_SAW, TW_OFF}, TRIO_RING | TRIO_SYNC, {TRIO_G2 + 2000, TRIO_G2, 0}}, /* R+S */ + {{TW_TRI, TW_PLS, TW_OFF}, TRIO_RING | TRIO_SYNC, {TRIO_G2 + 2000, TRIO_G2, 0}}, /* R+SP */ +}; +static const char *const N_TRIO_MODE[] = {"LP", "BP", "HP", "NOT"}; +/* filter output = (in * a + bp * b + lp * c) >> 10; HP and notch take k * bp off (k: per block) */ +static const int16_t TRIO_MIX[4][3] = {{0, 0, 1024}, {0, 1400, 0}, {1024, 0, -1024}, {1024, 0, 0}}; + +/* polyBLEP of a step j (the value after it minus the one before, at level g Q15) that lies a + * fraction x (Q15) of a sample before sample i: half the step is spread over the sample before + * it (cr[0]) and sample i (cr[1]), with the usual quadratic residual; cr = the block's + * corrections + i */ +static inline void trio_blep(int32_t j, int32_t x, int32_t g, int32_t *cr) +{ + int32_t h = ((j >> 1) * g) >> 15, y = 32767 - x; + cr[0] += (h * ((x * x) >> 15)) >> 15; + cr[1] -= (h * ((y * y) >> 15)) >> 15; +} + +/* how far (Q15 of one sample) a phase is past a step it crossed: past / inc */ +static inline int32_t trio_frac(uint32_t past, uint32_t inc) +{ + uint32_t d = inc >> 15, x; + if (!d) + return 0; + x = past / d; + return x > 32767u ? 32767 : (int32_t)x; +} + +typedef struct { + uint32_t pw; /* pulse width as a phase */ + int32_t pdc, psm; /* means of the naive pulse and of pulse AND saw (taken off) */ +} trio_pw_t; + +static inline int32_t trio_tri16(uint32_t ph) /* the 16-bit triangle of a combined wave */ +{ + return (int32_t)(((ph & 0x80000000u) ? ~ph : ph) >> 15) & 0xFFFF; +} +static inline int32_t trio_st(uint32_t ph) { return ((int32_t)(ph >> 16) & trio_tri16(ph)) - 16384; } +static inline int32_t trio_ps(uint32_t ph, const trio_pw_t *q) +{ + return (ph >= q->pw ? (int32_t)(ph >> 16) : 0) - q->psm; +} + +/* naive value of a wave at phase ph (the step of a sync restart) */ +static int32_t trio_naive(uint32_t w, uint32_t ph, const trio_pw_t *q) +{ + switch (w) { + case TW_TRI: + return osc_tri(ph); + case TW_SAW: + return (int32_t)(ph >> 16) - 32768; + case TW_PLS: + return (ph < q->pw ? 32767 : -32768) - q->pdc; + case TW_ST: + return trio_st(ph); + case TW_PS: + return trio_ps(ph, q); + default: + return 0; + } +} + +/* one oscillator over the block: mix[i] += its sample at level g, its steps into cr; one loop per + * wave, so the wave is not looked at per sample. wx (osc 1 of a SYNC set: saw or pulse): where it + * starts a cycle, how far before sample i (Q15), else -1 */ +static void trio_pass(uint32_t w, uint32_t *php, uint32_t inc, int32_t g, const trio_pw_t *q, int32_t *nz, + int32_t *nst, int32_t *mix, int32_t *cr, int16_t *wx, uint32_t n) +{ + uint32_t ph = *php, o, i, pw = q->pw; + int32_t pdc = q->pdc, z = *nz; + switch (w) { + case TW_TRI: + for (i = 0; i < n; i++) { + ph += inc; + mix[i] += (osc_tri(ph) * g) >> 15; + } + break; + case TW_SAW: + for (i = 0; i < n; i++) { + o = ph; + ph += inc; + if (ph < o) { + int32_t x = trio_frac(ph, inc); + trio_blep(-65536, x, g, cr + i); + if (wx) + wx[i] = (int16_t)x; + } + mix[i] += (((int32_t)(ph >> 16) - 32768) * g) >> 15; + } + break; + case TW_PLS: + for (i = 0; i < n; i++) { + o = ph; + ph += inc; + if (ph < o) { + int32_t x = trio_frac(ph, inc); + trio_blep(65535, x, g, cr + i); + if (wx) + wx[i] = (int16_t)x; + } + if (ph - pw < o - pw) /* crossed pw */ + trio_blep(-65535, trio_frac(ph - pw, inc), g, cr + i); + mix[i] += (((ph < pw ? 32767 : -32768) - pdc) * g) >> 15; + } + break; + case TW_NOI: + for (i = 0; i < n; i++) { + o = ph; + ph += inc; + if ((o ^ ph) & 0x08000000u) + z = (int32_t)(noise32(nst) >> 16) - 32768; + mix[i] += (z * g) >> 15; + } + break; + case TW_ST: + for (i = 0; i < n; i++) { + ph += inc; + mix[i] += (trio_st(ph) * g) >> 15; + } + break; + case TW_PS: + for (i = 0; i < n; i++) { + ph += inc; + mix[i] += (trio_ps(ph, q) * g) >> 15; + } + break; + default: /* silent: the phase still runs (RING) */ + ph += inc * n; + break; + } + *php = ph; + *nz = z; +} + +/* osc 1 as a triangle whose sign osc 3's top phase bit flips (RING; osc 3 starts at p3); each flip + * is a step of twice the triangle's value. wx as in trio_pass */ +static void trio_ring(uint32_t *php, uint32_t inc, int32_t g, uint32_t p3, uint32_t inc3, int32_t *mix, int32_t *cr, + int16_t *wx, uint32_t n) +{ + uint32_t ph = *php, o, o3, i; + for (i = 0; i < n; i++) { + int32_t s, sg; + o = ph; + ph += inc; + o3 = p3; + p3 += inc3; + if (wx && ph < o) + wx[i] = (int16_t)trio_frac(ph, inc); + s = osc_tri(ph); + sg = (p3 & 0x80000000u) ? -g : g; + if ((o3 ^ p3) & 0x80000000u) /* flipped: a step of 2 s */ + trio_blep(2 * s, trio_frac(p3 & 0x7FFFFFFFu, inc3), sg, cr + i); + mix[i] += (s * sg) >> 15; + } + *php = ph; +} + +/* osc 2, saw or pulse, restarted where osc 1 starts a cycle (wx, from trio_pass / trio_ring): the + * restart lies x before sample i, so osc 2 is x of its own cycle in; the jump from where it was + * to its start is one step */ +static void trio_sync(uint32_t w, uint32_t *php, uint32_t inc, int32_t g, const trio_pw_t *q, const int16_t *wx, + int32_t *mix, int32_t *cr, uint32_t n) +{ + uint32_t ph = *php, o, i, pw = q->pw; + int32_t pdc = q->pdc, pls = w == TW_PLS; + for (i = 0; i < n; i++) { + o = ph; + ph += inc; + if (wx[i] >= 0) { + uint32_t back = (uint32_t)wx[i] * (inc >> 15); + trio_blep(trio_naive(w, 0, q) - trio_naive(w, ph - back, q), wx[i], g, cr + i); + ph = o = back; /* no step of its own in this sample */ + } + if (pls) { + if (ph < o) + trio_blep(65535, trio_frac(ph, inc), g, cr + i); + if (ph - pw < o - pw) + trio_blep(-65535, trio_frac(ph - pw, inc), g, cr + i); + mix[i] += (((ph < pw ? 32767 : -32768) - pdc) * g) >> 15; + } else { + if (ph < o) + trio_blep(-65536, trio_frac(ph, inc), g, cr + i); + mix[i] += (((int32_t)(ph >> 16) - 32768) * g) >> 15; + } + } + *php = ph; +} + +/* osc 2 / 3 increment: the base pitch + semitones + cents, with the voice's fine factor (unison, + * TUNE) that m->inc carries */ +static uint32_t trio_inc(int32_t pitch16, int32_t semi, int32_t ct, int32_t fine) +{ + int32_t d16 = ct * 16 / 100, rem = ct * 16 - d16 * 100; /* rem: 1/1600 semitone */ + uint32_t inc = PITCH_INC[clamp(pitch16 + semi * 16 + d16, 0, 2047)]; + return inc + (uint32_t)((int32_t)(inc >> 12) * (rem * 2367 / 16000 + fine)); +} + +static void trio_note_on(track_t *t, voice_t *v) +{ + (void)t; + v->ph[0] = 0; + v->ph[1] = 0x1C000000u; /* start phases a little apart (a third apart would cancel all but + * every third harmonic of equal-pitched saws until DTN drifts them) */ + v->ph[2] = 0x38000000u; + v->s[0] = v->s[1] = 0; /* filter */ + if (!v->s[2]) + v->s[2] = 0x2468ACE + (int32_t)v->age; /* noise state */ + v->s[3] = 0; /* held noise value */ + v->s[4] = 0; /* the sample waiting for its step corrections */ + v->s[5] = 0; /* cutoff drift */ +} + +static void trio_render(track_t *t, voice_t *v, int32_t *out, uint32_t n, const vmod_t *m) +{ + const int16_t *p = t->p; + const trio_set_t *ws = &TRIO_SETS[(uint32_t)p[P_E0] & 15u]; + uint32_t w1 = ws->w[0], w2 = ws->w[1], w3 = ws->w[2], i; + uint32_t ring = ws->flags & TRIO_RING, sync = ws->flags & TRIO_SYNC; + int32_t g1 = ws->g[0], g2 = ws->g[1], g3 = ws->g[2]; + uint32_t base = PITCH_INC[m->pitch16]; + int32_t fine = (base >> 12) ? (int32_t)(m->inc - base) / (int32_t)(base >> 12) : 0; + uint32_t inc1 = m->inc; + uint32_t inc2 = trio_inc(m->pitch16, p[P_E1], p[P_E3], fine); + uint32_t inc3 = trio_inc(m->pitch16, p[P_E2], -p[P_E3], fine); + int32_t duty = clamp((p[P_E7] << 8) + m->shape - (64 << 8), 768, 32000); /* Q15 */ + trio_pw_t q; + uint32_t mode = (uint32_t)p[P_E4] & 3u; + int32_t reso = p[P_E6], k = 8192 - reso * 7168 / 127; /* damping 2.0 .. 0.25 (Q12): no self-oscillation */ + int32_t ma = TRIO_MIX[mode][0], mb = TRIO_MIX[mode][1], mc = TRIO_MIX[mode][2]; + int32_t a1, a2, a3, g, cut, cur; + int32_t mix[CTL], cr[CTL + 1]; /* blocks are CTL long (dsp.c amp_at) */ + int16_t wx[CTL]; + uint32_t ph0 = v->ph[0], ph1 = v->ph[1], ph2 = v->ph[2], ph3s = ph2; /* state in locals: out[] may alias v->s[] */ + int32_t ic1 = v->s[0], ic2 = v->s[1], nst = v->s[2], nz = v->s[3], prev = v->s[4], drift = v->s[5]; + if (n > CTL) + n = CTL; + q.pw = (uint32_t)duty << 17; + q.pdc = 2 * duty - 32768; + q.psm = 32768 - ((duty * duty) >> 15); + if (mode >= 2u) + mb = -(k >> 2); /* HP / notch: in - k bp (- lp) */ + /* the cutoff wanders a little, once per block (the slightly unstable filter of the chips) */ + drift += (((int32_t)(noise32(&nst) >> 22) - 512) - drift) >> 3; + cut = clamp((p[P_E5] << 8) + m->cutoff + drift, 0, 127 << 8); + g = SVF_G[cut >> 8]; + if ((cut >> 8) < 127) + g += ((SVF_G[(cut >> 8) + 1] - g) * (cut & 255)) >> 8; + a1 = (int32_t)((4096u << 13) / (uint32_t)(4096 + ((g * (g + k)) >> 12))); + a2 = (a1 * g) >> 12; + a3 = (a2 * g) >> 12; + for (i = 0; i < n; i++) { + mix[i] = cr[i] = 0; + wx[i] = -1; + } + cr[n] = 0; + trio_pass(w3, &ph2, inc3, g3, &q, &nz, &nst, mix, cr, 0, n); /* first: RING reads its start phase */ + if (ring) + trio_ring(&ph0, inc1, g1, ph3s, inc3, mix, cr, sync ? wx : 0, n); + else + trio_pass(w1, &ph0, inc1, g1, &q, &nz, &nst, mix, cr, sync ? wx : 0, n); + if (sync) + trio_sync(w2, &ph1, inc2, g2, &q, wx, mix, cr, n); + else + trio_pass(w2, &ph1, inc2, g2, &q, &nz, &nst, mix, cr, 0, n); + cur = prev; + for (i = 0; i < n; i++) { + int32_t x = cur + cr[i], y, v1, v2, v3, a; /* one sample late: its corrections are complete */ + cur = mix[i]; + a = x < 0 ? -x : x; /* the input saturates above 16000 (soft knee) */ + if (a > 16000) { + a = 16000 + (softclip((a - 16000) * 2) >> 1); + x = x < 0 ? -a : a; + } + x >>= 1; + /* SVF (dsp.c tsvf_lp, with the band-pass out); the band-pass state is compressed */ + v3 = x - ic2; + v1 = (a1 * ic1 + a2 * v3) >> 13; + v2 = ic2 + ((a2 * ic1 + a3 * v3) >> 13); + ic1 = 2 * v1 - ic1; + ic2 = clamp(2 * v2 - ic2, -150000, 150000); + a = clamp(ic1, -49152, 49152); /* beyond +-49152 a quarter of the excess */ + ic1 = a + ((ic1 - a) >> 2); + y = (x * ma + v1 * mb + v2 * mc) >> 10; + a = y < 0 ? -y : y; /* linear up to half scale, then a soft knee */ + if (a > 16000) { + a = 16000 + (softclip((a - 16000) * 2) >> 1); + y = y < 0 ? -a : a; + } + out[i] += mulq15(mulq15(y << 1, amp_at(m, i)), VOICE_FS) << 1; + } + prev = cur + cr[n]; + v->ph[0] = ph0; + v->ph[1] = ph1; + v->ph[2] = ph2; + v->s[0] = ic1; + v->s[1] = ic2; + v->s[2] = nst; + v->s[3] = nz; + v->s[4] = prev; + v->s[5] = drift; +} + +static const preset_t TRIO_PRESETS[] = { + /* name, {WAVE, INT2, INT3, DTN, MODE, CUT, RES, PW}, {A D S R}, fenv, mono. INT2 / INT3: one-finger chords */ + {"FAT BASS", {0, 0, -12, 9, 0, 62, 45, 64}, {0, 62, 60, 25}, 40, 1, FX(10, 0, 0, 6), XP(P_TRANS + 1, -24)}, + {"MIN STAB", {0, 3, 7, 6, 0, 80, 20, 64}, {0, 50, 0, 30}, 30, 0, FX(0, 20, 20, 30)}, + {"MIN7 STAB", {3, 3, 10, 5, 0, 75, 15, 64}, {0, 60, 20, 40}, 20, 0, FX(0, 25, 18, 30)}, + {"SYNC LEAD", {9, 9, 0, 0, 0, 82, 30, 64}, {2, 70, 100, 40}, 18, 1, FX(0, 10, 30, 22), XP(P_GLIDE + 1, 56)}, + {"HOOVER", {0, 0, -12, 40, 0, 70, 20, 64}, {10, 70, 110, 40}, 10, 1, FX(10, 40, 10, 24), XP(P_GLIDE + 1, 70)}, +}; + +static const engine_t ENG_TRIO = { + "TRIO", {"OSC", "TONE"}, + { + {"WAVE", F_ENUM, 0, 15, 0, N_TRIO_WAVE, 0}, + {"INT2", F_SEMI, -24, 24, 0, 0, 0}, + {"INT3", F_SEMI, -24, 24, -12, 0, 0}, + {"DTN", F_INT, 0, 50, 6, 0, "ct"}, + {"MODE", F_ENUM, 0, 3, 0, N_TRIO_MODE, 0}, + {"CUT", F_CUTOFF, 0, 127, 80, 0, 0}, + {"RES", F_PCT, 0, 127, 40, 0, 0}, + {"PW", F_PCT, 0, 127, 64, 0, 0}, + }, + TRIO_PRESETS, sizeof(TRIO_PRESETS) / sizeof(TRIO_PRESETS[0]), 1, trio_note_on, trio_render, + 0xFFE0, {P_E5, P_E6, P_E7, P_E1}, +}; diff --git a/firmware/src/engines.c b/firmware/src/engines.c new file mode 100644 index 0000000..b1ffbe3 --- /dev/null +++ b/firmware/src/engines.c @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* Engine table: order = PRESETS browsing order (and the engine numbers of the editor protocol). */ +#include "dsp.c" +#include "eng_analog.c" +#include "eng_digital.c" +#include "eng_phase.c" +#include "eng_lofi.c" +#include "eng_sample.c" +#include "eng_formant.c" +#include "eng_trio.c" +#include "eng_drawbar.c" +#include "eng_grain.c" +#if FELUCCA_SLICE +#include "eng_slice.c" +#endif + +static const engine_t *const ENGINES[NENGINES] = {&ENG_ANALOG, &ENG_DIGITAL, &ENG_PHASE, &ENG_LOFI, &ENG_SAMPLE, + &ENG_FORMANT, &ENG_TRIO, &ENG_DRAWBAR, &ENG_GRAIN, +#if FELUCCA_SLICE + &ENG_SLICE, +#endif +}; diff --git a/firmware/src/felucca.c b/firmware/src/felucca.c new file mode 100644 index 0000000..a776cc7 --- /dev/null +++ b/firmware/src/felucca.c @@ -0,0 +1,186 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* SLOOP (based on FELUCCA): one compilation unit (the HAL is header-only). Order matters. */ +#include +#include "fm1_time.h" +#include "fm1_sys.h" +#include "fm1_irq.h" +#include "fm1_guard.h" +#include "fm1_input.h" +#include "fm1_timer.h" +#include "fm1_audio.h" +#include "fm1_adc.h" +#include "fm1_lcd_hw.h" +#include "felucca_tables.h" + +#include "libc.c" +#include "lcd.c" +#include "gfx.c" +#include "core.h" +#include "engines.c" +#include "drums.c" +#include "params.c" +#include "voice.c" +#include "slicer.c" /* per-track SLICER insert, used by fx.c */ +#include "fx.c" +#ifndef FELUCCA_OTA +#define FELUCCA_OTA 1 /* M-UPGRADE update entry; needs FELUCCA_FLASH */ +#endif +#ifndef FELUCCA_OTA_DRYRUN +#define FELUCCA_OTA_DRYRUN 0 /* 1 = stage, ask "success", then undo: no record, no reset */ +#endif +#ifndef FELUCCA_ID +#define FELUCCA_ID "FM-1_900" /* package identity (build.py: the .fwsc marker string) */ +#endif +#ifndef FELUCCA_CDC +#define FELUCCA_CDC 1 /* USB CDC-ACM serial console */ +#endif +#include "usb.c" +#ifndef FELUCCA_UART +#define FELUCCA_UART 0 /* 1 = TRS MIDI IN on UART1 (untested) */ +#endif +#if FELUCCA_UART +#include "midi_uart.c" +#endif +#define FELUCCA_ARRANGER 1 +#include "arranger.c" +#include "seq.c" +#include "audio.c" +#include "panel.c" +#include "ui.c" +#include "ui_song.c" +#include "ui_studio.c" +#include "icons.c" /* parameter icons (FELUCCA_ICONS), used by ui_draw.c */ +#include "ui_draw.c" +#include "ui_layers.c" /* hold a function button: what the keys and knobs do (TE style) */ +#include "ui_menu.c" +#include "ui_input.c" +#ifndef FELUCCA_FLASH +#define FELUCCA_FLASH 1 /* flash driver + storage.c */ +#endif +#if FELUCCA_OTA && !FELUCCA_FLASH +#error "FELUCCA_OTA needs FELUCCA_FLASH" +#endif +#if FELUCCA_FLASH +#include "fm1_flash.h" +static uint8_t flash_ok; /* JEDEC id matched at boot (persist_boot) */ +static int st_read(uint32_t off, void *dst, uint32_t n) /* 256-byte IRQ-off windows: audio keeps up */ +{ + uint8_t *d = dst; + while (n) { + uint32_t k = n > 256u ? 256u : n, f = irq_save(); + int rc = FL_FAR(fl_read_ram)(off, d, k); + irq_restore(f); + if (rc) + return rc; + off += k; + d += k; + n -= k; + } + return 0; +} +static void audio_silence(void) /* IRQs off: the DMA would loop stale audio (buzz) */ +{ + uint32_t i; + for (i = 0; i < sizeof abuf / sizeof abuf[0]; i++) + abuf[i] = 0; +} +/* a sector erase with the audio silenced inside the same interrupts-off window (silenced before it, the + * audio interrupt could render a fresh half that the DMA then loops for the whole erase: a buzz) */ +static int fl_erase4k_quiet(uint32_t off, uint32_t *took) +{ + uint32_t f = irq_save(); + int rc; + audio_silence(); + rc = FL_FAR(fl_erase4k_ram)(off, took); + irq_restore(f); + return rc; +} +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 "storage.c" +#endif +#include "upreset.c" /* user presets (RAM mirror; flash with FELUCCA_FLASH) */ +#include "project.c" +#if FELUCCA_OTA +static uint8_t recovery_active; +#define OTA_IDENTITY (recovery_active ? "FM-1_000" : FELUCCA_ID) +#include "ota.c" +static void recovery_poll(void); +static uint32_t ota_now_ms(void) { return fm1_ms; } +static void ota_idle(void) +{ + fm1_wdt_feed(); + if (recovery_active) recovery_poll(); +} +static int ota_in_area(uint32_t off, uint32_t n) { return FL_IN(off, n, OTA_AREA, OTA_AREA + OTA_AREA_LEN); } +static int ota_erase(uint32_t off) +{ + uint32_t took; + if (!ota_in_area(off, 0x1000u) || (off & 0xFFFu)) + return -8; + return fl_erase4k_quiet(off, &took); +} +static int ota_prog(uint32_t off, const void *p, uint32_t n) +{ + if (!ota_in_area(off, n)) + return -8; + return fl_write(off, p, n); +} +static int ota_fread(uint32_t off, void *p, uint32_t n) { return st_read(off, p, n); } +static void ota_show(uint32_t step, int32_t code) +{ + static const char *const STEP[] = {"", "PACKAGE", "CHECK HEAD", "LOADER", "CONFIRM", "RESTART"}; + char b[24]; + if (recovery_active) return; /* keep polled USB alive during OTA */ + lcd_fill(0, 0, 240, 240, C_BLACK); + draw_text_box(0, 92, 240, &FONT_S, "UPDATE", C_WHITE, 1); + if (step < 9u) { + draw_text_box(0, 124, 240, &FONT_S, STEP[step < 6u ? step : 0], C_HI, 1); + return; + } + if (code == 1) + str_cpy(b, "DRY RUN OK", sizeof b); + else { + uint32_t k = 0, v = (uint32_t)-code; + str_cpy(b, "FAILED -", sizeof b); + while (b[k]) + k++; + if (v >= 10u) + b[k++] = (char)('0' + v / 10u); + b[k++] = (char)('0' + v % 10u); + b[k] = 0; + } + draw_text_box(0, 124, 240, &FONT_S, b, C_HI, 1); + fm1_delay_ms(1500); +} +static void ota_commit(const uint8_t *parm) +{ + bootguard_clear(&bootguard); /* intentional update reset */ + usb_detach(); + fm1_delay_ms(30); + fm1_enter_update(parm); /* record into RAM, core reset (fm1_sys.h) */ +} +#endif +#if FELUCCA_OTA +#include "editor.c" /* web editor SysEx (needs the OTA SysEx plumbing) */ +#endif +#if FELUCCA_CDC +#include "console.c" +#endif +#if FELUCCA_OTA +#include "recovery.c" /* early, polled USB updater; no synth or settings */ +#endif +#include "splash.c" /* SLOOP boot logo (build/gen/sloop_logo.h) */ +#include "main.c" diff --git a/firmware/src/fx.c b/firmware/src/fx.c new file mode 100644 index 0000000..407581a --- /dev/null +++ b/firmware/src/fx.c @@ -0,0 +1,406 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* Effects: per-track DIST insert, then sends into three + * shared buses (chorus, tempo delay, reverb). Mono buses, stereo dry mix. */ +#define DLY_LEN 65536u /* 1.49 s: 1/4 at 40 BPM fits */ +#define CHO_LEN 2048u +static int16_t dly_buf[DLY_LEN] __attribute__((section(".pool"))); +static int16_t cho_buf[CHO_LEN] __attribute__((section(".pool"))); +static const uint16_t REV_COMB[4] = {1116, 1188, 1277, 1356}; +static const uint16_t REV_AP[2] = {556, 441}; +static int16_t rev_comb[1116 + 1188 + 1277 + 1356] __attribute__((section(".pool"))); +static int16_t rev_ap[556 + 441] __attribute__((section(".pool"))); +static struct { + uint32_t dly_w, cho_w, cho_ph; + int32_t dly_lp; + uint16_t comb_i[4], ap_i[2]; + int32_t comb_lp[4]; +} fx; + +/* DIST: low cut -> drive (1x..8x, exponential) -> asymmetric soft clip + * (a little bias = even harmonics) -> tone low-pass that closes with drive -> + * make-up gain. State per part (track_t dist_*). */ +static void track_dist(track_t *t, int32_t *b, uint32_t n) +{ + int32_t d = t->p[P_DIST], i, g, k, mk, bias = 2400, b0; + if (!d) { + t->dist_on = 0; + return; + } + if (!t->dist_on) { /* coming on: no stale high-pass state (a thump) */ + t->dist_on = 1; + t->dist_hp = b[0]; + t->dist_lp1 = t->dist_lp2 = 0; + } + g = 4096 + d * d * 2; /* Q12: 1x .. ~9x, gentle at first */ + k = 32000 - d * 95; /* tone: transparent at low drive .. ~3 kHz, Q15 */ + mk = 30000 - d * 120; /* make-up */ + b0 = softclip(bias); + for (i = 0; i < (int32_t)n; i++) { + 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 */ + 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); + } +} + +/* master: peak limiter in front of the soft clipper. Fast attack (~0.1 ms), + * ~150 ms release, threshold where tanh is still nearly linear, so chords + * get quieter instead of crushed. */ +#define LIM_T 18000 +static int32_t lim_env = LIM_T; +static volatile uint8_t fx_lowcut; /* settings: 12 dB/oct ~110 Hz for the small speaker */ +static int32_t lc_l1, lc_l2, lc_r1, lc_r2, dc_l, dc_r, dce_l, dce_r; + +/* DC blocker (~2 Hz), always on: a leaky integrator of the input (Q6 state) subtracted from it. + * The >> 12 step keeps its remainder (error feedback, 0..4095) and adds it to the next one, so no + * part of the step is lost: the state follows the input exactly, down to 0 after the sound stops. + * (It was rounded, and a rounded step of (x - dc) / 4096 stops moving at |x - dc| < 2048: a + * constant offset of up to +-31 stayed at the output after silence.) */ +static inline int32_t dc_block(int32_t x, int32_t *dc, int32_t *err) +{ + int32_t e = (x << 6) - *dc + *err, d = e >> 12; + *err = e - (d << 12); + *dc += d; + return x - ((*dc + 32) >> 6); +} + +static int32_t lce[4]; +static inline int32_t lowcut1(int32_t x, int32_t *lc, int32_t *err) /* x minus its one-pole low-pass */ +{ + int32_t e = x - *lc + *err, d = e >> 6; + *err = e - (d << 6); + *lc += d; + return x - *lc; +} + +/* the output stage: linear up to KNEE (a clean low end: no tanh harmonics on a loud sine), above it + * a tanh knee with the same slope at the joint, to full scale */ +#define KNEE 16384 +static inline int32_t knee(int32_t x) +{ + int32_t a = x < 0 ? -x : x; + if (a <= KNEE) + return x; + a = KNEE + (softclip((a - KNEE) * 2) >> 1); + return x < 0 ? -a : a; +} + +static inline void master_out(int32_t *l, int32_t *r) +{ + int32_t al, ar, a; + *l = dc_block(*l, &dc_l, &dce_l); + *r = dc_block(*r, &dc_r, &dce_r); + if (fx_lowcut) { /* two one-pole high-passes, error feedback as dc_block (the */ + *l = lowcut1(*l, &lc_l1, &lce[0]); /* rounded step stopped at |x - lc| < 32: an offset) */ + *l = lowcut1(*l, &lc_l2, &lce[1]); + *r = lowcut1(*r, &lc_r1, &lce[2]); + *r = lowcut1(*r, &lc_r2, &lce[3]); + } + al = *l < 0 ? -*l : *l; + ar = *r < 0 ? -*r : *r; + a = al > ar ? al : ar; + if (a > lim_env) + lim_env += (a - lim_env) >> 2; + else if (lim_env > LIM_T) + lim_env -= ((lim_env - LIM_T) >> 12) + 1; + if (lim_env > LIM_T) { + int32_t g = (int32_t)(((uint32_t)LIM_T << 15) / (uint32_t)lim_env); /* < 32768 */ + *l = ((*l >> 4) * g) >> 11; /* >> 4 first: |l| may be far above Q15 */ + *r = ((*r >> 4) * g) >> 11; + } + *l = knee(*l); + *r = knee(*r); +} + + + +static uint32_t delay_samples(void) +{ + uint32_t s = div_samples((uint32_t)song.g[G_DTIME]); + return s < 16u ? 16u : s >= DLY_LEN ? DLY_LEN - 1u : s; +} + +/* process the three buses for one block; sends in, wet stereo-equal out */ +static void fx_buses(const int32_t *cho_in, const int32_t *dly_in, const int32_t *rev_in, int32_t *wet, + uint32_t n) +{ + uint32_t i, k, dl = delay_samples(); + int32_t fb = song.g[G_DFDBK] * 230, col = 2000 + song.g[G_DCOLOR] * 240; + int32_t dmix = song.g[G_DMIX] * 258; + int32_t size = 25000 + song.g[G_RSIZE] * 50, damp = 32767 - song.g[G_RDAMP] * 200; + int32_t cdepth = song.g[G_CDEPTH] * 6; + uint32_t cinc = LFO_INC[song.g[G_CRATE] & 127] / CTL; + for (i = 0; i < n; i++) { + int32_t y = 0, x, r, a; + /* chorus: modulated short delay, 5..15 ms */ + cho_buf[fx.cho_w & (CHO_LEN - 1u)] = (int16_t)clamp(cho_in[i] >> 1, -32768, 32767); + fx.cho_ph += cinc; + r = (400 << 8) + ((osc_sine(fx.cho_ph) + 32768) * cdepth >> 8); /* Q8 delay: read between samples */ + { + uint32_t ri = (uint32_t)r >> 8; + int32_t f = r & 255, c0 = cho_buf[(fx.cho_w - ri) & (CHO_LEN - 1u)]; + int32_t c1 = cho_buf[(fx.cho_w - ri - 1u) & (CHO_LEN - 1u)]; + y += (c0 + (((c1 - c0) * f) >> 8)) << 1; + } + fx.cho_w++; + /* delay with a low-passed feedback */ + x = dly_buf[(fx.dly_w - dl) & (DLY_LEN - 1u)]; + fx.dly_lp += mulq15(x - fx.dly_lp, col); + dly_buf[fx.dly_w & (DLY_LEN - 1u)] = + (int16_t)clamp((dly_in[i] >> 1) + mulq15(fx.dly_lp, fb), -32768, 32767); + fx.dly_w++; + y += mulq15(x << 1, dmix); + /* reverb: 4 damped combs + 2 allpasses (Freeverb-like, mono) */ + a = 0; + { + int16_t *c = rev_comb; + int32_t in = mulq15(rev_in[i], 2580); /* 1/8 at -4 dB */ + for (k = 0; k < 4u; k++) { + int32_t o = c[fx.comb_i[k]]; + fx.comb_lp[k] = o + mulq15(fx.comb_lp[k] - o, 32767 - damp); + c[fx.comb_i[k]] = (int16_t)clamp(in + mulq15(fx.comb_lp[k], size), -32768, 32767); + if (++fx.comb_i[k] >= REV_COMB[k]) + fx.comb_i[k] = 0; + a += o; + c += REV_COMB[k]; + } + c = rev_ap; + for (k = 0; k < 2u; k++) { + int32_t o = c[fx.ap_i[k]]; + int32_t v = a + (o >> 1); + c[fx.ap_i[k]] = (int16_t)clamp(v, -32768, 32767); + a = o - a; /* Freeverb: out = buf - in (o - v would be a notch comb) */ + if (++fx.ap_i[k] >= REV_AP[k]) + fx.ap_i[k] = 0; + c += REV_AP[k]; + } + } + y += a; + wet[i] = y; + } +} + +/* one block of the whole mix (shared with tests/hostsim.c): events -> each part + * -> dist -> SLICER -> level / pan / sends -> drums (-> SLICER) -> buses -> master; out: stereo Q15 */ +static void events_block(uint32_t n); /* seq.c */ +static int32_t send_c[CTL], send_d[CTL], send_r[CTL], wet[CTL], mix_l[CTL], mix_r[CTL], part_buf[CTL]; + +/* ---- mute / solo: a track that goes silent fades out over ~6 ms (and back in) */ +#define MUTE_STEP 4096 /* Q15 per block: 8 blocks */ +static int32_t gain_next(track_t *t) /* the track's mute gain at the end of this block */ +{ + int32_t to = trk_silent(t) ? 32767 : 0, a = t->att; + t->att = a < to ? (to - a > MUTE_STEP ? a + MUTE_STEP : to) : (a - to > MUTE_STEP ? a - MUTE_STEP : to); + return 32767 - t->att; +} + +/* ---- DUCK: every kick (the drum track's KICK / KICK 2) dips the synth parts, which come back over an + * eighth note: depth G_DUCK, the curve (1 - t / T)^2. drum_on sets drums.kick. */ +static struct { + uint32_t t; /* units since the kick */ + int32_t g0, g1; /* the parts' gain at the block start, end (Q15) */ +} duck = {0xFFFFFFFFu, 32767, 32767}; + +static void duck_block(uint32_t adv) +{ + int32_t depth = song.g[G_DUCK] * 258, x; + uint32_t len = BEAT_U / 2u; + duck.g0 = duck.g1; + if (drums.kick) { + drums.kick = 0; + duck.t = 0; + } + if (!depth || duck.t >= len) { + duck.g1 = 32767; + return; + } + x = 32767 - (int32_t)((duck.t << 10) / (len >> 5)); /* 1 - t / T, Q15 (t < len < 2^21) */ + if (x < 0) + x = 0; + duck.g1 = 32767 - mulq15(depth, mulq15(x, x)); + duck.t = duck.t + adv < duck.t ? 0xFFFFFFFFu : duck.t + adv; +} + +/* one synth part into the dry mix and the sends; a part with no voice sounding costs + * the LFO tick and a cleared buffer only (after the DIST tail has run out) */ +static void mix_part(track_t *t, uint32_t n) +{ + int32_t *b = part_buf; + uint32_t i; + int32_t g0 = 32767 - t->att, g1 = gain_next(t); + if (track_render(t, b, n)) + t->tail = 16; /* blocks of DIST state to run out after the last voice */ + else if ((!t->tail || !t->p[P_DIST] || !--t->tail) && !slicer_busy(t)) { + slicer_track(t, 0, n); /* (the SLICER's step clock runs on) */ + return; + } + if (!g0 && !g1) { /* silent (MUTE / SOLO): the voices run, nothing is heard */ + slicer_track(t, 0, n); + return; + } + { + int32_t lvl = LEVEL_Q12[t->p[P_LEVEL] & 127], pan = t->p[P_PAN]; + int32_t gl = 4096 - (pan > 0 ? pan * 64 : 0), gr = 4096 + (pan < 0 ? pan * 64 : 0); + int32_t c = t->p[P_CHOR] * 258, d = t->p[P_DLY] * 258, r = t->p[P_REV] * 258, pk = t->peak; + int32_t xmax = c > d ? c : d; + int32_t ga = mulq15(g0, duck.g0), gb = mulq15(g1, duck.g1); /* mute x duck, ramped over the block */ + xmax = 0x7FFFFFFF / ((xmax > r ? xmax : r) | 1); /* sends: loud chords at a high LEVEL */ + track_dist(t, b, n); + slicer_track(t, b, n); /* slicer.c: before the level, pan and sends */ + for (i = 0; i < n; i++) { + int32_t x = ((b[i] >> 2) * lvl) >> 10, a; /* pre-shift: 8 loud voices */ + 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) */ + a = x < 0 ? -x : x; + xs = clamp(x, -xmax, xmax); /* sends: mulq15 would overflow */ + if (a > pk) + pk = a; + if (c) + send_c[i] += mulq15(xs, c); + if (d) + send_d[i] += mulq15(xs, d); + if (r) + send_r[i] += mulq15(xs, r); + mix_l[i] += ((x >> 4) * gl) >> 8; /* (x may pass 2^19: >> 4 first) */ + mix_r[i] += ((x >> 4) * gr) >> 8; + } + t->peak = pk; + } +} + +/* ---- DUST: the master through an old sampler and a record. G_DUST 0..127 turns up together: drive + * into a soft clip, a lower sample rate (held samples, 44.1 -> 11 kHz), fewer bits (15 -> 8), a + * one-pole low-pass (open -> ~3 kHz), a little hiss and crackle. The hiss and the crackle are the + * record turning: they fade in with PLAY and out (~0.1 s) at STOP, so a stopped SLOOP is silent. + * Stereo, ~25 ops a sample. */ +static struct { + int32_t hl, hr, hn; /* held samples, samples left to hold */ + int32_t ll, lr; /* low-pass states */ + int32_t rnd, click; /* noise state, a crackle decaying */ + int32_t bed; /* hiss / crackle level, Q15: 0 stopped, 32767 playing */ +} dust = {0, 0, 0, 0, 0, 0x2545F491, 0, 0}; + +static int32_t crush_bits(int32_t v, int32_t shift) /* fewer bits, rounded toward 0: no DC from tails */ +{ + return v >= 0 ? (v >> shift) << shift : -((-v >> shift) << shift); +} + +static void dust_process(int32_t *l, int32_t *r, uint32_t n) +{ + int32_t d = song.g[G_DUST], hold, shift, a, drive, hiss, i, bed0, bed1; + uint32_t pc; + if (!d) { + dust.bed = 0; + return; + } + hold = 1 + d * 3 / 127; + shift = d / 18; + a = 32767 - d * 165; /* one-pole coefficient, Q15 */ + drive = 4096 + d * 24; /* Q12: 1x .. 1.75x */ + hiss = d * 2; + pc = (uint32_t)d * 7u; /* crackle: chance per sample, x 2^-22 */ + bed0 = dust.bed; /* ~0.1 s from 0 to full (238 a block of 32) */ + bed1 = dust.bed = clamp(dust.bed + (song.playing ? 238 : -238), 0, 32767); + for (i = 0; i < (int32_t)n; i++) { + int32_t x = l[i], y = r[i]; + int32_t bed = bed0 + (((bed1 - bed0) * i) >> CTL_LOG2); + uint32_t nz = noise32(&dust.rnd); + if (--dust.hn <= 0) { /* sample and hold, then the bits */ + dust.hn = hold; + dust.hl = softclip(((x >> 2) * drive) >> 10); + dust.hr = softclip(((y >> 2) * drive) >> 10); + if (shift) { + dust.hl = crush_bits(dust.hl, shift); + dust.hr = crush_bits(dust.hr, shift); + } + } + dust.ll += mulq15(dust.hl - dust.ll, a); + dust.lr += mulq15(dust.hr - dust.lr, a); + if ((nz >> 10) < pc) /* a speck of dust */ + dust.click = mulq15(((int32_t)(nz & 0x3FFu) - 512) * d / 8, bed); + x = dust.ll + dust.click + mulq15(((int32_t)(nz >> 16) - 32768) * hiss >> 15, bed); + y = dust.lr + dust.click + mulq15(((int32_t)(nz & 0xFFFFu) - 32768) * hiss >> 15, bed); + dust.click -= dust.click >> 2; + l[i] = x; + r[i] = y; + } +} + +/* ---- the DJ filter on the master: G_FILT < 0 a low-pass closing, > 0 a high-pass opening, 0 off. + * The cutoff glides to the knob (no zipper); at 0 it opens fully, then the filter is bypassed. */ +static struct { + int32_t cut; /* now, 0..127 << 8 (CUTOFF_HZ index) */ + int8_t mode; /* -1 LP, 1 HP, 0 off */ + int32_t l1, l2, r1, r2; +} djf; + +static void djf_process(int32_t *l, int32_t *r, uint32_t n) +{ + int32_t v = song.g[G_FILT], to, i; + tsvf_t c; + if (v < 0 && djf.mode >= 0) { /* (switching side: from open) */ + djf.mode = -1; + djf.cut = 127 << 8; + djf.l1 = djf.l2 = djf.r1 = djf.r2 = 0; + } else if (v > 0 && djf.mode <= 0) { + djf.mode = 1; + djf.cut = 0; + djf.l1 = djf.l2 = djf.r1 = djf.r2 = 0; + } + if (!djf.mode) + return; + to = djf.mode < 0 ? (v < 0 ? (127 << 8) + v * 90 * 4 : 127 << 8) : (v > 0 ? v * 90 * 4 : 0); + djf.cut += clamp(to - djf.cut, -384, 384); /* ~1.5 index a block */ + if (!v && djf.cut == to) { + djf.mode = 0; /* fully open again: off */ + return; + } + tsvf_coef(&c, djf.cut, 40); + for (i = 0; i < (int32_t)n; i++) { + int32_t x = clamp(l[i], -140000, 140000), y = clamp(r[i], -140000, 140000); + int32_t fl = tsvf_lp(&c, x, &djf.l1, &djf.l2), fr = tsvf_lp(&c, y, &djf.r1, &djf.r2); + l[i] = djf.mode < 0 ? fl : x - fl; + r[i] = djf.mode < 0 ? fr : y - fr; + } +} + +#include "punch.c" /* PUNCH-IN FX on the whole mix (FX held + a white key) */ +static int32_t master_cur = -1; /* the volume knob, ramped per sample (no zipper) */ +static void mix_block(int32_t *out, uint32_t n) +{ + uint32_t i; + int32_t m0, m1; + for (i = 0; i < n; i++) + send_c[i] = send_d[i] = send_r[i] = mix_l[i] = mix_r[i] = 0; + events_block(n); + duck_block(n * (uint32_t)song.g[G_BPM]); + for (i = 0; i < NPART; i++) + mix_part(&trk[i], n); + drums.a0 = TDRUM->att; /* the drum track's mute / solo fade */ + drums.a1 = 32767 - gain_next(TDRUM); + slicer_drums(mix_l, mix_r, send_r, n); /* drums_render, through the SLICER when on */ + fx_buses(send_c, send_d, send_r, wet, n); + for (i = 0; i < n; i++) { + mix_l[i] += wet[i]; + mix_r[i] += wet[i]; + } + dust_process(mix_l, mix_r, n); + punch_process(mix_l, mix_r, n); + djf_process(mix_l, mix_r, n); + m1 = (int32_t)song.master_q12; + m0 = master_cur < 0 ? m1 : master_cur; + master_cur = m1; + for (i = 0; i < n; i++) { + int32_t m = m0 + (((m1 - m0) * (int32_t)i) >> CTL_LOG2); + int32_t l = ((mix_l[i] >> 2) * m) >> 10; + int32_t r = ((mix_r[i] >> 2) * m) >> 10; + master_out(&l, &r); + out[2u * i] = l; + out[2u * i + 1u] = r; + } +} diff --git a/firmware/src/gfx.c b/firmware/src/gfx.c new file mode 100644 index 0000000..f853abb --- /dev/null +++ b/firmware/src/gfx.c @@ -0,0 +1,180 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* Small-canvas renderer (no full framebuffer). Draw text/lines into + * an off-screen strip, then blit it in one DMA transfer. Pixels are stored + * byte-swapped (the panel takes RGB565 big-endian). */ +typedef struct { /* proportional, see tools/gen_font.py */ + uint8_t h; + uint8_t pad; /* bitmap starts this many pixels left of the pen */ + uint8_t first, last; + const uint8_t *adv; /* advance per glyph */ + const uint8_t *bw; /* bitmap width per glyph (starts FONT_PAD left of the pen) */ + const uint16_t *off; /* byte offset of each glyph */ + const uint8_t *data; +} felucca_font_t; +#include "felucca_font.h" + +#define CV_MAX (240u * 124u) /* the graph strip is 240 x 124 */ +static uint16_t cv_px[CV_MAX] __attribute__((section(".pool"))); +static uint32_t cv_w, cv_h; +static int32_t cv_oy; /* y offset for graph drawing */ + +#define RGB(r, g, b) ((uint16_t)((((r) >> 3) << 11) | (((g) >> 2) << 5) | ((b) >> 3))) +#define C_BLACK 0x0000u +#define C_WHITE 0xFFFFu /* accent only: what is being touched / where we are */ +/* The screen is five steps of one colour, darkest to brightest, plus white. + * Palettes are picked in the HOME-hold menu (COLOR). */ +typedef struct { + const char *name; + uint16_t c[5]; +} palette_t; +static const palette_t PALETTES[] = { + {"GREEN", {RGB(0, 40, 12), RGB(0, 84, 30), RGB(16, 140, 54), RGB(56, 200, 92), RGB(120, 255, 146)}}, + {"AMBER", {RGB(60, 26, 0), RGB(110, 50, 0), RGB(170, 82, 0), RGB(225, 120, 8), RGB(255, 166, 40)}}, + {"CYAN", {RGB(0, 30, 50), RGB(0, 62, 96), RGB(16, 112, 160), RGB(56, 172, 222), RGB(140, 222, 255)}}, + {"RED", {RGB(52, 8, 8), RGB(100, 18, 14), RGB(170, 36, 26), RGB(226, 64, 48), RGB(255, 112, 92)}}, + {"MONO", {RGB(40, 40, 40), RGB(80, 80, 80), RGB(130, 130, 130), RGB(186, 186, 186), RGB(226, 226, 226)}}, +}; +#define NPALETTES (sizeof(PALETTES) / sizeof(PALETTES[0])) +static uint16_t pal[5]; +#define C_LINE pal[0] /* 1 rules, separators */ +#define C_DIM pal[1] /* 2 inactive, empty steps, units */ +#define C_GRAY pal[2] /* 3 labels */ +#define C_AMB pal[3] /* 4 secondary text */ +#define C_HI pal[4] /* 5 values, curves */ + +static void palette_set(uint32_t i) +{ + uint32_t k; + for (k = 0; k < 5u; k++) + pal[k] = PALETTES[i % NPALETTES].c[k]; +} + +static inline uint16_t swap16(uint32_t c) { return (uint16_t)(((c >> 8) & 0xFFu) | ((c & 0xFFu) << 8)); } + +static void cv_begin(uint32_t w, uint32_t h, uint16_t bg) +{ + uint32_t i, n; + if (w * h > CV_MAX) + h = CV_MAX / w; + lcd_sync(); /* the last blit may still read cv_px */ + cv_w = w; + cv_h = h; + n = w * h; + for (i = 0; i < n; i++) + cv_px[i] = swap16(bg); +} + +static void cv_blit(uint32_t x, uint32_t y) { lcd_blit(x, y, cv_w, cv_h, cv_px); } + +/* canvas rows r0 .. cv_h-1 only, to screen row y + r0 */ +static void cv_blit_from(uint32_t x, uint32_t y, uint32_t r0) +{ + if (r0 < cv_h) + lcd_blit(x, y + r0, cv_w, cv_h - r0, cv_px + r0 * cv_w); +} + +static inline void cv_pset(int32_t x, int32_t y, uint16_t c) +{ + y += cv_oy; + if ((uint32_t)x < cv_w && (uint32_t)y < cv_h) + cv_px[(uint32_t)y * cv_w + (uint32_t)x] = swap16(c); +} + +static void cv_rect(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t c) +{ + int32_t x1 = x + w, y1 = y + h + cv_oy, i; + uint16_t sc = swap16(c); + y += cv_oy; /* clipped once, then filled row by row */ + if (x < 0) + x = 0; + if (y < 0) + y = 0; + if (x1 > (int32_t)cv_w) + x1 = (int32_t)cv_w; + if (y1 > (int32_t)cv_h) + y1 = (int32_t)cv_h; + for (; y < y1; y++) + for (i = x; i < x1; i++) + cv_px[(uint32_t)y * cv_w + (uint32_t)i] = sc; +} + +static void cv_line(int32_t x0, int32_t y0, int32_t x1, int32_t y1, uint16_t c) +{ + int32_t dx = x1 > x0 ? x1 - x0 : x0 - x1, sx = x0 < x1 ? 1 : -1; + int32_t dy = y1 > y0 ? y0 - y1 : y1 - y0, sy = y0 < y1 ? 1 : -1; + int32_t err = dx + dy, guard = 2000; + while (guard--) { /* bounded: a line is never longer than 480 px */ + int32_t e2 = 2 * err; /* both tests use the same error value */ + cv_pset(x0, y0, c); + if (x0 == x1 && y0 == y1) + break; + if (e2 >= dy) { + err += dy; + x0 += sx; + } + if (e2 <= dx) { + err += dx; + y0 += sy; + } + } +} + +/* glyph index of a character: lower case folds to upper case when the font + * has none, anything missing (and C1 controls) draws as '?' */ +static uint32_t glyph(const felucca_font_t *f, uint32_t ch) +{ + if (ch >= 'a' && ch <= 'z' && f->last < 'a') + ch -= 32u; + if (ch < f->first || ch > f->last || (ch >= 127u && ch < 160u)) + ch = '?'; + return ch - f->first; +} + +/* text, alpha-blended onto black with colour c; returns the end x */ +static int32_t cv_text(int32_t x, int32_t y, const felucca_font_t *f, const char *s, uint16_t c) +{ + uint16_t ramp[16]; + uint32_t r = c >> 11, g = (c >> 5) & 63u, b = c & 31u, a; + for (a = 0; a < 16u; a++) + ramp[a] = (uint16_t)(((r * a / 15u) << 11) | ((g * a / 15u) << 5) | (b * a / 15u)); + for (; *s; s++) { + uint32_t gi = glyph(f, (uint8_t)*s), gx, gy, w, bpr; + const uint8_t *gd; + w = f->bw[gi]; + bpr = (w + 1u) / 2u; + gd = f->data + f->off[gi]; + for (gy = 0; gy < f->h; gy++) + for (gx = 0; gx < w; gx++) { + uint32_t v = gd[gy * bpr + gx / 2u]; + v = (gx & 1u) ? (v & 15u) : (v >> 4); + if (v) + cv_pset(x - f->pad + (int32_t)gx, y + (int32_t)gy, ramp[v]); + } + x += f->adv[gi]; + } + return x; +} + +static int32_t text_w(const felucca_font_t *f, const char *s) +{ + int32_t w = 0; + for (; *s; s++) + w += f->adv[glyph(f, (uint8_t)*s)]; + return w; +} + +/* one-shot: text in a box, cleared to black, blitted */ +static void draw_text_box(uint32_t x, uint32_t y, uint32_t w, const felucca_font_t *f, const char *s, + uint16_t c, int align) +{ + int32_t tw = text_w(f, s), tx = 0; + cv_begin(w, f->h, C_BLACK); + if (align == 1) + tx = ((int32_t)w - tw) / 2; + else if (align == 2) + tx = (int32_t)w - tw; + cv_text(tx, 0, f, s, c); + cv_blit(x, y); + lcd_sync(); /* one-shots (boot, crash, UBOOT, update) finish here */ +} diff --git a/firmware/src/icons.c b/firmware/src/icons.c new file mode 100644 index 0000000..4f9808d --- /dev/null +++ b/firmware/src/icons.c @@ -0,0 +1,156 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* Parameter icons: a 12 x 12 px, 2-bit glyph left of each column label. + * Art: assets/icons.png + icons.json -> build/gen/felucca_icons.h + * (tools/gen_icons.py). Which icon a parameter gets is decided here, by its label. + * FELUCCA_ICONS=0 turns them off (labels get their full width back). */ +#include "felucca_icons.h" +#ifndef FELUCCA_ICONS +#define FELUCCA_ICONS (FELUCCA_ICONS_N > 0) /* on when the atlas has icons */ +#endif +#if FELUCCA_ICONS && FELUCCA_ICONS_N == 0 +#error "FELUCCA_ICONS=1 but felucca_icons.h has no icons (assets/icons.png missing?)" +#endif +#define ICON_NONE 0xFFu /* no icon (empty column) */ +#define ICON_AUTO 0xFEu /* draw_column: look the label up */ +#define ICON_GAP 2 /* px between the icon and the label */ + +#if FELUCCA_ICONS +typedef struct { + const char *label; + uint8_t icon; +} icon_map_t; + +/* label -> icon. Labels shared by several parameters (RATE, WAVE, SET) are + * told apart by descriptor in param_icon(). Unknown labels get ICON_GENERIC. */ +static const icon_map_t ICON_MAP[] = { + /* track: ENV, LFO, destinations */ + {"LVL", ICON_LEVEL}, {"ATK", ICON_ATTACK}, {"DEC", ICON_DECAY}, {"SUS", ICON_SUSTAIN}, + {"REL", ICON_RELEASE}, {"FLT", ICON_CUTOFF}, {"PIT", ICON_PITCH}, {"SHP", ICON_SHAPE}, + {"FX", ICON_MOD}, {"RATE", ICON_RATE}, {"WAVE", ICON_WAVE}, {"PHS", ICON_PHASE}, + {"FADE", ICON_FADE}, {"AMP", ICON_LEVEL}, + /* arp, scale, pattern */ + {"MODE", ICON_ARP}, {"OCT", ICON_OCTAVE}, {"GATE", ICON_GATE}, {"SWG", ICON_SWING}, + {"PROB", ICON_PROB}, {"HOLD", ICON_HOLD}, {"ORD", ICON_ORDER}, {"ROOT", ICON_PITCH}, + {"SCL", ICON_SCALE}, {"QNT", ICON_QUANTIZE}, {"TRN", ICON_TRANSPOSE}, {"LEN", ICON_LENGTH}, + {"DIV", ICON_DIVISION}, + /* fx sends, voice */ + {"DST", ICON_DIST}, {"CHO", ICON_CHORUS}, {"DLY", ICON_DELAY}, {"REV", ICON_REVERB}, + {"VCE", ICON_VOICE}, {"GLD", ICON_GLIDE}, {"GLMOD", ICON_GLIDE}, {"PRIO", ICON_ORDER}, + {"ALLOC", ICON_VOICE}, {"DTUNE", ICON_DETUNE}, {"PAN", ICON_PAN}, {"MUTE", ICON_MUTE}, + /* global */ + {"BPM", ICON_TEMPO}, {"CLK", ICON_TEMPO}, {"TUNE", ICON_TUNE}, {"TIME", ICON_TIME}, + {"FDBK", ICON_FEEDBACK}, {"COLR", ICON_TONE}, {"MIX", ICON_MIX}, {"SIZE", ICON_SIZE}, + {"DAMP", ICON_DAMP}, {"CRT", ICON_RATE}, {"CDP", ICON_MOD}, {"MIDI", ICON_MIDI}, + {"SYNC", ICON_TEMPO}, {"ROUT", ICON_MIX}, {"CPU", ICON_CHIP}, {"SLOT", ICON_SAVE}, + {"LOAD", ICON_LOAD}, {"SAVE", ICON_SAVE}, {"ENG", ICON_WAVE}, {"CLRSQ", ICON_CLEAR}, + {"INIT", ICON_CLEAR}, {"ERASE", ICON_CLEAR}, {"CH", ICON_MIDI}, {"LEVEL", ICON_LEVEL}, + /* engines (eng_*.c edit[] labels) */ + {"DTN", ICON_DETUNE}, {"NOIS", ICON_NOISE}, {"CUT", ICON_CUTOFF}, {"RES", ICON_RESO}, + {"DRV", ICON_DRIVE}, {"KTR", ICON_KEYTRACK}, {"ALG", ICON_ALGORITHM}, {"R2", ICON_RATIO}, + {"R3", ICON_RATIO}, {"R4", ICON_RATIO}, {"IDX", ICON_MOD}, {"MDEC", ICON_DECAY}, + {"FB", ICON_FEEDBACK}, {"CHIP", ICON_CHIP}, {"DUTY", ICON_PULSE}, {"CRSH", ICON_BITS}, + {"SWP", ICON_SWEEP}, {"VIB", ICON_VIBRATO}, {"ARP", ICON_ARP}, {"TONE", ICON_TONE}, + {"SET", ICON_SAMPLE}, {"BITS", ICON_BITS}, {"LOOP", ICON_LOOP}, {"WAVE2", ICON_WAVE}, + {"DCW", ICON_SHAPE}, {"ENV", ICON_ENV}, {"LINE", ICON_MIX}, {"SUB", ICON_SUB}, + {"FOLD", ICON_FOLD}, {"WAV#", ICON_WAVE}, {"DCY", ICON_DECAY}, {"INT2", ICON_TRANSPOSE}, + {"INT3", ICON_TRANSPOSE}, {"PW", ICON_PULSE}, + {"REG", ICON_DRAWBAR}, {"BODY", ICON_LEVEL}, {"TOP", ICON_TONE}, {"PERC", ICON_DECAY}, + {"CLICK", ICON_ATTACK}, {"ROTR", ICON_VIBRATO}, + {"SRC", ICON_SAMPLE}, {"START", ICON_STEPS}, {"PTCH", ICON_PITCH}, {"DCAY", ICON_DECAY}, + {"POS", ICON_PHASE}, {"DENS", ICON_GRAIN}, {"SPRD", ICON_NOISE}, + {"VOWL", ICON_VOICE}, {"VOWL2", ICON_VOICE}, {"TALK", ICON_SWEEP}, {"SHIFT", ICON_TRANSPOSE}, + {"BUZZ", ICON_PULSE}, {"BRTH", ICON_NOISE}, {"Q", ICON_RESO}, {"RAND", ICON_PROB}, + /* fixed columns drawn by ui_draw.c (STEP page, preset browser, SYSTEM) */ + {"NOTE", ICON_PITCH}, {"STEP", ICON_STEPS}, {"FLAG", ICON_ACCENT}, {"ACC", ICON_ACCENT}, {"SLD", ICON_SLIDE}, {"USB", ICON_MIDI}, + {"TRACK", ICON_MIX}, /* TRACKS page (LEVEL, LEN, PAN: above) */ + {"SLCR", ICON_SLICE}, {"PAT", ICON_STEPS}, {"DEPTH", ICON_MIX}, /* SLICER page (RATE: param_icon) */ +}; + +static uint32_t icon_for_label(const char *l) +{ + uint32_t i; + if (!l || !l[0] || l[0] == '-') + return ICON_NONE; + for (i = 0; i < sizeof(ICON_MAP) / sizeof(ICON_MAP[0]); i++) + if (str_eq(l, ICON_MAP[i].label)) + return ICON_MAP[i].icon; + return ICON_GENERIC; +} + +/* WAVE / WAVE2 set to a shape: that shape's icon (value names of the engines and the LFO) */ +static const icon_map_t WAVE_ICON[] = { + {"SIN", ICON_W_SIN}, {"TRI", ICON_W_TRI}, {"SAW", ICON_W_SAW}, {"SQR", ICON_W_SQR}, + {"PLS", ICON_W_PLS}, {"PWM", ICON_W_PWM}, {"S&H", ICON_W_SH}, {"NOIS", ICON_NOISE}, + {"DSIN", ICON_W_DSIN}, {"SPLS", ICON_W_SPLS}, {"RSAW", ICON_W_RSAW}, {"RTRI", ICON_W_RTRI}, + {"RTRP", ICON_W_RTRP}, +}; + +static uint32_t param_icon(const param_desc_t *d, int32_t v) +{ + uint32_t i; + if (!d) + return ICON_NONE; + if (d->fmt == F_ENUM && d->names && v >= d->min && v <= d->max && + (str_eq(d->label, "WAVE") || str_eq(d->label, "WAVE2"))) + for (i = 0; i < sizeof(WAVE_ICON) / sizeof(WAVE_ICON[0]); i++) + if (str_eq(d->names[v], WAVE_ICON[i].label)) + return WAVE_ICON[i].icon; + if (d == &TP[P_LWAVE]) + return ICON_LFO_WAVE; /* "WAVE" is also the oscillator wave */ + if (d == &TP[P_ARATE] || d == &TP[P_SLRATE]) + return ICON_DIVISION; /* arp / SLICER RATE is a note division, not Hz */ + if (d->names == N_TRIO_MODE) + return ICON_CUTOFF; /* TRIO's MODE is the filter type, not the arp mode */ +#if FELUCCA_SLICE + if (d->names == N_SLC_DIV) + return ICON_SLICE; /* SLICE: DIV is the slicing, MODE the gate, REV the direction */ + if (d->names == N_SLC_MODE) + return ICON_GATE; + if (d->names == N_SLC_REV) + return ICON_ORDER; +#endif + return icon_for_label(d->label); +} + +/* engine name (ENGINES[]->name, or "DRUM") -> icon */ +static uint32_t engine_icon(const char *name) +{ + static const icon_map_t M[] = { + {"ANALOG", ICON_WAVE}, {"DIGITAL", ICON_ALGORITHM}, {"PHASE", ICON_PHASE}, {"LOFI", ICON_BITS}, + {"SAMPLE", ICON_SAMPLE}, {"VOICE", ICON_MOUTH}, {"TRIO", ICON_TRIO}, {"WHEEL", ICON_DRAWBAR}, + {"SLICE", ICON_SLICE}, + {"GRAIN", ICON_GRAIN}, + {"DRUM", ICON_DRUM}, + }; + uint32_t i; + for (i = 0; i < sizeof M / sizeof M[0]; i++) + if (str_eq(name, M[i].label)) + return M[i].icon; + return ICON_GENERIC; +} + +/* 2-bit icon, ink levels 1..3 = a third .. all of colour c (blended onto black, like cv_text) */ +static void cv_icon(int32_t x, int32_t y, uint32_t id, uint16_t c) +{ + uint16_t ramp[4]; + uint32_t r = c >> 11, g = (c >> 5) & 63u, b = c & 31u, a, i, j; + const uint8_t *p; + if (id >= FELUCCA_ICONS_N) + return; + for (a = 0; a < 4u; a++) + ramp[a] = (uint16_t)(((r * a / 3u) << 11) | ((g * a / 3u) << 5) | (b * a / 3u)); + p = ICON_DATA[id]; + for (j = 0; j < ICON_CELL; j++) + for (i = 0; i < ICON_CELL; i++) { + uint32_t k = j * ICON_CELL + i, v = (p[k >> 2] >> (6u - 2u * (k & 3u))) & 3u; + if (v) + cv_pset(x + (int32_t)i, y + (int32_t)j, ramp[v]); + } +} +#else +static uint32_t icon_for_label(const char *l) { (void)l; return ICON_NONE; } +static uint32_t param_icon(const param_desc_t *d, int32_t v) { (void)d; (void)v; return ICON_NONE; } +static uint32_t engine_icon(const char *name) { (void)name; return ICON_NONE; } +static void cv_icon(int32_t x, int32_t y, uint32_t id, uint16_t c) { (void)x; (void)y; (void)id; (void)c; } +#endif diff --git a/firmware/src/lcd.c b/firmware/src/lcd.c new file mode 100644 index 0000000..a337a3c --- /dev/null +++ b/firmware/src/lcd.c @@ -0,0 +1,130 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* ST7789-class 240x240 panel on SPI1: PC9 CLK, PC10 DO, PC7 CS, PC8 D/C, + * backlight PA2 active low. Polled DMA transfers; every source buffer must be + * in RAM. A pixel transfer is left running (lcd_busy): the next LCD access, or + * a write to its source buffer (lcd_sync), waits for it, so the main loop works + * while the last strip of a frame goes out. */ +/* pins and SPI1: hal/fm1_lcd_hw.h */ +#ifndef LCD_BAUD +#define LCD_BAUD 4u /* lsb/(BAUD+1): 4 = 12 MHz */ +#endif + +static uint8_t lcd_small[64]; +static uint8_t lcd_busy; /* a lcd_data DMA may still run; CS is low */ + +static void lcd_spin(uint32_t n) +{ + for (volatile uint32_t i = 0; i < n; i++) + ; +} + +static void lcd_sync(void) /* finish the running transfer (before touching its buffer) */ +{ + if (!lcd_busy) + return; + fm1_lcd_wait(); + fm1_lcd_deselect(); + lcd_busy = 0; +} + +static void lcd_cmd(uint8_t c) +{ + lcd_sync(); + fm1_lcd_send_cmd(c); + fm1_lcd_wait(); + fm1_lcd_deselect(); +} + +static void lcd_data(const void *p, uint32_t n) +{ + if (!n) + return; /* SPI_CNT = 0 never completes */ + lcd_sync(); + fm1_lcd_send_data(p, n); + lcd_busy = 1; /* completed by lcd_sync */ +} + +static void lcd_window(uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1) +{ + lcd_sync(); + lcd_small[0] = (uint8_t)(x0 >> 8); + lcd_small[1] = (uint8_t)x0; + lcd_small[2] = (uint8_t)(x1 >> 8); + lcd_small[3] = (uint8_t)x1; + lcd_cmd(0x2A); + lcd_data(lcd_small, 4); + lcd_small[4] = (uint8_t)(y0 >> 8); /* own bytes: the x transfer may still read [0..3] */ + lcd_small[5] = (uint8_t)y0; + lcd_small[6] = (uint8_t)(y1 >> 8); + lcd_small[7] = (uint8_t)y1; + lcd_cmd(0x2B); + lcd_data(lcd_small + 4, 4); + lcd_cmd(0x2C); +} + +static uint16_t lcd_fillbuf[240]; + +static void lcd_fill(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint16_t c) +{ + uint32_t i, n, k, sw = (uint16_t)((c >> 8) | (c << 8)); + if (!w || !h || x >= 240u || y >= 240u) + return; + if (x + w > 240u) + w = 240u - x; + if (y + h > 240u) + h = 240u - y; + lcd_sync(); + k = 240u / w * w; /* whole rows per transfer (narrow fills: one DMA) */ + for (i = 0; i < k; i++) + lcd_fillbuf[i] = (uint16_t)sw; + lcd_window(x, y, x + w - 1u, y + h - 1u); + for (n = w * h; n; n -= k) { + if (k > n) + k = n; + lcd_data(lcd_fillbuf, k * 2u); + } +} + +static void lcd_blit(uint32_t x, uint32_t y, uint32_t w, uint32_t h, const uint16_t *px) +{ + if (!w || !h) + return; + lcd_window(x, y, x + w - 1u, y + h - 1u); + lcd_data(px, w * h * 2u); +} + +/* ST7789V init: reset, then 16-bit colour, scan direction and IPS inversion; + * voltage and gamma stay at the defaults. Format: cmd, n, n data bytes; + * cmd 0x00 = wait (data byte: ~ms). */ +static const uint8_t LCD_SEQ[] = { + 0x01, 0, /* SWRESET */ + 0x00, 1, 150, + 0x11, 0, /* SLPOUT */ + 0x00, 1, 120, + 0x3A, 1, 0x55, /* COLMOD: RGB565 */ + 0x36, 1, 0x00, /* MADCTL: top-left origin, RGB order */ + 0x21, 0, /* INVON: IPS panel */ + 0x13, 0, /* NORON */ +}; + +static void lcd_init(void) +{ + uint32_t r, x; + fm1_lcd_hw_init(); + lcd_spin(2000000u); + for (r = 0; r < sizeof LCD_SEQ; r += 2u + LCD_SEQ[r + 1u]) { + if (LCD_SEQ[r] == 0x00u) { /* pseudo command: wait */ + lcd_spin(LCD_SEQ[r + 2u] * 25000u); /* ~1 ms per unit (lcd_spin(3000000) ~ 120 ms) */ + continue; + } + lcd_cmd(LCD_SEQ[r]); + for (x = 0; x < LCD_SEQ[r + 1u]; x++) + lcd_small[x] = LCD_SEQ[r + 2u + x]; + if (LCD_SEQ[r + 1u]) + lcd_data(lcd_small, LCD_SEQ[r + 1u]); + } + fm1_lcd_baud(LCD_BAUD); + lcd_fill(0, 0, 240, 240, 0); + lcd_cmd(0x29); +} diff --git a/firmware/src/libc.c b/firmware/src/libc.c new file mode 100644 index 0000000..3a5637f --- /dev/null +++ b/firmware/src/libc.c @@ -0,0 +1,86 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* The few libc routines the compiler may call implicitly (struct copies, + * zeroing). Freestanding: no other libc. */ +void *memset(void *d, int c, unsigned n) +{ + unsigned char *p = d; + while (n--) + *p++ = (unsigned char)c; + return d; +} + +void *memcpy(void *d, const void *s, unsigned n) +{ + unsigned char *p = d; + const unsigned char *q = s; + while (n--) + *p++ = *q++; + return d; +} + +int memcmp(const void *a, const void *b, unsigned n) +{ + const unsigned char *p = a, *q = b; + for (; n; n--, p++, q++) + if (*p != *q) + return *p - *q; + return 0; +} + +static int str_eq(const char *a, const char *b) +{ + while (*a && *a == *b) { + a++; + b++; + } + return *a == *b; +} + +static unsigned str_len(const char *s) +{ + unsigned n = 0; + while (s[n]) + n++; + return n; +} + +static void str_cpy(char *d, const char *s, unsigned max) +{ + unsigned i = 0; + while (s[i] && i + 1 < max) { + d[i] = s[i]; + i++; + } + d[i] = 0; +} + +/* decimal with an optional fixed point: fmt_fix(buf, -63, 1) -> "-6.3" */ +static void fmt_fix(char *b, int32_t v, int decimals) +{ + char t[12]; + int n = 0, neg = v < 0, i; + uint32_t u = (uint32_t)(neg ? -v : v); + do { + t[n++] = (char)('0' + u % 10u); + u /= 10u; + if (n == decimals) + t[n++] = '.'; + } while (u || n <= decimals); + if (neg) + t[n++] = '-'; + for (i = 0; i < n; i++) + b[i] = t[n - 1 - i]; + b[n] = 0; +} + +static void fmt_int(char *b, int32_t v) { fmt_fix(b, v, 0); } + +static uint32_t rng_state = 0x1234567u; +static uint32_t rng(void) +{ + rng_state ^= rng_state << 13; + rng_state ^= rng_state >> 17; + rng_state ^= rng_state << 5; + return rng_state; +} diff --git a/firmware/src/main.c b/firmware/src/main.c new file mode 100644 index 0000000..9324041 --- /dev/null +++ b/firmware/src/main.c @@ -0,0 +1,273 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* FELUCCA boot and main loop. Boot order: WDT first, boot-loop guard, fatal + * vectors, guards; then LCD, input (TIMER5 IRQ, 10 kHz), audio (ALNK0 IRQ). */ +extern uint32_t _data_start[], _data_end[], _data_load[], _bss_start[], _bss_end[]; +extern uint32_t _pool_start[], _pool_end[], _rt_start[], _rt_end[], _rt_load[]; + + +void fm1_timer5_irq(void) +{ + static uint32_t sub; + fm1_timer5_ack(); + felucca_dbg.timer_irqs++; + if (felucca_dbg.in_audio) + felucca_dbg.nested++; /* only possible if this IRQ outranks ALNK0 */ + fm1_input_tick(); + if (sub % 5u == 0u) + usb_poll(); /* 2 kHz: all USB SIE traffic lives here */ +#if FELUCCA_UART + if (sub % 5u == 2u) + uart_midi_poll(); /* 2 kHz: <= ~7 bytes per call at 31250 baud */ +#endif + if (++sub == 10u) + sub = 0; + { /* milliseconds from the 24 MHz TIMER4: TIMER5 ticks coalesce while ALNK0 renders */ + static uint32_t last, acc; + uint32_t now = fm1_ticks(); + acc += now - last; + last = now; + while (acc >= 1000u * FM1_TICKS_PER_US) { + acc -= 1000u * FM1_TICKS_PER_US; + fm1_ms++; + } + } +} +extern void isr_timer5(void); + +static void timer5_start(void) /* OSC /4 = 6 MHz, PRD 600 -> 10 kHz */ +{ + fm1_timer5_start(isr_timer5, 1); /* below ALNK0 (3): no nesting into audio */ +} + +static void hexs(char *b, uint32_t v) +{ + uint32_t i; + for (i = 0; i < 8u; i++) + b[i] = "0123456789ABCDEF"[(v >> (28u - 4u * i)) & 15u]; + b[8] = 0; +} + +static void fm1_fault(const fm1_crash_t *c) +{ + char b[12]; + uint32_t t0; + fm1_audio_stop(); + lcd_fill(0, 0, 240, 240, RGB(160, 0, 0)); + draw_text_box(0, 8, 240, &FONT_S, "FELUCCA CRASH", C_WHITE, 1); + hexs(b, c->vec); + draw_text_box(10, 40, 220, &FONT_S, b, C_WHITE, 0); + hexs(b, c->pc); + draw_text_box(10, 60, 220, &FONT_S, b, C_WHITE, 0); + hexs(b, c->emu); + draw_text_box(10, 84, 220, &FONT_S, b, C_WHITE, 0); + hexs(b, c->dbg); + draw_text_box(10, 102, 220, &FONT_S, b, C_WHITE, 0); + hexs(b, c->rets); + draw_text_box(10, 120, 220, &FONT_S, b, C_WHITE, 0); + t0 = fm1_ticks(); + while ((uint32_t)(fm1_ticks() - t0) < 4000u * 1000u * FM1_TICKS_PER_US) + ; + fm1_reboot(); +} + +/* power-on: three parts with their default sounds (TRK_DEF), the drum track, empty patterns */ +static void felucca_init(void) +{ + uint32_t i; + for (i = 0; i < G_COUNT; i++) + song.g[i] = GP[i].def; + 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]); /* with its sends */ + t->engine = t->eng_req; + } + track_defaults_steps(t); /* the sequencers start empty */ + } + TDRUM->p[P_E0] = DRUM_DEFAULT_KIT; /* the 808 kit */ + song.sel = 0; + song.master_q12 = 2048; + autosave_resume(); /* the project as it was left (project.c) */ + layers_init(); /* the panel's layer buttons for the keys (ui_layers.c) */ + go_home(); + ui.force = 1; +} + +static void fm1_main(void) +{ + int32_t knob = 512 * 16; + uint32_t healthy_since; + persist_boot(); +#if FELUCCA_OTA + if (flash_ok) + ota_boot_cleanup(); /* staging area left by an update */ +#endif + settings_init(); + lcd_init(); + sloop_splash(); /* the SLOOP logo (splash.c) */ + if (felucca_dbg.magic != DBG_MAGIC) { + memset(&felucca_dbg, 0, sizeof felucca_dbg); + felucca_dbg.magic = DBG_MAGIC; + } + felucca_dbg.boots++; + felucca_dbg.max_us = 0; + felucca_dbg.prev_stage = felucca_dbg.stage; /* a WDT reset leaves the last breadcrumb here */ + felucca_dbg.prev_page = felucca_dbg.page; + felucca_dbg.prev_home = felucca_dbg.home; + felucca_dbg.prev_frames = felucca_dbg.ui_frames; + felucca_dbg.prev_rst = fm1_boot.p3_rst; + fm1_input_init(); + fm1_adc_init(); + panel_init(); + felucca_init(); + audio_init(); + usb_start(); +#if FELUCCA_UART + uart_midi_init(); +#endif + timer5_start(); + fm1_guard_lock_top(); + fm1_irq_enable_all(); + fm1_delay_ms(30); + if ((fm1_in.buttons & 3u) == 3u) { + panel_setup(); /* OCT- + OCT+ held at power-on */ + settings_save(); + } + fm1_delay_ms(900); /* (the logo stays a moment) */ + lcd_fill(0, 0, 240, 240, C_BLACK); + + healthy_since = fm1_ms; + for (;;) { + uint32_t m = fm1_ms; + fm1_wdt_feed(); + usb_retry(fm1_ms); + if ((uint32_t)(m - healthy_since) >= 30000u && bootguard.pending) { + bootguard_clear(&bootguard); /* 30 s of this boot, even if TIMER4 survived reset */ + } + { + int32_t b = fm1_adc_read(FM1_ADC_BATT); /* battery: slow IIR */ + if (b > 0) + song.batt_raw = song.batt_raw ? song.batt_raw + (b - song.batt_raw) / 32 : b; + } + { + int32_t a = fm1_adc_read(FM1_ADC_MASTER); + if (a >= 0) { + uint32_t k10; + knob += (a * 16 - knob) / 8; + k10 = (uint32_t)(knob / 16); + song.master_q12 = (k10 * k10) >> 8; /* 0 .. ~4096 */ + } + } + { /* OCT- + OCT+ held 5 s: enter UBOOT with RAM intact (debug / update); a countdown + * shows from 2 s, letting go cancels it */ + static uint32_t t0, shown; + uint32_t both = (1u << panel.btn[B_OCTDN]) | (1u << panel.btn[B_OCTUP]); + if ((fm1_in.buttons & both) != both) { + if (shown) + ui_say("UPDATE MODE ", "CANCELLED"); + shown = 0; + t0 = fm1_ms; + } else if (fm1_ms - t0 > 2000u && fm1_ms - t0 <= 5000u) { + uint32_t left = (5000u - (fm1_ms - t0) + 999u) / 1000u; + if (left != shown) { + char d[4] = {(char)('0' + left), '.', '.', 0}; + ui_say("UPDATE MODE IN ", d); + shown = left; + } + } else if (fm1_ms - t0 > 5000u) { + fm1_audio_stop(); + lcd_fill(0, 0, 240, 240, C_BLACK); + draw_text_box(0, 110, 240, &FONT_S, "UBOOT", RGB(80, 120, 255), 1); + usb_detach(); + fm1_delay_ms(30); + bootguard.pending = 0; /* intentional reset: not a failed boot */ + fm1_enter_uboot(); + } + } +#if FELUCCA_OTA + ed_service(); /* web editor SysEx */ + ota_service(); /* M-UPGRADE handshake */ + if (usb.ota_req) { /* M-UPGRADE upgrade command */ + usb.ota_req = 0; + panic_req = (1u << NTRK) - 1u; /* every track (bit per track) */ + if (flash_ok) + ota_session(); /* returns only if nothing was committed */ + lcd_fill(0, 0, 240, 240, C_BLACK); + ui.force = 1; + } +#endif + if (usb.uboot_req) { /* SysEx F0 22 24 35 7D F7 from the host */ + fm1_audio_stop(); + lcd_fill(0, 0, 240, 240, C_BLACK); + draw_text_box(0, 110, 240, &FONT_S, "UBOOT (USB)", C_WHITE, 1); + fm1_delay_ms(20); + usb_detach(); + fm1_delay_ms(30); + bootguard.pending = 0; + fm1_enter_uboot(); + } +#if FELUCCA_CDC + cdc_task(); +#endif + felucca_dbg.ui_frames++; + felucca_dbg.page = ui.page; + felucca_dbg.home = ui.home; + felucca_dbg.stage = 1; + ui_input(); + felucca_dbg.stage = 2; + ui_leds(); + ui_draw(); + felucca_dbg.stage = 8; + autosave_tick(); /* the working project into flash, when quiet */ + felucca_dbg.stage = 9; + while (fm1_ms - m < 15u) { /* ~60 UI frames/s at most */ + ui_input(); +#if FELUCCA_OTA + ed_service(); /* editor replies without waiting for the next frame */ +#endif + } + } +} + +void fm1_cstart(void) +{ + uint32_t *s, *d, p3, src, wdt, boot_mode; + fm1_time_init(); + fm1_reset_reason(); + p3 = fm1_boot.p3_rst; + src = fm1_boot.rst_src; + wdt = fm1_boot.wdt_con; + fm1_wdt_arm(0x0D); + if ((p3 & 1u) && !(p3 & (4u | 0x40u))) + bootguard_clear(&bootguard); /* a power-on (not a watchdog or soft reset): no failed boot to count */ + boot_mode = bootguard_begin(&bootguard); + if (boot_mode == BOOT_ROM) { + fm1_enter_uboot(); + } + fm1_irq_init(); + for (d = _bss_start; d < _bss_end; d++) + *d = 0; + for (d = _pool_start; d < _pool_end; d++) + *d = 0; + for (s = _data_load, d = _data_start; d < _data_end; s++, d++) + *d = *s; + for (s = _rt_load, d = _rt_start; d < _rt_end; s++, d++) + *d = *s; /* flash driver code that must run from RAM */ + fm1_mailbox_clear(); + fm1_guard_enable(FM1_GUARD_STACK | FM1_GUARD_WRITE | FM1_GUARD_BUS | FM1_GUARD_PC); + fm1_boot.p3_rst = (uint8_t)p3; + fm1_boot.rst_src = src; + fm1_boot.wdt_con = (uint8_t)wdt; +#if FELUCCA_OTA + if (boot_mode == BOOT_RECOVERY || recovery_key()) + recovery_main(); +#else + if (boot_mode == BOOT_RECOVERY) fm1_enter_uboot(); +#endif + fm1_main(); + for (;;) + ; +} diff --git a/firmware/src/midi_uart.c b/firmware/src/midi_uart.c new file mode 100644 index 0000000..36de637 --- /dev/null +++ b/firmware/src/midi_uart.c @@ -0,0 +1,74 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* MIDI IN on the TRS jack: PH8 -> input channel 1 -> UART1 RX, 31250 baud, + * RX DMA into a 128-byte ring, polled from the TIMER5 ISR (no UART IRQ). + * Built only with FELUCCA_UART=1. Channel messages go into midi_in_q next to + * USB, as USB-MIDI packets (cable 0, CIN = status >> 4), so seq.c routes them by + * channel as it does USB; realtime, system common and SysEx are dropped. */ +#include "../hal/fm1_uart.h" /* registers; relative, so the host tests find it too */ + +#define UM_RING 128u +static volatile uint8_t um_ring[UM_RING] __attribute__((aligned(16))); +static struct { + uint32_t rd, pend, bytes, drops, msgs; + uint8_t st, need, got, d0, sysex; +} um; + +static void uart_midi_init(void) /* before timer5_start(): PORTH RMW */ +{ + fm1_uart1_midi_init(um_ring, UM_RING); +} + +static uint32_t um_len(uint32_t s) /* data bytes of a channel status */ +{ + return (s & 0xE0u) == 0xC0u ? 1u : 2u; /* Cx Dx: 1, else 2 */ +} + +static void um_byte(uint32_t b) +{ + if (b >= 0xF8u) + return; /* realtime: ignored, state kept */ + if (b & 0x80u) { + um.sysex = b == 0xF0u; + um.st = b < 0xF0u ? (uint8_t)b : 0; /* system common/SysEx cancel running status */ + um.need = (uint8_t)um_len(b); + um.got = 0; + return; + } + if (um.sysex || !um.st) + return; + if (um.need == 2u && !um.got) { + um.d0 = (uint8_t)b; + um.got = 1; + return; + } + { + uint32_t d1 = um.need == 2u ? um.d0 : b, d2 = um.need == 2u ? b : 0u; + uint32_t pkt = (um.st >> 4) | (uint32_t)um.st << 8 | d1 << 16 | d2 << 24; + um.got = 0; + if (mi_w - mi_r < MQ) { + midi_in_q[mi_w % MQ] = pkt; + RING_PUBLISH(); + mi_w++; + um.msgs++; + } else { + um.drops++; + } + } +} + +static void uart_midi_poll(void) /* TIMER5 ISR, same context as usb_poll */ +{ + um.pend += fm1_uart1_rx_take(); + if (um.pend > UM_RING) { + um.drops += um.pend - UM_RING; + um.rd = (um.rd + um.pend - UM_RING) & (UM_RING - 1u); + um.pend = UM_RING; + } + while (um.pend) { + um_byte(um_ring[um.rd]); + um.rd = (um.rd + 1u) & (UM_RING - 1u); + um.pend--; + um.bytes++; + } +} diff --git a/firmware/src/ota.c b/firmware/src/ota.c new file mode 100644 index 0000000..9dbfb30 --- /dev/null +++ b/firmware/src/ota.c @@ -0,0 +1,408 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* M-UPGRADE update entry. + * + * The updater talks SysEx (F0 pack7(00 59 cmd len24 body chk) F7): + * cmd 0x11 handshake -> we answer our package identity (FELUCCA_ID) + * F0 22 24 35 7F F7 upgrade -> ota_session(): pull parts of the package + * with cmd 0x30 read requests, check them, stage the package's update + * loader at 0xE0000 (outside Felucca's store), ask 0xE0000000 ("success"), + * then write the UPDATA_PARM record (flash 0xE4F00 + RAM 0x01C7FD88) and + * reset. The SPL runs the loader, which installs the package. + * Nothing is committed before the host's "success"; any failure erases the + * staging area and Felucca carries on. + * + * The firmware (felucca.c) and the host test supply these hooks: + * ota_wire_send(p, n) one complete F0..F7 message to the host + * ota_frame_get(&p, &n) next received SysEx (7-bit bytes between F0/F7), 0 if none + * ota_frame_done() release it + * ota_now_ms(), ota_idle() time; called while waiting (watchdog, USB) + * ota_erase(off) ota_prog(off, p, n) ota_fread(off, p, n) flash, 0 = ok + * ota_show(step, code) progress / result for the screen + * ota_commit(parm) write RAM record + reset (never returns on hardware) + */ +#define OTA_AREA 0x000E0000u /* staged loader, 5 x 4 KiB */ +#define OTA_AREA_LEN 0x5000u +#define OTA_RES (OTA_AREA + OTA_AREA_LEN - 0x100u) /* 0xE4F00 = 4K boundary - 256: SPL scan */ +#define OTA_LDR_HCRC 0xEBAAu /* official update loader (usb_hid_ota.bin) */ +#define OTA_LDR_DCRC 0x5881u +#define OTA_LDR_LEN 0x4DE1u +#define OTA_FRAME_MAX 640u /* 512-B response = 605 wire bytes */ + +static int ota_wire_send(const uint8_t *p, uint32_t n); +static int ota_frame_get(const uint8_t **p, uint32_t *n); +static void ota_frame_done(void); +static uint32_t ota_now_ms(void); +static void ota_idle(void); +static int ota_erase(uint32_t off); +static int ota_prog(uint32_t off, const void *p, uint32_t n); +static int ota_fread(uint32_t off, void *p, uint32_t n); +static void ota_show(uint32_t step, int32_t code); +static void ota_commit(const uint8_t *parm); + +static uint32_t ota_rd16(const uint8_t *p) { return (uint32_t)p[0] | (uint32_t)p[1] << 8; } +static uint32_t ota_rd24(const uint8_t *p) { return ota_rd16(p) | (uint32_t)p[2] << 16; } +static uint32_t ota_rd32(const uint8_t *p) { return ota_rd24(p) | (uint32_t)p[3] << 24; } +static void ota_wr16(uint8_t *p, uint32_t v) { p[0] = (uint8_t)v; p[1] = (uint8_t)(v >> 8); } +static void ota_wr32(uint8_t *p, uint32_t v) { ota_wr16(p, v); ota_wr16(p + 2, v >> 16); } + +static uint32_t ota_crc16(const uint8_t *p, uint32_t n, uint32_t c) /* poly 0x1021, init 0 */ +{ + uint32_t i; + while (n--) { + c ^= (uint32_t)*p++ << 8; + for (i = 0; i < 8u; i++) + c = c & 0x8000u ? (c << 1) ^ 0x1021u : c << 1; + c &= 0xFFFFu; + } + return c; +} + +static void ota_jl_enc(uint8_t *p, uint32_t n) /* UFW header cipher, key 0xFFFF */ +{ + uint32_t k = 0xFFFFu; + while (n--) { + *p++ ^= (uint8_t)k; + k = ((k << 1) ^ (k & 0x8000u ? 0x1021u : 0u)) & 0xFFFFu; + } +} + +/* 8-to-7, LSB first */ +static uint32_t ota_pack7(const uint8_t *in, uint32_t n, uint8_t *out) +{ + uint32_t acc = 0, nb = 0, o = 0; + while (n--) { + acc |= (uint32_t)*in++ << nb; + nb += 8u; + while (nb >= 7u) { + out[o++] = (uint8_t)(acc & 0x7Fu); + acc >>= 7; + nb -= 7u; + } + } + if (nb) + out[o++] = (uint8_t)(acc & 0x7Fu); + return o; +} + +static uint32_t ota_unpack7(const uint8_t *in, uint32_t n, uint8_t *out, uint32_t max) +{ + uint32_t acc = 0, nb = 0, o = 0; + while (n--) { + acc |= (uint32_t)(*in++ & 0x7Fu) << nb; + nb += 7u; + if (nb >= 8u) { + if (o < max) + out[o] = (uint8_t)acc; + o++; + acc >>= 8; + nb -= 8u; + } + } + return o; +} + +static uint8_t ota_msg[8 + 32], ota_wire[2 + 48]; +static uint8_t ota_dec[OTA_FRAME_MAX]; /* decoded host message */ + +static int ota_send_msg(uint32_t cmd, const uint8_t *body, uint32_t n) /* n <= 32 */ +{ + uint32_t i, s = 0, w; + ota_msg[0] = 0; + ota_msg[1] = 0x59; + ota_msg[2] = (uint8_t)cmd; + ota_msg[3] = (uint8_t)n; + ota_msg[4] = 0; + ota_msg[5] = 0; + for (i = 0; i < n; i++) { + ota_msg[6 + i] = body[i]; + s += body[i]; + } + ota_msg[6 + n] = (uint8_t)~s; + ota_wire[0] = 0xF0; + w = 1u + ota_pack7(ota_msg, 7u + n, ota_wire + 1); + ota_wire[w++] = 0xF7; + return ota_wire_send(ota_wire, w); +} + +static void ota_reply_identity(void) +{ +#ifdef OTA_IDENTITY + const char *id_text = OTA_IDENTITY; + uint8_t id[27]; + uint32_t i; + for (i = 0; i < sizeof id; i++) id[i] = 0; + for (i = 0; i < sizeof id && id_text[i]; i++) id[i] = (uint8_t)id_text[i]; +#else + static const char ID[] = FELUCCA_ID; /* loader / unmodified builds */ + uint8_t id[27]; + uint32_t i; + for (i = 0; i < sizeof id; i++) + id[i] = i < sizeof ID - 1u ? (uint8_t)ID[i] : 0; +#endif + ota_send_msg(0x11, id, sizeof id); +} + +/* decode the pending frame; returns its decoded length (0 = not ours) */ +static uint32_t ota_take(void) +{ + const uint8_t *p; + uint32_t n, d, s = 0, i; + if (!ota_frame_get(&p, &n)) + return 0; + d = ota_unpack7(p, n, ota_dec, sizeof ota_dec); + ota_frame_done(); + if (d < 7u || d > sizeof ota_dec || ota_dec[0] != 0 || ota_dec[1] != 0x59 || ota_rd24(ota_dec + 3) + 7u != d) + return 0; + for (i = 6; i + 1u < d; i++) + s += ota_dec[i]; + if ((uint8_t)~s != ota_dec[d - 1u]) + return 0; + return d; +} + +/* main loop, outside a session: answer handshakes */ +static void ota_service(void) +{ + uint32_t d = ota_take(); + if (d == 7u && ota_dec[2] == 0x11) + ota_reply_identity(); +} + +/* one read request (3 tries x 5 s); data -> dst */ +static uint32_t ota_deadline; /* 0 = none; else ota_now_ms() limit of the session */ + +static int ota_read(uint32_t addr, uint8_t *dst, uint32_t len) +{ + uint8_t q[8]; + uint32_t tries, t, d, i; + if (ota_deadline && (int32_t)(ota_now_ms() - ota_deadline) > 0) + return -1; /* the whole session took too long: give up */ + q[0] = 0; + ota_wr32(q + 1, addr); + q[5] = (uint8_t)len; + q[6] = (uint8_t)(len >> 8); + q[7] = 0; + for (tries = 0; tries < 3u; tries++) { + if (ota_send_msg(0x30, q, 8)) + return -1; + for (t = ota_now_ms(); ota_now_ms() - t < 5000u;) { + ota_idle(); + d = ota_take(); + if (!d) + continue; + if (d == 7u && ota_dec[2] == 0x11) { + ota_reply_identity(); + continue; + } + if (d == len + 15u && ota_dec[2] == 0x30 && ota_rd24(ota_dec + 3) == len + 8u && + ota_rd32(ota_dec + 7) == addr && ota_rd24(ota_dec + 11) == len) { + for (i = 0; i < len; i++) + dst[i] = ota_dec[14 + i]; + return 0; + } + } + } + return -1; +} + +static int ota_memeq(const uint8_t *a, const uint8_t *b, uint32_t n) +{ + while (n--) + if (*a++ != *b++) + return 0; + return 1; +} + +/* JLFS head "LOADER.BIN" in front of the staged loader (vm_update_defrag), written last */ +static int ota_stage_head(uint32_t len) +{ + static const char NAME[16] = "LOADER.BIN"; + uint8_t h[32]; + uint32_t i; + for (i = 0; i < 32u; i++) + h[i] = 0; + ota_wr16(h + 2, 0xFFFFu); + ota_wr32(h + 4, OTA_AREA); + ota_wr32(h + 8, len + 32u); + h[12] = 0x41u; + h[13] = 0xFFu; + ota_wr16(h + 14, 0xFFFFu); + for (i = 0; i < 16u; i++) + h[16 + i] = (uint8_t)NAME[i]; + ota_wr16(h, ota_crc16(h + 2, 30, 0)); + return ota_prog(OTA_AREA, h, 32); +} + +/* UFW header + entry list (hdr: 1 KiB) from the host -> offset / length of + * flash.bin (entry type 0) and ota.bin (type 100), 0 if absent, and the CRC16 the + * package stores for flash.bin (the loader checks what it was served against it); + * -1 read, -2 CRC */ +static int ota_ufw(uint8_t *hdr, uint32_t *fl_off, uint32_t *fl_len, uint32_t *ota_off, uint32_t *ota_len, + uint32_t *fl_crc) +{ + uint32_t i, nent; + *fl_off = *fl_len = *ota_off = *ota_len = *fl_crc = 0; + if (ota_read(0, hdr, 512) || ota_read(512, hdr + 512, 512)) + return -1; + ota_jl_enc(hdr, 0x40); + nent = ota_rd16(hdr + 8); + if (ota_crc16(hdr + 2, 0x3E, 0) != ota_rd16(hdr) || nent == 0 || nent > 11u || + ota_crc16(hdr + 0x40, nent * 0x50u, 0) != ota_rd16(hdr + 2)) + return -2; + for (i = 0; i < nent; i++) { + uint8_t *e = hdr + 0x40 + i * 0x50u; + ota_jl_enc(e, 0x50); + if (ota_rd16(e) == 0) { /* flash.bin */ + *fl_crc = ota_rd16(e + 4); + *fl_off = ota_rd32(e + 8); + *fl_len = ota_rd32(e + 12); + } + if (ota_rd16(e) == 100) { /* ota.bin */ + *ota_off = ota_rd32(e + 8); + *ota_len = ota_rd32(e + 12); + } + } + return 0; +} + +static int ota_stage(void) /* steps 1..6; 0 = host said success */ +{ + static uint8_t hdr[0x400], b[512], mine[512]; + uint32_t i, n, ota_off, ota_len, fl_off, fl_len, fl_crc, c, len, own, official; + int rc; + /* 1. UFW header + entry list */ + ota_show(1, 0); + if ((rc = ota_ufw(hdr, &fl_off, &fl_len, &ota_off, &ota_len, &fl_crc)) != 0) + return rc; + if (!fl_off || !ota_off) + return -3; + /* 2. which loader: the official one (known CRCs; it rewrites the whole flash.bin + * including the head) or Felucca's own (app area only, checks the chip key) */ + if (ota_read(ota_off, b, 512)) + return -6; + len = ota_rd32(b + 8); + if (ota_crc16(b + 2, 30, 0) != ota_rd16(b) || ota_rd32(b + 4) != 0x20u || b[12] != 0x41u || + ota_len != len + 0x20u || len > OTA_AREA_LEN - 0x200u || ota_crc16(b + 0x22, 30, 0) != ota_rd16(b + 0x20) || + ota_rd32(b + 0x20 + 8) != 0x01C0A800u) + return -7; + official = ota_rd16(b) == OTA_LDR_HCRC && ota_rd16(b + 2) == OTA_LDR_DCRC && len == OTA_LDR_LEN; + for (i = 0x48, own = 0; i + 16u <= 0x48u + 64u && !own; i++) /* first LZ4 literals: crt0_ldr.S */ + own = ota_memeq(b + i, (const uint8_t *)"FELUCCA-LOADER-1", 16) && ota_rd32(b + 0x20 + 4) <= 0x14000u; + if (!official && !own) + return -7; + if (official) { /* the official loader writes the head: it must equal ours */ + ota_show(2, 0); + for (i = 0; i < 0x4000u; i += 512u) { + if (ota_read(fl_off + i, b, 512) || ota_fread(i, mine, 512)) + return -4; + if (!ota_memeq(b, mine, 512)) + return -5; + } + } + /* 4. stage the package's loader: erase, body, verify, head last */ + ota_show(3, 0); + if (ota_read(ota_off, b, 512)) + return -6; + c = ota_rd16(b + 2); /* outer dcrc of the body */ + for (i = 0; i < OTA_AREA_LEN; i += 0x1000u) + if (ota_erase(OTA_AREA + i)) + return -8; + { + uint32_t crc = 0; + for (i = 0; i < len; i += n) { + n = len - i > 512u ? 512u : len - i; + if (ota_read(ota_off + 0x20u + i, b, n)) + return -9; + crc = ota_crc16(b, n, crc); + if (ota_prog(OTA_AREA + 32u + i, b, n)) + return -10; + } + if (crc != c) + return -11; + for (i = 0, crc = 0; i < len; i += n) { /* read back from flash */ + n = len - i > 512u ? 512u : len - i; + if (ota_fread(OTA_AREA + 32u + i, b, n)) + return -11; + crc = ota_crc16(b, n, crc); + } + if (crc != c) + return -11; + } + if (ota_stage_head(len)) + return -12; + /* 6. the host confirms: nothing is committed without it */ + ota_show(4, 0); + for (i = 0; i < 4u; i++) + if (!ota_read(0xE0000000u, b, 8) && ota_memeq(b, (const uint8_t *)"success", 8)) + return 0; + return -13; +} + +static void ota_unstage(void) +{ + uint32_t i; + for (i = 0; i < OTA_AREA_LEN; i += 0x1000u) + ota_erase(OTA_AREA + i); +} + +/* returns only when nothing was committed (refused, failed, or dry run) */ +static int ota_session(void) +{ + static uint8_t parm[112]; + uint8_t back[112]; + uint32_t i; + int rc; + ota_deadline = ota_now_ms() + 120000u; /* step 1 normally takes ~5 s; a stalled host gives up after 2 min */ + rc = ota_stage(); + if (rc) { + ota_unstage(); + ota_show(9, rc); + return rc; + } + /* 5./7. UPDATA_PARM (update_mode_api_v2 layout), flash copy first */ + for (i = 0; i < sizeof parm; i++) + parm[i] = 0; + ota_wr16(parm + 2, 0x5A0Du); + ota_wr16(parm + 4, 0x5A01u); + ota_wr16(parm + 6, 0x5441u); + for (i = 0; i < 12u; i++) + parm[8 + i] = (uint8_t)"ota-FM-1_015"[i]; /* the loader's own USB identity */ + ota_wr32(parm + 72, OTA_AREA); + ota_wr16(parm, ota_crc16(parm + 2, 78, 0)); +#if FELUCCA_OTA_DRYRUN + ota_unstage(); + ota_show(9, 1); /* 1 = dry run complete */ + return 1; +#endif +#ifndef FELUCCA_OTA_RAMONLY +#define FELUCCA_OTA_RAMONLY 0 /* 1: RAM record only, no power-loss resume (a power + * cycle leaves a broken loader behind) */ +#endif + if (!FELUCCA_OTA_RAMONLY && (ota_prog(OTA_RES, parm, sizeof parm) || ota_fread(OTA_RES, back, sizeof back) || + !ota_memeq(back, parm, sizeof parm))) { + ota_unstage(); + ota_show(9, -14); + return -14; + } + ota_show(5, 0); + ota_commit(parm); + return 0; +} + +/* boot: a staging area left over (we are running, so the update finished or + * never started): erase it so the SPL does not re-enter the loader */ +static int ota_boot_cleanup(void) +{ + uint8_t a[4], r[8]; + uint32_t i, used = 0; + if (ota_fread(OTA_AREA, a, 4) || ota_fread(OTA_RES, r, 8)) + return -1; + for (i = 0; i < 4u; i++) + used |= a[i] != 0xFFu; + for (i = 0; i < 8u; i++) + used |= r[i] != 0xFFu; + if (used) + ota_unstage(); + return (int)used; +} diff --git a/firmware/src/panel.c b/firmware/src/panel.c new file mode 100644 index 0000000..5a02736 --- /dev/null +++ b/firmware/src/panel.c @@ -0,0 +1,76 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* Physical panel: which matrix button / encoder carries which printed label. + * The default table can be overridden by HARDWARE CALIBRATION (hold OCT- and + * OCT+ while powering on), which asks for each label in turn. The learned + * table lives in .noinit and, with FELUCCA_FLASH, in flash with the settings + * (project.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 const char *const B_NAME[NB] = {"FX", "SCL", "ENV", "LFO", "EDIT", "GLO", "HOME", "SAVE", + "ARP", "SEQ", "PLAY", "REC", "OCT-", "OCT+"}; +static const char *const E_NAME[NE] = {"SELECT", "ALGORITHM", "PRESETS", "KNOB 1", "KNOB 2", + "KNOB 3", "KNOB 4"}; +#define PANEL_MAGIC 0x50414E35u /* "PAN5": bump when PANEL_DEFAULT changes */ + +typedef struct { + uint32_t magic; + uint8_t btn[NB]; /* matrix button id (0..13) per label */ + uint8_t enc[NE]; /* matrix encoder (0..6) per role */ + int8_t dir[NE]; /* +1 / -1 so that clockwise is + */ +} panel_t; +panel_t panel __attribute__((section(".noinit"))); + +static const panel_t PANEL_DEFAULT = { + PANEL_MAGIC, + {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 0, 1}, /* PLAY = 12, REC = 13 */ + {0, 1, 6, 2, 3, 4, 5}, /* SELECT = enc 0, ALGORITHM = enc 1, PRESETS = enc 6 */ + {1, 1, 1, 1, 1, 1, 1}, +}; + +static void panel_init(void) /* also after a flash load: ids are used as array indexes and shifts */ +{ + uint32_t i, ok = panel.magic == PANEL_MAGIC; + for (i = 0; ok && i < NB; i++) + ok = panel.btn[i] < 14u; + for (i = 0; ok && i < NE; i++) + ok = panel.enc[i] < 7u && (panel.dir[i] == 1 || panel.dir[i] == -1); + if (!ok) + panel = PANEL_DEFAULT; +} + +static uint32_t panel_btn_of(uint32_t matrix_id) /* label of a matrix button, NB if none */ +{ + uint32_t b; + for (b = 0; b < NB; b++) + if (panel.btn[b] == matrix_id) + return b; + return NB; +} + +static void panel_led(uint32_t label, int on) { fm1_led_key(panel.btn[label], on); } + +/* steps of a role, + = clockwise */ +static int32_t panel_enc(uint32_t role) +{ + return fm1_enc_take(panel.enc[role]) * panel.dir[role]; +} + +/* user settings that survive a reset */ +#define SETTINGS_MAGIC 0x53455433u /* "SET3" */ +struct { uint32_t magic, palette, lowcut, zoom; } settings __attribute__((section(".noinit"))); + +static void settings_save(void); /* project.c: flash copy (FELUCCA_FLASH) */ + +static void settings_init(void) +{ + if (settings.magic != SETTINGS_MAGIC || settings.palette >= NPALETTES) { + settings.magic = SETTINGS_MAGIC; + settings.palette = 4; /* MONO (default) */ + settings.lowcut = 0; + settings.zoom = 0; /* large readout of the touched value: off */ + } + palette_set(settings.palette); + fx_lowcut = (uint8_t)(settings.lowcut != 0); +} diff --git a/firmware/src/params.c b/firmware/src/params.c new file mode 100644 index 0000000..d8fd2ba --- /dev/null +++ b/firmware/src/params.c @@ -0,0 +1,337 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* Parameter descriptors, formatting and the page table. */ +static const char *const N_LWAVE[] = {"SIN", "TRI", "SAW", "SQR", "S&H"}; +static const char *const N_AMODE[] = {"OFF", "UP", "DN", "UPDN", "RND", "ORD"}; +static const char *const N_DIV[] = {"1/4", "1/8", "1/16", "1/32", "8T", "16T"}; +static const char *const N_SCALE[] = {"CHR", "MAJ", "MIN", "DOR", "MIX", "PEN", "MPEN", "HARM", + "PHRY", "LYD", "LOC", "MEL", "BLUES", "WHOLE", "DIMHW", "DIMWH"}; +static const char *const N_ONOFF[] = {"OFF", "ON"}; +static const char *const N_QUANT[] = {"OFF", "SNAP", "WHITE"}; /* seq.c kb_map; 1 = SNAP as the old ON */ +static const char *const N_VOICE[] = {"POLY", "MONO", "LEG", "UNI"}; /* V_POLY .. V_UNISON */ +static const char *const N_GLMODE[] = {"RATE", "TIME"}; +static const char *const N_PRIO[] = {"LAST", "LOW", "HIGH"}; +static const char *const N_ALLOC[] = {"ROT", "REUSE"}; +static const char *const N_ORDER[] = {"NOTE", "PLAY"}; +static const char *const N_CLICK[] = {"OFF", "REC", "ON"}; /* G_CLOCK is the metronome (seq.c click_tick) */ +static const char *const N_NOTE[] = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"}; +static const char *const N_DASH[] = {"--"}; +static const char *const N_GO[] = {"--", "GO"}; +static const char *const N_SLCR[] = {"OFF", "GATE", "STUT"}; /* SL_OFF .. SL_STUT (slicer.c) */ +static const char *const N_SLDIV[] = {"1/8", "1/16", "1/32", "8T", "16T", "32T"}; /* SL_DEN */ +static const char *const N_CHORD[] = {"OFF", "TRIAD", "7TH", "9TH", "SUS4", "POWER"}; /* seq.c CHORD_DEG */ +static const char *const N_ROLL[] = {"1/8", "1/16", "1/32", "32T", "1/64"}; /* seq.c ROLL_DEN */ +static const char *const N_ENGNAME[] = {"ANALOG", "DIGITAL", "PHASE", "LOFI", "SAMPLE", "VOICE", "TRIO", "WHEEL", "GRAIN", +#if FELUCCA_SLICE + "SLICE", +#endif +}; + +#define PD(l, f, mn, mx, df) {l, f, mn, mx, df, 0, 0} +#define PE(l, n, df) {l, F_ENUM, 0, (int16_t)(sizeof(n) / sizeof(n[0]) - 1), df, n, 0} + +static const param_desc_t TP[P_COUNT] = { + [P_LEVEL] = PD("LVL", F_DB, 0, 127, 104), + [P_ATK] = PD("ATK", F_TIME, 0, 127, 10), + [P_DEC] = PD("DEC", F_TIME, 0, 127, 70), + [P_SUS] = PD("SUS", F_PCT, 0, 127, 90), + [P_REL] = PD("REL", F_TIME, 0, 127, 60), + [P_ED_FLT] = PD("FLT", F_BIPCT, -64, 63, 0), + [P_ED_PIT] = PD("PIT", F_BIPCT, -64, 63, 0), + [P_ED_SHP] = PD("SHP", F_BIPCT, -64, 63, 0), + [P_ED_FX] = PD("FX", F_BIPCT, -64, 63, 0), + [P_LRATE] = PD("RATE", F_LFOHZ, 0, 127, 60), + [P_LWAVE] = PE("WAVE", N_LWAVE, 0), + [P_LPHASE] = PD("PHS", F_INT, 0, 127, 0), + [P_LFADE] = PD("FADE", F_TIME, 0, 127, 0), + [P_LD_PIT] = PD("PIT", F_BIPCT, -64, 63, 0), + [P_LD_FLT] = PD("FLT", F_BIPCT, -64, 63, 0), + [P_LD_SHP] = PD("SHP", F_BIPCT, -64, 63, 0), + [P_LD_AMP] = PD("AMP", F_PCT, 0, 127, 0), + [P_AMODE] = PE("MODE", N_AMODE, 0), + [P_ARATE] = PE("RATE", N_DIV, 2), + [P_AOCT] = PD("OCT", F_INT, 1, 4, 1), + [P_AGATE] = PD("GATE", F_PCT, 1, 127, 64), + [P_ASWING] = PD("SWG", F_SWING, 0, 100, 0), + [P_APROB] = PD("PROB", F_PCT, 0, 127, 127), + [P_AHOLD] = PE("HOLD", N_ONOFF, 0), + [P_AORDER] = PE("ORD", N_ORDER, 0), + [P_ROOT] = PD("ROOT", F_NOTE, 0, 11, 0), + [P_SCALE] = PE("SCL", N_SCALE, 0), + [P_QUANT] = PE("QNT", N_QUANT, 0), + [P_TRANS] = PD("TRN", F_SEMI, -24, 24, 0), + [P_SLEN] = PD("LEN", F_STEPS, 1, NSTEP, 16), + [P_SDIV] = PE("DIV", N_DIV, 2), + [P_SSWING] = PD("SWG", F_SWING, 0, 100, 0), + [P_SGATE] = PD("GATE", F_PCT, 1, 127, 64), + [P_DIST] = PD("DST", F_PCT, 0, 127, 0), + [P_CHOR] = PD("CHO", F_PCT, 0, 127, 0), + [P_DLY] = PD("DLY", F_PCT, 0, 127, 0), + [P_REV] = PD("REV", F_PCT, 0, 127, 0), + [P_VOICE] = PE("VCE", N_VOICE, 0), + [P_GLIDE] = PD("GLD", F_TIME, 0, 127, 0), + [P_GLMODE] = PE("GLMOD", N_GLMODE, 0), + [P_PRIO] = PE("PRIO", N_PRIO, 0), + [P_ALLOC] = PE("ALLOC", N_ALLOC, 0), + [P_DETUNE] = PD("DTUNE", F_INT, 0, 127, 40), + [P_PAN] = PD("PAN", F_BIPCT, -64, 63, 0), + [P_MUTE] = PE("MUTE", N_ONOFF, 0), + [P_SLCR] = PE("SLCR", N_SLCR, 0), + [P_SLPAT] = PD("PAT", F_INT, 1, 16, 1), /* SL_PAT[] */ + [P_SLRATE] = PE("RATE", N_SLDIV, 1), + [P_SLDEPTH] = PD("DEPTH", F_PCT, 0, 127, 127), + [P_CHORD] = PE("CHORD", N_CHORD, 0), +}; +/* a preset's extra parameters (preset_t.x) into p, each clamped to its range */ +static void preset_extras(int16_t *p, const preset_t *pr) +{ + uint32_t i; + for (i = 0; i + 1u < 8u; i += 2u) { + int32_t id = pr->x[i] - 1; + if (id >= 0 && id < P_E0) + p[id] = (int16_t)clamp(pr->x[i + 1u], TP[id].min, TP[id].max); + } +} + + +static const param_desc_t GP[G_COUNT] = { + [G_BPM] = PD("BPM", F_BPM, 40, 240, 90), + [G_SWING] = PD("SWING", F_SWING, 0, 100, 0), + [G_CLOCK] = PE("CLICK", N_CLICK, 0), /* (the old CLK slot: projects keep their format) */ + [G_TUNE] = PD("TUNE", F_INT, -50, 50, 0), + [G_DTIME] = PE("TIME", N_DIV, 1), + [G_DFDBK] = PD("FDBK", F_PCT, 0, 120, 60), + [G_DCOLOR] = PD("COLR", F_PCT, 0, 127, 70), + [G_DMIX] = PD("MIX", F_PCT, 0, 127, 90), + [G_RSIZE] = PD("SIZE", F_PCT, 0, 127, 90), + [G_RDAMP] = PD("DAMP", F_PCT, 0, 127, 60), + [G_CRATE] = PD("CRT", F_LFOHZ, 0, 127, 40), + [G_CDEPTH] = PD("CDP", F_PCT, 0, 127, 60), + [G_MIDI] = PE("MIDI", N_DASH, 0), + [G_SYNC] = PE("SYNC", N_DASH, 0), + [G_ROUTE] = PE("ROUT", N_DASH, 0), + [G_INFO] = PD("CPU", F_INT, 0, 0, 0), + [G_SLOT] = PD("SLOT", F_INT, 1, 4, 1), + [G_NAME] = PE("NAME", N_DASH, 0), + [G_LOAD] = PE("LOAD", N_GO, 0), + [G_SAVE] = PE("SAVE", N_GO, 0), + [G_ENGSEL] = PE("ENG", N_ENGNAME, 0), + [G_ENGGO] = PE("SET", N_GO, 0), + [G_CLRSEQ] = PE("CLRSQ", N_GO, 0), + [G_INITSND] = PE("INIT", N_GO, 0), + [G_DRCH] = PD("CH", F_INT, 0, 16, 10), /* GM drum part MIDI channel, 0 = off */ + [G_DRLVL] = PD("LVL", F_INT, 0, 127, 100), + [G_DRREV] = PD("REV", F_INT, 0, 127, 16), + [G_DUST] = PD("DUST", F_PCT, 0, 127, 0), + [G_DUCK] = PD("DUCK", F_PCT, 0, 127, 0), + [G_FILT] = PD("FILT", F_FILT, -64, 63, 0), + [G_ROLL] = PE("ROLL", N_ROLL, 1), + [G_NEWPRJ] = PE("NEW", N_GO, 0), +}; + +static const param_desc_t DRUM_KIT_DESC = PE("KIT", DRUM_KIT_NAMES, 0); +static const param_desc_t *track_desc(const track_t *t, uint32_t id) +{ + if(is_drum(t) && id==P_E0) return &DRUM_KIT_DESC; + if (id >= P_E0 && id <= P_E7) { /* the engine asked for (t->engine follows after a fade) */ + const engine_t *e = ENGINES[t->eng_req % NENGINES]; + const param_desc_t *d = e->desc ? e->desc(t, id - P_E0) : 0; /* a mode-dependent label / names */ + return d ? d : &e->edit[id - P_E0]; + } + return &TP[id]; +} + +/* value string (<= 5 chars) and unit for a parameter value */ +static void param_format(const param_desc_t *d, int32_t v, char *val, const char **unit) +{ + *unit = ""; + switch (d->fmt) { + case F_PCT: /* of the range: 0 .. 100 % */ + fmt_int(val, d->max > 0 ? (v * 100 + d->max / 2) / d->max : v); + *unit = "%"; + break; + case F_SWING: /* MPC style: the share of a step pair the first one gets */ + fmt_int(val, 50 + (clamp(v, 0, 100) + 2) / 4); + *unit = "%"; + break; + case F_FILT: /* LP 1..100 % closed, HP 1..100 % */ + if (!v) { + str_cpy(val, "OFF", 6); + } else { + str_cpy(val, v < 0 ? "LP" : "HP", 6); + fmt_int(val + 2, v < 0 ? (-v * 100 + 32) / 64 : (v * 100 + 31) / 63); + *unit = "%"; + } + break; + case F_BIPCT: + fmt_int(val, v * 100 / 64); + if (v > 0) { + char t[8]; + fmt_int(t, v * 100 / 64); + val[0] = '+'; + str_cpy(val + 1, t, 6); + } + *unit = "%"; + break; + case F_TIME: { + uint32_t ms10 = TIME_MS_X10[v & 127]; + if (ms10 < 100u) { + fmt_fix(val, (int32_t)ms10, 1); + *unit = "ms"; + } else if (ms10 < 10000u) { + fmt_int(val, (int32_t)((ms10 + 5u) / 10u)); + *unit = "ms"; + } else { + fmt_fix(val, (int32_t)(ms10 / 100u), 2); + if (ms10 >= 100000u) + fmt_fix(val, (int32_t)(ms10 / 1000u), 1); + *unit = "s"; + } + break; + } + case F_LFOHZ: { + uint32_t h = LFO_HZ_X100[v & 127]; + if (h < 1000u) + fmt_fix(val, (int32_t)h, 2); + else + fmt_fix(val, (int32_t)(h / 10u), 1); + *unit = "Hz"; + break; + } + case F_CUTOFF: { + uint32_t h = CUTOFF_HZ[v & 127]; + if (h < 1000u) { + fmt_int(val, (int32_t)h); + *unit = "Hz"; + } else { + fmt_fix(val, (int32_t)(h / 100u), 1); + *unit = "kHz"; + } + break; + } + case F_DB: + if (v <= 0) { + str_cpy(val, "OFF", 6); + } else { + fmt_fix(val, LEVEL_DB_X10[v], 1); + *unit = "dB"; + } + break; + case F_SEMI: + fmt_int(val, v); + if (v > 0) { + char t[8]; + fmt_int(t, v); + val[0] = '+'; + str_cpy(val + 1, t, 6); + } + *unit = "st"; + break; + case F_ENUM: + str_cpy(val, d->names[v < d->min ? d->min : v > d->max ? d->max : v], 6); + if (d->unit) + *unit = d->unit; + break; + case F_BPM: + fmt_int(val, v); + *unit = "BPM"; + break; + case F_NOTE: + str_cpy(val, N_NOTE[v % 12], 6); + break; + case F_ONOFF: + str_cpy(val, N_ONOFF[v ? 1 : 0], 6); + break; + case F_STEPS: + fmt_int(val, v); + *unit = "STEP"; + break; + default: + if (d->names) { /* F_INT with a 0-terminated name list: the range */ + uint32_t k = 0; /* split evenly over the names (engine desc hooks) */ + while (d->names[k]) + k++; + str_cpy(val, d->names[(uint32_t)(clamp(v, d->min, d->max) - d->min) * k / (uint32_t)(d->max - d->min + 1)], 6); + } else { + fmt_int(val, v); + } + if (d->unit) + *unit = d->unit; + break; + } +} + +/* ------------------------------------------------------------ pages --- */ +enum { FAM_HOME, FAM_ENV, FAM_LFO, FAM_FX, FAM_SCL, FAM_EDIT, FAM_GLO, FAM_SAVE, FAM_ARP, FAM_SEQ, FAM_TRK, + FAM_COUNT }; +enum { SC_TRACK, SC_GLOBAL, SC_ENGINE, SC_STEP, SC_TRK, SC_SONG, SC_DRUM }; +enum { GR_NONE, GR_ADSR, GR_LFO, GR_STEPS, GR_ARP, GR_SCALE, GR_FX, GR_ROLL, GR_BROWSE, GR_SLOTS, GR_USER, GR_TRK, + GR_SLCR }; + +typedef struct { + const char *title; + uint8_t fam, scope, graph; + uint8_t id[4]; /* param ids; 0xFF = empty slot */ +} page_t; + +static const page_t PAGES[] = { + {"ENV", FAM_ENV, SC_TRACK, GR_ADSR, {P_ATK, P_DEC, P_SUS, P_REL}}, + {"ENV DEST", FAM_ENV, SC_TRACK, GR_NONE, {P_ED_FLT, P_ED_PIT, P_ED_SHP, 0xFF}}, /* (P_ED_FX: nothing reads it) */ + {"LFO", FAM_LFO, SC_TRACK, GR_LFO, {P_LRATE, P_LWAVE, P_LPHASE, P_LFADE}}, + {"LFO DEST", FAM_LFO, SC_TRACK, GR_NONE, {P_LD_PIT, P_LD_FLT, P_LD_SHP, P_LD_AMP}}, + {"FX", FAM_FX, SC_TRACK, GR_FX, {P_DIST, P_CHOR, P_DLY, P_REV}}, + {"SLICER", FAM_FX, SC_TRACK, GR_SLCR, {P_SLCR, P_SLPAT, P_SLRATE, P_SLDEPTH}}, /* drum track too */ + {"DLY", FAM_FX, SC_GLOBAL, GR_NONE, {G_DTIME, G_DFDBK, G_DCOLOR, G_DMIX}}, + {"REV/CHO", FAM_FX, SC_GLOBAL, GR_NONE, {G_RSIZE, G_RDAMP, G_CRATE, G_CDEPTH}}, + {"SCL", FAM_SCL, SC_TRACK, GR_SCALE, {P_ROOT, P_SCALE, P_QUANT, P_CHORD}}, + {"SCL 2", FAM_SCL, SC_TRACK, GR_SCALE, {P_TRANS, 0xFF, 0xFF, 0xFF}}, + {"EDIT 1", FAM_EDIT, SC_ENGINE, GR_NONE, {P_E0, P_E1, P_E2, P_E3}}, + {"EDIT 2", FAM_EDIT, SC_ENGINE, GR_NONE, {P_E4, P_E5, P_E6, P_E7}}, + {"VOICE", FAM_EDIT, SC_TRACK, GR_NONE, {P_VOICE, P_GLIDE, P_GLMODE, P_PRIO}}, + {"VOICE 2", FAM_EDIT, SC_TRACK, GR_NONE, {P_ALLOC, P_DETUNE, P_PAN, P_MUTE}}, + {"GLOBAL", FAM_GLO, SC_GLOBAL, GR_NONE, {G_BPM, G_SWING, G_CLOCK, G_TUNE}}, + {"MASTER", FAM_GLO, SC_GLOBAL, GR_NONE, {G_DUST, G_DUCK, G_FILT, G_ROLL}}, + {"SYSTEM", FAM_GLO, SC_GLOBAL, GR_NONE, {G_MIDI, G_SYNC, G_ROUTE, G_INFO}}, + {"DRUMS", FAM_GLO, SC_GLOBAL, GR_NONE, {G_DRCH, G_DRLVL, G_DRREV, 0xFF}}, /* GM kit on MIDI ch 10 */ + {"PRESETS", FAM_SAVE, SC_GLOBAL, GR_BROWSE, {0xFF, 0xFF, 0xFF, 0xFF}}, /* browser: PRESETS knob / KNOB 1 */ + {"USER", FAM_SAVE, SC_GLOBAL, GR_USER, {0xFF, 0xFF, 0xFF, 0xFF}}, /* user presets: SLOT LOAD ERASE SAVE */ + {"PROJECT", FAM_SAVE, SC_GLOBAL, GR_SLOTS, {G_SLOT, 0xFF, G_LOAD, G_SAVE}}, + {"TOOLS", FAM_SAVE, SC_GLOBAL, GR_NONE, {G_CLRSEQ, G_INITSND, 0xFF, G_NEWPRJ}}, + {"ARP", FAM_ARP, SC_TRACK, GR_ARP, {P_AMODE, P_ARATE, P_AOCT, P_AGATE}}, + {"ARP 2", FAM_ARP, SC_TRACK, GR_NONE, {P_ASWING, P_APROB, P_AHOLD, P_AORDER}}, + {"STEP", FAM_SEQ, SC_STEP, GR_ROLL, {0, 1, 2, 3}}, + {"PATTERN", FAM_SEQ, SC_TRACK, GR_STEPS, {P_SLEN, P_SDIV, P_SSWING, P_SGATE}}, + {"SONG", FAM_SEQ, SC_SONG, GR_NONE, {0xFF, 0xFF, 0xFF, 0xFF}}, + {"TRACKS", FAM_TRK, SC_TRK, GR_TRK, {0, 1, 2, 3}}, /* REC button; TRACK LEVEL LEN PAN */ + {"DRUMS", FAM_TRK, SC_DRUM, GR_NONE, {0xFF,0xFF,0xFF,0xFF}}, +}; +#define NPAGES (sizeof(PAGES) / sizeof(PAGES[0])) + +/* the drum track has no sound of its own: it uses the global pages (not the preset + * pages, nor TOOLS > INIT: page_desc), STEP, PATTERN, SLICER and TRACKS; every other page + * shows "DRUM TRACK" */ +static int page_for_drum(const page_t *pg) +{ + if (pg->scope == SC_GLOBAL) + return pg->graph != GR_BROWSE && pg->graph != GR_USER; + return pg->scope != SC_ENGINE && (pg->scope != SC_TRACK || pg->fam == FAM_SEQ || pg->graph == GR_SLCR); +} + +static const param_desc_t *page_desc(const page_t *pg, uint32_t slot, int16_t **valp) +{ + uint32_t id = pg->id[slot]; + if (id == 0xFFu || (is_drum(TSEL) && (!page_for_drum(pg) || (pg->scope == SC_GLOBAL && id == G_INITSND)))) { + *valp = 0; + return 0; + } + if (pg->scope == SC_STEP || pg->scope == SC_TRK) { + *valp = 0; + return 0; + } + if (pg->scope == SC_GLOBAL) { + *valp = &song.g[id]; + return &GP[id]; + } + *valp = &TSEL->p[id]; + return track_desc(TSEL, id); +} diff --git a/firmware/src/project.c b/firmware/src/project.c new file mode 100644 index 0000000..624452f --- /dev/null +++ b/firmware/src/project.c @@ -0,0 +1,538 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* Projects: four slots in .noinit RAM (the song sections A..D), so they survive resets and UBOOT + * entry. With FELUCCA_FLASH every save also goes to flash through storage.c, and an empty RAM slot + * is filled from flash on load. The working project is also kept in flash by itself (autosave, when + * the transport is stopped and nothing sounds) and comes back at power-on: SLOOP starts where you + * left it. + * + * Formats: 4 ("FUN4", written, SLOOP 2.0): today's P_COUNT / G_COUNT, 10-byte steps (levels and + * ratchets; the drum track: 16 lanes). Read and converted: 3 ("FUN3", SLOOP 1.x: 8-byte steps, the + * drum track's notes become its lanes, the swings x 0.8 for the MPC scale), 2 ("FUN2") and 1 ("FUN1"), + * which held PROJ_NP_V2 parameters per track, mapped by count as user presets are (the first + * PROJ_NP_V2 - 8 are P_LEVEL.. in order, the last 8 P_E0..P_E7; the parameters added since take their + * defaults). Their engine bytes are kept: formats 1 and 2 had engines 0..7 (ANALOG .. WHEEL), and the + * engines added since were appended, no index moved; the drum track's byte (it has no engine) becomes 0. + * + * Built on the host too (tests/project_test.c, -DPROJ_HOST): the part above the #ifndef + * PROJ_HOST needs core.h, params.c (TP), drums.c (the lanes), the engines and trk_def_engine (ui.c). */ +#define PROJ_MAGIC 0x46554E34u /* "FUN4": four tracks, P_COUNT parameters each, 10-byte steps */ +#define PROJ_MAGIC_V3 0x46554E33u /* "FUN3": SLOOP 1.x; read only */ +#define PROJ_MAGIC_V2 0x46554E32u /* "FUN2": four tracks, PROJ_NP_V2 parameters; read only */ +#define PROJ_MAGIC_V1 0x46554E31u /* "FUN1": one instrument; loads into track 1 */ +#define PROJ_NP_V3 57u /* P_COUNT of format 3 (P_E0 was 49) */ +#define PROJ_NG_V3 27u /* G_COUNT of formats 1..3 */ +#define PROJ_NP_V2 53u /* P_COUNT of formats 1 and 2 (P_E0 was 45) */ +#define PROJ_NG_V2 27u /* G_COUNT of formats 1 and 2 */ +typedef struct { /* one track; the drum track ignores engine / preset */ + int16_t p[P_COUNT]; + uint8_t engine, preset; + union { + step_t step[NSTEP]; + dstep_t dstep[NSTEP]; /* (the drum track: 16 lanes, the same size) */ + }; +} proj_trk_t; +typedef struct { + uint32_t magic, size; + int16_t g[G_COUNT]; + uint8_t sel, rsv[3]; /* the selected track */ + proj_trk_t t[NTRK]; + uint32_t sum; +} project_t; +typedef struct { uint8_t note[4], n, time, flags, vel; } step8_t; /* the steps of formats 1..3 */ +typedef struct { /* a track of format 3, read only */ + int16_t p[PROJ_NP_V3]; + uint8_t engine, preset; + step8_t step[NSTEP]; +} proj_trk_v3_t; +typedef struct { /* format 3 (SLOOP 1.x), read only */ + uint32_t magic, size; + int16_t g[PROJ_NG_V3]; + uint8_t sel, rsv[3]; + proj_trk_v3_t t[NTRK]; + uint32_t sum; +} project_v3_t; +typedef struct { /* a track of formats 1 and 2, read only */ + int16_t p[PROJ_NP_V2]; + uint8_t engine, preset; + step8_t step[NSTEP]; +} proj_trk_v2_t; +typedef struct { /* format 2 (until 0.9), read only */ + uint32_t magic, size; + int16_t g[PROJ_NG_V2]; + uint8_t sel, rsv[3]; + proj_trk_v2_t t[NTRK]; + uint32_t sum; +} project_v2_t; +typedef struct { /* format 1 (until 0.5 beta), read only */ + uint32_t magic, size; + int16_t g[PROJ_NG_V2]; + proj_trk_v2_t t; + uint32_t sum; +} project_v1_t; +_Static_assert(sizeof(project_v2_t) == 2552u && sizeof(project_v1_t) == 688u && sizeof(project_v3_t) == 2584u, + "formats 1 / 2 / 3 as they were stored"); +project_t proj_slot[4] __attribute__((section(".noinit"))); + +static uint32_t proj_hash(const void *p, uint32_t n) /* FNV-1a over n bytes */ +{ + const uint8_t *b = (const uint8_t *)p; + uint32_t i, s = 0x811C9DC5u; + for (i = 0; i < n; i++) + s = (s ^ b[i]) * 16777619u; + return s; +} +static uint32_t proj_sum(const project_t *p) { return proj_hash(p, sizeof *p - 4u); } +static int proj_ok(const project_t *q) { return q->magic == PROJ_MAGIC && q->size == sizeof *q && q->sum == proj_sum(q); } + +/* ---- old formats -> format 4 */ +/* an old step into a synth step (no level, no ratchet) */ +static void step_from8(step_t *d, const step8_t *s) +{ + memcpy(d->note, s->note, 4); + d->n = s->n; + d->time = s->time; + d->flags = s->flags; + d->vel = s->vel; + d->lvl = d->rat = 0; +} +/* an old drum step (GM notes) into the drum track's lanes; its velocity / accent -> their level */ +static void dstep_from8(dstep_t *d, const step8_t *s) +{ + uint32_t i, lvl = (s->flags & SF_ACCENT) || s->vel > 115u ? LV_HARD : !s->vel ? LV_NORM : vel_lvl(s->vel); + memset(d, 0, sizeof *d); + if (s->time != ST_NOTE) + return; + for (i = 0; i < s->n && i < 4u; i++) + dstep_set(d, lane_of_note(s->note[i] & 127u), lvl, 0); +} +static int16_t swing_from_v3(int32_t v) { return (int16_t)clamp((v * 4 + 2) / 5, 0, 100); } /* /250 -> /200 */ + +/* the globals of formats 1..3 (G_* unchanged since; any added later: their defaults) */ +static void proj_g_from_old(int16_t *g, const int16_t *g2) +{ + uint32_t i; + for (i = 0; i < G_COUNT; i++) + g[i] = i < PROJ_NG_V3 ? g2[i] : GP[i].def; + g[G_SWING] = swing_from_v3(g[G_SWING]); +} + +/* a track of format 3 -> today's (by id up to P_SLDEPTH; P_E0.. moved) */ +static void proj_trk_from_v3(proj_trk_t *d, const proj_trk_v3_t *s, int drum) +{ + uint32_t k, nc = PROJ_NP_V3 - 8u; + for (k = 0; k < P_E0; k++) + d->p[k] = k < nc ? s->p[k] : TP[k].def; + for (k = 0; k < 8u; k++) + d->p[P_E0 + k] = s->p[nc + k]; + d->p[P_SSWING] = swing_from_v3(d->p[P_SSWING]); + d->p[P_ASWING] = swing_from_v3(d->p[P_ASWING]); + d->engine = drum ? 0u : s->engine; + d->preset = drum ? 0u : s->preset; + for (k = 0; k < NSTEP; k++) { + if (drum) + dstep_from8(&d->dstep[k], &s->step[k]); + else + step_from8(&d->step[k], &s->step[k]); + } +} + +/* a track of formats 1 and 2 -> format 3 (mapped by count, see the top) */ +static void proj_trk_v2_to_v3(proj_trk_v3_t *d, const proj_trk_v2_t *s, int drum) +{ + uint32_t k, nc = PROJ_NP_V2 - 8u; + for (k = 0; k < PROJ_NP_V3 - 8u; k++) + d->p[k] = k < nc ? s->p[k] : TP[k].def; + for (k = 0; k < 8u; k++) + d->p[PROJ_NP_V3 - 8u + k] = s->p[nc + k]; + d->engine = drum ? 0u : s->engine; /* (indices 0..7 as they were) */ + d->preset = drum ? 0u : s->preset; + memcpy(d->step, s->step, sizeof d->step); +} + +/* a format 3 project -> slot q as format 4 */ +static void proj_from_v3_ok(project_t *q, const project_v3_t *v3) +{ + uint32_t i; + memset(q, 0, sizeof *q); + q->magic = PROJ_MAGIC; + q->size = sizeof *q; + proj_g_from_old(q->g, v3->g); + q->sel = v3->sel; + for (i = 0; i < NTRK; i++) + proj_trk_from_v3(&q->t[i], &v3->t[i], i == TRK_DRUM); + q->sum = proj_sum(q); +} +static int proj_from_v3(project_t *q, const project_v3_t *v3, int n) +{ + if (n != (int)sizeof *v3 || v3->magic != PROJ_MAGIC_V3 || v3->size != sizeof *v3 || + v3->sum != proj_hash(v3, sizeof *v3 - 4u)) + return 0; + proj_from_v3_ok(q, v3); + return 1; +} + +static project_v3_t proj_v3_tmp; /* (formats 1, 2: through format 3) */ +/* a format 2 project (n bytes in *v2) -> slot q as format 4 */ +static int proj_from_v2(project_t *q, const project_v2_t *v2, int n) +{ + project_v3_t *v3 = &proj_v3_tmp; + uint32_t i; + if (n != (int)sizeof *v2 || v2->magic != PROJ_MAGIC_V2 || v2->size != sizeof *v2 || + v2->sum != proj_hash(v2, sizeof *v2 - 4u)) + return 0; + memset(v3, 0, sizeof *v3); + memcpy(v3->g, v2->g, sizeof v3->g); + v3->sel = v2->sel; + for (i = 0; i < NTRK; i++) + proj_trk_v2_to_v3(&v3->t[i], &v2->t[i], i == TRK_DRUM); + proj_from_v3_ok(q, v3); + return 1; +} + +/* a format 1 project (n bytes in *v1) -> slot q as format 4: the instrument becomes track 1, + * tracks 2..4 start empty (their sounds as at power-on) */ +static int proj_from_v1(project_t *q, const project_v1_t *v1, int n) +{ + project_v3_t *v3 = &proj_v3_tmp; + uint32_t i; + if (n != (int)sizeof *v1 || v1->magic != PROJ_MAGIC_V1 || v1->size != sizeof *v1 || + v1->sum != proj_hash(v1, sizeof *v1 - 4u)) + return 0; + memset(v3, 0, sizeof *v3); + memcpy(v3->g, v1->g, sizeof v3->g); + proj_trk_v2_to_v3(&v3->t[0], &v1->t, 0); + proj_from_v3_ok(q, v3); + for (i = 1; i < NTRK; i++) { /* the other tracks: their defaults, no steps */ + uint32_t k; + for (k = 0; k < P_COUNT; k++) + q->t[i].p[k] = k >= P_E0 ? ENGINES[trk_def_engine(i)]->edit[k - P_E0].def : TP[k].def; + q->t[i].engine = (uint8_t)trk_def_engine(i); + q->t[i].preset = 0xFF; /* 0xFF: its default preset (project_load) */ + memset(q->t[i].step, 0, sizeof q->t[i].step); + if (i != TRK_DRUM) + for (k = 0; k < NSTEP; k++) + q->t[i].step[k].time = ST_REST; + } + q->sum = proj_sum(q); + return 1; +} + +/* n bytes of a stored project (any format) -> slot q as format 4; 0 = not a project */ +static int proj_import(project_t *q, const void *b, int n) +{ + if (n == (int)sizeof *q && proj_ok((const project_t *)b)) { + memcpy(q, b, sizeof *q); + return 1; + } + return proj_from_v3(q, (const project_v3_t *)b, n) || proj_from_v2(q, (const project_v2_t *)b, n) || + proj_from_v1(q, (const project_v1_t *)b, n); +} + +/* ---- the working project <-> a project_t */ +static void proj_capture(project_t *p) /* what is playing now, as a project */ +{ + uint32_t i; + memset(p, 0, sizeof *p); + p->magic = PROJ_MAGIC; + p->size = sizeof *p; + for (i = 0; i < G_COUNT; i++) + p->g[i] = song.g[i]; + p->sel = song.sel; + for (i = 0; i < NTRK; i++) { + memcpy(p->t[i].p, trk[i].p, sizeof trk[i].p); + p->t[i].engine = trk[i].eng_req; + p->t[i].preset = trk[i].preset; + memcpy(p->t[i].step, trk[i].step, sizeof trk[i].step); + } + p->sum = proj_sum(p); +} + +/* a project's tracks (and its globals, all: a load; or only the drum level / reverb: a song + * section) into the working one, every value back inside its range. The audio ISR must not run + * meanwhile (the song sections: called from it; a load: IRQ off) */ +static void proj_apply(const project_t *p, int all) +{ + uint32_t i, k; + for (i = 0; i < G_COUNT; i++) + if (all ? i != G_SLOT && i != G_LOAD && i != G_SAVE : i == G_DRLVL || i == G_DRREV) + song.g[i] = (int16_t)clamp(p->g[i], GP[i].min, GP[i].max); + for (k = 0; k < NTRK; k++) { + track_t *t = &trk[k]; + const proj_trk_t *s = &p->t[k]; + uint32_t e = k < NPART ? s->engine % NENGINES : 0u; + t->eng_req = (uint8_t)e; + t->user = 0; /* (no user preset slot is saved) */ + for (i = 0; i < P_COUNT; i++) { /* every value back inside its range */ + const param_desc_t *d = k == TRK_DRUM && i == P_E0 ? &DRUM_KIT_DESC : /* the drum kit */ + i >= P_E0 && i <= P_E7 ? &ENGINES[e]->edit[i - P_E0] : &TP[i]; + t->p[i] = (int16_t)clamp(s->p[i], d->min, d->max); + } + t->preset = (uint8_t)(ENGINES[e]->npresets ? (s->preset == 0xFFu ? 0u : s->preset) % ENGINES[e]->npresets : 0u); + memcpy(t->step, s->step, sizeof t->step); + if (k != TRK_DRUM) + for (i = 0; i < NSTEP; i++) { + step_t *st = &t->step[i]; + uint32_t j; + if (st->n > 4u) + st->n = 4; + if (st->time > ST_REST) + st->time = ST_REST; + for (j = 0; j < 4u; j++) + st->note[j] &= 127u; + } + } +} + +#ifndef PROJ_HOST +#if FELUCCA_ARRANGER +#include "arranger_scene.c" +#endif +#if FELUCCA_FLASH +/* slot from flash into RAM (format 4, or an old one converted) */ +static union { + project_t v4; + project_v3_t v3; + project_v2_t v2; + project_v1_t v1; +} proj_tmp; +static void proj_fetch(uint32_t slot) +{ + project_t *q = &proj_slot[slot & 3u]; + int n = st_load(OBJ_PROJECT0 + (slot & 3u), &proj_tmp, sizeof proj_tmp); + if (!proj_import(q, &proj_tmp, n)) + q->magic = 0; +} +#endif + +static void project_save(uint32_t slot) +{ + project_t *p = &proj_slot[slot & 3u]; +#if FELUCCA_ARRANGER + if (song.playing || transport_req) { ui_message("STOP BEFORE SAVE"); return; } +#endif + proj_capture(p); +#if FELUCCA_FLASH + if (flash_ok) { + ui_message(st_save(OBJ_PROJECT0 + (slot & 3u), p, sizeof *p) ? "SAVE ERROR" : "SAVED"); + return; + } +#endif + ui_message("SAVED (RAM)"); +} + +/* a project into the working one: the transport stops, everything sounding is released */ +static void project_apply(const project_t *p) +{ + uint32_t k; + transport_req = 2; + panic_req = (1u << NTRK) - 1u; + fm1_irq_off(); /* the audio ISR must not see half a project */ + proj_apply(p, 1); + song.sel = (uint8_t)(p->sel < NTRK ? p->sel : 0u); + fm1_irq_on(); + for (k = 0; k < NPART; k++) /* a format 1 project: the default sounds of tracks 2, 3 */ + if (p->t[k].preset == 0xFFu) { + apply_preset_to(&trk[k], TRK_DEF[k][1]); + steps_clear(&trk[k]); + } + sync_reload = 1; + ui.force = 1; +} + +static void project_load(uint32_t slot) +{ + project_t *p = &proj_slot[slot & 3u]; +#if FELUCCA_ARRANGER + if (song.playing || transport_req) { ui_message("STOP BEFORE LOAD"); return; } +#endif +#if FELUCCA_FLASH + if (flash_ok && !proj_ok(p)) + proj_fetch(slot); +#endif + if (!proj_ok(p)) { + ui_message("EMPTY SLOT"); + return; + } + project_apply(p); + ui_message("LOADED"); +} + +/* ---- the working project, kept in flash by itself: saved when it changed, the transport is stopped, + * nothing sounds and the panel was not touched for AUTOSAVE_IDLE (a flash erase stops the audio for + * ~50 ms: never while something plays); loaded at power-on (autosave_resume) */ +#define AUTOSAVE_IDLE 2500u /* ms without input */ +#define AUTOSAVE_GAP 20000u /* ms between two saves at least */ +static project_t autosave_buf __attribute__((section(".pool"))); +static uint32_t autosave_hash, autosave_ms, autosave_checked; + +static int audio_quiet(void) +{ + uint32_t p, i; + for (p = 0; p < NPART; p++) + for (i = 0; i < NVOICE; i++) + if (trk[p].v[i].active) + return 0; + for (i = 0; i < NDRUM; i++) + if (drums.v[i].active) + return 0; + return 1; +} + +static void autosave_tick(void) /* main loop */ +{ +#if FELUCCA_FLASH + uint32_t h, now = fm1_ms; + if (!flash_ok || song.playing || transport_req || rec_wait || ft_on || ui.menu || + now - ui_input_ms < AUTOSAVE_IDLE || now - autosave_ms < AUTOSAVE_GAP || now - autosave_checked < 1000u) + return; + autosave_checked = now; + proj_capture(&autosave_buf); + h = autosave_buf.sum; + if (h == autosave_hash || !audio_quiet()) + return; + if (st_save(OBJ_AUTOSAVE, &autosave_buf, sizeof autosave_buf) == 0) + autosave_hash = h; + autosave_ms = fm1_ms; +#endif +} + +static void autosave_resume(void) /* power-on: the project as it was left (felucca_init) */ +{ +#if FELUCCA_FLASH + project_t *q = &autosave_buf; + int n; + if (!flash_ok) + return; + n = st_load(OBJ_AUTOSAVE, &proj_tmp, sizeof proj_tmp); + if (!proj_import(q, &proj_tmp, n)) + return; + autosave_hash = q->sum; + proj_apply(q, 1); + song.sel = (uint8_t)(q->sel < NTRK ? q->sel : 0u); + for (n = 0; n < NPART; n++) + trk[n].engine = trk[n].eng_req; /* (nothing sounds yet: no fade) */ +#endif +} + +/* settings + learned panel table: one flash object. The flash copy wins at + * boot (the .noinit copies are garbage after a power-off). */ +typedef struct { + uint32_t magic, palette, lowcut, zoom; + panel_t panel; +#if FELUCCA_ARRANGER + arr_config_t arrangement; +#endif +} persist_t; +#if FELUCCA_ARRANGER +#define PERSIST_MAGIC 0x50455233u /* "PER3": includes the song order */ +#else +#define PERSIST_MAGIC 0x50455232u +#endif +#if FELUCCA_FLASH +static persist_t persist_saved; +#endif + +static void persist_boot(void) /* before settings_init / panel_init */ +{ +#if FELUCCA_ARRANGER + arr_defaults(&arrangement); +#endif +#if FELUCCA_FLASH + persist_t p; + uint32_t f = irq_save(); + flash_ok = FL_FAR(fl_jedec_ram)() == 0x856014u; /* the expected 1 MiB part, else stay RAM-only */ + irq_restore(f); + if (!flash_ok) + return; + fl_plain_window_init(); /* flash above 0x93000 reads as plaintext through XIP + * (user sample sets are played from there) */ + { + uint32_t k; + for (k = 0; k < SMP_USER_SLOTS; k++) + smp_user_scan(k); + } + { + int n = st_load(OBJ_SETTINGS, &p, sizeof p); + if ((n == (int)sizeof p && p.magic == PERSIST_MAGIC) +#if FELUCCA_ARRANGER + || (n == (int)(16u + sizeof(panel_t)) && p.magic == 0x50455232u) +#endif + ) { + settings.magic = SETTINGS_MAGIC; + settings.palette = p.palette; + settings.lowcut = p.lowcut; + settings.zoom = p.zoom; + if (p.panel.magic == PANEL_MAGIC) + panel = p.panel; +#if FELUCCA_ARRANGER + if (p.magic == PERSIST_MAGIC && arr_valid(&p.arrangement, 15u)) + arrangement = p.arrangement; + else + p.arrangement = arrangement; +#endif + persist_saved = p; + } else if (n == (int)(8u + sizeof(panel_t)) && p.magic == 0x50455231u) { /* "PER1": palette, panel */ + const uint32_t *w = (const uint32_t *)&p; + panel_t old; + memcpy(&old, w + 2, sizeof old); + settings.magic = SETTINGS_MAGIC; + settings.palette = w[1]; + settings.lowcut = 0; + settings.zoom = 0; + if (old.magic == PANEL_MAGIC) + panel = old; + } + } + { /* projects: fill empty RAM slots from flash, so the slot list is right after power-on */ + uint32_t i; + for (i = 0; i < 4u; i++) + if (!proj_ok(&proj_slot[i])) + proj_fetch(i); + } + up_boot(); /* user presets */ +#endif +} + +static int project_used(uint32_t slot) { return proj_ok(&proj_slot[slot & 3u]); } + +static void settings_save(void) +{ +#if FELUCCA_FLASH + persist_t p; + if (!flash_ok) + return; + memset(&p, 0, sizeof p); + p.magic = PERSIST_MAGIC; + p.palette = settings.palette; + p.lowcut = settings.lowcut; + p.zoom = settings.zoom; + p.panel = panel; +#if FELUCCA_ARRANGER + p.arrangement = arrangement; +#endif + if (!memcmp(&p, &persist_saved, sizeof p)) + return; /* unchanged: no erase cycle */ + if (st_save(OBJ_SETTINGS, &p, sizeof p) == 0) + persist_saved = p; +#endif +} + +#if FELUCCA_FLASH +_Static_assert(sizeof(project_t) <= ST_PAYLOAD_MAX, "project does not fit one flash sector"); +#endif +#if FELUCCA_ARRANGER +static void arrangement_save(void) +{ + if (song.playing || transport_req) { ui_message("STOP BEFORE SAVE"); return; } + settings_save(); +#if FELUCCA_FLASH + if (flash_ok) { + ui_message(memcmp(&persist_saved.arrangement, &arrangement, sizeof arrangement) ? "SAVE ERROR" : "SONG SAVED"); + return; + } +#endif + ui_message("SONG IN RAM ONLY"); +} +#endif +#endif /* PROJ_HOST */ diff --git a/firmware/src/punch.c b/firmware/src/punch.c new file mode 100644 index 0000000..58d06ab --- /dev/null +++ b/firmware/src/punch.c @@ -0,0 +1,229 @@ +/* SPDX-License-Identifier: GPL-3.0-only */ +/* PUNCH-IN FX, pocket-operator style: hold FX, press a white key (16 of them, F3..G5) and the + * whole mix goes through that effect while the key is held; release it and the mix comes + * back. Beat-synced to the tempo; loops start on the grid of the running transport. + * A mono ring of the mix (PUNCH_N samples, 0.74 s) feeds the loops, reverse, tape stop, + * half speed, wobble and echo; the filters, crush and gate run in stereo. Every change + * crossfades over 64 samples. Runs in the audio ISR (mix_block, fx.c). */ +#define PUNCH_N 32768u /* power of two */ +/* the transport clock (core.h clk_pos) places the loops and the gate on the grid */ +static uint32_t clk_samples(void) { return clk_pos / (uint32_t)song.g[G_BPM]; } /* samples into the beat */ +#define PUNCH_NFX 16u +enum { PX_LOOP4, PX_LOOP8, PX_LOOP16, PX_LOOP32, PX_STUT, PX_REV, PX_STOP, PX_HALF, + PX_LPF, PX_HPF, PX_TEL, PX_CRUSH, PX_DOWN, PX_GATE, PX_ECHO, PX_WOBBLE }; +static const char *const PUNCH_NAME[PUNCH_NFX] = { + "LOOP 4", "LOOP 8", "LOOP 16", "LOOP 32", "STUTTER", "REVERSE", "STOP", "HALF", + "LOW", "HIGH", "PHONE", "CRUSH", "ALIAS", "GATE", "ECHO", "WOBBLE"}; +static int16_t punch_ring[PUNCH_N] __attribute__((section(".pool"))); +static struct { + volatile int8_t req; /* effect asked for by the keys (-1 none), ISR keyboard_block */ + volatile uint8_t hold; /* FX button held (UI main loop) */ + uint32_t keybit; /* the key that started it */ + int8_t cur; /* effect playing (fading out when req differs) */ + int32_t g; /* wet gain Q15 */ + uint32_t w; /* ring write index */ + uint32_t start, t, len; /* loop / reverse: start index, samples since, length */ + uint32_t pre; /* loops: samples of dry still to go to the next division */ + uint32_t k, sub; /* position in the loop; HALF: odd / even sample */ + uint32_t dspd; /* tape stop: speed step per sample */ + uint32_t gp; /* gate: samples into the 1/16 step */ + uint32_t rp; /* tape stop / wobble: read position Q16 */ + uint32_t spd; /* tape stop speed Q16 */ + uint32_t lfo; /* wobble phase */ + int32_t held_l, held_r, hn; /* downsample */ + int32_t f1l, f2l, f1r, f2r, f3l, f4l, f3r, f4r; /* filter states */ + int32_t cut; /* sweep, 0..127 << 8 */ +} punch = {.req = -1, .cur = -1}; + +static uint32_t beat_samples(void) { return (uint32_t)FS * 60u / (uint32_t)song.g[G_BPM]; } + +static int32_t ring_raw(uint32_t i) { return punch_ring[i & (PUNCH_N - 1u)]; } /* the stored 16 bits (mix / 8) */ +static int32_t ring_at(uint32_t i) { return ring_raw(i) << 3; } +static int32_t ring_q16(uint32_t p) /* read at Q16 position, linear (on the stored values: no overflow) */ +{ + int32_t a = ring_raw(p >> 16), b = ring_raw((p >> 16) + 1u); + return (a + (((b - a) * (int32_t)((p >> 1) & 0x7FFFu)) >> 15)) << 3; +} + +static void punch_start(int32_t fx) +{ + uint32_t beat = beat_samples(), len, ph = clk_samples(); + static const uint8_t DIV[8] = {1, 2, 4, 8, 6, 1, 1, 2}; /* loops: beat / DIV */ + punch.cur = (int8_t)fx; + punch.t = 0; + len = fx <= PX_HALF ? beat / DIV[fx] : beat; + if (len > PUNCH_N - 1024u) + len = PUNCH_N - 1024u; + if (len < 64u) + len = 64u; + punch.len = len; + punch.pre = 0; + punch.start = punch.w; + if (fx <= PX_STUT && song.playing) { /* on the grid: */ + uint32_t back = ph % len; + if (len - back <= 1536u) { /* just before a division: from that one */ + punch.pre = len - back; + } else { /* else from the last division start */ + punch.start = punch.w - back; + punch.t = back; + } + } + punch.rp = punch.w << 16; + punch.spd = 65536u; + punch.dspd = 65536u / len + 1u; + punch.sub = 0; + punch.k = punch.t % len; + punch.lfo = 0; + punch.hn = 0; + punch.cut = 127 << 8; + punch.f1l = punch.f2l = punch.f1r = punch.f2r = punch.f3l = punch.f4l = punch.f3r = punch.f4r = 0; +} + +/* the wet sample for the mono ring effects (after the ring got this sample); no divide per + * sample: k is the position in the loop, counted up and wrapped */ +static int32_t punch_ring_fx(int32_t fx) +{ + uint32_t len = punch.len, k = punch.k; + int32_t y; + switch (fx) { + case PX_REV: + y = ring_at(punch.start - k); + break; + case PX_STOP: + y = ring_q16(punch.rp); + punch.rp += punch.spd; + punch.spd = punch.spd > punch.dspd ? punch.spd - punch.dspd : 0u; /* to a stop in a beat */ + return ((y >> 3) * (int32_t)(punch.spd >> 4)) >> 9; + case PX_WOBBLE: { + int32_t d = 700 + (sine_i(punch.lfo) * 180 >> 15); + punch.lfo += 4u * (0xFFFFFFFFu / FS); /* 4 Hz */ + return ring_q16((punch.w << 16) - ((uint32_t)d << 16)); + } + default: /* loops, HALF */ + y = ring_at(punch.start + k); + break; + } + if (fx != PX_HALF || (punch.sub ^= 1u) == 0u) /* HALF: every other sample */ + punch.k = k + 1u >= len ? 0u : k + 1u; + /* declick at the seams */ + return k < 64u ? (y * (int32_t)k) >> 6 : len - k < 64u ? (y * (int32_t)(len - k)) >> 6 : y; +} + +/* l, r: the mix before the master (fx.c mix_block), n samples, in place */ +static void punch_process(int32_t *l, int32_t *r, uint32_t n) +{ + uint32_t i; + int32_t want = punch.req; + uint32_t beat, step, echo_d; + tsvf_t c1, c2; + if (punch.cur < 0 && want < 0) { /* idle: only the ring */ + for (i = 0; i < n; i++) + punch_ring[punch.w++ & (PUNCH_N - 1u)] = (int16_t)clamp((l[i] + r[i]) >> 4, -32768, 32767); + return; + } + if (punch.cur < 0 && want >= 0) + punch_start(want); + beat = beat_samples(); /* per block: no divide per sample */ + step = beat / 4u ? beat / 4u : 1u; + echo_d = beat * 3u / 4u; + if (echo_d > PUNCH_N - 64u) echo_d = PUNCH_N - 64u; + if (punch.cur == PX_GATE) + punch.gp = (song.playing ? clk_samples() : punch.t) % step; + { /* filter sweeps: per block */ + int32_t fx = punch.cur; + if (fx == PX_LPF && punch.g > 0) + punch.cut = punch.cut > (34 << 8) ? punch.cut - 96 : 34 << 8; /* closes over ~1 s */ + if (fx == PX_HPF && punch.g > 0) + punch.cut = punch.cut > (88 << 8) ? punch.cut - 64 : 88 << 8; + tsvf_coef(&c1, fx == PX_LPF ? punch.cut : fx == PX_HPF ? (127 << 8) - punch.cut + (40 << 8) : 96 << 8, 90); + tsvf_coef(&c2, 58 << 8, 40); /* PHONE: low cut ~ 500 Hz */ + } + for (i = 0; i < n; i++) { + int32_t x = l[i], y = r[i], wl = x, wr = y, m = (x + y) >> 1; + int32_t fx = punch.cur; + uint32_t target = want == fx ? 32767u : 0u; + punch_ring[punch.w & (PUNCH_N - 1u)] = (int16_t)clamp(m >> 3, -32768, 32767); + switch (fx) { + case PX_LPF: + wl = tsvf_lp(&c1, x >> 1, &punch.f1l, &punch.f2l) << 1; + wr = tsvf_lp(&c1, y >> 1, &punch.f1r, &punch.f2r) << 1; + break; + case PX_HPF: + wl = x - (tsvf_lp(&c1, x >> 1, &punch.f1l, &punch.f2l) << 1); + wr = y - (tsvf_lp(&c1, y >> 1, &punch.f1r, &punch.f2r) << 1); + break; + case PX_TEL: { + int32_t b = tsvf_lp(&c1, m >> 1, &punch.f1l, &punch.f2l); /* < 2.5 kHz */ + b -= tsvf_lp(&c2, b, &punch.f3l, &punch.f4l); /* > 500 Hz */ + wl = wr = softclip(b << 2) >> 1; + break; + } + case PX_CRUSH: + wl = x >= 0 ? x & ~0x7FF : -((-x) & ~0x7FF); /* towards zero: no offset */ + wr = y >= 0 ? y & ~0x7FF : -((-y) & ~0x7FF); + break; + case PX_DOWN: + if (--punch.hn <= 0) { + punch.hn = 8; + punch.held_l = x; + punch.held_r = y; + } + wl = punch.held_l; + wr = punch.held_r; + break; + case PX_GATE: { + uint32_t p = punch.gp; + int32_t gg = p < step / 2u ? 32767 : 0; + punch.gp = p + 1u >= step ? 0u : p + 1u; + if (p < 64u) gg = (int32_t)p * 512; + else if (p >= step / 2u && p < step / 2u + 64u) gg = 32767 - (int32_t)(p - step / 2u) * 512; + wl = ((x >> 3) * gg) >> 12; + wr = ((y >> 3) * gg) >> 12; + break; + } + case PX_ECHO: { + uint32_t d = echo_d; + int32_t e; + e = (ring_raw(punch.w - d) * 18000) >> 12; /* (x 8 after: no overflow on a hot mix) */ + punch_ring[punch.w & (PUNCH_N - 1u)] = (int16_t)clamp((m + e) >> 3, -32768, 32767); /* feedback */ + wl = x + e; + wr = y + e; + break; + } + default: + if (fx < 0) + break; + if (punch.pre) { /* waiting for the division */ + if (!--punch.pre) { + punch.start = punch.w + 1u; + punch.k = 0; + } + break; + } + wl = wr = punch_ring_fx(fx); + break; + } + if ((uint32_t)punch.g < target) + punch.g = punch.g + 512 > 32767 ? 32767 : punch.g + 512; + else if ((uint32_t)punch.g > target) + punch.g = punch.g < 512 ? 0 : punch.g - 512; + l[i] = x + ((((wl - x) >> 3) * (punch.g >> 3)) >> 9); /* (no 32-bit overflow) */ + r[i] = y + ((((wr - y) >> 3) * (punch.g >> 3)) >> 9); + punch.w++; + punch.t++; + if (punch.g == 0 && want != fx) { /* faded out: the next one, or none */ + if (want >= 0) + punch_start(want); + else + punch.cur = -1; + } + } +} + +/* the keyboard (seq.c keyboard_block) while FX is held: white key index 0..15, -1 = black */ +static int32_t punch_key(uint32_t k) +{ + static const int8_t W[12] = {0, -1, 1, -1, 2, -1, 3, 4, -1, 5, -1, 6}; /* from F */ + int32_t i = W[k % 12u]; + return i < 0 ? -1 : (int32_t)(k / 12u) * 7 + i; +} diff --git a/firmware/src/recovery.c b/firmware/src/recovery.c new file mode 100644 index 0000000..992e232 --- /dev/null +++ b/firmware/src/recovery.c @@ -0,0 +1,70 @@ +/* SPDX-License-Identifier: GPL-3.0-only */ +/* Application-level recovery, not a second firmware bank. The intact app's + * startup, RAM flash driver and USB stack are still required. TIMER5, audio, + * settings, samples, projects, editor and normal UI are never started here. */ +static uint32_t recovery_last, recovery_fraction, recovery_usb_last; + +static void recovery_poll(void) +{ + uint32_t now = fm1_ticks(), elapsed = now - recovery_last; + recovery_last = now; + /* Split before adding: also safe across the 32-bit TIMER4 wrap. */ + fm1_ms += elapsed / (1000u * FM1_TICKS_PER_US); + recovery_fraction += elapsed % (1000u * FM1_TICKS_PER_US); + fm1_ms += recovery_fraction / (1000u * FM1_TICKS_PER_US); + recovery_fraction %= 1000u * FM1_TICKS_PER_US; + fm1_wdt_feed(); + if (now - recovery_usb_last >= 500u * FM1_TICKS_PER_US) { + recovery_usb_last = now; + usb_poll(); + } +} + +static void recovery_step(void) +{ + recovery_poll(); + usb_retry(fm1_ms); + if (usb.uboot_req) { + usb_detach(); + fm1_delay_ms(30); + bootguard_clear(&bootguard); + fm1_enter_uboot(); + return; + } + ota_service(); + if (usb.ota_req) { + usb.ota_req = 0; + if (flash_ok) ota_session(); /* same validated updater as normal mode */ + } +} + +static int recovery_key(void) +{ + uint32_t start = fm1_ticks(); + fm1_input_init(); + do { + fm1_wdt_feed(); + fm1_input_scan(); + } while ((uint32_t)(fm1_ticks() - start) < 50u * 1000u * FM1_TICKS_PER_US); + return bootguard_manual(fm1_in.buttons); +} + +static void recovery_main(void) +{ + recovery_active = 1; + bootguard.pending = 2; /* WDT/exception here falls back to ROM */ + recovery_last = recovery_usb_last = fm1_ticks(); + recovery_fraction = fm1_ms = 0; + /* No persist_boot or OTA cleanup: no flash write just for entering rescue. */ + flash_ok = FL_FAR(fl_jedec_ram)() == 0x856014u; + lcd_init(); + lcd_fill(0, 0, 240, 240, C_BLACK); + draw_text_box(0, 64, 240, &FONT_S, "SLOOP USB RESCUE", C_WHITE, 1); + draw_text_box(0, 96, 240, &FONT_S, "CONNECT USB", C_WHITE, 1); + draw_text_box(0, 124, 240, &FONT_S, + flash_ok ? "OPEN THE INSTALLER" : "UNKNOWN FLASH", C_WHITE, 1); + draw_text_box(0, 164, 240, &FONT_S, "AUDIO OFF", C_WHITE, 1); + lcd_sync(); + usb_start(); + for (;;) recovery_step(); +} diff --git a/firmware/src/seq.c b/firmware/src/seq.c new file mode 100644 index 0000000..f7d8a7b --- /dev/null +++ b/firmware/src/seq.c @@ -0,0 +1,1467 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* Keyboard and its layers, scale and chords, arpeggiator, note repeat, sequencer, recording and + * transport. Runs in the audio ISR, once per CTL-sample block (events_block), and ends in + * trk_note_on / trk_note_off / drum_on: engines never see where a note came from. + * + * Time: the transport clock of fx.c (clk_beat, clk_pos, in units of a sample at 1 BPM). Every track + * reads its step from it (trk_grid): the step is the clock divided by the track's DIV, swung, modulo + * its LEN. So the tracks, the click, the arp, the rolls and the song arranger never drift apart, a + * tempo or DIV change plays at most one step a block, and a polymeter (any LEN) stays in phase. + * + * Four tracks: tracks 1..3 are synth parts (steps of up to 4 notes), track 4 the drum track (steps + * of 16 lanes, one per white key). Each step note / lane has a level (ghost .. hard) and a ratchet + * (x1..x4 hits in its step). The keys play the selected track; MIDI channels 1..3 play parts 1..3, + * the DRUMS channel (GLO > DRUMS, default 10) the drum track, any other channel the selected track. + * + * Layers: a function button held turns the keys into something else (TE style: hold + touch): + * FX punch-in effects (punch.c) EDIT erase that note / sound (while held, as it plays) + * ARP note repeat (roll) at G_ROLL SEQ steps 1..16 (the UI: ui_layers.c) + * SCL the key of the song (the UI) GLO mute / solo / tap tempo (the UI) + * On the drum track OCT- / OCT+ held play (and record) ghost / hard hits. */ +static const uint16_t SCALE_MASK[] = { + 0xFFF, /* CHR */ + (1 << 0) | (1 << 2) | (1 << 4) | (1 << 5) | (1 << 7) | (1 << 9) | (1 << 11), /* MAJ */ + (1 << 0) | (1 << 2) | (1 << 3) | (1 << 5) | (1 << 7) | (1 << 8) | (1 << 10), /* MIN */ + (1 << 0) | (1 << 2) | (1 << 3) | (1 << 5) | (1 << 7) | (1 << 9) | (1 << 10), /* DOR */ + (1 << 0) | (1 << 2) | (1 << 4) | (1 << 5) | (1 << 7) | (1 << 9) | (1 << 10), /* MIX */ + (1 << 0) | (1 << 2) | (1 << 4) | (1 << 7) | (1 << 9), /* PEN */ + (1 << 0) | (1 << 3) | (1 << 5) | (1 << 7) | (1 << 10), /* MPEN */ + (1 << 0) | (1 << 2) | (1 << 3) | (1 << 5) | (1 << 7) | (1 << 8) | (1 << 11), /* HARM */ + (1 << 0) | (1 << 1) | (1 << 3) | (1 << 5) | (1 << 7) | (1 << 8) | (1 << 10), /* PHRY */ + (1 << 0) | (1 << 2) | (1 << 4) | (1 << 6) | (1 << 7) | (1 << 9) | (1 << 11), /* LYD */ + (1 << 0) | (1 << 1) | (1 << 3) | (1 << 5) | (1 << 6) | (1 << 8) | (1 << 10), /* LOC */ + (1 << 0) | (1 << 2) | (1 << 3) | (1 << 5) | (1 << 7) | (1 << 9) | (1 << 11), /* MEL (ascending) */ + (1 << 0) | (1 << 3) | (1 << 5) | (1 << 6) | (1 << 7) | (1 << 10), /* BLUES (minor) */ + (1 << 0) | (1 << 2) | (1 << 4) | (1 << 6) | (1 << 8) | (1 << 10), /* WHOLE */ + (1 << 0) | (1 << 1) | (1 << 3) | (1 << 4) | (1 << 6) | (1 << 7) | (1 << 9) | (1 << 10), /* DIMHW */ + (1 << 0) | (1 << 2) | (1 << 3) | (1 << 5) | (1 << 6) | (1 << 8) | (1 << 9) | (1 << 11), /* DIMWH */ +}; +#define NSCALES (sizeof SCALE_MASK / sizeof SCALE_MASK[0]) +#define SEQ_NONE 0xFFFFFFFFu + +#define KB_SILENT 255u +static uint32_t kb_prev; +/* per key: what its press started, so its release ends the same (whatever the layer or track is now) */ +enum { KS_NONE, KS_NOTE, KS_DRUM, KS_ROLL, KS_ERASE, KS_FX, KS_UI }; +static uint8_t kb_kind[27], kb_trk[27], kb_n[27], kb_nt[27][4]; +static uint8_t last_note = 60; +static uint8_t pen_n = 1, pen_note[4] = {60}; /* the last chord / note played: the SEQ layer writes it */ +static uint8_t pen_lane; /* the last drum lane played: the SEQ layer's lane */ +static volatile uint8_t transport_req; /* 1 start, 2 stop (from the UI) */ +static volatile uint8_t panic_req; /* bit per track: release every sounding note (preset / engine change) */ + +static uint32_t trk_index(const track_t *t) { return (uint32_t)(t - trk); } + +static uint32_t trk_midi_ch(uint32_t i) /* MIDI channel 0..15 of track i (keys -> MIDI out) */ +{ + if (i < NPART) + return i; + return song.g[G_DRCH] ? (uint32_t)song.g[G_DRCH] - 1u : 9u; +} + +static uint32_t scale_mask(const track_t *t) +{ + return SCALE_MASK[clamp(t->p[P_SCALE], 0, NSCALES - 1)]; +} + +/* ---------------------------------------------------------- layers --- */ +enum { LY_PLAY, LY_FX, LY_ERASE, LY_ROLL, LY_STEP, LY_SCALE, LY_MIX, LY_COUNT }; +static uint32_t ly_bit[LY_COUNT]; /* the button (fm1_in.buttons bit) of each layer: the UI sets them */ +static uint32_t dyn_bit[2]; /* OCT- / OCT+: ghost / hard on the drum track */ +/* the layer the keys are in: the held function button (FX, EDIT, ARP, SEQ, SCL, GLO in that order) */ +static uint32_t layer_now(void) +{ + uint32_t b = fm1_in.buttons, l; + for (l = LY_FX; l < LY_COUNT; l++) + if (b & ly_bit[l]) + return l; + return LY_PLAY; +} +/* the keys of the layers the UI handles (steps, key, mix): key k down / up, in order */ +#define LKQ 16u +static volatile uint16_t lk_q[LKQ]; +static volatile uint32_t lk_w, lk_r; +static void lk_push(uint32_t layer, uint32_t k, uint32_t down) +{ + if (lk_w - lk_r < LKQ) { + lk_q[lk_w % LKQ] = (uint16_t)(layer << 8 | down << 7 | k); + RING_PUBLISH(); + lk_w++; + } +} + +/* ------------------------------------------------------------- keys --- */ +/* key k -> note on a synth part (KB_SILENT: none). WHITE (and chord mode): the white keys walk the + * scale from C4 = the root, the black keys are silent; SNAP: every key, rounded down into the scale */ +static uint32_t kb_map(const track_t *t, uint32_t k) +{ + static const int8_t DEGREE[12] = {0, -1, 1, -1, 2, 3, -1, 4, -1, 5, -1, 6}; + int32_t n = 53 + (int32_t)k; + if (is_drum(t)) + return LANE_NOTE[lane_of_key(k)]; + if (ENGINES[t->eng_req % NENGINES] == &ENG_SAMPLE && drum_set() >= 0 && /* (the engine it switches to) */ + (uint32_t)t->p[P_E0] % SMP_NSETS == (uint32_t)drum_set()) /* GM KIT: lowest key = kick (C2), no scale */ + return (uint32_t)clamp(36 + 12 * song.octave + (int32_t)k, 0, 127); +#if FELUCCA_SLICE + if (ENGINES[t->eng_req % NENGINES] == &ENG_SLICE) /* SLICE: lowest key = slice 0 (C4 + ROOT), no scale */ + return (uint32_t)clamp(SLC_BASE + t->p[P_ROOT] + 12 * song.octave + (int32_t)k, 0, 127); +#endif + if (t->p[P_QUANT] == 1 && !t->p[P_CHORD]) { /* SNAP: every key, rounded down to the scale (the old ON) */ + uint32_t mask = scale_mask(t), guard = 12; + n += 12 * song.octave + t->p[P_TRANS]; + while (guard-- && !((mask >> (uint32_t)((n - t->p[P_ROOT] + 120) % 12)) & 1u)) + n--; + return (uint32_t)clamp(n, 0, 127); + } + if (t->p[P_QUANT] == 2 || t->p[P_CHORD]) { /* WHITE: white keys walk the scale, black keys are silent */ + uint32_t mask = t->p[P_CHORD] && !t->p[P_SCALE] ? SCALE_MASK[2] : scale_mask(t), i; + int32_t count = 0, degree = DEGREE[n % 12], oct; + if (degree < 0) + return KB_SILENT; + /* C4 is the root. Walk scale degrees on successive white keys, including + * below C4; scales with 5, 6, 8 or 12 notes still have no duplicated degrees. */ + degree += (n / 12 - 5) * 7; + for (i = 0; i < 12u; i++) + count += (mask >> i) & 1u; + oct = degree / count; + degree %= count; + if (degree < 0) { + degree += count; + oct--; + } + for (i = 0; i < 12u; i++) + if ((mask >> i) & 1u) { + if (!degree) + break; + degree--; + } + n = 60 + t->p[P_ROOT] + 12 * oct + (int32_t)i; + } + return (uint32_t)clamp(n + 12 * song.octave + t->p[P_TRANS], 0, 127); +} + +/* chord mode (P_CHORD): the chord of the scale built on note n (in the scale; CHR: minor), into c[]; + * the notes it holds (<= 4, the most a step keeps) */ +static const int8_t CHORD_DEG[6][4] = { + {0, -1, -1, -1}, /* OFF */ + {0, 2, 4, -1}, /* TRIAD: 1 3 5 */ + {0, 2, 4, 6}, /* 7TH: 1 3 5 7 */ + {0, 2, 6, 8}, /* 9TH: 1 3 7 9 (the lo-fi / R&B voicing) */ + {0, 3, 4, -1}, /* SUS4: 1 4 5 */ + {0, -1, -1, -1}, /* POWER: 1 5 8 (semitones, below) */ +}; +static uint32_t chord_notes(const track_t *t, uint32_t n, uint8_t *c) +{ + uint32_t type = (uint32_t)clamp(t->p[P_CHORD], 0, 5), mask = t->p[P_SCALE] ? scale_mask(t) : SCALE_MASK[2]; + uint32_t k = 0, j; + if (type == 5u) { + static const uint8_t PW[3] = {0, 7, 12}; + for (j = 0; j < 3u; j++) + if (n + PW[j] < 128u) + c[k++] = (uint8_t)(n + PW[j]); + return k; + } + for (j = 0; j < 4u && CHORD_DEG[type][j] >= 0; j++) { + int32_t m = (int32_t)n, d = CHORD_DEG[type][j], guard = 48; + while (d > 0 && guard--) { /* d scale degrees up */ + m++; + if ((mask >> (uint32_t)((m - t->p[P_ROOT] + 120) % 12)) & 1u) + d--; + } + if (m < 128) + c[k++] = (uint8_t)m; + } + return k; +} + +/* ------------------------------------------------------------- grid --- */ +/* units an odd step starts late: the track's + the global SWING (MPC: 0 = 50 %, 100 = 75 %) */ +static uint32_t swing_units(int32_t pct, uint32_t u) +{ + return (uint32_t)clamp(pct, 0, 100) * u / 200u; +} +/* the clock on a grid of den steps a beat, odd steps sw late: the step, units into it, its length */ +static uint32_t grid_at(uint32_t den, uint32_t sw, uint32_t *into, uint32_t *len) +{ + uint32_t u = BEAT_U / den, abs = clk_beat * den + clk_pos / u, frac = clk_pos % u; + if (abs & 1u) { /* an odd step: sw late */ + if (frac < sw) { + abs--; + frac += u; + *len = u + sw; + } else { + frac -= sw; + *len = u - sw; + } + } else { + *len = u + sw; + } + *into = frac; + return abs; +} +static uint32_t trk_grid(const track_t *t, uint32_t *into, uint32_t *len) +{ + uint32_t den = DIV_DEN[(uint32_t)t->p[P_SDIV] % 6u]; + return grid_at(den, swing_units(t->p[P_SSWING] + song.g[G_SWING], BEAT_U / den), into, len); +} +static uint32_t trk_len(const track_t *t) { return t->p[P_SLEN] > 0 ? (uint32_t)t->p[P_SLEN] : 1u; } + +/* ------------------------------------------------------------- undo --- */ +/* One step back (and forward again) for the pattern of one track: what it was before the last + * recording pass, erase, step edit, tool or clear (a session: one mark). EDIT + OCT- / OCT+. */ +static struct { + uint8_t valid, undone, trk; + int16_t len; + uint32_t sess; + step_t st[NSTEP]; +} undo; +static uint32_t undo_sess = 1; /* UI sessions (seq.c: recording passes use the track's pass) */ +static void undo_mark(const track_t *t, uint32_t sess) +{ + uint32_t i = trk_index(t); + if (undo.valid && !undo.undone && undo.trk == i && undo.sess == sess) + return; /* (this session is marked already) */ + memcpy(undo.st, t->step, sizeof undo.st); + undo.len = t->p[P_SLEN]; + undo.trk = (uint8_t)i; + undo.sess = sess; + undo.valid = 1; + undo.undone = 0; +} +#define UNDO_REC(t) (((t)->pass << 2) | 1u) /* a recording pass of track t */ +static uint32_t undo_erase_sess; + +/* ------------------------------------------------------- recording --- */ +/* key to ear, in samples: the key's debounce (~3 ms) and the audio out buffer (HALF_FRAMES to + * 2 x HALF_FRAMES, ~9 ms on average). A note played in time with what the player hears reaches + * the sequencer this much later than the sound it was played to: recording takes it back. */ +#define REC_LAT 512u + +/* the step a note played now goes into (as heard: REC_LAT earlier): the one playing, or the next one + * when it is past the middle of the playing one; *later: it has not played yet (it must not sound twice) */ +static uint32_t rec_target(const track_t *t, uint32_t *later) +{ + uint32_t into, slen, abs = trk_grid(t, &into, &slen), half = slen / 2u, lat = REC_LAT * (uint32_t)song.g[G_BPM]; + if (into > half + (lat < half ? lat : half)) + abs++; + *later = abs != t->seq_abs; + return abs; +} + +/* note into synth step idx (overdub: a step that holds notes gets this one added, a chord of up to 4; + * when full, the last note is replaced; MONO / LEGATO / UNISON parts keep one note per step) */ +static void step_add(track_t *t, uint32_t idx, uint32_t note, uint32_t vel, uint32_t lvl, uint32_t rat) +{ + step_t *s = &t->step[idx]; + uint32_t k; + if (s->time != ST_NOTE || !s->n || t->p[P_VOICE] != V_POLY) { + s->n = 0; /* a fresh step */ + s->flags = 0; + s->vel = 0; + s->lvl = 0; + s->rat = 0; + } + for (k = 0; k < s->n && s->note[k] != note; k++) + ; + if (k == s->n) { + if (s->n < 4u) + s->n++; + k = s->n - 1u; + s->note[k] = (uint8_t)note; + } + s->lvl = (uint8_t)((s->lvl & ~(3u << (2u * k))) | (lvl & 3u) << (2u * k)); + s->rat = (uint8_t)((s->rat & ~(3u << (2u * k))) | (rat & 3u) << (2u * k)); + s->time = ST_NOTE; + if (vel > s->vel) + s->vel = (uint8_t)vel; +} + +/* live recording into a synth part: the nearest step (rec_target). Held on: each further step the + * sequencer enters while the note is held becomes a TIE (rec_hold), up to the pattern length and + * never over a step with notes (overdub keeps them); a release before the middle of the last one + * puts that step back (rec_release), so a short note stays one step. A note recorded into another + * step ends the hold before (the step model ties the notes of one step only). */ +static void rec_note(track_t *t, uint32_t note, uint32_t vel, uint32_t rat, int hold) +{ + uint32_t len = trk_len(t), later, abs = rec_target(t, &later), idx = abs % len, k; + undo_mark(t, UNDO_REC(t)); + step_add(t, idx, note, vel, vel_lvl(vel), rat); + t->seq_active = 1; + if (later) { /* it sounds now: the step must not trigger it again */ + if (t->rskip_abs != abs) + t->rskip_n = 0; + t->rskip_abs = abs; + if (t->rskip_n < 4u) + t->rskip[t->rskip_n++] = (uint8_t)note; + } + if (!hold) + return; + if (!t->rh_n || t->rh_start != idx) { /* a new hold (one in another step ends) */ + t->rh_n = 0; + t->rh_start = (uint8_t)idx; + t->rh_ties = 0; + } + for (k = 0; k < t->rh_n && t->rh_note[k] != note; k++) + ; + if (k == t->rh_n && t->rh_n < 4u) + t->rh_note[t->rh_n++] = (uint8_t)note; /* a chord: held until its last key is up */ +} + +/* live recording into the drum track: lane, level, ratchet */ +static void rec_hit(track_t *t, uint32_t lane, uint32_t lvl, uint32_t rat) +{ + uint32_t later, abs = rec_target(t, &later); + undo_mark(t, UNDO_REC(t)); + dstep_set(&t->dstep[abs % trk_len(t)], lane, lvl, rat); + t->seq_active = 1; + if (later) { + if (t->rskip_abs != abs) + t->rskip_lanes = 0; + t->rskip_abs = abs; + t->rskip_lanes |= (uint16_t)(1u << lane); + } +} + +/* the sequencer enters step idx (before playing it): a recorded note still held ties into it */ +static void rec_hold(track_t *t, uint32_t idx, uint32_t len, uint32_t abs) +{ + step_t *s; + if (!t->rh_n) + return; + if (!((song.rec >> trk_index(t)) & 1u) || t->rh_ties + 1u >= len) { + t->rh_n = 0; /* disarmed, or the whole pattern is this note */ + return; + } + if (idx == t->rh_start) + return; /* (recorded ahead into the step now starting) */ + s = &t->step[idx]; + if (s->time == ST_NOTE && s->n) { + t->rh_n = 0; /* a step with notes: the hold ends before it */ + return; + } + t->rh_bak = *s; + t->rh_last = (uint8_t)idx; + t->rh_last_abs = abs; + t->rh_ties++; + memset(s, 0, sizeof *s); + s->time = ST_TIE; +} + +/* a key of a recorded note is up: the hold ends with the last one */ +static void rec_release(track_t *t, uint32_t note) +{ + uint32_t i, k = 0, into, slen, half, lat; + for (i = 0; i < t->rh_n; i++) + if (t->rh_note[i] != note) + t->rh_note[k++] = t->rh_note[i]; + if (k == t->rh_n || (t->rh_n = (uint8_t)k)) + return; /* not one of them, or others still held */ + if (!t->rh_ties || trk_grid(t, &into, &slen) != t->rh_last_abs) + return; + half = slen / 2u; + lat = REC_LAT * (uint32_t)song.g[G_BPM]; + if (into <= half + (lat < half ? lat : half) && t->step[t->rh_last].time == ST_TIE) + t->step[t->rh_last] = t->rh_bak; /* released early in it: not held into this step */ +} + +/* LIVE recording, no click needed (REC: ui_input.c rec_toggle). + * playing: REC records the selected track at once (song.rec), quantised, overdub. + * stopped: REC arms (rec_wait). The first note played on the selected track: + * - a project with notes: starts the transport, that note is step 1, recording on. + * PLAY while armed starts the transport and the recording together. + * - an empty project: a FREE TAKE (ft_on). Play freely, as long as you like: no tempo, no + * grid. REC on the next downbeat closes the loop: its length sets the tempo (1, 2 or 4 + * bars, the nearest the current tempo; within 3 % of it the tempo is kept), the notes are + * quantised to 1/16 into it with their lengths, and the loop plays on. PLAY drops the take. */ +static volatile uint8_t rec_wait; /* 1: armed, waits for a note */ +static volatile uint8_t rec_go; /* recording just started (the UI says so) */ +static void seq_start(void); +static void rec_begin(void) +{ + song.rec = (uint8_t)(1u << (song.sel % NTRK)); + rec_wait = 0; + rec_go = 1; +} + +#define FT_MAX 192u +#define FT_BLOCKS (24u * FS / CTL) /* 24 s: 4 bars at 40 BPM, the longest loop */ +#define FT_OPEN 0xFFFFu /* the key is still down */ +typedef struct { uint16_t t, d; uint8_t note, vel; } ft_ev_t; /* in blocks from the first note; drums: lane, level */ +static ft_ev_t ft_ev[FT_MAX]; +static uint32_t ft_n; +static volatile uint8_t ft_on; /* a free take runs */ +static uint8_t ft_trk; +static volatile uint32_t ft_t; /* blocks since its first note */ +static volatile uint32_t ft_btn_mask; /* the REC button (the UI sets it): closes the take */ +static volatile uint32_t ft_drop_mask; /* the PLAY button: drops it */ +static uint32_t ft_btn_prev; +static volatile uint8_t ft_bars; /* the loop just closed: bars (the UI says so), 0xFF dropped */ +static volatile uint32_t ft_close_ms; /* when (the UI drops the press that closed it) */ +static volatile uint8_t ft_closed; /* (ft_close_ms is set) */ + +static int track_empty(const track_t *t) +{ + uint32_t k; + for (k = 0; k < NSTEP; k++) + if (is_drum(t) ? dstep_mask(&t->dstep[k]) != 0u : t->step[k].time == ST_NOTE && t->step[k].n) + return 0; + return 1; +} +static int project_empty(void) +{ + uint32_t i; + for (i = 0; i < NTRK; i++) + if (!track_empty(&trk[i])) + return 0; + return 1; +} +static void steps_clear(track_t *t) /* an empty pattern (synth: REST steps, drums: no lane) */ +{ + uint32_t k; + memset(t->step, 0, sizeof t->step); + if (!is_drum(t)) + for (k = 0; k < NSTEP; k++) + t->step[k].time = ST_REST; +} + +/* tempo x 10 of a loop of T blocks holding n bars of 4/4 */ +static uint32_t ft_bpm10(uint32_t T, uint32_t n) +{ + uint32_t den = T * CTL; /* (n * 2400 * FS < 2^32 up to n = 4) */ + return den ? (n * 2400u * FS + den / 2u) / den : 0u; +} + +/* the bars a loop of T blocks holds (1, 2 or 4: the tempo the nearest the current one, in + * 40..240), 0 none; *bpm its tempo */ +static uint32_t ft_fit(uint32_t T, uint32_t *bpm) +{ + static const uint8_t BARS[3] = {1, 2, 4}; + uint32_t i, best = 0, cur = (uint32_t)song.g[G_BPM] * 10u, err = 0xFFFFFFFFu; + for (i = 0; i < 3u; i++) { + uint32_t b = ft_bpm10(T, BARS[i]), e; + if (b < 400u || b > 2400u) + continue; + e = b > cur ? b * 1000u / cur : cur * 1000u / b; /* the ratio, x 1000 */ + if (e < err) { + err = e; + best = BARS[i]; + *bpm = (b + 5u) / 10u; + if (e <= 1030u) + *bpm = cur / 10u; /* played to the tempo set: keep it */ + } + } + return best; +} + +static void ft_start(track_t *t) +{ + ft_on = 1; + ft_trk = (uint8_t)trk_index(t); + ft_t = 0; + ft_n = 0; + rec_wait = 0; +} + +static void ft_note_on(uint32_t note, uint32_t vel) +{ + if (ft_n < FT_MAX && ft_t < FT_BLOCKS) { + ft_ev[ft_n].t = (uint16_t)ft_t; + ft_ev[ft_n].d = FT_OPEN; + ft_ev[ft_n].note = (uint8_t)note; + ft_ev[ft_n].vel = (uint8_t)vel; + ft_n++; + } +} + +static void ft_note_off(uint32_t note) +{ + uint32_t i = ft_n; + while (i--) + if (ft_ev[i].note == note && ft_ev[i].d == FT_OPEN) { + ft_ev[i].d = (uint16_t)(ft_t - ft_ev[i].t); + return; + } +} + +/* REC on the downbeat: the loop is the time from the first note to now */ +static void ft_close(void) +{ + track_t *t = &trk[ft_trk % NTRK]; + uint32_t T = ft_t, bars, bpm = 0, len, i, k; + ft_on = 0; + ft_close_ms = fm1_ms; + ft_closed = 1; + bars = ft_n && T >= FS / CTL / 2u ? ft_fit(T, &bpm) : 0u; + if (!bars) { + ft_bars = 0xFF; /* nothing played, or no tempo fits */ + return; + } + len = 16u * bars; + undo_mark(t, (undo_sess += 4u) | 3u); /* (undo: back to the empty project) */ + steps_clear(t); /* (no tie left over from an old pattern) */ + for (i = 0; i < NTRK; i++) { /* the project is empty: one loop length */ + trk[i].p[P_SLEN] = (int16_t)len; + trk[i].p[P_SDIV] = 2; /* 1/16 */ + } + for (i = 0; i < ft_n; i++) { /* the notes, to the nearest step */ + uint32_t idx = (ft_ev[i].t * len * 2u + T) / (2u * T) % len; + if (is_drum(t)) + dstep_set(&t->dstep[idx], ft_ev[i].note & 15u, ft_ev[i].vel & 3u, 0); + else + step_add(t, idx, ft_ev[i].note, ft_ev[i].vel, vel_lvl(ft_ev[i].vel), 0); + } + if (!is_drum(t)) + for (i = 0; i < ft_n; i++) { /* their lengths: TIE steps, up to the next note */ + uint32_t d = ft_ev[i].d == FT_OPEN || ft_ev[i].t + ft_ev[i].d > T ? T - ft_ev[i].t : ft_ev[i].d; + uint32_t idx = (ft_ev[i].t * len * 2u + T) / (2u * T) % len; + uint32_t steps = (d * len * 2u + T) / (2u * T); + for (k = 1; k < steps && k < len; k++) { + step_t *s = &t->step[(idx + k) % len]; + if (s->time == ST_NOTE && s->n) + break; + memset(s, 0, sizeof *s); + s->time = ST_TIE; + } + } + t->seq_active = 1; + song.g[G_BPM] = (int16_t)bpm; + ft_bars = (uint8_t)bars; +#if FELUCCA_ARRANGER + arrangement_enabled = 0; +#endif + seq_start(); /* this is the downbeat: the loop plays */ +} + +/* the UI: a REC / PLAY press is this one's (it runs the take, or just closed it): not the UI's */ +static int ft_owns_press(void) +{ + return ft_on || (ft_closed && (uint32_t)(fm1_ms - ft_close_ms) < 300u); +} + +/* a free take, once per block: REC closes it, PLAY drops it (their press, timed here, not by the UI) */ +static void ft_block(void) +{ + uint32_t b = fm1_in.buttons & (ft_btn_mask | ft_drop_mask), press = b & ~ft_btn_prev; + ft_btn_prev = b; + if (!ft_on) + return; + ft_t++; + if (press & ft_drop_mask) { + ft_on = 0; /* PLAY: dropped, nothing changes */ + ft_bars = 0xFF; + ft_close_ms = fm1_ms; + ft_closed = 1; + } else if ((press & ft_btn_mask) || ft_t >= FT_BLOCKS) { + ft_close(); + } +} + +/* ------------------------------------------------------------ erase --- */ +/* EDIT + key: that note / sound goes from the selected pattern. Playing: from the step playing and + * every step the sequencer enters while the key is held (MPC style); stopped: from every step. */ +static uint8_t er_trk; +static uint16_t er_lanes; /* drums: lanes held */ +static uint32_t er_notes[4]; /* synth: notes held (bit per MIDI note) */ +static volatile uint8_t er_flash; /* something was erased (the UI flashes) */ + +static int er_has(uint32_t note) { return (er_notes[(note >> 5) & 3u] >> (note & 31u)) & 1u; } +static void erase_step(track_t *t, uint32_t idx) +{ + if (is_drum(t)) { + dstep_t *s = &t->dstep[idx]; + uint32_t l, m = dstep_mask(s) & er_lanes; + for (l = 0; m; l++, m >>= 1) + if (m & 1u) { + dstep_clr(s, l); + er_flash = 1; + } + } else { + step_t *s = &t->step[idx]; + uint32_t i, k = 0, lv = 0, rt = 0; + if (s->time != ST_NOTE) + return; + for (i = 0; i < s->n; i++) + if (!er_has(s->note[i])) { + lv |= ((s->lvl >> (2u * i)) & 3u) << (2u * k); + rt |= ((s->rat >> (2u * i)) & 3u) << (2u * k); + s->note[k++] = s->note[i]; + } + if (k == s->n) + return; + er_flash = 1; + s->n = (uint8_t)k; + s->lvl = (uint8_t)lv; + s->rat = (uint8_t)rt; + if (!k) { + s->time = ST_REST; + s->flags = 0; + s->vel = 0; + } + } +} +static void erase_now(track_t *t) /* a key just went down */ +{ + uint32_t i, len = trk_len(t); + undo_mark(t, undo_erase_sess); + if (song.playing && t->seq_abs != SEQ_NONE) { + erase_step(t, t->seq_idx % len); + } else { + for (i = 0; i < len; i++) + erase_step(t, i); + } +} +static int erasing(const track_t *t) { return trk_index(t) == er_trk && (er_lanes || er_notes[0] || er_notes[1] || er_notes[2] || er_notes[3]); } + +/* ------------------------------------------------------------- arp --- */ +static void arp_add(track_t *t, uint32_t note) +{ + uint32_t i; + if (t->p[P_AHOLD] && t->arp_phys == 0u) + t->nheld = 0; /* new chord replaces the latched one */ + t->arp_phys++; /* every key-down: arp_remove counts every key-up */ + for (i = 0; i < t->nheld; i++) + if (t->held[i] == note) + return; /* repeated note-on: not a new note */ + if (t->nheld < 16u) + t->held[t->nheld++] = (uint8_t)note; + if (t->nheld == 1u) { + t->arp_new = 1; /* the first note: now (or on the grid just ahead) */ + t->arp_idx = 0xFFFFFFFFu; + } +} + +static void arp_remove(track_t *t, uint32_t note) +{ + uint32_t i, k = 0; + if (t->arp_phys) + t->arp_phys--; + if (t->p[P_AHOLD]) + return; + for (i = 0; i < t->nheld; i++) + if (t->held[i] != note) + t->held[k++] = t->held[i]; + t->nheld = (uint8_t)k; +} + +/* the next note of the arp: the held notes (sorted or as played) over OCT octaves, by MODE */ +static uint32_t arp_next(track_t *t) +{ + uint32_t cnt, list[64], len = 0, i, j, o; + for (i = 0; i < t->nheld; i++) + list[i] = t->held[i]; + cnt = t->nheld; + if (!t->p[P_AORDER]) + for (i = 1; i < cnt; i++) + for (j = i; j > 0 && list[j - 1] > list[j]; j--) { + uint32_t x = list[j]; + list[j] = list[j - 1]; + list[j - 1] = x; + } + for (o = 0; o < (uint32_t)t->p[P_AOCT]; o++) + for (i = 0; i < cnt && len < 64u; i++) + list[len++] = (uint32_t)clamp((int32_t)list[i] + 12 * (int32_t)o, 0, 127); + t->arp_idx++; + switch (t->p[P_AMODE]) { + case 2: + j = len - 1u - t->arp_idx % len; + break; + case 3: { + uint32_t cyc = len > 1u ? 2u * len - 2u : 1u, k = t->arp_idx % cyc; + j = k < len ? k : cyc - k; + break; + } + case 4: + j = rng() % len; + break; + default: + j = t->arp_idx % len; + break; + } + return list[j]; +} + +/* the arp, once per block: on the transport's grid of RATE (with its SWING) while playing, from the + * first key while stopped. A new chord starts at once unless the grid is just ahead. While recording, + * each note it plays is recorded (what you hear) */ +static void arp_tick(track_t *t, uint32_t adv) +{ + uint32_t den = DIV_DEN[(uint32_t)t->p[P_ARATE] % 6u], u = BEAT_U / den, into, slen, abs = 0, fire = 0; + if (t->arp_note) { + if (t->arp_off <= adv) { + trk_note_off(t, t->arp_note); + t->arp_note = 0; + } else { + t->arp_off -= adv; + } + } + if (!t->p[P_AMODE] || !t->nheld) { + if (!t->nheld && t->arp_note) { + trk_note_off(t, t->arp_note); + t->arp_note = 0; + } + t->arp_new = 0; + return; + } + if (song.playing) { + abs = grid_at(den, swing_units(t->p[P_ASWING], u), &into, &slen); + if (t->arp_new) { + t->arp_new = 0; + t->arp_abs = into * 4u >= slen * 3u ? abs : abs - 1u; /* the last quarter: the grid plays it */ + } + fire = abs != t->arp_abs; + t->arp_abs = abs; + } else { + if (t->arp_new) { + t->arp_new = 0; + t->arp_pos = u; + } + slen = u; + t->arp_pos += adv; + if (t->arp_pos >= u) { + t->arp_pos = t->arp_pos - u < u ? t->arp_pos - u : 0; + fire = 1; + } + } + if (!fire) + return; + if (t->arp_note) + trk_note_off(t, t->arp_note); + t->arp_note = 0; + if ((uint32_t)(rng() & 127u) <= (uint32_t)t->p[P_APROB]) { + uint32_t n = arp_next(t); + t->arp_note = (uint8_t)n; + t->arp_off = slen * (uint32_t)t->p[P_AGATE] / 128u; + trk_note_on(t, n, 100); + if (((song.rec >> trk_index(t)) & 1u) && song.playing) + rec_note(t, n, 100, 0, 0); + } +} + +/* ------------------------------------------------------- note input --- */ +/* armed and stopped, a note on the selected track: an empty project starts a free take, else the + * note is the downbeat (the transport starts, recording on) */ +static void arm_start(track_t *t) +{ + if (!rec_wait || t != TSEL || song.playing) + return; + if (project_empty()) { + ft_start(t); /* the first take sets the loop and the tempo */ + } else { +#if FELUCCA_ARRANGER + arrangement_enabled = 0; +#endif + seq_start(); /* the note is the downbeat */ + if (song.playing) + rec_begin(); + } +} + +static void drum_input(uint32_t lane, uint32_t lvl, uint32_t rat, int rec); +static void input_on(track_t *t, uint32_t note, uint32_t vel) +{ + if (is_drum(t)) { /* (a GM note on the drum track: its lane) */ + drum_input(lane_of_note(note), vel_lvl(vel), 0, 1); + return; + } + last_note = (uint8_t)note; + arm_start(t); + if (ft_on && t == &trk[ft_trk % NTRK]) + ft_note_on(note, vel); + if (t->p[P_AMODE]) { + arp_add(t, note); /* (the arp records the notes it plays) */ + return; + } + if (((song.rec >> trk_index(t)) & 1u) && song.playing) + rec_note(t, note, vel, 0, 1); + trk_note_on(t, note, vel); +} + +static void input_off(track_t *t, uint32_t note) +{ + if (is_drum(t)) { + if (ft_on && ft_trk == TRK_DRUM) + ft_note_off(lane_of_note(note)); + return; + } + if (ft_on && t == &trk[ft_trk % NTRK]) + ft_note_off(note); + rec_release(t, note); + arp_remove(t, note); /* both: the note may have started in the */ + trk_note_off(t, note); /* other mode (ARP switched while held) */ +} + +/* a drum hit from a key, MIDI or a roll: lane, level; rat: its ratchet when recorded (rolls); rec: it + * may be recorded (a roll records one hit a step) */ +static void drum_input(uint32_t lane, uint32_t lvl, uint32_t rat, int rec) +{ + track_t *t = TDRUM; + lane &= 15u; + pen_lane = (uint8_t)lane; + arm_start(t); + if (ft_on && ft_trk == TRK_DRUM) + ft_note_on(lane, lvl); + if (rec && ((song.rec >> TRK_DRUM) & 1u) && song.playing) + rec_hit(t, lane, lvl, rat); + trk_note_on(t, LANE_NOTE[lane], lvl_vel(lvl, 100)); +} + +/* -------------------------------------------------------------- roll --- */ +/* ARP + key: note repeat. The key plays at G_ROLL (1/8, 1/16, 1/32, 32T, 1/64) on the transport's grid + * (stopped: from the press) until it or ARP is up. Recorded, a roll faster than the track's steps + * becomes ratchets (1/32 on 1/16 steps: x2, 32T: x3, 1/64: x4). */ +static const uint8_t ROLL_DEN[5] = {2, 4, 8, 12, 16}; +#define NROLL 4u +static struct { + uint8_t on, key, trk, note, lvl; /* note: the synth note, or the lane */ + uint32_t last; /* playing: the roll step last played; stopped: units since */ + uint32_t off; /* synth: units to its note-off, 0 = not sounding */ + uint32_t rec_abs; /* the step its last recorded hit went into */ +} roll[NROLL]; +static uint32_t roll_den(void) { return ROLL_DEN[(uint32_t)clamp(song.g[G_ROLL], 0, 4)]; } +/* the lanes / notes a roll plays live on track t: the pattern does not play them meanwhile (no flam + * with what was recorded, nor with what this roll is recording) */ +static uint32_t roll_lanes(const track_t *t) +{ + uint32_t r, m = 0; + for (r = 0; r < NROLL; r++) + if (roll[r].on && roll[r].trk == trk_index(t)) + m |= 1u << (roll[r].note & 15u); + return m; +} +static int roll_has(const track_t *t, uint32_t note) +{ + uint32_t r; + for (r = 0; r < NROLL; r++) + if (roll[r].on && roll[r].trk == trk_index(t) && roll[r].note == note) + return 1; + return 0; +} + +static void roll_hit(uint32_t r) +{ + track_t *t = &trk[roll[r].trk % NTRK]; + uint32_t u = BEAT_U / roll_den(), su = div_units((uint32_t)t->p[P_SDIV]); + uint32_t hits = su / u, rat = hits > 4u ? 3u : hits > 1u ? hits - 1u : 0u; + uint32_t armed = ((song.rec >> trk_index(t)) & 1u) && song.playing, later, abs = 0, rec = 0; + if (armed) { /* one recorded hit a step: the ratchet does the rest */ + abs = rec_target(t, &later); + rec = abs != roll[r].rec_abs; + roll[r].rec_abs = abs; + } + if (is_drum(t)) { + drum_input(roll[r].note, roll[r].lvl, rat, rec || !armed); + return; + } + arm_start(t); + if (roll[r].off) + trk_note_off(t, roll[r].note); + trk_note_on(t, roll[r].note, lvl_vel(roll[r].lvl, 100)); + roll[r].off = u / 2u; + if (rec) + rec_note(t, roll[r].note, 100, rat, 0); + if (ft_on && t == &trk[ft_trk % NTRK]) + ft_note_on(roll[r].note, 100), ft_note_off(roll[r].note); +} + +static void roll_start(uint32_t k, track_t *t, uint32_t note, uint32_t lvl) +{ + uint32_t r, den = roll_den(), into, slen, abs; + for (r = 0; r < NROLL && roll[r].on; r++) + ; + if (r == NROLL) + return; + roll[r].on = 1; + roll[r].key = (uint8_t)k; + roll[r].trk = (uint8_t)trk_index(t); + roll[r].note = (uint8_t)note; + roll[r].lvl = (uint8_t)lvl; + roll[r].off = 0; + roll[r].rec_abs = SEQ_NONE; + if (song.playing) { + abs = grid_at(den, 0, &into, &slen); + roll[r].last = abs; + if (into * 4u >= slen * 3u) + return; /* the grid is just ahead: it starts there */ + } else { + roll[r].last = 0; + } + roll_hit(r); +} + +static void roll_end(uint32_t r) +{ + if (roll[r].on && roll[r].off && roll[r].trk != TRK_DRUM) + trk_note_off(&trk[roll[r].trk % NTRK], roll[r].note); + roll[r].on = 0; +} + +static void roll_block(uint32_t adv) +{ + uint32_t r, den = roll_den(), u = BEAT_U / den, into, slen; + for (r = 0; r < NROLL; r++) { + if (!roll[r].on) + continue; + if (roll[r].off) { + if (roll[r].off <= adv) { + trk_note_off(&trk[roll[r].trk % NTRK], roll[r].note); + roll[r].off = 0; + } else { + roll[r].off -= adv; + } + } + if (song.playing) { + uint32_t abs = grid_at(den, 0, &into, &slen); + if (abs != roll[r].last) { + roll[r].last = abs; + roll_hit(r); + } + } else { + roll[r].last += adv; + if (roll[r].last >= u) { + roll[r].last = roll[r].last - u < u ? roll[r].last - u : 0; + roll_hit(r); + } + } + } +} + +/* ---------------------------------------------------------- keyboard --- */ +/* the level of a key on the drum track: OCT- held ghost, OCT+ held hard */ +static uint32_t key_lvl(void) +{ + uint32_t b = fm1_in.buttons; + return (b & dyn_bit[0]) ? LV_GHOST : (b & dyn_bit[1]) ? LV_HARD : LV_NORM; +} + +static void key_down(uint32_t k) +{ + uint32_t layer = layer_now(), sel = song.sel % NTRK, i, mc; + track_t *t = &trk[sel]; + kb_kind[k] = KS_NONE; + kb_trk[k] = (uint8_t)sel; + kb_n[k] = 0; + switch (layer) { + case LY_FX: { /* FX held: the white keys pick a punch-in effect */ + int32_t fx = punch_key(k); + kb_kind[k] = KS_FX; + if (fx >= 0 && fx < (int32_t)PUNCH_NFX) { + punch.req = (int8_t)fx; + punch.keybit = 1u << k; + } + return; + } + case LY_STEP: + case LY_SCALE: + case LY_MIX: /* the UI's: steps, the key, the mix */ + kb_kind[k] = KS_UI; + kb_nt[k][0] = (uint8_t)layer; /* (its key-up goes to the same layer) */ + lk_push(layer, k, 1); + return; + case LY_ERASE: + kb_kind[k] = KS_ERASE; + if (!erasing(t) || er_trk != sel) + undo_erase_sess = (undo_sess += 4u) | 2u; /* a new erase: one undo */ + if (er_trk != sel) { + er_lanes = 0; + er_notes[0] = er_notes[1] = er_notes[2] = er_notes[3] = 0; + er_trk = (uint8_t)sel; + } + if (is_drum(t)) { + kb_nt[k][0] = (uint8_t)lane_of_key(k); + kb_n[k] = 1; + er_lanes |= (uint16_t)(1u << kb_nt[k][0]); + } else { + uint32_t n = kb_map(t, k); + if (n == KB_SILENT) + return; + kb_n[k] = (uint8_t)(t->p[P_CHORD] ? chord_notes(t, n, kb_nt[k]) : 1u); + if (!t->p[P_CHORD]) + kb_nt[k][0] = (uint8_t)n; + for (i = 0; i < kb_n[k]; i++) + er_notes[(kb_nt[k][i] >> 5) & 3u] |= 1u << (kb_nt[k][i] & 31u); + } + erase_now(t); + return; + default: + break; + } + if (is_drum(t)) { /* the drum track: the key's lane */ + uint32_t lane = lane_of_key(k), lvl = key_lvl(); + kb_nt[k][0] = (uint8_t)lane; + kb_n[k] = 1; + if (layer == LY_ROLL) { + kb_kind[k] = KS_ROLL; + roll_start(k, t, lane, lvl); + return; + } + kb_kind[k] = KS_DRUM; + drum_input(lane, lvl, 0, 1); + mc = trk_midi_ch(sel); + midi_out_event(0x09u | (0x90u | mc) << 8 | (uint32_t)LANE_NOTE[lane] << 16 | lvl_vel(lvl, 100) << 24); + return; + } + { + uint32_t n = kb_map(t, k); + if (n == KB_SILENT) + return; + if (layer == LY_ROLL) { + kb_kind[k] = KS_ROLL; + kb_nt[k][0] = (uint8_t)n; + kb_n[k] = 1; + roll_start(k, t, n, LV_NORM); + return; + } + kb_kind[k] = KS_NOTE; + if (t->p[P_CHORD]) { + kb_n[k] = (uint8_t)chord_notes(t, n, kb_nt[k]); + } else { + kb_nt[k][0] = (uint8_t)n; + kb_n[k] = 1; + } + mc = trk_midi_ch(sel); + for (i = 0; i < kb_n[k]; i++) { + input_on(t, kb_nt[k][i], 100); + midi_out_event(0x09u | (0x90u | mc) << 8 | (uint32_t)kb_nt[k][i] << 16 | 100u << 24); + } + /* the pen of the SEQ layer: the keys down now (a chord), else this note */ + if (!(kb_prev & ~(1u << k)) || pen_n >= 4u) + pen_n = 0; + for (i = 0; i < kb_n[k] && pen_n < 4u; i++) + pen_note[pen_n++] = kb_nt[k][i]; + } +} + +static void key_up(uint32_t k) +{ + uint32_t i, mc, kind = kb_kind[k]; + track_t *t = &trk[kb_trk[k] % NTRK]; + kb_kind[k] = KS_NONE; + switch (kind) { + case KS_FX: + if (punch.keybit == 1u << k) { /* its key is up: the mix comes back */ + punch.keybit = 0; + punch.req = -1; + } + return; + case KS_UI: + lk_push(kb_nt[k][0], k, 0); + return; + case KS_ERASE: + if (is_drum(t)) + er_lanes &= (uint16_t)~(1u << kb_nt[k][0]); + else + for (i = 0; i < kb_n[k]; i++) + er_notes[(kb_nt[k][i] >> 5) & 3u] &= ~(1u << (kb_nt[k][i] & 31u)); + return; + case KS_ROLL: + for (i = 0; i < NROLL; i++) + if (roll[i].on && roll[i].key == k) + roll_end(i); + return; + case KS_NOTE: + mc = trk_midi_ch(kb_trk[k] % NTRK); + for (i = 0; i < kb_n[k]; i++) { + input_off(t, kb_nt[k][i]); + midi_out_event(0x08u | (0x80u | mc) << 8 | (uint32_t)kb_nt[k][i] << 16); + } + return; + case KS_DRUM: + if (ft_on && ft_trk == TRK_DRUM) + ft_note_off(kb_nt[k][0]); + mc = trk_midi_ch(TRK_DRUM); + midi_out_event(0x08u | (0x80u | mc) << 8 | (uint32_t)LANE_NOTE[kb_nt[k][0] & 15u] << 16); + return; + default: + return; + } +} + +static void keyboard_block(void) +{ + uint32_t cur = fm1_in.notes, ch = cur ^ kb_prev, k, r; + if (!(fm1_in.buttons & ly_bit[LY_ROLL])) /* ARP up: the rolls end (the keys stay silent) */ + for (r = 0; r < NROLL; r++) + if (roll[r].on) + roll_end(r); + if (!ch) + return; + for (k = 0; k < 27u; k++) { + if (!((ch >> k) & 1u)) + continue; + if ((cur >> k) & 1u) + key_down(k); + else + key_up(k); + kb_prev ^= 1u << k; /* (key_down sees the keys down before it) */ + } +} + +/* LIVE: one record arm at most, on the selected track; selecting another track moves it there + * (an arm follows too: it waits for a note on the track selected; a free take stays on its track) */ +static void rec_follow(uint32_t sel) +{ + if (song.rec) + song.rec = (uint8_t)(1u << (sel % NTRK)); +} + +/* -------------------------------------------------------- metronome --- */ +/* A wood block on every beat, louder on the first of the bar, from the drum kit's voices + * (not recorded, not muted with the drum track; GLO > DRUMS LVL sets its level). + * GLO > GLOBAL CLICK: OFF (0, default: LIVE needs none), REC = while a track records, + * ON = while playing. */ +#define CLICK_REC 1 +#define CLICK_ON 2 +static uint32_t click_last = SEQ_NONE; /* the beat it last played */ +static void click_tick(void) +{ + uint32_t mode = (uint32_t)song.g[G_CLOCK]; + if (!song.playing || clk_beat == click_last) + return; + click_last = clk_beat; + if (mode == CLICK_ON || (mode == CLICK_REC && song.rec)) + drum_on(clk_beat % 4u ? 76u : 77u, clk_beat % 4u ? 72u : 120u); +} + +/* -------------------------------------------------------- sequencer --- */ +/* every track from its step 0, together, at pos units into beat 0 (a song section: the arranger's + * remainder, so the new section starts exactly on its bar) */ +static void seq_reset_tracks(uint32_t pos) +{ + uint32_t i; + for (i = 0; i < NTRK; i++) { + track_t *t = &trk[i]; + t->seq_abs = SEQ_NONE; + t->seq_idx = 0; + t->rskip_n = 0; + t->rskip_lanes = 0; + t->rskip_abs = SEQ_NONE; + t->rh_n = 0; + t->arp_new = t->nheld != 0; + } + for (i = 0; i < NROLL; i++) + roll[i].last = SEQ_NONE - 1u; /* (a roll held over the start: on the grid from here) */ + clk_beat = 0; + clk_pos = pos; + click_last = SEQ_NONE; + song.tick = 0; + song.playing = 1; + slicer_start(pos); /* slicer.c: its step 0 with the sequencer's */ +} + +static void song_backup(void); /* project.c: song mode keeps the loop you made */ +static void song_restore(void); + +static void seq_start(void) +{ +#if FELUCCA_ARRANGER + if (arrangement_enabled && !song.playing) { + rec_wait = 0; /* song mode plays, it does not record */ + song_backup(); + } + if (!arrangement_start()) return; +#endif + seq_reset_tracks(0); +} + +static void seq_release(track_t *t) +{ + uint32_t i; + for (i = 0; i < t->seq_n; i++) + trk_note_off(t, t->seq_notes[i]); + t->seq_n = 0; + t->seq_hold = 0; + t->slide_glide = 0; /* live MONO / LEG keys must not glide after it */ +} + +static void seq_stop(void) +{ + uint32_t i; + song.playing = 0; + for (i = 0; i < NTRK; i++) { + seq_release(&trk[i]); + trk[i].rh_n = 0; /* a recorded note held over the stop: as far as it got */ + } +#if FELUCCA_ARRANGER + if (arrangement_clock.running) { + arrangement_clock.running = 0; + song_restore(); /* back to the loop you were making */ + } +#endif +} + +/* the velocity of note i of synth step s */ +static uint32_t step_vel(const step_t *s, uint32_t i) +{ + uint32_t base = (s->flags & SF_ACCENT) ? 127u : (s->vel ? s->vel : 96u); + return lvl_vel((s->lvl >> (2u * i)) & 3u, base); +} + +/* play one synth step: TIE extends, REST releases, NOTE (re)triggers; a SLIDE on the previous + * step makes this one legato with a glide (acid style). skip: bit k = note k already sounds + * from live recording (not triggered, not released here). len: the step's length (units). */ +static void seq_step(track_t *t, const step_t *s, uint32_t slen, uint32_t skip) +{ + uint32_t i, j, gate = slen * (uint32_t)t->p[P_SGATE] / 128u; + uint32_t slide_in = t->seq_hold && t->seq_n; + uint32_t next_tie = t->step[(t->seq_idx + 1u) % trk_len(t)].time == ST_TIE; + if (s->time == ST_TIE) { + if (t->seq_n) { + t->seq_off = gate + slen / 2u; + t->seq_hold = (s->flags & SF_SLIDE) != 0 || next_tie; /* chains hold at any GATE / swing */ + } + return; + } + if (s->time == ST_REST || !s->n) { + seq_release(t); + return; + } + if (s->rat) { /* ratchets: each hit its share of the step */ + uint32_t hits = 1u + ((s->rat >> 0) & 3u); + for (i = 1; i < s->n; i++) + if (1u + ((s->rat >> (2u * i)) & 3u) > hits) + hits = 1u + ((s->rat >> (2u * i)) & 3u); + gate /= hits; + } + t->slide_glide = (uint8_t)slide_in; + if (!slide_in) + seq_release(t); + for (i = 0; i < s->n; i++) + if (roll_has(t, s->note[i])) + skip |= 1u << i; /* (a roll plays it) */ + for (i = 0; i < s->n; i++) + if (!((skip >> i) & 1u)) + trk_note_on(t, s->note[i], step_vel(s, i)); + if (slide_in) /* release what is not held over */ + for (i = 0; i < t->seq_n; i++) { + for (j = 0; j < s->n && s->note[j] != t->seq_notes[i]; j++) + ; + if (j == s->n) + trk_note_off(t, t->seq_notes[i]); + } + t->seq_n = 0; + for (i = 0; i < s->n; i++) + if (!((skip >> i) & 1u)) + t->seq_notes[t->seq_n++] = s->note[i]; + t->seq_off = gate; + t->seq_hold = !s->rat && ((s->flags & SF_SLIDE) != 0 || next_tie); /* next step a TIE: keep the notes to it */ +} + +/* play one drum step: each lane a hit (skip: lanes already played by live recording, or rolling) */ +static void drum_step(track_t *t, const dstep_t *s, uint32_t skip) +{ + uint32_t l, m = dstep_mask(s) & ~skip & ~roll_lanes(t); + for (l = 0; m; l++, m >>= 1) + if (m & 1u) + trk_note_on(t, LANE_NOTE[l], lvl_vel(dstep_lvl(s, l), 100)); +} + +/* ratchets: the further hits of the playing step's notes / lanes, each at its share of the step */ +static void seq_ratchets(track_t *t, uint32_t into, uint32_t slen) +{ + uint32_t i; + if (is_drum(t)) { + const dstep_t *s = &t->dstep[t->seq_idx % NSTEP]; + uint32_t m = dstep_mask(s) & ~roll_lanes(t); + for (i = 0; m; i++, m >>= 1) { + uint32_t hits = 1u + dstep_rat(s, i), h, done; + if (!(m & 1u) || hits == 1u) + continue; + h = into * hits / slen; + done = (t->rat_lanes >> (2u * i)) & 3u; + if (h > done && h < hits) { + t->rat_lanes = (t->rat_lanes & ~(3u << (2u * i))) | h << (2u * i); + trk_note_on(t, LANE_NOTE[i], lvl_vel(dstep_lvl(s, i), 100)); + } + } + return; + } + { + const step_t *s = &t->step[t->seq_idx % NSTEP]; + if (s->time != ST_NOTE || !s->rat) + return; + for (i = 0; i < s->n; i++) { + uint32_t hits = 1u + ((s->rat >> (2u * i)) & 3u), h; + if (hits == 1u || roll_has(t, s->note[i])) + continue; + h = into * hits / slen; + if (h > t->rat_done[i] && h < hits) { + uint32_t j; + t->rat_done[i] = (uint8_t)h; + trk_note_off(t, s->note[i]); + trk_note_on(t, s->note[i], step_vel(s, i)); + t->seq_off = slen / hits * (uint32_t)t->p[P_SGATE] / 128u; + for (j = 0; j < t->seq_n && t->seq_notes[j] != s->note[i]; j++) + ; + if (j == t->seq_n && t->seq_n < 4u) + t->seq_notes[t->seq_n++] = s->note[i]; /* (its gate ends it) */ + } + } + } +} + +static void seq_tick(track_t *t, uint32_t adv) +{ + uint32_t len = trk_len(t), into, slen, abs, idx; + if (t->seq_n && !t->seq_hold) { + if (t->seq_off <= adv) + seq_release(t); + else + t->seq_off -= adv; + } + if (!song.playing) + return; + abs = trk_grid(t, &into, &slen); + if (abs != t->seq_abs) { /* a new step: one a block at most */ + t->seq_abs = abs; + idx = abs % len; + t->seq_idx = (uint16_t)idx; + t->rat_done[0] = t->rat_done[1] = t->rat_done[2] = t->rat_done[3] = 0; + t->rat_lanes = 0; + if (!idx) + t->pass++; /* a new pass of the loop (recording: one undo) */ + if (erasing(t)) + erase_step(t, idx); /* EDIT + key held: gone as it passes */ + if (is_drum(t)) { + uint32_t skip = t->rskip_abs == abs ? t->rskip_lanes : 0u; + t->rskip_lanes = 0; + drum_step(t, &t->dstep[idx], skip); + } else { + const step_t *s = &t->step[idx]; + uint32_t skip = 0, i, k; + rec_hold(t, idx, len, abs); + if (t->rskip_n && t->rskip_abs == abs) + for (i = 0; i < s->n; i++) + for (k = 0; k < t->rskip_n; k++) + if (s->note[i] == t->rskip[k]) + skip |= 1u << i; + t->rskip_n = 0; + seq_step(t, s, slen, skip); + } + } + seq_ratchets(t, into, slen); +} + +/* MIDI in: the track a channel plays (0..15) */ +static track_t *midi_track(uint32_t ch) +{ + if (song.g[G_DRCH] && ch + 1u == (uint32_t)song.g[G_DRCH]) + return TDRUM; + return ch < NPART ? &trk[ch] : TSEL; +} + +/* a channel that plays the selected track: its note-off goes to the track its note-on went to, + * even when another track was selected in between (else that note would hang) */ +static uint8_t midi_sel_on[16][128]; /* per channel and note: track + 1, 0 = none */ +static track_t *midi_route(uint32_t ch, uint32_t note, int on) +{ + track_t *t = midi_track(ch); + if (ch < NPART || (song.g[G_DRCH] && ch + 1u == (uint32_t)song.g[G_DRCH])) + return t; /* a part's own channel, or the drum channel */ + if (on) + midi_sel_on[ch & 15u][note & 127u] = (uint8_t)(song.sel + 1u); + else if (midi_sel_on[ch & 15u][note & 127u]) { + t = &trk[(midi_sel_on[ch & 15u][note & 127u] - 1u) % NTRK]; + midi_sel_on[ch & 15u][note & 127u] = 0; + } + return t; +} + +/* everything that happens between two rendered blocks: transport, input, the steps of every + * track at the clock, the click, the rolls and the arps; then the clock moves on by n samples */ +static void events_block(uint32_t n) +{ + uint32_t i, pr, adv = n * (uint32_t)song.g[G_BPM]; + if (transport_req == 1u) { + transport_req = 0; + if (ft_on) { + ft_close(); /* (PLAY from elsewhere: the editor) */ + } else { + seq_start(); + if (rec_wait && song.playing) + rec_begin(); /* PLAY while armed: record from the top */ + } + } else if (transport_req == 2u) { + seq_stop(); + transport_req = 0; + song.rec = 0; /* STOP ends the take (and the wait) */ + rec_wait = 0; + if (ft_on) { + ft_on = 0; /* a free take: dropped */ + ft_bars = 0xFF; + } + } + if (rec_wait && song.playing) + rec_begin(); /* started some other way: record now */ + ft_block(); +#if FELUCCA_ARRANGER + if (song.playing && arrangement_clock.running) { + int scene = arr_next(&arrangement_clock, &arrangement, FS); + if (scene == ARR_DONE) seq_stop(); + else if (scene >= 0) { + arrangement_apply((uint32_t)scene); + seq_reset_tracks(arrangement_clock.phase); /* (the remainder: exactly on the bar) */ + } + } +#endif + pr = panic_req; + panic_req = 0; + for (i = 0; i < NTRK; i++) { + track_t *t = &trk[i]; + if ((pr >> i) & 1u) { + trk_all_off(t); + t->nheld = 0; + t->arp_phys = 0; + t->arp_note = 0; + } + if (i < NPART) + engine_block(t); /* engine switch: fade, then switch (voice.c) */ + /* ARP turned off, or HOLD released with no key down: drop the latched chord */ + if ((t->armp && !t->p[P_AMODE]) || (t->aholdp && !t->p[P_AHOLD] && !t->arp_phys)) { + t->nheld = 0; + if (!t->p[P_AMODE]) + t->arp_phys = 0; + if (t->arp_note) { + trk_note_off(t, t->arp_note); + t->arp_note = 0; + } + } + t->armp = t->p[P_AMODE]; + t->aholdp = t->p[P_AHOLD]; + } + keyboard_block(); + while (mi_r != mi_w) { /* USB-MIDI (and TRS) in */ + uint32_t pkt = midi_in_q[mi_r % MQ], st = (pkt >> 8) & 0xF0u, ch = (pkt >> 8) & 0x0Fu; + uint32_t d1 = (pkt >> 16) & 0x7Fu, d2 = (pkt >> 24) & 0x7Fu; + track_t *t; + mi_r++; + if (st != 0x90u && st != 0x80u) + continue; + t = midi_route(ch, d1, st == 0x90u && d2); + if (is_drum(t)) { + if (st == 0x90u && d2) + drum_input(lane_of_note(d1), vel_lvl(d2), 0, 1); + } else if (st == 0x90u && d2) { + input_on(t, d1, d2); + } else { + input_off(t, d1); + } + } + for (i = 0; i < NTRK; i++) + seq_tick(&trk[i], adv); + click_tick(); + roll_block(adv); + for (i = 0; i < NPART; i++) + arp_tick(&trk[i], adv); + if (song.playing) { + song.tick++; + clk_pos += adv; + while (clk_pos >= BEAT_U) { + clk_pos -= BEAT_U; + clk_beat++; + } +#if FELUCCA_ARRANGER + arr_elapse(&arrangement_clock, n, (uint32_t)song.g[G_BPM]); +#endif + } +} diff --git a/firmware/src/slicer.c b/firmware/src/slicer.c new file mode 100644 index 0000000..047b8da --- /dev/null +++ b/firmware/src/slicer.c @@ -0,0 +1,204 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* SLICER: a per-track insert, a tempo-synced 16-step gate / stutter. It works on the track's dry + * mono signal after DIST and before LEVEL / PAN / the sends (fx.c mix_part), so the sends follow + * the chopped sound; on the drum track before its pan and reverb send (slicer_drums). + * P_SLCR OFF / GATE / STUT + * P_SLPAT one of SL_NPAT patterns of 16 steps ('x' live / open, '.' gated / repeated) + * P_SLRATE the step: 1/8, 1/16, 1/32, 8T, 16T, 32T + * P_SLDEPTH GATE: how far a '.' step closes (100 % = silent); STUT: the level of the repeat + * GATE: the gain moves at most 1 / SL_RAMP per sample (2.9 ms from open to closed): a closing + * ramp ends on the step boundary, an opening one starts on it. + * STUT: an 'x' step plays live and is recorded (22.05 kHz, 16 bit, SL_LEN samples a track); a '.' + * step plays that recording from its start, looped at the step length (halved until it fits the + * recording), cross-faded with the live sound by DEPTH. Every pass of the loop is windowed + * (SL_RAMP at both ends and at the step end), the cross-fade moves as the gate does. + * The step clock: per track, always running (also with the SLICER OFF, so switching it on lands + * in time), restarted with the transport (seq_start -> slicer_start: step 0 starts with the + * sequencer's step 0), in the transport clock's units (fx.c BEAT_U: exact at any tempo, no drift + * from the steps), the track's + the global SWING as the sequencer has them (seq.c trk_grid); sample + * exact. With the SLICER OFF and no ramp left, the signal is not touched. */ +#define SL_NPAT 16 +#define SL_LEN 4096u /* recording, 22.05 kHz samples a track: 186 ms, 8 KB */ +#define SL_RAMP_LOG2 7 +#define SL_RAMP (1 << SL_RAMP_LOG2) /* 128 samples, 2.9 ms */ +#define SL_SLOPE (32768 / SL_RAMP) +enum { SL_OFF, SL_GATE, SL_STUT }; /* P_SLCR (params.c N_SLCR) */ + +/* bit k = step k: 1 = 'x' (open / live), 0 = '.' (closed / repeat) */ +static const uint16_t SL_PAT[SL_NPAT] = { + 0x5555, /* 1 x.x.x.x.x.x.x.x. */ + 0xB6DB, /* 2 xx.xx.xx.xx.xx.x */ + 0x5249, /* 3 x..x..x..x..x.x. */ + 0xB777, /* 4 xxx.xxx.xxx.xx.x */ + 0x6D6D, /* 5 x.xx.xx.x.xx.xx. */ + 0x0F0F, /* 6 xxxx....xxxx.... */ + 0x1111, /* 7 x...x...x...x... */ + 0x54A5, /* 8 x.x..x.x..x.x.x. */ + 0x5333, /* 9 xx..xx..xx..x.x. */ + 0xA929, /* 10 x..x.x..x..x.x.x */ + 0xAAFF, /* 11 xxxxxxxx.x.x.x.x */ + 0xD501, /* 12 x.......x.x.x.xx */ + 0xAAAA, /* 13 .x.x.x.x.x.x.x.x */ + 0xAB6B, /* 14 xx.x.xx.xx.x.x.x */ + 0xBB5D, /* 15 x.xxx.x.xx.xxx.x */ + 0x7597, /* 16 xxx.x..xx.x.xxx. */ +}; +static const uint8_t SL_DEN[6] = {2, 4, 8, 3, 6, 12}; /* P_SLRATE (N_SLDIV): a step = 1 / DEN beats */ + +static int16_t sl_buf[NTRK][SL_LEN] __attribute__((section(".pool"))); +typedef struct { + uint32_t pos, len; /* clock units into the step, its length */ + uint32_t base; /* the step without swing (units) */ + uint32_t rp, loop; /* repeat: read position, loop length (44.1 kHz samples), 0 = none */ + uint32_t rec; /* recorded (22.05 kHz samples) */ + int32_t gc; /* gate closure, Q15: 0 = open */ + int32_t w; /* STUT cross-fade, Q15: 0 = live */ + int32_t half; /* recording: the first sample of a pair */ + uint32_t half_n; /* (samples recorded this step: odd = the second of a pair) */ + uint8_t idx; /* step 0..15 */ + uint8_t bit; /* this step's pattern bit (latched at its start) */ + uint8_t rec_on; /* recording this step */ +} sl_t; +static sl_t sl[NTRK]; +static int32_t sl_dbuf[CTL]; /* the drum track's dry mono signal (slicer_drums) */ + +static void slicer_start(uint32_t pos) /* seq_start: step 0 of every track, pos units in */ +{ + uint32_t k; + for (k = 0; k < NTRK; k++) { + sl[k].idx = 15; + sl[k].pos = pos; + sl[k].len = 0; + } +} + +static uint32_t sl_pattern(const track_t *t) { return SL_PAT[(uint32_t)(t->p[P_SLPAT] - 1) % SL_NPAT]; } + +/* the step clock enters the next step */ +static void sl_enter(const track_t *t, sl_t *s) +{ + uint32_t mode = (uint32_t)t->p[P_SLCR], sw; + s->pos = s->pos >= s->len ? s->pos - s->len : 0; /* (the overshoot: no drift) */ + s->idx = (uint8_t)((s->idx + 1u) & 15u); + s->base = BEAT_U / SL_DEN[(uint32_t)t->p[P_SLRATE] % 6u]; + sw = (uint32_t)clamp(t->p[P_SSWING] + song.g[G_SWING], 0, 100) * s->base / 200u; /* as seq.c trk_grid */ + s->len = (s->idx & 1u) ? s->base - sw : s->base + sw; + s->bit = (uint8_t)((sl_pattern(t) >> s->idx) & 1u); + s->rp = 0; + s->loop = 0; + s->rec_on = 0; + if (mode != SL_STUT) { + s->rec = 0; /* nothing old to repeat when STUT comes on */ + } else if (s->bit) { + s->rec = 0; /* a live step: record it */ + s->rec_on = 1; + s->half_n = 0; + } else if (s->rec >= 2u * SL_RAMP) { /* a repeat: the last live step, looped */ + uint32_t l = s->base / (uint32_t)song.g[G_BPM]; /* (in samples) */ + while (l > 2u * SL_LEN) + l >>= 1; /* (a long step: a half, a quarter .. of it) */ + s->loop = l < 2u * s->rec ? l : 2u * s->rec; + } +} + +/* m samples of one step (no boundary inside); left: samples to the step end at the first */ +static void sl_seg(const track_t *t, sl_t *s, int16_t *buf, int32_t *b, uint32_t m, uint32_t left0) +{ + uint32_t mode = (uint32_t)t->p[P_SLCR], j, nbit = (sl_pattern(t) >> ((s->idx + 1u) & 15u)) & 1u; + int32_t depth = t->p[P_SLDEPTH] * 258; /* Q15, 0..32766 */ + int32_t tc = mode == SL_GATE && !s->bit ? depth : 0; /* gate closure of this step */ + int32_t tn = mode == SL_GATE && !nbit ? depth : 0; /* .. of the next one */ + int32_t tw = mode == SL_STUT && s->loop ? depth : 0; /* repeat level */ + for (j = 0; j < m; j++) { + int32_t x = b[j], y, tg = tc; + uint32_t left = left0 - j; /* samples to the step end, >= 1 */ + if (left <= (uint32_t)SL_RAMP && tn > tg) + tg = tn; /* close by the boundary */ + s->gc += clamp(tg - s->gc, -SL_SLOPE, SL_SLOPE); + s->w += clamp(tw - s->w, -SL_SLOPE, SL_SLOPE); + y = s->gc ? x - mulq16(x, (uint32_t)s->gc << 1) : x; + if (s->rec_on) { /* 2:1, the pair's mean; Q15 >> 2 (the mix's headroom) */ + if ((s->half_n++) & 1u) { + buf[s->rec] = (int16_t)clamp((s->half + x) >> 3, -32768, 32767); + if (++s->rec >= SL_LEN) + s->rec_on = 0; + } else { + s->half = x; + } + } + if (s->loop) { /* the repeat, windowed, read between samples */ + uint32_t rp = s->rp, e = s->loop - 1u - rp; + int32_t r = buf[rp >> 1]; + if (rp & 1u) + r = (r + buf[((rp >> 1) + 1u) & (SL_LEN - 1u)]) >> 1; + r <<= 2; + if (rp < e) + e = rp; + if (left - 1u < e) + e = left - 1u; + if (e < (uint32_t)SL_RAMP) + r = (r * (int32_t)e) >> SL_RAMP_LOG2; + if (++s->rp >= s->loop) + s->rp = 0; + y += mulq16(r - y, (uint32_t)s->w << 1); + } else if (s->w) { + y -= mulq16(y, (uint32_t)s->w << 1); /* (the repeat ended on a boundary: it is 0 there) */ + } + b[j] = y; + } +} + +/* the step clock over n samples and the SLICER on b (0: the clock only, the track is silent) */ +static void slicer_track(const track_t *t, int32_t *b, uint32_t n) +{ + uint32_t k = (uint32_t)(t - trk), i = 0, bpm = (uint32_t)song.g[G_BPM]; + sl_t *s = &sl[k]; + int act = b && (t->p[P_SLCR] != SL_OFF || s->gc || s->w); + while (i < n) { + uint32_t m, left; + while (s->pos >= s->len) + sl_enter(t, s); + left = (s->len - s->pos + bpm - 1u) / bpm; /* samples to the boundary */ + m = left < n - i ? left : n - i; + if (act) + sl_seg(t, s, sl_buf[k], b + i, m, left); + s->pos += m * bpm; + i += m; + } +} + +/* a silent part must still be rendered: a repeat is playing or fading (fx.c mix_part) */ +static int slicer_busy(const track_t *t) +{ + const sl_t *s = &sl[t - trk]; + return s->w || (t->p[P_SLCR] == SL_STUT && s->loop); +} + +/* the drum track: as drums_render, through the SLICER when it is on (or still fading) */ +static void slicer_drums(int32_t *ml, int32_t *mr, int32_t *rev, uint32_t n) +{ + const track_t *t = TDRUM; + const sl_t *s = &sl[TRK_DRUM]; + uint32_t i; + if (t->p[P_SLCR] == SL_OFF && !s->gc && !s->w) { + slicer_track(t, 0, n); + drums_render(ml, mr, rev, n); + return; + } + for (i = 0; i < n; i++) + sl_dbuf[i] = 0; + drums_render_mono(sl_dbuf, n); + slicer_track(t, sl_dbuf, n); + { + int32_t send = song.g[G_DRREV] * 258, pan = t->p[P_PAN]; + int32_t gl = 4096 - (pan > 0 ? pan * 64 : 0), gr = 4096 + (pan < 0 ? pan * 64 : 0); + for (i = 0; i < n; i++) { + int32_t x = sl_dbuf[i]; + ml[i] += (x * gl) >> 12; + mr[i] += (x * gr) >> 12; + if (send) + rev[i] += mulq15(x, send); + } + } +} diff --git a/firmware/src/splash.c b/firmware/src/splash.c new file mode 100644 index 0000000..b0e39ad --- /dev/null +++ b/firmware/src/splash.c @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-3.0-only */ +/* SLOOP boot splash: the logo (tools/gen_logo.py -> sloop_logo.h: 16 colours, RLE runs of + * (run - 1) << 4 | colour), drawn into the canvas in bands of at most 120 rows. */ +#include "sloop_logo.h" +static void sloop_logo_draw(uint32_t y0) +{ + uint32_t r0; + for (r0 = 0; r0 < SLOOP_SPLASH_H; r0 += 120u) { + uint32_t rows = SLOOP_SPLASH_H - r0 > 120u ? 120u : SLOOP_SPLASH_H - r0; + uint32_t lo = r0 * SLOOP_SPLASH_W, hi = (r0 + rows) * SLOOP_SPLASH_W, pos = 0, i; + cv_begin(SLOOP_SPLASH_W, rows, C_BLACK); + for (i = 0; i < sizeof SLOOP_SPLASH_RLE && pos < hi; i++) { + uint32_t run = (SLOOP_SPLASH_RLE[i] >> 4) + 1u, c = SLOOP_SPLASH_RLE[i] & 15u, p; + if (c && pos + run > lo) + for (p = pos < lo ? lo : pos; p < pos + run && p < hi; p++) + cv_px[p - lo] = swap16(SLOOP_SPLASH_PAL[c]); + pos += run; + } + cv_blit((240u - SLOOP_SPLASH_W) / 2u, y0 + r0); + } +} + +/* the boot screen: the logo, the version, where it comes from */ +static void sloop_splash(void) +{ + lcd_fill(0, 0, 240, 240, C_BLACK); + sloop_logo_draw(10); + const char *v = FELUCCA_VERSION; + if (v[0] == 'S' && v[1] == 'L' && v[5] == ' ') + v += 6; /* "SLOOP 1.0" -> "1.0" under the wordmark */ + cv_begin(240, 36, C_BLACK); + cv_text(120 - text_w(&FONT_S, v) / 2, 0, &FONT_S, v, RGB(196, 196, 204)); + cv_text(120 - text_w(&FONT_S, "based on felucca") / 2, 18, &FONT_S, "based on felucca", RGB(96, 96, 104)); + cv_blit(0, 202); +} diff --git a/firmware/src/storage.c b/firmware/src/storage.c new file mode 100644 index 0000000..570e38a --- /dev/null +++ b/firmware/src/storage.c @@ -0,0 +1,156 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* Persistent storage on the SPI NOR. + * + * Every object has an A/B sector pair. A save goes to the copy that is not + * the current one: erase the sector, program the payload (from offset 256), + * then the 32-byte header at offset 0 last. The header is the commit record; + * on load the valid copy with the highest seq wins, so a torn write leaves + * the previous copy in charge. + * + * Flash access goes through three hooks (also used by the host test): + * st_read(off, dst, n) st_erase(off) st_prog(off, src, n) + */ +#define ST_MAGIC 0x554C4546u /* "FELU" */ +#define ST_SECTOR 4096u +#define ST_PAYLOAD_OFF 256u +#define ST_PAYLOAD_MAX (ST_SECTOR - ST_PAYLOAD_OFF) + +/* flash map (FL_DATA 0x97000..0xDFFFF, FL_GLOB 0xFC000..): settings 0xFC000 / 0xFD000, projects + * 0x97000..0x9EFFF, user sample slots 0xA0000..0xDBFFF (eng_sample.c), user preset banks 0xDC000..0xDFFFF + * (upreset.c); the working project (autosave, project.c): copy A 0x9F000, copy B 0xFE000 (the two sectors + * left: A/B needs no two neighbours) */ +enum { OBJ_SETTINGS, OBJ_PROJECT0, OBJ_UPRESET0 = OBJ_PROJECT0 + 4, OBJ_AUTOSAVE = OBJ_UPRESET0 + 2, OBJ_COUNT }; + +typedef struct { + uint32_t magic; + uint16_t type, slot; + uint32_t seq, len, crc, rsv[2]; + uint32_t hcrc; +} st_hdr_t; + +static int st_read(uint32_t off, void *dst, uint32_t n); +static int st_erase(uint32_t off); +static int st_prog(uint32_t off, const void *src, uint32_t n); + +static uint32_t st_crc32(const void *p, uint32_t n) /* zlib CRC-32, 4 bits per step */ +{ + static const uint32_t T[16] = { + 0x00000000u, 0x1DB71064u, 0x3B6E20C8u, 0x26D930ACu, 0x76DC4190u, 0x6B6B51F4u, 0x4DB26158u, 0x5005713Cu, + 0xEDB88320u, 0xF00F9344u, 0xD6D6A3E8u, 0xCB61B38Cu, 0x9B64C2B0u, 0x86D3D2D4u, 0xA00AE278u, 0xBDBDF21Cu}; + const uint8_t *b = p; + uint32_t c = 0xFFFFFFFFu; + while (n--) { + c ^= *b++; + c = (c >> 4) ^ T[c & 15u]; + c = (c >> 4) ^ T[c & 15u]; + } + return ~c; +} + +static uint32_t st_sector(uint32_t obj, uint32_t copy) /* flash offset of copy A (0) / B (1) */ +{ + if (obj == OBJ_SETTINGS) + return 0xFC000u + copy * ST_SECTOR; + if (obj == OBJ_AUTOSAVE) + return copy ? 0xFE000u : 0x9F000u; + if (obj >= OBJ_UPRESET0 && obj < OBJ_AUTOSAVE) + return 0xDC000u + (obj - OBJ_UPRESET0) * 2u * ST_SECTOR + copy * ST_SECTOR; + return 0x97000u + (obj - OBJ_PROJECT0) * 2u * ST_SECTOR + copy * ST_SECTOR; +} + +static uint8_t st_buf[ST_PAYLOAD_MAX] __attribute__((aligned(4))); + +static int st_head(uint32_t obj, uint32_t copy, st_hdr_t *h) /* commit record valid: 0 */ +{ + if (st_read(st_sector(obj, copy), h, sizeof *h)) + return -1; + if (h->magic != ST_MAGIC || h->type != obj || h->len > ST_PAYLOAD_MAX || + h->hcrc != st_crc32(h, sizeof *h - 4u)) + return -1; + return 0; +} + +static int st_body(uint32_t obj, uint32_t copy, const st_hdr_t *h) /* payload -> st_buf, CRC ok: 0 */ +{ + if (st_read(st_sector(obj, copy) + ST_PAYLOAD_OFF, st_buf, h->len) || st_crc32(st_buf, h->len) != h->crc) + return -1; + return 0; +} + +/* the current copy: the valid one with the highest seq (A on a tie), -1 when + * neither is valid. Headers first, so only the winner's payload is read (it + * is left in st_buf); *h gets its header. */ +static int st_current(uint32_t obj, st_hdr_t *h) +{ + st_hdr_t a, b; + int va = st_head(obj, 0, &a) == 0, vb = st_head(obj, 1, &b) == 0; + if (vb && (!va || b.seq > a.seq)) { + if (st_body(obj, 1, &b) == 0) { + *h = b; + return 1; + } + vb = 0; + } + if (va && st_body(obj, 0, &a) == 0) { + *h = a; + return 0; + } + if (vb && st_body(obj, 1, &b) == 0) { + *h = b; + return 1; + } + return -1; +} + +/* load object into dst (up to max bytes); returns the length, or -1 */ +static int st_load(uint32_t obj, void *dst, uint32_t max) +{ + uint32_t i; + st_hdr_t h; + if (st_current(obj, &h) < 0) + return -1; + if (h.len > max) + h.len = max; + for (i = 0; i < h.len; i++) + ((uint8_t *)dst)[i] = st_buf[i]; + return (int)h.len; +} + +static int st_save(uint32_t obj, const void *src, uint32_t len) +{ + uint32_t seq, base, off; + int cur, rc; + st_hdr_t h; + if (len > ST_PAYLOAD_MAX) + return -1; + cur = st_current(obj, &h); + seq = cur < 0 ? 0u : h.seq; + base = st_sector(obj, cur == 0 ? 1u : 0u); /* write the other copy */ + for (off = 0; off < len; off++) + st_buf[off] = ((const uint8_t *)src)[off]; /* the driver wants RAM sources */ + if ((rc = st_erase(base)) != 0) + return rc; + for (off = 0; off < len; off += 256u) { + uint32_t n = len - off > 256u ? 256u : len - off; + if ((rc = st_prog(base + ST_PAYLOAD_OFF + off, st_buf + off, n)) != 0) + return rc; + } + h.magic = ST_MAGIC; + h.type = (uint16_t)obj; + h.slot = (uint16_t)(cur == 0 ? 1 : 0); + h.seq = seq + 1u; + h.len = len; + h.crc = st_crc32(st_buf, len); + h.rsv[0] = h.rsv[1] = 0xFFFFFFFFu; + h.hcrc = st_crc32(&h, sizeof h - 4u); + if ((rc = st_prog(base, &h, sizeof h)) != 0) /* the commit record, last */ + return rc; + { /* read back: a write-protected or failing part must not report SAVED */ + st_hdr_t chk; + uint32_t c = cur == 0 ? 1u : 0u; + if (st_head(obj, c, &chk) || chk.seq != h.seq || st_body(obj, c, &chk)) + return -7; + } + return 0; +} diff --git a/firmware/src/ui.c b/firmware/src/ui.c new file mode 100644 index 0000000..5658d41 --- /dev/null +++ b/firmware/src/ui.c @@ -0,0 +1,382 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* 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.0" /* the beat machine firmware for the FM-1 (based on Felucca) */ +#endif +static void project_save(uint32_t slot); +static void arrangement_save(void); +static void panel_setup(void); +static void project_load(uint32_t slot); +static int project_used(uint32_t slot); +static int up_used(uint32_t k); /* user presets: upreset.c */ +static int up_load(uint32_t k); +static uint32_t up_count(void); +static uint32_t up_nth(uint32_t n); +static uint32_t up_rank(uint32_t slot); +static void up_name(uint32_t k, char *b); +static void up_slot_label(char *b, uint32_t k); +static void up_ui(uint32_t op, uint32_t k); +static uint32_t user_of(const track_t *t) /* user preset slot its sound came from, UP_SLOTS = none */ +{ + return t->user && up_used(t->user - 1u) ? t->user - 1u : UP_SLOTS; +} +static uint32_t up_gen; /* bumped on every user bank change (redraws) */ +static uint8_t sync_reload; /* engine / preset / project / user preset loaded: editor RELOAD push */ + +#define ACC C_HI /* amber everywhere; white is the only accent */ +#define VAL(c) ((c) == ui.hot_col && ui.hot_t ? C_WHITE : TE_COL[(c) & 3u]) /* LIVE: one colour per knob */ +#define RATIO(d, v) ((d)->max > (d)->min ? ((int32_t)(v) - (d)->min) * 1000 / ((d)->max - (d)->min) : -1) +/* layout: four 60 px columns, 4 px inset */ +/* Terminus 8x16 (S) and 16x32 (L) */ +#define Y_HEAD 0 +#define H_HEAD 20 +#define Y_LABEL 26 +#define Y_VALUE 44 +#define Y_GAUGE 64 +#define Y_SEP_END 70 +#define Y_GRAPH 74 +#define H_GRAPH 124 +#define G_OY 24 /* graphs draw in the lower 100 px; the focus readout sits on top */ +#define Y_FOOT 202 +#define H_FOOT 38 + +static struct { + uint8_t home; + uint8_t page; /* index into PAGES */ + uint8_t fam_last[FAM_COUNT]; /* last page used per family */ + uint8_t bank; /* SEQ: 16-step bank (follows the cursor) */ + uint8_t cursor; /* SEQ: step being edited (STEP page KNOB 1 moves it) */ + uint8_t entry_open; /* SEQ: keys held since the first press of this entry */ + uint8_t hot_col, hot_t; /* column whose knob was just turned (drawn white) */ + uint8_t menu; /* 0 off, 1 list, 2 about (HOME held) */ + uint8_t menu_sel; + uint32_t menu_sig, home_t0; /* HOME press time (btn_hold) */ + uint8_t force; /* full redraw pending */ + uint8_t msg_t; /* transient message frames */ + uint8_t bpm_t; /* frames the BPM stays highlighted after a SELECT turn */ + uint8_t arm, arm_t; /* destructive action armed: param id, frames left to confirm */ + uint32_t rec_t0; /* REC press time (btn_hold) */ + uint8_t confirm; /* 1 = "clear the sequence?" (REC held on SEQ / ARP), 2 = "clear track n?" (TRACKS) */ + uint8_t confirm_trk; /* the track the dialog clears */ + uint8_t uslot; /* SAVE > USER: the selected user preset slot */ + /* layers (ui_layers.c): a function button held, the keys and knobs do something else */ + uint8_t layer; /* the layer drawn (LY_*), LY_PLAY = none */ + uint8_t layer_btn; /* its button (B_*), NB = none */ + uint8_t layer_used; /* a key / knob / OCT was used while it was held: no tap on release */ + uint32_t layer_t0; /* its press time (ms) */ + uint8_t step_page; /* SEQ layer: the 16 steps shown (page x 16) */ + uint16_t step_held; /* SEQ layer: the step keys held (white key index) */ + uint32_t step_sess; /* SEQ layer: the undo session of this hold */ + uint8_t hold_kind; /* a hold to confirm: 1 = clear the track (REC), 2 = save (SAVE) */ + uint32_t hold_t0; /* (ms) */ + uint8_t hold_trk; + uint32_t tap_ms[4]; /* tap tempo: the last taps */ + uint8_t tap_n; + char msg[24]; + uint32_t enc_t[NE]; + /* drawn-state cache */ + char col[4][32]; + char focus_l[8], focus_v[8], focus_u[8]; /* the touched column, shown large */ + uint32_t graph_sig, head_sig, foot_sig, frame; + uint8_t graph_top; /* the graph strip's top G_OY rows hold something */ +} ui; + +static const page_t *cur_page(void) { return &PAGES[ui.page]; } +static int32_t accel(uint32_t role, int32_t s, int32_t range); /* ui_input.c */ +static uint32_t ui_input_ms; /* the last button / key (ui_input.c; autosave) */ +static void layer_screen_draw(void); /* ui_layers.c */ +static void hold_screen_draw(void); +static uint8_t layer_shown; + +static uint32_t page_first(uint32_t fam) +{ + uint32_t i; + for (i = 0; i < NPAGES; i++) + if (PAGES[i].fam == fam) + return i; + return 0; +} + +/* transient message in the top bar: a + b */ +static void ui_say(const char *a, const char *b) +{ + uint32_t n; + str_cpy(ui.msg, a, sizeof ui.msg); + n = str_len(ui.msg); + str_cpy(ui.msg + n, b, sizeof ui.msg - n); + ui.msg_t = 40; +} + +static void ui_message(const char *s) { ui_say(s, ""); } + +static void page_entered(void) +{ + const page_t *pg = cur_page(); + song.seq_mode = !ui.home && pg->fam == FAM_SEQ; + ui.entry_open = 0; + ui.hot_t = 0; /* the white value / focus box was the old page's */ + ui.force = 1; +} + +static int step_on(const step_t *st) { return st->time == ST_NOTE && st->n; } +/* step i of track t has something to play (synth: notes, drums: a lane) */ +static int trk_step_on(const track_t *t, uint32_t i) +{ + return is_drum(t) ? dstep_mask(&t->dstep[i % NSTEP]) != 0u : step_on(&t->step[i % NSTEP]); +} + +static void step_clear(step_t *st) +{ + memset(st, 0, sizeof *st); + st->time = ST_REST; +} + +/* undo / redo (EDIT + OCT- / OCT+): the marked pattern and the one now swap places */ +static int undo_swap(int redo) +{ + track_t *t; + int16_t len; + if (!undo.valid || (uint32_t)!!redo != undo.undone) + return 0; + t = &trk[undo.trk % NTRK]; + fm1_irq_off(); + { + uint32_t i; + for (i = 0; i < NSTEP; i++) { + step_t x = t->step[i]; + t->step[i] = undo.st[i]; + undo.st[i] = x; + } + } + len = t->p[P_SLEN]; + t->p[P_SLEN] = undo.len; + undo.len = len; + undo.undone = (uint8_t)!redo; + fm1_irq_on(); + sync_reload = 1; + ui.force = 1; + return 1; +} + +/* SEQ cursor: wraps inside the pattern length, the bank follows, a step entry ends */ +static void cursor_set(int32_t c) +{ + int32_t len = TSEL->p[P_SLEN] > 0 ? TSEL->p[P_SLEN] : 1; + ui.cursor = (uint8_t)((c % len + len) % len); + ui.bank = (uint8_t)(ui.cursor / 16u); + ui.entry_open = 0; +} + +static void cursor_fix(void) /* LEN got shorter: onto the last step */ +{ + if (ui.cursor >= (uint32_t)TSEL->p[P_SLEN]) + cursor_set(TSEL->p[P_SLEN] - 1); +} + +static void note_name(char *b, uint32_t n) +{ + str_cpy(b, N_NOTE[n % 12u], 4); + fmt_int(b + str_len(b), (int32_t)(n / 12u) - 1); +} + +static void open_family(uint32_t fam) +{ + if (!ui.home && cur_page()->fam == fam) { /* same button again: next page */ + uint32_t i = ui.page + 1u; + if (i >= NPAGES || PAGES[i].fam != fam) + i = page_first(fam); + ui.page = (uint8_t)i; + } else { + ui.page = ui.fam_last[fam] && PAGES[ui.fam_last[fam]].fam == fam ? ui.fam_last[fam] + : (uint8_t)page_first(fam); + } + ui.fam_last[fam] = ui.page; + ui.home = 0; + page_entered(); +} + +static void go_home(void) +{ +#if FELUCCA_ARRANGER + ui.home = 0; + ui.page = (uint8_t)page_first(FAM_TRK); +#else + ui.home = 1; +#endif + ui.entry_open = 0; + ui.hot_t = 0; + song.seq_mode = 0; + ui.force = 1; +} + +/* ------------------------------------------------------- track setup --- */ +/* LIVE: no factory sequence patterns. Loading a sound (factory or user preset) never + * writes the sequencer: every pattern is the one the player records or enters. */ + +/* the parts' sounds at power-on (engine, preset): bass, pad, lead */ +static const uint8_t TRK_DEF[NPART][2] = {{0, 0}, {1, 0}, {4, 5}}; /* ANALOG 808 BOOM, DIGITAL RHODES, SAMPLE LOFI FLUTE */ +static uint32_t trk_def_engine(uint32_t i) { return i < NPART ? TRK_DEF[i][0] : 0u; } + +static int seq_is_empty(const track_t *t) { return track_empty(t); } + +static void track_defaults_steps(track_t *t) { steps_clear(t); } + +/* what loading a sound (factory or user preset) leaves alone: the mix (LEVEL, PAN, MUTE: + * the TRACKS faders), the pattern parameters (LEN, DIV, SWING, GATE) and the key the part plays + * in (ROOT, SCALE, QNT, CHORD: the song's; SCL + key sets the root of every part). The SLICER is + * part of the sound: a factory preset turns it OFF (its defaults), a user preset brings its own */ +static int param_kept(uint32_t i) +{ + return i == P_LEVEL || i == P_PAN || i == P_MUTE || (i >= P_SLEN && i <= P_SGATE) || + (i >= P_ROOT && i <= P_QUANT) || i == P_CHORD; +} + +/* preset pi of the engine the track asked for: the whole sound (not the pattern parameters) */ +static void apply_preset_to(track_t *t, uint32_t pi) +{ + const engine_t *e = ENGINES[t->eng_req % NENGINES]; + uint32_t i; + if (is_drum(t)) + return; + panic_req |= (uint8_t)(1u << trk_index(t)); /* MONO/POLY may change: release what sounds */ + t->user = 0; + if (t == TSEL) + sync_reload = 1; + if (!e->npresets) + return; + pi %= e->npresets; + t->preset = (uint8_t)pi; + for (i = 0; i < P_E0; i++) /* the rest of the sound to its defaults: a preset */ + if (!param_kept(i)) + t->p[i] = TP[i].def; /* sounds the same after any edit (not the pattern, not the mix) */ + for (i = 0; i < 8u; i++) + t->p[P_E0 + i] = (int16_t)e->presets[pi].e[i]; + t->p[P_ATK] = e->presets[pi].env[0]; + t->p[P_DEC] = e->presets[pi].env[1]; + t->p[P_SUS] = e->presets[pi].env[2]; + t->p[P_REL] = e->presets[pi].env[3]; + t->p[P_ED_FLT] = e->presets[pi].fenv; + t->p[P_VOICE] = e->presets[pi].mono ? V_LEGATO : V_POLY; /* mono presets keep the legato feel */ + { /* the rest of the patch: sends, arpeggiator (never a pattern: LIVE) */ + static const uint8_t FX_DEF[4] = {0, 24, 28, 36}; + const preset_t *pr = &e->presets[pi]; + for (i = 0; i < 4u; i++) { + t->p[P_DIST + i] = (int16_t)(pr->fx[i] ? pr->fx[i] - 1 : FX_DEF[i]); + t->p[P_AMODE + i] = (int16_t)(pr->arp[i] ? pr->arp[i] - 1 : TP[P_AMODE + i].def); + } + preset_extras(t->p, pr); /* glide, pitch / LFO modulation, voice mode */ + } +} + +/* the engine's defaults and its first preset. With the audio IRQ off: the ISR sees the old engine with + * its values or the new one with its own (voice.c engine_block), never one with the other's */ +static void set_engine_of(track_t *t, uint32_t ei) +{ + const engine_t *e = ENGINES[ei % NENGINES]; + uint32_t i; + if (is_drum(t)) + return; + fm1_irq_off(); + t->eng_req = (uint8_t)(ei % NENGINES); + for (i = 0; i < 8u; i++) + t->p[P_E0 + i] = e->edit[i].def; + apply_preset_to(t, 0); + fm1_irq_on(); +} + +static void apply_preset(uint32_t pi) { apply_preset_to(TSEL, pi); } +static void set_engine(uint32_t ei) { set_engine_of(TSEL, ei); } + +static void track_defaults(track_t *t) +{ + uint32_t i; + for (i = 0; i < P_E0; i++) + t->p[i] = TP[i].def; + track_defaults_steps(t); +} + +/* switch engine (its defaults + first preset) and say so */ +static void select_engine(uint32_t e) +{ + if (is_drum(TSEL)) + return; + set_engine(e); + ui_say("ENGINE ", ENGINES[TSEL->eng_req]->name); + ui.force = 1; +} + +/* the presets of every engine, then the used user presets, as one list (the PRESETS knob and the PRESETS page browse it) */ +static uint32_t preset_pos(uint32_t *total) /* list index of the selected track's preset */ +{ + uint32_t n = 0, cur = 0, e; + for (e = 0; e < NENGINES; e++) { + if (e == TSEL->eng_req) + cur = n + TSEL->preset % (ENGINES[e]->npresets ? ENGINES[e]->npresets : 1u); + n += ENGINES[e]->npresets; + } + if (user_of(TSEL) < UP_SLOTS) + cur = n + up_rank(user_of(TSEL)); + *total = n + up_count(); + return cur; +} + +/* list index n (< total) -> engine, *k its preset; NENGINES = user preset, *k its slot */ +static uint32_t preset_at(uint32_t n, uint32_t *k) +{ + uint32_t e; + for (e = 0; e < NENGINES && n >= ENGINES[e]->npresets; e++) + n -= ENGINES[e]->npresets; + *k = e < NENGINES ? n : up_nth(n); + return e; +} + +static void preset_go(uint32_t n) /* load list index n into the selected track */ +{ + uint32_t k, e = preset_at(n, &k); + if (is_drum(TSEL)) + return; /* one GM kit: nothing to browse */ + if (e == NENGINES) { + up_load(k); + return; + } + if (e != TSEL->eng_req) + select_engine(e); + apply_preset(k); + ui.force = 1; +} + +/* HOME: what KNOB k edits: the engine's four main parameters; on the drum track + * LEVEL and REV (GLO > DRUMS), PAN and LEN */ +static const param_desc_t *home_param(uint32_t k, int16_t **vp) +{ + static const uint8_t DRUM_HOME[4][2] = {{1, G_DRLVL}, {1, G_DRREV}, {0, P_PAN}, {0, P_SLEN}}; + uint32_t id; + if (is_drum(TSEL)) { + id = DRUM_HOME[k & 3u][1]; + if (DRUM_HOME[k & 3u][0]) { + *vp = &song.g[id]; + return &GP[id]; + } + *vp = &TSEL->p[id]; + return &TP[id]; + } + id = ENGINES[TSEL->eng_req % NENGINES]->macro[k & 3u]; + *vp = &TSEL->p[id]; + return track_desc(TSEL, id); +} + +/* select track i (KNOB 1 on TRACKS, the editor): its sound, pages and pattern from now on */ +static void track_select(uint32_t i) +{ + if (i >= NTRK || i == song.sel) + return; + song.sel = (uint8_t)i; + rec_follow(i); /* LIVE: recording follows the selected track */ + ui.entry_open = 0; + ui.cursor = 0; + ui.bank = 0; + sync_reload = 1; + ui.force = 1; +} diff --git a/firmware/src/ui_draw.c b/firmware/src/ui_draw.c new file mode 100644 index 0000000..f06c9e7 --- /dev/null +++ b/firmware/src/ui_draw.c @@ -0,0 +1,1008 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* Felucca UI drawing: status bar (top), columns + gauges, graphs, focus readout, + * footer (steps + engine / preset / page). */ +static void draw_menu(void); +static uint32_t str_hash(uint32_t h, const char *s); + +/* --------------------------------------------------------- drawing --- */ +static int is_eng_name(const char *s) /* one of the ENGINES[]->name strings */ +{ + uint32_t e; + for (e = 0; e < NENGINES; e++) + if (s == ENGINES[e]->name) + return 1; + return 0; +} + +/* at most 5 characters, and no wider than maxw */ +static void fit(char *d, const char *src, const felucca_font_t *f, int32_t maxw) +{ + str_cpy(d, src, is_eng_name(src) ? 8 : 6); /* engine names are kept whole */ + while (d[0] && text_w(f, d) > maxw) + d[str_len(d) - 1u] = 0; +} + +static int32_t batt_level(void) /* ADC ch3 thresholds */ +{ + return song.batt_raw >= 591 ? 3 : song.batt_raw >= 561 ? 2 : song.batt_raw >= 531 ? 1 : 0; +} +/* charging (a USB host powers us; there is no charger status line): bars fill 1, 2, 3 + * every 0.6 s, so the header is redrawn twice a second at most; else the level */ +static int32_t batt_shown(void) +{ + if (usb.config && !usb.suspended) + return 1 + (int32_t)((fm1_ms / 600u) % 3u); + return batt_level(); +} + +/* top bar: transport, BPM, octave | USB, battery, CPU; messages replace it */ +static void draw_head(void) +{ + char b[16]; + uint32_t i; + int32_t x; + uint32_t rec = (song.rec >> song.sel) & 1u ? 2u : song.rec != 0u; /* 2 the selected track armed, 1 another */ + uint32_t sig = (uint32_t)song.playing * 3u + rec * 5u + (uint32_t)(song.octave + 8) * 11u + song.sel * 13131u + + (ui.msg_t ? str_hash(7u, ui.msg) : 0u) + (uint32_t)song.g[G_BPM] * 101u + (ui.bpm_t != 0) * 31u + + (uint32_t)batt_shown() * 7777u + (usb.config && !usb.suspended) * 99991u; + if (!ui.force && sig == ui.head_sig) + return; + ui.head_sig = sig; + cv_begin(240, H_HEAD, C_BLACK); + if (ui.msg_t) { + cv_text(4, 1, &FONT_S, ui.msg, C_HI); + cv_blit(0, Y_HEAD); + return; + } + if (song.playing) { /* > play, square stop */ + for (i = 0; i < 5u; i++) + cv_rect(4 + (int32_t)i * 2, 4 + (int32_t)i, 2, 10 - 2 * (int32_t)i, C_WHITE); + } else { + cv_rect(4, 5, 8, 8, C_HI); + } + if (rec) /* recording armed: white = this track, gray = another */ + te_disc(21, 9, 4, rec == 2u ? TE_RED : C_GRAY); + fmt_int(b, song.g[G_BPM]); + x = 32; + if (FELUCCA_ICONS) { /* metronome, then the BPM */ + cv_icon(x, 2, ICON_TEMPO, C_GRAY); + x += 14; + } + x = cv_text(x, 1, &FONT_S, b, ui.bpm_t ? C_WHITE : C_HI); /* white while SELECT turns it */ + if (song.octave) { + str_cpy(b, song.octave > 0 ? "+" : "", 4); + fmt_int(b + str_len(b), song.octave); + cv_text(x + 12, 1, &FONT_S, "OCT", C_GRAY); + cv_text(x + 40, 1, &FONT_S, b, C_HI); + } + if (FELUCCA_ICONS) { /* the selected track: tape + number */ + cv_icon(156, 2, ICON_TAPE, C_GRAY); + b[0] = (char)('1' + song.sel); + b[1] = 0; + cv_rect(168, 2, 12, 16, TE_COL[song.sel & 3u]); + cv_text(170, 1, &FONT_S, b, C_BLACK); + } else { + b[0] = 'T'; + b[1] = (char)('1' + song.sel); + b[2] = 0; + cv_text(158, 1, &FONT_S, b, C_HI); + } + { /* battery, 3 bars; USB when a host is there */ + int32_t lvl = batt_shown(), k; + int32_t bx = 236 - 19; /* right edge (the CPU figure is in the console) */ + cv_rect(bx, 4, 17, 1, C_GRAY); + cv_rect(bx, 12, 17, 1, C_GRAY); + cv_rect(bx, 4, 1, 9, C_GRAY); + cv_rect(bx + 16, 4, 1, 9, C_GRAY); + cv_rect(bx + 17, 6, 2, 5, C_GRAY); + for (k = 0; k < lvl; k++) + cv_rect(bx + 2 + k * 5, 6, 3, 5, lvl == 1 && batt_level() <= 1 ? C_WHITE : C_HI); + if (usb.config && !usb.suspended) + cv_text(bx - 28, 1, &FONT_S, "USB", C_DIM); + } + cv_blit(0, Y_HEAD); +} +/* full redraw: the strips (head, columns, graph, foot) cover the rest, so only + * the space between them is cleared, then the rules are drawn */ +static void draw_frame(void) +{ + uint32_t i; + lcd_fill(0, H_HEAD, 240, Y_LABEL - H_HEAD, C_BLACK); + lcd_fill(0, Y_SEP_END, 240, Y_GRAPH - Y_SEP_END, C_BLACK); + lcd_fill(0, Y_GRAPH + H_GRAPH, 240, Y_FOOT - Y_GRAPH - H_GRAPH, C_BLACK); + for (i = 0; i < 4u; i++) /* left inset of each column */ + lcd_fill(i * 60u, Y_LABEL, 4, Y_SEP_END - Y_LABEL, C_BLACK); + lcd_fill(0, H_HEAD, 240, 1, C_LINE); + lcd_fill(0, Y_FOOT - 2, 240, 1, C_LINE); + for (i = 1; i < 4u; i++) + lcd_fill(i * 60u - 1u, H_HEAD + 4, 1, Y_SEP_END - H_HEAD - 4, C_LINE); +} + +/* one column: [icon] LABEL / value unit / gauge, redrawn only when it changed. + * ratio: 0..1000 for the gauge, -1 = no gauge. icon: ICON_* (icons.c), ICON_AUTO = by label */ +#define LABEL_X (FELUCCA_ICONS ? ICON_CELL + ICON_GAP : 0) +static void draw_column(uint32_t c, const char *label, const char *val, const char *unit, uint16_t vc, + int32_t ratio, uint32_t icon) +{ + char l[8], v[8], u[8], key[32]; + int32_t x, gw = 52, fx; + if (icon == ICON_AUTO) + icon = icon_for_label(label); + fit(l, label, &FONT_S, 54 - LABEL_X); + fit(v, val, &FONT_S, is_eng_name(val) ? 56 : 40); /* engine names whole */ + fit(u, unit, &FONT_S, 54 - text_w(&FONT_S, v) - 3); + str_cpy(key, l, 8); /* cache key: texts + colour + gauge */ + str_cpy(key + str_len(key), "|", 2); + str_cpy(key + str_len(key), v, 8); + str_cpy(key + str_len(key), "|", 2); + str_cpy(key + str_len(key), u, 8); + { + uint32_t n = str_len(key); + key[n] = (char)('A' + (vc == C_WHITE) + (vc == C_DIM) * 2); + key[n + 1] = (char)(' ' + (ratio < 0 ? 0 : 1 + ratio / 20)); + key[n + 2] = (char)(icon == ICON_NONE ? '~' : '!' + icon % 90u); /* same label, other icon */ + key[n + 3] = 0; + } + if (c == ui.hot_col) { + str_cpy(ui.focus_l, l, 8); + str_cpy(ui.focus_v, v, 8); + str_cpy(ui.focus_u, u, 8); + } + if (!ui.force && str_eq(key, ui.col[c])) + return; + str_cpy(ui.col[c], key, sizeof ui.col[c]); + cv_begin(55, Y_SEP_END - Y_LABEL, C_BLACK); /* x 4..58: the rule at 59 stays */ + if (FELUCCA_ICONS && icon != ICON_NONE && l[0]) + cv_icon(0, 1, icon, TE_COL[c & 3u]); /* icon rows 1..10 = the label's cap height */ + cv_text(l[0] ? LABEL_X : 0, 0, &FONT_S, l, C_GRAY); + x = cv_text(0, Y_VALUE - Y_LABEL, &FONT_S, v, vc); + cv_text(x + 3, Y_VALUE - Y_LABEL, &FONT_S, u, C_DIM); + if (ratio >= 0) { /* gauge: track, fill, 1 px end line */ + int32_t gy = Y_GAUGE - Y_LABEL; + fx = ratio * gw / 1000; + cv_rect(0, gy + 1, gw, 1, C_LINE); + cv_rect(0, gy, fx, 3, vc == C_DIM ? C_DIM : TE_DIM[c & 3u]); + cv_rect(fx, gy - 1, 1, 5, vc == C_DIM ? C_HI : vc); + } + cv_blit(c * 60u + 4u, Y_LABEL); +} + +/* Matches voice.c: attack is linear, decay and release are exponential + * (env += (target - env) * k each tick, ~99 % after the set time). Time + * axis is the parameter value (the times themselves are exponential). */ +static void graph_adsr(const track_t *t, uint16_t c) +{ + int32_t a = 4 + t->p[P_ATK] * 50 / 127, d = 6 + t->p[P_DEC] * 50 / 127, r = 6 + t->p[P_REL] * 60 / 127; + int32_t top = 8, bot = 90, sus = t->p[P_SUS] * 1000 / 127; /* 0..1000 */ + int32_t x0 = 6, x1 = x0 + a, x3 = 232 - r, i, px, py; + int32_t e = 32768; /* exp(-4.6 u), Q15 */ +#define EGY(lvl) (bot - (lvl) * (bot - top) / 1000) + cv_line(x0, bot, x1, top, c); /* attack: linear */ + px = x1; + py = top; + for (i = 1; i <= d; i++) { /* decay: exponential to SUS */ + int32_t lvl; + e = (e * (32768 - 150733 / d)) >> 15; /* k^d = exp(-4.6) */ + lvl = sus + ((1000 - sus) * e >> 15); + cv_line(px, py, x1 + i, EGY(lvl), c); + px = x1 + i; + py = EGY(lvl); + } + cv_line(px, py, x3, EGY(sus), c); /* sustain */ + px = x3; + py = EGY(sus); + e = 32768; + for (i = 1; i <= r; i++) { /* release: exponential to 0 */ + e = (e * (32768 - 150733 / r)) >> 15; + cv_line(px, py, x3 + i, EGY(sus * e >> 15), c); + px = x3 + i; + py = EGY(sus * e >> 15); + } + cv_line(0, bot + 1, 239, bot + 1, C_LINE); +#undef EGY +} + +static void graph_lfo(const track_t *t, uint16_t c) +{ + int32_t x, py = 50; + uint32_t ph = (uint32_t)t->p[P_LPHASE] << 25; + for (x = 0; x < 240; x++) { /* (lfo_wave only reads the track) */ + int32_t y = 50 - lfo_wave((track_t *)t, ph + (uint32_t)x * (0xFFFFFFFFu / 120u)) * 38 / 32768; + if (t->p[P_LWAVE] == 4) + y = 50 - ((int32_t)((x / 20 * 2654435761u) >> 16) - 32768) * 38 / 32768; + if (x) + cv_line(x - 1, py, x, y, c); + py = y; + } + cv_line(0, 50, 239, 50, C_LINE); +} + +static void graph_steps(const track_t *t, uint16_t c) +{ + uint32_t i, len = (uint32_t)t->p[P_SLEN]; + for (i = 0; i < NSTEP; i++) { /* 4 rows of 16 thin bars */ + int32_t x = 6 + (int32_t)(i % 16u) * 14 + (int32_t)(i % 16u) / 4 * 4, y = 6 + (int32_t)(i / 16u) * 24; + const step_t *st = &t->step[i]; + if (i >= len) + continue; + if (step_on(st)) + cv_rect(x, y, 1, 14, c); + else if (st->time == ST_TIE) + cv_rect(x, y + 6, 1, 8, C_DIM); + else + cv_rect(x, y + 13, 1, 1, C_DIM); + if (st->flags & SF_ACCENT) + cv_rect(x - 1, y - 2, 3, 1, c); + if ((song.playing && i == t->seq_idx) || i == ui.cursor) + cv_rect(x - 1, y + 16, 3, 3, C_WHITE); + } +} +/* STEP page: the cursor's 16-step bank as a little piano roll */ +static void graph_roll(const track_t *t, uint16_t c) +{ + uint32_t i, j, len = (uint32_t)t->p[P_SLEN], base = ui.bank * 16u; + int32_t lo = 127, hi = 0, prev_y = -1; + for (i = 0; i < len; i++) + for (j = 0; j < t->step[i].n; j++) { + if (t->step[i].note[j] < lo) + lo = t->step[i].note[j]; + if (t->step[i].note[j] > hi) + hi = t->step[i].note[j]; + } + if (lo > hi) { + lo = 48; + hi = 72; + } + if (hi - lo < 12) + hi = lo + 12; + for (i = 0; i < 16u; i++) { + uint32_t si = base + i; + const step_t *st = &t->step[si]; + int32_t x = (int32_t)i * 15, yb = 86; + if (si >= len) + break; + if (si == ui.cursor) + cv_rect(x + 5, 92, 3, 3, C_WHITE); + if (song.playing && si == t->seq_idx) + cv_rect(x + 1, 97, 12, 1, C_WHITE); + if (st->time == ST_TIE && prev_y >= 0) { + cv_rect(x, prev_y, 14, 1, C_GRAY); + continue; + } + if (!step_on(st)) { + cv_rect(x + 6, yb, 2, 1, C_DIM); + prev_y = -1; + continue; + } + for (j = 0; j < st->n; j++) { + int32_t y = 80 - (st->note[j] - lo) * 74 / (hi - lo); + cv_rect(x + 2, y, 10, 1, (st->flags & SF_ACCENT) ? C_WHITE : c); + if (j == 0) + prev_y = y; + } + if (st->flags & SF_SLIDE) + cv_line(x + 11, prev_y, x + 17, prev_y + 2, c); + } +} +static void graph_scale(const track_t *t, uint16_t c) +{ + static const uint8_t BLACK[12] = {0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0}; + uint32_t i, mask = scale_mask(t); + for (i = 0; i < 12u; i++) { + uint32_t deg = (i + 12u - (uint32_t)t->p[P_ROOT]) % 12u; + int32_t x = 6 + (int32_t)i * 19; + uint16_t col = (mask >> deg) & 1u ? (deg == 0u ? C_WHITE : c) : C_DIM; + cv_rect(x, BLACK[i] ? 10 : 40, 16, 1, col); + cv_rect(x + 7, BLACK[i] ? 10 : 40, 1, 40, col); + } +} + +static void graph_fx(const track_t *t, uint16_t c) +{ + uint32_t i; + for (i = 0; i < 4u; i++) { + int32_t h = t->p[P_DIST + i] * 80 / 127, x = (int32_t)i * 60 + 28; + cv_rect(x, 10, 1, 80, C_LINE); + cv_rect(x, 90 - h, 1, h, c); + cv_rect(x - 3, 90 - h, 7, 1, c); + } +} +/* SLICER page: the pattern's 16 steps, a 'x' step a full bar; a '.' step: GATE a bar as high as + * it stays open (DEPTH), STUT hatched (it repeats the last 'x'); the step playing underlined. + * Grey when the SLICER is OFF. */ +static void graph_slicer(const track_t *t, uint16_t c) +{ + uint32_t i, pat = sl_pattern(t), mode = (uint32_t)t->p[P_SLCR], cur = sl[t - trk].idx; + int32_t open = 70 - t->p[P_SLDEPTH] * 70 / 127; /* px a closed GATE step keeps */ + uint16_t col = mode == SL_OFF ? C_DIM : c; + for (i = 0; i < 16u; i++) { + int32_t x = 4 + (int32_t)i * 14 + (int32_t)(i / 4u) * 2, y; + if ((pat >> i) & 1u) { + cv_rect(x, 10, 11, 70, col); + } else if (mode == SL_STUT) { + for (y = 10; y < 80; y += 4) + cv_rect(x, y, 11, 1, col); + } else { + cv_rect(x, 79, 11, 1, C_LINE); + if (open) + cv_rect(x, 80 - open, 11, open, C_DIM); + } + if (mode != SL_OFF && i == cur) + cv_rect(x, 85, 11, 3, C_WHITE); + } +} +static uint32_t steps_hash(const track_t *t) +{ + uint32_t h = 2166136261u, i; + for (i = 0; i < NSTEP; i++) { + const step_t *st = &t->step[i]; + h = (h ^ (st->note[0] + st->n * 128u + st->time * 1024u + st->flags * 4096u + st->note[1] * 65536u)) * + 16777619u; + } + return h; +} + +static uint32_t str_hash(uint32_t h, const char *s) +{ + while (*s) + h = (h ^ (uint8_t)*s++) * 16777619u; + return h; +} + +static uint32_t graph_signature(void) +{ + const page_t *pg = cur_page(); + const track_t *t = TSEL; + uint32_t h = 2166136261u, i; + if (ui.hot_t && settings.zoom) + h = str_hash(str_hash(str_hash(h ^ 0x5555u, ui.focus_v), ui.focus_l), ui.focus_u); + if (ui.home) + return h ^ (ui.frame / 2u); /* scope: redraw every other frame */ + h ^= (uint32_t)pg->graph * 131u + TSEL->eng_req + song.sel * 7777u; + for (i = 0; i < P_COUNT; i++) + h = (h ^ (uint32_t)t->p[i]) * 16777619u; + h ^= (uint32_t)TSEL->preset * 7u + (uint32_t)song.g[G_SLOT] * 13u + TSEL->user * 257u + up_gen * 7919u + ui.uslot * 104729u; + if (pg->graph == GR_SLCR && t->p[P_SLCR]) /* the SLICER's step playing */ + h ^= (sl[song.sel].idx + 1u) * 2654435761u; + if (pg->graph == GR_SLOTS) /* (a checksum over each slot) */ + for (i = 0; i < 4u; i++) + h ^= (uint32_t)project_used(i) << (20u + i); + if (pg->graph == GR_STEPS || pg->graph == GR_ROLL) { + uint32_t ph = song.playing ? t->seq_idx : 0xFFFFu; + if (pg->graph == GR_ROLL && ph / 16u != ui.bank) + ph = 0xFFFFu; /* the roll shows the cursor's bank only */ + h ^= steps_hash(t) + ph * 31u + ui.cursor * 7919u; + } + return h; +} +/* preset browser: the global list (every engine), current one in white */ +static void graph_browse(void) +{ + uint32_t total, cur = preset_pos(&total), e, k; + int32_t row; + if (!total) + return; + for (row = -3; row <= 3; row++) { + int32_t y = 4 + (row + 3) * 17; + char tag[4], nm[13]; + int sel = row == 0; + e = preset_at((cur + total * 4u + (uint32_t)row) % total, &k); + if (e == NENGINES) { /* user preset: "U07" and its name */ + up_slot_label(tag, k); + up_name(k, nm); + } else { + str_cpy(tag, ENGINES[e]->name, sizeof tag); + str_cpy(nm, ENGINES[e]->presets[k].name, sizeof nm); + } + if (sel) + cv_rect(4, y + 6, 3, 3, C_WHITE); + cv_text(14, y, &FONT_S, tag, sel ? C_GRAY : C_DIM); + cv_text(54, y, &FONT_S, nm, sel ? C_WHITE : C_GRAY); + } +} + +/* user preset slots around the selected one: "U07 NAME" / EMPTY, the selected one in white */ +static void graph_user(void) +{ + int32_t row, first = clamp((int32_t)ui.uslot - 3, 0, UP_SLOTS - 7); + for (row = 0; row < 7; row++) { + uint32_t k = (uint32_t)(first + row); + int32_t y = 4 + row * 17; + char tag[4], nm[13]; + int sel = k == ui.uslot, used = up_used(k); + up_slot_label(tag, k); + if (used) + up_name(k, nm); + else + str_cpy(nm, "EMPTY", sizeof nm); + if (sel) + cv_rect(4, y + 6, 3, 3, C_WHITE); + cv_text(14, y, &FONT_S, tag, sel ? C_WHITE : C_GRAY); + cv_text(54, y, &FONT_S, nm, used ? (sel ? C_WHITE : C_HI) : C_DIM); + } +} + +/* project slots: used / empty, the selected one in white */ +static void graph_slots(void) +{ + uint32_t i; + for (i = 0; i < 4u; i++) { + int32_t y = 8 + (int32_t)i * 26; + char b[4]; + int sel = (int32_t)i + 1 == song.g[G_SLOT]; + b[0] = (char)('1' + i); + b[1] = 0; + if (sel) + cv_rect(4, y + 6, 3, 3, C_WHITE); + cv_text(14, y, &FONT_S, b, sel ? C_WHITE : C_GRAY); + cv_text(40, y, &FONT_S, project_used(i) ? "USED" : "EMPTY", project_used(i) ? (sel ? C_WHITE : C_HI) : C_DIM); + } +} + +/* TRACKS page: four channel strips (mixer style), one under each column: number + + * REC / ARM / MUTE, the sound's short name, then a level fader with the output meter + * (note activity), the pattern over its LEN (time running down; bar width = notes in + * the step) and the play head. The selected track is drawn bright. Every part is + * its own small canvas with its own signature: while the transport runs only the + * head markers and the meters move. (No ZOOM focus here.) */ +#define TS_HEAD_Y (Y_GRAPH + 2) +#define TS_NAME_Y (Y_GRAPH + 20) +#define TS_Y (Y_GRAPH + 38) +#define TS_H 84 /* body: rows Y_GRAPH + 38 .. + 121 */ +static struct { + uint32_t head[NTRK], name[NTRK], fader[NTRK], ov[NTRK], mark[NTRK]; + uint8_t meter[NTRK]; +} ts; + +static int32_t meter_px(int32_t a) /* |sample| (Q15) -> px: 6 dB = TS_H / 10 */ +{ + int32_t lg = 0, v; + if (a < 64) + return 0; + while ((a >> lg) > 1) + lg++; + v = lg * 8 + (((a << 3) >> lg) & 7); /* 8 log2(a): 48 (-54 dB) .. 128 (+6 dB) */ + return clamp((v - 48) * (TS_H - 2) / 80, 0, TS_H - 2); +} + +static uint32_t trk_level(uint32_t c) /* LEVEL 0..127 (the drum track: GLO > DRUMS LEVEL) */ +{ + return (uint32_t)(c == TRK_DRUM ? song.g[G_DRLVL] : trk[c].p[P_LEVEL]) & 127u; +} + +static void trk_short_name(uint32_t c, char *b) /* the track's sound, b holds 13 */ +{ + const track_t *t = &trk[c]; + const engine_t *e = ENGINES[t->eng_req % NENGINES]; + if (c == TRK_DRUM) + str_cpy(b, "DRUM", 13); + else if (user_of(t) < UP_SLOTS) + up_name(user_of(t), b); + else if (e->npresets) + str_cpy(b, e->presets[t->preset % e->npresets].name, 13); + else + str_cpy(b, e->name, 13); +} + +static void draw_tracks(void) +{ + uint32_t c; + if (ui.force) { + lcd_fill(0, Y_GRAPH, 240, H_GRAPH, C_BLACK); + for (c = 0; c < NTRK; c++) + ts.meter[c] = 0; + } + for (c = 0; c < NTRK; c++) { + track_t *t = &trk[c]; + uint32_t x0 = c * 60u + 4u, sel = c == song.sel, lvl = trk_level(c), mute = !lvl || t->p[P_MUTE]; + uint32_t arm = (song.rec >> c) & 1u, st = arm ? (song.playing ? 1u : 2u) : mute ? 3u : 0u, sig; + uint32_t len = t->p[P_SLEN] > 0 ? (uint32_t)t->p[P_SLEN] : 1u, row = 0xFFFFu; + int32_t pk, m; + char b[16]; + if (c == TRK_DRUM) { + pk = drums.peak; + drums.peak = 0; + } else { + pk = t->peak; + t->peak = 0; + } + /* head: number (white = selected), REC / ARM / MUTE */ + sig = 1u + sel + st * 2u; + if (ui.force || sig != ts.head[c]) { + ts.head[c] = sig; + b[0] = (char)('1' + c); + b[1] = 0; + cv_begin(54, 16, C_BLACK); + cv_text(0, 0, &FONT_S, b, sel ? C_WHITE : C_GRAY); + if (sel) + cv_rect(0, 15, 8, 1, C_WHITE); + if (st == 1u || st == 2u) { + cv_rect(14, 5, 6, 6, st == 1u ? C_WHITE : C_AMB); + cv_text(24, 0, &FONT_S, st == 1u ? "REC" : "ARM", st == 1u ? C_WHITE : C_AMB); + } else if (st) { + cv_text(14, 0, &FONT_S, "MUTE", C_DIM); + } + cv_blit(x0, TS_HEAD_Y); + } + /* the sound: preset name (user preset, DRUM), cut to the column */ + trk_short_name(c, b); + while (b[0] && text_w(&FONT_S, b) > 54) + b[str_len(b) - 1u] = 0; + sig = str_hash(2u + sel, b); + if (ui.force || sig != ts.name[c]) { + ts.name[c] = sig; + cv_begin(54, 16, C_BLACK); + cv_text(0, 0, &FONT_S, b, sel ? C_HI : C_DIM); + cv_blit(x0, TS_NAME_Y); + } + /* fader (LEVEL) + meter of the output */ + m = mute ? 0 : meter_px(pk); + if (m < ts.meter[c] - 3) + m = ts.meter[c] - 3; /* falls ~20 dB/s */ + ts.meter[c] = (uint8_t)(m < 0 ? 0 : m); + sig = 1u + lvl + ts.meter[c] * 128u + sel * 65536u + (sel && ui.hot_t && ui.hot_col == 1u) * 131072u + + (t->p[P_MUTE] != 0) * 262144u; + if (ui.force || sig != ts.fader[c]) { + int32_t fy = (int32_t)(TS_H - 2u) - (int32_t)lvl * (TS_H - 4) / 127; + ts.fader[c] = sig; + cv_begin(12, TS_H, C_BLACK); + cv_rect(3, 0, 1, TS_H, C_LINE); + if (lvl) { + cv_rect(2, fy, 3, TS_H - fy, C_DIM); + cv_rect(0, fy - 1, 7, 2, (sig & 131072u) ? C_WHITE : sel ? C_HI : C_GRAY); + } else { + cv_rect(0, TS_H - 2, 7, 2, C_DIM); + } + if (ts.meter[c]) + cv_rect(9, TS_H - ts.meter[c], 3, ts.meter[c], C_AMB); + cv_blit(x0, TS_Y); + } + /* the pattern: one band per step over LEN, a note step as wide as its notes */ + sig = steps_hash(t) * 31u + len * 7u + sel; + if (ui.force || sig != ts.ov[c]) { + uint32_t i; + ts.ov[c] = sig; + cv_begin(34, TS_H, C_BLACK); + cv_rect(17, 0, 1, TS_H, C_LINE); + for (i = 0; i < len; i++) { + const step_t *s = &t->step[i]; + int32_t r0 = (int32_t)(i * TS_H / len), r1 = (int32_t)((i + 1u) * TS_H / len), h = r1 - r0; + if (h > 2) + h--; /* a gap between steps when there is room */ + if (h < 1) + h = 1; + if (step_on(s)) { + int32_t w = 2 + 6 * (int32_t)s->n; + cv_rect(17 - w / 2, r0, w, h, (s->flags & SF_ACCENT) && sel ? C_WHITE : sel ? C_HI : C_GRAY); + } else if (s->time == ST_TIE) { + cv_rect(16, r0, 3, r1 - r0, C_DIM); + } + } + cv_blit(x0 + 14u, TS_Y); + } + /* play head: a small arrow right of the pattern (white while recording) */ + if (song.playing) + row = ((t->seq_idx % len) * 2u + 1u) * TS_H / (2u * len); + sig = 1u + row + (st == 1u) * 65536u; + if (ui.force || sig != ts.mark[c]) { + int32_t i; + ts.mark[c] = sig; + cv_begin(5, TS_H, C_BLACK); + if (row != 0xFFFFu) + for (i = -2; i <= 2; i++) { + int32_t w = 5 - 2 * (i < 0 ? -i : i); + cv_rect(5 - w, (int32_t)row + i, w, 1, st == 1u ? C_WHITE : C_AMB); + } + cv_blit(x0 + 49u, TS_Y); + } + } +} + +/* oscilloscope of the output, triggered on a rising zero crossing */ +static void graph_scope(uint16_t c) +{ + static int16_t snap[SCOPE_N]; + uint32_t w = scope_w, i, trig = 0; + int32_t py = 50, x, peak = 1500; + for (i = 0; i < SCOPE_N; i++) { + snap[i] = scope_buf[(w + i) & (SCOPE_N - 1u)]; + if (snap[i] > peak) + peak = snap[i]; + else if (-snap[i] > peak) + peak = -snap[i]; + } + for (i = 1; i < SCOPE_N - 240u; i++) + if (snap[i - 1] < 0 && snap[i] >= 0) { + trig = i; + break; + } + cv_line(0, 50, 239, 50, C_LINE); + for (x = 0; x < 240; x++) { + int32_t y = 50 - snap[trig + (uint32_t)x] * 44 / peak; /* auto-scaled */ + if (x) + cv_line(x - 1, py, x, y, c); + py = y; + } +} + +static void draw_graph(void) +{ + const page_t *pg = cur_page(); + const track_t *t = TSEL; + uint16_t c = TE_COL[song.sel & 3u]; /* LIVE: the curves in the track's colour */ + uint32_t sig, top, drum_note = !ui.home && is_drum(t) && !page_for_drum(pg); + if (!ui.home && pg->graph == GR_TRK) { + draw_tracks(); + ui.graph_top = 1; /* the next graph draws its top rows again */ + return; + } + sig = graph_signature(); + if (!ui.force && sig == ui.graph_sig) + return; + ui.graph_sig = sig; + cv_begin(240, H_GRAPH, C_BLACK); + cv_oy = G_OY; + if (ui.home) { + graph_scope(c); + } else if (drum_note) { /* a page the drum track has no use for */ + static const char *const L[2] = {"DRUM TRACK", "SEQ TRACKS GLO DRUMS"}; + cv_text((240 - text_w(&FONT_S, L[0])) / 2, 26, &FONT_S, L[0], C_HI); + cv_text((240 - text_w(&FONT_S, L[1])) / 2, 52, &FONT_S, L[1], C_DIM); + } else { + switch (pg->graph) { + case GR_ADSR: + graph_adsr(t, c); + break; + case GR_LFO: + graph_lfo(t, c); + break; + case GR_STEPS: + graph_steps(t, c); + break; + case GR_ROLL: + graph_roll(t, c); + break; + case GR_SCALE: + graph_scale(t, c); + break; + case GR_FX: + graph_fx(t, c); + break; + case GR_SLCR: + graph_slicer(t, c); + break; + case GR_BROWSE: + cv_oy = 0; + graph_browse(); + break; + case GR_SLOTS: + cv_oy = 0; + graph_slots(); + break; + case GR_USER: + cv_oy = 0; + graph_user(); + break; + default: + break; + } + } + top = !ui.home && !drum_note && (pg->graph == GR_BROWSE || pg->graph == GR_SLOTS || pg->graph == GR_USER); /* these draw from the top */ + cv_oy = 0; + if (ui.hot_t && settings.zoom) { /* focus (menu ZOOM): the touched value, large and white */ + int32_t x; + top = 1; + cv_rect(0, 0, 150, 50, C_BLACK); + cv_text(4, 0, &FONT_S, ui.focus_l, C_GRAY); + x = cv_text(4, 16, &FONT_L, ui.focus_v, C_WHITE); + cv_text(x + 4, 30, &FONT_S, ui.focus_u, C_DIM); + } + /* graphs keep out of the top G_OY rows: skip them unless something is (or was) there */ + cv_blit_from(0, Y_GRAPH, top || ui.graph_top || ui.force ? 0u : G_OY); + ui.graph_top = (uint8_t)top; +} + +static void draw_foot(void) +{ + char s[48], pn[16], en[10], ti[20]; + const track_t *t = TSEL; + uint32_t sig; + const page_t *pg = cur_page(); + const engine_t *e = ENGINES[TSEL->eng_req % NENGINES]; + const char *ename = is_drum(t) ? "DRUM" : e->name; + int32_t x; + pn[0] = 0; + if (is_drum(t)) + str_cpy(pn, DRUM_KIT_NAMES[drum_kit()], sizeof pn); + else if (user_of(t) < UP_SLOTS) + up_name(user_of(t), pn); /* a user preset */ + else if (e->npresets) + str_cpy(pn, e->presets[TSEL->preset % e->npresets].name, sizeof pn); + if (ui.home) { + str_cpy(ti, "HOME", sizeof ti); + } else { /* page title + number in its family: "ENV DEST 2/2" */ + uint32_t i, n = 0, k = 0; + const char *pt = pg->scope == SC_ENGINE ? e->page_title[pg->id[0] != P_E0] : 0; /* EDIT: the engine's */ + for (i = 0; i < NPAGES; i++) + if (PAGES[i].fam == pg->fam) { + n++; + if (i == ui.page) + k = n; + } + str_cpy(ti, pt ? pt : pg->title, 10); + if (n > 1) { + str_cpy(ti + str_len(ti), " ", 4); + fmt_int(ti + str_len(ti), (int32_t)k); + str_cpy(ti + str_len(ti), "/", 4); + fmt_int(ti + str_len(ti), (int32_t)n); + } + } + str_cpy(s, ename, sizeof s); + s[str_len(s) + 1u] = 0; + s[str_len(s)] = (char)('1' + song.sel); + str_cpy(s + str_len(s), pn, 16); + str_cpy(s + str_len(s), ti, sizeof ti); + { /* step markers: the playhead only when it is in the shown bank, the cursor only in SEQ */ + uint32_t ph = song.playing && t->seq_idx / 16u == ui.bank ? t->seq_idx : 0xFFu; + sig = str_hash(0x9E3779B9u, s) + ph * 97u + (song.seq_mode ? ui.cursor : 0xFFu) * 3001u + steps_hash(t) + + ui.bank * 7u + (uint32_t)t->p[P_SLEN] * 13u; + } + if (!ui.force && sig == ui.foot_sig) + return; + ui.foot_sig = sig; + cv_begin(240, H_FOOT, C_BLACK); + { + uint32_t i; + for (i = 0; i < 16u; i++) { /* row 1: the cursor's bank as 16 thin bars */ + uint32_t si = ui.bank * 16u + i; + int32_t sx = 6 + (int32_t)i * 14 + (int32_t)(i / 4u) * 4; + const step_t *st = &t->step[si]; + if (si >= (uint32_t)t->p[P_SLEN]) + continue; + if (step_on(st)) + cv_rect(sx, 2, 2, 9, TE_COL[song.sel & 3u]); + else + cv_rect(sx, 10, 1, 1, C_DIM); + if ((song.playing && si == t->seq_idx) || (song.seq_mode && si == ui.cursor)) + cv_rect(sx - 1, 13, 3, 3, C_WHITE); + } + } + x = 4; + if (FELUCCA_ICONS) { /* row 2: engine icon + name, preset, page */ + cv_icon(x, 21, engine_icon(ename), C_GRAY); + x += 14; + } + fit(en, ename, &FONT_S, 90 - (x - 4)); + x = cv_text(x, 20, &FONT_S, en, C_HI); + { + char pf[16]; + int32_t room = 236 - text_w(&FONT_S, ti) - 10 - (x + 10); + str_cpy(pf, pn, sizeof pf); + while (pf[0] && text_w(&FONT_S, pf) > room) + pf[str_len(pf) - 1u] = 0; + cv_text(x + 10, 20, &FONT_S, pf, C_AMB); + } + cv_text(236 - text_w(&FONT_S, ti), 20, &FONT_S, ti, C_GRAY); + cv_blit(0, Y_FOOT); +} +static void draw_columns(void) +{ + uint32_t c; + char val[12]; + const char *unit; + if (ui.home) { + for (c = 0; c < 4u; c++) { + int16_t *vp; + const param_desc_t *d = home_param(c, &vp); + param_format(d, *vp, val, &unit); + draw_column(c, d->label, val, unit, VAL(c), RATIO(d, *vp), param_icon(d, *vp)); + } + return; + } + if (is_drum(TSEL) && !page_for_drum(cur_page())) { /* "DRUM TRACK" (the graph says so) */ + for (c = 0; c < 4u; c++) + draw_column(c, "", "", "", C_HI, -1, ICON_AUTO); + return; + } + if (cur_page()->scope == SC_TRK) { /* TRACK LEVEL LEN PAN of the selected track */ + const track_t *t = TSEL; + uint32_t lvl = trk_level(song.sel); + fmt_int(val, (int32_t)song.sel + 1); + draw_column(0, "TRACK", val, "/4", VAL(0u), (int32_t)song.sel * 1000 / (NTRK - 1), ICON_AUTO); + if (!lvl || t->p[P_MUTE]) { /* (MUTE: a turn of KNOB 2 unmutes, tracks_edit) */ + str_cpy(val, "MUTE", 12); + unit = ""; + } else if (is_drum(t)) { + fmt_int(val, (int32_t)lvl); + unit = ""; + } else { + param_format(&TP[P_LEVEL], (int32_t)lvl, val, &unit); + } + draw_column(1, "LEVEL", val, unit, lvl && !t->p[P_MUTE] ? VAL(1u) : C_DIM, (int32_t)lvl * 1000 / 127, ICON_AUTO); + param_format(&TP[P_SLEN], t->p[P_SLEN], val, &unit); + draw_column(2, "LEN", val, unit, VAL(2u), RATIO(&TP[P_SLEN], t->p[P_SLEN]), ICON_AUTO); + param_format(&TP[P_PAN], t->p[P_PAN], val, &unit); + draw_column(3, "PAN", val, unit, VAL(3u), RATIO(&TP[P_PAN], t->p[P_PAN]), param_icon(&TP[P_PAN], t->p[P_PAN])); + return; + } + if (cur_page()->graph == GR_BROWSE) { + uint32_t total, cur = preset_pos(&total); + char u[8]; + fmt_int(val, (int32_t)cur + 1); + str_cpy(u, "/", 8); + fmt_int(u + 1, (int32_t)total); + draw_column(0, "No.", val, u, VAL(0u), -1, ICON_NONE); + draw_column(1, "ENG", ENGINES[TSEL->eng_req]->name, "", VAL(1u), -1, engine_icon(ENGINES[TSEL->eng_req]->name)); + draw_column(2, "", "", "", C_HI, -1, ICON_AUTO); + draw_column(3, "", "", "", C_HI, -1, ICON_AUTO); + return; + } + if (cur_page()->graph == GR_USER) { /* SLOT, then three GO buttons */ + int used = up_used(ui.uslot); + up_slot_label(val, ui.uslot); + draw_column(0, "SLOT", val, "", VAL(0u), (int32_t)ui.uslot * 1000 / (int32_t)(UP_SLOTS - 1u), ICON_AUTO); + draw_column(1, "LOAD", "--", "", used ? C_HI : C_DIM, -1, ICON_AUTO); + draw_column(2, "ERASE", "--", "", used ? C_HI : C_DIM, -1, ICON_AUTO); + draw_column(3, "SAVE", "--", "", C_HI, -1, ICON_AUTO); + return; + } + if (cur_page()->scope == SC_STEP) { + static const char *const TIME_N[3] = {"NOTE", "TIE", "REST"}; + const step_t *st = &TSEL->step[ui.cursor]; + char u[8]; + if (st->n) { + note_name(val, st->note[0]); + u[0] = 0; + if (st->n > 1) { + str_cpy(u, "+", 8); + fmt_int(u + 1, st->n - 1); + } + } else { + str_cpy(val, "--", 12); + u[0] = 0; + } + { + static const char *const FLAG_N[4] = {"-", "ACC", "SLD", "A+S"}; + char sn[8], sl[8]; + fmt_int(sn, (int32_t)ui.cursor + 1); + str_cpy(sl, "/", 8); + fmt_int(sl + 1, TSEL->p[P_SLEN]); + draw_column(0, "STEP", sn, sl, VAL(0u), -1, ICON_AUTO); + draw_column(1, "NOTE", val, u, step_on(st) ? VAL(1u) : C_DIM, -1, ICON_AUTO); + draw_column(2, "TIME", TIME_N[st->time % 3u], "", VAL(2u), -1, ICON_AUTO); + draw_column(3, "FLAG", FLAG_N[(st->flags & SF_ACCENT ? 1u : 0u) | (st->flags & SF_SLIDE ? 2u : 0u)], "", + VAL(3u), -1, ICON_AUTO); + } + return; + } + for (c = 0; c < 4u; c++) { + int16_t *vp; + const param_desc_t *d = page_desc(cur_page(), c, &vp); + if (!d || !d->label || d->label[0] == '-') { + draw_column(c, "", "", "", C_HI, -1, ICON_AUTO); + continue; + } + if (cur_page()->id[c] == G_MIDI && cur_page()->scope == SC_GLOBAL) { + str_cpy(val, !usb.up ? "OFF" : usb.config ? "MIDI" : usb.setups ? "ENUM" : usb.sof_seen ? "BUS" : "WAIT", 12); + unit = "USB"; + draw_column(c, "USB", val, unit, C_HI, -1, ICON_AUTO); + continue; + } + if (cur_page()->id[c] == G_INFO && cur_page()->scope == SC_GLOBAL) { + fmt_int(val, (int32_t)(song.cpu_q8 * 100u / 256u)); + unit = "%"; + } else { + param_format(d, *vp, val, &unit); + } + draw_column(c, d->label, val, unit, VAL(c), d->fmt == F_ENUM && d->max < 2 ? -1 : RATIO(d, *vp), + param_icon(d, *vp)); + } +} + + +/* the UI's timers, once a frame whatever the screen (a message, the BPM highlight, an armed GO, the + * white value of the knob just turned) */ +static void ui_timers(void) +{ + if (ui.msg_t) + ui.msg_t--; + if (ui.bpm_t) + ui.bpm_t--; + if (ui.arm_t && !--ui.arm_t) + ui.arm = 0; + if (ui.hot_t) + ui.hot_t--; +} + +static void ui_draw(void) +{ + ui.frame++; + pads_tick(); + if (rec_go) { /* the take started: say so */ + rec_go = 0; + ui_message("RECORDING"); + } + if (ft_bars) { /* a free take closed: the loop it made */ + char m[24]; + uint32_t n = ft_bars; + ft_bars = 0; + if (n == 0xFFu) { + ui_message("TAKE DROPPED"); + } else { + str_cpy(m, n == 1u ? "LOOP 1 BAR " : n == 2u ? "LOOP 2 BARS " : "LOOP 4 BARS ", sizeof m); + fmt_int(m + str_len(m), song.g[G_BPM]); + str_cpy(m + str_len(m), " BPM", sizeof m - str_len(m)); + ui_message(m); + } + } + if (er_flash) { /* EDIT + key took something out */ + er_flash = 0; + if (!ui.msg_t) + ui_message("ERASED"); + } + if (!ui.menu && (ui.layer != LY_PLAY || ui.hold_kind)) { /* a layer held / a hold to confirm */ + if (ui.hold_kind) + hold_screen_draw(); + else + layer_screen_draw(); + ui_timers(); + ui.force = 0; + return; + } + if (layer_shown) { /* back to the page */ + layer_shown = 0; + lcd_fill(0, 0, 240, 240, C_BLACK); + ui.force = 1; + } + if ((rec_wait || ft_on) && !ui.menu && !on_song_page()) { /* armed / free take */ + rec_screen_draw(); + ui_timers(); + ui.force = 0; + return; + } + if (rec_shown) { /* back to the page */ + rec_shown = 0; + lcd_fill(0, 0, 240, 240, C_BLACK); + ui.force = 1; + } +#if FELUCCA_ARRANGER + if (!ui.menu && on_song_page()) { + song_screen_draw(); + ui_timers(); + ui.force = 0; + return; + } +#endif + if (ui.menu) { + draw_menu(); + ui_timers(); + ui.force = 0; + return; + } + if (!ui.home && cur_page()->scope == SC_TRK) { + studio_tracks_draw(); + ui_timers(); + ui.force = 0; + return; + } + if (on_drum_page()) { + drum_screen_draw(); + ui_timers(); + ui.force = 0; + return; + } + cursor_fix(); + if (ui.force) + draw_frame(); + felucca_dbg.stage = 3; + draw_head(); + felucca_dbg.stage = 4; + draw_columns(); + felucca_dbg.stage = 5; + draw_graph(); + ui_timers(); + felucca_dbg.stage = 6; + draw_foot(); + ui.force = 0; +} diff --git a/firmware/src/ui_input.c b/firmware/src/ui_input.c new file mode 100644 index 0000000..8b1d097 --- /dev/null +++ b/firmware/src/ui_input.c @@ -0,0 +1,806 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* Felucca UI input: LEDs, knobs and buttons, the layers (ui_layers.c), holds, SEQ step entry, panel setup. */ +/* ----------------------------------------------------------- LEDs --- */ +/* The LED picture is built off-line and copied one byte per column: clearing + * and relighting would let the 10 kHz scan catch the dark gap and flicker. */ +static uint8_t led_pos[41]; /* (col << 3) | row bit, 0xFF = none */ + +static void led_pos_init(void) +{ + uint32_t id, p, r; + for (id = 0; id < 41u; id++) { + led_pos[id] = 0xFF; + for (p = 0; p < FM1_NCOL; p++) + for (r = 1; r < 5u; r++) + if (FM1_KEYMAP[r][p] == (int8_t)id) + led_pos[id] = (uint8_t)((p << 3) | r); + } +} + +static void led_put(uint8_t *nl, uint32_t id, int on) +{ + uint8_t q = led_pos[id]; + if (q != 0xFF && on) + nl[q >> 3] |= (uint8_t)(1u << (q & 7u)); +} + +static const uint8_t FAM_BTN[FAM_COUNT] = {B_HOME, B_ENV, B_LFO, B_FX, B_SCL, B_EDIT, B_GLO, B_SAVE, + B_ARP, B_SEQ, B_HOME}; /* button of each page family (TRACKS: HOME) */ + +static uint32_t cur_fam(void) { return ui.home ? FAM_HOME : cur_page()->fam; } +static uint32_t cur_btn(void) /* the button of the screen shown */ +{ + if (!ui.home && cur_page()->scope == SC_SONG) + return B_SAVE; + if (!ui.home && cur_page()->scope == SC_DRUM) + return B_SEQ; + return FAM_BTN[cur_fam()]; +} + +/* PLAY flashes on every beat, as heard (the sound leaves ~9 ms after it is rendered) */ +static int play_led(void) +{ + uint32_t p = clk_pos, lat = HALF_FRAMES * 3u / 2u * (uint32_t)song.g[G_BPM]; + if (!song.playing) + return 0; + p = p >= lat ? p - lat : p + BEAT_U - lat; + return p < BEAT_U / 4u; +} + +/* the keys' lights: what the layer held does, else the keys down and the drum hits */ +static uint32_t keys_lit(void) +{ + uint32_t m = 0, i, blink = (fm1_ms / 125u) & 1u; + track_t *t = TSEL; + switch (ui.layer) { + case LY_FX: + return punch.req >= 0 ? 1u << key_of_white((uint32_t)punch.req) : 0u; + case LY_STEP: { /* the steps that play; the playhead blinks */ + uint32_t len = trk_len(t); + for (i = 0; i < 16u; i++) { + uint32_t idx = ui.step_page * 16u + i, on; + if (idx >= len) + continue; + on = is_drum(t) ? dstep_has(&t->dstep[idx], pen_lane) : step_on(&t->step[idx]); + if (song.playing && idx == t->seq_idx) + on = !on || blink; + if (on) + m |= 1u << key_of_white(i); + } + return m | fm1_in.notes; + } + case LY_SCALE: { /* the keys in the scale; the root blinks */ + uint32_t root = (uint32_t)trk[0].p[P_ROOT] % 12u, mask = SCALE_MASK[clamp(trk[0].p[P_SCALE], 0, NSCALES - 1)]; + for (i = 0; i < 27u; i++) { + uint32_t d = (53u + i - root + 120u) % 12u; + if ((mask >> d) & 1u && (d || blink)) + m |= 1u << i; + } + return m; + } + case LY_MIX: /* tracks heard: 1..4; soloed: 5..8; tap: the beat */ + for (i = 0; i < 4u; i++) { + if (!trk_silent(&trk[i])) + m |= 1u << key_of_white(i); + if ((song.solo >> i) & 1u) + m |= 1u << key_of_white(4u + i); + } + if (play_led()) + m |= 1u << key_of_white(15); + return m; + case LY_ERASE: /* the sounds the pattern holds */ + if (is_drum(t)) + for (i = 0; i < trk_len(t); i++) { + uint32_t l, d = dstep_mask(&t->dstep[i]); + for (l = 0; d; l++, d >>= 1) + if (d & 1u) + m |= 1u << key_of_white(l); + } + return m | fm1_in.notes; + default: + break; + } + m = fm1_in.notes; + if (is_drum(t)) /* the drum track: each hit lights its key */ + for (i = 0; i < DRUM_LANES; i++) + if (pad_lit[i]) + m |= 1u << key_of_white(i); + return m; +} + +static void ui_leds(void) +{ + uint8_t nl[FM1_NCOL] = {0}; + uint32_t k, c, keys; + static uint8_t ready; + if (!ready) { + led_pos_init(); + ready = 1; + } + led_put(nl, panel.btn[ui.layer != LY_PLAY ? LAYER_BTN[ui.layer] : cur_btn()], 1); + led_put(nl, panel.btn[B_PLAY], play_led() || (song.playing && !song.rec && ft_on)); + led_put(nl, panel.btn[B_REC], song.rec != 0u || ft_on || (rec_wait && ((fm1_ms / 125u) & 1u)) || + (ui.hold_kind == 1u && ((fm1_ms / 60u) & 1u))); /* blinks: armed; fast: clearing */ + if (is_drum(TSEL)) { /* the drum track: OCT- / OCT+ lit while ghost / hard */ + led_put(nl, panel.btn[B_OCTDN], (fm1_in.buttons & dyn_bit[0]) != 0u); + led_put(nl, panel.btn[B_OCTUP], (fm1_in.buttons & dyn_bit[1]) != 0u); + } else { + led_put(nl, panel.btn[B_OCTDN], song.octave < 0); + led_put(nl, panel.btn[B_OCTUP], song.octave > 0); + } + keys = keys_lit(); + for (k = 0; k < 27u; k++) + led_put(nl, 14u + k, (int)((keys >> k) & 1u)); + for (c = 0; c < FM1_NCOL; c++) + fm1_led[c] = nl[c]; +} + +/* ---------------------------------------------------------- input --- */ +static int32_t accel(uint32_t role, int32_t s, int32_t range) +{ + uint32_t now = fm1_ticks(), dt = now - ui.enc_t[role]; + ui.enc_t[role] = now; + if (range > 40 && dt < 60u * 1000u * FM1_TICKS_PER_US) + return s * (range > 150 ? 6 : 3); + return s; +} + +/* TRACKS page: KNOB 1 SWING (the groove of every track, MPC 50..75 %), 2 LEVEL (0 = mute; the drum + * track: GLO > DRUMS LEVEL), 3 LEN of its pattern, 4 PAN. A track muted with MUTE (GLO + key, the + * editor): the first turn of KNOB 2 unmutes it */ +static void tracks_edit(uint32_t slot, int32_t steps) +{ + track_t *t = TSEL; + int16_t *vp; + const param_desc_t *d; + switch (slot) { + case 0: + vp = &song.g[G_SWING]; + d = &GP[G_SWING]; + break; + case 1: + if (t->p[P_MUTE]) { + t->p[P_MUTE] = 0; + return; + } + vp = is_drum(t) ? &song.g[G_DRLVL] : &t->p[P_LEVEL]; + d = is_drum(t) ? &GP[G_DRLVL] : &TP[P_LEVEL]; + break; + case 2: + vp = &t->p[P_SLEN]; + d = &TP[P_SLEN]; + break; + default: + vp = &t->p[P_PAN]; + d = &TP[P_PAN]; + break; + } + *vp = (int16_t)clamp(*vp + accel(EN_K1 + slot, steps, d->max - d->min), d->min, d->max); +} + +static void step_edit(uint32_t slot, int32_t steps) +{ + step_t *st = &TSEL->step[ui.cursor]; + uint32_t i; + if (is_drum(TSEL)) + return; /* (the drum track: its grid) */ + switch (slot) { + case 0: /* STEP: the cursor */ + cursor_set(ui.cursor + steps); + break; + case 1: /* NOTE: transpose the step */ + if (!st->n) { + st->note[0] = last_note; + st->n = 1; + st->time = ST_NOTE; + break; + } + for (i = 0; i < st->n; i++) + st->note[i] = (uint8_t)clamp(st->note[i] + steps, 1, 127); + st->time = ST_NOTE; + last_note = st->note[0]; + break; + case 2: + st->time = (uint8_t)clamp((int32_t)st->time + (steps > 0 ? 1 : -1), ST_NOTE, ST_REST); + break; + default: { /* FLAG: - / ACC / SLD / A+S */ + uint32_t f = (st->flags & SF_ACCENT ? 1u : 0u) | (st->flags & SF_SLIDE ? 2u : 0u); + f = (uint32_t)clamp((int32_t)f + (steps > 0 ? 1 : -1), 0, 3); + st->flags = (uint8_t)((st->flags & ~(SF_ACCENT | SF_SLIDE)) | (f & 1u ? SF_ACCENT : 0u) | (f & 2u ? SF_SLIDE : 0u)); + break; + } + } +} + +/* a new project: every track empty, the default sounds, 90 BPM (TOOLS > NEW) */ +static void project_new(void) +{ + uint32_t i; + transport_req = 2; + panic_req = (1u << NTRK) - 1u; + for (i = 0; i < NTRK; i++) { + track_t *t = &trk[i]; + undo_mark(t, (undo_sess += 4u) | 3u); + fm1_irq_off(); + track_defaults(t); + if (i < NPART) { + set_engine_of(t, TRK_DEF[i][0]); + apply_preset_to(t, TRK_DEF[i][1]); + } + fm1_irq_on(); + } + TDRUM->p[P_E0] = DRUM_DEFAULT_KIT; + for (i = 0; i < G_COUNT; i++) + if (i != G_SLOT && i != G_DRCH) + song.g[i] = GP[i].def; + song.solo = 0; + song.octave = 0; + sync_reload = 1; + ui.force = 1; +} + +static void edit_param(uint32_t slot, int32_t steps) +{ + int16_t *vp; + const page_t *pg = cur_page(); + const param_desc_t *d; + uint32_t id = pg->id[slot]; + int32_t v; + if (is_drum(TSEL) && !page_for_drum(pg)) + return; /* "DRUM TRACK": nothing to edit here */ + if (pg->scope == SC_STEP) { + step_edit(slot, steps); + return; + } + if (pg->scope == SC_TRK) { + tracks_edit(slot, steps); + return; + } + if (pg->graph == GR_BROWSE) { /* KNOB 1: one preset, KNOB 2: the next / previous engine */ + if (slot == 0u && !is_drum(TSEL)) { + uint32_t total, cur = preset_pos(&total); + if (total) + preset_go((uint32_t)(((int32_t)cur + steps % (int32_t)total + (int32_t)total) % (int32_t)total)); + } else if (slot == 1u && !is_drum(TSEL)) { + select_engine((TSEL->eng_req + (steps > 0 ? 1u : NENGINES - 1u)) % NENGINES); + } + return; + } + if (pg->graph == GR_USER) { /* KNOB 1 slot; LOAD / ERASE / SAVE: GO buttons */ + static const char *const UP_GO[3] = {"LOAD", "ERASE", "SAVE"}; + if (slot == 0u) { + ui.uslot = (uint8_t)clamp((int32_t)ui.uslot + steps, 0, UP_SLOTS - 1); + ui.arm = 0; + return; + } + if (steps <= 0) + return; + if (ui.arm != 0xE0u + slot) { /* one detent arms, a second one within ~1.5 s acts */ + ui.arm = (uint8_t)(0xE0u + slot); + ui.arm_t = 90; + ui_say("AGAIN: ", UP_GO[slot - 1u]); + return; + } + ui.arm = 0; + up_ui(slot - 1u, ui.uslot); + return; + } + d = page_desc(pg, slot, &vp); + if (!d || !vp || d->max == d->min) + return; + v = clamp(*vp + accel(EN_K1 + slot, steps, d->max - d->min), d->min, d->max); + *vp = (int16_t)v; + if (!v) + return; + if (pg->scope == SC_GLOBAL && (id == G_LOAD || id == G_SAVE || id == G_CLRSEQ || id == G_INITSND || id == G_NEWPRJ) && + ui.arm != id) { /* one detent arms, a second one within ~1.5 s acts */ + *vp = 0; + ui.arm = (uint8_t)id; + ui.arm_t = 90; + ui_say("AGAIN: ", d->label); + return; + } + ui.arm = 0; + if (pg->scope != SC_GLOBAL) + return; + switch (id) { /* GO buttons: act, then back to 0 */ + case G_LOAD: + *vp = 0; + project_load((uint32_t)song.g[G_SLOT] - 1u); + break; + case G_SAVE: + *vp = 0; + project_save((uint32_t)song.g[G_SLOT] - 1u); + break; + case G_CLRSEQ: + *vp = 0; + undo_mark(TSEL, (undo_sess += 4u) | 3u); + fm1_irq_off(); + track_defaults_steps(TSEL); + fm1_irq_on(); + ui_message("PATTERN CLEARED"); + break; + case G_INITSND: + *vp = 0; + set_engine(TSEL->eng_req); /* engine defaults + its first preset */ + ui_message("SOUND INIT"); + ui.force = 1; + break; + case G_NEWPRJ: + *vp = 0; + project_new(); + ui_message("NEW PROJECT"); + break; + default: + break; + } +} + +/* SEQ step entry, acid style: the keys pressed together (POLY: up to 4, MONO: + * the last one) become the cursor step; releasing all keys moves on. Not while recording or armed: + * the keys record live then (they would be written twice) */ +static void seq_entry(uint32_t pressed) +{ + track_t *t = TSEL; + step_t *st = &t->step[ui.cursor]; + uint32_t k; + if (is_drum(t) || song.rec || rec_wait || ft_on) + return; + for (k = 0; k < 27u; k++) { + uint32_t note; + if (!((pressed >> k) & 1u)) + continue; + note = kb_map(t, k); + if (note == KB_SILENT) + continue; + if (!ui.entry_open) { + ui.entry_open = 1; + undo_mark(t, (undo_sess += 4u) | 3u); + st->n = 0; + st->lvl = st->rat = 0; + st->time = ST_NOTE; + } + if (t->p[P_VOICE]) { + st->note[0] = (uint8_t)note; + st->n = 1; + } else if (st->n < 4u) { + st->note[st->n++] = (uint8_t)note; + } + last_note = (uint8_t)note; + } + if (ui.entry_open && !fm1_in.notes) + cursor_set(ui.cursor + 1); +} + +/* HOME: tap on release, hold 0.7 s fires once. t0 = press time | 1, + * bit 1 = fired (or swallowed: then the release is no tap either) */ +enum { BT_NONE, BT_TAP, BT_HOLD }; +static uint32_t btn_hold(uint32_t *t0, uint32_t label, uint32_t now, int hold_ok) +{ + uint32_t tap; + if ((fm1_in.buttons >> panel.btn[label]) & 1u) { + if (!*t0) + *t0 = (now | 1u) & ~2u; + else if (hold_ok && !(*t0 & 2u) && now - (*t0 & ~3u) > 700u * 1000u * FM1_TICKS_PER_US) { + *t0 |= 2u; + return BT_HOLD; + } + return BT_NONE; + } + tap = *t0 && !(*t0 & 2u); + *t0 = 0; + return tap ? BT_TAP : BT_NONE; +} + +/* a layer button tapped (pressed and let go, nothing touched): its pages, as before the layers */ +static void layer_tap(uint32_t layer) +{ + switch (layer) { + case LY_FX: + open_family(FAM_FX); + break; + case LY_ERASE: + case LY_STEP: + if (on_drum_page()) { /* DRUMS: GRID <-> KIT */ + drum_page = (uint8_t)((drum_page + 1u) % 2u); + ui.force = 1; + break; + } + if (!ui.home && cur_page()->scope == SC_TRK && is_drum(TSEL)) { + studio_open(SC_DRUM); + break; + } + if (layer == LY_ERASE && song.seq_mode && cur_page()->scope == SC_STEP && !is_drum(TSEL)) { + undo_mark(TSEL, (undo_sess += 4u) | 3u); /* STEP page: EDIT clears the step */ + step_clear(&TSEL->step[ui.cursor]); + cursor_set(ui.cursor + 1); + ui_message("STEP CLEARED"); + break; + } + open_family(layer == LY_STEP ? FAM_SEQ : FAM_EDIT); + break; + case LY_ROLL: + open_family(FAM_ARP); + break; + case LY_SCALE: + open_family(FAM_SCL); + break; + case LY_MIX: + open_family(FAM_GLO); + break; + default: + break; + } +} + +/* the layers, once a frame: which one is held, the taps on release, its keys and knobs. Returns 1 + * while one is held (the page does not take the knobs then) */ +static int layers_input(uint32_t note_edges) +{ + static uint8_t down[LY_COUNT], used[LY_COUNT]; + static uint32_t t0[LY_COUNT]; + uint32_t l, now = fm1_ms, held = LY_PLAY; + for (l = LY_FX; l < LY_COUNT; l++) { + uint32_t d = (fm1_in.buttons & ly_bit[l]) != 0u; + if (d && !down[l]) { + t0[l] = now; + used[l] = 0; + } + if (d && note_edges) + used[l] = 1; /* a key while held: not a tap */ + if (!d && down[l] && !used[l] && now - t0[l] < TAP_MS && !ui.menu && !ui.confirm) + layer_tap(l); + down[l] = (uint8_t)d; + if (d && held == LY_PLAY) + held = l; + } + punch.hold = (uint8_t)(held == LY_FX); + if (held != LY_PLAY && held != ui.layer && ui.layer != LY_PLAY) + ui.layer = (uint8_t)held; /* (from one layer straight to another) */ + if (held == LY_PLAY) { + while (lk_r != lk_w) { /* a key let go after its layer: its release only */ + uint32_t e = lk_q[lk_r % LKQ]; + lk_r++; + if (!((e >> 7) & 1u)) + layer_key(e >> 8, e & 31u, 0); + } + if (ui.layer != LY_PLAY) { + ui.layer = LY_PLAY; + ui.step_held = 0; + ui.force = 1; /* the page comes back */ + } + ui.step_sess = 0; + return 0; + } + ui.layer_used = used[held]; + while (lk_r != lk_w) { /* the keys of SEQ, SCL, GLO (seq.c) */ + uint32_t e = lk_q[lk_r % LKQ]; + lk_r++; + used[held] = 1; + layer_key(e >> 8, e & 31u, (e >> 7) & 1u); + } + layer_knobs(held); + if (ui.layer_used) + used[held] = 1; + if (ui.layer == LY_PLAY && (used[held] || now - t0[held] >= SHOW_MS)) { + ui.layer = (uint8_t)held; /* show it (not for a quick tap) */ + if (held == LY_STEP && (uint32_t)ui.step_page * 16u >= trk_len(TSEL)) + ui.step_page = 0; + } + if (held == LY_ERASE) { /* EDIT + OCT- / OCT+: undo / redo */ + uint32_t ob = 1u << panel.btn[B_OCTDN], pb = 1u << panel.btn[B_OCTUP]; + static uint32_t prev; + uint32_t b = fm1_in.buttons & (ob | pb), press = b & ~prev; + prev = b; + if (press) { + used[held] = 1; + if (press & ob) + ui_message(undo_swap(0) ? "UNDO" : "NOTHING TO UNDO"); + else + ui_message(undo_swap(1) ? "REDO" : "NOTHING TO REDO"); + } + } + if (held == LY_STEP) { /* SEQ + OCT- / OCT+: the page */ + uint32_t ob = 1u << panel.btn[B_OCTDN], pb = 1u << panel.btn[B_OCTUP]; + static uint32_t prev; + uint32_t b = fm1_in.buttons & (ob | pb), press = b & ~prev, pages = (trk_len(TSEL) + 15u) / 16u; + prev = b; + if (press) { + used[held] = 1; + ui.step_page = (uint8_t)((ui.step_page + ((press & pb) ? 1u : pages - 1u)) % pages); + } + } + return 1; +} + +/* REC: acts on the press (no lag). Held 0.7 s the press is undone and a ring fills: held on to the + * end, the selected track is cleared (EDIT + OCT- brings it back); let go before, nothing happens. + * SAVE: tapped, its pages (TRACKS: the song); held, the ring, then the project is saved into its slot */ +static void holds_input(uint32_t pressed, uint32_t now_ms) +{ + static uint8_t prev_rec, prev_wait, eaten, rec_on, save_on; /* *_on: pressed, *_t0 its time */ + static uint32_t rec_t0, save_t0; + uint32_t rb = 1u << panel.btn[B_REC], sb = 1u << panel.btn[B_SAVE]; + uint32_t rec_down = (fm1_in.buttons & rb) != 0u, save_down = (fm1_in.buttons & sb) != 0u; + if (on_song_page()) + rec_down = 0, pressed &= ~rb; /* (the song page: REC stores a section) */ + /* REC */ + if (pressed & rb) { + eaten = (uint8_t)ft_owns_press(); /* (the press closed a free take: seq.c) */ + prev_rec = song.rec; + prev_wait = rec_wait; + rec_t0 = now_ms; + rec_on = 1; + rec_toggle(); + } + if (rec_down && rec_on && !eaten && !ui.hold_kind && now_ms - rec_t0 >= 700u) { + song.rec = prev_rec; /* a hold: the press is undone */ + rec_wait = prev_wait; + ui.msg_t = 0; + ui.hold_kind = 1; + ui.hold_t0 = now_ms; + ui.hold_trk = song.sel; + ui.force = 1; + } + if (ui.hold_kind == 1u && rec_down && now_ms - ui.hold_t0 >= HOLD_CLEAR_MS) { + track_t *t = &trk[ui.hold_trk % NTRK]; + char b[12] = "1 CLEARED"; + undo_mark(t, (undo_sess += 4u) | 3u); + fm1_irq_off(); + track_defaults_steps(t); + t->nheld = 0; /* and the latched arp chord */ + t->arp_phys = 0; + fm1_irq_on(); + b[0] = (char)('1' + ui.hold_trk); + ui_say("TRACK ", b); + ui.hold_kind = 0; + rec_on = 0; /* (until REC is up: nothing more) */ + ui.force = 1; + } + if (!rec_down) { + if (ui.hold_kind == 1u) { + ui.hold_kind = 0; /* let go before the end: nothing */ + ui.force = 1; + } + rec_on = 0; + } + /* SAVE */ + if (pressed & sb) { + save_t0 = now_ms; + save_on = 1; + } + if (save_down && save_on && !ui.hold_kind && now_ms - save_t0 >= 600u && !on_song_page()) { + ui.hold_kind = 2; + ui.hold_t0 = now_ms; + ui.force = 1; + } + if (ui.hold_kind == 2u && save_down && now_ms - ui.hold_t0 >= HOLD_SAVE_MS) { + ui.hold_kind = 0; + save_on = 0; + ui.force = 1; + project_save((uint32_t)clamp(song.g[G_SLOT], 1, 4) - 1u); + } + if (!save_down) { + if (ui.hold_kind == 2u) { + ui.hold_kind = 0; + ui.force = 1; + } else if (save_on && now_ms - save_t0 < 600u) { /* a tap: TRACKS -> the song, else the SAVE pages */ + if (on_song_page()) + arrangement_save(); + else if (!ui.home && cur_page()->scope == SC_TRK) + studio_open(SC_SONG); + else if (on_drum_page()) + studio_open(SC_SONG); + else + open_family(FAM_SAVE); + } + save_on = 0; + } +} + +static void ui_input(void) +{ + uint32_t pressed = fm1_input_edges(0), notes = fm1_input_note_edges(), now = fm1_ticks(), id, b, k; + uint32_t home = btn_hold(&ui.home_t0, B_HOME, now, 1); + int32_t s; + int layered; + if (pressed || notes) + ui_input_ms = fm1_ms; + if (home == BT_HOLD) { /* HOME held: open the menu, or leave it */ + if (ui.menu) { + menu_close(); + } else { + ui.menu = 1; + ui.menu_sel = 0; + ui.confirm = 0; + ui.force = 1; + song.seq_mode = 0; + } + } + if (ui.menu) { /* HOME / REC taps do nothing here */ + punch.hold = 0; + if (!ui.home_t0) + menu_input(pressed); + return; + } + layered = layers_input(notes); + pressed &= ~(ly_bit[LY_FX] | ly_bit[LY_ERASE] | ly_bit[LY_ROLL] | ly_bit[LY_STEP] | ly_bit[LY_SCALE] | ly_bit[LY_MIX]); + holds_input(pressed, fm1_ms); + pressed &= ~((on_song_page() ? 0u : 1u << panel.btn[B_REC]) | (1u << panel.btn[B_SAVE])); + if (layered || ui.hold_kind) { /* a layer / a hold: the rest waits */ + if ((s = panel_enc(EN_SELECT)) != 0) { /* (the tempo always) */ + song.g[G_BPM] = (int16_t)clamp(song.g[G_BPM] + accel(EN_SELECT, s, 200), GP[G_BPM].min, GP[G_BPM].max); + ui.bpm_t = 40; + } + panel_enc(EN_ALGO); /* (track and sound wait: no jump afterwards) */ + panel_enc(EN_PRESET); + if (ui.hold_kind) + for (k = 0; k < 4u; k++) + panel_enc(EN_K1 + k); + pressed &= ~((1u << panel.btn[B_OCTDN]) | (1u << panel.btn[B_OCTUP])); /* (undo, pages, ghost / hard) */ + if (!(pressed & (1u << panel.btn[B_PLAY]))) + return; + pressed &= 1u << panel.btn[B_PLAY]; /* PLAY still plays */ + } + if (rec_wait || ft_on) { /* the REC screen is up: KNOB 1..4 edit nothing */ + for (k = 0; k < 4u; k++) /* hidden (tempo and sound still work; the track */ + panel_enc(EN_K1 + k); /* too, while armed: the arm follows) */ + } +#if FELUCCA_ARRANGER + if (on_song_page()) { + song_screen_input(pressed, home); + return; + } + if (on_drum_page()) { + drum_screen_input(pressed, home); + return; + } +#endif + if (home == BT_TAP) /* HOME acts on release: a hold opens the menu */ + go_home(); + cursor_fix(); /* LEN may have changed (knob, editor, load) */ + for (id = 0; id < 14u; id++) { + if (!((pressed >> id) & 1u)) + continue; + b = panel_btn_of(id); + switch (b) { + case B_PLAY: +#if FELUCCA_ARRANGER + if (!song.playing && arrangement_enabled && !arr_valid(&arrangement, arrangement_ready())) { + ui_message("EMPTY SECTION: REC"); + break; + } +#endif + if (!ft_owns_press()) /* (it closed or dropped a free take: seq.c) */ + transport_req = song.playing ? 2 : 1; + break; + case B_OCTDN: + case B_OCTUP: { + uint32_t both = (1u << panel.btn[B_OCTDN]) | (1u << panel.btn[B_OCTUP]); + if (is_drum(TSEL)) + break; /* the drum track: ghost / hard while held (seq.c) */ + if ((fm1_in.buttons & both) == both) + song.octave = 0; + else + song.octave += b == B_OCTDN ? (song.octave > -3 ? -1 : 0) : (song.octave < 3 ? 1 : 0); + break; + } + case B_ENV: + open_family(FAM_ENV); + break; + case B_LFO: + open_family(FAM_LFO); + break; + default: + break; + } + } + if (song.seq_mode && cur_page()->scope == SC_STEP) + seq_entry(notes); + + if ((s = panel_enc(EN_PRESET)) != 0 && (ui.home || cur_page()->graph == GR_BROWSE || cur_fam() == FAM_TRK)) { + /* PRESETS browses the selected part's presets (all engines, then user presets) on HOME, the PRESETS + * page and TRACKS only (the drum track: its kits); elsewhere a stray turn would throw away the sound + * being edited. Every detent counts */ + uint32_t total, cur = preset_pos(&total); + if (is_drum(TSEL)) + TDRUM->p[P_E0] = (int16_t)clamp(TDRUM->p[P_E0] + s, 0, DRUM_KITS - 1); + else if (total) + preset_go((uint32_t)(((int32_t)cur + s % (int32_t)total + (int32_t)total) % (int32_t)total)); + } + if ((s = panel_enc(EN_ALGO)) != 0 && !ft_on) /* ALGORITHM: the selected track, on every page (not in a take) */ + track_select((uint32_t)clamp((int32_t)song.sel + (s > 0 ? 1 : -1), 0, NTRK - 1)); + if ((s = panel_enc(EN_SELECT)) != 0) { /* SELECT knob = global tempo */ + song.g[G_BPM] = (int16_t)clamp(song.g[G_BPM] + accel(EN_SELECT, s, 200), GP[G_BPM].min, GP[G_BPM].max); + ui.bpm_t = 40; /* the header's BPM lights up; no message over the header */ + } + for (k = 0; k < 4u; k++) { + const page_t *pg = cur_page(); + int16_t *hv; + if ((s = panel_enc(EN_K1 + k)) == 0) + continue; + if (ui.home || pg->scope == SC_STEP || pg->scope == SC_TRK || page_desc(pg, k, &hv) || + (pg->graph == GR_USER && k == 0u)) { /* (not an empty column, nor "DRUM TRACK") */ + ui.hot_col = (uint8_t)k; + ui.hot_t = 40; + } + if (ui.home) { + int16_t *vp; + const param_desc_t *d = home_param(k, &vp); + *vp = (int16_t)clamp(*vp + accel(EN_K1 + k, s, d->max - d->min), d->min, d->max); + } else { + edit_param(k, s); + } + } +} + +/* ---------------------------------------------------- panel setup --- */ +/* 30 s without input: give up and keep the old table (a stuck key cannot hang the boot) */ +#define SETUP_IDLE_MS 30000u +static void panel_setup(void) +{ + uint32_t i, used = 0, t0 = fm1_ms; + const panel_t old = panel; + lcd_fill(0, 0, 240, 240, C_BLACK); + draw_text_box(0, 10, 240, &FONT_S, "HARDWARE CALIBRATION", C_WHITE, 1); + draw_text_box(0, 30, 240, &FONT_S, "TEACH EACH BUTTON AND KNOB", C_GRAY, 1); + while (fm1_in.buttons) { /* wait for OCT-/OCT+ release */ + fm1_wdt_feed(); + if (fm1_ms - t0 > SETUP_IDLE_MS) + goto timeout; + } + fm1_input_edges(0); + for (i = 0; i < NB; i++) { + uint32_t p = 0, id; + draw_text_box(0, 80, 240, &FONT_S, "PRESS", C_GRAY, 1); + draw_text_box(0, 100, 240, &FONT_L, B_NAME[i], C_WHITE, 1); + t0 = fm1_ms; + while (!(p & ~used)) { + fm1_wdt_feed(); + p |= fm1_input_edges(0); + if (fm1_ms - t0 > SETUP_IDLE_MS) + goto timeout; + } + for (id = 0; id < 14u; id++) + if (((p & ~used) >> id) & 1u) + break; + panel.btn[i] = (uint8_t)id; + used |= 1u << id; + } + used = 0; + for (i = 0; i < NE; i++) { + uint32_t e; + int32_t st = 0; + draw_text_box(0, 80, 240, &FONT_S, "TURN RIGHT", C_GRAY, 1); + draw_text_box(0, 100, 240, &FONT_L, E_NAME[i], C_WHITE, 1); + for (e = 0; e < 7u; e++) + fm1_enc_take(e); + t0 = fm1_ms; + for (;;) { + fm1_wdt_feed(); + if (fm1_ms - t0 > SETUP_IDLE_MS) + goto timeout; + for (e = 0; e < 7u; e++) + if (!((used >> e) & 1u) && (st = fm1_enc_take(e)) != 0) + break; + if (e < 7u) + break; + } + panel.enc[i] = (uint8_t)e; + panel.dir[i] = (int8_t)(st > 0 ? 1 : -1); + used |= 1u << e; + fm1_delay_ms(300); + fm1_enc_take(e); + } + panel.magic = PANEL_MAGIC; + lcd_fill(0, 0, 240, 240, C_BLACK); + layers_init(); + ui.force = 1; + return; +timeout: + panel = old; + lcd_fill(0, 0, 240, 240, C_BLACK); + ui.force = 1; + ui_message("SETUP CANCELLED"); +} diff --git a/firmware/src/ui_layers.c b/firmware/src/ui_layers.c new file mode 100644 index 0000000..0578786 --- /dev/null +++ b/firmware/src/ui_layers.c @@ -0,0 +1,674 @@ +/* SPDX-License-Identifier: GPL-3.0-only */ +/* LAYERS, teenage-engineering style: hold a function button, touch a key (or turn a knob). While the + * button is held the screen shows what the 16 white keys and KNOB 1..4 do now; tapped (pressed and + * let go without touching anything) the button opens its pages as before. + * FX punch-in effects (punch.c) knobs: FILTER DUST DUCK + * EDIT erase that sound / note (seq.c) knobs: SHIFT LENGTH x2 / half TRANSPOSE OCT- undo OCT+ redo + * ARP note repeat (seq.c roll) knobs: RATE + * SEQ steps 1..16 of the page knobs: SOUND / NOTE DIV SWING LENGTH; a step key held: + * (black keys 1..4: pages) SOUND / NOTE LEVEL RATCHET + * SCL any key: the key of the song knobs: CHORD SCALE KEYS TRANSPOSE + * GLO keys 1..4 mute, 5..8 solo, knobs: the levels of tracks 1..4 + * the last white key: tap tempo + * The keys' part runs in the audio ISR (seq.c layer_now: no lag, no lost press); the SEQ, SCL and + * GLO keys come to the UI through seq.c lk_q. HOLD: REC held clears the track, SAVE held saves the + * project (a ring fills; let go before and nothing happens). */ +static const uint8_t LAYER_BTN[LY_COUNT] = {NB, B_FX, B_EDIT, B_ARP, B_SEQ, B_SCL, B_GLO}; +static const char *const LAYER_NAME[LY_COUNT] = {"", "punch", "erase", "roll", "steps", "key", "mix"}; +#define TAP_MS 450u /* a press shorter than this, untouched: a tap */ +#define SHOW_MS 140u /* the layer shows after this (a tap does not flash it) */ + +/* the ISR's view of the panel: the layers' buttons, OCT- / OCT+, REC / PLAY of a free take */ +static void layers_init(void) +{ + uint32_t l; + for (l = LY_FX; l < LY_COUNT; l++) + ly_bit[l] = 1u << panel.btn[LAYER_BTN[l]]; + dyn_bit[0] = 1u << panel.btn[B_OCTDN]; + dyn_bit[1] = 1u << panel.btn[B_OCTUP]; + ft_btn_mask = 1u << panel.btn[B_REC]; + ft_drop_mask = 1u << panel.btn[B_PLAY]; +} + +static uint32_t key_of_white(uint32_t w) { return key_of_lane(w & 15u); } /* white key w -> key index */ + +/* ------------------------------------------------------------ tools --- */ +/* EDIT layer knobs; each a step of one undo (the layer's hold) */ +static void layer_undo_mark(track_t *t) +{ + if (!ui.step_sess) + ui.step_sess = (undo_sess += 4u) | 3u; + undo_mark(t, ui.step_sess); +} +static void pattern_rotate(track_t *t, int32_t d) /* every step one later (d > 0) / earlier */ +{ + uint32_t len = trk_len(t), i; + step_t keep; + layer_undo_mark(t); + fm1_irq_off(); + if (d > 0) { + keep = t->step[len - 1u]; + for (i = len - 1u; i > 0; i--) + t->step[i] = t->step[i - 1u]; + t->step[0] = keep; + } else { + keep = t->step[0]; + for (i = 0; i + 1u < len; i++) + t->step[i] = t->step[i + 1u]; + t->step[len - 1u] = keep; + } + fm1_irq_on(); +} +static void pattern_length(track_t *t, int32_t d) /* x2 (the pattern again after itself), or half */ +{ + uint32_t len = trk_len(t), i; + layer_undo_mark(t); + fm1_irq_off(); + if (d > 0 && len * 2u <= NSTEP) { + for (i = 0; i < len; i++) + t->step[len + i] = t->step[i]; + t->p[P_SLEN] = (int16_t)(len * 2u); + } else if (d < 0 && len >= 2u) { + t->p[P_SLEN] = (int16_t)(len / 2u); + } + fm1_irq_on(); + { + char b[8]; + fmt_int(b, t->p[P_SLEN]); + ui_say("STEPS ", b); + } +} +static void pattern_transpose(track_t *t, int32_t d) /* every note a semitone up / down (synth parts) */ +{ + uint32_t i, j; + if (is_drum(t)) + return; + layer_undo_mark(t); + fm1_irq_off(); + for (i = 0; i < NSTEP; i++) + for (j = 0; j < t->step[i].n && j < 4u; j++) + t->step[i].note[j] = (uint8_t)clamp(t->step[i].note[j] + (d > 0 ? 1 : -1), 0, 127); + fm1_irq_on(); +} + +/* ------------------------------------------------------------- SEQ --- */ +/* a step key (white key w) of the SEQ layer, Elektron style: an empty step is set at once (drums: the + * sound's lane; synth: the pen, the chord / note played last); a set one goes when its key is let go, + * unless a knob changed it meanwhile (level, ratchet, note) */ +static uint16_t step_pend_off; /* the step keys that clear their step when let go */ +static int step_is_on(const track_t *t, uint32_t idx) +{ + return is_drum(t) ? dstep_has(&t->dstep[idx], pen_lane) : step_on(&t->step[idx]); +} +static void step_down(uint32_t w) +{ + track_t *t = TSEL; + uint32_t idx = ui.step_page * 16u + w; + if (idx >= trk_len(t)) + return; + if (song.playing && arrangement_enabled) { + ui_message("STOP THE SONG FIRST"); + return; + } + if (step_is_on(t, idx)) { + step_pend_off |= (uint16_t)(1u << w); + return; + } + layer_undo_mark(t); + fm1_irq_off(); + if (is_drum(t)) { + dstep_set(&t->dstep[idx], pen_lane, LV_NORM, 0); + } else { + step_t *s = &t->step[idx]; + uint32_t i, n = pen_n ? pen_n : 1u; + memset(s, 0, sizeof *s); + for (i = 0; i < n && i < 4u; i++) + s->note[i] = pen_n ? pen_note[i] : last_note; + s->n = (uint8_t)(t->p[P_VOICE] == V_POLY ? n : 1u); + s->time = ST_NOTE; + s->vel = 100; + } + t->seq_active = 1; + fm1_irq_on(); + sync_reload = 1; +} +static void step_up(uint32_t w) +{ + track_t *t = TSEL; + uint32_t idx = ui.step_page * 16u + w; + if (!((step_pend_off >> w) & 1u)) + return; + step_pend_off &= (uint16_t)~(1u << w); + if (idx >= trk_len(t) || !step_is_on(t, idx)) + return; + layer_undo_mark(t); + fm1_irq_off(); + if (is_drum(t)) + dstep_clr(&t->dstep[idx], pen_lane); + else + step_clear(&t->step[idx]); + fm1_irq_on(); + sync_reload = 1; +} +/* KNOB 2 / 3 with step keys held: their level / ratchet (drums: the sound's lane; synth: every note) */ +static void steps_held_edit(uint32_t knob, int32_t s) +{ + track_t *t = TSEL; + uint32_t w, i; + layer_undo_mark(t); + step_pend_off &= (uint16_t)~ui.step_held; /* (edited: kept when let go) */ + fm1_irq_off(); + for (w = 0; w < 16u; w++) { + uint32_t idx = ui.step_page * 16u + w; + if (!((ui.step_held >> w) & 1u) || idx >= trk_len(t)) + continue; + if (is_drum(t)) { + dstep_t *d = &t->dstep[idx]; + uint32_t lv = dstep_lvl(d, pen_lane), rt = dstep_rat(d, pen_lane); + if (!dstep_has(d, pen_lane)) + continue; + if (knob == 1u) + lv = LV_UP[clamp((int32_t)lvl_rank(lv) + s, 0, 3)]; + else + rt = (uint32_t)clamp((int32_t)rt + s, 0, 3); + dstep_set(d, pen_lane, lv, rt); + } else { + step_t *st = &t->step[idx]; + if (!step_on(st)) + continue; + for (i = 0; i < st->n; i++) { + uint32_t sh = 2u * i, lv = (st->lvl >> sh) & 3u, rt = (st->rat >> sh) & 3u; + if (knob == 0u) { + st->note[i] = (uint8_t)clamp(st->note[i] + s, 0, 127); + continue; + } + if (knob == 1u) + lv = LV_UP[clamp((int32_t)lvl_rank(lv) + s, 0, 3)]; + else + rt = (uint32_t)clamp((int32_t)rt + s, 0, 3); + st->lvl = (uint8_t)((st->lvl & ~(3u << sh)) | lv << sh); + st->rat = (uint8_t)((st->rat & ~(3u << sh)) | rt << sh); + } + } + } + fm1_irq_on(); + sync_reload = 1; +} + +/* ------------------------------------------------------------- GLO --- */ +static void tap_tempo(void) +{ + uint32_t now = fm1_ms, i, sum = 0; + if (ui.tap_n && now - ui.tap_ms[(ui.tap_n - 1u) & 3u] > 2000u) + ui.tap_n = 0; /* a pause: a new count */ + ui.tap_ms[ui.tap_n & 3u] = now; + ui.tap_n++; + if (ui.tap_n < 2u) + return; + { + uint32_t n = ui.tap_n - 1u > 3u ? 3u : ui.tap_n - 1u; + for (i = 0; i < n; i++) + sum += ui.tap_ms[(ui.tap_n - 1u - i) & 3u] - ui.tap_ms[(ui.tap_n - 2u - i) & 3u]; + if (sum) + song.g[G_BPM] = (int16_t)clamp((int32_t)((60000u * n + sum / 2u) / sum), 40, 240); + ui.bpm_t = 40; + } +} + +/* a key of the layers the UI runs (seq.c lk_q): SEQ steps, SCL key, GLO mix */ +static void layer_key(uint32_t layer, uint32_t k, uint32_t down) +{ + int32_t w = punch_key(k); + if (!down) { + if (w >= 0) { + ui.step_held &= (uint16_t)~(1u << w); + if (layer == LY_STEP) + step_up((uint32_t)w); + } + return; + } + switch (layer) { + case LY_STEP: + if (w < 0) { /* the first four black keys: pages 1..4 */ + static const int8_t PG[12] = {-1, 0, -1, 1, -1, 2, -1, -1, 3, -1, -1, -1}; + if (k < 12u && PG[k] >= 0 && (uint32_t)PG[k] * 16u < trk_len(TSEL)) + ui.step_page = (uint8_t)PG[k]; + return; + } + ui.step_held |= (uint16_t)(1u << w); + step_down((uint32_t)w); + return; + case LY_SCALE: { /* the key of the song: every synth part */ + uint32_t i, root = (53u + k) % 12u; + for (i = 0; i < NPART; i++) + trk[i].p[P_ROOT] = (int16_t)root; + ui_say("KEY ", N_NOTE[root]); + return; + } + case LY_MIX: + if (w >= 0 && w < 4) { + trk[w].p[P_MUTE] = (int16_t)!trk[w].p[P_MUTE]; + } else if (w >= 4 && w < 8) { + song.solo ^= (uint8_t)(1u << (w - 4)); + } else if (w == 15) { + tap_tempo(); + } + return; + default: + return; + } +} + +/* KNOB 1..4 while a layer is held: what the layer gives them (the page does not see them) */ +static void layer_knobs(uint32_t layer) +{ + uint32_t k; + int32_t s; + track_t *t = TSEL; + for (k = 0; k < 4u; k++) { + if ((s = panel_enc(EN_K1 + k)) == 0) + continue; + ui.layer_used = 1; + ui.hot_col = (uint8_t)k; + ui.hot_t = 40; + switch (layer) { + case LY_FX: + if (k == 0u) + song.g[G_FILT] = (int16_t)clamp(song.g[G_FILT] + accel(EN_K1, s, 127), -64, 63); + else if (k == 1u) + song.g[G_DUST] = (int16_t)clamp(song.g[G_DUST] + accel(EN_K2, s, 127), 0, 127); + else if (k == 2u) + song.g[G_DUCK] = (int16_t)clamp(song.g[G_DUCK] + accel(EN_K3, s, 127), 0, 127); + break; + case LY_ERASE: + if (k == 0u) + pattern_rotate(t, s); + else if (k == 1u) + pattern_length(t, s); + else if (k == 2u) + pattern_transpose(t, s); + break; + case LY_ROLL: + if (k == 0u) + song.g[G_ROLL] = (int16_t)clamp(song.g[G_ROLL] + s, 0, 4); + break; + case LY_STEP: + if (ui.step_held && k < 3u) { + if (k == 0u && is_drum(t)) + pen_lane = (uint8_t)clamp(pen_lane + s, 0, DRUM_LANES - 1); + else + steps_held_edit(k, s); + } else if (k == 0u) { + if (is_drum(t)) { + pen_lane = (uint8_t)clamp(pen_lane + s, 0, DRUM_LANES - 1); + } else { + pen_note[0] = (uint8_t)clamp(pen_note[0] + s, 0, 127); + pen_n = 1; + } + } else if (k == 1u) { + t->p[P_SDIV] = (int16_t)clamp(t->p[P_SDIV] + s, 0, 5); + } else if (k == 2u) { + t->p[P_SSWING] = (int16_t)clamp(t->p[P_SSWING] + accel(EN_K3, s, 100), 0, 100); + } else { + t->p[P_SLEN] = (int16_t)clamp(t->p[P_SLEN] + accel(EN_K4, s, 63), 1, NSTEP); + if ((uint32_t)ui.step_page * 16u >= trk_len(t)) + ui.step_page = (uint8_t)((trk_len(t) - 1u) / 16u); + } + break; + case LY_SCALE: + if (k == 0u) { + if (!is_drum(t)) + t->p[P_CHORD] = (int16_t)clamp(t->p[P_CHORD] + s, 0, 5); + } else if (k == 1u) { + uint32_t i; + int16_t v = (int16_t)clamp(trk[0].p[P_SCALE] + s, 0, NSCALES - 1); + for (i = 0; i < NPART; i++) + trk[i].p[P_SCALE] = v; + } else if (k == 2u) { + if (!is_drum(t)) + t->p[P_QUANT] = (int16_t)clamp(t->p[P_QUANT] + s, 0, 2); + } else if (!is_drum(t)) { + t->p[P_TRANS] = (int16_t)clamp(t->p[P_TRANS] + s, -24, 24); + } + break; + case LY_MIX: { + int16_t *lv = k == TRK_DRUM ? &song.g[G_DRLVL] : &trk[k].p[P_LEVEL]; + *lv = (int16_t)clamp(*lv + accel(EN_K1 + k, s, 127), 0, 127); + break; + } + default: + break; + } + } +} + +/* --------------------------------------------------------- drawing --- */ +/* 16 tiles (the white keys, 4 x 4) under a title band, the knobs' dials at the bottom */ +typedef struct { + char lab[8]; + uint16_t bg, fg, top; /* fill, text, the 3-pixel top band (0 = none) */ + uint8_t marks; /* small marks under the label (a ratchet), 0 = none */ +} tile_t; + +static void tiles_draw(const tile_t *tl, uint32_t *cache) +{ + uint32_t r, c, sig = 7u; + for (r = 0; r < 16u; r++) + sig = studio_hash(sig * 31u + tl[r].bg * 3u + tl[r].fg * 5u + tl[r].top * 7u + tl[r].marks, tl[r].lab); + if (!ui.force && sig == *cache) + return; + *cache = sig; + for (r = 0; r < 4u; r++) { + cv_begin(240, 36, C_BLACK); + for (c = 0; c < 4u; c++) { + const tile_t *t = &tl[r * 4u + c]; + int32_t x = 2 + (int32_t)c * 60; + uint32_t m; + cv_rect(x, 2, 56, 32, t->bg); + if (t->top) + cv_rect(x, 2, 56, 3, t->top); + te_text_c(x + 28, 9, t->lab, t->fg); + for (m = 0; m < t->marks; m++) + cv_rect(x + 22 + (int32_t)m * 5, 27, 3, 3, t->fg); + } + cv_blit(0, 40 + r * 36); + } +} + +static void layer_title(const char *name, const char *sub, uint16_t col, uint32_t *cache) +{ + uint32_t sig = studio_hash(studio_hash(col, name), sub) + (ui.msg_t ? studio_hash(3u, ui.msg) : 0u); + if (!ui.force && sig == *cache) + return; + *cache = sig; + cv_begin(240, 40, C_BLACK); + cv_text(4, 2, &FONT_L, name, col); + cv_text(4 + text_w(&FONT_L, name) + 10, 18, &FONT_S, ui.msg_t ? ui.msg : sub, ui.msg_t ? C_WHITE : TE_G3); + cv_rect(0, 38, 240, 1, TE_G1); + cv_blit(0, 0); +} + +static uint8_t layer_shown; /* the screen holds a layer (or a hold) */ +static void layer_screen_draw(void) +{ + static uint32_t head, tiles, foot; + static tile_t tl[16]; + static char v[4][10], sub[24]; + const char *lab[4] = {"", "", "", ""}, *val[4] = {v[0], v[1], v[2], v[3]}; + int32_t ratio[4] = {-1, -1, -1, -1}; + uint32_t i, layer = ui.layer, sel = song.sel; + track_t *t = TSEL; + uint16_t col = TE_COL[sel & 3u]; + if (!layer_shown) { + lcd_fill(0, 0, 240, 240, C_BLACK); + ui.force = 1; + layer_shown = 1; + } + for (i = 0; i < 4u; i++) + v[i][0] = 0; + memset(tl, 0, sizeof tl); + for (i = 0; i < 16u; i++) { + tl[i].bg = TE_G1; + tl[i].fg = TE_G3; + } + str_cpy(sub, "track ", sizeof sub); + sub[6] = (char)('1' + sel); + sub[7] = 0; + switch (layer) { + case LY_FX: /* the 16 punch-in effects */ + col = TE_DRUM; + str_cpy(sub, "hold + key", sizeof sub); + for (i = 0; i < 16u; i++) { + static const char *const PSHORT[16] = {"loop 4", "loop 8", "loop16", "loop32", "stutt", "rev", "stop", "half", + "low", "high", "phone", "crush", "alias", "gate", "echo", "wobble"}; + int on = punch.req == (int8_t)i; + str_cpy(tl[i].lab, PSHORT[i], 8); + tl[i].bg = on ? C_WHITE : TE_G1; + tl[i].fg = on ? C_BLACK : TE_G4; + tl[i].top = on ? 0 : TE_DIM[i / 4u]; + } + lab[0] = "filter", lab[1] = "dust", lab[2] = "duck"; + { + const char *u; + param_format(&GP[G_FILT], song.g[G_FILT], v[0], &u); + te_lower(v[0], v[0], 8); + fmt_int(v[1], song.g[G_DUST] * 100 / 127); + fmt_int(v[2], song.g[G_DUCK] * 100 / 127); + } + ratio[0] = (song.g[G_FILT] + 64) * 1000 / 127; + ratio[1] = song.g[G_DUST] * 1000 / 127; + ratio[2] = song.g[G_DUCK] * 1000 / 127; + break; + case LY_ERASE: + case LY_ROLL: { /* the keys' sounds: lit = held */ + uint32_t held = fm1_in.notes; + col = layer == LY_ERASE ? TE_RED : col; + str_cpy(sub, layer == LY_ERASE ? (song.playing ? "as it plays" : "every step") : "hold + key", sizeof sub); + for (i = 0; i < 16u; i++) { + uint32_t k = key_of_white(i), down = (held >> k) & 1u, present = 0, j; + if (is_drum(t)) { + str_cpy(tl[i].lab, LANE_SHORT[i], 8); + for (j = 0; j < trk_len(t); j++) + present |= dstep_has(&t->dstep[j], i); + } else { + uint32_t n = kb_map(t, k); + if (n == KB_SILENT) { + str_cpy(tl[i].lab, "-", 8); + } else { + note_name(tl[i].lab, n); + for (j = 0; j < trk_len(t); j++) + if (t->step[j].time == ST_NOTE) { + uint32_t q; + for (q = 0; q < t->step[j].n; q++) + present |= t->step[j].note[q] == n; + } + } + } + tl[i].bg = down ? (layer == LY_ERASE ? TE_RED : C_WHITE) : TE_G1; + tl[i].fg = down ? C_BLACK : present ? C_WHITE : TE_G3; + tl[i].top = present && !down ? (layer == LY_ERASE ? TE_RED : col) : 0; + } + if (layer == LY_ERASE) { + lab[0] = "shift", lab[1] = "length", lab[2] = is_drum(t) ? "" : "transp"; + str_cpy(v[0], "< >", 8); + fmt_int(v[1], t->p[P_SLEN]); + str_cpy(v[2], is_drum(t) ? "" : "- +", 8); + str_cpy(sub, undo.valid ? (undo.undone ? "oct+ redo" : "oct- undo") : sub, sizeof sub); + } else { + lab[0] = "rate"; + str_cpy(v[0], N_ROLL[clamp(song.g[G_ROLL], 0, 4)], 8); + ratio[0] = song.g[G_ROLL] * 250; + } + break; + } + case LY_STEP: { /* the 16 steps of the page */ + uint32_t len = trk_len(t), page = ui.step_page; + for (i = 0; i < 16u; i++) { + uint32_t idx = page * 16u + i, on, lv = LV_NORM, rt = 0; + if (idx >= len) { + tl[i].bg = C_BLACK; + continue; + } + if (is_drum(t)) { + const dstep_t *d = &t->dstep[idx]; + on = dstep_has(d, pen_lane); + if (on) { + lv = dstep_lvl(d, pen_lane); + rt = dstep_rat(d, pen_lane); + } + } else { + const step_t *st = &t->step[idx]; + on = step_on(st); + if (on) { + lv = st->lvl & 3u; + rt = st->rat & 3u; + note_name(tl[i].lab, st->note[0]); + } else if (st->time == ST_TIE) { + str_cpy(tl[i].lab, "--", 8); + } + } + if (!tl[i].lab[0]) + fmt_int(tl[i].lab, (int32_t)idx + 1); + tl[i].bg = on ? (lv == LV_GHOST ? TE_DIM[sel & 3u] : lv == LV_SOFT ? TE_MID[sel & 3u] : lv == LV_HARD ? C_WHITE : col) + : TE_G1; + tl[i].fg = on ? C_BLACK : TE_G3; + tl[i].marks = (uint8_t)(on ? rt : 0u); + if (song.playing && idx == t->seq_idx) + tl[i].top = C_WHITE; + if ((ui.step_held >> i) & 1u) + tl[i].top = TE_RED; + } + if (len > 16u) { + char p[4] = {'1', '/', '1', 0}; + p[0] = (char)('1' + page); + p[2] = (char)('0' + (len + 15u) / 16u); + str_cpy(sub, "page ", sizeof sub); + str_cpy(sub + 5, p, 4); + } + lab[0] = is_drum(t) ? "sound" : "note"; + if (is_drum(t)) + str_cpy(v[0], LANE_SHORT[pen_lane], 8); + else + note_name(v[0], pen_note[0]); + ratio[0] = is_drum(t) ? pen_lane * 1000 / 15 : pen_note[0] * 1000 / 127; + if (ui.step_held) { + lab[1] = "level", lab[2] = "ratchet"; + str_cpy(v[1], "- +", 8); + str_cpy(v[2], "x1 x4", 8); + } else { + lab[1] = "div", lab[2] = "swing", lab[3] = "steps"; + str_cpy(v[1], N_DIV[t->p[P_SDIV] % 6], 8); + swing_str(v[2], t->p[P_SSWING]); + fmt_int(v[3], t->p[P_SLEN]); + ratio[1] = t->p[P_SDIV] * 200; + ratio[2] = t->p[P_SSWING] * 10; + ratio[3] = (t->p[P_SLEN] - 1) * 1000 / 63; + } + break; + } + case LY_SCALE: { /* the white keys' notes / chords; the root lit */ + uint32_t root = (uint32_t)trk[0].p[P_ROOT] % 12u, mask = SCALE_MASK[clamp(trk[0].p[P_SCALE], 0, NSCALES - 1)]; + col = TE_COL[1]; + str_cpy(sub, "key: ", sizeof sub); + str_cpy(sub + 5, N_NOTE[root], 4); + str_cpy(sub + str_len(sub), " ", 2); + te_lower(sub + str_len(sub), N_SCALE[clamp(trk[0].p[P_SCALE], 0, NSCALES - 1)], 8); + for (i = 0; i < 16u; i++) { + uint32_t k = key_of_white(i), pc = (53u + k) % 12u, in = (mask >> ((pc + 12u - root) % 12u)) & 1u; + if (!is_drum(t) && t->p[P_CHORD]) { /* chord mode: the chord this key plays (the i chord lit) */ + uint8_t c[4]; + uint32_t n = kb_map(t, k), m; + if (n != KB_SILENT && (m = chord_notes(t, n, c)) != 0u) { + uint32_t third = m > 1u ? (uint32_t)(c[1] - c[0]) : 4u; + str_cpy(tl[i].lab, N_NOTE[c[0] % 12u], 8); + if (t->p[P_CHORD] == 5) + str_cpy(tl[i].lab + str_len(tl[i].lab), "5", 2); + else if (third == 3u) + str_cpy(tl[i].lab + str_len(tl[i].lab), "m", 2); + pc = c[0] % 12u; + in = 1; + } + } else { + str_cpy(tl[i].lab, N_NOTE[pc], 8); + } + tl[i].bg = pc == root ? col : TE_G1; + tl[i].fg = pc == root ? C_BLACK : in ? C_WHITE : TE_G2; + } + lab[0] = "chord", lab[1] = "scale", lab[2] = "keys", lab[3] = "transp"; + te_lower(v[0], N_CHORD[clamp(t->p[P_CHORD], 0, 5)], 8); + te_lower(v[1], N_SCALE[clamp(trk[0].p[P_SCALE], 0, NSCALES - 1)], 8); + te_lower(v[2], N_QUANT[clamp(t->p[P_QUANT], 0, 2)], 8); + fmt_int(v[3], t->p[P_TRANS]); + if (is_drum(t)) + v[0][0] = v[2][0] = v[3][0] = 0; + ratio[0] = t->p[P_CHORD] * 200; + ratio[1] = trk[0].p[P_SCALE] * 1000 / (NSCALES - 1); + ratio[2] = t->p[P_QUANT] * 500; + ratio[3] = (t->p[P_TRANS] + 24) * 1000 / 48; + break; + } + case LY_MIX: { /* mute 1..4, solo 1..4, tap */ + col = C_WHITE; + str_cpy(sub, "mute solo tap", sizeof sub); + for (i = 0; i < 4u; i++) { + int m = trk[i].p[P_MUTE] != 0, so = (song.solo >> i) & 1u; + str_cpy(tl[i].lab, "mute 1", 8); + tl[i].lab[5] = (char)('1' + i); + tl[i].bg = m ? TE_G2 : TE_COL[i]; + tl[i].fg = m ? TE_G3 : C_BLACK; + str_cpy(tl[4 + i].lab, "solo 1", 8); + tl[4 + i].lab[5] = (char)('1' + i); + tl[4 + i].bg = so ? C_WHITE : TE_G1; + tl[4 + i].fg = so ? C_BLACK : TE_G3; + tl[4 + i].top = TE_DIM[i]; + } + fmt_int(tl[15].lab, song.g[G_BPM]); + tl[15].bg = song.playing && clk_pos < BEAT_U / 4u ? C_WHITE : TE_G2; + tl[15].fg = tl[15].bg == C_WHITE ? C_BLACK : C_WHITE; + str_cpy(tl[14].lab, "tap>", 8); + tl[14].bg = C_BLACK; + for (i = 0; i < 4u; i++) { + uint32_t lv = trk_level(i); + static const char *const L[4] = {"1", "2", "3", "4"}; + lab[i] = L[i]; + fmt_int(v[i], (int32_t)lv * 100 / 127); + ratio[i] = (int32_t)lv * 1000 / 127; + } + break; + } + default: + break; + } + layer_title(LAYER_NAME[layer % LY_COUNT], sub, col, &head); + tiles_draw(tl, &tiles); + { /* (a message shows in the title: the dials stay) */ + uint8_t m = ui.msg_t; + ui.msg_t = 0; + te_dials(184, lab, val, ratio, layer * 7919u, &foot); + ui.msg_t = m; + } +} + +/* HOLD to confirm: a ring fills while REC (clear the track) or SAVE (save the project) is held */ +#define HOLD_CLEAR_MS 1300u /* after the 0.7 s that make REC a hold */ +#define HOLD_SAVE_MS 1000u +static void hold_screen_draw(void) +{ + static uint32_t cache; + uint32_t span = ui.hold_kind == 1u ? HOLD_CLEAR_MS : HOLD_SAVE_MS, el = fm1_ms - ui.hold_t0; + int32_t ratio = el >= span ? 1000 : (int32_t)(el * 1000u / span); + uint32_t sig = ui.hold_kind * 7u + (uint32_t)ratio / 20u + ui.hold_trk * 131u; + char b[24]; + if (!layer_shown) { + lcd_fill(0, 0, 240, 240, C_BLACK); + layer_shown = 1; + cache = ~sig; + } + if (sig == cache && !ui.force) + return; + cache = sig; + cv_begin(240, 124, C_BLACK); + cv_text(120 - text_w(&FONT_L, ui.hold_kind == 1u ? "clear" : "save") / 2, 4, &FONT_L, + ui.hold_kind == 1u ? "clear" : "save", ui.hold_kind == 1u ? TE_RED : C_WHITE); + { /* the ring: 36 px, 7 thick, filling clockwise from the top */ + int32_t a, rr, end = ratio * 1024 / 1000; + for (a = 0; a < 1024; a += 2) { + int32_t co = SINE[((uint32_t)a + 768u) & 1023u], si = SINE[(uint32_t)a & 1023u]; /* from 12 o'clock */ + uint16_t c = a <= end ? (ui.hold_kind == 1u ? TE_RED : C_WHITE) : TE_G2; + for (rr = 30; rr <= 36; rr++) + cv_pset(120 + ((si * rr) >> 15), 80 + ((co * rr) >> 15), c); + } + } + cv_blit(0, 20); + cv_begin(240, 60, C_BLACK); + if (ui.hold_kind == 1u) { + str_cpy(b, "track 1", sizeof b); + b[6] = (char)('1' + ui.hold_trk); + } else { + str_cpy(b, "project in slot 1", sizeof b); + b[16] = (char)('0' + clamp(song.g[G_SLOT], 1, 4)); + } + te_text_c(120, 4, b, TE_G4); + te_text_c(120, 30, "keep holding", TE_G3); + cv_blit(0, 160); +} diff --git a/firmware/src/ui_menu.c b/firmware/src/ui_menu.c new file mode 100644 index 0000000..5ff7f4f --- /dev/null +++ b/firmware/src/ui_menu.c @@ -0,0 +1,127 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* SLOOP menu (HOME held): COLOR, LOWCUT, ZOOM, HARDWARE CALIBRATION, ABOUT. */ +/* ------------------------------------------------------------ menu --- */ +enum { MI_COLOR, MI_LOWCUT, MI_ZOOM, MI_PANEL, MI_ABOUT, MI_BACK, MI_COUNT }; +static const char *const MI_NAME[MI_COUNT] = {"COLOR", "LOWCUT", "ZOOM", "HARDWARE CALIBRATION", "ABOUT", "BACK"}; + +static void draw_menu(void) +{ + uint32_t i, pass, sig = ui.menu * 7u + ui.menu_sel * 131u + settings.palette * 1009u + settings.lowcut * 7919u + + settings.zoom * 104729u; + if (!ui.force && sig == ui.menu_sig) + return; + ui.menu_sig = sig; + if (ui.force) /* head + rule + two bands cover rows 0..229 */ + lcd_fill(0, H_HEAD + 1 + 124 + 95, 240, 240 - (H_HEAD + 1 + 124 + 95), C_BLACK); + cv_begin(240, H_HEAD, C_BLACK); + cv_text(4, 1, &FONT_S, ui.menu == 2 ? "ABOUT" : "MENU", C_HI); + cv_blit(0, Y_HEAD); + lcd_fill(0, H_HEAD, 240, 1, C_LINE); + for (pass = 0; pass < 2u; pass++) { /* the canvas holds 124 rows: draw in two bands */ + cv_begin(240, pass ? 95u : 124u, C_BLACK); + cv_oy = pass ? -124 : 0; + if (ui.menu == 2) { + cv_text(4, 4, &FONT_L, "SLOOP", C_WHITE); + cv_rect(96, 10, 8, 4, TE_COL[0]), cv_rect(96, 16, 12, 4, TE_COL[1]); /* the sail */ + cv_rect(96, 22, 16, 4, TE_COL[2]), cv_rect(96, 28, 20, 4, TE_COL[3]); + cv_text(4, 36, &FONT_S, "BASED ON FELUCCA", C_AMB); + cv_text(4, 54, &FONT_S, FELUCCA_VERSION, C_HI); + cv_text(236 - text_w(&FONT_S, __DATE__), 54, &FONT_S, __DATE__, C_GRAY); /* build date */ + cv_text(cv_text(4, 72, &FONT_S, "LEO KUROSHITA", C_HI) + 8, 72, &FONT_S, "@KUROGEDELIC", C_AMB); + cv_text(4, 88, &FONT_S, "H\xDCGELTON INSTRUMENTS", C_HI); /* Latin-1 U-umlaut */ + cv_text(4, 104, &FONT_S, "HUGELTON.COM", C_AMB); + cv_text(4, 119, &FONT_S, "GPL-3.0, NO WARRANTY", C_HI); + cv_text(4, 132, &FONT_S, "GITHUB.COM/HUGELTON/FELUCCA", C_AMB); + cv_text(4, 146, &FONT_S, "FONT: TERMINUS (OFL)", C_DIM); + cv_text(4, 159, &FONT_S, "SAMPLES: VERSILIAN (CC0)", C_DIM); + cv_text(4, 172, &FONT_S, "+ H\xDCGELTON SAMPLE PACK", C_DIM); + cv_text(4, 185, &FONT_S, "PHASE: CRISPYZEBRA (GPL)", C_DIM); + cv_text(4, 198, &FONT_S, "VOICE: REF. KLATTSCH (MIT)", C_DIM); + } else { + for (i = 0; i < MI_COUNT; i++) { + int32_t y = 4 + (int32_t)i * 24; + int sel = i == ui.menu_sel; + if (sel) + cv_rect(4, y + 6, 3, 3, C_WHITE); + cv_text(14, y, &FONT_S, MI_NAME[i], sel ? C_WHITE : C_GRAY); + if (i == MI_LOWCUT || i == MI_ZOOM) + cv_text(90, y, &FONT_S, (i == MI_LOWCUT ? settings.lowcut : settings.zoom) ? "ON" : "OFF", C_HI); + if (i == MI_COLOR) { + uint32_t k; + cv_text(90, y, &FONT_S, PALETTES[settings.palette].name, C_HI); + for (k = 0; k < 5u; k++) + cv_rect(160 + (int32_t)k * 14, y + 3, 10, 10, pal[k]); + } + } + cv_text(4, 170, &FONT_S, "PRESETS MOVE", C_DIM); + cv_text(4, 188, &FONT_S, "OCT+ OK OCT- BACK", C_DIM); + } + cv_oy = 0; + cv_blit(0, H_HEAD + 1 + pass * 124u); + } +} + +static void enc_drop(void) /* knob turns nobody takes */ +{ + uint32_t k; + for (k = 0; k < NE; k++) + panel_enc(k); +} + +static void menu_close(void) +{ + settings_save(); /* palette / panel table, if changed */ + ui.menu = 0; + ui.force = 1; + go_home(); +} + +/* menu: PRESETS moves, OCT+ confirms, OCT- cancels (ABOUT -> list -> close) */ +static void menu_input(uint32_t pressed) +{ + int32_t s; + uint32_t ok = (pressed >> panel.btn[B_OCTUP]) & 1u, back = (pressed >> panel.btn[B_OCTDN]) & 1u; + if (back) { + if (ui.menu == 2) + ui.menu = 1, ui.force = 1; + else + menu_close(); + return; + } + if ((s = panel_enc(EN_PRESET)) != 0 && ui.menu == 1) + ui.menu_sel = (uint8_t)((ui.menu_sel + (s > 0 ? 1u : MI_COUNT - 1u)) % MI_COUNT); + s = panel_enc(EN_K1); + if (s != 0 && ui.menu == 1 && ui.menu_sel == MI_COLOR) { + settings.palette = (settings.palette + (s > 0 ? 1u : NPALETTES - 1u)) % NPALETTES; + palette_set(settings.palette); /* (the menu signature redraws) */ + } + if ((s != 0 || ok) && ui.menu == 1 && (ui.menu_sel == MI_LOWCUT || ui.menu_sel == MI_ZOOM)) { + /* KNOB 1: right = ON, left = OFF; OCT+ toggles */ + uint32_t *v = ui.menu_sel == MI_LOWCUT ? &settings.lowcut : &settings.zoom; + *v = s > 0 ? 1u : s < 0 ? 0u : !*v; + fx_lowcut = (uint8_t)(settings.lowcut != 0); + ok = 0; + } + if (ok && ui.menu == 1) { + switch (ui.menu_sel) { + case MI_COLOR: /* OCT+ steps through the palettes too */ + settings.palette = (settings.palette + 1u) % NPALETTES; + palette_set(settings.palette); + break; + case MI_PANEL: + panel_setup(); + ui.force = 1; + break; + case MI_ABOUT: + ui.menu = 2; + ui.force = 1; + break; + default: + menu_close(); + break; + } + } + enc_drop(); /* swallow the rest while the menu is up */ +} + diff --git a/firmware/src/ui_song.c b/firmware/src/ui_song.c new file mode 100644 index 0000000..eda0d0c --- /dev/null +++ b/firmware/src/ui_song.c @@ -0,0 +1,154 @@ +/* SPDX-License-Identifier: GPL-3.0-only */ +/* 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 int on_song_page(void) { return !ui.home && cur_page()->scope == SC_SONG; } +static void song_sane(void) /* a bad chain (blank / damaged settings): defaults */ +{ + uint32_t i, ok = arrangement.count >= 1u && arrangement.count <= ARR_STEPS; + for (i = 0; ok && i < arrangement.count; i++) + ok = arrangement.entry[i].scene < ARR_SCENES && arrangement.entry[i].bars >= 1u && arrangement.entry[i].bars <= 64u; + if (!ok) + arr_defaults(&arrangement); + if (song_cursor >= arrangement.count) + song_cursor = (uint8_t)(arrangement.count - 1u); +} + +/* SONG: the chain of sections (A..D in the track colours), bars of each, where the song is */ +static void song_screen_draw(void) +{ + song_sane(); + uint32_t i, start = song_cursor > 3u ? song_cursor - 3u : 0u; + static uint32_t previous; + static const uint16_t SC[4] = {RGB(40, 124, 255), RGB(30, 204, 112), RGB(255, 198, 24), RGB(255, 98, 26)}; + uint32_t sig = song_cursor + 17u * arrangement_enabled + 37u * song.playing + + 71u * arrangement_clock.index + 127u * arrangement_clock.bar + + 257u * arrangement.count + 509u * song.g[G_BPM]; + char b[30]; + for (i = 0; i < arrangement.count; i++) + sig = sig * 31u + arrangement.entry[i].scene + 7u * arrangement.entry[i].bars; + for (i = 0; i < ARR_SCENES; i++) sig = sig * 3u + (uint32_t)project_used(i); + if (!ui.force && !ui.msg_t && sig == previous) return; + previous = ui.msg_t ? ~sig : sig; /* redraw after a message expires */ + /* Draw one small band at a time: never exceed the 124-row canvas. */ + cv_begin(240, 40, C_BLACK); + cv_text(4, 4, &FONT_L, "SONG", C_WHITE); + cv_text(76, 20, &FONT_S, arrangement_enabled ? "song mode" : "loop mode", arrangement_enabled ? SC[3] : RGB(118, 118, 126)); + fmt_int(b, song.g[G_BPM]); + cv_text(236 - text_w(&FONT_S, b) - 28, 4, &FONT_S, b, C_WHITE); + cv_text(236 - 24, 4, &FONT_S, "bpm", RGB(118, 118, 126)); + cv_text(236 - text_w(&FONT_S, song.playing ? "playing" : "stopped"), 20, &FONT_S, + song.playing ? "playing" : "stopped", song.playing ? SC[1] : RGB(118, 118, 126)); + cv_rect(0, 39, 240, 1, RGB(26, 26, 30)); + cv_blit(0, 0); + for (i = 0; i < 5u; i++) { + uint32_t pos = start + i; + cv_begin(240, 26, C_BLACK); + if (pos < arrangement.count) { + const arr_entry_t *e = &arrangement.entry[pos]; + int selected = pos == song_cursor, used = project_used(e->scene); + uint16_t sc = SC[e->scene & 3u]; + int32_t w; + fmt_int(b, (int32_t)pos + 1); + cv_text(4, 5, &FONT_S, b, selected ? C_WHITE : RGB(118, 118, 126)); + cv_rect(30, 3, 22, 20, used ? sc : RGB(26, 26, 30)); /* the section tile */ + b[0] = (char)('A' + e->scene); b[1] = 0; + cv_text(37, 5, &FONT_S, b, used ? C_BLACK : sc); + w = e->bars * 120 / 64 + 4; /* its length as a bar */ + cv_rect(60, 9, w, 8, used ? (selected ? sc : RGB(54, 54, 60)) : RGB(26, 26, 30)); + fmt_int(b, e->bars); + str_cpy(b + str_len(b), e->bars == 1 ? " bar" : " bars", 8); + cv_text(60 + w + 6, 5, &FONT_S, used ? b : "empty", selected ? C_WHITE : RGB(118, 118, 126)); + if (arrangement_clock.running && arrangement_clock.index == pos) { + cv_rect(60, 19, (int32_t)(arrangement_clock.bar + 1u) * w / (e->bars ? e->bars : 1), 2, C_WHITE); + cv_rect(226, 9, 9, 9, SC[1]); + } + if (selected) cv_rect(0, 1, 240, 1, RGB(54, 54, 60)), cv_rect(0, 24, 240, 1, RGB(54, 54, 60)); + } + cv_blit(0, 42 + 26u * i); + } + cv_begin(240, 68, C_BLACK); + if (ui.msg_t) { + cv_rect(0, 4, 240, 30, C_WHITE); + cv_text((240 - text_w(&FONT_S, ui.msg)) / 2, 11, &FONT_S, ui.msg, C_BLACK); + } else { + static const char *const L[4] = {"entry", "section", "bars", "length"}; + for (i = 0; i < 4u; i++) { + cv_rect((int32_t)i * 60 + 4, 6, 52, 3, SC[i]); + cv_text((int32_t)i * 60 + 30 - text_w(&FONT_S, L[i]) / 2, 12, &FONT_S, L[i], RGB(118, 118, 126)); + } + } + cv_text(4, 34, &FONT_S, "rec: store save: chain", RGB(196, 196, 204)); + cv_text(4, 50, &FONT_S, "oct-: loop/song oct+ x2: load", RGB(118, 118, 126)); + cv_blit(0, 172); +} + +static void song_screen_input(uint32_t pressed, uint32_t home) +{ + uint32_t k, b; + int32_t steps; + song_sane(); + if (home == 1u) { go_home(); return; } /* BT_TAP */ + for (k = 0; k < NB; k++) { + if (!((pressed >> panel.btn[k]) & 1u)) continue; + b = k; + if ((b == B_PLAY || b == B_REC) && ft_owns_press()) + continue; /* (they close a free take: seq.c) */ + if (b == B_PLAY) { + if (!song.playing && arrangement_enabled && !arr_valid(&arrangement, arrangement_ready())) { + ui_message("EMPTY SECTION: REC"); + } else transport_req = song.playing ? 2 : 1; + } else if (b == B_SEQ) { + open_family(FAM_SEQ); + } else if (b == B_SAVE || b == B_REC || b == B_OCTDN || b == B_OCTUP) { + uint32_t scene = arrangement.entry[song_cursor].scene; + if (song.playing || transport_req) { ui_message("STOP FIRST"); continue; } + if (b == B_SAVE) { + arrangement_save(); + song_store_armed = 0; + } else if (b == B_OCTDN) { + 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) { + song_load_armed = 0; + project_load(scene); + } else { + song_load_armed = 1; + song_store_armed = 0; + song_store_deadline = fm1_ms + 3000u; + ui_message("OCT+ AGAIN: LOAD"); + } + } else if (project_used(scene) && + (!song_store_armed || (int32_t)(fm1_ms - song_store_deadline) > 0)) { + song_store_armed = 1; + song_store_deadline = fm1_ms + 3000u; + ui_message("REC AGAIN: REPLACE"); + } else { + project_save(scene); + settings_save(); + song_store_armed = 0; + } + } + } + for (k = 0; k < 4u; k++) { + steps = panel_enc(EN_K1 + k); + if (!steps) continue; + song_store_armed = 0; + song_load_armed = 0; + if (k == 0) { + song_cursor = (uint8_t)clamp(song_cursor + steps, 0, arrangement.count - 1); + continue; + } + if (song.playing || transport_req) { ui_message("STOP FIRST"); continue; } + if (k == 1) arrangement.entry[song_cursor].scene = (uint8_t)clamp(arrangement.entry[song_cursor].scene + steps, 0, 3); + if (k == 2) arrangement.entry[song_cursor].bars = (uint8_t)clamp(arrangement.entry[song_cursor].bars + steps, 1, 64); + if (k == 3) { + arrangement.count = (uint8_t)clamp(arrangement.count + steps, 1, ARR_STEPS); + if (song_cursor >= arrangement.count) song_cursor = arrangement.count - 1; + } + } + /* Unused encoders have no hidden action on this screen. */ + panel_enc(EN_SELECT); panel_enc(EN_ALGO); panel_enc(EN_PRESET); +} diff --git a/firmware/src/ui_studio.c b/firmware/src/ui_studio.c new file mode 100644 index 0000000..fe67b6f --- /dev/null +++ b/firmware/src/ui_studio.c @@ -0,0 +1,582 @@ +/* SPDX-License-Identifier: GPL-3.0-only */ +/* LIVE screens, 240 x 240, in a teenage-engineering-like style: black, four colours (one per + * track and per knob: blue, green, yellow, orange), white for what you touch, red for recording, + * big numbers, lowercase labels, four dials at the bottom that show what KNOB 1..4 do. + * Screens: TRACKS (the performance view), DRUMS (GRID / KIT, pads that flash on each hit), the + * LAYERS (a function button held: what the 16 white keys and the knobs do now), HOLD (a hold to + * confirm: clear, save), REC (armed / free take). Every band is drawn into the canvas only when its + * signature changed. */ +static uint8_t drum_page, drum_lane, drum_cursor; /* drum_page: 0 GRID, 1 KIT */ +static void trk_short_name(uint32_t c, char *b); +static int on_drum_page(void) { return !ui.home && cur_page()->scope == SC_DRUM; } + +/* ---------------------------------------------------------------- style --- */ +#define TE_G1 RGB(26, 26, 30) /* tiles */ +#define TE_G2 RGB(54, 54, 60) /* empty steps, dial tracks */ +#define TE_G3 RGB(118, 118, 126) /* labels */ +#define TE_G4 RGB(196, 196, 204) /* secondary text */ +#define TE_RED RGB(255, 44, 52) /* recording, erasing */ +static const uint16_t TE_COL[4] = {RGB(40, 124, 255), RGB(30, 204, 112), RGB(255, 198, 24), RGB(255, 98, 26)}; +static const uint16_t TE_MID[4] = {RGB(26, 82, 170), RGB(20, 136, 76), RGB(170, 132, 16), RGB(170, 66, 18)}; +static const uint16_t TE_DIM[4] = {RGB(14, 40, 86), RGB(10, 66, 38), RGB(86, 66, 8), RGB(86, 32, 8)}; +#define TE_DRUM TE_COL[3] + +static void te_disc(int32_t cx, int32_t cy, int32_t r, uint16_t c) /* filled circle */ +{ + int32_t y, x; + for (y = -r; y <= r; y++) + for (x = -r; x <= r; x++) + if (x * x + y * y <= r * r + r) + cv_pset(cx + x, cy + y, c); +} +/* a dial: a 270-degree ring (lit up to the value), a pointer; ratio 0..1000, -1 = a plain ring */ +static void te_dial(int32_t cx, int32_t cy, int32_t r, int32_t ratio, uint16_t c, uint16_t dim) +{ + int32_t i, end = ratio < 0 ? 768 : ratio * 768 / 1000; + for (i = 0; i <= 768; i += 8) { + uint32_t a = (uint32_t)(384 + i) & 1023u; + int32_t co = SINE[(a + 256u) & 1023u], si = SINE[a], k; + uint16_t col = ratio < 0 || i <= end ? c : dim; + for (k = r - 2; k <= r; k++) + cv_pset(cx + ((co * k) >> 15), cy + ((si * k) >> 15), col); + } + if (ratio >= 0) { + uint32_t a = (uint32_t)(384 + end) & 1023u; + int32_t co = SINE[(a + 256u) & 1023u], si = SINE[a]; + cv_line(cx, cy, cx + ((co * (r - 4)) >> 15), cy + ((si * (r - 4)) >> 15), C_WHITE); + te_disc(cx, cy, 2, C_WHITE); + } +} +static void te_play_icon(int32_t x, int32_t y, int playing) +{ + int32_t i; + if (playing) + for (i = 0; i < 12; i++) + cv_rect(x + i, y + i / 2, 1, 14 - i, C_WHITE); /* a triangle */ + else + cv_rect(x, y + 1, 12, 12, TE_G3); +} +static uint32_t studio_hash(uint32_t h, const char *p) +{ while (*p) h = h * 31u + (uint8_t)*p++; return h; } +static void te_lower(char *d, const char *s, uint32_t n) +{ + uint32_t i; + for (i = 0; i + 1u < n && s[i]; i++) + d[i] = s[i] >= 'A' && s[i] <= 'Z' ? (char)(s[i] + 32) : s[i]; + d[i] = 0; +} +static void te_text_c(int32_t cx, int32_t y, const char *s, uint16_t c) /* centred on cx */ +{ + cv_text(cx - text_w(&FONT_S, s) / 2, y, &FONT_S, s, c); +} + +/* the dial strip: KNOB 1..4, label + value under each (a dial with no label: an empty column); a + * message replaces it */ +static void te_dials(int32_t y0, const char *const lab[4], const char *const val[4], const int32_t ratio[4], + uint32_t sig, uint32_t *cache) +{ + uint32_t k; + sig = studio_hash(sig, ui.msg_t ? ui.msg : ""); + for (k = 0; k < 4u; k++) { + sig = studio_hash(sig * 7u + (uint32_t)ratio[k] + (ui.hot_t && ui.hot_col == k) * 5003u, lab[k]); + sig = studio_hash(sig, val[k]); + } + if (!ui.force && sig == *cache) + return; + *cache = sig; + cv_begin(240, ui.msg_t ? 240u - (uint32_t)y0 : 40u, C_BLACK); + if (ui.msg_t) { /* a message: a white bar */ + cv_rect(0, 10, 240, 32, C_WHITE); + cv_text((240 - text_w(&FONT_S, ui.msg)) / 2, 18, &FONT_S, ui.msg, C_BLACK); + cv_blit(0, (uint32_t)y0); + return; + } + for (k = 0; k < 4u; k++) { + int32_t cx = 30 + 60 * (int32_t)k; + if (!lab[k][0]) + continue; + te_dial(cx, 12, 11, ratio[k], TE_COL[k], TE_DIM[k]); + te_text_c(cx, 24, lab[k], TE_G3); + } + cv_blit(0, (uint32_t)y0); + cv_begin(240, 16, C_BLACK); /* the values: white while turned */ + for (k = 0; k < 4u; k++) + te_text_c(30 + 60 * (int32_t)k, 0, val[k], ui.hot_t && ui.hot_col == k ? C_WHITE : TE_G4); + cv_blit(0, (uint32_t)y0 + 40u); +} + +static void studio_open(uint32_t scope) +{ + uint32_t i; + if (scope == SC_SONG && rec_wait) + rec_wait = 0; /* (an arm does not follow into the song page) */ + for (i = 0; i < NPAGES; i++) if (PAGES[i].scope == scope) { + ui.page = (uint8_t)i; ui.home = 0; song.seq_mode = 0; ui.force = 1; + ui.msg_t = 0; ui.entry_open = 0; return; + } +} +/* LIVE: REC, on any page. One record arm, on the selected track (it follows ALGORITHM). No + * click (seq.c): playing, recording starts at once; stopped, REC arms and the first note + * starts the loop (or, in an empty project, a free take that REC closes: seq.c ft_close). + * REC again stops recording / cancels the arm (playback continues). */ +static void rec_toggle(void) +{ + if (ft_owns_press()) + return; + if (song.playing && arrangement_enabled) { + ui_message("STOP THE SONG FIRST"); + return; + } + if (song.rec || rec_wait) { + song.rec = 0; + rec_wait = 0; + ui_message("REC OFF"); + return; + } + arrangement_enabled = 0; + if (song.playing) + rec_begin(); /* playing: record now */ + else + rec_wait = 1; /* stopped: the first note starts it */ +} + +/* the loop position of track t: "bar.beat" in its pattern (1.1 .. ) */ +static void loop_pos(const track_t *t, char *b) +{ + uint32_t len = (uint32_t)clamp(t->p[P_SLEN], 1, NSTEP), s = t->seq_idx % len, k; + fmt_int(b, (int32_t)(s / 16u + 1u)); + k = str_len(b); + b[k] = '.'; + b[k + 1] = (char)('1' + (s % 16u) / 4u); + b[k + 2] = 0; +} + +/* the header of the live screens: BPM, transport, the loop position, the beat lights, REC */ +static void te_header(const char *title, uint16_t tc, uint32_t *cache) +{ + char b[12]; + uint32_t beat = clk_beat, k, playing = song.playing; + uint32_t sig = studio_hash((uint32_t)song.g[G_BPM] * 7u + playing * 3u + (song.rec != 0) * 1999u + + (playing ? beat * 131u + TSEL->seq_idx * 7919u : 0u) + (uint32_t)song.g[G_CLOCK] * 77u + + arrangement_enabled * 5u + (ui.bpm_t != 0) * 104729u + song.solo * 37u, title); + sig = sig * 31u + tc; + if (!ui.force && sig == *cache) + return; + *cache = sig; + cv_begin(240, 40, C_BLACK); + fmt_int(b, song.g[G_BPM]); + cv_text(4, 4, &FONT_L, b, ui.bpm_t ? C_WHITE : TE_G4); + cv_text(4 + text_w(&FONT_L, b) + 4, 20, &FONT_S, "bpm", TE_G3); + te_play_icon(104, 6, (int)playing); + if (playing) { /* bar.beat in the selected track's loop */ + loop_pos(TSEL, b); + cv_text(122, 5, &FONT_S, b, C_WHITE); + } else { + cv_text(122, 5, &FONT_S, arrangement_enabled ? "song" : "loop", TE_G3); + } + for (k = 0; k < 4u; k++) /* the four beats of the bar */ + cv_rect(104 + (int32_t)k * 9, 26, 7, 7, playing && beat % 4u == k ? (k ? C_WHITE : TE_RED) : TE_G2); + if (song.rec) { + te_disc(224, 12, 8, TE_RED); + cv_text(176, 4, &FONT_S, "rec", TE_RED); + if (song.g[G_CLOCK] != 0) /* the click is on */ + cv_text(168, 22, &FONT_S, "click", TE_G3); + } else { + cv_text(240 - text_w(&FONT_S, title) - 4, 5, &FONT_S, title, tc); + if (song.solo) + cv_text(236 - text_w(&FONT_S, "solo"), 22, &FONT_S, "solo", C_WHITE); + } + cv_rect(0, 39, 240, 1, TE_G1); + cv_blit(0, 0); +} + +/* --------------------------------------------------------------- TRACKS --- */ +/* swing, MPC style: "62%" */ +static void swing_str(char *b, int32_t v) +{ + fmt_int(b, 50 + (clamp(v, 0, 100) + 2) / 4); + str_cpy(b + str_len(b), "%", 2); +} + +static void studio_tracks_draw(void) +{ + static uint32_t head, rows[NTRK], footer; + uint32_t i, j; + te_header("tracks", TE_G3, &head); + for (i = 0; i < NTRK; i++) { + track_t *t = &trk[i]; + char b[24], e[16]; + uint32_t selected = song.sel == i, len = (uint32_t)clamp(t->p[P_SLEN], 1, 64); + uint32_t level = i == TRK_DRUM ? song.g[G_DRLVL] : t->p[P_LEVEL]; + uint32_t silent = trk_silent(t) || !level, pos = t->seq_idx % len, rec = (song.rec >> i) & 1u; + uint32_t solo = (song.solo >> i) & 1u, bank = song.playing ? pos / 16u : 0u, h; + uint16_t col = TE_COL[i], dim = TE_DIM[i]; + if (i == TRK_DRUM) { + str_cpy(b, DRUM_KIT_NAMES[drum_kit()], sizeof b); + te_lower(e, "drums", sizeof e); + } else { + trk_short_name(i, b); + te_lower(e, ENGINES[t->eng_req % NENGINES]->name, sizeof e); + } + b[13] = 0; + h = studio_hash(selected + level * 7u + silent * 997u + rec * 1999u + solo * 4999u + len * 37u + + song.playing * 7u + pos * 71u + bank * 13u, b); + for (j = 0; j < len; j++) h = h * 31u + (uint32_t)trk_step_on(t, j); + if (!ui.force && h == rows[i]) continue; + rows[i] = h; + cv_begin(240, 36, C_BLACK); + cv_rect(2, 3, 26, 30, selected ? col : dim); /* the track tile */ + { + char n[2] = {(char)('1' + i), 0}; + cv_text(11, 10, &FONT_S, n, selected ? C_BLACK : col); + } + cv_text(34, 1, &FONT_S, b, selected ? C_WHITE : TE_G4); + if (34 + text_w(&FONT_S, b) + 6 + text_w(&FONT_S, e) < 196) + cv_text(34 + text_w(&FONT_S, b) + 6, 1, &FONT_S, e, selected ? col : TE_G3); + if (rec) { + cv_rect(200, 2, 36, 15, TE_RED); + cv_text(206, 1, &FONT_S, "rec", C_WHITE); + } else if (solo) { + cv_rect(200, 2, 36, 15, C_WHITE); + cv_text(202, 1, &FONT_S, "solo", C_BLACK); + } else if (silent) { + cv_text(204, 1, &FONT_S, "mute", TE_G3); + } + for (j = 0; j < 16u; j++) { /* the 16 steps in view */ + uint32_t p = bank * 16u + j, on = 0; + if (len <= 16u) { + if (p < len) on = trk_step_on(t, p) ? 2u : 1u; + } else { /* > 16 and stopped: the whole pattern, folded */ + uint32_t a = j * len / 16u, z = (j + 1u) * len / 16u, k; + if (song.playing) { + if (p < len) on = trk_step_on(t, p) ? 2u : 1u; + } else { + on = 1; + for (k = a; k < z; k++) if (trk_step_on(t, k)) on = 2; + } + } + cv_rect(34 + (int32_t)j * 10, 21, 8, 9, + !on ? C_BLACK : on == 2u ? (silent ? TE_G3 : selected ? col : dim) : TE_G1); + if (on == 2u && !selected && !silent) + cv_rect(34 + (int32_t)j * 10, 21, 8, 2, col); + if (song.playing && p == pos) + cv_rect(34 + (int32_t)j * 10, 31, 8, 2, C_WHITE); + } + cv_rect(198, 23, 38, 5, TE_G1); /* the level */ + if (!silent) + cv_rect(198, 23, (int32_t)level * 38 / 127, 5, selected ? col : TE_G3); + cv_blit(0, 40 + i * 36); + } + { /* KNOB 1 swing (the global groove), 2 level, 3 steps, 4 pan of the selected track */ + track_t *t = TSEL; + static char v[4][8]; + static const char *const lab[4] = {"swing", "level", "steps", "pan"}; + const char *val[4] = {v[0], v[1], v[2], v[3]}; + int32_t ratio[4]; + uint32_t lvl = is_drum(t) ? song.g[G_DRLVL] : t->p[P_LEVEL]; + swing_str(v[0], song.g[G_SWING]); + fmt_int(v[1], t->p[P_MUTE] ? 0 : (int32_t)lvl * 100 / 127); + fmt_int(v[2], t->p[P_SLEN]); + fmt_int(v[3], t->p[P_PAN]); + ratio[0] = song.g[G_SWING] * 10; + ratio[1] = t->p[P_MUTE] ? 0 : (int32_t)lvl * 1000 / 127; + ratio[2] = (t->p[P_SLEN] - 1) * 1000 / 63; + ratio[3] = (t->p[P_PAN] + 64) * 1000 / 127; + te_dials(184, lab, val, ratio, song.sel, &footer); + } +} + +/* ---------------------------------------------------------------- DRUMS --- */ +static const char *const LV_NAME[4] = {"norm", "ghost", "soft", "hard"}; +static uint16_t lvl_col(uint32_t lvl) /* a hit's colour by its level */ +{ + return lvl == LV_GHOST ? TE_DIM[3] : lvl == LV_SOFT ? TE_MID[3] : lvl == LV_HARD ? C_WHITE : TE_DRUM; +} +static uint16_t pad_lit[DRUM_LANES]; /* pads and key LEDs: frames left lit */ +static void pads_tick(void) /* once a frame: the hits since the last one */ +{ + uint32_t i, hits; + fm1_irq_off(); + hits = drums.hits; + drums.hits = 0; + fm1_irq_on(); + for (i = 0; i < DRUM_LANES; i++) { + if ((hits >> i) & 1u) pad_lit[i] = 6; + else if (pad_lit[i]) pad_lit[i]--; + } +} + +static void drum_screen_draw(void) +{ + static uint32_t head, title_sig, body_sig, footer; + uint32_t i, j, len = (uint32_t)clamp(TDRUM->p[P_SLEN], 1, 64), kit = drum_kit(), sig, bank; + if (drum_cursor >= len) drum_cursor = (uint8_t)(len - 1u); + bank = drum_cursor / 16u; + { + char st[16]; + te_lower(st, DRUM_KIT_STYLES[kit], sizeof st); + st[12] = 0; + te_header(st, TE_DRUM, &head); + } + sig = kit * 131u + drum_page * 7u + drum_lane * 977u + bank * 31u + len; /* title band */ + if (ui.force || sig != title_sig) { + char b[8]; + title_sig = sig; + cv_begin(240, 44, C_BLACK); + cv_rect(2, 4, 34, 34, TE_DRUM); + fmt_int(b, (int32_t)kit + 1); + cv_text(19 - text_w(&FONT_S, b) / 2, 13, &FONT_S, b, C_BLACK); + cv_text(44, 6, &FONT_L, DRUM_KIT_NAMES[kit], C_WHITE); + cv_text(202, 4, &FONT_S, "grid", drum_page == 0 ? C_WHITE : TE_G3); + cv_text(202, 22, &FONT_S, "kit", drum_page == 1 ? C_WHITE : TE_G3); + cv_rect(196, drum_page ? 26 : 8, 3, 9, TE_DRUM); + cv_blit(0, 40); + } + sig = drum_page + drum_lane * 7u + drum_cursor * 101u + song.playing * 71u + len * 3u; + if (song.playing) sig = sig * 31u + TDRUM->seq_idx; + for (i = 0; i < DRUM_LANES; i++) sig = sig * 3u + (pad_lit[i] != 0); + for (i = 0; i < len; i++) { + const dstep_t *s = &TDRUM->dstep[i]; + sig = sig * 31u + dstep_mask(s); + sig = sig * 31u + s->lvl[0] + s->lvl[1] * 7u + s->lvl[2] * 49u + s->lvl[3] * 343u; + sig = sig * 31u + s->rat[0] + s->rat[1] * 7u + s->rat[2] * 49u + s->rat[3] * 343u; + } + if (ui.force || sig != body_sig) { + body_sig = sig; + cv_begin(240, 100, C_BLACK); + if (!drum_page) { /* GRID: the 16 lanes x 16 steps of this bank */ + for (i = 0; i < DRUM_LANES; i++) { + int32_t y = (int32_t)i * 6 + 2; + cv_rect(2, y, 6, 5, pad_lit[i] ? C_WHITE : i == drum_lane ? TE_DRUM : TE_G2); + for (j = 0; j < 16u; j++) { + uint32_t p = bank * 16u + j; + const dstep_t *s = &TDRUM->dstep[p < NSTEP ? p : 0]; + uint16_t c; + if (p >= len) continue; + c = dstep_has(s, i) ? lvl_col(dstep_lvl(s, i)) : i == drum_lane ? TE_G2 : TE_G1; + if (song.playing && p == TDRUM->seq_idx && c == TE_G1) c = TE_G2; + cv_rect(12 + (int32_t)j * 14, y, 12, 5, c); + if (dstep_has(s, i) && dstep_rat(s, i)) { /* a ratchet: a notch per extra hit */ + uint32_t r; + for (r = 0; r < dstep_rat(s, i); r++) + cv_rect(13 + (int32_t)j * 14 + (int32_t)r * 3, y + 2, 2, 1, C_BLACK); + } + if (p == drum_cursor && i == drum_lane) { + cv_rect(11 + (int32_t)j * 14, y - 1, 14, 1, C_WHITE); + cv_rect(11 + (int32_t)j * 14, y + 5, 14, 1, C_WHITE); + } + } + } + } else { /* KIT: 16 pads, lit on each hit */ + for (i = 0; i < DRUM_LANES; i++) { + int32_t x = 2 + (int32_t)(i % 4u) * 60, y = (int32_t)(i / 4u) * 25; + cv_rect(x, y, 56, 23, pad_lit[i] ? TE_DRUM : TE_G1); + te_text_c(x + 28, y + 4, LANE_SHORT[i], pad_lit[i] ? C_BLACK : i == drum_lane ? C_WHITE : TE_G3); + } + } + cv_blit(0, 84); + } + { + static char v[4][12]; + const char *val[4] = {v[0], v[1], v[2], v[3]}; + static const char *const LG[4] = {"sound", "step", "hit", "level"}, *const LK[4] = {"kit", "level", "reverb", "pan"}; + int32_t ratio[4]; + if (!drum_page) { + const dstep_t *s = &TDRUM->dstep[drum_cursor]; + str_cpy(v[0], LANE_SHORT[drum_lane], 8); + fmt_int(v[1], drum_cursor + 1); + str_cpy(v[2], dstep_has(s, drum_lane) ? "on" : "--", 4); + str_cpy(v[3], dstep_has(s, drum_lane) ? LV_NAME[dstep_lvl(s, drum_lane)] : "--", 8); + ratio[0] = (int32_t)drum_lane * 1000 / (DRUM_LANES - 1); + ratio[1] = (int32_t)drum_cursor * 1000 / (int32_t)(len > 1u ? len - 1u : 1u); + ratio[2] = v[2][0] == 'o' ? 1000 : 0; + ratio[3] = dstep_has(s, drum_lane) ? (int32_t)((dstep_lvl(s, drum_lane) + 1u) % 4u) * 333 : 0; + te_dials(184, LG, val, ratio, 1u, &footer); + } else { + fmt_int(v[0], (int32_t)kit + 1); + fmt_int(v[1], song.g[G_DRLVL] * 100 / 127); + fmt_int(v[2], song.g[G_DRREV] * 100 / 127); + fmt_int(v[3], TDRUM->p[P_PAN]); + ratio[0] = (int32_t)kit * 1000 / (int32_t)(DRUM_KITS - 1u); + ratio[1] = song.g[G_DRLVL] * 1000 / 127; + ratio[2] = song.g[G_DRREV] * 1000 / 127; + ratio[3] = (TDRUM->p[P_PAN] + 64) * 1000 / 127; + te_dials(184, LK, val, ratio, 2u, &footer); + } + } +} + +/* the level order of the knobs: ghost < soft < norm < hard */ +static const uint8_t LV_UP[4] = {LV_GHOST, LV_SOFT, LV_NORM, LV_HARD}; +static uint32_t lvl_rank(uint32_t lvl) { return lvl == LV_GHOST ? 0u : lvl == LV_SOFT ? 1u : lvl == LV_NORM ? 2u : 3u; } + +static void drum_screen_input(uint32_t pressed, uint32_t home) +{ + uint32_t k, b; + int32_t s; + if (song.sel != TRK_DRUM || home == 1u) { + go_home(); + return; + } + for (k = 0; k < NB; k++) if ((pressed >> panel.btn[k]) & 1u) { + b = k; + if (b == B_PLAY) { + if (ft_owns_press()) ; + else if (!song.playing && arrangement_enabled && !arr_valid(&arrangement, arrangement_ready())) ui_message("EMPTY SECTION: REC"); + else transport_req = song.playing ? 2 : 1; + } else if (b == B_SEQ || b == B_EDIT) { + drum_page = (uint8_t)((drum_page + 1u) % 2u); + ui.msg_t = 0; + ui.force = 1; + } else if (b == B_SAVE) { + studio_open(SC_SONG); + return; + } + } + if ((s = panel_enc(EN_SELECT))) { + song.g[G_BPM] = (int16_t)clamp(song.g[G_BPM] + accel(EN_SELECT, s, 200), 40, 240); + ui.bpm_t = 40; + } + if ((s = panel_enc(EN_ALGO)) && !ft_on) { + track_select((uint32_t)clamp((int32_t)song.sel + s, 0, 3)); + if (song.sel != TRK_DRUM) { + go_home(); + return; + } + } + if ((s = panel_enc(EN_PRESET))) TDRUM->p[P_E0] = (int16_t)clamp(TDRUM->p[P_E0] + s, 0, DRUM_KITS - 1); + for (k = 0; k < 4u; k++) if ((s = panel_enc(EN_K1 + k))) { + ui.hot_col = (uint8_t)k; + ui.hot_t = 40; + if (!drum_page) { + dstep_t *st = &TDRUM->dstep[drum_cursor]; + if (k == 0) drum_lane = (uint8_t)clamp(drum_lane + s, 0, DRUM_LANES - 1); + if (k == 1) drum_cursor = (uint8_t)clamp(drum_cursor + s, 0, TDRUM->p[P_SLEN] - 1); + if (k >= 2) { + if (song.playing && arrangement_enabled) { ui_message("STOP THE SONG FIRST"); continue; } + undo_mark(TDRUM, ui.step_sess ? ui.step_sess : (ui.step_sess = (undo_sess += 4u) | 3u)); + fm1_irq_off(); + if (k == 2) { + if (s > 0) dstep_set(st, drum_lane, LV_NORM, 0); + else dstep_clr(st, drum_lane); + } else if (dstep_has(st, drum_lane)) { + uint32_t r = (uint32_t)clamp((int32_t)lvl_rank(dstep_lvl(st, drum_lane)) + (s > 0 ? 1 : -1), 0, 3); + dstep_set(st, drum_lane, LV_UP[r], dstep_rat(st, drum_lane)); + } + fm1_irq_on(); + sync_reload = 1; + } + } else { + if (k == 0) TDRUM->p[P_E0] = (int16_t)clamp(TDRUM->p[P_E0] + s, 0, DRUM_KITS - 1); + if (k == 1) song.g[G_DRLVL] = (int16_t)clamp(song.g[G_DRLVL] + s, 0, 127); + if (k == 2) song.g[G_DRREV] = (int16_t)clamp(song.g[G_DRREV] + s, 0, 127); + if (k == 3) TDRUM->p[P_PAN] = (int16_t)clamp(TDRUM->p[P_PAN] + s, -64, 63); + } + } +} + +/* ---------------------------------------------------------------- REC --- */ +/* a big seven-segment digit, TE style: w x h, segments t thick */ +static void te_digit(int32_t x, int32_t y, int32_t w, int32_t h, int32_t t, uint32_t d, uint16_t c) +{ + static const uint8_t SEG[10] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F}; /* gfedcba */ + uint32_t m = SEG[d % 10u]; + int32_t hh = h / 2; + if (m & 0x01) cv_rect(x + t, y, w - 2 * t, t, c); /* a */ + if (m & 0x02) cv_rect(x + w - t, y + t, t, hh - t, c); /* b */ + if (m & 0x04) cv_rect(x + w - t, y + hh, t, hh - t, c); /* c */ + if (m & 0x08) cv_rect(x + t, y + h - t, w - 2 * t, t, c); /* d */ + if (m & 0x10) cv_rect(x, y + hh, t, hh - t, c); /* e */ + if (m & 0x20) cv_rect(x, y + t, t, hh - t, c); /* f */ + if (m & 0x40) cv_rect(x + t, y + hh - t / 2, w - 2 * t, t, c); /* g */ +} + +static uint8_t rec_shown; +/* REC armed (stopped: waiting for the first note) or a free take running (seq.c). The four + * tracks stay in view below; the REC LED blinks while armed, is lit during the take. */ +static void rec_screen_draw(void) +{ + static uint32_t head, body, rows, foot; + uint32_t sig, i, j, take = ft_on, empty = take || project_empty(), rt = take ? ft_trk % NTRK : song.sel; + uint32_t blink = (fm1_ms / 250u) & 1u, secs = take ? ft_t * CTL / FS : 0u, bars = 0, bpm = 0; + if (take) + bars = ft_fit(ft_t, &bpm); + if (!rec_shown) { + lcd_fill(0, 0, 240, 240, C_BLACK); + ui.force = 1; + } + rec_shown = 1; + te_header(take ? "free take" : "rec ready", TE_RED, &head); + sig = take * 1000003u + empty * 7u + rt * 7919u + blink * 31u + secs * 131u + bars * 17u + bpm * 3u; + if (ui.force || sig != body) { + char b[24]; + body = sig; + cv_begin(240, 106, C_BLACK); + if (take) { /* free take: the time, the loop it makes */ + uint32_t n = secs > 99u ? 99u : secs; + te_disc(18, 30, 9, blink ? TE_RED : TE_DIM[3]); + if (n >= 10u) + te_digit(36, 4, 32, 56, 7, n / 10u, C_WHITE); + te_digit(76, 4, 32, 56, 7, n % 10u, C_WHITE); + cv_text(112, 44, &FONT_S, "s", TE_G3); + cv_rect(132, 6, 1, 54, TE_G1); + if (bars) { + fmt_int(b, (int32_t)bars); + cv_text(146, 4, &FONT_L, b, TE_COL[rt & 3u]); + cv_text(146 + text_w(&FONT_L, b) + 6, 18, &FONT_S, bars == 1u ? "bar" : "bars", TE_G3); + fmt_int(b, (int32_t)bpm); + cv_text(146, 42, &FONT_S, b, C_WHITE); + cv_text(146 + text_w(&FONT_S, b) + 4, 42, &FONT_S, "bpm", TE_G3); + } else { + cv_text(146, 4, &FONT_L, "-", TE_G3); + } + te_text_c(120, 80, "press rec on the 1", TE_RED); + } else { /* ready: the first note starts everything */ + te_disc(120, 30, 22, blink ? TE_RED : TE_DIM[3]); + te_disc(120, 30, 9, C_BLACK); + te_text_c(120, 62, empty ? "play freely" : "play a note", C_WHITE); + te_text_c(120, 80, empty ? "then rec on the 1" : "it starts the loop", TE_G3); + } + cv_blit(0, 42); + } + /* the four tracks, compact: the one that records is framed in red */ + sig = rt * 3u + rec_wait + take * 5u + drum_kit() * 977u; + for (i = 0; i < NTRK; i++) { + char b[16]; + if (i == TRK_DRUM) str_cpy(b, DRUM_KIT_NAMES[drum_kit()], sizeof b); + else trk_short_name(i, b); + sig = studio_hash(sig, b) + (uint32_t)trk[i].p[P_SLEN] * 31u; + for (j = 0; j < NSTEP; j++) sig = sig * 3u + (uint32_t)trk_step_on(&trk[i], j); + } + if (ui.force || sig != rows) { + rows = sig; + cv_begin(240, 76, C_BLACK); + for (i = 0; i < NTRK; i++) { + const track_t *t = &trk[i]; + uint32_t len = (uint32_t)clamp(t->p[P_SLEN], 1, 64), armed = i == rt; + int32_t y = (int32_t)i * 19; + char b[16]; + if (armed) cv_rect(0, y, 240, 18, TE_RED), cv_rect(1, y + 1, 238, 16, C_BLACK); + cv_rect(4, y + 3, 12, 12, armed ? TE_COL[i] : TE_DIM[i]); + if (i == TRK_DRUM) str_cpy(b, DRUM_KIT_NAMES[drum_kit()], sizeof b); + else trk_short_name(i, b); + b[10] = 0; + cv_text(22, y + 1, &FONT_S, b, armed ? C_WHITE : TE_G3); + for (j = 0; j < 16u; j++) { + uint32_t a = j * len / 16u, z = (j + 1u) * len / 16u, k, on = 0; + if (z == a) z = a + 1u; + for (k = a; k < z && k < NSTEP; k++) if (trk_step_on(t, k)) on = 1; + cv_rect(106 + (int32_t)j * 8, y + 5, 6, 8, on ? (armed ? TE_COL[i] : TE_DIM[i]) : TE_G1); + } + } + cv_blit(0, 148); + } + sig = take; + if (ui.force || sig != foot) { + foot = sig; + cv_begin(240, 16, C_BLACK); + cv_text(4, 0, &FONT_S, take ? "rec: close" : "rec: cancel", TE_G3); + cv_text(236 - text_w(&FONT_S, take ? "play: drop" : "play: go"), 0, &FONT_S, take ? "play: drop" : "play: go", TE_G3); + cv_blit(0, 224); + } +} diff --git a/firmware/src/upreset.c b/firmware/src/upreset.c new file mode 100644 index 0000000..d676ede --- /dev/null +++ b/firmware/src/upreset.c @@ -0,0 +1,319 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* User presets (editor protocol v2, cmds 16-21; the SAVE > USER page): 32 + * slots in two storage.c objects (OBJ_UPRESET0/1, 0xDC000..0xDFFFF), 16 + * records each, mirrored in RAM so browsing never reads flash. A record: + * engine, name, the instrument parameters, a 16-step pattern. + * + * A bank whose magic, record size or slot count differ reads as empty; so + * does a record with another UP_VER. A record keeps np = the P_COUNT it was + * stored with; when that differs it is mapped by count: its last 8 values + * are P_E0..P_E7, the first np - 8 are P_LEVEL.. in order, missing ones take + * their defaults. So common parameters may only be added just before P_E0 + * (else bump UP_VER). + * + * With -DUP_HOST (host test) only the part above #ifndef UP_HOST is built; + * it needs nothing but core.h. */ +#define UP_PER_BANK 16u +#define UP_PMAX 72u /* room for P_COUNT to grow */ +#define UP_USED 0xA5u +#define UP_VER 1u +#define UP_BANK_MAGIC 0x31425055u /* "UPB1" */ +typedef struct { + uint8_t used, ver, engine, np; /* UP_USED, UP_VER, engine, P_COUNT when stored */ + char name[12]; /* ASCII 32..126, 0-padded (no 0 when 12 long) */ + int16_t p[UP_PMAX]; + uint8_t note[16], flags[16]; /* note 0 = rest; flags 1 accent, 2 slide, 4 tie */ +} up_rec_t; +typedef struct { + uint32_t magic; + uint16_t rsize, nslot; + up_rec_t r[UP_PER_BANK]; +} up_bank_t; +_Static_assert(sizeof(up_rec_t) == 192, "user preset record layout"); +_Static_assert(P_COUNT <= UP_PMAX && P_COUNT < 128, "user preset record: P_COUNT"); +static up_bank_t up_bank[UP_SLOTS / UP_PER_BANK]; + +static up_rec_t *up_rec(uint32_t k) { return &up_bank[k / UP_PER_BANK].r[k % UP_PER_BANK]; } + +static int up_valid(const up_rec_t *r) +{ + return r->used == UP_USED && r->ver == UP_VER && r->engine < NENGINES && r->np >= 8u && r->np <= UP_PMAX && + r->name[0]; +} + +static int up_used(uint32_t k) { return k < UP_SLOTS && up_valid(up_rec(k)); } + +static void up_bank_check(uint32_t b, int len) /* after loading bank b (len bytes, -1 = none): wrong shape -> empty */ +{ + up_bank_t *bk = &up_bank[b]; + if (len != (int)sizeof *bk || bk->magic != UP_BANK_MAGIC || bk->rsize != sizeof(up_rec_t) || + bk->nslot != UP_PER_BANK) + memset(bk, 0, sizeof *bk); +} + +/* the record's values in today's P_* order (mapped by count, see above); def = the defaults */ +static void up_params(const up_rec_t *r, int16_t *out, const int16_t *def) +{ + uint32_t i, nc = r->np - 8u; + for (i = 0; i < P_E0; i++) + out[i] = i < nc ? r->p[i] : def[i]; + for (i = 0; i < 8u; i++) + out[P_E0 + i] = r->p[nc + i]; +} + +static int up_name_ok(const uint8_t *s, uint32_t n) /* 1..12 printable ASCII */ +{ + uint32_t i; + if (!n || n > 12u) + return 0; + for (i = 0; i < n; i++) + if (s[i] < 32u || s[i] > 126u) + return 0; + return 1; +} + +static void up_name(uint32_t k, char *b) /* upper case, 0-terminated: b holds 13 */ +{ + const up_rec_t *r = up_rec(k); + uint32_t i; + for (i = 0; i < 12u && r->name[i]; i++) + b[i] = r->name[i] >= 'a' && r->name[i] <= 'z' ? (char)(r->name[i] - 32) : r->name[i]; + b[i] = 0; +} + +static void up_pat_norm(uint8_t *note, uint8_t *flags) /* tie: no note; rest: no flags */ +{ + *note &= 127u; + if (*flags & 4u) { + *note = 0; + *flags = 4; + } else { + *flags = *note ? (uint8_t)(*flags & (SF_ACCENT | SF_SLIDE)) : 0u; + } +} + +static void up_pat_from(up_rec_t *r, const step_t *st) /* the first 16 steps -> the pattern */ +{ + uint32_t i; + for (i = 0; i < 16u; i++) { + r->note[i] = st[i].time == ST_NOTE && st[i].n ? st[i].note[0] : 0u; + r->flags[i] = st[i].time == ST_TIE ? 4u : st[i].flags; + up_pat_norm(&r->note[i], &r->flags[i]); + } +} + +static int up_pat_empty(const up_rec_t *r) +{ + uint32_t i; + for (i = 0; i < 16u; i++) + if (r->note[i]) + return 0; + return 1; +} + +/* UP_PUT arguments: slot, engine, name, P_COUNT x v14, 16 x (note, flags) -> *r (values not yet + * clamped); 0 ok, 1 bad arguments. *slot gets the slot byte when there is one. */ +static int up_parse(const uint8_t *a, uint32_t na, up_rec_t *r, uint32_t *slot) +{ + uint32_t i, n, k; + if (na < 3u) + return 1; + *slot = a[0]; + for (n = 0; 2u + n < na && a[2 + n]; n++) + ; + k = 3u + n; /* after the name's 0 */ + if (a[0] >= UP_SLOTS || a[1] >= NENGINES || 2u + n >= na || !up_name_ok(a + 2, n) || + na < k + 2u * P_COUNT + 32u) + return 1; + memset(r, 0, sizeof *r); + r->used = UP_USED; + r->ver = UP_VER; + r->engine = a[1]; + r->np = P_COUNT; + for (i = 0; i < n; i++) + r->name[i] = (char)a[2 + i]; + for (i = 0; i < P_COUNT; i++, k += 2u) + r->p[i] = (int16_t)((int32_t)((a[k] & 127u) | (a[k + 1] & 127u) << 7) - 8192); + for (i = 0; i < 16u; i++, k += 2u) { + r->note[i] = a[k]; + r->flags[i] = a[k + 1]; + up_pat_norm(&r->note[i], &r->flags[i]); + } + return 0; +} + +#ifndef UP_HOST +static const param_desc_t *up_desc(uint32_t e, uint32_t i) +{ + return i >= P_E0 ? &ENGINES[e]->edit[i - P_E0] : &TP[i]; +} + +static void up_values(const up_rec_t *r, int16_t *v) /* mapped and clamped for its engine */ +{ + int16_t def[P_COUNT]; + uint32_t i; + for (i = 0; i < P_COUNT; i++) + def[i] = up_desc(r->engine, i)->def; + up_params(r, v, def); + for (i = 0; i < P_COUNT; i++) + v[i] = (int16_t)clamp(v[i], up_desc(r->engine, i)->min, up_desc(r->engine, i)->max); +} + +static void up_boot(void) /* persist_boot: the banks from flash */ +{ +#if FELUCCA_FLASH + uint32_t b; + for (b = 0; b < UP_SLOTS / UP_PER_BANK; b++) + up_bank_check(b, flash_ok ? st_load(OBJ_UPRESET0 + b, &up_bank[b], sizeof up_bank[b]) : -1); +#endif +} + +/* record k = *r (0: erase), then the bank to flash: 0 ok, 2 flash error, 3 no flash (kept in RAM) */ +static int up_put(uint32_t k, const up_rec_t *r) +{ + up_bank_t *bk = &up_bank[k / UP_PER_BANK]; + bk->magic = UP_BANK_MAGIC; + bk->rsize = sizeof(up_rec_t); + bk->nslot = UP_PER_BANK; + if (r) + *up_rec(k) = *r; + else + memset(up_rec(k), 0, sizeof(up_rec_t)); + if (!r) { + uint32_t i; + for (i = 0; i < NTRK; i++) + if (trk[i].user == k + 1u) + trk[i].user = 0; + } + up_gen++; +#if FELUCCA_FLASH + if (flash_ok) + return st_save(OBJ_UPRESET0 + k / UP_PER_BANK, bk, sizeof *bk) ? 2 : 0; +#endif + return 3; +} + +static void up_slot_label(char *b, uint32_t k) /* "U07" */ +{ + b[0] = 'U'; + b[1] = (char)('0' + (k + 1u) / 10u); + b[2] = (char)('0' + (k + 1u) % 10u); + b[3] = 0; +} + +/* the selected part's sound -> slot k; name 0 or "": engine name + slot number ("ANALOG 07"). + * 1 = the drum track is selected (it has no sound to store) */ +static int up_store(uint32_t k, const char *name) +{ + up_rec_t r; + uint32_t i; + if (is_drum(TSEL)) + return 1; + memset(&r, 0, sizeof r); + r.used = UP_USED; + r.ver = UP_VER; + r.engine = TSEL->eng_req; + r.np = P_COUNT; + if (name && name[0]) { + for (i = 0; i < 12u && name[i]; i++) + r.name[i] = name[i]; + } else { + char b[16], l[4]; + str_cpy(b, ENGINES[TSEL->eng_req]->name, 9); + up_slot_label(l, k); + str_cpy(b + str_len(b), " ", 2); + str_cpy(b + str_len(b), l + 1, 3); + for (i = 0; i < 12u && b[i]; i++) + r.name[i] = b[i]; + } + for (i = 0; i < P_COUNT; i++) + r.p[i] = TSEL->p[i]; + up_pat_from(&r, TSEL->step); + return up_put(k, &r); +} + +/* slot k -> the selected part's sound: engine and every parameter except its mix (LEVEL, + * PAN, MUTE: the TRACKS faders) and its pattern parameters (param_kept). LIVE: the pattern + * stored in the record is not loaded: changing the sound never changes the sequence. + * 0 ok, 1 empty (or the drum track is selected) */ +static int up_load(uint32_t k) +{ + const up_rec_t *r; + int16_t v[P_COUNT]; + uint32_t i; + track_t *t = TSEL; + if (!up_used(k) || is_drum(t)) + return 1; + r = up_rec(k); + up_values(r, v); + for (i = 0; i < P_COUNT; i++) /* (LEN etc. of a kept pattern changed too, and */ + if (param_kept(i)) /* a preset pattern then counted as edited) */ + v[i] = t->p[i]; + panic_req |= (uint8_t)(1u << song.sel); + fm1_irq_off(); /* the audio ISR must not see half a sound */ + t->eng_req = r->engine; + for (i = 0; i < P_COUNT; i++) + t->p[i] = v[i]; + t->preset = 0; + fm1_irq_on(); + t->user = (uint8_t)(k + 1u); + sync_reload = 1; + ui.force = 1; + return 0; +} + +static uint32_t up_count(void) /* used slots */ +{ + uint32_t k, n = 0; + for (k = 0; k < UP_SLOTS; k++) + n += (uint32_t)up_used(k); + return n; +} + +static uint32_t up_nth(uint32_t n) /* slot of the n-th used one (n < up_count()) */ +{ + uint32_t k; + for (k = 0; k < UP_SLOTS; k++) + if (up_used(k) && !n--) + return k; + return 0; +} + +static uint32_t up_rank(uint32_t slot) /* used slots before it */ +{ + uint32_t k, n = 0; + for (k = 0; k < slot && k < UP_SLOTS; k++) + n += (uint32_t)up_used(k); + return n; +} + +/* SAVE > USER page actions, with the message in the top bar */ +static void up_ui(uint32_t op, uint32_t k) /* 0 load, 1 erase, 2 save */ +{ + char l[4]; + int rc; + up_slot_label(l, k); + if (op != 1u && is_drum(TSEL)) { + ui_message("DRUM TRACK: NO SOUND"); + return; + } + if (op < 2u && !up_used(k)) { + ui_message("EMPTY SLOT"); + return; + } + if (op == 0u) { + up_load(k); + ui_say("LOADED ", l); + return; + } + rc = op == 1u ? up_put(k, 0) : up_store(k, 0); + if (rc == 3) + ui_message(op == 1u ? "ERASED (RAM)" : "SAVED (RAM)"); + else if (rc) + ui_message(op == 1u ? "ERASE ERROR" : "SAVE ERROR"); + else + ui_say(op == 1u ? "ERASED " : "SAVED ", l); + ui.force = 1; +} +#endif diff --git a/firmware/src/usb.c b/firmware/src/usb.c new file mode 100644 index 0000000..9c87ba9 --- /dev/null +++ b/firmware/src/usb.c @@ -0,0 +1,731 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* USB full-speed device on USB0: a class-compliant USB-MIDI interface. + * All SIE traffic happens in usb_poll(), called from the TIMER5 ISR at 2 kHz, + * so INDEX is never shared and no USB IRQ is needed. MIDI in goes to a ring + * the audio ISR drains; MIDI out comes from a ring the audio ISR fills. + * SysEx F0 22 24 35 7D F7 (soft key) asks the main loop to enter UBOOT. + * VID 0x1209 / PID 0x0001 is the pid.codes test id. + * FELUCCA_CDC=1 adds a CDC-ACM serial function (IAD composite: EP2 notify, + * EP3 bulk data) for the console in console.c. */ +#include "../hal/fm1_usb.h" /* registers; relative, so the loader and the host tests find it too */ +enum { S_FADDR = 0, S_POWER = 1, S_INTRTX1 = 2, S_INTRTX2 = 3, S_INTRRX1 = 4, S_INTRRX2 = 5, S_INTRUSB = 6, + S_INTRTX1E = 7, S_INTRTX2E = 8, S_INTRRX1E = 9, S_INTRRX2E = 10, S_INTRUSBE = 11, S_FRAME1 = 12, + S_FRAME2 = 13, S_INDEX = 14, + S_TXMAXP = 16, S_CSR0 = 17, S_TXCSR1 = 17, S_TXCSR2 = 18, S_RXMAXP = 19, S_RXCSR1 = 20, S_RXCSR2 = 21, + S_COUNT0 = 22, S_RXCOUNT1 = 22, S_RXCOUNT2 = 23 }; + +static uint8_t ep0buf[64 + 4] __attribute__((aligned(4))); +static uint8_t ep1tx[64] __attribute__((aligned(4))); +static uint8_t ep1rx[64 + 4] __attribute__((aligned(4))); +#if FELUCCA_CDC +static uint8_t ep2tx[8] __attribute__((aligned(4))); +static uint8_t ep3tx[64] __attribute__((aligned(4))); +static uint8_t ep3rx[64 + 4] __attribute__((aligned(4))); +/* serial rings: in = host -> console (ISR writes), out = console -> host (ISR reads) */ +#define CI_N 256u +#define CO_N 2048u +static uint8_t cdc_in[CI_N], cdc_out[CO_N]; +static volatile uint32_t ci_w, ci_r, co_w, co_r; +static struct { + uint8_t line[7]; /* line coding: just stored and echoed back */ + volatile uint8_t dtr; /* host has the port open */ + uint8_t e0_rx; /* SET_LINE_CODING data stage pending */ + uint8_t rx_pend; /* EP3 OUT packet seen, not yet taken (the ring was full) */ + uint32_t rx_pkts, tx_pkts; +} cdc = {{0x00, 0xC2, 0x01, 0x00, 0, 0, 8}}; /* 115200 8N1 */ +#endif + +static struct { + uint8_t up, config, pend_addr, has_pend_addr, e0_tx, e0_zlp; + const uint8_t *e0_src; + uint16_t e0_left; + uint32_t resets, setups, rx_pkts, tx_pkts, sof_seen, timeouts, no_sof; + uint32_t suspends, max_gap, retries, frame_stalls; + uint16_t frame, frame_same; /* last SOF frame number and how long it has not moved (x 10 ms) */ + uint8_t detached; /* usb_detach() was called: no retry */ + volatile uint8_t suspended; /* bus idle > 3 ms (unplugged or host asleep): the UI hides "USB" */ + uint8_t last_setup[8]; + uint8_t sysex[16]; + uint8_t sx_len, sx_on; + volatile uint8_t uboot_req; + volatile uint8_t ota_req; /* F0 22 24 35 7F F7: M-UPGRADE upgrade command (FELUCCA_OTA) */ +} usb; + +#if FELUCCA_OTA +/* M-UPGRADE SysEx (ota.c): one received frame at a time (7-bit bytes between + * F0 and F7; frames arriving while one is pending are dropped, the host + * retries), and a TX ring of SysEx event packets sent before any MIDI. */ +static uint8_t sx_frame[640]; +static uint32_t sx_pos; +static volatile uint32_t sx_frame_len; +static volatile uint8_t sx_ready, sx_collect, sx_busy; +#define SXQ 64u +static uint32_t sx_out_q[SXQ]; +static volatile uint32_t so_w, so_r; +#endif + +/* MIDI rings: 4-byte USB-MIDI event packets */ +#define MQ 64u +static uint32_t midi_in_q[MQ], midi_out_q[MQ]; +static volatile uint32_t mi_w, mi_r, mo_w, mo_r; + +static void midi_out_event(uint32_t pkt) /* from the audio ISR */ +{ + if (usb.config && mo_w - mo_r < MQ) { + midi_out_q[mo_w % MQ] = pkt; + RING_PUBLISH(); + mo_w++; + } +} + +/* ------------------------------------------------------- descriptors --- */ +#if FELUCCA_CDC +static const uint8_t DEV_DESC[18] = {18, 1, 0x00, 0x02, 0xEF, 0x02, 0x01, 64, 0x09, 0x12, 0x01, 0x00, 0x01, 0x03, + 1, 2, 0, 1}; /* misc/IAD, bcdDevice 3.01 */ +static const uint8_t CFG_DESC[175] = { + 9, 2, 175, 0, 4, 1, 0, 0x80, 50, + 8, 0x0B, 0, 2, 1, 1, 0, 0, /* IAD: MIDI (IF 0-1) */ +#else +#ifndef FELUCCA_USB_PID +#define FELUCCA_USB_PID 0x0001 /* the update loader is 0x0002 */ +#endif +static const uint8_t DEV_DESC[18] = {18, 1, 0x10, 0x01, 0, 0, 0, 64, 0x09, 0x12, FELUCCA_USB_PID & 0xFF, + FELUCCA_USB_PID >> 8, 0x00, 0x03, + 1, 2, 0, 1}; +static const uint8_t CFG_DESC[101] = { + 9, 2, 101, 0, 2, 1, 0, 0x80, 50, +#endif + 9, 4, 0, 0, 0, 1, 1, 0, 0, + 9, 0x24, 1, 0x00, 0x01, 9, 0, 1, 1, + 9, 4, 1, 0, 2, 1, 3, 0, 0, + 7, 0x24, 1, 0x00, 0x01, 0x41, 0x00, + 6, 0x24, 2, 1, 1, 0, + 6, 0x24, 2, 2, 2, 0, + 9, 0x24, 3, 1, 3, 1, 2, 1, 0, + 9, 0x24, 3, 2, 4, 1, 1, 1, 0, + 9, 5, 0x01, 2, 64, 0, 0, 0, 0, + 5, 0x25, 1, 1, 1, + 9, 5, 0x81, 2, 64, 0, 0, 0, 0, + 5, 0x25, 1, 1, 3, +#if FELUCCA_CDC + 8, 0x0B, 2, 2, 2, 2, 1, 0, /* IAD: CDC ACM (IF 2-3) */ + 9, 4, 2, 0, 1, 2, 2, 1, 0, /* IF2 communication */ + 5, 0x24, 0x00, 0x10, 0x01, /* header 1.10 */ + 5, 0x24, 0x01, 0x00, 3, /* call management: data IF 3 */ + 4, 0x24, 0x02, 0x02, /* ACM: line coding + state */ + 5, 0x24, 0x06, 2, 3, /* union 2 -> 3 */ + 7, 5, 0x82, 3, 8, 0, 16, /* EP2 IN interrupt (never sent) */ + 9, 4, 3, 0, 2, 0x0A, 0, 0, 0, /* IF3 data */ + 7, 5, 0x03, 2, 64, 0, 0, /* EP3 OUT bulk */ + 7, 5, 0x83, 2, 64, 0, 0, /* EP3 IN bulk */ +#endif +}; +static const uint8_t STR0[4] = {4, 3, 0x09, 0x04}; +static const uint8_t STR1[] = {42, 3, 'H', 0, 0xFC, 0, 'g', 0, 'e', 0, 'l', 0, 't', 0, 'o', 0, 'n', 0, ' ', 0, 'I', 0, + 'n', 0, 's', 0, 't', 0, 'r', 0, 'u', 0, 'm', 0, 'e', 0, 'n', 0, 't', 0, 's', 0}; +#ifdef FELUCCA_LOADER +static const uint8_t STR2[] = {30, 3, 'F', 0, 'e', 0, 'l', 0, 'u', 0, 'c', 0, 'c', 0, 'a', 0, ' ', 0, 'U', 0, 'p', 0, + 'd', 0, 'a', 0, 't', 0, 'e', 0}; +#else +static const uint8_t STR2[] = {16, 3, 'F', 0, 'e', 0, 'l', 0, 'u', 0, 'c', 0, 'c', 0, 'a', 0}; +#endif + +static int get_desc(uint32_t wvalue, const uint8_t **d, uint16_t *l) +{ + switch (wvalue >> 8) { + case 1: + *d = DEV_DESC; + *l = sizeof DEV_DESC; + return 1; + case 2: + *d = CFG_DESC; + *l = sizeof CFG_DESC; + return 1; + case 3: + switch (wvalue & 0xFFu) { + case 0: + *d = STR0; + *l = sizeof STR0; + return 1; + case 1: + *d = STR1; + *l = sizeof STR1; + return 1; + case 2: + *d = STR2; + *l = sizeof STR2; + return 1; + default: + return 0; + } + default: + return 0; + } +} + +/* ---------------------------------------------------------- the SIE --- */ +static void sie_wr(uint32_t r, uint32_t v) +{ + uint32_t n = 20000; + if (!fm1_usb_sie_on()) + return; + fm1_usb_sie_wr_start(r, v); + while (!fm1_usb_sie_done() && --n) + ; + if (n) + usb.timeouts = 0; /* consecutive failures only */ + else if (++usb.timeouts > 50u) + usb.up = 0; /* SIE dead (no clock?): stop polling it */ +} + +static uint32_t sie_rd(uint32_t r) +{ + uint32_t n = 20000; + if (!fm1_usb_sie_on()) + return 0; + fm1_usb_sie_rd_start(r); + while (!fm1_usb_sie_done()) + if (!--n) { + if (++usb.timeouts > 50u) + usb.up = 0; + return 0; + } + usb.timeouts = 0; + return fm1_usb_sie_data(); +} + +static void ep1_config(void) +{ + fm1_usb_ep_txbuf(1, ep1tx); + fm1_usb_ep_rxbuf(1, ep1rx); + sie_wr(S_INDEX, 1); + sie_wr(S_TXMAXP, 0xFF); + sie_wr(S_TXCSR1, 0x48); + sie_wr(S_TXCSR2, 0); + sie_wr(S_RXMAXP, 0xFF); + sie_wr(S_RXCSR1, 0x90); + sie_wr(S_RXCSR2, 0); + sie_wr(S_INTRRX1E, 0x02); + fm1_usb_ep_enable(1u << 1); +#if FELUCCA_CDC + fm1_usb_ep_txbuf(2, ep2tx); + sie_wr(S_INDEX, 2); + sie_wr(S_TXMAXP, 0xFF); + sie_wr(S_TXCSR1, 0x48); + sie_wr(S_TXCSR2, 0); + fm1_usb_ep_txbuf(3, ep3tx); + fm1_usb_ep_rxbuf(3, ep3rx); + sie_wr(S_INDEX, 3); + sie_wr(S_TXMAXP, 0xFF); + sie_wr(S_TXCSR1, 0x48); + sie_wr(S_TXCSR2, 0); + sie_wr(S_RXMAXP, 0xFF); + sie_wr(S_RXCSR1, 0x90); + sie_wr(S_RXCSR2, 0); + sie_wr(S_INTRRX1E, 0x0A); + fm1_usb_ep_enable((1u << 2) | (1u << 3)); + cdc.rx_pend = 1; /* look once: a packet may already wait */ +#endif +} + +static void e0_chunk(void) +{ + uint32_t n = usb.e0_left > 64u ? 64u : usb.e0_left, i; + int last; + for (i = 0; i < n; i++) + ep0buf[i] = usb.e0_src[i]; + fm1_usb_ep0_send(ep0buf, n); + usb.e0_src += n; + usb.e0_left = (uint16_t)(usb.e0_left - n); + last = usb.e0_left == 0 && !(n == 64u && usb.e0_zlp); + if (usb.e0_left == 0 && n == 64u) + usb.e0_zlp = 0; + sie_wr(S_INDEX, 0); + sie_wr(S_CSR0, last ? 0x0A : 0x02); + if (last) + usb.e0_tx = 0; +} + +static void e0_send(const uint8_t *p, uint16_t len, uint16_t wlen) +{ + if (len > wlen) + len = wlen; + usb.e0_src = p; + usb.e0_left = len; + usb.e0_zlp = (len < wlen) && (len % 64u == 0); + usb.e0_tx = 1; + sie_wr(S_INDEX, 0); + sie_wr(S_CSR0, 0x40); + e0_chunk(); +} + +static void ep0_service(void) +{ + static const uint8_t zero2[2]; + uint32_t csr, i; + uint16_t wvalue, wlength; + uint8_t *s = usb.last_setup; + if (usb.has_pend_addr) { + sie_wr(S_FADDR, usb.pend_addr); + usb.has_pend_addr = 0; + } + sie_wr(S_INDEX, 0); + csr = sie_rd(S_CSR0); + if (csr & 0x04u) { /* SentStall */ + sie_wr(S_CSR0, 0); + usb.e0_tx = 0; +#if FELUCCA_CDC + cdc.e0_rx = 0; +#endif + return; + } + if (csr & 0x10u) { /* SetupEnd: the host abandoned the transfer */ + sie_wr(S_CSR0, 0x80); + usb.e0_tx = 0; +#if FELUCCA_CDC + cdc.e0_rx = 0; /* else the next SETUP is taken as line coding */ +#endif + } + if (usb.e0_tx) { + if (!(csr & 0x02u)) + e0_chunk(); + return; + } + if (!(csr & 0x01u)) + return; + fm1_usb_rx_sync(); +#if FELUCCA_CDC + if (cdc.e0_rx) { /* SET_LINE_CODING data stage */ + uint32_t n = sie_rd(S_COUNT0); + for (i = 0; i < 7u && i < n; i++) + cdc.line[i] = ep0buf[i]; + cdc.e0_rx = 0; + goto ack; + } +#endif + for (i = 0; i < 8u; i++) + s[i] = ep0buf[i]; + usb.setups++; + wvalue = (uint16_t)(s[2] | s[3] << 8); + wlength = (uint16_t)(s[6] | s[7] << 8); + switch ((uint32_t)s[0] << 8 | s[1]) { + case 0x0005: /* SET_ADDRESS */ + usb.pend_addr = s[2] & 0x7Fu; + usb.has_pend_addr = 1; + goto ack; + case 0x8006: { /* GET_DESCRIPTOR */ + const uint8_t *d; + uint16_t l; + if (get_desc(wvalue, &d, &l)) { + if (!wlength) + goto ack; + e0_send(d, l, wlength); + return; + } + goto stall; + } + case 0x0009: /* SET_CONFIGURATION: 0 or 1 only */ + if (s[2] > 1u) + goto stall; + usb.config = s[2]; + if (usb.config == 1u) + ep1_config(); + else + sie_wr(S_INTRRX1E, 0); + goto ack; + case 0x8008: + e0_send(&usb.config, 1, wlength); + return; + case 0x8000: + case 0x8100: + case 0x8200: + e0_send(zero2, 2, wlength); + return; + case 0x010B: /* SET_INTERFACE alt 0 */ + if (wvalue == 0) + goto ack; + goto stall; + case 0x810A: + e0_send(zero2, 1, wlength); + return; + case 0x0201: { /* CLEAR_FEATURE(ENDPOINT_HALT): data toggle reset */ +#if FELUCCA_CDC + uint32_t ep = s[4] & 0x0Fu, last = 3u; +#else + uint32_t ep = s[4] & 0x0Fu, last = 1u; +#endif + if (wvalue != 0 || ep > last) + goto stall; /* not an endpoint we have */ + if (ep) { /* (EP0 has no halt to clear) */ + sie_wr(S_INDEX, ep); + if (s[4] & 0x80u) + sie_wr(S_TXCSR1, 0x40); + else + sie_wr(S_RXCSR1, 0x80); + } + goto ack; + } +#if FELUCCA_CDC + case 0x2120: /* SET_LINE_CODING: 7 bytes follow */ + if (wlength) { + cdc.e0_rx = 1; + sie_wr(S_INDEX, 0); + sie_wr(S_CSR0, 0x40); /* ServicedRxPktRdy, no DataEnd yet */ + return; + } + goto ack; + case 0xA121: /* GET_LINE_CODING */ + e0_send(cdc.line, 7, wlength); + return; + case 0x2122: /* SET_CONTROL_LINE_STATE */ + cdc.dtr = s[2] & 1u; + goto ack; + case 0x2123: /* SEND_BREAK */ + goto ack; +#endif + default: + goto stall; + } +ack: + sie_wr(S_INDEX, 0); + sie_wr(S_CSR0, 0x48); + return; +stall: + sie_wr(S_INDEX, 0); + sie_wr(S_CSR0, 0x60); +} + +/* SysEx assembly: only short commands matter here */ +static void sysex_byte(uint8_t b) +{ + static const uint8_t UBOOT_KEY[6] = {0xF0, 0x22, 0x24, 0x35, 0x7D, 0xF7}; + if (b == 0xF0) { + usb.sx_on = 1; + usb.sx_len = 0; +#if FELUCCA_OTA + sx_collect = !sx_ready; + sx_pos = 0; +#endif + } + if (!usb.sx_on) + return; +#if FELUCCA_OTA + if (sx_collect && b != 0xF0 && b != 0xF7) { + if (sx_pos < sizeof sx_frame) + sx_frame[sx_pos++] = b; + else + sx_collect = 0; /* too long: not ours */ + } +#endif + if (usb.sx_len < sizeof usb.sysex) + usb.sysex[usb.sx_len++] = b; + if (b == 0xF7) { + uint32_t i, ok = usb.sx_len == 6u; + for (i = 0; ok && i < 6u; i++) + ok = usb.sysex[i] == UBOOT_KEY[i]; + if (ok) + usb.uboot_req = 1; +#if FELUCCA_OTA + else if (usb.sx_len == 6u && usb.sysex[1] == 0x22 && usb.sysex[2] == 0x24 && usb.sysex[3] == 0x35 && + usb.sysex[4] == 0x7F) + usb.ota_req = 1; + else if (sx_collect && sx_pos) { + sx_frame_len = sx_pos; + RING_PUBLISH(); + sx_ready = 1; /* main loop: ota_take() / ed_service() */ + } + sx_collect = 0; +#endif + usb.sx_on = 0; + } +} + +static void ep1_rx(void) +{ + uint32_t csr, n, i; + sie_wr(S_INDEX, 1); + csr = sie_rd(S_RXCSR1) | (sie_rd(S_RXCSR2) << 8); + if (!(csr & 1u)) + return; + n = sie_rd(S_RXCOUNT1) | (sie_rd(S_RXCOUNT2) << 8); + if (n > 64u) + n = 64u; + fm1_usb_rx_sync(); + for (i = 0; i + 3u < n; i += 4u) { + uint32_t cin = ep1rx[i] & 15u, pkt = (uint32_t)ep1rx[i] | (uint32_t)ep1rx[i + 1] << 8 | + (uint32_t)ep1rx[i + 2] << 16 | (uint32_t)ep1rx[i + 3] << 24; + if (cin >= 4u && cin <= 7u) { /* SysEx */ + uint32_t k, nb = cin == 4u || cin == 7u ? 3u : cin == 6u ? 2u : 1u; + for (k = 0; k < nb; k++) + sysex_byte(ep1rx[i + 1 + k]); + } else if (cin >= 8u && cin <= 0xEu && mi_w - mi_r < MQ) { + midi_in_q[mi_w % MQ] = pkt; + RING_PUBLISH(); + mi_w++; + } + } + usb.rx_pkts++; + csr = (csr & ~0x164u) | 0x10u; + sie_wr(S_RXCSR1, csr & 0xFFu); + sie_wr(S_RXCSR2, csr >> 8); +} + +#if FELUCCA_OTA +/* ---- SysEx frames for the main loop (ota.c / editor.c hooks; felucca.c and the + * update loader supply ota_now_ms / ota_idle) ---- */ +static uint32_t ota_now_ms(void); +static void ota_idle(void); + +static int ota_wire_send(const uint8_t *p, uint32_t n) /* F0..F7 -> USB-MIDI SysEx packets */ +{ + uint32_t i = 0, t0 = ota_now_ms(); + sx_busy = 1; + while (i < n) { + uint32_t k = n - i >= 3u ? 3u : n - i, pkt; + uint32_t cin = k == 3u && i + 3u < n ? 4u : k == 3u ? 7u : 4u + k; /* 4 continues; 5/6/7 end */ + pkt = cin | (uint32_t)p[i] << 8 | (k > 1u ? (uint32_t)p[i + 1] << 16 : 0u) | + (k > 2u ? (uint32_t)p[i + 2] << 24 : 0u); + while (so_w - so_r >= SXQ) { + if (!*(volatile uint8_t *)&usb.config || ota_now_ms() - t0 > 200u) { + sx_busy = 0; + return -1; + } + ota_idle(); + } + sx_out_q[so_w % SXQ] = pkt; + RING_PUBLISH(); + so_w++; + i += k; + } + sx_busy = 0; + return 0; +} +static int ota_frame_get(const uint8_t **p, uint32_t *n) +{ + if (!sx_ready) + return 0; + RING_PUBLISH(); /* read the frame only after the flag */ + *p = sx_frame; + *n = sx_frame_len; + return 1; +} +static void ota_frame_done(void) +{ + RING_PUBLISH(); /* done with the frame before the ISR may refill it */ + sx_ready = 0; +} +#endif + +static void ep1_tx(void) +{ + uint32_t csr, n = 0; +#if FELUCCA_OTA + if (mo_w == mo_r && so_w == so_r) + return; +#else + if (mo_w == mo_r) + return; +#endif + sie_wr(S_INDEX, 1); + csr = sie_rd(S_TXCSR1); + if (csr & 0x01u) + return; /* previous packet still pending */ + if (csr & 0x80u) + sie_wr(S_TXCSR1, csr & ~0x80u); +#if FELUCCA_OTA + while (so_r != so_w && n < 64u) { /* SysEx first, never split by notes */ + uint32_t pkt = sx_out_q[so_r % SXQ]; + ep1tx[n] = (uint8_t)pkt; + ep1tx[n + 1] = (uint8_t)(pkt >> 8); + ep1tx[n + 2] = (uint8_t)(pkt >> 16); + ep1tx[n + 3] = (uint8_t)(pkt >> 24); + n += 4u; + so_r++; + } + while (!sx_busy && so_r == so_w && mo_r != mo_w && n < 64u) { +#else + while (mo_r != mo_w && n < 64u) { +#endif + uint32_t pkt; + RING_PUBLISH(); /* the audio ISR (producer) can preempt us: */ + pkt = midi_out_q[mo_r % MQ]; /* slot read strictly between the index checks */ + ep1tx[n] = (uint8_t)pkt; + ep1tx[n + 1] = (uint8_t)(pkt >> 8); + ep1tx[n + 2] = (uint8_t)(pkt >> 16); + ep1tx[n + 3] = (uint8_t)(pkt >> 24); + n += 4u; + RING_PUBLISH(); + mo_r++; + } + if (!n) + return; + fm1_usb_ep_send(1, ep1tx, n); + sie_wr(S_TXCSR1, sie_rd(S_TXCSR1) | 0x01u); + usb.tx_pkts++; +} + +#if FELUCCA_CDC +static void ep3_rx(void) /* leaves the packet (NAK) while the ring is full */ +{ + uint32_t csr, n, i; + sie_wr(S_INDEX, 3); + csr = sie_rd(S_RXCSR1) | (sie_rd(S_RXCSR2) << 8); + if (!(csr & 1u)) { + cdc.rx_pend = 0; + return; + } + n = sie_rd(S_RXCOUNT1) | (sie_rd(S_RXCOUNT2) << 8); + if (n > 64u) + n = 64u; + if (CI_N - (ci_w - ci_r) < n) + return; /* rx_pend stays: retried next poll */ + cdc.rx_pend = 0; + fm1_usb_rx_sync(); + for (i = 0; i < n; i++) + cdc_in[(ci_w + i) % CI_N] = ep3rx[i]; + RING_PUBLISH(); + ci_w += n; + cdc.rx_pkts++; + csr = (csr & ~0x164u) | 0x10u; + sie_wr(S_RXCSR1, csr & 0xFFu); + sie_wr(S_RXCSR2, csr >> 8); +} + +static void ep3_tx(void) /* <= 63 bytes per packet: never needs a ZLP */ +{ + uint32_t csr, n = 0; + if (co_w == co_r) + return; + sie_wr(S_INDEX, 3); + csr = sie_rd(S_TXCSR1); + if (csr & 0x01u) + return; + if (csr & 0x80u) + sie_wr(S_TXCSR1, csr & ~0x80u); + while (co_r != co_w && n < 63u) + ep3tx[n++] = cdc_out[co_r++ % CO_N]; + fm1_usb_ep_send(3, ep3tx, n); + sie_wr(S_TXCSR1, sie_rd(S_TXCSR1) | 0x01u); + cdc.tx_pkts++; +} +#endif + +static void usb_poll(void) /* TIMER5 ISR, 2 kHz */ +{ + uint32_t iu, it, ir; + if (!usb.up) + return; + if (fm1_usb_sof_take()) { /* SOF pending: not a reliable "host is there", */ + /* it keeps firing with the cable out */ + usb.sof_seen++; + usb.no_sof = 0; + } else if (++usb.no_sof > usb.max_gap) { + usb.max_gap = usb.no_sof; + } + if (usb.config) { /* the frame number only advances with a real host */ + static uint32_t tick; + if (++tick >= 20u) { /* every 20 polls = 10 ms */ + uint16_t f; + tick = 0; + f = (uint16_t)(sie_rd(S_FRAME1) | (sie_rd(S_FRAME2) & 7u) << 8); + if (f != usb.frame) { + usb.frame = f; + usb.frame_same = 0; + usb.suspended = 0; + } else if (++usb.frame_same >= 10u && !usb.suspended) { /* 100 ms frozen: unplugged / host asleep */ + usb.suspended = 1; + usb.frame_stalls++; + } + } + } + iu = sie_rd(S_INTRUSB); +#ifdef FELUCCA_LOADER + it = sie_rd(S_INTRTX1) | sie_rd(S_INTRTX2) << 8; /* the update loader reads both */ + ir = sie_rd(S_INTRRX1) | sie_rd(S_INTRRX2) << 8; +#else + it = sie_rd(S_INTRTX1); /* EP0..7 only: skipping INTR*2 saves */ + ir = sie_rd(S_INTRRX1); /* 2 SIE round trips per poll */ +#endif + if (iu & 0x01u) { /* suspend: the bus went idle */ + usb.suspends++; + usb.suspended = 1; + } + if (iu & 0x02u) /* resume */ + usb.suspended = 0; + if (iu & 0x04u) { /* bus reset */ + usb.resets++; + sie_wr(S_FADDR, 0); + usb.config = 0; + usb.suspended = 0; + mo_r = mo_w; /* nothing stale for the next host */ + usb.sx_on = 0; +#if FELUCCA_OTA + so_r = so_w; + sx_collect = 0; +#endif + usb.e0_tx = 0; + usb.has_pend_addr = 0; +#if FELUCCA_CDC + cdc.dtr = 0; + cdc.e0_rx = 0; + cdc.rx_pend = 0; +#endif + fm1_usb_ep0_buf(ep0buf); + sie_wr(S_INTRUSBE, 0x07); + sie_wr(S_INTRTX1E, 0x01); + sie_wr(S_INTRRX1E, 0); + } + if (it & 0x01u) + ep0_service(); + if (ir & 0x02u) + ep1_rx(); + if (usb.config) + ep1_tx(); +#if FELUCCA_CDC + if (usb.config) { + if (ir & 0x08u) + cdc.rx_pend = 1; + if (cdc.rx_pend) /* not every poll: 3 SIE round trips each */ + ep3_rx(); + if (cdc.dtr) + ep3_tx(); + } +#endif +} + +static void usb_start(void) /* boot, or main-loop retry while usb.up == 0 */ +{ + usb.timeouts = 0; + fm1_usb_reset(); /* reset whatever the ROM left */ + fm1_delay_ms(25); + fm1_usb_attach(ep0buf); + sie_wr(S_POWER, 0x60); + sie_wr(S_INTRUSBE, 0x07); /* suspend, resume, reset (polled) */ + sie_wr(S_INTRTX1E, 0x01); + sie_wr(S_INTRTX2E, 0); + sie_wr(S_INTRRX1E, 0); + sie_wr(S_INTRRX2E, 0); + fm1_usb_ep_enable(0x1Fu); + usb.up = usb.timeouts < 3u; /* a dead SIE leaves USB off */ +} + +/* Powered on without a cable, the SIE does not answer and usb_start leaves + * USB off: retry once a second from the main loop so a cable plugged in + * later still enumerates. */ +static void usb_retry(uint32_t now_ms) +{ + static uint32_t t; + if (usb.up || usb.detached || now_ms - t < 1000u) + return; + t = now_ms; + usb.retries++; + usb_start(); +} + +static void usb_detach(void) +{ + usb.detached = 1; + usb.up = 0; + fm1_usb_off(); +} diff --git a/firmware/src/voice.c b/firmware/src/voice.c new file mode 100644 index 0000000..c432689 --- /dev/null +++ b/firmware/src/voice.c @@ -0,0 +1,577 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* Voice allocation, envelopes, LFO and per-track rendering. Runs in the + * audio ISR. + * + * Each synth part has its own NVOICE voices (so MONO / LEGATO / UNISON keep using + * v[0..]), but only NVOICE of all the parts' voices sound at once: a part that starts + * a voice while the budget is full takes one from any part (voice_victim): the oldest + * released voice, else the oldest extra UNISON voice, else the oldest held voice of a + * POLY part that is not its lowest note. A voice taken from another part fades out + * over one block (stage 4: the envelope goes to 0, the block's amplitude ramp + * declicks it); one of the part's own is restarted in place. Extra UNISON + * voices only start when there is room. The drum track has its own voices (drums.c). */ +static uint32_t vage; /* voice ages: one clock for every part */ +/* engines that play recorded material (a position, not a phase): no phases kept or spread */ +#if FELUCCA_SLICE +static int eng_sampled(const engine_t *e) { return e == &ENG_SAMPLE || e == &ENG_SLICE; } +#else +static int eng_sampled(const engine_t *e) { return e == &ENG_SAMPLE; } +#endif +static int32_t lfo_wave(track_t *t, uint32_t ph) +{ + switch (t->p[P_LWAVE]) { + case 1: + return osc_tri(ph); + case 2: + return (int32_t)(ph >> 16) - 32768; + case 3: + return ph < 0x80000000u ? 32767 : -32767; + case 4: + return (int32_t)(t->lfo_rnd >> 16) - 32768; + default: + return osc_sine(ph); + } +} + +static void track_lfo_tick(track_t *t) +{ + uint32_t old = t->lfo_ph; + t->lfo_ph += LFO_INC[t->p[P_LRATE] & 127]; + if (t->lfo_ph < old) + t->lfo_rnd = rng(); + t->lfo_val = lfo_wave(t, t->lfo_ph); + if (t->lfo_fade < 32767) { + int32_t step = (int32_t)(ENV_LIN[t->p[P_LFADE] & 127] >> 9); + t->lfo_fade = t->p[P_LFADE] ? clamp(t->lfo_fade + (step ? step : 1), 0, 32767) : 32767; + } +} + +/* voices the engine may use (POLY and UNISON): its cap, else all of them */ +static uint32_t trk_nvoice(const track_t *t) +{ + uint32_t c = ENGINES[t->engine]->poly; + return c && c < NPOLY ? c : NPOLY; +} + +/* ------------------------------------------------- the shared voice budget --- */ +static uint32_t voices_busy(void) /* sounding voices of all parts (not the fading ones) */ +{ + uint32_t p, i, n = 0; + for (p = 0; p < NPART; p++) + for (i = 0; i < NVOICE; i++) + n += trk[p].v[i].active && trk[p].v[i].stage != 4u; + return n; +} + +static uint32_t lowest_held(const track_t *t) /* index of the lowest held note (the bass), NVOICE = none */ +{ + uint32_t i, low = NVOICE; + for (i = 0; i < NVOICE; i++) + if (t->v[i].active && t->v[i].gate && (low == NVOICE || t->v[i].note < t->v[low].note)) + low = i; + return low; +} + +/* the voice to give up for a new one (see the top); soft: only released voices and + * extra UNISON voices of other parts. Returns its index, *pp its part; NVOICE = none */ +static uint32_t voice_victim(const track_t *self, int soft, track_t **pp) +{ + uint32_t p, i, best = NVOICE, cat = 4; + for (p = 0; p < NPART; p++) { + track_t *t = &trk[p]; + uint32_t mode = (uint32_t)t->p[P_VOICE], nu = mode == V_UNISON ? trk_nvoice(t) : 1u; + uint32_t low = mode == V_POLY ? lowest_held(t) : NVOICE; + if (soft && t == self) + continue; + for (i = 0; i < NVOICE; i++) { + const voice_t *v = &t->v[i]; + uint32_t c; + if (!v->active || v->stage == 4u) + continue; + if (!v->gate) + c = 1; /* released */ + else if (mode == V_UNISON && i > 0 && i < nu) + c = 2; /* an extra UNISON voice */ + else if (!soft && mode == V_POLY && i != low) + c = 3; /* held, not the bass */ + else + continue; + if (c < cat || (c == cat && v->age < (*pp)->v[best].age)) { + cat = c; + best = i; + *pp = t; + } + } + } + return best; +} + +static uint32_t voice_kills; /* voices given up (budget, overload): console, hostsim */ +#define KILL_BLOCKS 2u /* 1.5 ms: no click on a bass, little extra load */ +static void voice_kill(voice_t *v) /* fade out over the next blocks (env_tick stage 4) */ +{ + v->gate = 0; + if (v->stage != 4u) + v->kill = KILL_BLOCKS; + v->stage = 4; + voice_kills++; +} + +/* the budget is full: free a voice for part t. 0 = nothing to take (soft) */ +static int voice_room(track_t *t, int soft) +{ + track_t *vp = 0; + uint32_t k; + if (voices_busy() < NVOICE) + return 1; + k = voice_victim(t, soft, &vp); + if (k == NVOICE) + return !soft; /* hard: over the budget (cannot happen with 3 parts) */ + voice_kill(&vp->v[k]); + return 1; +} + +/* POLY allocation (within the engine's voice cap). Same note: reuse its voice. Else a free voice: ROTATE takes + * the next one round-robin (release tails ring out), REUSE (or any GLIDE) takes + * the free voice whose last pitch is closest, so poly portamento moves each + * voice the shortest way. Steal: the oldest released voice, else the oldest + * held one, never the lowest held note (the bass). A free voice needs room in the + * shared budget: when the voice to give up is one of this part's, it is restarted + * in place instead. */ +static voice_t *voice_alloc(track_t *t, uint32_t note) +{ + uint32_t i, np = trk_nvoice(t), best = np, low = np, nfree = 0; + int32_t bd = 0x7FFFFFFF; + for (i = 0; i < np; i++) { + if (t->v[i].active && t->v[i].note == note) + return &t->v[i]; + nfree += !t->v[i].active; + } + if (nfree && voices_busy() >= NVOICE) { + track_t *vp = 0; + uint32_t k = voice_victim(t, 0, &vp); + if (k < np && vp == t) + return &t->v[k]; /* our own: restart it in place (no click) */ + if (k < NVOICE) + voice_kill(&vp->v[k]); + } + if (t->p[P_ALLOC] || t->p[P_GLIDE]) { + for (i = 0; i < np; i++) { + int32_t d = t->v[i].pitch_cur - (int32_t)note * 16; + if (t->v[i].active) + continue; + d = d < 0 ? -d : d; + if (!t->v[i].pitch_cur) + d = 0x7FFFFFF0; /* never played: last choice */ + if (d < bd) { + bd = d; + best = i; + } + } + } else { + for (i = 0; i < np && best == np; i++) { + uint32_t k = (t->rr + i) % np; + if (!t->v[k].active) + best = k; + } + t->rr = (uint8_t)((best == np ? t->rr : best) + 1u) % np; + } + if (best < np) + return &t->v[best]; + for (i = 0; i < np; i++) /* the lowest held note is protected */ + if (t->v[i].gate && (low == np || t->v[i].note < t->v[low].note)) + low = i; + for (i = 0; i < np; i++) /* oldest released (not one fading out for another part) */ + if (!t->v[i].gate && t->v[i].stage != 4u && (best == np || t->v[i].age < t->v[best].age)) + best = i; + if (best == np) + for (i = 0; i < np; i++) /* oldest held, not the bass */ + if (i != low && (best == np || t->v[i].age < t->v[best].age)) + best = i; + return &t->v[best == np ? 0 : best]; +} + +/* glide, in 1/4096 semitone a control tick (pitch_cur . pitch_frac): RATE = GLIDE is the time an octave + * takes (any interval at that speed), TIME = GLIDE is the time of any glide. A sequencer SLIDE with + * GLIDE 0 glides in SLIDE_T (TIME), as an acid slide */ +#define SLIDE_T 54 /* TIME_MS index: ~50 ms */ +static int32_t glide_ticks(int32_t g) /* control ticks of TIME_MS index g */ +{ + int32_t k = (int32_t)ENV_LIN[g & 127]; + return k ? (int32_t)((1u << 24) / (uint32_t)k) : 1; +} +static void glide_set(track_t *t, voice_t *v, int glide) +{ + int32_t d, ticks; + if (!glide || !v->pitch_cur) { + v->pitch_cur = v->pitch16; + v->pitch_frac = 0; + v->gstep = 0; + return; + } + if (t->p[P_GLMODE] || !t->p[P_GLIDE]) { + d = (v->pitch16 << 8) - ((v->pitch_cur << 8) + v->pitch_frac); + d = d < 0 ? -d : d; + ticks = glide_ticks(t->p[P_GLIDE] ? t->p[P_GLIDE] : SLIDE_T); + v->gstep = d / ticks > 0 ? d / ticks : 1; + } else { + v->gstep = 0; + } +} + +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]; + int sounding = v->active && v->stage != 0; + uint32_t ph0 = v->ph[0], ph1 = v->ph[1], ph2 = v->ph[2]; + int32_t s0 = v->s[0], s1 = v->s[1], s4 = v->s[4], s5 = v->s[5], s6 = v->s[6], s7 = v->s[7]; + v->note = (uint8_t)note; + v->vel = (uint8_t)vel; + v->gate = 1; + v->active = 1; + v->stage = 1; + v->age = ++vage; + v->pitch16 = (int32_t)note * 16; + glide_set(t, v, glide); + v->penv = 32767; /* the pitch envelope starts over (not on legato) */ + if (!sounding) { + v->env = 0; + v->env_out = 0; + } /* sounding: the attack starts from the current level */ + e->note_on(t, v); + if (sounding && !eng_sampled(e)) { /* retrigger / steal: keep phases and filter states */ + v->ph[0] = ph0; /* (resetting them clicks) */ + v->ph[1] = ph1; + v->ph[2] = ph2; + if (e == &ENG_ANALOG) { + v->s[0] = s0; + v->s[1] = s1; + } else if (e == &ENG_DIGITAL) { + v->s[5] = s5; + v->s[6] = s6; + v->s[7] = s7; /* op 4 phase; the modulator envelope restarts */ + } else if (e == &ENG_LOFI) { + v->s[0] = s0; + v->s[4] = s4; + } + } +} + +/* 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) +{ + uint32_t mode = (uint32_t)t->p[P_VOICE], nv = mode == V_UNISON ? trk_nvoice(t) : 1u, i; + for (i = 0; i < nv; i++) { + voice_t *v = &t->v[i]; + int32_t k = 2 * (int32_t)i - (int32_t)(nv - 1u); /* -7 .. 7 */ + if (nv > 1u && nv < NVOICE) + k = k * (NVOICE - 1) / (int32_t)(nv - 1u); /* fewer voices: the outer ones as wide */ + v->fine = nv > 1u ? k * t->p[P_DETUNE] * 56 / 889 : 0; /* up to ~±40 cents */ + if (retrig || !v->active || !v->gate) { + if ((!v->active || v->stage == 4u) && !voice_room(t, i > 0)) + 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])) { /* random start phases: */ + static uint32_t seed = 0x1234567u; /* in phase they stack, evenly spread they cancel */ + seed = seed * 1664525u + 1013904223u; + v->ph[0] += seed; + } + } else { /* legato: new pitch, same envelope */ + v->note = (uint8_t)note; + v->pitch16 = (int32_t)note * 16; + if (vel > v->vel && nv == 1u) + v->vel = (uint8_t)vel; + glide_set(t, v, glide); + } + } + t->mono_note = (uint8_t)note; +} + +/* the note the mono stack asks for (PRIO: LAST / LOW / HIGH), 0 = none */ +static uint32_t mono_pick(const track_t *t) +{ + uint32_t i, n; + if (!t->nmono) + return 0; + n = t->mono_stack[t->nmono - 1u]; + for (i = 0; i < t->nmono; i++) { + if (t->p[P_PRIO] == 1 && t->mono_stack[i] < n) + n = t->mono_stack[i]; + if (t->p[P_PRIO] == 2 && t->mono_stack[i] > n) + n = t->mono_stack[i]; + } + return n; +} + +static void mono_remove(track_t *t, uint32_t note) +{ + uint32_t j, k = 0; + for (j = 0; j < t->nmono; j++) + if (t->mono_stack[j] != note) + t->mono_stack[k++] = t->mono_stack[j]; + t->nmono = (uint8_t)k; +} + +static void trk_note_on(track_t *t, uint32_t note, uint32_t vel) +{ + uint32_t any = 0, i, mode = (uint32_t)t->p[P_VOICE]; + if (trk_silent(t)) + return; /* MUTE, or another track soloed */ + if (is_drum(t)) { /* the drum track: GM drums (drums.c) */ + drum_on(note, vel); + return; + } + if (t->xf_on || t->eng_req != t->engine) { /* engine switch under way: after the fade */ + for (i = 0; i < t->xp_n && t->xp_note[i] != note; i++) + ; + if (i == t->xp_n && t->xp_n < 4u) + t->xp_n++; + i = i < t->xp_n ? i : t->xp_n - 1u; /* (full: the last one is replaced) */ + t->xp_note[i] = (uint8_t)note; + t->xp_vel[i] = (uint8_t)vel; + return; + } + for (i = 0; i < NVOICE; i++) + any |= t->v[i].gate; + if (!any) { /* fresh phrase: LFO retrigger and fade */ + t->lfo_ph = (uint32_t)t->p[P_LPHASE] << 25; + t->lfo_fade = 0; + } + if (mode == V_POLY) { + voice_t *v = voice_alloc(t, note); + t->nmono = 0; /* no stale mono stack after a mode change */ + t->mono_note = 0; + v->fine = 0; + voice_start(t, v, note, vel, t->p[P_GLIDE] != 0); + return; + } + { + uint32_t sounding = t->mono_note && t->v[0].active && t->v[0].gate, want; + mono_remove(t, note); + if (t->nmono >= 8u) + mono_remove(t, t->mono_stack[0]); + t->mono_stack[t->nmono++] = (uint8_t)note; + want = mono_pick(t); + if (sounding && want == t->mono_note) + return; /* LOW / HIGH priority: this key does not win */ + if (mode == V_MONO) /* MONO: always retrigger, glide when GLIDE is set */ + mono_play(t, want, vel, 1, t->p[P_GLIDE] != 0 || t->slide_glide); + else /* LEGATO / UNISON: glide only between held notes */ + mono_play(t, want, vel, !sounding, sounding && (t->p[P_GLIDE] != 0 || t->slide_glide)); + } +} + +static void trk_note_off(track_t *t, uint32_t note) +{ + uint32_t i, k = 0, mode = (uint32_t)t->p[P_VOICE]; + if (is_drum(t)) + return; /* one-shots */ + for (i = 0; i < t->xp_n; i++) /* not sounding yet (engine switch): forget it */ + if (t->xp_note[i] != note) { + t->xp_note[k] = t->xp_note[i]; + t->xp_vel[k++] = t->xp_vel[i]; + } + t->xp_n = (uint8_t)k; + if (mode != V_POLY) { + uint32_t nv = mode == V_UNISON ? trk_nvoice(t) : 1u; + mono_remove(t, note); + if (t->mono_note == note) { + uint32_t next = mono_pick(t); + if (next) { /* fall back to a held note, legato */ + mono_play(t, next, t->v[0].vel, 0, t->p[P_GLIDE] != 0); + } else { + for (i = 0; i < nv; i++) + if (t->v[i].gate) { + t->v[i].gate = 0; + t->v[i].stage = 3; + } + t->mono_note = 0; + } + } + } + for (i = 0; i < NVOICE; i++) /* POLY voices (also ones left from another mode: */ + if (t->v[i].note == note && t->v[i].gate && /* VOICE changed while they were held) */ + (mode == V_POLY || i >= (mode == V_UNISON ? trk_nvoice(t) : 1u) || t->mono_note != note)) { + t->v[i].gate = 0; + t->v[i].stage = 3; + } +} + +static void trk_all_off(track_t *t) +{ + uint32_t i; + for (i = 0; i < NVOICE; i++) { + t->v[i].gate = 0; + t->v[i].stage = t->v[i].active ? 3 : 0; + } + t->nmono = 0; + t->mono_note = 0; + t->xp_n = 0; +} + +/* engine switch, at each block start (events_block), before any note of the block. The UI writes + * eng_req and the new engine's P_E0..P_E7 together (IRQ off). The part's sounding voices (released by + * the preset change) then fade out over XF_BLOCKS blocks on the old engine, rendered with its own + * parameters (pe_old: an engine never reads another engine's values, which index its tables); only + * then the engine switches and the notes that came during the fade start on it. A part with nothing + * sounding switches at once. */ +#define XF_BLOCKS 4u /* 4 x 32 samples: 2.9 ms */ +static void engine_block(track_t *t) +{ + uint32_t i, any = 0; + if (t->xf_on || t->eng_req != t->engine) { + if (!t->xf_on) { + for (i = 0; i < NVOICE; i++) + any |= t->v[i].active; + if (any) { + t->xf_on = 1; + t->xf = XF_BLOCKS; + return; + } + } else if (t->xf) { + return; /* still fading (track_render counts down) */ + } + for (i = 0; i < NVOICE; i++) { /* faded to 0: gone */ + voice_t *v = &t->v[i]; + v->active = v->gate = 0; + v->stage = 0; + v->env = v->env_out = 0; + } + t->engine = t->eng_req % NENGINES; + t->xf_on = 0; + t->nmono = 0; + t->mono_note = 0; + { + uint32_t n = t->xp_n; + t->xp_n = 0; + for (i = 0; i < n; i++) + trk_note_on(t, t->xp_note[i], t->xp_vel[i]); + } + } + for (i = 0; i < 8u; i++) /* the engine's own values, for a later fade */ + t->pe_old[i] = t->p[P_E0 + i]; +} + +/* one control tick (CTL samples) of the amplitude envelope; returns Q15 */ +static int32_t env_tick(track_t *t, voice_t *v) +{ + const int16_t *p = t->p; + int32_t sus = (int32_t)p[P_SUS] << 17; /* Q24 */ + switch (v->stage) { + case 1: + v->env += (int32_t)ENV_LIN[p[P_ATK] & 127]; + if (v->env >= (1 << 24)) { + v->env = 1 << 24; + v->stage = 2; + } + break; + case 2: + v->env += mulq16(sus - v->env, ENV_EXP[p[P_DEC] & 127]); + break; + case 3: + v->env -= mulq16(v->env, ENV_EXP[p[P_REL] & 127]); + if (v->env < (1 << 12)) { + v->env = 0; + v->stage = 0; + v->active = 0; + } + break; + case 4: /* given up for another part: faded out over KILL_BLOCKS */ + if (v->kill > 1u) { + v->env -= v->env / v->kill; + v->kill--; + } else { + v->env = 0; + v->stage = 0; + v->active = 0; + v->kill = 0; + } + break; + default: + v->env = 0; + break; + } + return v->env >> 9; +} + +/* render one block of a part into out (cleared here); returns the voices rendered */ +static uint32_t track_render(track_t *t, int32_t *out, uint32_t n) +{ + const engine_t *e = ENGINES[t->engine]; + const int16_t *p = t->p; + uint32_t i; + int32_t lfo = mulq15(t->lfo_val, t->lfo_fade); + /* TUNE in cents: whole 1/16 semitones in the pitch, the rest as a fine factor (no dead zone) */ + int32_t tune = song.g[G_TUNE] >= 0 ? song.g[G_TUNE] * 16 / 100 : -((-song.g[G_TUNE] * 16 + 99) / 100); + int32_t tune_fine = (song.g[G_TUNE] * 16 - tune * 100) * 2367 / 16000; /* rest, in 1/4096 (1 ct = 2.367) */ + uint32_t nr = 0, fade = t->xf_on && t->xf; + int16_t pe_new[8]; + for (i = 0; i < n; i++) + out[i] = 0; + if (fade) /* engine switch: the old engine, its own values */ + for (i = 0; i < 8u; i++) { + pe_new[i] = t->p[P_E0 + i]; + t->p[P_E0 + i] = t->pe_old[i]; + } + track_lfo_tick(t); + if (e->block) /* the engine's per-part work (DRAWBAR: bars, rotor) */ + e->block(t); + for (i = 0; i < NVOICE; i++) { + voice_t *v = &t->v[i]; + vmod_t m; + int32_t env, pitch; + if (!v->active) + continue; + { + env = env_tick(t, v); + if (e->amp) /* the engine's own amplitude curve */ + env = e->amp(t, v, env); + m.envq15 = env; + m.amp1 = mulq15(env, v->vel * 258); + if (p[P_LD_AMP]) + m.amp1 = mulq15(m.amp1, 32767 - mulq15((lfo + 32768) >> 1, p[P_LD_AMP] * 258)); + if (fade) /* linear to 0 over the fade */ + m.amp1 = m.amp1 * (int32_t)(t->xf - 1u) / (int32_t)XF_BLOCKS; + m.amp0 = v->env_out; + v->env_out = m.amp1; + } + if (v->pitch_cur != v->pitch16 || v->pitch_frac) { /* glide, in 1/4096 semitone */ + int32_t q = (v->pitch_cur << 8) + v->pitch_frac, d = (v->pitch16 << 8) - q; + int32_t st = v->gstep ? v->gstep : (int32_t)((ENV_LIN[p[P_GLIDE] & 127] * 3u) >> 10); /* RATE: an octave in GLIDE */ + if (st < 1) + st = 1; + q += d > 0 ? (d < st ? d : st) : (-d < st ? d : -st); + v->pitch_cur = q >> 8; + v->pitch_frac = (uint8_t)(q & 255); + } + if (v->penv) /* the pitch envelope: ~40 ms */ + v->penv = (int16_t)(v->penv - ((v->penv * 590 + 32767) >> 15)); + if (!env && !m.amp0 && v->stage == 2 && !eng_sampled(e)) + continue; /* held at a silent sustain (SUS 0): nothing to render */ + { /* the pitch in 1/4096 semitone: glide, LFO, the pitch envelope; the fraction goes into the increment */ + int32_t q = (v->pitch_cur << 8) + v->pitch_frac + ((lfo * p[P_LD_PIT] * 3) >> 7) + + ((v->penv * p[P_ED_PIT] * 3) >> 7); + pitch = (q >> 8) + tune; + m.pitch16 = clamp(pitch, 0, 2047); + m.inc = PITCH_INC[m.pitch16]; + q = (q & 255) * 3792 >> 16; /* the fraction, as fine (1/16 st = 14.8) */ + if (v->fine + tune_fine + q) /* unison detune, fine tune and the fraction */ + m.inc += (uint32_t)((int32_t)(m.inc >> 12) * (v->fine + tune_fine + q)); + } + m.cutoff = ((lfo * p[P_LD_FLT]) >> 7) + ((m.envq15 * p[P_ED_FLT]) >> 7); + if (v->vel > 110) /* accent opens the filter with the env */ + m.cutoff += (m.envq15 * 24) >> 7; + m.shape = (64 << 8) + ((lfo * p[P_LD_SHP]) >> 7) + ((m.envq15 * p[P_ED_SHP]) >> 7); + e->render(t, v, out, n, &m); + nr++; + } + if (fade) { + for (i = 0; i < 8u; i++) + t->p[P_E0 + i] = pe_new[i]; + t->xf--; + } + return nr; +} diff --git a/tests/arranger_test.c b/tests/arranger_test.c new file mode 100644 index 0000000..eebc6d0 --- /dev/null +++ b/tests/arranger_test.c @@ -0,0 +1,47 @@ +/* SPDX-License-Identifier: GPL-3.0-only */ +#include +#include +#include "../firmware/src/arranger.h" + +int main(void) +{ + arr_config_t c; + arr_clock_t r; + unsigned long samples; + unsigned transitions = 0; + int event; + arr_defaults(&c); + assert(!arr_valid(&c, 7)); /* missing drum/scene slot cannot silently play */ + assert(arr_begin(&r, &c, 7) == ARR_INVALID && !r.running); + c.count = 3; + c.entry[0] = (arr_entry_t){0, 1}; + c.entry[1] = (arr_entry_t){2, 2}; + c.entry[2] = (arr_entry_t){0, 1}; /* repeated scenes are valid */ + assert(arr_begin(&r, &c, 5) == 0); + /* 137 BPM has a fractional samples-per-bar: transitions must never drift + * by more than one 32-sample audio block, even over multiple sections. */ + for (samples = 0; r.running; samples += 32) { + event = arr_next(&r, &c, 44118); + if (event != ARR_NONE) { + unsigned bars = transitions == 0 ? 1 : transitions == 1 ? 3 : 4; + double expected = 44118.0 * 240.0 * bars / 137.0; + assert(samples >= expected && samples - expected < 32.0); + assert(event == (transitions == 0 ? 2 : transitions == 1 ? 0 : ARR_DONE)); + transitions++; + } + arr_elapse(&r, 32, 137); + } + assert(transitions == 3); + c.count = 1; c.entry[0].bars = 1; c.loop = 1; + assert(arr_begin(&r, &c, 1) == 0); + arr_elapse(&r, 44118, 120); /* half bar at 120 BPM */ + assert(arr_next(&r, &c, 44118) == ARR_NONE); + arr_elapse(&r, 88236, 60); /* tempo change preserves musical position */ + assert(arr_next(&r, &c, 44118) == 0 && r.running); + c.entry[0].bars = 0; assert(!arr_valid(&c, 15)); + c.entry[0].bars = 65; assert(!arr_valid(&c, 15)); + c.entry[0].bars = 1; c.entry[0].scene = 4; assert(!arr_valid(&c, 15)); + c.entry[0].scene = 0; c.count = 17; assert(!arr_valid(&c, 15)); + puts("arranger: order, repeats, stop, loop, tempo change, fractional timing and invalid scenes PASS"); + return 0; +} diff --git a/tests/cpu_baseline.txt b/tests/cpu_baseline.txt new file mode 100644 index 0000000..79f67b9 --- /dev/null +++ b/tests/cpu_baseline.txt @@ -0,0 +1,59 @@ +# FELUCCA host CPU baseline (tests/regress.c): instructions per 44.1 kHz sample, cc -O2 on +# the Mac (kernel-counted, ~1 % run to run). The check allows +25 %. Rewritten by BUDGET_UPDATE=1. +cpu/ANALOG/00_SAW_LEAD 1202 +cpu/ANALOG/01_SOFT_PAD 1106 +cpu/ANALOG/02_SQR_BASS 1436 +cpu/ANALOG/03_PWM_STR 1259 +cpu/ANALOG/04_ACID 1247 +cpu/ANALOG/05_SINE_KEY 1020 +cpu/ANALOG/06_RAVE 1461 +cpu/ANALOG/07_SUB_BASS 1170 +cpu/ANALOG/08_PLUCK 1043 +cpu/ANALOG/09_BRASS 1203 +cpu/ANALOG/10_WIND 1126 +cpu/ANALOG/11_STRINGS 1042 +cpu/DIGITAL/00_E.PIANO 971 +cpu/DIGITAL/01_BELL 967 +cpu/DIGITAL/02_BASS 958 +cpu/DIGITAL/03_BRASS 963 +cpu/DIGITAL/04_ORGAN 1011 +cpu/DIGITAL/05_PAD 1004 +cpu/DIGITAL/06_MARIMBA 966 +cpu/DIGITAL/07_FUNK_KEY 971 +cpu/PHASE/00_BRASS 902 +cpu/PHASE/01_ORGAN 963 +cpu/PHASE/02_STRING 1311 +cpu/PHASE/03_RESO 1113 +cpu/PHASE/04_BELL 1114 +cpu/PHASE/05_WIRE 1558 +cpu/LOFI/00_PULSE_LD 710 +cpu/LOFI/01_WAVE_BASS 653 +cpu/LOFI/02_ARP_8BIT 706 +cpu/LOFI/03_WAVE_LEAD 807 +cpu/LOFI/04_STEP_LEAD 311 +cpu/SAMPLE/00_PIANO 617 +cpu/SAMPLE/01_TRANH 589 +cpu/SAMPLE/02_FLUTE 785 +cpu/SAMPLE/03_SAX 907 +cpu/SAMPLE/04_PERC 359 +cpu/VOICE/00_CHOIR_AAH 975 +cpu/VOICE/01_VOX_LEAD 969 +cpu/VOICE/02_WOW_BASS 965 +cpu/VOICE/03_WHISPER 954 +cpu/TRIO/00_FAT_BASS 1322 +cpu/TRIO/01_ARP_LEAD 1316 +cpu/TRIO/02_SYNC_LEAD 1241 +cpu/TRIO/03_RING_BELL 1199 +cpu/TRIO/04_CHIP_CHOIR 1478 +cpu/WHEEL/00_FULL_ORGAN 1418 +cpu/WHEEL/01_JAZZ_PERC 952 +cpu/WHEEL/02_GOSPEL 1036 +cpu/WHEEL/03_SOFT_FLUTE 692 +cpu/WHEEL/04_ROCK_DRIVE 1243 +cpu/GRAIN/00_CLOUD_PAD 849 +cpu/GRAIN/01_GLITCH 674 +cpu/GRAIN/02_FROZEN 846 +cpu/GRAIN/03_SHIMMER 906 +cpu/mix/idle 286 +cpu/mix/idle_drums 495 +cpu/mix/3parts_full_drums 1566 diff --git a/tests/drumkit_test.c b/tests/drumkit_test.c new file mode 100644 index 0000000..1b5c91a --- /dev/null +++ b/tests/drumkit_test.c @@ -0,0 +1,109 @@ +/* SPDX-License-Identifier: GPL-3.0-only */ +/* Synthesised drum kits (drum_synth.c): every kit x every sound is bounded, audible and + * ends; the level of each kit stays near the sampled kit; the host cost of 6 synth voices. + * argv[1]: a WAV demo (each kit plays one bar), argv[2]: a per-kit report. */ +#define main hostsim_main +#include "hostsim.c" +#undef main +#include +static const uint8_t DS_NOTE[DS_LANES] = {36, 38, 39, 42, 46, 43, 48, 49, 51, 70, 63, 37, 56, 75}; /* one GM note per synth lane */ +static uint32_t one_hit(uint32_t kit, uint32_t note, int32_t *peak, uint64_t *energy) +{ + uint32_t j, k, blocks = 0; + int32_t l[CTL], r[CTL], rv[CTL]; + memset(&drums, 0, sizeof drums); + drums.set = -2; + TDRUM->p[P_E0] = (int16_t)kit; + song.g[G_DRLVL] = 100; + drum_on(note, 110); + *peak = 0; + *energy = 0; + for (j = 0; j < FS * 6u / CTL; j++) { + memset(l, 0, sizeof l), memset(r, 0, sizeof r), memset(rv, 0, sizeof rv); + drums_render(l, r, rv, CTL); + for (k = 0; k < CTL; k++) { + int32_t a = l[k] < 0 ? -l[k] : l[k]; + assert(a < 131072); + if (a > *peak) *peak = a; + *energy += (uint64_t)a; + } + blocks++; + for (k = 0; k < NDRUM && !drums.v[k].active; k++) + ; + if (k == NDRUM) + break; + } + return blocks; +} + +int main(int argc, char **argv) +{ + uint32_t kit, lane, j, k; + int32_t peak, ref_peak = 0; + uint64_t e; + FILE *rep = argc > 2 ? fopen(argv[2], "w") : stdout; + host_tracks_init(); + one_hit(0, 36, &ref_peak, &e); /* the sampled kick */ + for (kit = DRUM_SAMPLED; kit < DRUM_KITS; kit++) { + int32_t kpk = 0; + fprintf(rep, "%-8s %-12s", DRUM_KIT_NAMES[kit], DRUM_KIT_STYLES[kit]); + for (lane = 0; lane < DS_LANES; lane++) { + uint32_t b = one_hit(kit, DS_NOTE[lane], &peak, &e); + assert(b < FS * 6u / CTL); /* every sound ends */ + assert(peak > 600); /* and is heard */ + if (peak > kpk) kpk = peak; + fprintf(rep, " %5d/%4ums", peak, b * CTL * 1000u / FS); + } + fprintf(rep, "\n"); + assert(kpk < ref_peak * 3 && kpk > ref_peak / 4); /* near the sampled kit */ + } + { /* cost: 6 synth voices (open hat, crash, ride, kick, snare, clap) vs 6 sampled ones */ + int32_t l[CTL], r[CTL], rv[CTL]; + struct timespec t0, t1; + double ns_s, ns_y; + for (k = 0; k < 2u; k++) { + uint32_t rep_n = 2000; + memset(&drums, 0, sizeof drums); + drums.set = -2; + TDRUM->p[P_E0] = (int16_t)(k ? DRUM_SAMPLED + 1u : 0u); + clock_gettime(CLOCK_MONOTONIC, &t0); + for (j = 0; j < rep_n; j++) { + if (j % 100u == 0u) { + static const uint8_t N[6] = {46, 49, 51, 36, 38, 39}; + uint32_t q; + for (q = 0; q < 6u; q++) drum_on(N[q], 100); + } + drums_render(l, r, rv, CTL); + } + clock_gettime(CLOCK_MONOTONIC, &t1); + *(k ? &ns_y : &ns_s) = ((t1.tv_sec - t0.tv_sec) * 1e9 + (t1.tv_nsec - t0.tv_nsec)) / (rep_n * (double)CTL); + } + fprintf(rep, "cost: 6 voices sampled %.1f ns/sample, synthesised %.1f ns/sample (host)\n", ns_s, ns_y); + } + if (argc > 1) { /* demo: each kit, one bar: K . H . S . H . K K H . S . H O */ + static const uint8_t P[16][3] = {{36, 42, 0}, {0}, {42, 0}, {0}, {38, 42, 0}, {0}, {42, 0}, {70, 0}, + {36, 42, 0}, {36, 0}, {42, 0}, {37, 0}, {38, 39, 0}, {0}, {42, 63, 0}, {46, 0}}; + uint32_t step = FS * 60u / 120u / 4u, total = (DRUM_KITS - DRUM_SAMPLED) * 16u * step; + FILE *f = fopen(argv[1], "wb"); + int32_t l[CTL], r[CTL], rv[CTL]; + wav_hdr(f, total / CTL * CTL); + memset(&drums, 0, sizeof drums); + drums.set = -2; + for (kit = DRUM_SAMPLED; kit < DRUM_KITS; kit++) { + TDRUM->p[P_E0] = (int16_t)kit; + for (j = 0; j < 16u; j++) { + uint32_t q, s; + for (q = 0; q < 3u && P[j][q]; q++) drum_on(P[j][q], q ? 90 : 115); + for (s = 0; s < step / CTL; s++) { + memset(l, 0, sizeof l), memset(r, 0, sizeof r), memset(rv, 0, sizeof rv); + drums_render(l, r, rv, CTL); + for (k = 0; k < CTL; k++) wav_put(f, clamp(l[k], -32767, 32767), clamp(r[k], -32767, 32767)); + } + } + } + fclose(f); + } + printf("drum kits: %u synthesised x %u sounds bounded, audible, finite; levels near the sampled kit PASS\n", + DRUM_KITS - DRUM_SAMPLED, DS_LANES); + return 0; +} diff --git a/tests/golden.txt b/tests/golden.txt new file mode 100644 index 0000000..7d47666 --- /dev/null +++ b/tests/golden.txt @@ -0,0 +1,85 @@ +# 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 91bd46828e4771fc +preset/ANALOG/01_808_DIRTY 2c3d7f8e9cc7a898 +preset/ANALOG/02_SUB_BASS fd5d0a0346553640 +preset/ANALOG/03_REESE 2ddec1f52f0fe1c0 +preset/ANALOG/04_WOBBLE f77e468296c0af10 +preset/ANALOG/05_FUNK_BASS f12f34904163e30c +preset/ANALOG/06_G-FUNK_LD 1447ff72b50471f0 +preset/ANALOG/07_TRAP_PLUCK 62ecc05959554414 +preset/ANALOG/08_SYN_BRASS 9222cb0f4eb2e8d0 +preset/ANALOG/09_WARM_PAD 06f2cfbec91089dc +preset/ANALOG/10_DARK_STR 808468459c08ef24 +preset/ANALOG/11_ATMOS_PAD 6f40de60747d9888 +preset/DIGITAL/00_RHODES f621f5680ae3a698 +preset/DIGITAL/01_DX_RHODES 5fe2645349af9e44 +preset/DIGITAL/02_WURLI f1fff3df5bbad504 +preset/DIGITAL/03_CLAV 1d4589c5a33222b0 +preset/DIGITAL/04_TRAP_BELL 6040dd65eebfae80 +preset/DIGITAL/05_MUSIC_BOX 01e25152e312a8e0 +preset/DIGITAL/06_MARIMBA 29afd3298fb06180 +preset/DIGITAL/07_FM_BASS e2a5281c83016738 +preset/PHASE/00_CZ_BASS 997c664f2dd1150c +preset/PHASE/01_SOFT_KEYS d2c81c7507b8f644 +preset/PHASE/02_CZ_STRING d15d6d5ecf706dac +preset/PHASE/03_RESO_PLUCK 97ad740aef8b33e8 +preset/PHASE/04_CZ_BRASS 1e9d96856c82d828 +preset/LOFI/00_GAME_LEAD 60c22148ac4225e0 +preset/LOFI/01_GB_BASS 3a973469e22dab74 +preset/LOFI/02_8BIT_ARP 12c659d0a9c850fc +preset/SAMPLE/00_DUSTY_PNO ea7d7a14e7b935b0 +preset/SAMPLE/01_UP_BASS 04168ec2119d3224 +preset/SAMPLE/02_VIBES 9f12b852211a63a0 +preset/SAMPLE/03_HORN_STAB dc4a12e1d701abc0 +preset/SAMPLE/04_STRING_STB 820a5597166e5050 +preset/SAMPLE/05_LOFI_FLUTE b12690a7223bc6dc +preset/SAMPLE/06_SCRATCH 1cfe8f24d0960ab4 +preset/SAMPLE/07_GM_KIT eb39d74532ac74a8 +preset/SAMPLE/08_LOFI_KEYS 0139c05f9099a090 +preset/SAMPLE/09_DEEP_BASS 3ba4e5171c9d7e3c +preset/VOICE/00_CHOIR_AAH 6ac6b77a5a244e8c +preset/VOICE/01_SOUL_OOH 25cbfd56a1797514 +preset/VOICE/02_TALKBOX 7c354bdf8092a9d4 +preset/VOICE/03_WOW_BASS 971064951bd72248 +preset/TRIO/00_FAT_BASS 03cc706d00abee64 +preset/TRIO/01_MIN_STAB bab0d8583eb666b0 +preset/TRIO/02_MIN7_STAB 03ad3c26a7acd040 +preset/TRIO/03_SYNC_LEAD 50fe9d79d93e4e94 +preset/TRIO/04_HOOVER 64163a1667ba2660 +preset/WHEEL/00_SOUL_ORGAN 8fbeaedbecedce9c +preset/WHEEL/01_GOSPEL f13df2e34751e7cc +preset/WHEEL/02_JAZZ_ORGAN 83c4e74a5c2771cc +preset/WHEEL/03_DIRTY_B3 975aa455b771182c +preset/GRAIN/00_LOFI_CLOUD 65f2c9ff18c8f8f0 +preset/GRAIN/01_VIBE_HAZE d2586407009652c4 +preset/GRAIN/02_FLUTE_DUST 0e5bf8944c5861b8 +drums/gm_kit 61ea94f48c2cbdb0 +mode/ANALOG/POLY 9efd45d25230813c +mode/ANALOG/MONO 86255713a8e40df8 +mode/ANALOG/LEGATO fbd487f9d8cb8aec +mode/ANALOG/UNISON e785536edde115c8 +mode/DIGITAL/POLY 5fe2645349af9e44 +mode/DIGITAL/MONO f3e1159055665c2c +mode/DIGITAL/LEGATO cb35d2dd9973be54 +mode/DIGITAL/UNISON 9bb5175ca12eff48 +mode/VOICE/POLY 6ac6b77a5a244e8c +mode/VOICE/MONO b2d262dd7902f320 +mode/VOICE/LEGATO fa66adf3d68c2948 +mode/VOICE/UNISON db93caf4fc2be9cc +sends/ANALOG/dry 594309a5b10bb768 +sends/ANALOG/chorus 34c9174766a53088 +sends/ANALOG/delay f3060fde00060f1c +sends/ANALOG/reverb bd306c1401998c64 +sends/ANALOG/all b938d8a018fbc768 +sends/ANALOG/dist 6dcfb035d32f69f4 +sends/DIGITAL/dry 55c96843978d611c +sends/DIGITAL/chorus 0694aa7254e09714 +sends/DIGITAL/delay b0c3ae30b43d680c +sends/DIGITAL/reverb 17f9f5e4cfc3915c +sends/DIGITAL/all 6e813a9a68cc6860 +sends/DIGITAL/dist 62f7246dd651ff08 +song/4track_mix 5c08fb64fc5fda48 +slicer/gate/ANALOG_DARK_STR 6806fe0d516445f8 +slicer/stut/DIGITAL_RHODES fe0b6079af5f57e4 +slicer/song_gate_stut 8724bf8bf5b80d88 diff --git a/tests/hostsim.c b/tests/hostsim.c new file mode 100644 index 0000000..867d3d4 --- /dev/null +++ b/tests/hostsim.c @@ -0,0 +1,906 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* Host-side render of the FELUCCA DSP (engines, voices, FX, sequencer) to a WAV, + * for debugging sound without hardware. Same sources as the firmware. + * tests/run_tests.sh builds it into build/host/; + * build/host/hostsim ENGINE PRESET MONO OUT.wav [CHORUS] + * env: SECS=n renders n s (the 2 s note pattern repeats), CHORD[=k] holds k keys + * (default 4, up to 8), DRUMS=1 adds GM drum hits, BENCH=1 prints the render time, + * DIST=d, LEVEL=l, SENDS=c,d,r, SWEEP=1, NOTE=k, OCT=o, PSET=id:v,..., VSWEEP=1, PSWEEP=id:a:b, + * PRESET=1 (the whole preset: sends, ARP, voice mode), STEPS=n,n,... (a pattern, 0 = rest; see below). + * TRACKS=DIR: the 4-track test (tracks_demo below): a bass / pad / lead / drums pattern + * with live recording into DIR (mix + solos), checks, and the cost against one track. */ +#include +#include +#include +#include +#include +#include +#include +#include +#define __attribute__(x) +#define memset felucca_memset +#define memcpy felucca_memcpy +#define memcmp felucca_memcmp +#include "felucca_tables.h" +#include "../firmware/src/libc.c" +#undef memset +#undef memcpy +#undef memcmp +static struct { volatile uint32_t notes, buttons; } fm1_in; +static void fm1_irq_off(void) {} /* (the host: one thread) */ +static void fm1_irq_on(void) {} +#include "../firmware/src/core.h" +#include "../firmware/src/engines.c" +#include "../firmware/src/drums.c" +#include "../firmware/src/params.c" +#include "../firmware/src/voice.c" +#include "../firmware/src/slicer.c" +#include "../firmware/src/fx.c" +static void fm1_delay_ms(uint32_t ms) { (void)ms; } +#include "../firmware/src/usb.c" +#include "../firmware/src/midi_uart.c" /* TRS MIDI IN: its parser (um_byte) feeds midi_in_q */ +#if FELUCCA_ARRANGER +#include "../firmware/src/arranger.c" +#endif +#include "../firmware/src/seq.c" +#define inst (trk[0]) /* the single-part renders below: part 1 */ + +static void wav_hdr(FILE *f, uint32_t frames) +{ + uint32_t v; + fwrite("RIFF", 1, 4, f); v = 36 + frames * 4; fwrite(&v, 4, 1, f); + fwrite("WAVEfmt ", 1, 8, f); v = 16; fwrite(&v, 4, 1, f); + uint16_t a = 1, ch = 2, ba = 4, bits = 16; uint32_t sr = FS, br = FS * 4; + fwrite(&a, 2, 1, f); fwrite(&ch, 2, 1, f); fwrite(&sr, 4, 1, f); fwrite(&br, 4, 1, f); + fwrite(&ba, 2, 1, f); fwrite(&bits, 2, 1, f); + fwrite("data", 1, 4, f); v = frames * 4; fwrite(&v, 4, 1, f); +} + +static void wav_put(FILE *f, int32_t l, int32_t r) +{ + int16_t s[2] = {(int16_t)(l > 32767 ? 32767 : l < -32768 ? -32768 : l), + (int16_t)(r > 32767 ? 32767 : r < -32768 ? -32768 : r)}; + fwrite(s, 2, 2, f); +} + +/* ---------------------------------------------------------------- TRACKS --- */ +static uint64_t now_ns(void) +{ + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return (uint64_t)ts.tv_sec * 1000000000u + (uint64_t)ts.tv_nsec; +} + +static void host_tracks_init(void) /* as felucca_init: defaults, empty patterns */ +{ + uint32_t i, k; + for (i = 0; i < G_COUNT; i++) + song.g[i] = GP[i].def; + song.g[G_BPM] = 120; /* (the tests' tempo; SLOOP powers on at 90) */ + for (k = 0; k < NTRK; k++) { + for (i = 0; i < P_E0; i++) + trk[k].p[i] = TP[i].def; + steps_clear(&trk[k]); + } + song.master_q12 = 4096; +} + +/* the factory preset as ui.c apply_preset_to sets it (sound, sends, arp; not the pattern, not the mix); + * the engine as the UI asks for it (eng_req: the audio side switches; host_preset: at once) */ +static void host_preset_req(track_t *t, uint32_t e, uint32_t pi) +{ + static const uint8_t FX_DEF[4] = {0, 24, 28, 36}; + const preset_t *p = &ENGINES[e]->presets[pi % ENGINES[e]->npresets]; + uint32_t i; + t->eng_req = (uint8_t)e; + t->preset = (uint8_t)(pi % ENGINES[e]->npresets); + for (i = 0; i < 8u; i++) + t->p[P_E0 + i] = p->e[i]; + t->p[P_ATK] = p->env[0]; + t->p[P_DEC] = p->env[1]; + t->p[P_SUS] = p->env[2]; + t->p[P_REL] = p->env[3]; + t->p[P_ED_FLT] = p->fenv; + t->p[P_VOICE] = p->mono ? V_LEGATO : V_POLY; + for (i = 0; i < 4u; i++) { + t->p[P_DIST + i] = (int16_t)(p->fx[i] ? p->fx[i] - 1 : FX_DEF[i]); + t->p[P_AMODE + i] = (int16_t)(p->arp[i] ? p->arp[i] - 1 : TP[P_AMODE + i].def); + } + preset_extras(t->p, p); +} +static void host_preset(track_t *t, uint32_t e, uint32_t pi) +{ + host_preset_req(t, e, pi); + t->engine = (uint8_t)e; +} + +/* the sequencer clock as the harness sees it: the step of t at the clock (as the next block plays it), + * *q100: how far into it, in % of its (swung) length */ +static uint32_t at_step(const track_t *t, uint32_t *q100) +{ + uint32_t into, len, abs = trk_grid(t, &into, &len); + if (q100) + *q100 = (uint32_t)((uint64_t)into * 100u / len); + return abs % trk_len(t); +} + +static void put_step(track_t *t, uint32_t i, uint32_t n, const uint8_t *notes, uint32_t time, uint32_t flags) +{ + step_t *s = &t->step[i]; + uint32_t k; + if (is_drum(t)) { /* the drum track: GM notes -> its lanes (accent: hard) */ + memset(&t->dstep[i], 0, sizeof t->dstep[i]); + for (k = 0; k < n && time == ST_NOTE; k++) + dstep_set(&t->dstep[i], lane_of_note(notes[k]), (flags & SF_ACCENT) ? LV_HARD : LV_NORM, 0); + return; + } + s->n = (uint8_t)n; + for (k = 0; k < 4u; k++) + s->note[k] = k < n ? notes[k] : 0; + s->time = (uint8_t)time; + s->flags = (uint8_t)flags; + s->vel = n ? 100 : 0; +} + +static uint32_t busy_now(void) /* sounding voices of the parts (not the ones fading out: given up) */ +{ + uint32_t p, i, n = 0; + for (p = 0; p < NPART; p++) + for (i = 0; i < NVOICE; i++) + n += trk[p].v[i].active && trk[p].v[i].stage != 4u; + return n; +} + +/* the demo song: T1 ANALOG ACID (16 steps), T2 DIGITAL PAD (32 steps, tied chords), T3 LOFI PULSE LD + * (12 steps: 3 against 4), T4 drums (16 steps, up to 3 notes a step); 120 BPM, 8 bars. Bars 5..6: + * live recording: a clap into the drums just before step 4 (quantised onto it, not triggered twice), + * MIDI ch 3 into the lead, a two-key chord on the keys into an empty pad step. solo: 0 = the mix, + * 1..4 = that track only. Writes DIR/NAME; returns the number of failed checks. */ +static int tracks_demo(const char *dir, const char *name, uint32_t solo) +{ + static const uint8_t ACID[16] = {45, 45, 57, 45, 0, 48, 45, 55, 45, 0, 57, 52, 45, 48, 0, 50}; + static const uint8_t ACIDF[16] = {1, 0, 2, 0, 0, 0, 1, 2, 0, 0, 1, 0, 0, 2, 0, 1}; + static const uint8_t AM[4] = {57, 60, 64, 67}, FM[4] = {53, 57, 60, 64}; + static const uint8_t LEAD[12] = {76, 0, 0, 79, 0, 0, 81, 0, 79, 0, 76, 0}; + const uint32_t frames = 16u * FS, bar = 2u * FS; + char path[512]; + FILE *w; + uint32_t f, i, bmax = 0, clips = 0, fail = 0, clap_done = 0, lead_done = 0, keys_t = 0, keys_on = 0; + uint32_t clap_age = 0, clap_hits = 0xFFFFu, clap_pass = 0, kills0; + track_t *t1 = &trk[0], *t2 = &trk[1], *t3 = &trk[2], *td = TDRUM; + snprintf(path, sizeof path, "%s/%s", dir, name); + if (!(w = fopen(path, "wb"))) { + fprintf(stderr, "tracks: cannot write %s\n", path); + return 1; + } + host_tracks_init(); + song.g[G_BPM] = 120; + host_preset(t1, 0, 4); + host_preset(t2, 1, 5); + host_preset(t3, 3, 0); + for (i = 0; i < 16u; i++) { + uint8_t n = ACID[i]; + put_step(t1, i, n ? 1u : 0u, &n, n ? ST_NOTE : ST_REST, ACIDF[i]); + } + t2->p[P_SLEN] = 32; + t2->p[P_SGATE] = 120; + for (i = 0; i < 32u; i++) + put_step(t2, i, i % 16u == 0u ? 4u : 0u, i < 16u ? AM : FM, i % 16u == 0u ? ST_NOTE : i % 16u < 14u ? ST_TIE : ST_REST, 0); + t3->p[P_SLEN] = 12; + for (i = 0; i < 12u; i++) { + uint8_t n = LEAD[i]; + put_step(t3, i, n ? 1u : 0u, &n, n ? ST_NOTE : ST_REST, i == 0u ? SF_ACCENT : 0u); + } + for (i = 0; i < 16u; i++) { /* kick 4 on the floor, snare 4 / 12, hats on the 8ths */ + uint8_t n[4]; + uint32_t k = 0; + if (i % 4u == 0u) + n[k++] = 36; + if (i == 4u || i == 12u) + n[k++] = 38; + if (i % 2u == 0u) + n[k++] = i == 14u ? 46 : 42; + put_step(td, i, k, n, k ? ST_NOTE : ST_REST, i % 4u == 0u ? SF_ACCENT : 0u); + } + if (solo) { /* the other tracks silent */ + for (i = 0; i < NPART; i++) + if (i + 1u != solo) + trk[i].p[P_LEVEL] = 0; + if (solo != 4u) + song.g[G_DRLVL] = 0; + } + kills0 = voice_kills; + transport_req = 1; + wav_hdr(w, frames); + for (f = 0; f < frames; f += CTL) { + int32_t o[2 * CTL]; + uint32_t barn = f / bar, period = div_samples(2), q; + if (barn == 4u && !song.rec) + song.rec = 0x0Eu; /* bars 5..6: tracks 2, 3, 4 armed */ + if (barn == 6u) + song.rec = 0; + /* (a) a clap into the drums, late in step 3: lands on step 4, sounds now, step 4 does not repeat it */ + if (song.rec && !clap_done && at_step(td, &q) == 3u && q > 75u) { + input_on(td, 39, 110); + clap_done = 1; + clap_age = drums.age; + clap_pass = 1; + } else if (clap_pass == 1u && td->seq_idx == 4u) { + clap_hits = drums.age - clap_age; /* what step 4 triggered right after (36, 38, 42; not 39) */ + clap_pass = 2; + } + /* (b) MIDI ch 3 into the lead, early in its step 1 */ + if (song.rec && !lead_done && at_step(t3, &q) == 1u && q < 25u) { + midi_in_q[mi_w++ % MQ] = 0x09u | 0x92u << 8 | 84u << 16 | 100u << 24; + lead_done = 1; + } else if (lead_done == 1u && t3->seq_idx == 2u) { + midi_in_q[mi_w++ % MQ] = 0x08u | 0x82u << 8 | 84u << 16; + lead_done = 2; + } + /* (c) the keys, track 2 selected: two keys at once into the empty pad step 14 */ + if (song.rec && !keys_on && !keys_t && at_step(t2, &q) == 14u && q < 25u) { + song.sel = 1; + fm1_in.notes = (1u << 7) | (1u << 11); + keys_on = 1; + keys_t = f; + } else if (keys_on && f - keys_t > period / 2u) { + fm1_in.notes = 0; + keys_on = 0; + } + mix_block(o, CTL); + if (busy_now() > bmax) + bmax = busy_now(); + for (i = 0; i < CTL; i++) { + int32_t l = o[2 * i]; + if (l >= 32700 || l <= -32700) + clips++; + wav_put(w, o[2 * i], o[2 * i + 1]); + } + } + fclose(w); + if (solo) + return bmax > NVOICE; + { + const dstep_t *s4 = &td->dstep[4]; + const step_t *l1 = &t3->step[1], *p14 = &t2->step[14]; + uint32_t lanes = dstep_mask(s4), nl = 0, m; + int ok_clap; + for (m = lanes; m; m >>= 1) + nl += m & 1u; + ok_clap = nl == 4u && dstep_has(s4, lane_of_note(39)) && clap_hits == 3u; + int ok_lead = l1->n == 1u && l1->note[0] == 84u && l1->time == ST_NOTE; + int ok_keys = p14->n == 2u && p14->time == ST_NOTE && p14->note[0] == 60u && p14->note[1] == 64u; + printf("tracks: recording: drums step 4 = %u lanes (kick snare hat + clap: %s), hits when step 4 played right " + "after: %u (want 3: the clap is not triggered twice) %s\n", nl, dstep_has(s4, lane_of_note(39)) ? "yes" : "no", + clap_hits, ok_clap ? "ok" : "FAIL"); + printf("tracks: recording: MIDI ch 3 -> lead step 1 = %u (want 84) %s; keys -> pad step 14 = %u notes %u %u %s\n", + l1->note[0], ok_lead ? "ok" : "FAIL", p14->n, p14->note[0], p14->note[1], ok_keys ? "ok" : "FAIL"); + printf("tracks: voices sounding at most %u (budget %u) %s; given up to another part %u; %u samples near full " + "scale\n", bmax, NVOICE, bmax <= NVOICE ? "ok" : "FAIL", voice_kills - kills0, clips); + fail = !ok_clap + !ok_lead + !ok_keys + (bmax > NVOICE) + (clips > 0); + } + return (int)fail; +} + +/* ns per 44.1 kHz sample of the whole mix (events, parts, drums on 16ths, buses, master) with notes + * held: parts[k] = {engine, preset, notes} for part k, 0 notes = idle. 2 s to settle, then the + * fastest of four 2 s stretches (the host's other load only ever adds). Runs in a child process + * (a clean state each time); the result comes back through a pipe. */ +static double tracks_cost(const uint8_t parts[NPART][3], uint32_t *busy_max) +{ + int fd[2]; + pid_t pid; + double r[2] = {-1, 0}; + if (pipe(fd)) + return -1; + fflush(stdout); + if (!(pid = fork())) { + static const uint8_t NOTES[8] = {48, 52, 55, 59, 60, 64, 67, 71}; + uint64_t ns = 0, best = ~0ull, k, nblk = 8u * FS / CTL, seg = nblk / 4u; /* the fastest of 4 x 2 s: */ + uint32_t p, i, bm = 0; + int32_t o[2 * CTL]; + host_tracks_init(); + for (p = 0; p < NPART; p++) { + host_preset(&trk[p], parts[p][0], parts[p][1]); + trk[p].p[P_VOICE] = V_POLY; + trk[p].p[P_SUS] = 127; /* held notes keep sounding */ + trk[p].p[P_AMODE] = 0; + } + for (p = 0; p < NPART; p++) + for (i = 0; i < parts[p][2]; i++) + trk_note_on(&trk[p], NOTES[i] + 12u * p, 100); + for (k = 0; k < 2u * FS / CTL + nblk; k++) { /* 2 s to settle (attacks), then measure */ + uint64_t t0; + if ((k * CTL) % (FS / 8u) < CTL) /* 16ths at 120 BPM */ + drum_on((k * CTL) % (FS / 2u) < CTL ? 36u : ((k * CTL) / (FS / 8u)) % 4u == 2u ? 38u : 42u, 100u); + t0 = now_ns(); + mix_block(o, CTL); + if (k >= 2u * FS / CTL) { /* (the host's own noise only ever adds) */ + ns += now_ns() - t0; + if ((k - 2u * FS / CTL) % seg == seg - 1u) { + best = ns < best ? ns : best; + ns = 0; + } + } + if (busy_now() > bm) + bm = busy_now(); + } + r[0] = (double)best / (double)(seg * CTL); + r[1] = bm; + if (write(fd[1], r, sizeof r) != sizeof r) + _exit(1); + _exit(0); + } + close(fd[1]); + if (read(fd[0], r, sizeof r) != sizeof r) + r[0] = -1; + close(fd[0]); + waitpid(pid, 0, 0); + if (busy_max) + *busy_max = (uint32_t)r[1]; + return r[0]; +} + +/* stealing across parts must not click: three parts of plain sines (smooth: the largest sample + * step is set by the pitches), 7 + 1 notes fill the budget, then notes on parts 2 and 3 take held + * voices of part 1 (and part 2). Each taken voice fades over one block. Compares the largest sample + * step around each take with the largest one in the 0.25 s before it; a hard cut would be several + * times larger. Writes DIR/steal.wav. */ +static int steal_test(const char *dir) +{ + static const uint8_t N1[7] = {48, 52, 55, 59, 62, 65, 69}; + const uint32_t frames = 4u * FS; + char path[512]; + FILE *w; + int32_t prev = 0, *L = calloc(frames, sizeof *L); + uint32_t f, i, p, k, events[6], nev = 0, bad = 0, kills0; + double worst = 0; + snprintf(path, sizeof path, "%s/steal.wav", dir); + if (!L || !(w = fopen(path, "wb"))) + return 1; + host_tracks_init(); + for (p = 0; p < NPART; p++) { + track_t *t = &trk[p]; + host_preset(t, 0, 5); /* ANALOG SINE KEY, as a plain held sine: */ + t->p[P_E4] = 127; /* filter open, no resonance, no drive */ + t->p[P_E5] = t->p[P_E6] = 0; + t->p[P_ED_FLT] = 0; + t->p[P_ATK] = 40; /* slow attack, full sustain, no sends */ + t->p[P_SUS] = 127; + t->p[P_DIST] = t->p[P_CHOR] = t->p[P_DLY] = t->p[P_REV] = 0; + t->p[P_VOICE] = V_POLY; + t->p[P_LEVEL] = 90; + } + kills0 = voice_kills; + wav_hdr(w, frames); + for (f = 0; f < frames; f += CTL) { + int32_t o[2 * CTL]; + uint32_t ms = f * 1000u / FS, k0 = voice_kills; + if (f == 0) + for (i = 0; i < 7u; i++) + trk_note_on(&trk[0], N1[i], 90); + if (f == FS / 2u / CTL * CTL) + trk_note_on(&trk[1], 74, 90); /* 8: the budget is full */ + if (ms >= 1000u && ms % 500u == 0u && f % (FS / 2u) < CTL && ms < 3500u) { + p = ms / 500u % 2u ? 1u : 2u; /* parts 2, 3 in turn: each takes a voice */ + trk_note_on(&trk[p], 76u + ms / 250u, 90); + } + mix_block(o, CTL); + if (voice_kills != k0 && nev < 6u) + events[nev++] = f; + for (i = 0; i < CTL; i++) { + L[f + i] = o[2 * i]; + wav_put(w, o[2 * i], o[2 * i + 1]); + } + } + fclose(w); + for (k = 0; k < nev; k++) { /* around the take vs. the 0.25 s before */ + int32_t calm = 0, at = 0; + uint32_t e = events[k]; + for (i = e - FS / 4u; i < e - 2u * CTL; i++) + calm = abs(L[i] - L[i - 1]) > calm ? abs(L[i] - L[i - 1]) : calm; + for (i = e; i < e + 2u * CTL; i++) + at = abs(L[i] - L[i - 1]) > at ? abs(L[i] - L[i - 1]) : at; + if ((double)at / calm > worst) + worst = (double)at / calm; + if (at > calm * 3 / 2) + bad++; + } + (void)prev; + printf("tracks: stealing across parts: %u voices taken; largest sample step at a take / before it: at most %.2f x " + "(a hard cut: several x) %s\n", voice_kills - kills0, worst, nev >= 4u && !bad ? "ok" : "FAIL"); + free(L); + return nev < 4u || bad; +} + +/* a preset change across engines while notes sound (the PRESETS knob, the editor's PRESET) must not click: + * part 1 as a plain sine pad (ANALOG SINE KEY, filter open, slow release, no sends: smooth, so the largest + * sample step is set by the pitches), (a) a chord held and released, the switch to DIGITAL in its release + * tail; (b) twice a chord held, the switch to PHASE / LOFI while it is held (the preset change releases + * it); (c) a switch to SAMPLE with a note in its second block: that note must sound on the new engine. As ui.c + * set_engine_of + apply_preset_to: eng_req, the new engine's values and panic_req at once (the main loop + * writes them with the audio IRQ off). Compares the largest sample step in the 10 ms after (a) and (b) + * with the largest one in the 0.1 s before (a hard cut of the voices: many times larger). + * Writes DIR/engine_switch.wav. */ +static void xfade_sine(track_t *t) +{ + host_preset(t, 0, 5); /* ANALOG SINE KEY, as a plain held sine */ + t->p[P_E4] = 127; + t->p[P_E5] = t->p[P_E6] = 0; + t->p[P_ED_FLT] = 0; + t->p[P_ATK] = 40; + t->p[P_SUS] = 127; + t->p[P_REL] = 100; + t->p[P_DIST] = t->p[P_CHOR] = t->p[P_DLY] = t->p[P_REV] = 0; + t->p[P_VOICE] = V_POLY; + t->p[P_LEVEL] = 100; +} +static int xfade_test(const char *dir) +{ + static const uint8_t CH[3] = {57, 60, 64}; + const uint32_t frames = 4u * FS, B = FS / 10u / CTL * CTL; /* B: 0.1 s in whole blocks */ + /* switches: (a) in a release tail, (b) twice with a chord held, (c) with a note right after it */ + const uint32_t sw[4] = {11u * B, 23u * B, 29u * B + 7u * CTL, 33u * B}; + const uint32_t on[3] = {B, 15u * B, 25u * B}, sine[3] = {14u * B, 24u * B, 32u * B}; + const uint8_t to[4] = {1, 2, 3, 4}; + char path[512]; + FILE *w; + int32_t *L = calloc(frames, sizeof *L); + uint32_t f, i, k, bad = 0, late_ok = 0; + double worst = 0; + track_t *t = &trk[0]; + snprintf(path, sizeof path, "%s/engine_switch.wav", dir); + if (!L || !(w = fopen(path, "wb"))) + return 1; + host_tracks_init(); + xfade_sine(t); + wav_hdr(w, frames); + for (f = 0; f < frames; f += CTL) { + int32_t o[2 * CTL]; + for (k = 0; k < 3u; k++) { + if (f == sine[k]) + xfade_sine(t); /* silent since the switch before: the sine again at once */ + if (f == on[k]) + for (i = 0; i < 3u; i++) + trk_note_on(t, CH[i] - 2u * k, 100); + } + if (f == 9u * B) + for (i = 0; i < 3u; i++) + trk_note_off(t, CH[i]); /* (a): the release tail rings */ + for (k = 0; k < 4u; k++) + if (f == sw[k]) { + host_preset_req(t, to[k], 0); + t->p[P_DIST] = t->p[P_CHOR] = t->p[P_DLY] = t->p[P_REV] = 0; + panic_req |= 1u; + } else if (k == 3u && f == sw[k] + CTL) { + trk_note_on(t, 60, 100); /* (c): a note during the fade */ + } + if (f == sw[3] + FS / 50u / CTL * CTL) { + uint32_t v; + for (v = 0; v < NVOICE; v++) + late_ok |= t->v[v].active && t->v[v].note == 60u && t->v[v].gate; + late_ok = late_ok && t->engine == to[3]; + trk_note_off(t, 60); + } + mix_block(o, CTL); + for (i = 0; i < CTL; i++) { + L[f + i] = o[2 * i]; + wav_put(w, o[2 * i], o[2 * i + 1]); + } + } + fclose(w); + for (k = 0; k < 3u; k++) { + int32_t calm = 1, at = 0; + for (i = sw[k] - FS / 10u; i < sw[k]; i++) + calm = abs(L[i] - L[i - 1]) > calm ? abs(L[i] - L[i - 1]) : calm; + for (i = sw[k]; i < sw[k] + FS / 100u; i++) + at = abs(L[i] - L[i - 1]) > at ? abs(L[i] - L[i - 1]) : at; + printf("tracks: engine switch %s -> %s (%s): largest sample step %d in the 10 ms after, %d in the 0.1 s " + "before (%.2f x)\n", ENGINES[0]->name, ENGINES[to[k]]->name, k ? "chord held" : "release tail", at, + calm, (double)at / calm); + worst = (double)at / calm > worst ? (double)at / calm : worst; + bad += at > calm * 3 / 2; + } + printf("tracks: engine switch: at most %.2f x the step before (a hard cut: several x) %s\n", worst, bad ? "FAIL" : "ok"); + printf("tracks: a note during the switch sounds on the new engine (%s) %s\n", ENGINES[to[3]]->name, + late_ok ? "ok" : "FAIL"); + free(L); + return bad || !late_ok; +} + +/* live recording: held lengths (TIE steps) and swing-aware quantising. Blocks are rendered until track t + * is at fraction q (1/100) into step idx (its swung length); the keys go in between, as events_block + * takes them. */ +static void rec_run_to(track_t *t, uint32_t idx, uint32_t q) +{ + int32_t o[2 * CTL]; + uint32_t guard = 0, at; + do { + mix_block(o, CTL); + } while (++guard < 100000u && !(at_step(t, &at) == idx && at >= q)); +} +static int rec_step_is(const track_t *t, uint32_t i, uint32_t time, uint32_t n, uint32_t note) +{ + const step_t *s = &t->step[i]; + return s->time == time && s->n == n && (!n || s->note[0] == note); +} +static int rec_test(void) +{ + track_t *t1 = &trk[0], *t2 = &trk[1], *t3 = &trk[2]; + uint32_t i; + int ok_len, ok_short, ok_half, ok_cap, ok_swing, ok_mono, ok_chord, fail; + host_tracks_init(); + song.g[G_BPM] = 120; + host_preset(t1, 0, 1); /* POLY pad */ + host_preset(t2, 0, 1); + host_preset(t3, 0, 0); /* SAW LEAD */ + t1->p[P_VOICE] = t2->p[P_VOICE] = V_POLY; + t3->p[P_VOICE] = V_MONO; + t2->p[P_SLEN] = 4; + t3->p[P_SSWING] = 50; /* odd steps start 0.2 step late */ + put_step(t1, 5, 1, (const uint8_t[]){48}, ST_NOTE, 0); /* an older take: put back by an early release */ + song.rec = 0x07u; + transport_req = 1; + /* (a) held 3.3 steps from step 2: 2 NOTE, 3 4 TIE, 5 (released early in it) as before */ + rec_run_to(t1, 2, 10); + input_on(t1, 60, 100); + rec_run_to(t1, 5, 30); + input_off(t1, 60); + ok_len = rec_step_is(t1, 2, ST_NOTE, 1, 60) && rec_step_is(t1, 3, ST_TIE, 0, 0) && rec_step_is(t1, 4, ST_TIE, 0, 0) && + rec_step_is(t1, 5, ST_NOTE, 1, 48); + /* (b) released after 0.3 step: one step */ + rec_run_to(t1, 8, 5); + input_on(t1, 62, 100); + rec_run_to(t1, 8, 35); + input_off(t1, 62); + rec_run_to(t1, 9, 50); + ok_short = rec_step_is(t1, 8, ST_NOTE, 1, 62) && rec_step_is(t1, 9, ST_REST, 0, 0); + /* (c) released past the middle of the next step: tied into it */ + rec_run_to(t1, 10, 10); + input_on(t1, 64, 100); + rec_run_to(t1, 11, 60); + input_off(t1, 64); + rec_run_to(t1, 12, 50); + ok_half = rec_step_is(t1, 10, ST_NOTE, 1, 64) && rec_step_is(t1, 11, ST_TIE, 0, 0) && rec_step_is(t1, 12, ST_REST, 0, 0); + /* (d) a two-key chord held 2.6 steps: ties until the last key is up */ + rec_run_to(t1, 13, 5); + input_on(t1, 67, 100); + input_on(t1, 71, 100); + rec_run_to(t1, 14, 20); + input_off(t1, 67); + rec_run_to(t1, 15, 60); + input_off(t1, 71); + rec_run_to(t1, 0, 10); + ok_chord = t1->step[13].n == 2u && rec_step_is(t1, 14, ST_TIE, 0, 0) && rec_step_is(t1, 15, ST_TIE, 0, 0) && + t1->step[0].time != ST_TIE; + /* (e) LEN 4, held for 10 steps: the note fills the pattern (3 TIEs), not more */ + rec_run_to(t2, 1, 10); + input_on(t2, 55, 100); + for (i = 0; i < 10u; i++) + rec_run_to(t2, (2u + i) % 4u, 50); + input_off(t2, 55); + ok_cap = rec_step_is(t2, 1, ST_NOTE, 1, 55) && rec_step_is(t2, 2, ST_TIE, 0, 0) && rec_step_is(t2, 3, ST_TIE, 0, 0) && + rec_step_is(t2, 0, ST_TIE, 0, 0); + /* (f) SWING 50 %: 0.55 into an even (long) step is before its middle (stays); 0.56 period into an odd + * (short, 0.8) step is past its middle and the key-to-ear latency REC_LAT (the next one) */ + rec_run_to(t3, 4, 46); /* 0.46 x 1.2 = 0.55 period */ + input_on(t3, 72, 100); + input_off(t3, 72); + rec_run_to(t3, 7, 70); /* 0.70 x 0.8 = 0.56 period */ + input_on(t3, 74, 100); + input_off(t3, 74); + ok_swing = rec_step_is(t3, 4, ST_NOTE, 1, 72) && t3->step[5].n == 0u && rec_step_is(t3, 8, ST_NOTE, 1, 74) && + t3->step[7].n == 0u; + /* (g) MONO, legato: A held from step 10, B pressed in step 12 while A is still down, A up, B up late in + * 13: 10 A, 11 TIE, 12 B (one note), 13 TIE */ + rec_run_to(t3, 10, 10); + input_on(t3, 60, 100); + rec_run_to(t3, 12, 10); + input_on(t3, 62, 100); + rec_run_to(t3, 12, 40); + input_off(t3, 60); + rec_run_to(t3, 13, 70); + input_off(t3, 62); + rec_run_to(t3, 14, 50); + ok_mono = rec_step_is(t3, 10, ST_NOTE, 1, 60) && rec_step_is(t3, 11, ST_TIE, 0, 0) && rec_step_is(t3, 12, ST_NOTE, 1, 62) && + rec_step_is(t3, 13, ST_TIE, 0, 0) && t3->step[14].time != ST_TIE; + printf("tracks: recording lengths: held 3.3 steps -> NOTE TIE TIE (the 4th step put back) %s; 0.3 step -> one " + "step %s; past the middle of the next -> NOTE TIE %s\n", ok_len ? "ok" : "FAIL", ok_short ? "ok" : "FAIL", + ok_half ? "ok" : "FAIL"); + printf("tracks: recording lengths: a chord ties until its last key %s; capped at LEN 4 %s; MONO legato A..B -> " + "A TIE B TIE %s\n", ok_chord ? "ok" : "FAIL", ok_cap ? "ok" : "FAIL", ok_mono ? "ok" : "FAIL"); + printf("tracks: recording with SWING 50 %%: nearest swung step, as heard (0.55 into a long step stays, 0.56 into a " + "short one moves on) %s\n", ok_swing ? "ok" : "FAIL"); + fail = !ok_len + !ok_short + !ok_half + !ok_chord + !ok_cap + !ok_mono + !ok_swing; + return fail; +} + +/* TRS MIDI IN (midi_uart.c, untested on hardware): bytes through its parser into the same queue as + * USB, routed by channel: 1..3 -> parts 1..3, 10 -> drums, others -> the selected track; running + * status, note-on velocity 0 = note-off; a note-off on a "selected track" channel reaches the track + * its note-on went to after another track was selected; recording into an armed track. */ +static int trs_held(const track_t *t, uint32_t note) +{ + uint32_t v; + for (v = 0; v < NVOICE; v++) + if (t->v[v].active && t->v[v].gate && t->v[v].note == note) + return 1; + return 0; +} +static void trs_bytes(const uint8_t *b, uint32_t n) +{ + int32_t o[2 * CTL]; + while (n--) + um_byte(*b++); + mix_block(o, CTL); +} +static int trs_test(void) +{ + uint32_t d0, i; + int ok_parts, ok_drum, ok_sel, ok_off, ok_hang, ok_rec; + host_tracks_init(); + for (i = 0; i < NPART; i++) { + host_preset(&trk[i], 0, 1); + trk[i].p[P_VOICE] = V_POLY; + trk[i].p[P_SUS] = 127; + } + song.sel = 1; + d0 = drums.age; + trs_bytes((const uint8_t[]){0x90, 60, 100, 65, 0xF8, 100, 0x91, 62, 100, 0x92, 64, 100, 0x99, 36, 110, 0x94, 67, 90}, 18); + ok_parts = trs_held(&trk[0], 60) && trs_held(&trk[0], 65) && trs_held(&trk[1], 62) && trs_held(&trk[2], 64) && !trs_held(&trk[0], 62); + ok_drum = drums.age == d0 + 1u; + ok_sel = trs_held(&trk[1], 67) && !trs_held(&trk[0], 67); + trs_bytes((const uint8_t[]){0x90, 60, 0, 65, 0, 0x81, 62, 0, 0x82, 64, 64}, 11); /* vel 0 = off, 0x8n */ + ok_off = !trs_held(&trk[0], 60) && !trs_held(&trk[0], 65) && !trs_held(&trk[1], 62) && !trs_held(&trk[2], 64); + song.sel = 2; /* another track selected while ch 5's note is down */ + trs_bytes((const uint8_t[]){0x84, 67, 0}, 3); + ok_hang = !trs_held(&trk[1], 67); + song.rec = 1u << 2; /* track 3 armed, transport on: ch 3 records */ + transport_req = 1; + trs_bytes((const uint8_t[]){0xF8}, 1); + trs_bytes((const uint8_t[]){0x92, 72, 100}, 3); + trs_bytes((const uint8_t[]){0x92, 72, 0}, 3); + ok_rec = trk[2].step[0].n == 1u && trk[2].step[0].note[0] == 72u && trk[2].step[0].time == ST_NOTE && trk[1].step[0].n == 0u; + printf("tracks: TRS MIDI IN: ch 1..3 -> parts %s, ch 10 -> drums %s, ch 5 -> the selected track %s; note-offs " + "(running status, vel 0) %s\n", ok_parts ? "ok" : "FAIL", ok_drum ? "ok" : "FAIL", ok_sel ? "ok" : "FAIL", + ok_off ? "ok" : "FAIL"); + printf("tracks: TRS MIDI IN: note-off after another track was selected reaches the note's track %s; ch 3 records " + "into armed track 3 %s\n", ok_hang ? "ok" : "FAIL", ok_rec ? "ok" : "FAIL"); + return !ok_parts + !ok_drum + !ok_sel + !ok_off + !ok_hang + !ok_rec; +} + +static int tracks_test(const char *dir) +{ + static const char *const SOLO[5] = {"tracks_demo.wav", "t1_bass.wav", "t2_pad.wav", "t3_lead.wav", "t4_drums.wav"}; + uint32_t e, pi, s, worst_e = 0, worst_p = 0, heavy[NENGINES] = {0}, bm = 0; + double worst = 0, best_e[NENGINES] = {0}, four, four_full; + int fail = 0; + for (s = 0; s < 5u; s++) { + pid_t pid; + fflush(stdout); + pid = fork(); + int st = 0; + if (!pid) + { int rc = tracks_demo(dir, SOLO[s], s); fflush(stdout); _exit(rc); } + waitpid(pid, &st, 0); + if (!WIFEXITED(st) || WEXITSTATUS(st)) + fail++; + } + { + pid_t pid; + int st = 0; + fflush(stdout); + pid = fork(); + if (!pid) { + int rc = steal_test(dir); + fflush(stdout); + _exit(rc); + } + waitpid(pid, &st, 0); + if (!WIFEXITED(st) || WEXITSTATUS(st)) + fail++; + fflush(stdout); + pid = fork(); + if (!pid) { + int rc = trs_test(); + fflush(stdout); + _exit(rc); + } + waitpid(pid, &st, 0); + if (!WIFEXITED(st) || WEXITSTATUS(st)) + fail++; + fflush(stdout); + pid = fork(); + if (!pid) { + int rc = rec_test(); + fflush(stdout); + _exit(rc); + } + waitpid(pid, &st, 0); + if (!WIFEXITED(st) || WEXITSTATUS(st)) + fail++; + fflush(stdout); + pid = fork(); + if (!pid) { + int rc = xfade_test(dir); + fflush(stdout); + _exit(rc); + } + waitpid(pid, &st, 0); + if (!WIFEXITED(st) || WEXITSTATUS(st)) + fail++; + } + printf("tracks: WAVs in %s: %s (mix), %s, %s, %s, %s, steal.wav, engine_switch.wav\n", dir, SOLO[0], SOLO[1], SOLO[2], SOLO[3], SOLO[4]); + /* one part: every preset with 8 held notes (the engine's cap: VOICE 4) + drums; the worst one */ + for (e = 0; e < NENGINES; e++) + for (pi = 0; pi < ENGINES[e]->npresets; pi++) { + uint8_t parts[NPART][3] = {{(uint8_t)e, (uint8_t)pi, 8}, {0, 0, 0}, {0, 0, 0}}; + double c = tracks_cost(parts, 0); + if (c > best_e[e]) { + best_e[e] = c; + heavy[e] = pi; + } + if (c > worst) { + worst = c; + worst_e = e; + worst_p = pi; + } + } + printf("tracks: one part, 8 notes held + drums (host -O2, ns per sample, heaviest preset per engine):"); + for (e = 0; e < NENGINES; e++) + printf(" %s %s %.1f%s", ENGINES[e]->name, ENGINES[e]->presets[heavy[e]].name, best_e[e], e + 1u < NENGINES ? "," : "\n"); + { /* DIGITAL, PHASE, VOICE (their heaviest presets) at once: 3 + 3 + 2 notes = the budget of 8 */ + uint8_t parts[NPART][3] = {{1, (uint8_t)heavy[1], 3}, {2, (uint8_t)heavy[2], 3}, {5, (uint8_t)heavy[5], 2}}; + uint8_t full[NPART][3] = {{1, (uint8_t)heavy[1], 8}, {2, (uint8_t)heavy[2], 8}, {5, (uint8_t)heavy[5], 4}}; + uint8_t vv[NPART][3] = {{5, (uint8_t)heavy[5], 4}, {5, (uint8_t)heavy[5], 4}, {0, 0, 0}}; + uint8_t idle[NPART][3] = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}; + uint32_t bm2 = 0, bm3 = 0; + double two_voice, none; + four = tracks_cost(parts, &bm); + four_full = tracks_cost(full, &bm2); + two_voice = tracks_cost(vv, &bm3); + none = tracks_cost(idle, 0); + printf("tracks: worst single part: %s %s %.1f ns\n", ENGINES[worst_e]->name, ENGINES[worst_e]->presets[worst_p].name, worst); + printf("tracks: DIGITAL + PHASE + VOICE + drums, 3 + 3 + 2 notes: %.1f ns (%.2f x the worst single part), " + "%u voices\n", four, four / worst, bm); + printf("tracks: the same, 8 + 8 + 4 notes asked for (budget keeps %u): %.1f ns (%.2f x)\n", bm2, four_full, + four_full / worst); + printf("tracks: two VOICE parts, 4 + 4 voices (the heaviest 8 the budget allows): %.1f ns (%.2f x); " + "no notes (drums, buses, 3 idle parts): %.1f ns\n", two_voice, two_voice / worst, none); + if (bm > NVOICE || bm2 > NVOICE || bm3 > NVOICE) + fail++; + } + printf("tracks: %s\n", fail ? "FAILED" : "all checks ok"); + return fail; +} + +int main(int argc, char **argv) +{ + int eng = argc > 1 ? atoi(argv[1]) : 0, preset = argc > 2 ? atoi(argv[2]) : 4; + int mono = argc > 3 ? atoi(argv[3]) : 1; + const char *out = argc > 4 ? argv[4] : "out.wav"; + uint32_t i, frames = FS * (getenv("SWEEP") ? 4 : 2), f, nk = 0; + clock_t c0; + FILE *w = fopen(out, "wb"); + if (getenv("SECS")) + frames = FS * (uint32_t)atoi(getenv("SECS")); + if (getenv("CHORD")) + nk = atoi(getenv("CHORD")) > 4 ? (uint32_t)atoi(getenv("CHORD")) : 4u; + for (i = 0; i < G_COUNT; i++) song.g[i] = GP[i].def; + for (i = 0; i < P_E0; i++) inst.p[i] = TP[i].def; + inst.eng_req = inst.engine = (uint8_t)eng; + for (i = 0; i < 8; i++) inst.p[P_E0 + i] = ENGINES[eng]->edit[i].def; + if (ENGINES[eng]->npresets) { + const preset_t *p = &ENGINES[eng]->presets[preset % ENGINES[eng]->npresets]; + for (i = 0; i < 8; i++) inst.p[P_E0 + i] = p->e[i]; + inst.p[P_ATK] = p->env[0]; inst.p[P_DEC] = p->env[1]; + inst.p[P_SUS] = p->env[2]; inst.p[P_REL] = p->env[3]; inst.p[P_ED_FLT] = p->fenv; + preset_extras(inst.p, p); + } + inst.p[P_VOICE] = (int16_t)mono; + inst.p[P_CHOR] = argc > 5 ? atoi(argv[5]) : 24; /* as felucca_init */ + inst.p[P_DLY] = argc > 5 ? atoi(argv[5]) : 28; + inst.p[P_REV] = argc > 5 ? atoi(argv[5]) : 36; + if (getenv("PRESET")) /* PRESET=1: sends, ARP, voice mode too (then SENDS, PSET) */ + host_preset(&inst, (uint32_t)eng, (uint32_t)preset); + if (getenv("SENDS")) /* SENDS=chorus,delay,reverb */ + sscanf(getenv("SENDS"), "%hd,%hd,%hd", &inst.p[P_CHOR], &inst.p[P_DLY], &inst.p[P_REV]); + if (getenv("OCT")) /* OCT=o: keyboard octave shift (key 7 = C4 + 12 o) */ + song.octave = (int8_t)atoi(getenv("OCT")); + if (getenv("PSET")) { /* PSET=id:value,... (track parameter ids, P_E0 = 49) */ + const char *s = getenv("PSET"); + int id, val, k; + while (sscanf(s, "%d:%d%n", &id, &val, &k) == 2) { + if (id >= 0 && id < P_COUNT) + inst.p[id] = (int16_t)val; + s += k; + if (*s == ',') + s++; + } + } + if (getenv("STEPS")) { /* STEPS=n,n,...: a pattern (0 = rest) played by the sequencer */ + const char *s = getenv("STEPS"); + int nt, k, c = 0; + while (c < NSTEP && sscanf(s, "%d%n", &nt, &k) == 1) { + uint8_t u = (uint8_t)nt; + put_step(&inst, (uint32_t)c++, nt ? 1u : 0u, &u, nt ? ST_NOTE : ST_REST, 0); + s += k; + if (*s == ',') + s++; + } + inst.p[P_SLEN] = (int16_t)c; + transport_req = 1; + } + song.master_q12 = 4096; + if (getenv("TRACKS")) { + fclose(w); + remove(out); + return tracks_test(getenv("TRACKS")); + } + wav_hdr(w, frames); + c0 = clock(); + for (f = 0; f < frames; f += CTL) { + int32_t o[2 * CTL]; + uint32_t fp = f % (2u * FS); /* position in the repeating 2 s pattern */ + { /* C4 0.1-0.5 s, E4 0.45-0.8 s (overlap: legato/steal), G4 0.9-1.2 s */ + uint32_t n = 0, f = fp; + if (f > FS / 10 && f < FS / 2) n |= 1u << 7; + if (f > FS * 45 / 100 && f < FS * 8 / 10) n |= 1u << 11; + if (f > FS * 9 / 10 && f < FS * 12 / 10) n |= 1u << 14; + fm1_in.notes = getenv("STEPS") ? 0u : n; /* STEPS: only the sequencer plays */ + } + if (nk) { /* keys held 0.1-1.5 s (C E G B, then D F A C) */ + static const uint8_t K[8] = {7, 11, 14, 18, 9, 12, 16, 19}; + uint32_t n = 0, k; + for (k = 0; k < nk && k < 8u; k++) + n |= 1u << K[k]; + fm1_in.notes = (fp > FS / 10 && fp < FS * 3 / 2) ? n : 0; + } + if (getenv("DRUMS") && fp % (FS / 4u) < CTL) /* kick / closed hat / snare on 8ths */ + drum_on(fp % (FS / 2u) < CTL ? 36u : (fp / (FS / 4u)) % 4u == 3u ? 38u : 42u, 100u); + if (getenv("DIST")) + inst.p[P_DIST] = (int16_t)atoi(getenv("DIST")); + if (getenv("LEVEL")) + inst.p[P_LEVEL] = (int16_t)atoi(getenv("LEVEL")); + if (getenv("SWEEP")) { /* cutoff and resonance sweeps while a note is held */ + uint32_t t = f * 1000 / FS; /* ms */ + inst.p[P_E4] = (int16_t)((t / 4) % 256 < 128 ? (t / 4) % 128 : 127 - (t / 4) % 128); + inst.p[P_E5] = (int16_t)((t / 7) % 256 < 128 ? (t / 7) % 128 : 127 - (t / 7) % 128); + fm1_in.notes = (f > FS / 20) ? (1u << 7) : 0; + } + if (getenv("NOTE")) /* NOTE=k: one key (7 = C4, see OCT) held to 0.5 s before the end */ + fm1_in.notes = (f > FS / 20 && f + FS / 2 < frames) ? 1u << atoi(getenv("NOTE")) : 0; + if (getenv("VSWEEP")) /* VSWEEP=1: EDIT 1 (P_E0) from 0 to 127 over the render */ + inst.p[P_E0] = (int16_t)((uint64_t)f * 128u / frames); + if (getenv("PSWEEP")) { /* PSWEEP=id:from:to: a track parameter from .. to over the render */ + int id, a, b; + if (sscanf(getenv("PSWEEP"), "%d:%d:%d", &id, &a, &b) == 3 && id >= 0 && id < P_COUNT) + inst.p[id] = (int16_t)(a + (int64_t)(b - a) * f / frames); + } + mix_block(o, CTL); + { /* VOICES=1: report the most voices active at once (engine voice caps) */ + static uint32_t vmax, hi; + uint32_t k, a = 0; + for (k = 0; k < NVOICE; k++) + if (inst.v[k].active) { + a++; + hi |= 1u << k; + } + if (a > vmax) + vmax = a; + if (getenv("VOICES") && f + CTL >= frames) + fprintf(stderr, "voices: at most %u active, slots used 0x%02X\n", vmax, hi); + } + for (i = 0; i < 2 * CTL; i++) { + int16_t s = (int16_t)(o[i] > 32767 ? 32767 : o[i] < -32768 ? -32768 : o[i]); + fwrite(&s, 2, 1, w); + } + } + if (getenv("BENCH")) + fprintf(stderr, "%.1f s audio in %.1f ms (%.2f %% of real time)\n", (double)frames / FS, + (double)(clock() - c0) * 1000.0 / CLOCKS_PER_SEC, + (double)(clock() - c0) * 100.0 / CLOCKS_PER_SEC / ((double)frames / FS)); + fclose(w); + return 0; +} diff --git a/tests/install_test.py b/tests/install_test.py new file mode 100644 index 0000000..8ef074f --- /dev/null +++ b/tests/install_test.py @@ -0,0 +1,287 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-3.0-only +# Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments +"""tools/fm1_install.py against a simulated FM-1 (no hardware, no mido). +The fake device is the one in web/test_web.mjs: identity on the handshake, +then "device asks, host answers" reads of the logical image. Run from the repo root: + python3 tests/install_test.py +Also checks logical_image/product_of against web/fm1pkg.js (needs node and +build/felucca.fwsc, skipped otherwise).""" +import io +import queue +import shutil +import subprocess +import sys +import tempfile +import threading +import time +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[1] +sys.path.insert(0, str(ROOT / "tools")) +import fm1_install as I # noqa: E402 + +I.DELAY.update(open=0, start=0.01, reply=0, loader=0.01, reboot=0.01, retry=0.02, poll=0.05, hs=0.1, + idle_check=0.4, idle_write=0.4, wait_loader=2, wait_reboot=2) +failed = 0 + + +def ok(cond, what): + global failed + print(f"{what:<64} {'ok' if cond else 'FAIL'}") + failed += not cond + + +# ---------------------------------------------------------- simulated FM-1 --- + +class FakeLink: + def __init__(self, dev, gen): + self.dev, self.gen, self.q, self.closed = dev, gen, queue.Queue(), False + + @property + def lost(self): + return self.gen != self.dev.gen or not self.dev.connected + + def send(self, pkt): + if self.lost: + return False + self.dev.sent.append(bytes(pkt)) + self.dev.rx(bytes(pkt)) + return True + + def read(self, timeout): + try: + return self.q.get(timeout=max(timeout, 0)) + except queue.Empty: + return None + + def drain(self): + while not self.q.empty(): + self.q.get_nowait() + + def close(self): + self.closed = True + + +class FakeFM1: + """a MIDI backend with one FM-1 on it""" + + def __init__(self, image, identity="FM-1_015", name="FM-1", unplug_after=None, after_write="FM-1_900", + stall_after=None, bad_addr=None): + self.image, self.unplug_after, self.after_write = image, unplug_after, after_write + self.stall_after, self.bad_addr = stall_after, bad_addr + self.served = self.bad = self.upgrades = 0 + self.sent, self.links, self.gen, self.lock = [], [], 0, threading.Lock() + self.boot(identity, name) + + def boot(self, identity, name): + with self.lock: + self.gen += 1 + self.identity, self.name, self.connected = identity, name, True + self.waiting, self.queue = None, [] + + def input_names(self): + return [self.name] if self.connected else [] + + output_names = input_names + + def open(self, in_name, out_name): + if in_name != self.name or not self.connected: + raise IOError("no such port") + link = FakeLink(self, self.gen) + self.links.append(link) + return link + + def tx(self, pkt): + for link in self.links: + if link.gen == self.gen and not link.closed: + link.q.put(bytes(pkt)) + + def rx(self, d): + if d == I.HS_QUERY: + t = self.identity.encode() + self.tx(b"\xF0" + I.pack7(bytes([0, 0x59, 0x11, 0, 0, 0]) + t + bytes(28 - len(t))) + b"\xF7") + elif d == I.UPGRADE: + self.upgrades += 1 + first = self.bad_addr if self.bad_addr is not None else 0 + self.queue = ([(first + k * 512, 512) for k in range(6)] + [(I.FINISH_WRITE, 8)] + if self.identity.startswith("ota-") + else [(0, 64), (0x40, 160), (0x1000, 512), (I.FINISH_CHECK, 8)]) + self.next() + elif self.waiting: + u = I.unpack7(d[1:-1]) + addr, n = self.waiting + fin = addr >= I.FINISH_CHECK + want = b"success\0" if fin else self.image[addr:addr + n] + if u[14:14 + len(want)] != want or len(u) != 15 + len(want): + self.bad += 1 + self.waiting = None + self.served += 1 + if self.unplug_after and self.served >= self.unplug_after: + self.connected = False + return + if self.stall_after and self.served >= self.stall_after: + return + if addr == I.FINISH_CHECK: + threading.Timer(0.05, self.boot, ("ota-FM-1_900", "Felucca Update")).start() + elif addr == I.FINISH_WRITE: + threading.Timer(0.05, self.boot, (self.after_write, "Felucca")).start() + else: + self.next() + + def next(self): + if not self.queue: + return + self.waiting = addr, n = self.queue.pop(0) + u = bytearray([0, 0x59, 0x30, 0, 0, 0, 0]) + addr.to_bytes(4, "little") + bytes([n & 0xFF, n >> 8, 0]) + u.append(~sum(u[6:14]) & 0xFF) + self.tx(b"\xF0" + I.pack7(u) + b"\xF7") + + +# ----------------------------------------------------------------- helpers --- + +def package(product="FM-1_900", marker=True, size=0x2000): + raw = bytearray((i * 7) & 0xFF for i in range(size + I.BLOCKS)) + for i in range(I.BLOCKS): + raw[i * I.BLK + I.KEEP] = (ord(product[i]) + i + 1) & 0xFF if i < len(product) else 0x7D + raw[0x1800:0x1800 + 16] = I.LOADER_MARK if marker else bytes(16) + return bytes(raw) + + +TMP = Path(tempfile.mkdtemp(prefix="felucca-install-")) + + +def pkgfile(name, raw): + p = TMP / name + p.write_bytes(raw) + return str(p) + + +def cli(args, dev, answer=True): + out, err = io.StringIO(), io.StringIO() + old, sys.stderr = sys.stderr, err + try: + rc = I.main(args, backend=dev, out=out, ask=lambda _p: answer) + finally: + sys.stderr = old + return rc, out.getvalue(), err.getvalue() + + +# ------------------------------------------------------------------- tests --- + +def wire(): + data = bytes(range(256)) * 3 + ok(I.unpack7(I.pack7(data))[:len(data)] == data, "pack7 / unpack7 round trip") + pkt = I.response(0x12345, b"\x01\x02\x03", fl=5) + u = I.unpack7(pkt[1:-1]) + ok(u[:3] == b"\x00\x59\x30" and int.from_bytes(u[7:11], "little") == 0x12345 and u[14:17] == b"\x01\x02\x03" + and ~sum(u[6:17]) & 0xFF == u[17], "response: header, address, data, checksum") + raw = package("FM-1_906") + ok(I.product_of(raw) == "FM-1_906" and len(I.logical_image(raw)) == len(raw) - 20, "product_of / logical_image (synthetic)") + + +def installs(): + raw = package() + image = I.logical_image(raw) + p = pkgfile("ok.fwsc", raw) + + dev = FakeFM1(image) + rc, out, err = cli([p, "--yes"], dev) + ok(rc == 0 and dev.bad == 0 and dev.upgrades == 2 and dev.served == 11 and "done: the FM-1 runs FM-1_900" in out + and "100%" in out, f"install: running -> loader -> Felucca ({dev.served} reads)") + + dev = FakeFM1(image, identity="ota-FM-1_900", name="Felucca Update") + rc, out, err = cli([p, "--yes"], dev) + ok(rc == 0 and dev.bad == 0 and dev.upgrades == 1 and "update mode" in out, "install: device already in update mode -> finishes the write") + + dev = FakeFM1(image) + rc, out, err = cli([p], dev, answer=False) + ok(rc == 1 and dev.upgrades == 0 and "cancelled" in out, "install: answer no -> nothing sent but the handshake") + + dev = FakeFM1(image, identity="FM-1_905", name="Felucca") + rc, out, err = cli(["--info"], dev) + ok(rc == 0 and "FM-1_905" in out and "running" in out and dev.upgrades == 0, "--info: identity of the connected FM-1") + + dev = FakeFM1(image, identity="ota-FM-1_900", name="Felucca Update") + rc, out, err = cli(["--info"], dev) + ok(rc == 0 and "update loader" in out, "--info: device in update mode") + + +def errors(): + raw = package() + image = I.logical_image(raw) + p = pkgfile("ok.fwsc", raw) + + rc, out, err = cli([p, "--yes"], FakeFM1(image, name="IAC Driver Bus 1")) + ok(rc == 3 and "not found" in err and "IAC Driver" in err, "no FM-1 port -> exit 3, lists the MIDI inputs") + dev = FakeFM1(image) + rc, out, err = cli([p, "--yes", "--port", "Felucca"], dev) + ok(rc == 3 and dev.upgrades == 0, "--port that matches nothing -> exit 3") + dev = FakeFM1(image, name="My Interface") + rc, out, err = cli(["--info", "--port", "my int"], dev) + ok(rc == 0 and "FM-1_015" in out, "--port picks a port the default match skips") + + t0 = time.monotonic() + rc, out, err = cli([p, "--yes"], FakeFM1(image, unplug_after=2)) + ok(rc == 4 and "disconnected" in err and "nothing was written" in err and time.monotonic() - t0 < 3, + "unplugged in step 1 -> exit 4 'lost', nothing written") + t0 = time.monotonic() + rc, out, err = cli([p, "--yes"], FakeFM1(image, identity="ota-FM-1_900", name="Felucca Update", unplug_after=3)) + ok(rc == 4 and "run the install again" in err and time.monotonic() - t0 < 3, "unplugged during the write -> exit 4 at once") + rc, out, err = cli([p, "--yes"], FakeFM1(image, identity="ota-FM-1_900", name="Felucca Update", stall_after=3)) + ok(rc == 4 and "stopped answering" in err, "loader stops answering -> exit 4 after the idle time") + rc, out, err = cli([p, "--yes"], FakeFM1(image, identity="ota-FM-1_900", name="Felucca Update", bad_addr=len(image))) + ok(rc == 4 and "outside the package" in err, "read past the package -> exit 4") + + rc, out, err = cli([p, "--yes"], FakeFM1(image, after_write="FM-1_015")) + ok(rc == 6 and "reports FM-1_015" in err, "another identity after the restart -> exit 6") + dev = FakeFM1(image, identity="XY-9_001", name="usb-midi") + rc, out, err = cli([p, "--yes"], dev) + ok(rc == 6 and dev.upgrades == 0, "another model -> exit 6, nothing sent") + dev = FakeFM1(image, identity="ota-FM-1_015", name="FM-1 Update") + rc, out, err = cli([p, "--yes"], dev) + ok(rc == 6 and dev.upgrades == 0 and "another firmware" in err, "another firmware's update loader -> exit 6, nothing sent") + + class Stuck(FakeFM1): # the loader never shows up + def boot(self, identity, name): + super().boot(identity, name) + if identity.startswith("ota-"): + self.connected = False + rc, out, err = cli([p, "--yes"], Stuck(image)) + ok(rc == 5 and "loader did not appear" in err, "no loader after step 1 -> exit 5") + + plain = pkgfile("plain.fwsc", package(marker=False)) + dev = FakeFM1(image) + rc, out, err = cli([plain, "--yes"], dev) + ok(rc == 2 and "no Felucca update loader" in err and dev.sent == [], "package without the loader marker -> exit 2, no MIDI") + dev = FakeFM1(I.logical_image(package(marker=False))) + rc, out, err = cli([plain, "--yes", "--force"], dev) + ok(rc == 0 and dev.bad == 0, "... installs with --force") + rc, out, err = cli([pkgfile("short.fwsc", b"\0" * 100), "--yes"], FakeFM1(image)) + ok(rc == 2 and "too short" in err, "not a package -> exit 2") + rc, out, err = cli([str(TMP / "missing.fwsc"), "--yes"], FakeFM1(image)) + ok(rc == 2, "missing file -> exit 2") + + +def against_js(): + clean = ROOT / "build/felucca.fwsc" + if not shutil.which("node") or not clean.exists(): + print("logical image vs fm1pkg.js: skipped (needs node and build/felucca.fwsc)") + return + js = ("import { logicalImage, productOf } from %r; import { readFileSync } from 'node:fs';" + "const p = readFileSync(process.argv[1]); process.stderr.write(productOf(p));" + "process.stdout.write(logicalImage(p));") % str(ROOT / "web/fm1pkg.js") + r = subprocess.run(["node", "--input-type=module", "-e", js, str(clean)], capture_output=True, check=True) + raw = clean.read_bytes() + ok(I.logical_image(raw) == r.stdout and I.product_of(raw) == r.stderr.decode(), + f"logical_image / product_of == fm1pkg.js ({clean.name}, {I.product_of(raw)})") + ok(I.LOADER_MARK in raw, f"{clean.name} carries the Felucca loader marker") + + +wire() +installs() +errors() +against_js() +shutil.rmtree(TMP, ignore_errors=True) +print(f"INSTALL TESTS FAILED ({failed})" if failed else "install tests passed") +sys.exit(1 if failed else 0) diff --git a/tests/ldr_test.c b/tests/ldr_test.c new file mode 100644 index 0000000..1268d38 --- /dev/null +++ b/tests/ldr_test.c @@ -0,0 +1,238 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* Host test of the Felucca update loader (firmware/loader/ldr_core.c): a fake + * host serves a package over the SysEx protocol, the "device" flash starts as + * another package's flash.bin (as if that firmware were installed). + * ldr_test OLD.fwsc NEW.fwsc */ +#include +#include +#include +#include + +#define FELUCCA_ID "ota-FM-1_900" +#define FELUCCA_OTA_DRYRUN 0 + +static uint8_t nor[0x100000], *logical; +static size_t logical_len; +static uint8_t rx[1024]; +static uint32_t rx_len, rx_full, now_ms, requests, erases, bad_range, record_cleared, f0_asked; +static uint32_t corrupt_at, corrupt_once, no_finish; /* the host serves a damaged byte / never says "success" */ + +static uint32_t pack7(const uint8_t *in, uint32_t n, uint8_t *out) +{ + uint32_t acc = 0, nb = 0, o = 0; + while (n--) { + acc |= (uint32_t)*in++ << nb; + nb += 8; + while (nb >= 7) { out[o++] = acc & 0x7F; acc >>= 7; nb -= 7; } + } + if (nb) out[o++] = acc & 0x7F; + return o; +} +static uint32_t unpack7h(const uint8_t *in, uint32_t n, uint8_t *out) +{ + uint32_t acc = 0, nb = 0, o = 0; + while (n--) { + acc |= (uint32_t)*in++ << nb; + nb += 7; + if (nb >= 8) { out[o++] = (uint8_t)acc; acc >>= 8; nb -= 8; } + } + return o; +} + +static int ota_wire_send(const uint8_t *p, uint32_t n) +{ + uint8_t u[64], m[600]; + uint32_t addr, len, i, s = 0; + unpack7h(p + 1, n - 2, u); + if (u[2] == 0x11) return 0; + addr = u[7] | u[8] << 8 | u[9] << 16 | (uint32_t)u[10] << 24; + len = u[11] | u[12] << 8 | u[13] << 16; + requests++; + memcpy(m, "\x00\x59\x30", 3); + m[3] = (uint8_t)(len + 8); m[4] = (uint8_t)((len + 8) >> 8); m[5] = 0; m[6] = 0; + memcpy(m + 7, &addr, 4); + m[11] = (uint8_t)len; m[12] = (uint8_t)(len >> 8); m[13] = 0; + if (addr == 0xF0000000u && no_finish) { + f0_asked++; + return 0; /* no reply */ + } + if (addr >= 0xE0000000u) { + f0_asked += addr == 0xF0000000u; + memset(m + 14, 0, len); + memcpy(m + 14, "success", 8); + } else { + if (addr + len > logical_len) { printf("read past the package %#x\n", addr); exit(1); } + memcpy(m + 14, logical + addr, len); + if (corrupt_at && addr <= corrupt_at && corrupt_at < addr + len) { + m[14 + corrupt_at - addr] ^= 0x08; /* (the frame's own checksum is fine: only the CRC sees it) */ + if (corrupt_once) + corrupt_at = 0; + } + } + for (i = 6; i < 14 + len; i++) s += m[i]; + m[14 + len] = (uint8_t)~s; + rx_len = pack7(m, 15 + len, rx); + rx_full = 1; + return 0; +} +static int ota_frame_get(const uint8_t **p, uint32_t *n) { if (!rx_full) return 0; *p = rx; *n = rx_len; return 1; } +static void ota_frame_done(void) { rx_full = 0; } +static uint32_t ota_now_ms(void) { return now_ms; } +static void ota_idle(void) { now_ms++; } +static int ota_erase(uint32_t off) { (void)off; return -1; } +static int ota_prog(uint32_t off, const void *p, uint32_t n) { (void)off; (void)p; (void)n; return -1; } +static int ota_fread(uint32_t off, void *p, uint32_t n) { memcpy(p, nor + off, n); return 0; } +static void ota_show(uint32_t step, int32_t code) { (void)step; (void)code; } +static void ota_commit(const uint8_t *parm) { (void)parm; } +#include "../firmware/src/ota.c" + +static int ldr_fread(uint32_t off, void *p, uint32_t n) { memcpy(p, nor + off, n); return 0; } +static int ldr_erase(uint32_t off) +{ + if (off < 0x4000u || off >= 0xFC000u || (off & 0xFFFu)) bad_range++; + if (off < 0x4000u) { printf("ERASE IN THE HEAD %#x\n", off); exit(1); } + erases++; + memset(nor + off, 0xFF, 0x1000); + return 0; +} +static int ldr_prog(uint32_t off, const void *p, uint32_t n) +{ + const uint8_t *s = p; + uint32_t i; + if (off < 0x4000u || off + n > 0x93000u || ((off & 0xFFu) + n) > 256u) bad_range++; + for (i = 0; i < n; i++) nor[off + i] &= s[i]; + return 0; +} +static void ldr_record_clear(void) { record_cleared++; } +static uint32_t flash_unknown; +static int ldr_flash_known(void) { return !flash_unknown; } +static void ldr_progress(uint32_t done, uint32_t total) { (void)done; (void)total; } +#include "../firmware/loader/ldr_core.c" + +static uint8_t *load_logical(const char *path, size_t *len) +{ + FILE *f = fopen(path, "rb"); + uint8_t *raw = malloc(0x200000), *lg; + size_t n, i; + if (!f) { perror(path); exit(2); } + n = fread(raw, 1, 0x200000, f); + fclose(f); + lg = malloc(n); + for (i = 0; i < 20; i++) memcpy(lg + i * 47, raw + i * 48, 47); + memcpy(lg + 20 * 47, raw + 20 * 48, n - 20 * 48); + *len = n - 20; + free(raw); + return lg; +} + +static uint32_t flash_off(const uint8_t *lg) /* flash.bin offset in the logical image */ +{ + uint8_t h[0x400]; + uint32_t i, n; + memcpy(h, lg, sizeof h); + ota_jl_enc(h, 0x40); + n = ota_rd16(h + 8); + for (i = 0; i < n; i++) { + uint8_t *e = h + 0x40 + i * 0x50u; + ota_jl_enc(e, 0x50); + if (ota_rd16(e) == 0) return ota_rd32(e + 8); + } + return 0; +} + +static int check(const char *what, int ok) { printf("%-56s %s\n", what, ok ? "ok" : "FAIL"); return ok ? 0 : 1; } + +static void put_record(void) /* a valid update record at 0xE4F00 (the SPL runs the loader) */ +{ + uint8_t r[112] = {0}; + r[2] = 0x0D; r[3] = 0x5A; r[4] = 0x01; r[5] = 0x5A; r[6] = 0x41; r[7] = 0x54; + ota_wr16(r, ota_crc16(r + 2, 78, 0)); + memcpy(nor + 0xE4F00, r, sizeof r); +} + +int main(int argc, char **argv) +{ + size_t olen; + uint8_t *old, head[0x4000]; + uint32_t ofo, nfo; + int bad = 0, rc; + if (argc < 3) { printf("usage: ldr_test OLD.fwsc NEW.fwsc\n"); return 2; } + old = load_logical(argv[1], &olen); + logical = load_logical(argv[2], &logical_len); + ofo = flash_off(old); + nfo = flash_off(logical); + /* device: OLD installed, plus a valid update record at 0xE4F00 */ + memset(nor, 0xFF, sizeof nor); + memcpy(nor, old + ofo, 0x93000); + memcpy(head, nor, sizeof head); + put_record(); + rc = ldr_session(); + printf(" rc %d, %u requests, %u sector erases\n", rc, requests, erases); + bad += check("install completes", rc == 0); + bad += check("app area == the new package's flash.bin", !memcmp(nor + 0x4000, logical + nfo + 0x4000, 0x93000 - 0x4000)); + bad += check("flash head [0, 0x4000) untouched", !memcmp(nor, head, sizeof head)); + bad += check("finish asked (0xF0000000)", f0_asked >= 1); + bad += check("update record cleared (RAM + flash)", record_cleared && nor[0xE4F06] == 0xFF); + bad += check("no write outside the allowed windows", bad_range == 0); + /* same package again: nothing to erase */ + erases = 0; requests = 0; + rc = ldr_session(); + bad += check("re-run with the same package erases nothing", rc == 0 && erases == 0); + /* a package for another chip key is refused before any erase */ + { + uint8_t save = logical[nfo + 0x4000 + 5]; + logical[nfo + 0x4000 + 5] ^= 0x5A; /* app area head no longer decrypts */ + memcpy(nor, old + ofo, 0x93000); + erases = 0; + rc = ldr_session(); + bad += check("foreign key / damaged app head refused, nothing erased", rc == -6 && erases == 0); + logical[nfo + 0x4000 + 5] = save; + } + /* one bit damaged on the way, once: the CRC sees it, the next pass rewrites that sector */ + { + const uint8_t r6 = 0x41; /* byte 6 of a valid record ("AT"); 0xFF once erased */ + memcpy(nor, old + ofo, 0x93000); + put_record(); + record_cleared = 0; + corrupt_at = nfo + 0x30123u; + corrupt_once = 1; + rc = ldr_session(); + bad += check("a byte damaged once: caught by the CRC, fixed by a 2nd pass", rc == 0 && record_cleared + && nor[0xE4F06] == 0xFF && !memcmp(nor + 0x4000, logical + nfo + 0x4000, 0x93000 - 0x4000)); + /* the package itself damaged (every pass): the record stays, nothing is booted */ + memcpy(nor, old + ofo, 0x93000); + put_record(); + record_cleared = 0; + corrupt_at = nfo + 0x30123u; + corrupt_once = 0; + rc = ldr_session(); + bad += check("a damaged package: refused after 3 passes, the record stays", rc == -12 && !record_cleared + && nor[0xE4F06] == r6); + corrupt_at = nfo + 0x100u; /* in the head: never written, still checked */ + rc = ldr_session(); + bad += check("... also when the damage is in the head", rc == -12 && !record_cleared); + corrupt_at = 0; + /* no "success" from the host: the record stays (the host can finish later) */ + no_finish = 1; + rc = ldr_session(); + bad += check("no \"success\" from the host: the record stays", rc == -13 && !record_cleared && nor[0xE4F06] == r6); + no_finish = 0; + rc = ldr_session(); + bad += check("... and the next session finishes", rc == 0 && record_cleared && nor[0xE4F06] == 0xFF); + } + /* another flash chip: nothing written, the records go (the old firmware starts again) */ + { + memcpy(nor, old + ofo, 0x93000); + put_record(); + record_cleared = 0; + erases = 0; + flash_unknown = 1; + rc = ldr_session(); + bad += check("unknown flash chip: nothing written, record dropped", rc == -14 && record_cleared && erases == 1 + && nor[0xE4F06] == 0xFF && !memcmp(nor, old + ofo, 0x93000)); + flash_unknown = 0; + } + printf("%s\n", bad ? "LOADER TEST FAILED" : "loader test passed"); + return bad != 0; +} diff --git a/tests/midi_uart_test.c b/tests/midi_uart_test.c new file mode 100644 index 0000000..f70357c --- /dev/null +++ b/tests/midi_uart_test.c @@ -0,0 +1,144 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* Host test of the MIDI input parsers: the running-status parser in + * firmware/src/midi_uart.c (um_byte) and the USB-MIDI SysEx path of firmware/src/usb.c + * (sysex_byte frame assembly, ota_wire_send packetising). */ +#include +#include +#include +#define RING_PUBLISH() __asm__ volatile("" ::: "memory") +#define FELUCCA_OTA 1 +#define FELUCCA_CDC 0 +static void fm1_delay_ms(uint32_t ms) { (void)ms; } +#pragma GCC diagnostic ignored "-Wint-to-pointer-cast" /* SIE register macros (never touched here) */ +#include "../firmware/src/usb.c" +#include "../firmware/src/midi_uart.c" + +static uint32_t now_ms; +static uint32_t ota_now_ms(void) { return now_ms; } +static void ota_idle(void) { now_ms++; } + +static int check(const char *what, int ok) +{ + printf("%-52s %s\n", what, ok ? "ok" : "FAIL"); + return ok ? 0 : 1; +} + +static void feed(const uint8_t *p, uint32_t n) +{ + while (n--) + sysex_byte(*p++); +} + +/* the queued SysEx packets back to bytes, as the host's USB-MIDI driver does */ +static uint32_t drain(uint8_t *out, int *cin_ok) +{ + uint32_t n = 0; + *cin_ok = 1; + while (so_r != so_w) { + uint32_t pkt = sx_out_q[so_r++ % SXQ], cin = pkt & 15u, k; + uint32_t nb = cin == 4u || cin == 7u ? 3u : cin == 6u ? 2u : cin == 5u ? 1u : 0u; + if (!nb || (cin == 4u) != (so_r != so_w)) /* 4 except the last, which ends (5/6/7) */ + *cin_ok = 0; + for (k = 0; k < nb; k++) + out[n++] = (uint8_t)(pkt >> (8u * (k + 1u))); + } + return n; +} + +static int test_usb_sysex(void) +{ + static uint8_t msg[700], got[700]; + uint32_t n, i; + int bad = 0, enc_ok = 1, rt_ok = 1, cin_ok; + usb.config = 1; + for (n = 2; n <= 40u; n++) { /* every length mod 3, through the ring */ + msg[0] = 0xF0; + for (i = 1; i + 1u < n; i++) + msg[i] = (uint8_t)((i * 37u + n) & 0x7Fu); + msg[n - 1] = 0xF7; + if (ota_wire_send(msg, n) || drain(got, &cin_ok) != n || memcmp(got, msg, n) || !cin_ok || sx_busy) + enc_ok = 0; + feed(got, n); + if (n > 2u && (!sx_ready || sx_frame_len != n - 2u || memcmp(sx_frame, msg + 1, n - 2u))) + rt_ok = 0; + ota_frame_done(); + } + bad += check("usb: ota_wire_send packets (CIN 4.. then 5/6/7)", enc_ok); + bad += check("usb: received frame == the bytes between F0 and F7", rt_ok); + + feed((const uint8_t *)"\xF0\x01\x02\xF7", 4); + feed((const uint8_t *)"\xF0\x03\x04\x05\xF7", 5); + bad += check("usb: a frame while one is pending is dropped", + sx_ready && sx_frame_len == 2u && sx_frame[0] == 1 && sx_frame[1] == 2); + ota_frame_done(); + feed((const uint8_t *)"\xF0\x11\x12", 3); /* cut off by the next F0 */ + feed((const uint8_t *)"\xF0\x21\xF7", 3); + bad += check("usb: a truncated frame is replaced by the next one", + sx_ready && sx_frame_len == 1u && sx_frame[0] == 0x21); + ota_frame_done(); + msg[0] = 0xF0; + memset(msg + 1, 0x55, sizeof msg - 2u); + msg[sizeof msg - 1u] = 0xF7; + feed(msg, sizeof msg); + bad += check("usb: an oversized frame (698 B) is not taken", !sx_ready); + feed((const uint8_t *)"\xF0\x22\x24\x35\x7D\xF7", 6); + bad += check("usb: soft key -> uboot_req, not a frame", usb.uboot_req && !sx_ready); + feed((const uint8_t *)"\xF0\x22\x24\x35\x7F\xF7", 6); + bad += check("usb: upgrade key -> ota_req, not a frame", usb.ota_req && !sx_ready); + feed((const uint8_t *)"\x22\x24\xF7", 3); /* no F0: ignored */ + bad += check("usb: bytes outside F0..F7 are ignored", !sx_ready); + + so_w = so_r + SXQ; /* ring full ... */ + usb.config = 0; /* ... and the host gone */ + bad += check("usb: send with a full ring and no host fails at once", + ota_wire_send(msg, 9) == -1 && !sx_busy && now_ms == 0); + usb.config = 1; + bad += check("usb: send with a full ring times out (200 ms)", + ota_wire_send(msg, 9) == -1 && !sx_busy && now_ms > 200u && now_ms < 210u); + so_r = so_w; + return bad; +} + +int main(void) +{ + static const uint8_t in[] = { + 0x90, 60, 100, 62, 101, /* note on + running status */ + 0xF8, 64, 0xFE, 102, /* realtime inside a message */ + 0xC1, 5, 6, /* program change + running */ + 0xF0, 0x22, 0x24, 0x35, 0x7D, 0xF7, 70, 71, /* SysEx dropped; cancels running status */ + 0xB0, 7, 0x7F, 0xF2, 1, 2, 9, 9, /* CC, song position (dropped), data without status */ + 0x80, 60, 0, + }; + static const uint32_t want[] = { + 0x643C9009u, 0x653E9009u, 0x66409009u, 0x0005C10Cu, 0x0006C10Cu, 0x7F07B00Bu, 0x003C8008u, + }; + uint32_t i, bad = 0, n = sizeof want / sizeof want[0]; + for (i = 0; i < sizeof in; i++) + um_byte(in[i]); + if (mi_w != n) { + printf("got %u packets, want %u\n", mi_w, n); + bad = 1; + } + for (i = 0; i < n && i < mi_w; i++) + if (midi_in_q[i] != want[i]) { + printf("pkt %u: %08x want %08x\n", i, midi_in_q[i], want[i]); + bad = 1; + } + bad += (uint32_t)check("uart: running status, realtime, SysEx, system common", !bad); + { /* 4-track routing reads the channel from the packet as for USB-MIDI: cable 0, CIN = status >> 4 */ + static const uint8_t chs[] = {0x90, 60, 1, 0x91, 61, 2, 0x92, 62, 3, 0x99, 36, 4, 0x9F, 63, 5, 0x89, 36, 0}; + uint32_t w0 = mi_w, ok = 1; + for (i = 0; i < sizeof chs; i++) + um_byte(chs[i]); + for (i = 0; i < 6u; i++) { + uint32_t pkt = midi_in_q[(w0 + i) % MQ], st = chs[3u * i]; + ok &= mi_w == w0 + 6u && (pkt & 0xFFu) == (st >> 4) && ((pkt >> 8) & 0xFFu) == st && + ((pkt >> 16) & 0x7Fu) == chs[3u * i + 1u] && (pkt >> 24) == chs[3u * i + 2u]; + } + bad += (uint32_t)check("uart: channels 1, 2, 3, 10, 16 -> USB-MIDI packets", ok); + } + bad += (uint32_t)test_usb_sysex(); + printf("%s\n", bad ? "MIDI PARSER TEST FAILED" : "midi parser test passed"); + return (int)bad; +} diff --git a/tests/ota_test.c b/tests/ota_test.c new file mode 100644 index 0000000..88d1b6f --- /dev/null +++ b/tests/ota_test.c @@ -0,0 +1,231 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* Host test of firmware/src/ota.c: a fake M-UPGRADE serves a real .fwsc over + * the SysEx protocol (pack7, cmd 0x30 reads, 0xE0000000 -> "success") and a + * simulated NOR plays the flash. + * cc -o ota_test tests/ota_test.c && ./ota_test FILE.fwsc + */ +#include +#include +#include +#include + +#define FELUCCA_ID "FM-1_900" +#define FELUCCA_OTA_DRYRUN 0 +static int recovery_active; +#define OTA_IDENTITY (recovery_active ? "FM-1_000" : FELUCCA_ID) + +static uint8_t nor[0x100000]; +static uint8_t *logical; +static size_t logical_len; +static uint8_t rx[1024]; /* one pending host frame (7-bit bytes) */ +static uint32_t rx_len, rx_full; +static uint32_t now_ms, requests, ident_replies, mute_after = 0xFFFFFFFFu, bad_erase; +static int committed; +static uint8_t committed_parm[112]; +static int32_t last_code; +static uint8_t *corrupt_at; /* flip a served byte (loader body) */ + +static uint32_t pack7(const uint8_t *in, uint32_t n, uint8_t *out) +{ + uint32_t acc = 0, nb = 0, o = 0; + while (n--) { + acc |= (uint32_t)*in++ << nb; + nb += 8; + while (nb >= 7) { out[o++] = acc & 0x7F; acc >>= 7; nb -= 7; } + } + if (nb) out[o++] = acc & 0x7F; + return o; +} + +static uint32_t unpack7h(const uint8_t *in, uint32_t n, uint8_t *out) +{ + uint32_t acc = 0, nb = 0, o = 0; + while (n--) { + acc |= (uint32_t)*in++ << nb; + nb += 7; + if (nb >= 8) { out[o++] = (uint8_t)acc; acc >>= 8; nb -= 8; } + } + return o; +} + +static void host_reply(const uint8_t *msg, uint32_t n) /* queue msg as a device-bound frame */ +{ + rx_len = pack7(msg, n, rx); + rx_full = 1; +} + +/* ---- hooks ---- */ +static int ota_wire_send(const uint8_t *p, uint32_t n) +{ + uint8_t u[64], m[600]; + uint32_t d, addr, len, i, s = 0; + if (p[0] != 0xF0 || p[n - 1] != 0xF7) { printf("bad wire framing\n"); exit(1); } + d = unpack7h(p + 1, n - 2, u); + if (u[2] == 0x11) { ident_replies++; return 0; } + if (d != 15 || u[2] != 0x30) { printf("unexpected device msg cmd %02x len %u\n", u[2], d); exit(1); } + addr = u[7] | u[8] << 8 | u[9] << 16 | (uint32_t)u[10] << 24; + len = u[11] | u[12] << 8 | u[13] << 16; + if (++requests > mute_after) + return 0; /* host gone */ + memcpy(m, "\x00\x59\x30", 3); + m[3] = (uint8_t)(len + 8); m[4] = (uint8_t)((len + 8) >> 8); m[5] = 0; + m[6] = 0; + memcpy(m + 7, &addr, 4); + m[11] = (uint8_t)len; m[12] = (uint8_t)(len >> 8); m[13] = 0; + if (addr == 0xE0000000u) { + memset(m + 14, 0, len); + memcpy(m + 14, "success", 8); + } else { + if (addr + len > logical_len) { printf("read past the package %#x\n", addr); exit(1); } + memcpy(m + 14, logical + addr, len); + if (corrupt_at && corrupt_at >= logical + addr && corrupt_at < logical + addr + len) + m[14 + (corrupt_at - (logical + addr))] ^= 0x01; + } + for (i = 6; i < 14 + len; i++) s += m[i]; + m[14 + len] = (uint8_t)~s; + host_reply(m, 15 + len); + return 0; +} +static int ota_frame_get(const uint8_t **p, uint32_t *n) +{ + if (!rx_full) return 0; + *p = rx; *n = rx_len; + return 1; +} +static void ota_frame_done(void) { rx_full = 0; } +static uint32_t ota_now_ms(void) { return now_ms; } +static void ota_idle(void) { now_ms += 1; } +static int ota_erase(uint32_t off) +{ + if (off < 0xE0000u || off >= 0xE5000u || (off & 0xFFFu)) { bad_erase++; return -8; } + memset(nor + off, 0xFF, 4096); + return 0; +} +static int ota_prog(uint32_t off, const void *src, uint32_t n) +{ + const uint8_t *s = src; + uint32_t i; + if (off < 0xE0000u || off + n > 0xE5000u) { bad_erase++; return -8; } + for (i = 0; i < n; i++) nor[off + i] &= s[i]; + return 0; +} +static int ota_fread(uint32_t off, void *dst, uint32_t n) { memcpy(dst, nor + off, n); return 0; } +static void ota_show(uint32_t step, int32_t code) { if (step == 9) last_code = code; } +static void ota_commit(const uint8_t *parm) { committed = 1; memcpy(committed_parm, parm, 112); } + +#include "../firmware/src/ota.c" + +static uint32_t ota_body_off(void) /* ota.bin data + 0x20 in the logical image */ +{ + uint8_t h[0x400]; + uint32_t i, n; + memcpy(h, logical, sizeof h); + ota_jl_enc(h, 0x40); + n = ota_rd16(h + 8); + for (i = 0; i < n; i++) { + uint8_t *e = h + 0x40 + i * 0x50u; + ota_jl_enc(e, 0x50); + if (ota_rd16(e) == 100) return ota_rd32(e + 8) + 0x20u; + } + return 0; +} + +static int check(const char *what, int ok) +{ + printf("%-52s %s\n", what, ok ? "ok" : "FAIL"); + return ok ? 0 : 1; +} + +static int area_erased(void) +{ + uint32_t i; + for (i = 0xE0000; i < 0xE5000; i++) if (nor[i] != 0xFF) return 0; + return 1; +} + +static void reset_dev(void) +{ + memset(nor, 0xFF, sizeof nor); + memcpy(nor, logical + 0x400, 0x4000); /* device flash head = package flash.bin head */ + rx_full = 0; requests = 0; ident_replies = 0; committed = 0; last_code = 0; + mute_after = 0xFFFFFFFFu; corrupt_at = NULL; bad_erase = 0; +} + +int main(int argc, char **argv) +{ + FILE *f; + uint8_t *raw; + size_t n, i; + int bad = 0, rc; + if (argc < 2) { printf("usage: ota_test FILE.fwsc\n"); return 2; } + f = fopen(argv[1], "rb"); + if (!f) { perror(argv[1]); return 2; } + raw = malloc(0x200000); + n = fread(raw, 1, 0x200000, f); + fclose(f); + logical = malloc(n); + for (i = 0; i < 20; i++) memcpy(logical + i * 47, raw + i * 48, 47); /* drop the marker bytes */ + memcpy(logical + 20 * 47, raw + 20 * 48, n - 20 * 48); + logical_len = n - 20; + + /* handshake outside a session */ + reset_dev(); + { + uint8_t m[7] = {0, 0x59, 0x11, 0, 0, 0, 0xFF}; + host_reply(m, 7); + ota_service(); + bad += check("handshake answered", ident_replies == 1); + bad += check("identity frame is " FELUCCA_ID, + ota_msg[2] == 0x11 && !memcmp(ota_msg + 6, FELUCCA_ID, sizeof FELUCCA_ID - 1)); + recovery_active = 1; + host_reply(m, 7); + ota_service(); + bad += check("recovery identity is distinct from a successful normal boot", + ident_replies == 2 && !memcmp(ota_msg + 6, "FM-1_000", 9)); + recovery_active = 0; + } + + /* full session */ + reset_dev(); + rc = ota_session(); + printf(" %u requests\n", requests); + bad += check("session commits", rc == 0 && committed); + bad += check("headers + loader + confirm, no head reads", requests >= 10 && requests <= 30); + { + uint8_t *h = nor + 0xE0000, *p = committed_parm; + bad += check("staged body == the package's loader", !memcmp(nor + 0xE0020, logical + ota_body_off(), 64)); + bad += check("LOADER.BIN head CRC", + (h[0] | h[1] << 8) == ota_crc16(h + 2, 30, 0) && !memcmp(h + 16, "LOADER.BIN", 10)); + bad += check("record at 0xE4F00 == RAM record", !memcmp(nor + 0xE4F00, p, 112)); + bad += check("record CRC / type / magic / ota_addr", + (p[0] | p[1] << 8) == ota_crc16(p + 2, 78, 0) && (p[2] | p[3] << 8) == 0x5A0D && + (p[6] | p[7] << 8) == 0x5441 && ota_rd32(p + 72) == 0xE0000); + bad += check("nothing written outside 0xE0000..0xE4FFF", bad_erase == 0); + } + /* boot cleanup erases it */ + bad += check("boot cleanup erases the area", ota_boot_cleanup() == 1 && area_erased()); + bad += check("second boot: nothing to do", ota_boot_cleanup() == 0); + + /* host disappears in the middle */ + reset_dev(); + mute_after = 4; + rc = ota_session(); + bad += check("host gone -> no commit, area clean", rc < 0 && !committed && area_erased()); + + /* host never confirms */ + reset_dev(); + mute_after = 0xFFFFFFFFu; + { + uint32_t total; + rc = ota_session(); + total = requests; /* requests of a full run incl. confirm */ + reset_dev(); + mute_after = total - 1; /* answer everything but the confirmation */ + rc = ota_session(); + bad += check("no 'success' -> -13, no commit, area clean", rc == -13 && !committed && area_erased()); + } + + printf("%s\n", bad ? "OTA TEST FAILED" : "ota test passed"); + return bad != 0; +} diff --git a/tests/pitch.py b/tests/pitch.py new file mode 100644 index 0000000..e923b26 --- /dev/null +++ b/tests/pitch.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-3.0-only +# Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments +"""YIN pitch of hostsim renders (4000 samples from 0.25 s, the held note). + + tests/pitch.py build/host/render.wav ... +""" +import sys +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "tools")) +from sampleio import read_any_wav, yin # noqa: E402 + +for f in sys.argv[1:]: + sr, x = read_any_wav(Path(f)) + a = int(0.25 * sr) + print(f"{f}: {yin(x[a:a + 4000], sr, interpolate=False):.1f} Hz") diff --git a/tests/project_test.c b/tests/project_test.c new file mode 100644 index 0000000..18c9ef3 --- /dev/null +++ b/tests/project_test.c @@ -0,0 +1,244 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* Host test of the project formats (firmware/src/project.c, -DPROJ_HOST part). Format 4 ("FUN4", + * SLOOP 2.0: 10-byte steps with levels and ratchets, the drum track's 16 lanes, P_CHORD) is written; + * format 3 ("FUN3", SLOOP 1.x), format 2 ("FUN2", 53 parameters per track) and format 1 ("FUN1"), built + * byte for byte as the firmware stored them, convert: every old value at its parameter, the parameters + * added since at their defaults, the swings onto the MPC scale (x 0.8), synth steps as they were, the + * drum track's notes onto its lanes (accent: hard), globals, selection, the engine bytes (kept; the + * drum track's 0); damaged ones are refused. Run by tests/run_tests.sh (needs build/gen). */ +#define main hostsim_main +#include "hostsim.c" +#undef main +#define PROJ_HOST 1 +static uint32_t trk_def_engine(uint32_t i) /* ui.c TRK_DEF: ANALOG, DIGITAL, LOFI */ +{ + static const uint8_t E[NPART] = {0, 1, 3}; + return i < NPART ? E[i] : 0u; +} +#include "../firmware/src/project.c" + +static int check(const char *what, int ok) +{ + printf("%-66s %s\n", what, ok ? "ok" : "FAIL"); + return ok ? 0 : 1; +} + +/* the value parameter k (old id) of track t had in the old project */ +static int16_t oldv(uint32_t t, uint32_t k) { return (int16_t)(t * 100u + k * 3u + 1u); } + +static const uint8_t OLD_ENG[NTRK] = {7, 0, 6, 8}; /* WHEEL, ANALOG, TRIO; the drum track: 8 (none) */ +static void fill_old_steps(step8_t *st, uint32_t t) +{ + uint32_t k; + for (k = 0; k < NSTEP; k++) { + step8_t *s = &st[k]; + s->note[0] = (uint8_t)(36u + (k + t) % 40u); + s->note[1] = (uint8_t)(38u + k % 5u); + s->n = (uint8_t)(k % 3u); + s->time = (uint8_t)(k % 3u); + s->flags = (uint8_t)(k & 3u); + s->vel = (uint8_t)(64u + t); + } +} +static void fill_v2_track(proj_trk_v2_t *d, uint32_t t) +{ + uint32_t k; + for (k = 0; k < PROJ_NP_V2; k++) + d->p[k] = oldv(t, k); + d->engine = OLD_ENG[t]; + d->preset = (uint8_t)(t + 5u); + fill_old_steps(d->step, t); +} +static void fill_v3_track(proj_trk_v3_t *d, uint32_t t) +{ + uint32_t k; + for (k = 0; k < PROJ_NP_V3; k++) + d->p[k] = oldv(t, k); + d->p[P_SSWING] = 50; /* (swings: within 0..100) */ + d->p[P_ASWING] = 100; + d->engine = OLD_ENG[t]; + d->preset = (uint8_t)(t + 5u); + fill_old_steps(d->step, t); +} + +/* the steps of a converted track against the old ones: synth as they were, drums onto lanes */ +static int steps_ok(const proj_trk_t *n, const step8_t *o, int drum) +{ + uint32_t k, i; + for (k = 0; k < NSTEP; k++) { + if (drum) { + const dstep_t *d = &n->dstep[k]; + uint32_t want = 0; + if (o[k].time == ST_NOTE) + for (i = 0; i < o[k].n; i++) + want |= 1u << lane_of_note(o[k].note[i]); + if (dstep_mask(d) != want) + return 0; + for (i = 0; i < DRUM_LANES; i++) + if ((want >> i) & 1u && dstep_lvl(d, i) != ((o[k].flags & SF_ACCENT) ? LV_HARD : vel_lvl(o[k].vel))) + return 0; + } else { + const step_t *s = &n->step[k]; + if (memcmp(s->note, o[k].note, 4) || s->n != o[k].n || s->time != o[k].time || s->flags != o[k].flags || + s->vel != o[k].vel || s->lvl || s->rat) + return 0; + } + } + return 1; +} + +/* track t converted from format 2 / 1 has the old values where they belong */ +static int track_ok_v2(const proj_trk_t *n, const proj_trk_v2_t *o, uint32_t t) +{ + uint32_t k; + int ok = (t == TRK_DRUM ? n->engine == 0 && n->preset == 0 : n->engine == o->engine && n->preset == o->preset) && + steps_ok(n, o->step, t == TRK_DRUM); + for (k = 0; k <= P_DETUNE; k++) + if (k != P_SSWING && k != P_ASWING) + ok &= n->p[k] == oldv(t, k); + ok &= n->p[P_SLCR] == 0 && n->p[P_SLPAT] == TP[P_SLPAT].def && n->p[P_SLRATE] == TP[P_SLRATE].def && + n->p[P_SLDEPTH] == TP[P_SLDEPTH].def && n->p[P_CHORD] == 0; + for (k = 0; k < 8u; k++) + ok &= n->p[P_E0 + k] == oldv(t, 45u + k); + return ok; +} + +int main(void) +{ + static project_v3_t v3; + static project_v2_t v2; + static project_v1_t v1; + static project_t q, q2; + static union { + project_t v4; + project_v3_t v3; + project_v2_t v2; + project_v1_t v1; + } buf; + uint32_t i, t; + int bad = 0, ok; + + bad += check("layout: P_CHORD just before P_E0 (50), P_COUNT = format 3's + 1", + P_CHORD + 1 == P_E0 && P_E0 == 50 && P_COUNT == PROJ_NP_V3 + 1u && P_SLDEPTH + 1 == P_CHORD); + bad += check("format 4 fits one flash object; 4 slots fit .noinit", sizeof(project_t) <= 4096u - 256u && + 4u * sizeof(project_t) < 0x3D50u - 1024u); + + /* format 3 (SLOOP 1.x) */ + memset(&v3, 0, sizeof v3); + v3.magic = PROJ_MAGIC_V3; + v3.size = sizeof v3; + for (i = 0; i < PROJ_NG_V3; i++) + v3.g[i] = (int16_t)(300 + i); + v3.g[G_SWING] = 50; + v3.sel = 3; + for (t = 0; t < NTRK; t++) + fill_v3_track(&v3.t[t], t); + v3.sum = proj_hash(&v3, sizeof v3 - 4u); + memcpy(&buf, &v3, sizeof v3); + ok = proj_import(&q, &buf, (int)sizeof v3); + bad += check("FUN3 -> FUN4: converted, valid format 4 slot", ok && proj_ok(&q) && q.magic == PROJ_MAGIC); + ok = q.sel == 3 && q.g[G_SWING] == 40; + for (i = 0; i < PROJ_NG_V3; i++) + ok &= i == G_SWING || q.g[i] == (int16_t)(300 + i); + for (i = PROJ_NG_V3; i < G_COUNT; i++) + ok &= q.g[i] == GP[i].def; + bad += check("FUN3 -> FUN4: globals (swing 50 -> 40: the MPC scale), the new ones default", ok); + ok = 1; + for (t = 0; t < NTRK; t++) { + const proj_trk_t *n = &q.t[t]; + uint32_t k; + ok &= (t == TRK_DRUM ? n->engine == 0 : n->engine == OLD_ENG[t]) && steps_ok(n, v3.t[t].step, t == TRK_DRUM); + for (k = 0; k < PROJ_NP_V3 - 8u; k++) + if (k != P_SSWING && k != P_ASWING) + ok &= n->p[k] == oldv(t, k); + ok &= n->p[P_SSWING] == 40 && n->p[P_ASWING] == 80 && n->p[P_CHORD] == 0; + for (k = 0; k < 8u; k++) + ok &= n->p[P_E0 + k] == oldv(t, PROJ_NP_V3 - 8u + k); + } + bad += check("FUN3 -> FUN4: parameters (P_E0.. moved), steps, drum notes -> lanes", ok); + + /* format 2, as written before the SLICER */ + memset(&v2, 0, sizeof v2); + v2.magic = PROJ_MAGIC_V2; + v2.size = sizeof v2; + for (i = 0; i < PROJ_NG_V2; i++) + v2.g[i] = (int16_t)(500 + i); + v2.sel = 2; + for (t = 0; t < NTRK; t++) + fill_v2_track(&v2.t[t], t); + v2.sum = proj_hash(&v2, sizeof v2 - 4u); + bad += check("FUN2 image is 2552 bytes (as stored)", sizeof v2 == 2552u); + memcpy(&buf, &v2, sizeof v2); + ok = proj_import(&q, &buf, (int)sizeof v2); + bad += check("FUN2 -> FUN4: converted, valid format 4 slot", ok && proj_ok(&q) && q.magic == PROJ_MAGIC); + ok = q.sel == 2; + for (i = 0; i < PROJ_NG_V2; i++) + ok &= i == G_SWING || q.g[i] == (int16_t)(500 + i); + bad += check("FUN2 -> FUN4: globals and selected track", ok); + ok = 1; + for (t = 0; t < NTRK; t++) + ok &= track_ok_v2(&q.t[t], &v2.t[t], t); + bad += check("FUN2 -> FUN4: every parameter mapped, SLICER OFF, CHORD OFF (4 tracks)", ok); + bad += check("FUN2 -> FUN4: engine bytes kept (WHEEL 7, ANALOG 0, TRIO 6), drum 0", + q.t[0].engine == 7 && q.t[1].engine == 0 && q.t[2].engine == 6 && q.t[3].engine == 0 && + str_eq(ENGINES[7]->name, "WHEEL") && str_eq(ENGINES[6]->name, "TRIO") && NENGINES > 8); + + /* a FUN4 round trip: stored as is (an engine added since: 8) */ + q.t[1].engine = 8; + q.t[0].step[3].lvl = 0x9C; + q.t[0].step[3].rat = 0x27; + dstep_set(&q.t[TRK_DRUM].dstep[5], 13, LV_GHOST, 2); + q.sum = proj_sum(&q); + memcpy(&buf, &q, sizeof q); + bad += check("FUN4 -> FUN4: as stored (levels, ratchets, lanes, engine 8)", + proj_import(&q2, &buf, (int)sizeof q) && !memcmp(&q, &q2, sizeof q) && q2.t[1].engine == 8); + + /* damaged / wrong size */ + v2.t[1].p[3]++; + memcpy(&buf, &v2, sizeof v2); + bad += check("FUN2 with a bad checksum: refused", !proj_import(&q2, &buf, (int)sizeof v2)); + v2.t[1].p[3]--; + memcpy(&buf, &v2, sizeof v2); + bad += check("FUN2 with a wrong length: refused", !proj_import(&q2, &buf, (int)sizeof v2 - 2)); + memcpy(&buf, &q, sizeof q); + buf.v4.magic = PROJ_MAGIC_V3; + bad += check("FUN4 size with a FUN3 magic: refused", !proj_import(&q2, &buf, (int)sizeof q)); + memcpy(&buf, &v3, sizeof v3); + buf.v3.t[2].step[7].vel ^= 1u; + bad += check("FUN3 with a bad checksum: refused", !proj_import(&q2, &buf, (int)sizeof v3)); + + /* format 1: one instrument -> track 1, the others their defaults */ + memset(&v1, 0, sizeof v1); + v1.magic = PROJ_MAGIC_V1; + v1.size = sizeof v1; + for (i = 0; i < PROJ_NG_V2; i++) + v1.g[i] = (int16_t)(700 + i); + fill_v2_track(&v1.t, 0); + v1.sum = proj_hash(&v1, sizeof v1 - 4u); + memcpy(&buf, &v1, sizeof v1); + ok = proj_import(&q, &buf, (int)sizeof v1) && proj_ok(&q) && track_ok_v2(&q.t[0], &v1.t, 0) && q.g[5] == 705; + for (t = 1; t < NTRK; t++) + ok &= q.t[t].preset == 0xFF && q.t[t].p[P_SLCR] == 0 && q.t[t].p[P_LEVEL] == TP[P_LEVEL].def && + q.t[t].p[P_E0] == ENGINES[trk_def_engine(t)]->edit[0].def && + (t == TRK_DRUM ? dstep_mask(&q.t[t].dstep[0]) == 0u : q.t[t].step[0].time == ST_REST); + bad += check("FUN1 -> FUN4: track 1 mapped, tracks 2..4 defaults", ok); + + /* capture / apply: the working project round trip */ + host_tracks_init(); + for (t = 0; t < NTRK; t++) + trk[t].p[P_SLEN] = (int16_t)(5 + t); + trk[1].step[2].n = 2, trk[1].step[2].note[0] = 60, trk[1].step[2].note[1] = 64, trk[1].step[2].time = ST_NOTE; + trk[1].step[2].lvl = 0x0D; + dstep_set(&TDRUM->dstep[9], 4, LV_SOFT, 1); + song.g[G_DUST] = 33; + proj_capture(&q); + host_tracks_init(); + proj_apply(&q, 1); + ok = trk[2].p[P_SLEN] == 7 && trk[1].step[2].n == 2 && trk[1].step[2].lvl == 0x0D && song.g[G_DUST] == 33 && + dstep_has(&TDRUM->dstep[9], 4) && dstep_lvl(&TDRUM->dstep[9], 4) == LV_SOFT && dstep_rat(&TDRUM->dstep[9], 4) == 1u; + bad += check("the working project: capture -> apply round trip (levels, lanes, DUST)", ok); + + printf("%s\n", bad ? "PROJECT FORMAT TEST FAILED" : "project format test passed"); + return bad != 0; +} diff --git a/tests/punch_test.c b/tests/punch_test.c new file mode 100644 index 0000000..3bc306c --- /dev/null +++ b/tests/punch_test.c @@ -0,0 +1,132 @@ +/* SPDX-License-Identifier: GPL-3.0-only */ +/* PUNCH-IN FX (punch.c): each of the 16 effects changes the mix while held, stays bounded, + * and the mix is exactly the dry one again once its key is up (after the 64-sample fade). + * The FX-held keyboard picks effects with the white keys and never plays or records a note. + * argv[1]: a WAV demo (a beat, then every effect for one beat). */ +#define main hostsim_main +#include "hostsim.c" +#undef main +#include +#define BLOCKS (FS * 3u / CTL) /* 3 s at 120 BPM */ +static int32_t got[CTL * 2u]; + +static void beat_setup(void) +{ + static const uint8_t B[16][2] = {{36, 42}, {42}, {42}, {42}, {38, 42}, {42}, {42}, {36, 46}, + {36, 42}, {42}, {36}, {42}, {38, 42}, {42}, {42}, {46}}; + uint32_t j, q; + host_tracks_init(); + memset(&drums, 0, sizeof drums); + drums.set = -2; + TDRUM->p[P_E0] = 0; /* the sampled kit: no random noise */ + song.g[G_BPM] = 120; + for (j = 0; j < NSTEP; j++) { + step_t *s = &TDRUM->step[j]; + memset(s, 0, sizeof *s); + s->time = ST_REST; + if (j < 16u) + for (q = 0; q < 2u && B[j][q]; q++) { + s->note[s->n++] = B[j][q]; + s->time = ST_NOTE; + s->vel = 100; + } + } + TDRUM->p[P_SLEN] = 16; + punch.req = -1; + punch.cur = -1; + punch.g = 0; + punch.hold = 0; + clk_beat = 0; + clk_pos = 0; + transport_req = 1; +} + +/* a deterministic "mix": a decaying 110 Hz tone every quarter + noise bursts every 1/16 */ +static void test_mix(uint32_t b, int32_t *l, int32_t *r) +{ + static uint32_t seed = 1; + uint32_t i; + if (b == 0) seed = 1; + for (i = 0; i < CTL; i++) { + uint32_t t = b * CTL + i, q = t % (FS / 2u), s16 = t % (FS / 8u); + int32_t tone = (sine_i((uint32_t)t * 10712093u) * (int32_t)(FS / 2u - q) / (int32_t)(FS / 2u)) >> 1; + int32_t nz = s16 < 2000u ? (int32_t)((seed = seed * 1664525u + 1013904223u) >> 18) - 8192 : 0; + l[i] = (tone + nz) * 3; + r[i] = (tone - nz) * 3; + } +} + +int main(int argc, char **argv) +{ + uint32_t fx, i, b, on = FS / CTL, off = on + FS / 2u / CTL; /* held from 1 s to 1.5 s */ + FILE *f = argc > 1 ? fopen(argv[1], "wb") : 0; + for (fx = 0; fx < PUNCH_NFX; fx++) { + uint64_t diff = 0; + beat_setup(); + song.playing = 1; + clk_pos = 0; + for (b = 0; b < BLOCKS; b++) { + int32_t l[CTL], r[CTL], l0[CTL], r0[CTL]; + test_mix(b, l, r); + memcpy(l0, l, sizeof l), memcpy(r0, r, sizeof r); + if (b == on) punch.req = (int8_t)fx; + if (b == off) punch.req = -1; + punch_process(l, r, CTL); + clk_pos = (clk_pos + CTL * (uint32_t)song.g[G_BPM]) % BEAT_U; /* (the transport clock) */ + for (i = 0; i < CTL; i++) { + assert(l[i] > -(1 << 22) && l[i] < (1 << 22) && r[i] > -(1 << 22) && r[i] < (1 << 22)); + if (b < on || b >= off + 3u) + assert(l[i] == l0[i] && r[i] == r0[i]); /* dry before, dry again after */ + else + diff += (uint64_t)(l[i] > l0[i] ? l[i] - l0[i] : l0[i] - l[i]); + } + } + if (diff <= 2000u * (off - on)) + printf("fx %u (%s): diff %llu\n", fx, PUNCH_NAME[fx], (unsigned long long)diff); + assert(diff > 2000u * (off - on)); /* it did something */ + assert(punch.cur == -1); + song.playing = 0; + } + { /* the keyboard while FX is held: white keys pick effects; nothing sounds, nothing records */ + uint32_t k; + beat_setup(); + song.sel = 0; + song.rec = 1u; + mix_block(got, CTL); + ly_bit[LY_FX] = 1u << 2; /* FX held (seq.c layer_now) */ + fm1_in.buttons = ly_bit[LY_FX]; + for (k = 0; k < 27u; k++) { + int32_t w = punch_key(k); + fm1_in.notes = 1u << k; + events_block(CTL); + assert(w < 0 ? 1 : punch.req == w); + assert(!trk[0].step[0].n && !trk[0].v[0].active); + fm1_in.notes = 0; + events_block(CTL); + assert(punch.req == -1); + } + assert(punch_key(0) == 0 && punch_key(26) == 15); + fm1_in.buttons = 0; + song.rec = 0; + transport_req = 2; + events_block(CTL); + } + if (f) { /* demo: one beat dry, then each effect for one beat with a beat dry between */ + uint32_t beat = FS / 2u / CTL, b, total = beat * (1u + 2u * PUNCH_NFX); + static int32_t blk[CTL * 2u]; + wav_hdr(f, total * CTL); + beat_setup(); + TDRUM->p[P_E0] = DRUM_SAMPLED + 1u; /* 909 */ + for (b = 0; b < total; b++) { + uint32_t q; + int32_t e = b < beat ? -1 : (int32_t)((b - beat) / beat); + punch.req = (int8_t)(e >= 0 && e % 2 == 0 ? e / 2 : -1); + mix_block(blk, CTL); + for (q = 0; q < CTL; q++) wav_put(f, blk[2 * q], blk[2 * q + 1]); + } + fclose(f); + } + printf("punch-in FX: %u effects change the mix while held, bounded, exact dry mix after release; " + "FX-held keys pick effects, play and record nothing PASS\n", PUNCH_NFX); + return 0; +} diff --git a/tests/recovery_test.c b/tests/recovery_test.c new file mode 100644 index 0000000..50139ad --- /dev/null +++ b/tests/recovery_test.c @@ -0,0 +1,101 @@ +/* SPDX-License-Identifier: GPL-3.0-only */ +/* Real recovery control flow with hardware hooks mocked. No claim of USB + * enumeration on hardware: the separate OTA suite exercises the real protocol. */ +#include +#include +#include +#include +#include "../firmware/src/bootguard.h" +static bootguard_t bootguard; +static uint32_t ticks, fm1_ms, polls, feeds, retries, services, sessions, rom, detached, scans; +static uint32_t jedec = 0x856014u, jedec_reads, lcd_calls, font; +static uint8_t recovery_active, flash_ok; +static struct { uint8_t ota_req, uboot_req; } usb; +static struct { uint32_t buttons; } fm1_in; +static uint32_t input_buttons, stop_at_retry; +static jmp_buf exit_loop; +#define FM1_TICKS_PER_US 24u +#define FL_FAR(x) x +#define C_BLACK 0 +#define C_WHITE 65535 +#define FONT_S font +static uint32_t fm1_ticks(void) { return ticks; } +static void fm1_wdt_feed(void) { feeds++; } +static void usb_poll(void) { polls++; } +static void usb_retry(uint32_t t) +{ + (void)t; retries++; + if (stop_at_retry && retries >= stop_at_retry) longjmp(exit_loop, 1); +} +static void usb_detach(void) { detached++; } +static void fm1_delay_ms(uint32_t n) { ticks += n * 24000u; } +static void fm1_enter_uboot(void) { rom++; } +static void ota_service(void) { services++; } +static void recovery_poll(void); +static int ota_session(void) +{ + unsigned i; + sessions++; + for (i = 0; i < 200; i++) { ticks += 12000u; recovery_poll(); } + return -13; /* failed update must leave rescue available for another try */ +} +static void fm1_input_init(void) { fm1_in.buttons = 0; } +static void fm1_input_scan(void) { scans++; ticks += 24000u; fm1_in.buttons = input_buttons; } +static uint32_t fl_jedec_ram(void) { jedec_reads++; return jedec; } +static void lcd_init(void) { lcd_calls++; } +static void lcd_fill(int x, int y, int w, int h, int c) { (void)x;(void)y;(void)w;(void)h;(void)c; } +static void draw_text_box(int x, int y, int w, const void *f, const char *s, int c, int a) +{ (void)x;(void)y;(void)w;(void)f;(void)s;(void)c;(void)a; } +static void lcd_sync(void) {} +static void usb_start(void) {} +#include "../firmware/src/recovery.c" + +int main(void) +{ + bootguard_t b = {0}; + assert(bootguard_begin(&b) == BOOT_NORMAL); + assert(bootguard_begin(&b) == BOOT_NORMAL && b.failed == 1); + assert(bootguard_begin(&b) == BOOT_RECOVERY && b.pending == 2); + assert(bootguard_begin(&b) == BOOT_ROM && b.pending == 0); + assert(bootguard_begin(&b) == BOOT_NORMAL); + bootguard_clear(&b); /* healthy boot / intentional update */ + assert(bootguard_begin(&b) == BOOT_NORMAL && b.failed == 0); + b.pending = 2; bootguard_clear(&b); + assert(bootguard_begin(&b) == BOOT_NORMAL); + b.failed = 0xFFFFFFFFu; + assert(bootguard_begin(&b) == BOOT_NORMAL && b.failed == 0); + assert(bootguard_manual(1) && !bootguard_manual(0) && !bootguard_manual(2) && !bootguard_manual(3)); + + input_buttons = 1; assert(recovery_key()); + input_buttons = 3; assert(!recovery_key()); + input_buttons = 0; assert(!recovery_key()); + assert(scans >= 150); + + fm1_ms = 0; recovery_fraction = 0; + recovery_last = recovery_usb_last = ticks = 0xFFFFF000u; + ticks += 12000u; recovery_poll(); /* wrap + half a millisecond */ + assert(fm1_ms == 0 && polls == 1); + ticks += 12000u; recovery_poll(); + assert(fm1_ms == 1 && polls == 2); + recovery_poll(); assert(polls == 2); /* never busy-poll USB faster than 2 kHz */ + + flash_ok = 0; usb.ota_req = 1; recovery_step(); + assert(sessions == 0 && usb.ota_req == 0); + flash_ok = 1; usb.ota_req = 1; recovery_step(); + assert(sessions == 1 && fm1_ms == 101 && polls == 202); + usb.ota_req = 1; recovery_step(); + assert(sessions == 2 && fm1_ms == 201 && polls == 402); + assert(feeds > 400 && services == 3); + usb.uboot_req = 1; bootguard.pending = 2; recovery_step(); + assert(rom == 1 && detached == 1 && bootguard.pending == 0); + usb.uboot_req = 0; + + retries = 0; stop_at_retry = 5; + if (!setjmp(exit_loop)) recovery_main(); + assert(recovery_active && bootguard.pending == 2 && flash_ok); + assert(jedec_reads == 1 && lcd_calls == 1); + assert(services == 7 && sessions == 2); /* idle startup starts no update */ + assert(bootguard_begin(&bootguard) == BOOT_ROM); + puts("recovery: boot failures, manual key, timer wrap, polled USB during OTA, retry, flash refusal and ROM fallback passed"); + return 0; +} diff --git a/tests/regress.c b/tests/regress.c new file mode 100644 index 0000000..3e2a58d --- /dev/null +++ b/tests/regress.c @@ -0,0 +1,1010 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* Regression suite of the FELUCCA DSP on the Mac (same sources as the firmware, through hostsim.c). + * build/host/regress [GOLDEN_FILE CPU_FILE] (run_tests.sh builds and runs it) + * + * 1. golden renders: every engine x factory preset, the GM drum kit, the voice modes (POLY / MONO / + * LEGATO / UNISON) of three engines, the FX sends, a 4-track sequencer mix, and the SLICER (slicer.c: + * GATE / STUT on the phrase, and on the 4-track mix with the transport). Each render plays + * a fixed phrase (notes, an overlap, a chord, note-offs, the release tail) and is reduced to a + * 64-bit FNV-1a hash of its output samples, compared with GOLDEN_FILE (tests/golden.txt). + * Every render runs in its own fork()ed child of a process that never touched the DSP state, so + * all state starts as at boot: the noise / RAND / unison-phase / arp seeds (libc.c rng_state, + * eng_formant.c formant_nz, voice.c's unison seed), the FX buffers, the limiter. + * 2. health checks on every render: no sample beyond 16 bits, none near full scale, DC offset, the + * peak level, every voice free after the release, silence at the end. Fails with the numbers. + * 3. CPU budget: per engine x preset (8 notes held; VOICE: its 4) and a few mixes, the instructions + * per sample counted by the kernel (proc_pid_rusage ri_instructions: the same on every run within + * ~1 %, unlike wall time), compared with CPU_FILE (tests/cpu_baseline.txt) at +-25 %; ns per + * sample printed for information. A count over the budget fails, one far under it only warns. + * 4. voices: the shared budget of 8 across 3 parts, stolen voices fade (no step), MONO / LEGATO / + * UNISON keep their note under pressure, the VOICE engine's 4-voice cap, release frees voices, and + * no hanging note after the note-offs on any routing (USB channels 1..3, 10, others while the + * selected track changes, the keys while the selected track changes, with ARP and the voice modes). + * env: GOLDEN_UPDATE=1 rewrites GOLDEN_FILE, BUDGET_UPDATE=1 rewrites CPU_FILE (on purpose: review the + * diff), VERBOSE=1 prints every render's numbers, JOBS=n children at once (default 8). */ +#define main hostsim_main +#include "hostsim.c" +#undef main +#ifdef __APPLE__ +#include +#include +#endif + +/* ------------------------------------------------------------- limits --- */ +#define LIM_NEAR 30000 /* |sample| at or above: "near full scale" (the limiter holds ~18000) */ +#define LIM_DC 400 /* |mean| of the sounding part, 16-bit units (1.2 %; the master blocks DC) */ +#define LIM_PEAK_MIN 250 /* quieter than this (-42 dBFS): something is missing */ +#define LIM_TAIL 6 /* AC peak of the last 0.25 s, after the voices are free and the FX rang out */ +#define LIM_TAIL_DC 2 /* its constant part: the master DC blocker settles to 0 (error feedback; it + * used to leave up to +-31), what is left is the midpoint of the AC tail */ +#define FREE_CAP_S 12 /* the voices must be free this long after the last note-off */ +#ifndef TAIL_S +#define TAIL_S 3 /* FX tail rendered after the voices are free */ +#endif +#define CPU_TOL 0.25 /* +-25 %, and at least CPU_SLACK instructions (light presets) */ +#define CPU_SLACK 20 + +/* ------------------------------------------------------------ results --- */ +typedef struct { + uint64_t hash; + uint32_t frames, over, near, vmax, ok; /* ok: a scenario's own checks passed */ + int32_t peak, tail_peak, tail_dc, tmin, tmax; + double dc, free_s; /* free_s: s from the last note-off until all voices free, -1 never */ + double ipc, ns; /* CPU: instructions and ns per sample */ + char msg[512]; +} res_t; + +static res_t R; +static uint32_t fpos, rel_at, dc_end, tail_from; +static int64_t dcs[2]; + +static int parts_free(void) +{ + uint32_t p, i; + for (p = 0; p < NPART; p++) + for (i = 0; i < NVOICE; i++) + if (trk[p].v[i].active) + return 0; + for (i = 0; i < NDRUM; i++) + if (drums.v[i].active) + return 0; + return 1; +} + +static uint32_t sounding(void) /* part voices sounding (not the ones fading for another part) */ +{ + uint32_t p, i, n = 0; + for (p = 0; p < NPART; p++) + for (i = 0; i < NVOICE; i++) + n += trk[p].v[i].active && trk[p].v[i].stage != 4u; + return n; +} + +/* one block of the mix into the hash and the numbers */ +static int32_t last_out[2 * CTL]; +static void blk(void) +{ + int32_t *o = last_out; + uint32_t i, k; + mix_block(o, CTL); + for (i = 0; i < 2u * CTL; i++) { + int32_t x = o[i], a = x < 0 ? -x : x; + uint32_t u = (uint32_t)x; + for (k = 0; k < 4u; k++) { + R.hash ^= (u >> (8u * k)) & 0xFFu; + R.hash *= 0x100000001B3ull; + } + if (a > R.peak) + R.peak = a; + R.over += a > 32767; + R.near += a >= LIM_NEAR; + if (fpos < dc_end) + dcs[i & 1u] += x; + if (tail_from && fpos >= tail_from) { + R.tmin = x < R.tmin ? x : R.tmin; + R.tmax = x > R.tmax ? x : R.tmax; + } + } + k = busy_now(); + if (k > R.vmax) + R.vmax = k; + fpos += CTL; +} + +static uint32_t at(double s) { return (uint32_t)(s * FS) / CTL * CTL; } +static void run_to(uint32_t f) { while (fpos < f) blk(); } + +/* after the last note-off (rel_at): until the voices are free, then the FX tail */ +static void finish(void) +{ + uint32_t cap = rel_at + FREE_CAP_S * FS; + dc_end = dc_end ? dc_end : fpos; + while (!parts_free() && fpos < cap) + blk(); + R.free_s = parts_free() ? (double)(fpos - rel_at) / FS : -1; + tail_from = fpos + TAIL_S * FS - FS / 4u; + R.tmin = 0x7FFFFFFF; + R.tmax = -0x7FFFFFFF; + run_to(fpos + TAIL_S * FS); + R.tail_peak = (R.tmax - R.tmin + 1) / 2; + R.tail_dc = (R.tmax + R.tmin) / 2; + R.frames = fpos; + R.dc = (double)(llabs(dcs[0]) > llabs(dcs[1]) ? dcs[0] : dcs[1]) / (double)(dc_end ? dc_end : 1); +} + +/* --------------------------------------------------------- the phrase --- */ +/* notes (with an overlap: legato / steal), a 5-note chord, note-offs, the tail. Through input_on / + * input_off (the keys' and MIDI's way in: a preset's ARP plays). */ +static void phrase(track_t *t, uint32_t base) +{ + static const uint8_t CH[5] = {0, 7, 12, 16, 19}; + uint32_t i; + input_on(t, base, 100); + run_to(at(0.30)); + input_off(t, base); + run_to(at(0.35)); + input_on(t, base + 4u, 80); + run_to(at(0.60)); + input_on(t, base + 7u, 120); /* overlaps: MONO / LEGATO hand over, POLY two voices */ + run_to(at(0.70)); + input_off(t, base + 4u); + run_to(at(0.95)); + input_off(t, base + 7u); + run_to(at(1.00)); + for (i = 0; i < 5u; i++) + input_on(t, base - 12u + CH[i], 90 + 5 * i); + run_to(at(1.80)); + for (i = 0; i < 5u; i++) + input_off(t, base - 12u + CH[i]); + rel_at = fpos; + dc_end = fpos + FS / 2u; + finish(); +} + +/* ------------------------------------------------------------- jobs --- */ +enum { J_PRESET, J_MODE, J_SENDS, J_DRUMS, J_SONG, J_CPU, J_CHECK, J_SLICER }; +typedef struct { + char name[64]; + uint8_t kind, e, pi, arg, cpu_notes; + const uint8_t (*parts)[3]; /* J_CPU mixes */ + int (*check)(char *msg, uint32_t n); /* J_CHECK */ + res_t r; + int crashed; +} job_t; + +static void job_preset(const job_t *j) +{ + track_t *t = &trk[0]; + host_tracks_init(); + host_preset(t, j->e, j->pi); + phrase(t, 60); +} + +static void job_mode(const job_t *j) /* arg: the voice mode, ARP off, glide on for MONO / LEGATO */ +{ + track_t *t = &trk[0]; + host_tracks_init(); + host_preset(t, j->e, j->pi); + t->p[P_VOICE] = j->arg; + t->p[P_AMODE] = 0; + t->p[P_GLIDE] = j->arg == V_MONO || j->arg == V_LEGATO ? 30 : 0; + t->p[P_DETUNE] = 40; + phrase(t, 60); +} + +static void job_sends(const job_t *j) /* arg: 0 dry, 1 chorus, 2 delay, 3 reverb, 4 all, 5 DIST */ +{ + static const int16_t S[6][4] = {{0, 0, 0, 0}, {0, 110, 0, 0}, {0, 0, 110, 0}, {0, 0, 0, 110}, + {40, 80, 80, 80}, {110, 0, 0, 30}}; + track_t *t = &trk[0]; + uint32_t i; + host_tracks_init(); + host_preset(t, j->e, j->pi); + t->p[P_AMODE] = 0; + for (i = 0; i < 4u; i++) + t->p[P_DIST + i] = S[j->arg][i]; + phrase(t, 60); +} + +static void job_drums(const job_t *j) /* every GM note through the drum track, a choke, a roll */ +{ + uint32_t n, k = 0; + (void)j; + host_tracks_init(); + for (n = 35; n <= 81u; n++, k++) { + input_on(TDRUM, n, 60u + (n * 7u) % 60u); + run_to(at(0.06 * (k + 1))); + input_off(TDRUM, n); + } + input_on(TDRUM, 46, 100); /* open hat, choked by the closed one */ + run_to(fpos + FS / 10u); + input_on(TDRUM, 42, 100); + for (k = 0; k < 12u; k++) { /* a snare roll: more hits than voices */ + input_on(TDRUM, 38, 40u + 6u * k); + run_to(fpos + FS / 40u / CTL * CTL); + } + rel_at = fpos; + dc_end = fpos; + finish(); +} + +/* the SLICER on the phrase (its clock free-running, no transport): arg 0 GATE (ANALOG ACID, + * pattern 6, 1/16), 1 STUT (DIGITAL PAD, pattern 7, 1/32, DEPTH 100 %) */ +static void job_slicer(const job_t *j) +{ + static const int16_t S[2][4] = {{SL_GATE, 6, 1, 120}, {SL_STUT, 7, 2, 127}}; + track_t *t = &trk[0]; + uint32_t i; + host_tracks_init(); + host_preset(t, j->e, j->pi); + t->p[P_AMODE] = 0; + for (i = 0; i < 4u; i++) + t->p[P_SLCR + i] = S[j->arg][i]; + phrase(t, 60); +} + +/* the 4-track mix: T1 ANALOG ACID, T2 DIGITAL pad (tied chords), T3 LOFI lead (12 steps against 16), + * T4 drums; 120 BPM, 4 bars (the hostsim TRACKS demo without the recording), stop, the tail. + * arg 1: with the SLICER (GATE on the pad, STUT on the acid line and the drums, SWING 20 %) */ +static void job_song(const job_t *j) +{ + static const uint8_t ACID[16] = {45, 45, 57, 45, 0, 48, 45, 55, 45, 0, 57, 52, 45, 48, 0, 50}; + static const uint8_t ACIDF[16] = {1, 0, 2, 0, 0, 0, 1, 2, 0, 0, 1, 0, 0, 2, 0, 1}; + static const uint8_t AM[4] = {57, 60, 64, 67}, FMI[4] = {53, 57, 60, 64}; + static const uint8_t LEAD[12] = {76, 0, 0, 79, 0, 0, 81, 0, 79, 0, 76, 0}; + track_t *t1 = &trk[0], *t2 = &trk[1], *t3 = &trk[2], *td = TDRUM; + uint32_t i; + (void)j; + host_tracks_init(); + song.g[G_BPM] = 120; + host_preset(t1, 0, 4); + host_preset(t2, 1, 5); + host_preset(t3, 3, 0); + for (i = 0; i < 16u; i++) { + uint8_t n = ACID[i]; + put_step(t1, i, n ? 1u : 0u, &n, n ? ST_NOTE : ST_REST, ACIDF[i]); + } + t2->p[P_SLEN] = 32; + t2->p[P_SGATE] = 120; + for (i = 0; i < 32u; i++) + put_step(t2, i, i % 16u == 0u ? 4u : 0u, i < 16u ? AM : FMI, i % 16u == 0u ? ST_NOTE : i % 16u < 14u ? ST_TIE : ST_REST, 0); + t3->p[P_SLEN] = 12; + for (i = 0; i < 12u; i++) { + uint8_t n = LEAD[i]; + put_step(t3, i, n ? 1u : 0u, &n, n ? ST_NOTE : ST_REST, i == 0u ? SF_ACCENT : 0u); + } + for (i = 0; i < 16u; i++) { + uint8_t n[4]; + uint32_t k = 0; + if (i % 4u == 0u) + n[k++] = 36; + if (i == 4u || i == 12u) + n[k++] = 38; + if (i % 2u == 0u) + n[k++] = i == 14u ? 46 : 42; + put_step(td, i, k, n, k ? ST_NOTE : ST_REST, i % 4u == 0u ? SF_ACCENT : 0u); + } + if (j->arg) { + static const int16_t S[4][4] = {{SL_STUT, 9, 1, 127}, {SL_GATE, 1, 1, 127}, {0, 1, 1, 127}, + {SL_STUT, 12, 2, 110}}; + for (i = 0; i < NTRK; i++) { + uint32_t k; + for (k = 0; k < 4u; k++) + trk[i].p[P_SLCR + k] = S[i][k]; + } + song.g[G_SWING] = 20; + } + transport_req = 1; + run_to(8u * FS); + transport_req = 2; + blk(); + rel_at = fpos; + dc_end = fpos; + finish(); +} + +/* CPU: parts[k] = {engine, preset, notes} (POLY, SUS 127, no ARP; SLICE: MODE LOOP), drums on 16ths if parts[3][0]; + * 0.5 s to settle, then 1 s counted */ +static uint64_t instr_now(void) +{ +#ifdef __APPLE__ + struct rusage_info_v4 ri; + if (!proc_pid_rusage(getpid(), RUSAGE_INFO_V4, (rusage_info_t *)&ri)) + return ri.ri_instructions; +#endif + return 0; +} +static void job_cpu(const job_t *j) +{ + static const uint8_t NOTES[8] = {48, 52, 55, 59, 60, 64, 67, 71}; + const uint8_t (*parts)[3] = j->parts; + uint32_t p, i, k, nb = FS / CTL, drums_on = parts[NPART][0]; + uint64_t i0, t0; + host_tracks_init(); + for (p = 0; p < NPART; p++) { + host_preset(&trk[p], parts[p][0], parts[p][1]); + trk[p].p[P_VOICE] = V_POLY; + trk[p].p[P_SUS] = 127; + trk[p].p[P_AMODE] = 0; +#if FELUCCA_SLICE + if (ENGINES[parts[p][0]] == &ENG_SLICE) + trk[p].p[P_E4] = SLC_LOOP; /* SLICE: its slices end by themselves; loop them */ +#endif + for (i = 0; i < parts[p][2]; i++) + trk_note_on(&trk[p], NOTES[i] + 12u * p, 100); + } + for (k = 0; k < nb / 2u + nb; k++) { + if (k == nb / 2u) { + i0 = instr_now(); + t0 = now_ns(); + } + if (drums_on && (k * CTL) % (FS / 8u) < CTL) + drum_on((k * CTL) % (FS / 2u) < CTL ? 36u : ((k * CTL) / (FS / 8u)) % 4u == 2u ? 38u : 42u, 100u); + mix_block(last_out, CTL); + } + R.ns = (double)(now_ns() - t0) / (nb * CTL); + R.ipc = i0 ? (double)(instr_now() - i0) / (nb * CTL) : 0; +} + +static int run_job_body(job_t *j) +{ + memset(&R, 0, sizeof R); + switch (j->kind) { + case J_PRESET: + job_preset(j); + break; + case J_MODE: + job_mode(j); + break; + case J_SENDS: + job_sends(j); + break; + case J_DRUMS: + job_drums(j); + break; + case J_SONG: + job_song(j); + break; + case J_SLICER: + job_slicer(j); + break; + case J_CPU: + job_cpu(j); + break; + case J_CHECK: + R.ok = (uint32_t)j->check(R.msg, sizeof R.msg); + break; + } + return 0; +} + +/* run jobs [0, n) in children, up to nj at once; results come back through pipes */ +static void run_jobs(job_t *jobs, uint32_t n, uint32_t nj) +{ + uint32_t i, k; + for (i = 0; i < n; i += nj) { + int fd[64]; + pid_t pid[64]; + uint32_t m = n - i < nj ? n - i : nj; + for (k = 0; k < m; k++) { + int p[2]; + if (pipe(p)) { + perror("pipe"); + exit(2); + } + fflush(stdout); + if (!(pid[k] = fork())) { + close(p[0]); + run_job_body(&jobs[i + k]); + if (write(p[1], &R, sizeof R) != sizeof R) + _exit(1); + _exit(0); + } + close(p[1]); + fd[k] = p[0]; + } + for (k = 0; k < m; k++) { + size_t got = 0; + ssize_t r; + int st = 0; + while (got < sizeof(res_t) && (r = read(fd[k], (char *)&jobs[i + k].r + got, sizeof(res_t) - got)) > 0) + got += (size_t)r; + close(fd[k]); + waitpid(pid[k], &st, 0); + jobs[i + k].crashed = got != sizeof(res_t) || !WIFEXITED(st) || WEXITSTATUS(st); + } + } +} + +/* ------------------------------------------------- voice / routing checks --- */ +static uint32_t lcg = 12345u; +static uint32_t rnd(uint32_t n) +{ + lcg = lcg * 1103515245u + 12345u; + return (lcg >> 8) % n; +} +static int held_gates(char *who, size_t wn) +{ + uint32_t p, i, n = 0; + who[0] = 0; + for (p = 0; p < NPART; p++) + if (trk[p].nheld) { /* a key the ARP still thinks is down: it plays on */ + if (!n) + snprintf(who, wn, "part %u ARP still holds %u notes (first %u)", p + 1u, trk[p].nheld, trk[p].held[0]); + n++; + } + for (p = 0; p < NPART; p++) + for (i = 0; i < NVOICE; i++) + if (trk[p].v[i].active && trk[p].v[i].gate) { + if (!n) + snprintf(who, wn, "part %u voice %u note %u", p + 1u, i, trk[p].v[i].note); + n++; + } + return (int)n; +} +static void midi_pkt(uint32_t st, uint32_t d1, uint32_t d2) /* as usb.c: the queue holds MQ packets */ +{ + if (mi_w - mi_r >= MQ) + blk(); + midi_in_q[mi_w++ % MQ] = (st >> 4) | st << 8 | d1 << 16 | d2 << 24; +} + +/* the shared budget: 3 POLY parts (ANALOG, DIGITAL, VOICE) play random notes on and off for 6 s, up to + * 8 held each; after every block: at most 8 part voices sounding, none still fading after KILL_BLOCKS + * (a stolen voice fades out), the VOICE part at most 4; then all off: every voice free */ +static int chk_budget(char *msg, uint32_t n) +{ + static const uint8_t E[3] = {0, 1, 5}; + uint8_t held[NPART][128] = {{0}}; + uint32_t p, k, worst = 0, vworst = 0, fading = 0, kills0 = voice_kills; + host_tracks_init(); + for (p = 0; p < NPART; p++) { + host_preset(&trk[p], E[p], 1); + trk[p].p[P_VOICE] = V_POLY; + trk[p].p[P_AMODE] = 0; + trk[p].p[P_SUS] = 100; + } + for (k = 0; k < 6u * FS / CTL; k++) { + uint32_t i, a = 0, va = 0; + if (k % 4u == 0u) { + uint32_t note = 36u + rnd(48); + p = rnd(NPART); + if (held[p][note]) { + trk_note_off(&trk[p], note); + held[p][note] = 0; + } else { + trk_note_on(&trk[p], note, 60u + rnd(60)); + held[p][note] = 1; + } + } + blk(); + for (p = 0; p < NPART; p++) + for (i = 0; i < NVOICE; i++) { + static uint8_t fade_blocks[NPART][NVOICE]; + uint32_t f4 = trk[p].v[i].active && trk[p].v[i].stage == 4u; + a += trk[p].v[i].active && !f4; /* sounding (a stolen voice fades out over KILL_BLOCKS) */ + va += p == 2u && trk[p].v[i].active && !f4; + fade_blocks[p][i] = (uint8_t)(f4 ? fade_blocks[p][i] + 1u : 0u); + fading += fade_blocks[p][i] >= KILL_BLOCKS; + } + worst = a > worst ? a : worst; + vworst = va > vworst ? va : vworst; + } + for (p = 0; p < NPART; p++) + for (k = 0; k < 128u; k++) + if (held[p][k]) + trk_note_off(&trk[p], k); + rel_at = fpos; + finish(); + snprintf(msg, n, "3 POLY parts, random notes: at most %u voices active (budget %u), VOICE part at most %u (cap 4), " + "%u voices taken, %u still fading after their KILL_BLOCKS, all free %.2f s after the note-offs", + worst, NVOICE, vworst, voice_kills - kills0, fading, R.free_s); + return worst <= NVOICE && vworst <= 4u && !fading && R.free_s >= 0 && voice_kills > kills0; +} + +/* a stolen voice fades: plain sines (filter open, no sends) on 3 parts; part 1 holds 7 notes, part 2 one, + * then parts 2 and 3 take voices in turn. The largest sample step in the 2 blocks of each take must stay + * within 1.5 x the largest one in the 0.25 s before it (a hard cut is several times larger) */ +static int chk_steal_fade(char *msg, uint32_t n) +{ + static const uint8_t N1[7] = {48, 52, 55, 59, 62, 65, 69}; + const uint32_t frames = 4u * FS; + int32_t *L = calloc(frames + CTL, sizeof *L); + uint32_t f, i, p, k, ev[8], nev = 0, bad = 0; + double worst = 0; + int32_t wat = 0, wcalm = 0; + host_tracks_init(); + for (p = 0; p < NPART; p++) + xfade_sine(&trk[p]); + for (f = 0; f < frames; f += CTL) { + uint32_t ms = f * 1000u / FS, k0 = voice_kills; + if (f == 0) + for (i = 0; i < 7u; i++) + trk_note_on(&trk[0], N1[i], 90); + if (f == at(0.5)) + trk_note_on(&trk[1], 74, 90); + if (ms >= 1000u && f % (FS / 2u) < CTL && ms < 3500u) + trk_note_on(&trk[ms / 500u % 2u ? 1u : 2u], 76u + ms / 250u, 90); + blk(); + if (voice_kills != k0 && nev < 8u) + ev[nev++] = f; + for (i = 0; i < CTL; i++) + L[f + i] = last_out[2 * i]; + } + for (k = 0; k < nev; k++) { + int32_t calm = 1, a = 0; + for (i = ev[k] - FS / 4u; i < ev[k] - 2u * CTL; i++) + calm = abs(L[i] - L[i - 1]) > calm ? abs(L[i] - L[i - 1]) : calm; + for (i = ev[k]; i < ev[k] + 2u * CTL; i++) + a = abs(L[i] - L[i - 1]) > a ? abs(L[i] - L[i - 1]) : a; + if ((double)a / calm > worst) { + worst = (double)a / calm; + wat = a; + wcalm = calm; + } + bad += a * 2 > calm * 3; + } + free(L); + snprintf(msg, n, "%u takes; largest sample step at a take %d vs %d before it (%.2f x, limit 1.50 x)", nev, wat, + wcalm, worst); + return nev >= 4u && !bad; +} + +/* MONO / LEGATO / UNISON keep their note: part 1 holds note 40 in mode m while parts 2 and 3 (POLY) + * flood the budget with new notes for 2 s; part 1's voice 0 must sound note 40, gate on, every block */ +static int chk_keep(char *msg, uint32_t n, uint32_t mode) +{ + static const char *const MN[4] = {"POLY", "MONO", "LEGATO", "UNISON"}; + uint32_t k, lost = 0, kills0 = voice_kills; + host_tracks_init(); + host_preset(&trk[0], 0, 0); + trk[0].p[P_VOICE] = (int16_t)mode; + trk[0].p[P_AMODE] = 0; + trk[0].p[P_SUS] = 100; + for (k = 1; k < NPART; k++) { + host_preset(&trk[k], 1, 1); + trk[k].p[P_VOICE] = V_POLY; + trk[k].p[P_AMODE] = 0; + trk[k].p[P_SUS] = 100; + } + trk_note_on(&trk[0], 40, 100); + for (k = 0; k < 2u * FS / CTL; k++) { + if (k % 3u == 0u) + trk_note_on(&trk[1u + k / 3u % 2u], 50u + k / 3u % 40u, 100); + blk(); + { + const voice_t *v = &trk[0].v[0]; + lost += !(v->active && v->gate && v->note == 40u && v->stage != 4u); + } + } + snprintf(msg, n, "%s part held its note through %u voices taken from the others: lost in %u blocks", + MN[mode], voice_kills - kills0, lost); + return !lost && voice_kills > kills0; +} +static int chk_keep_mono(char *m, uint32_t n) { return chk_keep(m, n, V_MONO); } +static int chk_keep_legato(char *m, uint32_t n) { return chk_keep(m, n, V_LEGATO); } +static int chk_keep_unison(char *m, uint32_t n) { return chk_keep(m, n, V_UNISON); } + +/* the VOICE engine's cap: 8 keys in POLY and in UNISON (alone: the budget does not limit it) */ +static int chk_voice_cap(char *msg, uint32_t n) +{ + uint32_t mode, k, i, most[2] = {0, 0}; + for (mode = 0; mode < 2u; mode++) { + track_t *t = &trk[0]; + host_tracks_init(); + host_preset(t, 5, 0); + t->p[P_VOICE] = mode ? V_UNISON : V_POLY; + t->p[P_AMODE] = 0; + for (k = 0; k < 8u; k++) + trk_note_on(t, 60u + 2u * k, 100); + for (k = 0; k < FS / 2u / CTL; k++) { + uint32_t a = 0; + blk(); + for (i = 0; i < NVOICE; i++) + a += t->v[i].active; + most[mode] = a > most[mode] ? a : most[mode]; + } + for (k = 0; k < 8u; k++) + trk_note_off(t, 60u + 2u * k); + for (k = 0; k < 4u * FS / CTL && !parts_free(); k++) + blk(); + if (!parts_free()) + most[mode] = 99; + } + snprintf(msg, n, "VOICE engine, 8 keys: at most %u voices in POLY, %u in UNISON (cap 4); freed after release", + most[0], most[1]); + return most[0] == 4u && most[1] == 4u; +} + +/* no hanging notes: 6 s of random MIDI note-ons / offs on channels 1, 2, 3 (the parts), 10 (drums), 5 and + * 16 (the selected track), and keys, while the selected track changes; the parts in random voice modes, + * some with ARP, SUS 127 (a hanging note keeps sounding). A channel's note-off goes to the same channel + * as its note-on. Then every held note off: no gate may stay on, no ARP may still hold a key, every voice + * must be free (also the same note held on two "selected track" channels across a selection change). */ +static int chk_hang(char *msg, uint32_t n) +{ + static const uint8_t CHS[6] = {0, 1, 2, 9, 4, 15}; + uint8_t on[6][128] = {{0}}; + uint32_t keys = 0, k, c, ev = 0, round; + char who[96] = ""; + int bad = 0; + for (round = 0; round < 3u && !bad; round++) { + host_tracks_init(); + for (k = 0; k < NPART; k++) { + host_preset(&trk[k], rnd(NENGINES), rnd(4)); + trk[k].p[P_VOICE] = (int16_t)rnd(4); + trk[k].p[P_AMODE] = rnd(3) == 0 ? (int16_t)(1 + rnd(4)) : 0; + trk[k].p[P_AHOLD] = 0; + trk[k].p[P_SUS] = 127; + } + for (k = 0; k < 6u * FS / CTL; k++) { + uint32_t r = rnd(16); + if (r < 6u) { /* MIDI */ + uint32_t ci = rnd(6), note = 36u + rnd(36); + if (on[ci][note]) { + midi_pkt(rnd(2) ? 0x80u | CHS[ci] : 0x90u | CHS[ci], note, 0); + on[ci][note] = 0; + } else { + midi_pkt(0x90u | CHS[ci], note, 1u + rnd(127)); + on[ci][note] = 1; + } + ev++; + } else if (r < 9u) { /* a key down or up */ + keys ^= 1u << rnd(27); + fm1_in.notes = keys; + ev++; + } else if (r == 9u) { + song.sel = (uint8_t)rnd(NTRK); /* another track selected */ + } + blk(); + } + fm1_in.notes = keys = 0; /* everything off */ + for (c = 0; c < 6u; c++) + for (k = 0; k < 128u; k++) + if (on[c][k]) { + midi_pkt(0x80u | CHS[c], k, 64); + on[c][k] = 0; + } + run_to(fpos + FS / 2u); /* (an ARP note-off: within its gate) */ + if (held_gates(who, sizeof who)) + bad = 1; + rel_at = fpos; + { + uint32_t cap = fpos + FREE_CAP_S * FS; + while (!parts_free() && fpos < cap) + blk(); + for (c = 0; c < NPART * NVOICE && !parts_free() && !bad; c++) { + const voice_t *v = &trk[c / NVOICE].v[c % NVOICE]; + if (v->active) { + bad = 2; + snprintf(who, sizeof who, "part %u voice %u note %u still active %d s after the note-offs (gate %u " + "stage %u)", c / NVOICE + 1u, c % NVOICE, v->note, FREE_CAP_S, v->gate, v->stage); + } + } + if (!parts_free() && !bad) { + bad = 2; + snprintf(who, sizeof who, "a drum voice still active %d s after the note-offs", FREE_CAP_S); + } + } + } + snprintf(msg, n, "%u random MIDI / key events on ch 1-3, 10, 5, 16 and the keys, track selection changing, " + "3 rounds: %s", ev, bad ? who : "no gate left on, every voice free"); + return !bad; +} + +/* ------------------------------------------------------------ files --- */ +typedef struct { char name[64]; char val[64]; } kv_t; +static uint32_t load_kv(const char *path, kv_t *kv, uint32_t max) +{ + FILE *f = fopen(path, "r"); + char line[256]; + uint32_t n = 0; + if (!f) + return 0; + while (fgets(line, sizeof line, f) && n < max) { + if (line[0] == '#' || line[0] == '\n') + continue; + if (sscanf(line, "%63s %63s", kv[n].name, kv[n].val) == 2) + n++; + } + fclose(f); + return n; +} +static const char *kv_get(const kv_t *kv, uint32_t n, const char *name) +{ + uint32_t i; + for (i = 0; i < n; i++) + if (!strcmp(kv[i].name, name)) + return kv[i].val; + return 0; +} + +static void slug(char *d, const char *s, size_t n) +{ + size_t i = 0; + for (; *s && i + 1 < n; s++) + d[i++] = (*s == ' ' || *s == '/') ? '_' : *s; + d[i] = 0; +} + +/* ------------------------------------------------------------- main --- */ +#define MAXJ 512 +static job_t J[MAXJ]; +static uint32_t nj; +static job_t *add(uint32_t kind, const char *name) +{ + job_t *j = &J[nj++]; + memset(j, 0, sizeof *j); + j->kind = (uint8_t)kind; + snprintf(j->name, sizeof j->name, "%s", name); + return j; +} + +int main(int argc, char **argv) +{ + const char *gpath = argc > 1 ? argv[1] : "tests/golden.txt"; + const char *cpath = argc > 2 ? argv[2] : "tests/cpu_baseline.txt"; + int gupd = getenv("GOLDEN_UPDATE") != 0, cupd = getenv("BUDGET_UPDATE") != 0, verbose = getenv("VERBOSE") != 0; + uint32_t jobs_at_once = getenv("JOBS") ? (uint32_t)atoi(getenv("JOBS")) : 8u; + static const char *const MN[4] = {"POLY", "MONO", "LEGATO", "UNISON"}; + static const char *const SN[6] = {"dry", "chorus", "delay", "reverb", "all", "dist"}; + static const uint8_t MODE_E[3][2] = {{0, 0}, {1, 1}, {5, 0}}; /* engine, preset */ + static const uint8_t SEND_E[2][2] = {{0, 7}, {1, 0}}; /* ANALOG TRAP PLUCK, DIGITAL RHODES */ + static uint8_t cpu_parts[MAXJ][NPART + 1][3]; + static kv_t gold[MAXJ], cpu[MAXJ]; + uint32_t ng, nc, e, pi, i, g0, g1, c0, c1, k0, ncpu = 0; + uint32_t g_changed = 0, g_new = 0, g_gone = 0, h_fail = 0, c_fail = 0, c_warn = 0, k_fail = 0, crash = 0; + double heavy[NENGINES] = {0}, heavy_ns[NENGINES] = {0}, idle_now, idle_base; + uint32_t heavy_p[NENGINES] = {0}; + uint64_t t_start = now_ns(); + char name[64], s[64]; + if (jobs_at_once < 1u || jobs_at_once > 64u) + jobs_at_once = 8; + + /* 1 + 2: the golden renders */ + g0 = nj; + for (e = 0; e < NENGINES; e++) + for (pi = 0; pi < ENGINES[e]->npresets; pi++) { + job_t *j; + slug(s, ENGINES[e]->presets[pi].name, sizeof s); + snprintf(name, sizeof name, "preset/%s/%02u_%s", ENGINES[e]->name, pi, s); + j = add(J_PRESET, name); + j->e = (uint8_t)e; + j->pi = (uint8_t)pi; + } + add(J_DRUMS, "drums/gm_kit"); + for (i = 0; i < 3u; i++) + for (k0 = 0; k0 < 4u; k0++) { + job_t *j; + snprintf(name, sizeof name, "mode/%s/%s", ENGINES[MODE_E[i][0]]->name, MN[k0]); + j = add(J_MODE, name); + j->e = MODE_E[i][0]; + j->pi = MODE_E[i][1]; + j->arg = (uint8_t)k0; + } + for (i = 0; i < 2u; i++) + for (k0 = 0; k0 < 6u; k0++) { + job_t *j; + snprintf(name, sizeof name, "sends/%s/%s", ENGINES[SEND_E[i][0]]->name, SN[k0]); + j = add(J_SENDS, name); + j->e = SEND_E[i][0]; + j->pi = SEND_E[i][1]; + j->arg = (uint8_t)k0; + } + add(J_SONG, "song/4track_mix"); + { /* the SLICER */ + job_t *j = add(J_SLICER, "slicer/gate/ANALOG_DARK_STR"); + j->e = 0, j->pi = 10, j->arg = 0; + j = add(J_SLICER, "slicer/stut/DIGITAL_RHODES"); + j->e = 1, j->pi = 0, j->arg = 1; + add(J_SONG, "slicer/song_gate_stut")->arg = 1; + } + g1 = nj; + { /* determinism: the first preset render once more */ + job_t *j = add(J_PRESET, "repeat"); + *j = J[g0]; + snprintf(j->name, sizeof j->name, "repeat"); + } + + /* 4: the voice checks */ + k0 = nj; + add(J_CHECK, "voices: budget of 8 across 3 parts")->check = chk_budget; + add(J_CHECK, "voices: a stolen voice fades")->check = chk_steal_fade; + add(J_CHECK, "voices: MONO keeps its note")->check = chk_keep_mono; + add(J_CHECK, "voices: LEGATO keeps its note")->check = chk_keep_legato; + add(J_CHECK, "voices: UNISON keeps its note")->check = chk_keep_unison; + add(J_CHECK, "voices: VOICE engine cap")->check = chk_voice_cap; + add(J_CHECK, "routing: no hanging notes")->check = chk_hang; + run_jobs(J, nj, jobs_at_once); + + /* 3: CPU, one child at a time (the ns are for information; the instruction counts do not care) */ + c0 = nj; + for (e = 0; e < NENGINES; e++) + for (pi = 0; pi < ENGINES[e]->npresets; pi++) { + job_t *j; + slug(s, ENGINES[e]->presets[pi].name, sizeof s); + snprintf(name, sizeof name, "cpu/%s/%02u_%s", ENGINES[e]->name, pi, s); + j = add(J_CPU, name); + memset(cpu_parts[ncpu], 0, sizeof cpu_parts[ncpu]); + cpu_parts[ncpu][0][0] = (uint8_t)e; + cpu_parts[ncpu][0][1] = (uint8_t)pi; + cpu_parts[ncpu][0][2] = 8; + j->parts = (const uint8_t (*)[3])cpu_parts[ncpu++]; + j->e = (uint8_t)e; + j->pi = (uint8_t)pi; + } + { /* mixes: idle (subtracted from the presets' counts), idle + drums, DIGITAL + PHASE + VOICE asking + * 8 + 8 + 4 (the budget keeps 8) + drums */ + job_t *j = add(J_CPU, "cpu/mix/idle"); + memset(cpu_parts[ncpu], 0, sizeof cpu_parts[ncpu]); + j->parts = (const uint8_t (*)[3])cpu_parts[ncpu++]; + j->e = 0xFF; + j = add(J_CPU, "cpu/mix/idle_drums"); + memset(cpu_parts[ncpu], 0, sizeof cpu_parts[ncpu]); + cpu_parts[ncpu][NPART][0] = 1; + j->parts = (const uint8_t (*)[3])cpu_parts[ncpu++]; + j->e = 0xFF; + j = add(J_CPU, "cpu/mix/3parts_full_drums"); + memset(cpu_parts[ncpu], 0, sizeof cpu_parts[ncpu]); + cpu_parts[ncpu][0][0] = 1, cpu_parts[ncpu][0][1] = 0, cpu_parts[ncpu][0][2] = 8; + cpu_parts[ncpu][1][0] = 2, cpu_parts[ncpu][1][1] = 0, cpu_parts[ncpu][1][2] = 8; + cpu_parts[ncpu][2][0] = 5, cpu_parts[ncpu][2][1] = 0, cpu_parts[ncpu][2][2] = 4; + cpu_parts[ncpu][NPART][0] = 1; + j->parts = (const uint8_t (*)[3])cpu_parts[ncpu++]; + j->e = 0xFF; + } + c1 = nj; + run_jobs(J + c0, c1 - c0, 1); + + /* ---- report: goldens and health ---- */ + ng = load_kv(gpath, gold, MAXJ); + for (i = g0; i < g1; i++) { + job_t *j = &J[i]; + const res_t *r = &j->r; + const char *want = kv_get(gold, ng, j->name); + char hs[24], why[256] = ""; + snprintf(hs, sizeof hs, "%016llx", (unsigned long long)r->hash); + if (j->crashed) { + printf("regress: CRASH %s\n", j->name); + crash++; + continue; + } + if (!want) + g_new++; + else if (strcmp(want, hs)) { + if (!gupd) + printf("regress: GOLDEN CHANGED %s (%s -> %s)\n", j->name, want, hs); + g_changed++; + } + if (r->over) + snprintf(why + strlen(why), sizeof why - strlen(why), " %u samples beyond 16 bits;", r->over); + if (r->near) + snprintf(why + strlen(why), sizeof why - strlen(why), " %u samples >= %d;", r->near, LIM_NEAR); + if (fabs(r->dc) > LIM_DC) + snprintf(why + strlen(why), sizeof why - strlen(why), " DC %.1f (limit %d);", r->dc, LIM_DC); + if (r->peak < LIM_PEAK_MIN) + snprintf(why + strlen(why), sizeof why - strlen(why), " peak %d (min %d);", r->peak, LIM_PEAK_MIN); + if (r->free_s < 0) + snprintf(why + strlen(why), sizeof why - strlen(why), " voices not free %d s after the note-offs;", FREE_CAP_S); + if (abs(r->tail_dc) > LIM_TAIL_DC) + snprintf(why + strlen(why), sizeof why - strlen(why), " DC %d left at the end (limit %d);", r->tail_dc, + LIM_TAIL_DC); + if (r->tail_peak > LIM_TAIL) + snprintf(why + strlen(why), sizeof why - strlen(why), " not silent at the end: peak %d (limit %d);", + r->tail_peak, LIM_TAIL); + if (r->vmax > NVOICE) + snprintf(why + strlen(why), sizeof why - strlen(why), " %u voices (budget %u);", r->vmax, NVOICE); + if (why[0]) { + printf("regress: HEALTH FAIL %s:%s\n", j->name, why); + h_fail++; + } + if (verbose) + printf(" %-44s %s %5.1f s peak %5d dc %6.1f free %5.2f s tail %3d dc %3d voices %u\n", j->name, + hs, (double)r->frames / FS, r->peak, r->dc, r->free_s, r->tail_peak, r->tail_dc, r->vmax); + } + for (i = 0; i < ng; i++) { /* in the file, not rendered any more */ + uint32_t k, found = 0; + for (k = g0; k < g1 && !found; k++) + found = !strcmp(J[k].name, gold[i].name); + if (!found) { + if (!gupd) + printf("regress: GOLDEN GONE %s (no such render now)\n", gold[i].name); + g_gone++; + } + } + if (J[g1].r.hash != J[g0].r.hash || J[g1].crashed) { + printf("regress: NOT DETERMINISTIC %s rendered twice: %016llx, %016llx\n", J[g0].name, + (unsigned long long)J[g0].r.hash, (unsigned long long)J[g1].r.hash); + h_fail++; + } + if (gupd) { + FILE *f = fopen(gpath, "w"); + if (!f) { + perror(gpath); + return 2; + } + fprintf(f, "# FELUCCA golden renders (tests/regress.c): name, FNV-1a 64 of the output samples.\n" + "# Rewritten by GOLDEN_UPDATE=1 tests/run_tests.sh -- only for an intended change of the sound.\n"); + for (i = g0; i < g1; i++) + fprintf(f, "%s %016llx\n", J[i].name, (unsigned long long)J[i].r.hash); + fclose(f); + printf("regress: golden file %s rewritten (%u renders; %u had changed, %u new, %u gone)\n", gpath, g1 - g0, + g_changed, g_new, g_gone); + } else if (g_new) { + printf("regress: %u renders not in %s (new: GOLDEN_UPDATE=1 adds them)\n", g_new, gpath); + } + + /* ---- voices ---- */ + for (i = k0; i < c0; i++) { + int ok = !J[i].crashed && J[i].r.ok; + printf("regress: %s: %s %s\n", J[i].name, J[i].crashed ? "crashed" : J[i].r.msg, ok ? "ok" : "FAIL"); + k_fail += !ok; + } + + /* ---- CPU ---- */ + /* a preset's own cost: its count less the idle mix's (the mix alone is half of a light preset's), + * so +25 % means 25 % more engine work; the mixes as they are */ + nc = load_kv(cpath, cpu, MAXJ); + idle_now = J[c1 - 3u].r.ipc; + idle_base = kv_get(cpu, nc, J[c1 - 3u].name) ? atof(kv_get(cpu, nc, J[c1 - 3u].name)) : 0; + for (i = c0; i < c1; i++) { + const job_t *j = &J[i]; + const char *want = kv_get(cpu, nc, j->name); + int own = j->e < NENGINES && idle_base > 0; + double b = want ? atof(want) - (own ? idle_base : 0) : 0, ipc = j->r.ipc - (own ? idle_now : 0); + if (j->crashed) { + printf("regress: CRASH %s\n", j->name); + crash++; + continue; + } + if (j->e < NENGINES && j->r.ipc > heavy[j->e]) { + heavy[j->e] = j->r.ipc; + heavy_ns[j->e] = j->r.ns; + heavy_p[j->e] = j->pi; + } + if (!j->r.ipc || cupd) + continue; + if (!want) + printf("regress: CPU %s: %.0f instructions / sample, no baseline (BUDGET_UPDATE=1 adds it)\n", j->name, ipc); + else if (ipc > b * (1 + CPU_TOL) && ipc > b + CPU_SLACK) { + printf("regress: CPU OVER BUDGET %s: %.0f instructions / sample%s, baseline %.0f (+%.0f %%, limit +%.0f %%)\n", + j->name, ipc, own ? " over the idle mix" : "", b, (ipc / b - 1) * 100, CPU_TOL * 100); + c_fail++; + } else if (ipc < b * (1 - CPU_TOL) && ipc < b - CPU_SLACK) { + printf("regress: CPU note %s: %.0f instructions / sample, baseline %.0f (%.0f %%): faster? " + "BUDGET_UPDATE=1 to keep it\n", j->name, ipc, b, (ipc / b - 1) * 100); + c_warn++; + } + } + if (!J[c0].r.ipc) + printf("regress: CPU: no instruction counter on this host (proc_pid_rusage); the budget is not checked\n"); + else if (cupd) { + FILE *f = fopen(cpath, "w"); + if (!f) { + perror(cpath); + return 2; + } + fprintf(f, "# FELUCCA host CPU baseline (tests/regress.c): instructions per 44.1 kHz sample, cc -O2 on\n" + "# the Mac (kernel-counted, ~1 %% run to run). The check allows +%.0f %%. Rewritten by BUDGET_UPDATE=1.\n", + CPU_TOL * 100); + for (i = c0; i < c1; i++) + fprintf(f, "%s %.0f\n", J[i].name, J[i].r.ipc); + fclose(f); + printf("regress: CPU baseline %s rewritten (%u entries)\n", cpath, c1 - c0); + } + printf("regress: CPU, one part with 8 notes held (VOICE 4), heaviest preset per engine (instructions / ns per sample):\n"); + for (e = 0; e < NENGINES; e++) + printf("regress: %-8s %-14s %6.0f instr %6.1f ns\n", ENGINES[e]->name, ENGINES[e]->presets[heavy_p[e]].name, + heavy[e], heavy_ns[e]); + for (i = c1 - 3u; i < c1; i++) + printf("regress: %-23s %6.0f instr %6.1f ns\n", J[i].name + 8, J[i].r.ipc, J[i].r.ns); + + printf("regress: %u golden renders (%u changed, %u gone), %u health failures, %u voice / routing checks failed, " + "%u CPU entries over budget (%u notes), %u crashes; %.1f s\n", g1 - g0, gupd ? 0 : g_changed, + gupd ? 0 : g_gone, h_fail, k_fail, cupd ? 0 : c_fail, c_warn, crash, (double)(now_ns() - t_start) / 1e9); + if (!gupd && (g_changed || g_gone)) + printf("regress: the sound changed. If that is intended: GOLDEN_UPDATE=1 sh tests/run_tests.sh, " + "then review and commit tests/golden.txt\n"); + return (!gupd && (g_changed || g_gone)) || h_fail || k_fail || (!cupd && c_fail) || crash; +} diff --git a/tests/run_tests.sh b/tests/run_tests.sh new file mode 100644 index 0000000..2702763 --- /dev/null +++ b/tests/run_tests.sh @@ -0,0 +1,99 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-3.0-only +# Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments +# Host tests (no hardware). Run from the repo root after ./build.sh: +# tests/run_tests.sh +# +# Regression suite (tests/regress.c, tests/target_budget.py; details at the top of regress.c): +# golden renders every engine x preset, the drum kit, voice modes, FX sends, a 4-track mix: one hash +# each in tests/golden.txt. A change of the sound fails with the list of renders. +# health clipping, DC, peak level, voices free after the release, silence at the end. +# CPU instructions / sample per preset and mix (tests/cpu_baseline.txt, +25 %), ns printed; +# target: loop instructions of the render functions in build/felucca.dis +# (tests/target_budget.txt, +10 %; exact, static). +# voices the budget of 8, steal fades, MONO / LEGATO / UNISON keep their note, the VOICE cap, +# no hanging notes on any MIDI / key routing. +# After an intended change of the sound: GOLDEN_UPDATE=1 sh tests/run_tests.sh, review the diff +# of tests/golden.txt, commit it with the change. After an intended change of the cost (or a new +# compiler): BUDGET_UPDATE=1 (rewrites cpu_baseline.txt and target_budget.txt). VERBOSE=1: every render. +set -e +export AC79_SDK="${AC79_SDK:-$HOME/fw-AC79_AIoT_SDK}" +cd "$(dirname "$0")/.." +OUT=build/host +mkdir -p "$OUT" +CC="${CC:-cc} -O1 -Wall -Wno-unused-function" +fail=0 +run() { echo "== $1"; shift; "$@" || fail=1; } + +[ -f build/felucca.fwsc ] || { echo "run ./build.sh first"; exit 1; } + +$CC -o "$OUT/storage_test" tests/storage_test.c +run "flash storage (A/B, torn writes)" "$OUT/storage_test" + +$CC -o "$OUT/recovery_test" tests/recovery_test.c +run "application USB recovery and boot-loop guard" "$OUT/recovery_test" + +$CC -o "$OUT/arranger_test" tests/arranger_test.c +run "song order, timing, repeats and missing scenes" "$OUT/arranger_test" +$CC -O2 -w -Ibuild/gen -Ifirmware/src -o "$OUT/song_audio_test" tests/song_audio_test.c -lm +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/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" +$CC -O2 -w -Ibuild/gen -Ifirmware/src -o "$OUT/seq2_test" tests/seq2_test.c -lm +run "sequencer 2.0: no drift, ratchets, roll, erase / undo, ghost / hard, chords, mute / solo" "$OUT/seq2_test" + +$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" +$CC -O2 -w -Ibuild/gen -Ifirmware/src -o "$OUT/punch_test" tests/punch_test.c -lm +run "punch-in FX: 16 effects, bounded, dry after release, FX-held keys" "$OUT/punch_test" "$OUT/punch-fx.wav" + +$CC -O2 -w -Ibuild/gen -Ifirmware/src -Ifirmware/hal -o "$OUT/ui_pages_test" tests/ui_pages_test.c -lm +run "live UI: pages, layers (punch, steps, erase, roll, key, mix), holds, drums, REC, fuzz" "$OUT/ui_pages_test" "$OUT" + +$CC -O2 -w -Ibuild/gen -Ifirmware/src -o "$OUT/soak_test" tests/soak_test.c -lm +run "soak: ${SOAK_MIN:-10} minutes of random live use (bounded, no hanging voices, idle after stop)" "$OUT/soak_test" "${SOAK_MIN:-10}" + +$CC -o "$OUT/upreset_test" tests/upreset_test.c +run "user presets (UP_PUT parser, bank round trip, versions)" "$OUT/upreset_test" + +$CC -o "$OUT/midi_uart_test" tests/midi_uart_test.c +run "TRS MIDI parser" "$OUT/midi_uart_test" + +$CC -o "$OUT/ota_test" tests/ota_test.c +run "M-UPGRADE entry" "$OUT/ota_test" build/felucca.fwsc + +head -c 200000 build/felucca.bin > "$OUT/old_app.bin" +python3 tools/fm1pkg_make.py "$OUT/old_app.bin" build/loader/ota.bin "$OUT/old.fwsc" >/dev/null +$CC -o "$OUT/ldr_test" tests/ldr_test.c +run "update loader: other app -> this build" "$OUT/ldr_test" "$OUT/old.fwsc" build/felucca.fwsc + +$CC -O2 -w -Ibuild/gen -Ifirmware/src -o "$OUT/hostsim" tests/hostsim.c -lm +$CC -O2 -w -Ibuild/gen -Ifirmware/src -o "$OUT/scale_test" tests/scale_test.c -lm +run "scales: white-key mapping and note lifecycle" "$OUT/scale_test" +run "DSP render (ANALOG preset 0)" "$OUT/hostsim" 0 0 1 "$OUT/render.wav" +mkdir -p build/tracks_demo +run "TRACKS: 4-track pattern, live recording (lengths, swing), voice budget, engine switch, cost" env TRACKS=build/tracks_demo "$OUT/hostsim" 0 0 1 "$OUT/tracks.wav" +$CC -w -Ibuild/gen -Ifirmware/src -o "$OUT/project_test" tests/project_test.c -lm +run "project formats (FUN3 / FUN2 / FUN1 -> FUN4), capture / apply, autosave" "$OUT/project_test" +$CC -O2 -w -Ibuild/gen -Ifirmware/src -o "$OUT/slicer_test" tests/slicer_test.c -lm +mkdir -p build/slicer_demo +run "SLICER: no clicks, timing, sync with the sequencer, STUT, cost, demos" "$OUT/slicer_test" build/slicer_demo +$CC -O2 -w -Ibuild/gen -Ifirmware/src -o "$OUT/regress" tests/regress.c -lm +run "regression: golden renders, health, voices, CPU budget" "$OUT/regress" tests/golden.txt tests/cpu_baseline.txt +# SLICE (tests/slice_test.c) needs a FELUCCA_SLICE=1 build; the engine is not built by default + +run "regression: target cost of the render loops" python3 tests/target_budget.py \ + build/felucca.dis tests/target_budget.txt + +run "installer CLI (fm1_install.py) against a simulated FM-1" python3 tests/install_test.py + +if command -v node >/dev/null 2>&1; then + run "web pages: editor protocol, samples, packages, update protocol" node web/test_web.mjs +else + echo "== skip web tests (no node)" +fi + +[ $fail -eq 0 ] && echo "ALL HOST TESTS PASSED" || { echo "HOST TESTS FAILED"; exit 1; } diff --git a/tests/scale_test.c b/tests/scale_test.c new file mode 100644 index 0000000..d4fe8e4 --- /dev/null +++ b/tests/scale_test.c @@ -0,0 +1,142 @@ +/* SPDX-License-Identifier: GPL-3.0-only */ +/* Exercise the real keyboard, recording, arp and MIDI-out paths on the host. + * Build with the same generated headers and flags as hostsim.c. */ +#include +#define main hostsim_main +#include "hostsim.c" +#undef main + +static const uint8_t WHITE_KEYS[] = {0, 2, 4, 6, 7, 9, 11, 12, 14, 16, 18, 19, 21, 23, 24, 26}; +static const struct { uint8_t count, notes[12]; } EXPECTED[] = { + {12, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}}, + {7, {0, 2, 4, 5, 7, 9, 11}}, {7, {0, 2, 3, 5, 7, 8, 10}}, + {7, {0, 2, 3, 5, 7, 9, 10}}, {7, {0, 2, 4, 5, 7, 9, 10}}, + {5, {0, 2, 4, 7, 9}}, {5, {0, 3, 5, 7, 10}}, + {7, {0, 2, 3, 5, 7, 8, 11}}, {7, {0, 1, 3, 5, 7, 8, 10}}, + {7, {0, 2, 4, 6, 7, 9, 11}}, {7, {0, 1, 3, 5, 6, 8, 10}}, + {7, {0, 2, 3, 5, 7, 9, 11}}, {6, {0, 3, 5, 6, 7, 10}}, + {6, {0, 2, 4, 6, 8, 10}}, {8, {0, 1, 3, 4, 6, 7, 9, 10}}, + {8, {0, 2, 3, 5, 6, 8, 9, 11}}, +}; + +static void mapping_test(void) +{ + track_t *t = &trk[0]; + uint32_t s, k, w; + int root, oct, trans; + assert(TP[P_SCALE].max + 1 == sizeof EXPECTED / sizeof EXPECTED[0]); + assert(sizeof SCALE_MASK / sizeof SCALE_MASK[0] == sizeof EXPECTED / sizeof EXPECTED[0]); + t->p[P_QUANT] = 2; + for (s = 0; s <= (uint32_t)TP[P_SCALE].max; s++) { + uint32_t mask = 0; + t->p[P_SCALE] = (int16_t)s; + for (k = 0; k < EXPECTED[s].count; k++) + mask |= 1u << EXPECTED[s].notes[k]; + assert(scale_mask(t) == mask); + for (root = 0; root < 12; root++) + for (oct = -3; oct <= 3; oct++) + for (trans = -24; trans <= 24; trans++) { + t->p[P_ROOT] = (int16_t)root; + song.octave = (int8_t)oct; + t->p[P_TRANS] = (int16_t)trans; + for (k = w = 0; k < 27u; k++) { + uint32_t actual = kb_map(t, k); + if (k == WHITE_KEYS[w]) { + /* Four white keys precede C4; use a positive cycle + * offset to independently handle the lower degrees. */ + int d = (int)w - 4 + 12 * EXPECTED[s].count; + int want = 60 + root + 12 * (oct + d / EXPECTED[s].count - 12) + + EXPECTED[s].notes[d % EXPECTED[s].count] + trans; + assert(actual == (uint32_t)clamp(want, 0, 127)); + w++; + } else { + assert(actual == KB_SILENT); + } + } + } + } + t->p[P_QUANT] = 0; + song.octave = 0; + t->p[P_TRANS] = -5; + for (k = 0; k < 27u; k++) + assert(kb_map(t, k) == 48u + k); + t->p[P_QUANT] = 2; + for (k = 0; k < 27u; k++) { /* the drum track: the key's lane, whatever the scale */ + TDRUM->p[P_QUANT] = 2; + assert(kb_map(TDRUM, k) == LANE_NOTE[lane_of_key(k)]); + } + t->engine = t->eng_req = 4; + if (drum_set() >= 0) { + t->p[P_E0] = (int16_t)drum_set(); + for (k = 0; k < 27u; k++) + assert(kb_map(t, k) == 36u + k); + } + t->engine = t->eng_req = 0; /* SNAP (QNT 1, the old ON): every key, rounded down */ + t->p[P_QUANT] = 1; + t->p[P_SCALE] = 2; /* C minor */ + t->p[P_ROOT] = 0; + t->p[P_TRANS] = 0; + song.octave = 0; + assert(kb_map(t, 11) == 63u && kb_map(t, 10) == 63u && kb_map(t, 7) == 60u && kb_map(t, 8) == 60u); + puts("scales: all 16 scales, 12 roots, octave/transpose ranges, bypass, drums and SNAP ok"); +} + +static void key_events_test(void) +{ + track_t *t = &trk[0]; + uint32_t before; + memset(trk, 0, sizeof trk); + memset(&song, 0, sizeof song); + host_tracks_init(); + kb_prev = 0; + usb.config = 1; + mo_w = mo_r = 0; + t->p[P_QUANT] = 2; + t->p[P_SCALE] = 2; /* C minor: E key plays Eb */ + t->p[P_AMODE] = 1; + song.playing = song.rec = 1; + fm1_in.notes = 1u << 8; /* C# is silent */ + keyboard_block(); + assert(t->arp_phys == 0 && t->nheld == 0 && t->step[0].n == 0 && mo_w == 0); + t->p[P_QUANT] = 0; /* releasing a muted key stays silent */ + fm1_in.notes = 0; + keyboard_block(); + assert(mo_w == 0); + t->p[P_QUANT] = 2; + fm1_in.notes = (1u << 11) | (1u << 10); /* E and D#: only Eb sounds/records */ + keyboard_block(); + assert(t->arp_phys == 1 && t->nheld == 1 && t->held[0] == 63); + assert(t->step[0].n == 0); /* ARP on: what it plays is recorded, not the key */ + arp_tick(t, CTL * (uint32_t)song.g[G_BPM]); + assert(t->step[0].n == 1 && t->step[0].note[0] == 63); + assert(mo_w == 1 && ((midi_out_q[0] >> 16) & 127u) == 63); + t->p[P_SCALE] = 9; + t->p[P_ROOT] = 6; + t->p[P_TRANS] = 12; + song.octave = 1; + song.sel = 1; /* key-up follows the original note/part */ + fm1_in.notes = 0; + keyboard_block(); + assert(t->arp_phys == 0 && t->nheld == 0); + assert(mo_w == 2 && ((midi_out_q[1] >> 16) & 127u) == 63); + assert(((midi_out_q[1] >> 8) & 255u) == 0x80u); + song.sel = 0; + t->p[P_QUANT] = 0; + fm1_in.notes = 1u << 8; /* held black key must release after enabling mode */ + keyboard_block(); + before = mo_w; + assert(t->arp_phys == 1); + t->p[P_QUANT] = 2; + fm1_in.notes = 0; + keyboard_block(); + assert(t->arp_phys == 0 && t->nheld == 0 && mo_w == before + 1); + puts("scales: silent keys, arp, live recording, MIDI out and held-note changes ok"); +} + +int main(void) +{ + host_tracks_init(); + mapping_test(); + key_events_test(); + return 0; +} diff --git a/tests/seq2_test.c b/tests/seq2_test.c new file mode 100644 index 0000000..746dc95 --- /dev/null +++ b/tests/seq2_test.c @@ -0,0 +1,385 @@ +/* SPDX-License-Identifier: GPL-3.0-only */ +/* SLOOP 2.0 sequencer: the transport clock and what plays on it. + * timing the kick and the click stay together for 64 bars at any tempo (no drift); a tempo or DIV + * change mid-step plays one step, not a burst; LEN changes keep the track in phase; an odd + * LEN with SWING stays in phase with a 16-step track + * ratchet x2 / x3 / x4 hits evenly in their step (drums and synth) + * roll ARP + key: hits on the grid at G_ROLL; recorded as ratchets (1/32 -> x2 on 1/16 steps) + * erase EDIT + key: the lane goes as the playhead passes (playing), all of it (stopped); undo / redo + * levels OCT- / OCT+ held on the drum track: ghost / hard hits, recorded as such + * chords P_CHORD: one key plays the chord of the scale (white keys walk the degrees from C4) + * mute P_MUTE / solo: no new notes, the output fades + * Exit status: the number of failed checks. */ +#define main hostsim_main +#include "hostsim.c" +#undef main +#include + +static uint64_t blk; +typedef struct { uint64_t blk; uint8_t note, vel; } hit_t; +static hit_t hits[200000]; +static uint32_t nhits; +static void run_block(void) +{ + int32_t out[CTL * 2]; + uint32_t a = drums.age, k; + mix_block(out, CTL); + if (drums.age != a) + for (k = 0; k < NDRUM; k++) + if (drums.v[k].age > a && nhits < 200000u) { + hits[nhits].blk = blk; + hits[nhits].note = drums.v[k].note; + hits[nhits].vel = drums.v[k].vel; + nhits++; + } + blk++; +} +static void reset(uint32_t bpm) +{ + uint32_t i; + host_tracks_init(); + for (i = 0; i < NTRK; i++) + steps_clear(&trk[i]); + memset(&drums, 0, sizeof drums); + drums.set = -2; + nhits = 0; + blk = 0; + song.g[G_BPM] = (int16_t)bpm; + song.rec = 0; + rec_wait = 0; + fm1_in.notes = fm1_in.buttons = 0; + kb_prev = 0; + ly_bit[LY_ROLL] = 1u << 8; /* (the buttons: any bits) */ + ly_bit[LY_ERASE] = 1u << 4; + dyn_bit[0] = 1u << 0; + dyn_bit[1] = 1u << 1; +} +static int fails; +static void check(int ok, const char *what) +{ + printf("seq2: %-72s %s\n", what, ok ? "ok" : "FAIL"); + fails += !ok; +} +static uint32_t count_note(uint32_t note, uint64_t b0, uint64_t b1) +{ + uint32_t i, n = 0; + for (i = 0; i < nhits; i++) + n += hits[i].note == note && hits[i].blk >= b0 && hits[i].blk < b1; + return n; +} + +static void t_drift(void) +{ + static const uint32_t BPM[5] = {87, 90, 120, 128, 174}; + uint32_t bi, worst = 0; + for (bi = 0; bi < 5u; bi++) { + uint32_t i, nk = 0, nc = 0, bad = 0; + uint64_t kb[80], cb[80]; + reset(BPM[bi]); + song.g[G_CLOCK] = 2; /* the click on: its downbeat (77) */ + dstep_set(&TDRUM->dstep[0], 0, LV_NORM, 0); /* a kick on the 1 */ + transport_req = 1; + while (blk < (uint64_t)(FS * 60.0 / BPM[bi] * 4 * 66 / CTL)) + run_block(); + for (i = 0; i < nhits; i++) { + if (hits[i].note == 36 && nk < 80u) + kb[nk++] = hits[i].blk; + if (hits[i].note == 77 && nc < 80u) + cb[nc++] = hits[i].blk; + } + for (i = 0; i < nk && i < nc && i < 64u; i++) { + uint32_t d = kb[i] > cb[i] ? (uint32_t)(kb[i] - cb[i]) : (uint32_t)(cb[i] - kb[i]); + bad += d != 0u; + worst = d > worst ? d : worst; + } + if (bad || nk < 64u || nc < 64u) + printf("seq2: %u BPM: %u kicks, %u clicks, %u apart\n", BPM[bi], nk, nc, bad); + worst += (nk < 64u || nc < 64u) * 1000u; + } + check(worst == 0u, "64 bars at 87..174 BPM: every kick in the block of its downbeat click"); +} + +static void t_burst(void) +{ + uint32_t i, n0; + int ok1, ok2; + reset(90); + TDRUM->p[P_SDIV] = 0; /* 1/4 */ + for (i = 0; i < 16u; i++) + dstep_set(&TDRUM->dstep[i], 4, LV_NORM, 0); + transport_req = 1; + while (clk_beat < 2u || clk_pos < BEAT_U * 85u / 100u) + run_block(); + TDRUM->p[P_SDIV] = 3; /* DIV 1/4 -> 1/32 at 85 % of a step */ + n0 = nhits; + run_block(); + ok1 = nhits - n0 <= 1u; + reset(40); + for (i = 0; i < 16u; i++) + dstep_set(&TDRUM->dstep[i], 4, LV_NORM, 0); + transport_req = 1; + while (clk_beat < 1u || clk_pos < BEAT_U / 4u * 3u / 4u) + run_block(); + song.g[G_BPM] = 240; /* 40 -> 240 in the middle of a step */ + n0 = nhits; + run_block(); + ok2 = nhits - n0 <= 1u; + check(ok1 && ok2, "DIV 1/4 -> 1/32 and 40 -> 240 BPM mid-step: one step a block, no burst"); +} + +static void t_swing_odd(void) +{ + uint32_t i, ok = 1, starts0 = 0, startsd = 0; + uint64_t at0[64], atd[64]; + reset(120); + song.g[G_SWING] = 50; + trk[0].p[P_SLEN] = 3; + TDRUM->p[P_SLEN] = 16; + transport_req = 1; + for (i = 0; i < 20u * FS / CTL; i++) { + uint32_t b0 = trk[0].seq_idx, bd = TDRUM->seq_idx; + uint32_t f0 = trk[0].seq_abs, fd = TDRUM->seq_abs; + run_block(); + if (trk[0].seq_abs != f0 && trk[0].seq_idx == 0u && starts0 < 64u) + at0[starts0++] = blk - 1u; + if (TDRUM->seq_abs != fd && TDRUM->seq_idx == 0u && startsd < 64u) + atd[startsd++] = blk - 1u; + (void)b0; + (void)bd; + } + /* step 48 = cycle 16 of 3 = bar 3 of 16; step 144 = cycle 48 = bar 9 */ + ok = starts0 > 48u && startsd > 9u && at0[16] == atd[3] && at0[48] == atd[9]; + if (!ok) + printf("seq2: %u %u starts; step 48: %llu %llu, step 144: %llu %llu\n", starts0, startsd, + (unsigned long long)at0[16], (unsigned long long)atd[3], (unsigned long long)at0[48], (unsigned long long)atd[9]); + check(ok, "SWING 75 %, LEN 3 against LEN 16: in phase after 15 bars (no drift)"); +} + +static void t_len_phase(void) +{ + reset(120); + TDRUM->p[P_SLEN] = 32; + trk[0].p[P_SLEN] = 16; + transport_req = 1; + while (TDRUM->seq_idx != 20u) + run_block(); + TDRUM->p[P_SLEN] = 16; /* LEN 32 -> 16 at step 20 */ + while (TDRUM->seq_idx == 20u) + run_block(); + check(TDRUM->seq_idx == trk[0].seq_idx, "LEN 32 -> 16 while playing: in phase with a 16-step track"); +} + +static void t_ratchet(void) +{ + uint32_t i, n = 0, gaps_ok = 1; + uint64_t b[8]; + reset(120); + dstep_set(&TDRUM->dstep[0], 4, LV_NORM, 3); /* a hat x4 on step 0 */ + dstep_set(&TDRUM->dstep[1], 0, LV_NORM, 0); /* a kick on step 1 */ + transport_req = 1; + while (blk < div_samples(2) * 2u / CTL + 2u) + run_block(); + for (i = 0; i < nhits; i++) + if (hits[i].note == 42 && n < 8u) + b[n++] = hits[i].blk; + for (i = 1; i < n; i++) { + int32_t g = (int32_t)(b[i] - b[i - 1]), want = (int32_t)(div_samples(2) / 4u / CTL); + gaps_ok &= g >= want - 1 && g <= want + 1; + } + check(n == 4u && gaps_ok && count_note(36, 0, blk) == 1u, "drums: a hat x4 plays 4 even hits in its step, the next step plays"); + reset(120); + host_preset(&trk[0], 0, 7); /* TRAP PLUCK (POLY) */ + put_step(&trk[0], 0, 1, (const uint8_t[]){60}, ST_NOTE, 0); + trk[0].step[0].rat = 2; /* x3 */ + transport_req = 1; + { + uint32_t starts = 0, last = vage; + while (blk < div_samples(2) / CTL) { + run_block(); + if (vage != last) + starts += vage - last; + last = vage; + } + check(starts == 3u, "synth: a note x3 starts 3 times in its step"); + } +} + +static void t_roll(void) +{ + uint32_t i, k = 6, n; /* key 6 = B3 -> lane 3 (clap) */ + reset(120); + song.g[G_ROLL] = 2; /* 1/32 */ + song.sel = TRK_DRUM; + song.rec = 1u << TRK_DRUM; + transport_req = 1; + run_block(); + fm1_in.buttons = ly_bit[LY_ROLL]; /* ARP held */ + fm1_in.notes = 1u << k; + for (i = 0; i < div_samples(2) * 8u / CTL; i++) /* 8 steps */ + run_block(); + fm1_in.notes = 0; + fm1_in.buttons = 0; + run_block(); + n = count_note(LANE_NOTE[3], 0, blk); + { + uint32_t s, rat_ok = 1, on = 0; + for (s = 1; s < 7u; s++) { + on += dstep_has(&TDRUM->dstep[s], 3); + rat_ok &= !dstep_has(&TDRUM->dstep[s], 3) || dstep_rat(&TDRUM->dstep[s], 3) == 1u; + } + if (n < 15u || n > 17u) + printf("seq2: roll: %u hits\n", n); + check(n >= 15u && n <= 17u, "roll 1/32 held 8 steps: ~16 hits"); + check(on >= 6u && rat_ok, "roll 1/32 recorded: one hit a step, ratchet x2"); + } +} + +static void t_erase_undo(void) +{ + uint32_t i, left = 0, kept = 0; + reset(120); + for (i = 0; i < 16u; i++) { + dstep_set(&TDRUM->dstep[i], 4, LV_NORM, 0); /* hats everywhere */ + if (i % 4u == 0u) + dstep_set(&TDRUM->dstep[i], 0, LV_NORM, 0); + } + song.sel = TRK_DRUM; + transport_req = 1; + while (TDRUM->seq_idx != 4u) + run_block(); + fm1_in.buttons = ly_bit[LY_ERASE]; /* EDIT held + the hat key (C4 = key 7) */ + fm1_in.notes = 1u << 7; + while (TDRUM->seq_idx != 7u) + run_block(); + for (i = 0; i < 20u; i++) /* (into step 7, not 8) */ + run_block(); + fm1_in.notes = 0; + fm1_in.buttons = 0; + run_block(); + for (i = 0; i < 16u; i++) { + left += dstep_has(&TDRUM->dstep[i], 4); + kept += dstep_has(&TDRUM->dstep[i], 0); + } + if (left != 12u) + printf("seq2: erase: %u hats left, %u kicks; %d %d\n", left, kept, dstep_has(&TDRUM->dstep[5], 4), dstep_has(&TDRUM->dstep[9], 4)); + check(left == 12u && kept == 4u && !dstep_has(&TDRUM->dstep[5], 4) && dstep_has(&TDRUM->dstep[9], 4), + "EDIT + hat while playing steps 4..7: those hats gone, the rest and the kicks kept"); + { /* undo (ui.c undo_swap): the hats back */ + step_t tmp[NSTEP]; + memcpy(tmp, TDRUM->step, sizeof tmp); + memcpy(TDRUM->step, undo.st, sizeof tmp); + memcpy(undo.st, tmp, sizeof tmp); + } + left = 0; + for (i = 0; i < 16u; i++) + left += dstep_has(&TDRUM->dstep[i], 4); + check(left == 16u && undo.trk == TRK_DRUM, "undo: the erased hats are back"); + transport_req = 2; + run_block(); + fm1_in.buttons = ly_bit[LY_ERASE]; /* stopped: every hat of the pattern */ + fm1_in.notes = 1u << 7; + run_block(); + fm1_in.notes = fm1_in.buttons = 0; + run_block(); + left = 0; + for (i = 0; i < 16u; i++) + left += dstep_has(&TDRUM->dstep[i], 4); + check(left == 0u, "EDIT + hat while stopped: every hat gone"); +} + +static void t_levels(void) +{ + uint32_t i, gh = 0, hd = 0; + reset(120); + song.sel = TRK_DRUM; + song.rec = 1u << TRK_DRUM; + transport_req = 1; + run_block(); + fm1_in.buttons = dyn_bit[0]; /* OCT- held: a ghost snare (A3 = key 4) */ + fm1_in.notes = 1u << 4; + run_block(); + fm1_in.notes = 0; + run_block(); + while (TDRUM->seq_idx != 3u) + run_block(); + fm1_in.buttons = dyn_bit[1]; /* OCT+ held: a hard kick */ + fm1_in.notes = 1u << 0; + run_block(); + fm1_in.notes = fm1_in.buttons = 0; + run_block(); + for (i = 0; i < 16u; i++) { + if (dstep_has(&TDRUM->dstep[i], 2)) + gh = dstep_lvl(&TDRUM->dstep[i], 2); + if (dstep_has(&TDRUM->dstep[i], 0)) + hd = dstep_lvl(&TDRUM->dstep[i], 0); + } + check(gh == LV_GHOST && hd == LV_HARD, "OCT- / OCT+ held on the drums: a ghost snare and a hard kick recorded"); + { + uint32_t vg = 0, vh = 0; + for (i = 0; i < nhits; i++) { + if (hits[i].note == 38) + vg = hits[i].vel; + if (hits[i].note == 36) + vh = hits[i].vel; + } + check(vg == 42u && vh == 127u, "... and played at 42 / 127"); + } +} + +static void t_chords(void) +{ + uint8_t c[4]; + uint32_t n; + reset(120); + trk[0].p[P_ROOT] = 0; + trk[0].p[P_SCALE] = 2; /* C minor */ + trk[0].p[P_CHORD] = 3; /* 9TH: 1 3 7 9 */ + n = chord_notes(&trk[0], kb_map(&trk[0], 7), c); /* C4: i */ + check(n == 4u && c[0] == 60 && c[1] == 63 && c[2] == 70 && c[3] == 74, "chord 9TH on C4 in C minor: C Eb Bb D"); + trk[0].p[P_CHORD] = 1; + n = chord_notes(&trk[0], kb_map(&trk[0], 9), c); /* D4: ii (dim) */ + check(n == 3u && c[0] == 62 && c[1] == 65 && c[2] == 68, "chord TRIAD on D4 in C minor: D F Ab"); + check(kb_map(&trk[0], 8) == KB_SILENT, "chord mode: the black keys are silent"); +} + +static void t_mute(void) +{ + uint32_t i, n0; + reset(120); + for (i = 0; i < 16u; i++) + dstep_set(&TDRUM->dstep[i], 0, LV_NORM, 0); + transport_req = 1; + while (blk < 200u) + run_block(); + TDRUM->p[P_MUTE] = 1; + n0 = nhits; + while (blk < 400u) + run_block(); + check(nhits == n0, "drum track muted: no hits"); + TDRUM->p[P_MUTE] = 0; + song.solo = 1u; /* track 1 soloed: the drums silent */ + n0 = nhits; + while (blk < 600u) + run_block(); + check(nhits == n0 && TDRUM->att == 32767, "track 1 soloed: the drums silent (faded out)"); + song.solo = 0; + while (blk < 800u) + run_block(); + check(nhits > n0 && TDRUM->att == 0, "solo off: the drums back"); +} + +int main(void) +{ + t_drift(); + t_burst(); + t_swing_odd(); + t_len_phase(); + t_ratchet(); + t_roll(); + t_erase_undo(); + t_levels(); + t_chords(); + t_mute(); + printf("seq2: %s\n", fails ? "FAILED" : "all checks ok"); + return fails; +} diff --git a/tests/slice_loop.py b/tests/slice_loop.py new file mode 100644 index 0000000..16328c0 --- /dev/null +++ b/tests/slice_loop.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-3.0-only +# Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments +"""A user-style drum loop for the SLICE AUTO test (tests/slice_test.c): two bars at 96 BPM with a +swing, played by Felucca's generated drums (build/genwav, tools/gen_waves.py) at +44.1 kHz with a little noise, not on the BREAK's grid or tempo. Writes OUT.wav and OUT.hits (one +line per onset: seconds). + tests/slice_loop.py OUT""" +import random +import struct +import sys +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "tools")) +import sampleio as sio # noqa: E402 + +ROOT = Path(__file__).resolve().parents[1] +GEN = ROOT / "build" / "genwav" +SR, BPM, SWING = 44100, 96, 0.16 # odd 16ths late by 16 % of a 16th +# (16th of the two bars, sound, gain) +HITS = [(0, "KICK", 1.0), (0, "CHAT", 0.4), (2, "CHAT", 0.3), (4, "SNARE", 0.9), (4, "CHAT", 0.35), + (6, "KICK", 0.8), (8, "CHAT", 0.4), (9, "RIM", 0.5), (10, "KICK", 0.85), (12, "SNARE", 0.95), + (14, "OHAT", 0.35), (16, "KICK", 1.0), (16, "CHAT", 0.4), (19, "KICK", 0.7), (20, "SNARE", 0.9), + (22, "CHAT", 0.3), (24, "CHAT", 0.4), (26, "KICK", 0.85), (27, "KICK", 0.6), (28, "SNARE", 1.0), + (28, "CLAP", 0.6), (29, "TOM HI", 0.6), (30, "TOM LO", 0.7), (31, "SNARE", 0.3)] + + +def main(out): + six = 60 / BPM / 4 + n = int(32 * six * SR) + x = [0.0] * n + rnd = random.Random(7) + times = {} + for step, name, gain in HITS: + t = step * six + (SWING * six if step % 2 else 0) + sr, s = sio.read_any_wav(GEN / f"D {name}.wav") + s = sio.resample(s, sr, SR) + i0 = int(round(t * SR)) + for i, v in enumerate(s): + if i0 + i < n: + x[i0 + i] += v * gain + times[i0] = t + pk = max(abs(v) for v in x) + pcm = [max(-32768, min(32767, int(v / pk * 28000 + rnd.uniform(-60, 60)))) for v in x] + w = Path(out + ".wav") + data = struct.pack(f"<{n}h", *pcm) + w.write_bytes(b"RIFF" + struct.pack(" slices (mod the count, START, ROOT, an empty slot plays BREAK); ONE / GATE / LOOP. + * 5. demos into DEMO_DIR: every preset with its pattern, BREAK re-sequenced, the user loop sliced AUTO. */ +#include +#include +static uint32_t host_slots[3u * 0x14000u / 4u]; /* USR1..3, as the flash at 0xA0000 */ +#define SMP_USER_XIP(k) ((const uint8_t *)host_slots + (k) * SMP_USER_SIZE) +#define main hostsim_main +#include "hostsim.c" +#undef main + +static int fails; +static void check(const char *what, int ok, const char *fmt, ...) +{ + printf("slice: %-58s %s", what, ok ? "ok" : "FAIL"); + if (fmt) { + va_list ap; + va_start(ap, fmt); + printf(" ("); + vprintf(fmt, ap); + printf(")"); + va_end(ap); + } + printf("\n"); + fails += !ok; +} + +/* 1: every stored state == the decoder's state there; returns the mismatches */ +static uint32_t table_check(const slc_src_t *s) +{ + slc_dec_t d; + uint32_t pos, k = 0, a = 0, bad = 0; + slc_dec_at(&d, 0, 0); + for (pos = 0; pos < s->len; pos++) { + while (k < SLC_GRID && slc_gpos(s, k) == pos) + bad += s->grid[k++] != slc_dec_st(&d); + while (a < s->nauto && s->apos[a] == pos) + bad += s->ast[a++] != slc_dec_st(&d); + slc_dec_next(s, &d); + } + return bad + (SLC_GRID - k) + (s->nauto - a); +} + +/* 2: hits h[] (samples) against slice starts: each hit has a start in [h - early, h + late], each start + * (but the first, at 0) is within that of a hit. Writes a list into msg. */ +static int match(const slc_src_t *s, const uint32_t *h, uint32_t nh, uint32_t early, uint32_t late, char *msg, + size_t mn, int32_t *worst) +{ + uint32_t i, j, miss = 0, extra = 0; + int32_t w = 0; + for (i = 0; i < nh; i++) { + int found = 0; + for (j = 0; j < s->nauto; j++) + if (s->apos[j] + early >= h[i] && s->apos[j] <= h[i] + late) { + int32_t e = (int32_t)h[i] - (int32_t)s->apos[j]; + found = 1; + w = abs(e) > abs(w) ? e : w; + } + miss += !found; + } + for (j = 1; j < s->nauto; j++) { + int near = 0; + for (i = 0; i < nh; i++) + near |= s->apos[j] + early >= h[i] && s->apos[j] <= h[i] + late; + extra += !near; + } + snprintf(msg, mn, "%u onsets, %u slices, %u missed, %u extra, worst %+.1f ms", nh, s->nauto, miss, extra, + w * 1000.0 / (s->rate * 44100.0 / 65536.0)); + *worst = w; + return !miss && !extra && (nh == 0 || h[0] > early || s->apos[0] == 0); +} + +/* 3: slice j of DIV div read backwards == forwards reversed */ +static uint32_t rev_check(uint32_t src, uint32_t div, uint32_t j) +{ + const slc_src_t *s = slc_get(src); + static int32_t fw[1 << 18]; + static int16_t rb[SLC_RB]; + voice_t v; + slc_dec_t d; + uint32_t a, b, st, i, n, bad = 0; + int32_t x; + slc_bounds(s, div, j, &a, &b, &st); + slc_dec_at(&d, a, st); + for (n = 0; d.pos < b && n < (1u << 18); n++) + fw[n] = slc_dec_next(s, &d); + memset(&v, 0, sizeof v); + v.ph[0] = b; + v.ph[2] = a; + v.s[0] = 0x7FFFFFFF; + v.s[4] = (int32_t)(src | (st >> 24) << 2 | 1u << 6 | j << 8 | div << 16); + for (i = 0; i < n; i++) + bad += !slc_rev(s, &v, rb, 0, &x) || x != fw[n - 1u - i]; + bad += slc_rev(s, &v, rb, 0, &x) != 0; /* and then it ends */ + return bad; +} + +static uint32_t slice_of(const voice_t *v) { return ((uint32_t)v->s[4] >> 8) & 63u; } +static voice_t *voice_of(track_t *t, uint32_t note) +{ + uint32_t i; + for (i = 0; i < NVOICE; i++) + if (t->v[i].active && t->v[i].note == note) + return &t->v[i]; + return 0; +} +static void blocks(uint32_t n) +{ + int32_t o[2 * CTL]; + while (n--) + mix_block(o, CTL); +} + +/* 5: a pattern on track 1 (SLICE preset pi, then edits), the sequencer for `bars` bars, a tail */ +typedef struct { + const char *file; + uint32_t preset, bpm, nsteps, bars; + const uint8_t *notes; + int16_t src, div; /* -1 = the preset's */ +} demo_t; +static int demo(const char *dir, const demo_t *dm) +{ + char path[512]; + FILE *w; + track_t *t = &trk[0]; + uint32_t f, i, frames, peak = 0, bar = 0; + snprintf(path, sizeof path, "%s/%s", dir, dm->file); + if (!(w = fopen(path, "wb"))) + return 1; + host_tracks_init(); + song.g[G_BPM] = (int16_t)dm->bpm; + host_preset(t, 8, dm->preset); + if (dm->src >= 0) + t->p[P_E0] = dm->src; + if (dm->div >= 0) + t->p[P_E1] = dm->div; + for (i = 0; i < dm->nsteps; i++) { + uint8_t n = dm->notes[i]; + put_step(t, i, n ? 1u : 0u, &n, n ? ST_NOTE : ST_REST, i % 4u == 0u ? SF_ACCENT : 0u); + } + t->p[P_SLEN] = (int16_t)dm->nsteps; + bar = (uint32_t)(4.0 * 60.0 / dm->bpm * FS); + frames = dm->bars * bar + FS; + wav_hdr(w, frames); + transport_req = 1; + for (f = 0; f < frames; f += CTL) { + int32_t o[2 * CTL]; + if (f >= dm->bars * bar && f < dm->bars * bar + CTL) + transport_req = 2; + mix_block(o, CTL); + for (i = 0; i < CTL; i++) { + uint32_t a = (uint32_t)abs(o[2 * i]); + peak = a > peak ? a : peak; + wav_put(w, o[2 * i], o[2 * i + 1]); + } + } + fclose(w); + printf("slice: demo %-30s %u bars at %u BPM, peak %u\n", dm->file, dm->bars, dm->bpm, peak); + return peak < 2000u || peak > 32767u; +} + +static int in_child(int (*fn)(const char *, const demo_t *), const char *dir, const demo_t *dm) +{ + pid_t pid; + int st = 0; + fflush(stdout); + if (!(pid = fork())) { + int rc = fn(dir, dm); + fflush(stdout); + _exit(rc); + } + waitpid(pid, &st, 0); + return !WIFEXITED(st) || WEXITSTATUS(st); +} + +static long load(const char *path, void *dst, long max) +{ + FILE *f = fopen(path, "rb"); + long n; + if (!f) + return -1; + n = (long)fread(dst, 1, (size_t)max, f); + fclose(f); + return n; +} + +int main(int argc, char **argv) +{ + static const uint8_t CHOP[16] = {60, 61, 62, 67, 64, 65, 60, 69, 68, 70, 62, 67, 72, 72, 74, 64}; /* ui.c 9..11 */ + static const uint8_t STUTTER[16] = {60, 60, 61, 61, 62, 0, 63, 63, 64, 65, 65, 0, 66, 66, 66, 67}; + static const uint8_t SLICES[16] = {60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75}; + static const uint8_t RESEQ[32] = {60, 0, 62, 60, 64, 0, 67, 62, 60, 69, 70, 0, 72, 0, 64, 72, /* 2 bars */ + 60, 61, 60, 61, 64, 0, 66, 67, 68, 64, 70, 71, 72, 72, 72, 72}; + static const uint8_t USR[32] = {60, 0, 61, 0, 62, 0, 63, 64, 65, 0, 66, 0, 67, 0, 60, 61, + 60, 0, 60, 63, 62, 0, 68, 0, 65, 66, 67, 0, 62, 70, 71, 72}; + const char *loop = argc > 1 ? argv[1] : "build/host/slice_loop"; + const char *dir = argc > 2 ? argv[2] : "build/slice_demo"; + char path[512], msg[160]; + uint32_t hits[64], nh = 0, i, bad; + int32_t worst; + long n; + + /* 1 */ + check("BREAK: build-time table == decoder states", !(bad = table_check(&SLC_BREAK)), "%u of %u differ", bad, + SLC_GRID + SLC_BREAK.nauto); + + /* 2: the detector on BREAK (hits = its build-time AUTO table) */ + { + static slc_src_t tmp; + tmp = SLC_BREAK; + tmp.len = 0; + slc_scan(&tmp, SLC_BREAK.len); + tmp.len = SLC_BREAK.len; + bad = memcmp(tmp.grid, SLC_BREAK.grid, sizeof tmp.grid) != 0; + check("BREAK: slc_scan grid == build-time grid", !bad, 0); + check("BREAK: slc_scan finds the hits (-6 .. +1 ms)", + match(&tmp, SLC_BREAK.apos, SLC_BREAK.nauto, 132, 22, msg, sizeof msg, &worst), "%s", msg); + } + + /* 2: the user loop, through the slot image and smp_user_scan */ + snprintf(path, sizeof path, "%s.hdr", loop); + n = load(path, host_slots, SMP_USER_DATA); + snprintf(path, sizeof path, "%s.bin", loop); + n = n == (long)sizeof(smp_user_hdr_t) ? load(path, (uint8_t *)host_slots + SMP_USER_DATA, SMP_USER_SIZE - SMP_USER_DATA) : -1; + { + FILE *f; + double s; + snprintf(path, sizeof path, "%s.hits", loop); + if ((f = fopen(path, "r"))) { + while (nh < 64u && fscanf(f, "%lf", &s) == 1) + hits[nh++] = (uint32_t)(s * 22050.0 + 0.5); + fclose(f); + } + } + if (n <= 0 || !nh) { + printf("slice: no user loop (%s.hdr / .bin / .hits: tests/slice_loop.py + fm1_sample_upload.py build)\n", loop); + return 1; + } + if ((uintptr_t)host_slots < (uintptr_t)SMP_DATA || (uintptr_t)host_slots - (uintptr_t)SMP_DATA > 0xF0000000u) { + printf("slice: the slot image must lie above SMP_DATA within 4 GiB (32-bit offsets)\n"); + return 1; + } + smp_user_scan(0); + check("USR1: valid after smp_user_scan, slice table built", usr_nz[0] && slc_usr[0].len && slc_get(1) != 0, + "%u zones, %u samples", usr_nz[0], slc_usr[0].len); + check("USR1: table == decoder states", !(bad = table_check(&slc_usr[0])), "%u differ", bad); + check("USR1: AUTO slices at the onsets (-6 .. +1 ms)", match(&slc_usr[0], hits, nh, 132, 22, msg, sizeof msg, &worst), + "%s", msg); + printf("slice: USR1 AUTO starts (ms):"); + for (i = 0; i < slc_usr[0].nauto; i++) + printf(" %.1f", slc_usr[0].apos[i] * 1000.0 / 22050.0); + printf("\nslice: onsets (ms): "); + for (i = 0; i < nh; i++) + printf(" %.1f", hits[i] * 1000.0 / 22050.0); + printf("\n"); + check("USR2 / USR3: empty, no material", !slc_get(2) && !slc_get(3), 0); + + /* 3 */ + for (bad = 0, i = 0; i < 16u; i++) + bad += rev_check(0, 2, i); + for (i = 0; i < 4u; i++) + bad += rev_check(0, 0, i); + for (i = 0; i < SLC_BREAK.nauto; i++) + bad += rev_check(0, SLC_DIV_AUTO, i); + for (i = 0; i < 4u; i++) + bad += rev_check(1, 0, i); + for (i = 0; i < slc_usr[0].nauto; i++) + bad += rev_check(1, SLC_DIV_AUTO, i); + check("REV: backwards == forwards reversed (BREAK, USR1; 4 / 16 / AUTO)", !bad, "%u samples differ", bad); + + /* 4: keys / steps -> slices */ + { + track_t *t = &trk[0]; + voice_t *v; + uint32_t a, b, st, ok = 1; + host_tracks_init(); + host_preset(t, 8, 0); /* BREAK 16 */ + trk_note_on(t, 65, 100); + v = voice_of(t, 65); + slc_bounds(&SLC_BREAK, 2, 5, &a, &b, &st); + ok &= v && slice_of(v) == 5u && v->ph[0] == a && v->ph[2] == b; + trk_note_on(t, 59, 100); + ok &= (v = voice_of(t, 59)) && slice_of(v) == 15u; + trk_note_on(t, 76, 100); + ok &= (v = voice_of(t, 76)) && slice_of(v) == 0u; + t->p[P_E2] = 3; /* START */ + trk_note_on(t, 60, 100); + ok &= (v = voice_of(t, 60)) && slice_of(v) == 3u; + t->p[P_E2] = 0; + t->p[P_ROOT] = 2; /* ROOT D: D4 is slice 0 */ + trk_note_on(t, 62, 100); + ok &= (v = voice_of(t, 62)) && slice_of(v) == 0u; + check("keys: note - C4 - ROOT + START mod 16", ok, 0); + ok = 1; + t->p[P_ROOT] = 0; + t->p[P_E1] = SLC_DIV_AUTO; + trk_note_on(t, 72, 100); /* 12 mod 10 hits */ + ok &= (v = voice_of(t, 72)) && slice_of(v) == 12u % SLC_BREAK.nauto && v->ph[0] == SLC_BREAK.apos[12u % SLC_BREAK.nauto]; + t->p[P_E0] = 2; /* USR2: empty -> BREAK */ + trk_note_on(t, 61, 100); + ok &= (v = voice_of(t, 61)) && ((uint32_t)v->s[4] & 3u) == 0u && v->ph[0] == SLC_BREAK.apos[1]; + t->p[P_E0] = 1; /* USR1 */ + trk_note_on(t, 63, 100); + ok &= (v = voice_of(t, 63)) && ((uint32_t)v->s[4] & 3u) == 1u && v->ph[0] == slc_usr[0].apos[3]; + check("keys: AUTO count, an empty slot plays BREAK, USR1", ok, 0); + ok = 1; + song.octave = 0; + t->p[P_E0] = 0; + ok &= kb_map(t, 0) == 60u && kb_map(t, 9) == 69u; + check("keys: the lowest key is slice 0 (no scale)", ok, 0); + } + { /* ONE / GATE / LOOP: a 125 ms slice, the note released after 10 ms */ + static const char *const MN[3] = {"ONE", "GATE", "LOOP"}; + uint32_t m; + for (m = 0; m < 3u; m++) { + track_t *t = &trk[0]; + voice_t *v; + uint32_t held, after, k; + host_tracks_init(); + host_preset(t, 8, 0); + t->p[P_E4] = (int16_t)m; + t->p[P_REL] = 10; + trk_note_on(t, 60, 100); + v = voice_of(t, 60); + if (m == SLC_LOOP) { + blocks(FS / CTL); /* 1 s held: still looping */ + held = v && v->active; + } else { + held = 1; + } + blocks(FS / 100u / CTL); + trk_note_off(t, 60); + blocks(FS / 20u / CTL); /* 50 ms after the note-off */ + after = v && v->active; + for (k = 0; k < FS / 4u / CTL && v && v->active; k++) + blocks(1); + snprintf(msg, sizeof msg, "MODE %s: %s", MN[m], m == SLC_ONE ? "plays on after the note-off, ends at the slice end" : + m == SLC_GATE ? "stops at the note-off" : "loops while held, ends after the note-off"); + check(msg, held && (m == SLC_ONE ? after : !after) && !(v && v->active), 0); + } + } + + /* 5 */ + { + const demo_t D[] = { + {"preset_break16.wav", 0, 120, 16, 4, CHOP, -1, -1}, + {"preset_chop8.wav", 1, 120, 16, 4, STUTTER, -1, -1}, + {"preset_reverse.wav", 2, 120, 16, 4, SLICES, -1, -1}, + {"preset_usr_slice_empty.wav", 3, 120, 16, 4, SLICES, -1, -1}, /* no slot: BREAK, AUTO */ + {"break_in_order.wav", 0, 120, 16, 2, SLICES, -1, -1}, + {"break_resequenced.wav", 0, 120, 32, 4, RESEQ, -1, -1}, + {"break_resequenced_32.wav", 0, 120, 32, 4, RESEQ, -1, 3}, + {"usr_loop_auto_in_order.wav", 3, 96, 16, 2, SLICES, 1, -1}, + {"usr_loop_auto_resequenced.wav", 3, 96, 32, 4, USR, 1, -1}, + {"usr_loop_16_resequenced.wav", 0, 96, 32, 4, USR, 1, 2}, + }; + int df = 0; + for (i = 0; i < sizeof D / sizeof D[0]; i++) + df += in_child(demo, dir, &D[i]); + check("demos rendered (peak above -24 dBFS, no clipping)", !df, "%s", dir); + } + printf("slice: %s\n", fails ? "FAILED" : "all checks ok"); + return fails != 0; +} diff --git a/tests/slicer_test.c b/tests/slicer_test.c new file mode 100644 index 0000000..5dddcd1 --- /dev/null +++ b/tests/slicer_test.c @@ -0,0 +1,395 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* Host test of the SLICER (firmware/src/slicer.c), same sources as the firmware (through hostsim.c). + * build/host/slicer_test [DEMO_DIR] (run_tests.sh: build/slicer_demo) + * 1. no clicks: a 110 Hz sine through GATE / STUT at several rates, tempi, swings, and with the mode, + * pattern and depth turned while it runs: the largest sample step of the output stays within a few + * times the sine's own (a hard gate edge would be ~60 x). + * 2. timing: a constant signal through GATE at 97 BPM with swing: every step's middle is open or + * closed as the pattern says, every closing ramp ends on the step boundary (sample exact, from the + * swung step lengths of seq.c). + * 3. sync: the 4-track song with the transport: at every block the SLICER's step is the sequencer's. + * 4. OFF is transparent (the signal untouched), STUT repeats what the live step played. + * 5. cost: instructions per sample of the mix, 4 SLICERs on against off (proc_pid_rusage). + * Demos (WAV, 44.1 kHz) into DEMO_DIR: dry / gated / stuttered versions of a pad, the acid line, the + * drums, and the song. */ +#define main hostsim_main +#include "hostsim.c" +#undef main +#ifdef __APPLE__ +#include +#include +#endif + +static int check(const char *what, int ok) +{ + printf("slicer: %-74s %s\n", what, ok ? "ok" : "FAIL"); + return ok ? 0 : 1; +} + +static void set_slicer(track_t *t, int mode, int pat, int rate, int depth) +{ + t->p[P_SLCR] = (int16_t)mode; + t->p[P_SLPAT] = (int16_t)pat; + t->p[P_SLRATE] = (int16_t)rate; + t->p[P_SLDEPTH] = (int16_t)depth; +} + +/* ---------------------------------------------------------- 1. clicks --- */ +/* n seconds of a 110 Hz sine (amplitude 20000) through track 1's SLICER; turn: change the settings + * while it runs. Returns the largest |step| of the output; *in_step: the sine's own */ +static int32_t sine_run(double secs, int turn, int32_t *in_step, int64_t *closed_energy) +{ + uint32_t f, i, frames = (uint32_t)(secs * FS) / CTL * CTL; + int32_t prev = 0, pin = 0, mx = 0, mi = 0; + double ph = 0, dph = 2 * M_PI * 110.0 / FS; + track_t *t = &trk[0]; + *closed_energy = 0; + slicer_start(0); + for (f = 0; f < frames; f += CTL) { + int32_t b[CTL]; + if (turn && f % 3008u == 0u) { /* modes, patterns, depths, rates while it runs */ + uint32_t k = f / 3008u; + set_slicer(t, (int)(k % 3u), (int)(1u + k * 7u % 16u), (int)(k % 6u), (int)(40u + k * 37u % 88u)); + } + for (i = 0; i < CTL; i++) { + b[i] = (int32_t)lrint(20000.0 * sin(ph)); + ph += dph; + if (f + i) { + int32_t d = abs(b[i] - pin); + mi = d > mi ? d : mi; + } + pin = b[i]; + } + slicer_track(t, b, CTL); + for (i = 0; i < CTL; i++) { + if (f + i) { + int32_t d = abs(b[i] - prev); + mx = d > mx ? d : mx; + } + prev = b[i]; + if (!sl[0].bit && sl[0].pos > (SL_RAMP + CTL) * (uint32_t)song.g[G_BPM]) /* (pos: clock units) */ + *closed_energy += (int64_t)b[i] * b[i]; + } + } + *in_step = mi; + return mx; +} + +static int test_clicks(void) +{ + static const struct { const char *name; int mode, pat, rate, depth, bpm, swing; double secs; } C[] = { + {"GATE pattern 1, 1/16, 120 BPM, 100 %", SL_GATE, 1, 1, 127, 120, 0, 4}, + {"GATE pattern 12, 1/32, 240 BPM, 100 %", SL_GATE, 12, 2, 127, 240, 0, 3}, + {"GATE pattern 2, 32T, 240 BPM, swing 50 %", SL_GATE, 2, 5, 127, 240, 50, 3}, + {"GATE pattern 5, 8T, 90 BPM, 60 %", SL_GATE, 5, 3, 76, 90, 10, 4}, + {"STUT pattern 7, 1/16, 120 BPM, 100 %", SL_STUT, 7, 1, 127, 120, 0, 4}, + {"STUT pattern 3, 32T, 200 BPM, 70 %, swing 30 %", SL_STUT, 3, 5, 90, 200, 30, 3}, + {"STUT pattern 9, 1/8, 40 BPM (loop shorter than the step)", SL_STUT, 9, 0, 127, 40, 0, 8}, + {"STUT pattern 13, 16T, 133 BPM", SL_STUT, 13, 4, 127, 133, 0, 4}, + }; + uint32_t c; + int bad = 0; + char what[160]; + for (c = 0; c < sizeof C / sizeof C[0]; c++) { + int32_t in, out; + int64_t ce; + host_tracks_init(); + memset(sl, 0, sizeof sl); + song.g[G_BPM] = (int16_t)C[c].bpm; + trk[0].p[P_SSWING] = (int16_t)C[c].swing; + set_slicer(&trk[0], C[c].mode, C[c].pat, C[c].rate, C[c].depth); + out = sine_run(C[c].secs, 0, &in, &ce); + snprintf(what, sizeof what, "no clicks: %s: largest step %d (sine %d, %.1f x)", C[c].name, out, in, + (double)out / in); + bad += check(what, out <= 4 * in); + if (C[c].mode == SL_GATE && C[c].depth == 127) { + snprintf(what, sizeof what, " closed steps silent (rms %.2f)", sqrt((double)ce / (FS * C[c].secs))); + bad += check(what, ce < (int64_t)(FS * C[c].secs)); + } + } + { + int32_t in, out; + int64_t ce; + host_tracks_init(); + memset(sl, 0, sizeof sl); + out = sine_run(10, 1, &in, &ce); + snprintf(what, sizeof what, "no clicks: mode / pattern / depth / rate turned while it runs: %d (%.1f x)", out, + (double)out / in); + bad += check(what, out <= 4 * in); + } + return bad; +} + +/* ---------------------------------------------------------- 2. timing --- */ +static int test_timing(void) +{ + const uint32_t steps = 64u, pat = 8u; + uint32_t f = 0, k, b0 = 0, bad_mid = 0, bad_edge = 0, n = 0; + static int32_t out[16u * 44100u]; + int bad = 0; + char what[160]; + track_t *t = &trk[0]; + host_tracks_init(); + memset(sl, 0, sizeof sl); + song.g[G_BPM] = 97; + song.g[G_SWING] = 10; + t->p[P_SSWING] = 20; + set_slicer(t, SL_GATE, (int)pat, 1, 127); + slicer_start(0); + while (f + CTL <= sizeof out / sizeof out[0]) { + uint32_t i; + for (i = 0; i < CTL; i++) + out[f + i] = 16384; + slicer_track(t, out + f, CTL); + f += CTL; + } + { + uint64_t cum = 0; /* the steps as seq.c trk_grid has them: clock units, a */ + for (k = 0; k < steps; k++) { /* boundary at the first sample at or after it */ + uint32_t base = BEAT_U / 4u, len, idx = k & 15u, on = (SL_PAT[pat - 1u] >> idx) & 1u; + uint32_t non = (SL_PAT[pat - 1u] >> ((idx + 1u) & 15u)) & 1u; + uint32_t sw = (20u + 10u) * base / 200u, lu = (idx & 1u) ? base - sw : base + sw; + b0 = (uint32_t)((cum + 96u) / 97u); + cum += lu; + len = (uint32_t)((cum + 96u) / 97u) - b0; + if (b0 + len >= f) + break; + n++; + if (on ? out[b0 + len / 2u] != 16384 : abs(out[b0 + len / 2u]) > 2) + bad_mid++; + if (on && !non && (abs(out[b0 + len - 1u]) > 300 || out[b0 + len - 1u - SL_RAMP] != 16384)) + bad_edge++; /* closed by the boundary, not earlier */ + if (!on && non && (abs(out[b0 + len]) > 300 || out[b0 + len + SL_RAMP] != 16384)) + bad_edge++; /* opens from the boundary */ + } + } + snprintf(what, sizeof what, "timing: GATE at 97 BPM, swing 20 + 10 %%: %u steps open / closed as the pattern says", + n); + bad += check(what, !bad_mid && n > 32u); + bad += check("timing: every ramp ends / starts on the swung step boundary (sample exact)", !bad_edge); + return bad; +} + +/* ------------------------------------------------------------ the song --- */ +static void song_setup(void) +{ + static const uint8_t ACID[16] = {45, 45, 57, 45, 0, 48, 45, 55, 45, 0, 57, 52, 45, 48, 0, 50}; + static const uint8_t ACIDF[16] = {1, 0, 2, 0, 0, 0, 1, 2, 0, 0, 1, 0, 0, 2, 0, 1}; + static const uint8_t AM[4] = {57, 60, 64, 67}, FMI[4] = {53, 57, 60, 64}; + static const uint8_t LEAD[12] = {76, 0, 0, 79, 0, 0, 81, 0, 79, 0, 76, 0}; + track_t *t1 = &trk[0], *t2 = &trk[1], *t3 = &trk[2], *td = TDRUM; + uint32_t i; + host_tracks_init(); + memset(sl, 0, sizeof sl); + song.g[G_BPM] = 120; + host_preset(t1, 0, 4); + host_preset(t2, 1, 5); + host_preset(t3, 3, 0); + for (i = 0; i < 16u; i++) { + uint8_t n = ACID[i]; + put_step(t1, i, n ? 1u : 0u, &n, n ? ST_NOTE : ST_REST, ACIDF[i]); + } + t2->p[P_SLEN] = 32; + t2->p[P_SGATE] = 120; + for (i = 0; i < 32u; i++) + put_step(t2, i, i % 16u == 0u ? 4u : 0u, i < 16u ? AM : FMI, i % 16u == 0u ? ST_NOTE : i % 16u < 14u ? ST_TIE : ST_REST, 0); + t3->p[P_SLEN] = 12; + for (i = 0; i < 12u; i++) { + uint8_t n = LEAD[i]; + put_step(t3, i, n ? 1u : 0u, &n, n ? ST_NOTE : ST_REST, i == 0u ? SF_ACCENT : 0u); + } + for (i = 0; i < 16u; i++) { + uint8_t n[4]; + uint32_t k = 0; + if (i % 4u == 0u) + n[k++] = 36; + if (i == 4u || i == 12u) + n[k++] = 38; + if (i % 2u == 0u) + n[k++] = i == 14u ? 46 : 42; + put_step(td, i, k, n, k ? ST_NOTE : ST_REST, i % 4u == 0u ? SF_ACCENT : 0u); + } +} + +/* ------------------------------------------------------------ 3. sync --- */ +static int test_sync(void) +{ + uint32_t f, k, blocks = 0, miss = 0; + char what[160]; + song_setup(); + song.g[G_SWING] = 15; + for (k = 0; k < NTRK; k++) { + trk[k].p[P_SSWING] = (int16_t)(10 * k); + trk[k].p[P_SLEN] = 16; /* 16 steps of 1/16: the SLICER's bar */ + set_slicer(&trk[k], k & 1u ? SL_STUT : SL_GATE, (int)(3u + k), 1, 127); + } + song.g[G_BPM] = 131; + transport_req = 1; + for (f = 0; f < 12u * FS; f += CTL) { + int32_t o[2 * CTL]; + mix_block(o, CTL); + blocks++; + for (k = 0; k < NTRK; k++) { /* the SLICER step that holds the block's first sample */ + uint32_t idx = sl[k].pos >= CTL * (uint32_t)song.g[G_BPM] ? sl[k].idx : (sl[k].idx + 15u) & 15u; + miss += idx != trk[k].seq_idx % 16u; + } + } + transport_req = 2; + snprintf(what, sizeof what, "sync: 4 tracks, 131 BPM, swing per track: the sequencer's step at %u blocks x 4", blocks); + return check(what, !miss); +} + +/* ------------------------------------------------------- 4. OFF / STUT --- */ +static int test_off_stut(void) +{ + uint32_t f, i, same = 1, rep_ok = 0, rep_n = 0; + track_t *t = &trk[0]; + int bad = 0; + host_tracks_init(); + memset(sl, 0, sizeof sl); + slicer_start(0); + for (f = 0; f < FS; f += CTL) { /* OFF: untouched */ + int32_t b[CTL], c[CTL]; + for (i = 0; i < CTL; i++) + b[i] = c[i] = (int32_t)((f + i) * 2654435761u >> 17) - 16384; + slicer_track(t, b, CTL); + same &= !memcmp(b, c, sizeof b); + } + bad += check("OFF: the signal is not touched", same); + /* STUT, pattern 7 (x...), 1/16 at 120 BPM, 100 %: the repeat steps play the live step again */ + song.g[G_BPM] = 120; + set_slicer(t, SL_STUT, 7, 1, 127); + slicer_start(0); + { + static int32_t in[4u * 44100u], out[4u * 44100u]; + uint32_t len = (uint32_t)FS * 60u / 120u / 4u; + for (f = 0; f < sizeof in / sizeof in[0]; f++) + in[f] = out[f] = (int32_t)(12000.0 * sin(2 * M_PI * 150.0 * f / FS)); /* 18.75 periods a step */ + for (f = 0; f + CTL <= sizeof in / sizeof in[0]; f += CTL) + slicer_track(t, out + f, CTL); + for (f = 0; f + 4u * len < sizeof in / sizeof in[0]; f += 4u * len) /* steps 1..3 of every 4 = step 0 */ + for (i = 1; i < 4u; i++) { + uint32_t a = f + i * len + len / 2u, b = f + len / 2u; + rep_n++; + rep_ok += abs(out[a] - in[b]) < 400; /* (22 kHz recording, read between samples) */ + } + } + { + char what[160]; + snprintf(what, sizeof what, "STUT: the repeat steps play the live step (%u of %u checked)", rep_ok, rep_n); + bad += check(what, rep_ok == rep_n && rep_n > 8u); + } + return bad; +} + +/* ------------------------------------------------------------ 5. cost --- */ +static uint64_t instr_now(void) +{ +#ifdef __APPLE__ + struct rusage_info_v4 ri; + if (!proc_pid_rusage(getpid(), RUSAGE_INFO_V4, (rusage_info_t *)&ri)) + return ri.ri_instructions; +#endif + return 0; +} + +static double cost_run(int on) +{ + uint32_t f, k; + uint64_t i0; + int32_t o[2 * CTL]; + song_setup(); + for (k = 0; k < NTRK; k++) + set_slicer(&trk[k], on ? (k & 1u ? SL_GATE : SL_STUT) : 0, 4, 1, 100); + transport_req = 1; + for (f = 0; f < FS; f += CTL) + mix_block(o, CTL); + i0 = instr_now(); + for (f = 0; f < 2u * FS; f += CTL) + mix_block(o, CTL); + transport_req = 2; + return i0 ? (double)(instr_now() - i0) / (2.0 * FS) : 0; +} + +static int test_cost(void) +{ + double off = cost_run(0), on = cost_run(1); + char what[160]; + if (!off) { + printf("slicer: cost: no instruction counter on this host\n"); + return 0; + } + snprintf(what, sizeof what, "cost: the song, 4 SLICERs on: %.0f instructions / sample (off %.0f): +%.0f, %.0f a track", + on, off, on - off, (on - off) / 4); + return check(what, (on - off) / 4 < 60); +} + +/* ------------------------------------------------------------ demos --- */ +static void demo_song(const char *dir, const char *name, const int16_t (*s)[4], uint32_t solo) +{ + char path[512]; + FILE *w; + uint32_t f, k, frames = 8u * FS; + snprintf(path, sizeof path, "%s/%s", dir, name); + if (!(w = fopen(path, "wb"))) + return; + song_setup(); + for (k = 0; k < NTRK; k++) { + set_slicer(&trk[k], s[k][0], s[k][1], s[k][2], s[k][3]); + if (solo && k + 1u != solo) { + if (k == TRK_DRUM) + song.g[G_DRLVL] = 0; + else + trk[k].p[P_LEVEL] = 0; + } + } + transport_req = 1; + wav_hdr(w, frames); + for (f = 0; f < frames; f += CTL) { + int32_t o[2 * CTL]; + uint32_t i; + mix_block(o, CTL); + for (i = 0; i < CTL; i++) + wav_put(w, o[2 * i], o[2 * i + 1]); + } + transport_req = 2; + fclose(w); +} + +static void demos(const char *dir) +{ + static const int16_t DRY[4][4] = {{0, 1, 1, 127}, {0, 1, 1, 127}, {0, 1, 1, 127}, {0, 1, 1, 127}}; + static const int16_t PAD_GATE[4][4] = {{0, 1, 1, 127}, {SL_GATE, 1, 1, 127}, {0, 1, 1, 127}, {0, 1, 1, 127}}; + static const int16_t PAD_GATE2[4][4] = {{0, 1, 1, 127}, {SL_GATE, 15, 2, 110}, {0, 1, 1, 127}, {0, 1, 1, 127}}; + static const int16_t ACID_STUT[4][4] = {{SL_STUT, 7, 1, 127}, {0, 1, 1, 127}, {0, 1, 1, 127}, {0, 1, 1, 127}}; + static const int16_t DRUM_STUT[4][4] = {{0, 1, 1, 127}, {0, 1, 1, 127}, {0, 1, 1, 127}, {SL_STUT, 12, 2, 127}}; + static const int16_t DRUM_GATE[4][4] = {{0, 1, 1, 127}, {0, 1, 1, 127}, {0, 1, 1, 127}, {SL_GATE, 3, 1, 127}}; + static const int16_t ALL[4][4] = {{SL_STUT, 9, 1, 127}, {SL_GATE, 1, 1, 127}, {SL_GATE, 14, 2, 90}, + {SL_STUT, 12, 2, 110}}; + demo_song(dir, "song_dry.wav", DRY, 0); + demo_song(dir, "song_slicers.wav", ALL, 0); + demo_song(dir, "pad_dry.wav", DRY, 2); + demo_song(dir, "pad_gate_p1_16th.wav", PAD_GATE, 2); + demo_song(dir, "pad_gate_p15_32nd.wav", PAD_GATE2, 2); + demo_song(dir, "acid_dry.wav", DRY, 1); + demo_song(dir, "acid_stut_p7.wav", ACID_STUT, 1); + demo_song(dir, "drums_dry.wav", DRY, 4); + demo_song(dir, "drums_gate_p3.wav", DRUM_GATE, 4); + demo_song(dir, "drums_stut_p12_32nd.wav", DRUM_STUT, 4); + printf("slicer: demos in %s (song_dry / song_slicers, pad, acid, drums: dry and sliced)\n", dir); +} + +int main(int argc, char **argv) +{ + int bad = 0; + bad += test_clicks(); + bad += test_timing(); + bad += test_sync(); + bad += test_off_stut(); + bad += test_cost(); + if (argc > 1) + demos(argv[1]); + printf("%s\n", bad ? "SLICER TEST FAILED" : "slicer test passed"); + return bad != 0; +} diff --git a/tests/soak_test.c b/tests/soak_test.c new file mode 100644 index 0000000..9275c9e --- /dev/null +++ b/tests/soak_test.c @@ -0,0 +1,156 @@ +/* SPDX-License-Identifier: GPL-3.0-only */ +/* SLOOP soak test: 10 simulated minutes of random live use through the real audio path + * (mix_block: sequencer, the 3 synth parts, the synthesised and sampled drum kits, the + * punch-in FX, the record arm, free takes, MIDI in), then everything stopped and released. + * Checks: the output stays bounded, every block renders in time on the host, voices never + * hang (all free a few seconds after the last note), the punch FX and the record state come + * back to idle, recorded steps stay well-formed. Seeded: the same run every time. */ +#define main hostsim_main +#include "hostsim.c" +#undef main +#include +static uint32_t seed = 12345, ft_count, ft_starts; +static uint8_t ft_prev, arm_next; +static uint32_t rnd(uint32_t n) { seed = seed * 1664525u + 1013904223u; return (seed >> 8) % (n ? n : 1u); } +static void midi_in(uint32_t st, uint32_t d1, uint32_t d2) +{ + if (mi_w - mi_r >= MQ) return; + midi_in_q[mi_w % MQ] = ((st >> 4) & 15u) | st << 8 | d1 << 16 | d2 << 24; + mi_w++; +} + +int main(int argc, char **argv) +{ + const uint32_t minutes = argc > 1 ? (uint32_t)atoi(argv[1]) : 10u; + const uint32_t blocks = minutes * 60u * FS / CTL; + static int32_t out[CTL * 2]; + uint32_t b, i, k, held = 0, maxblock_ns = 0, events = 0, peak = 0; + double total_ns = 0; + struct timespec t0, t1; + host_tracks_init(); + song.g[G_BPM] = 120; + host_preset(&trk[0], 0, 4); + host_preset(&trk[1], 1, 5); + host_preset(&trk[2], 3, 0); + TDRUM->p[P_E0] = DRUM_SAMPLED; + for (k = LY_FX; k < LY_COUNT; k++) /* the layer buttons (SLOOP 2.0): bits 8.. */ + ly_bit[k] = 1u << (7u + k); + dyn_bit[0] = 1u << 14; + dyn_bit[1] = 1u << 15; + for (b = 0; b < blocks; b++) { + static uint32_t layer_btn; + if (rnd(40) == 0) { /* an event every ~29 ms on average */ + events++; + switch (rnd(22)) { + case 16: layer_btn = rnd(3) ? 0u : ly_bit[1u + rnd(LY_COUNT - 1u)] | (rnd(4) ? 0u : dyn_bit[rnd(2)]); break; /* a layer held */ + case 17: song.g[G_DUST] = (int16_t)rnd(128); song.g[G_DUCK] = (int16_t)rnd(128); break; + case 18: song.g[G_FILT] = (int16_t)((int)rnd(128) - 64); song.g[G_ROLL] = (int16_t)rnd(5); break; + case 19: trk[rnd(NTRK)].p[P_MUTE] = (int16_t)(rnd(4) == 0); song.solo = (uint8_t)(rnd(5) ? 0u : 1u << rnd(NTRK)); break; + case 20: { /* levels, ratchets on steps */ + uint32_t t = rnd(NTRK), i2 = rnd(NSTEP); + if (t == TRK_DRUM) dstep_set(&trk[t].dstep[i2], rnd(DRUM_LANES), rnd(4), rnd(4)); + else if (trk[t].step[i2].n) { trk[t].step[i2].lvl = (uint8_t)rnd(256); trk[t].step[i2].rat = (uint8_t)rnd(256); } + break; + } + case 21: trk[rnd(NPART)].p[P_CHORD] = (int16_t)rnd(6); trk[rnd(NPART)].p[P_VOICE] = (int16_t)rnd(4); break; + case 0: if (!ft_on || !rnd(16)) transport_req = song.playing ? 2 : 1; break; /* (a free take: PLAY closes it) */ + case 1: if (song.playing) rec_begin(); else rec_wait = 1; break; /* REC */ + case 2: song.rec = 0; rec_wait = 0; break; /* REC off */ + case 3: { uint32_t s = rnd(NTRK); song.sel = (uint8_t)s; rec_follow(s); break; } /* ALGO */ + case 4: TDRUM->p[P_E0] = (int16_t)rnd(DRUM_KITS); break; /* kit */ + case 5: punch.req = (int8_t)(rnd(3) ? -1 : (int)rnd(PUNCH_NFX)); break; + case 6: song.g[G_BPM] = (int16_t)(60 + rnd(140)); break; + case 7: { uint32_t t = rnd(NPART), e = rnd(NENGINES); /* engine / preset */ + host_preset_req(&trk[t], e, rnd(ENGINES[e]->npresets)); panic_req |= (uint8_t)(1u << t); break; } + case 8: trk[rnd(NTRK)].p[P_SLEN] = (int16_t)(1 + rnd(64)); break; + case 9: trk[rnd(NTRK)].p[P_SDIV] = (int16_t)rnd(6); break; + case 10: song.g[G_CLOCK] = (int16_t)rnd(3); break; + case 11: midi_in(0x90u | rnd(16), 24 + rnd(80), 1 + rnd(127)); break; + case 12: midi_in(0x80u | rnd(16), 24 + rnd(80), 0); break; + case 13: trk[rnd(NTRK)].p[P_SLCR] = (int16_t)rnd(3); break; + case 14: trk[rnd(NPART)].p[P_AMODE] = (int16_t)rnd(6); break; + default: { /* keys: press / release */ + uint32_t key = rnd(27); + if (rnd(2)) held |= 1u << key; else held &= ~(1u << key); + if (rnd(8) == 0) held = 0; + break; + } + } + } + fm1_in.notes = held; + if (rnd(3000) == 0) { /* now and then an empty project: free takes */ + for (k = 0; k < NTRK; k++) + steps_clear(&trk[k]); + transport_req = 2; /* stopped, then armed */ + arm_next = 1; + } else if (arm_next && !transport_req) { + arm_next = 0; + rec_wait = 1; + } + ft_btn_mask = 1u << 3; + ft_drop_mask = 1u << 4; + fm1_in.buttons = (rnd(4000) == 0 ? 1u << 3 : rnd(20000) == 0 ? 1u << 4 : 0u) | layer_btn; /* REC closes, PLAY drops a take */ + clock_gettime(CLOCK_MONOTONIC, &t0); + mix_block(out, CTL); + clock_gettime(CLOCK_MONOTONIC, &t1); + if (ft_prev && !ft_on && song.playing) + ft_count++; + if (!ft_prev && ft_on) + ft_starts++; + ft_prev = ft_on; + { + uint32_t ns = (uint32_t)((t1.tv_sec - t0.tv_sec) * 1000000000L + (t1.tv_nsec - t0.tv_nsec)); + total_ns += ns; + if (ns > maxblock_ns && b > 1000u) maxblock_ns = ns; + } + for (i = 0; i < CTL * 2u; i++) { + int32_t a = out[i] < 0 ? -out[i] : out[i]; + assert(a < (1 << 24)); + if ((uint32_t)a > peak) peak = (uint32_t)a; + } + } + /* the end: keys up, MIDI notes off on every channel, stop, punch off; then 5 s */ + fm1_in.notes = 0; + fm1_in.buttons = 0; + punch.hold = 0; + punch.req = -1; + mix_block(out, CTL); + for (k = 0; k < 16u; k++) + for (i = 24; i < 104u; i++) { + midi_in(0x80u | k, i, 0); + if (mi_w - mi_r >= MQ - 4u) mix_block(out, CTL); + } + transport_req = 2; + for (k = 0; k < NTRK; k++) trk[k].p[P_AMODE] = 0; + for (b = 0; b < 5u * FS / CTL; b++) mix_block(out, CTL); + assert(!song.playing && !song.rec && !rec_wait && !ft_on); + assert(punch.cur == -1); + for (k = 0; k < NPART; k++) + for (i = 0; i < NVOICE; i++) + assert(!trk[k].v[i].active); /* no hanging synth note */ + for (i = 0; i < NDRUM; i++) + assert(!drums.v[i].active); /* every drum hit ended */ + for (k = 0; k < NPART; k++) + for (i = 0; i < NSTEP; i++) { + const step_t *s = &trk[k].step[i]; + assert(s->n <= 4u && s->time <= ST_REST); + } + for (i = 0; i < NROLL; i++) + assert(!roll[i].on); /* every roll ended with its key */ + { + int32_t quiet = 0; /* silence (the reverb / delay tails done) */ + for (b = 0; b < FS / CTL; b++) { + mix_block(out, CTL); + for (i = 0; i < CTL * 2u; i++) if ((out[i] < 0 ? -out[i] : out[i]) > quiet) quiet = out[i] < 0 ? -out[i] : out[i]; + } + printf("soak: %u min, %u events, peak %u, max block %.1f us, mean %.2f us; tail %d\n", + minutes, events, peak, maxblock_ns / 1000.0, total_ns / blocks / 1000.0, quiet); + assert(quiet < 64); + } + printf("soak: free takes %u, closed into a loop %u\n", ft_starts, ft_count); + fflush(stdout); + if (minutes >= 3u) /* (a shorter run may close none: a smoke test) */ + assert(ft_count > 0); + printf("soak: random live use, bounded output, no hanging voices, idle after stop PASS\n"); + return 0; +} diff --git a/tests/song_audio_test.c b/tests/song_audio_test.c new file mode 100644 index 0000000..bbc0472 --- /dev/null +++ b/tests/song_audio_test.c @@ -0,0 +1,108 @@ +/* SPDX-License-Identifier: GPL-3.0-only */ +/* Exercise the actual sequencer, scene loader and synth mixer together. */ +#define FELUCCA_ARRANGER 1 +#define main hostsim_main +#include "hostsim.c" +#undef main +#include +#define PROJ_HOST 1 +static uint32_t trk_def_engine(uint32_t i) { return i < NPART ? i : 0; } +#include "../firmware/src/project.c" +static struct { uint8_t force; } ui; +static uint8_t sync_reload; +#include "../firmware/src/arranger_scene.c" + +static void capture(uint32_t slot) +{ + project_t *p = &proj_slot[slot]; + uint32_t i; + memset(p, 0, sizeof *p); + p->magic = PROJ_MAGIC; p->size = sizeof *p; + memcpy(p->g, song.g, sizeof song.g); + for (i = 0; i < NTRK; i++) { + memcpy(p->t[i].p, trk[i].p, sizeof trk[i].p); + memcpy(p->t[i].step, trk[i].step, sizeof trk[i].step); + p->t[i].engine = trk[i].eng_req; + p->t[i].preset = trk[i].preset; + } + p->sum = proj_sum(p); +} + +int main(int argc, char **argv) +{ + uint32_t i, k, frame, at_change = 0, at_stop = 0; + uint32_t active_tracks = 0; + uint32_t simultaneous = 0; + int32_t out[CTL * 2]; + uint64_t energy = 0; + FILE *f = argc > 1 ? fopen(argv[1], "wb") : 0; + const uint32_t frames = (FS * 9u / CTL) * CTL; + host_tracks_init(); + host_preset(&trk[0], 0, 4); /* bass */ + host_preset(&trk[1], 1, 5); /* pad */ + host_preset(&trk[2], 3, 0); /* melody */ + for (i = 0; i < NTRK; i++) { + trk[i].p[P_SLEN] = 16; + trk[i].p[P_SDIV] = 2; + trk[i].p[P_AMODE] = 0; + trk[i].p[P_LEVEL] = 90; + } + for (k = 0; k < 16; k++) { + uint8_t bass[] = {36}, chord[] = {60, 63, 67}, lead[] = {(uint8_t)(72 + (k % 3u) * 3u)}; + uint8_t drum[] = {42, (uint8_t)(k % 8u == 4u ? 38 : 36)}; + if (!(k % 4u)) put_step(&trk[0], k, 1, bass, ST_NOTE, 0); + if (!(k % 8u)) put_step(&trk[1], k, 3, chord, ST_NOTE, 0); + if (!(k % 2u)) put_step(&trk[2], k, 1, lead, ST_NOTE, 0); + put_step(TDRUM, k, k % 4u ? 1 : 2, drum, ST_NOTE, 0); + } + capture(0); + for (i = 0; i < NPART; i++) + for (k = 0; k < 16; k++) { + uint32_t j; + for (j = 0; j < trk[i].step[k].n; j++) trk[i].step[k].note[j] += 5; + } + host_preset_req(&trk[2], 0, 1); /* change the lead's engine at the section boundary */ + song.g[G_DRLVL] = 80; + TDRUM->p[P_E0] = 4; /* drum kit is saved with the section */ + capture(1); + arr_defaults(&arrangement); + arrangement.count = 2; + arrangement.entry[0] = (arr_entry_t){0, 2}; + arrangement.entry[1] = (arr_entry_t){1, 2}; + arrangement_enabled = 1; + transport_req = 1; + if (f) wav_hdr(f, frames); + for (frame = 0; frame < frames; frame += CTL) { + mix_block(out, CTL); + if (song.playing && arrangement_clock.index == 1u && !at_change) at_change = frame; + if (!song.playing && frame && !at_stop) at_stop = frame; + uint32_t sounding = 0; + for (i = 0; i < NPART; i++) + for (k = 0; k < NVOICE; k++) + if (trk[i].v[k].active) sounding |= 1u << i; + for (k = 0; k < NDRUM; k++) if (drums.v[k].active) sounding |= 8; + active_tracks |= sounding; + if (sounding == 15u) simultaneous++; + for (k = 0; k < CTL; k++) { + energy += (uint64_t)(out[k*2] < 0 ? -(int64_t)out[k*2] : out[k*2]); + if (f) wav_put(f, out[k*2], out[k*2+1]); + } + } + if (f) fclose(f); + assert(active_tracks == 15u && simultaneous > 100u && energy > 1000000u); + assert(at_change >= FS*4u && at_change < FS*4u + CTL); + assert(at_stop >= FS*8u && at_stop < FS*8u + CTL); + assert(trk[0].step[0].note[0] == 41); + assert(trk[2].engine == 0 && song.g[G_DRLVL] == 80); + assert(drum_kit() == 4); + for (i = 0; i < NPART; i++) { + assert(trk[i].seq_n == 0); + for (k = 0; k < NVOICE; k++) assert(!trk[i].v[k].gate); + } + /* A missing later scene must prevent even the first scene from starting. */ + arrangement.entry[1].scene = 3; + transport_req = 1; events_block(CTL); + assert(!song.playing && arrangement_clock.error); + printf("song audio: 3 synth parts + drums, section at %u, stop at %u, no held sequencer notes PASS\n",at_change,at_stop); + return 0; +} diff --git a/tests/song_ui_test.c b/tests/song_ui_test.c new file mode 100644 index 0000000..9f606f1 --- /dev/null +++ b/tests/song_ui_test.c @@ -0,0 +1,87 @@ +/* SPDX-License-Identifier: GPL-3.0-only */ +/* Real song screen renderer and interaction code, with a framebuffer and + * panel/flash doubles. No device access. Writes a 240x240 PPM preview. */ +#define FELUCCA_ARRANGER 1 +#define main hostsim_main +#include "hostsim.c" +#undef main +#include +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>i)&1u;} +static void project_save(uint32_t i) {ready|=1u<1) { + FILE *f=fopen(argv[1],"wb");assert(f); + fprintf(f,"P6\n240 240\n255\n"); + for(i=0;i<240*240;i++) { + uint16_t p=swap16(screen[i]); + uint8_t rgb[3]={(uint8_t)((p>>11)*255/31),(uint8_t)(((p>>5)&63)*255/63),(uint8_t)((p&31)*255/31)}; + fwrite(rgb,1,3,f); + } + fclose(f); + } + puts("song UI: independent plan/scene save, overwrite confirmation, stopped-only changes, missing scene, bounds PASS"); + return 0; +} diff --git a/tests/storage_test.c b/tests/storage_test.c new file mode 100644 index 0000000..2bd35b7 --- /dev/null +++ b/tests/storage_test.c @@ -0,0 +1,109 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* Host test of firmware/src/storage.c against a simulated NOR flash: + * erase -> 0xFF, program can only clear bits, page writes must not wrap. */ +#include +#include +#include +#include + +static uint8_t nor[0x100000]; +static int fail_after = -1; /* torn-write injection: stop after N programs */ + +static int st_read(uint32_t off, void *dst, uint32_t n) { memcpy(dst, nor + off, n); return 0; } +static int st_erase(uint32_t off) { memset(nor + off, 0xFF, 4096); return 0; } +static int st_prog(uint32_t off, const void *src, uint32_t n) +{ + const uint8_t *s = src; + uint32_t i; + if (fail_after == 0) + return -9; + if (fail_after > 0) + fail_after--; + if ((off & 0xFFu) + n > 256u) { + printf("page wrap at %#x\n", off); + exit(1); + } + for (i = 0; i < n; i++) + nor[off + i] &= s[i]; + return 0; +} +#include "../firmware/src/storage.c" + +static int check(const char *what, int ok) +{ + printf("%-46s %s\n", what, ok ? "ok" : "FAIL"); + return ok ? 0 : 1; +} + +int main(void) +{ + char a[600], b[600], got[600]; + int bad = 0, n; + memset(nor, 0xFF, sizeof nor); + memset(a, 'A', sizeof a); + memset(b, 'B', sizeof b); + bad += check("empty flash loads nothing", st_load(OBJ_PROJECT0, got, sizeof got) < 0); + bad += check("save A", st_save(OBJ_PROJECT0, a, sizeof a) == 0); + n = st_load(OBJ_PROJECT0, got, sizeof got); + bad += check("load returns A", n == (int)sizeof a && !memcmp(got, a, sizeof a)); + bad += check("save B", st_save(OBJ_PROJECT0, b, sizeof b) == 0); + n = st_load(OBJ_PROJECT0, got, sizeof got); + bad += check("load returns B (newer seq)", n == (int)sizeof b && !memcmp(got, b, sizeof b)); + fail_after = 1; /* payload page 1 written, the rest torn */ + st_save(OBJ_PROJECT0, a, sizeof a); + fail_after = -1; + n = st_load(OBJ_PROJECT0, got, sizeof got); + bad += check("torn save keeps B", n == (int)sizeof b && !memcmp(got, b, sizeof b)); + fail_after = 3; /* all payload pages, header torn */ + st_save(OBJ_PROJECT0, a, sizeof a); + fail_after = -1; + n = st_load(OBJ_PROJECT0, got, sizeof got); + bad += check("header not written keeps B", n == (int)sizeof b && !memcmp(got, b, sizeof b)); + bad += check("save A again", st_save(OBJ_PROJECT0, a, sizeof a) == 0); + n = st_load(OBJ_PROJECT0, got, sizeof got); + bad += check("load returns A", n == (int)sizeof a && !memcmp(got, a, sizeof a)); + nor[st_sector(OBJ_PROJECT0, 0) + ST_PAYLOAD_OFF + 10] ^= 0x01; /* bit rot in one copy */ + nor[st_sector(OBJ_PROJECT0, 1) + ST_PAYLOAD_OFF + 10] ^= 0x01; + n = st_load(OBJ_PROJECT0, got, sizeof got); + bad += check("both copies corrupt -> nothing", n < 0); + bad += check("other objects untouched", st_load(OBJ_PROJECT0 + 1, got, sizeof got) < 0); + bad += check("settings save/load", + st_save(OBJ_SETTINGS, "hello", 5) == 0 && st_load(OBJ_SETTINGS, got, 5) == 5 && !memcmp(got, "hello", 5)); + bad += check("CRC-32 is zlib's (check value 0xCBF43926)", st_crc32("123456789", 9) == 0xCBF43926u); + memset(nor, 0xFF, sizeof nor); + st_save(OBJ_PROJECT0 + 2, a, sizeof a); + st_save(OBJ_PROJECT0 + 2, b, sizeof b); /* B is newer, in the other copy */ + { + st_hdr_t h; + int cur = st_current(OBJ_PROJECT0 + 2, &h); + nor[st_sector(OBJ_PROJECT0 + 2, (uint32_t)cur) + ST_PAYLOAD_OFF + 300] ^= 0x10; /* rot in the newer copy */ + } + n = st_load(OBJ_PROJECT0 + 2, got, sizeof got); + bad += check("newer copy rotten -> the older one loads", n == (int)sizeof a && !memcmp(got, a, sizeof a)); + bad += check("save over the rotten copy", st_save(OBJ_PROJECT0 + 2, b, sizeof b) == 0); + n = st_load(OBJ_PROJECT0 + 2, got, sizeof got); + bad += check("... loads the new data", n == (int)sizeof b && !memcmp(got, b, sizeof b)); + nor[st_sector(OBJ_PROJECT0 + 2, 0) + 8] ^= 0x01; /* both headers broken */ + nor[st_sector(OBJ_PROJECT0 + 2, 1) + 8] ^= 0x01; + bad += check("both headers broken -> nothing", st_load(OBJ_PROJECT0 + 2, got, sizeof got) < 0); + { /* every copy of every object in the Felucca regions, off the sample slots (0xA0000..0xDBFFF) and + * the update staging (0xE0000..), and no two sectors shared */ + uint32_t o, c, o2, c2, inside = 1, apart = 1; + for (o = 0; o < OBJ_COUNT; o++) + for (c = 0; c < 2u; c++) { + uint32_t a = st_sector(o, c); + int data = a >= 0x97000u && a + 4096u <= 0xA0000u, ups = a >= 0xDC000u && a + 4096u <= 0xE0000u; + int glob = a >= 0xFC000u && a + 4096u <= 0xFF000u; + inside &= (data || ups || glob) && !(a & 0xFFFu); + for (o2 = 0; o2 < OBJ_COUNT; o2++) + for (c2 = 0; c2 < 2u; c2++) + if ((o2 != o || c2 != c) && st_sector(o2, c2) == a) + apart = 0; + } + bad += check("data stays in the Felucca regions (autosave too)", inside); + bad += check("every object copy has its own sector", apart); + } + printf("%s\n", bad ? "STORAGE TEST FAILED" : "storage test passed"); + return bad != 0; +} diff --git a/tests/studio_drums_test.c b/tests/studio_drums_test.c new file mode 100644 index 0000000..69fc4c7 --- /dev/null +++ b/tests/studio_drums_test.c @@ -0,0 +1,180 @@ +/* SPDX-License-Identifier: GPL-3.0-only */ +#define main hostsim_main +#include "hostsim.c" +#undef main +#include +static uint32_t into_s(const track_t *t) /* samples into the step the clock is in */ +{ + uint32_t into, len; + trk_grid(t, &into, &len); + return into / (uint32_t)song.g[G_BPM]; +} +int main(int argc,char **argv) +{ + uint32_t i,j,k,v,total=0; uint64_t energy[DRUM_KITS]={0}; + int32_t out[CTL*2]; dstep_t step={{0}}; + host_tracks_init(); + for(i=0;i>2)&3u); /* SLOOP 2.0: all 16 lanes in one step */ + assert(dstep_mask(&step)==0xFFFFu); + for(i=0;i>2)&3u)); + dstep_clr(&step,5);assert(!dstep_has(&step,5) && dstep_has(&step,4) && dstep_has(&step,6) && dstep_lvl(&step,6)==2u); + for(i=0;i<27u;i++)assert(lane_of_key(i)p[P_E0]=(int16_t)i; + drum_on(36,110);drum_on(38,100);drum_on(46,80); + for(j=0;j-131072 && l[k]<131072);energy[i]+=l[k]<0?-l[k]:l[k];} + } + assert(energy[i]>10000); + for(k=0;k100)loud++;} + } + transport_req=2;events_block(CTL); + if(v==0||v==2)assert(hits==4 && loud==1); + else assert(hits==0 && drums.age==age0); + } + /* LIVE record start. Stopped and armed, a project with notes: the first note starts the + * loop and is step 1 */ + { + uint32_t period, b, k0 = 7u, half, c; /* key 7 = C4 */ + host_tracks_init();song.g[G_BPM]=120;song.g[G_CLOCK]=0;song.sel=0;song.playing=0; + for(c=0;cdstep[3],0,LV_NORM,0); + rec_wait=1; + for(b=0;b<10;b++)mix_block(out,CTL); /* nothing happens while it waits */ + assert(!song.playing && !song.rec && rec_wait==1 && !ft_on); + fm1_in.notes=1u<time==ST_NOTE && st->n==1 && st->note[0]==KN[(j/4u)&3u]); + } else if(j==5u) { + assert(st->time==ST_TIE); /* the held note: 2 steps */ + } else { + assert(!st->n && st->time!=ST_NOTE && st->time!=ST_TIE); + } + } + for(j=len;j1?fopen(argv[1],"wb"):0; + if(f)wav_hdr(f,total); + host_tracks_init();song.g[G_BPM]=120;song.rec=1u;transport_req=1; + for(j=0;j 1 else "build/felucca.dis" +budget = sys.argv[2] if len(sys.argv) > 2 else "tests/target_budget.txt" +LABEL = re.compile(r"^([A-Za-z_][A-Za-z_0-9.]*):$") +INSN = re.compile(r"^\s*([0-9a-f]+):\s+((?:[0-9a-f]{2} )+)\s*(.*)$") +TARGET = re.compile(r"goto -?\d+ <[^>]*: ([0-9a-f]+) >") + + +def functions(path): + """{name: [(addr, text)]}: a function runs to the next label not starting with '.' (the compiler's + jump-table labels are inside functions); jump-table data ('< n : 0x.. >') is left out""" + out, cur = {}, None + with open(path) as f: + for line in f: + m = LABEL.match(line.strip()) + if m: + name = m.group(1) + if not name.startswith("."): + cur = out.setdefault(name, []) if name in FUNCS else None + continue + m = INSN.match(line) + if cur is not None and m and not m.group(3).lstrip().startswith("<"): + cur.append((int(m.group(1), 16), m.group(3).strip())) + return out + + +def cost(insns): + """loops: one span per loop head (the farthest backward branch to it); an instruction inside d + spans weighs NEST ** (d - 1) (an inner loop runs several times per pass of the outer one)""" + lo = insns[0][0] + heads = {} + for a, t in insns: + m = TARGET.search(t) + if m and lo <= int(m.group(1), 16) < a: + h = int(m.group(1), 16) + heads[h] = max(heads.get(h, a), a) + n = divs = calls = 0 + w = 0 + for a, t in insns: + d = min(sum(1 for h, e in heads.items() if h <= a <= e), MAXD) + if not d: + continue + k = NEST ** (d - 1) + n += 1 + if re.search(r"= r\d+ / r\d+", t): + divs += 1 + k *= 1 + DIV_W + calls += t.startswith("call") + w += k + return {"insns": len(insns), "loop": n, "div": divs, "call": calls, "cost": w} + + +def main(): + if not os.path.exists(dis): + print(f"target: skip ({dis} missing: run ./build.sh)") + return 0 + fns = functions(dis) + res = {n: cost(fns[n]) for n in FUNCS if fns.get(n)} + missing = [n for n in FUNCS if n not in res] + base = {} + if os.path.exists(budget): + for line in open(budget): + p = line.split() + if len(p) >= 2 and not line.startswith("#"): + base[p[0]] = int(p[1]) + if os.environ.get("BUDGET_UPDATE"): + with open(budget, "w") as f: + f.write("# FELUCCA target cost budget (tests/target_budget.py): instructions in the loops of each\n" + f"# function in build/felucca.dis, x{NEST} per nesting level, divides x{1 + DIV_W}. The check allows " + f"+{TOL * 100:.0f} %.\n# Rewritten by BUDGET_UPDATE=1.\n") + for n, r in res.items(): + f.write(f"{n} {r['cost']}\n") + print(f"target: budget {budget} rewritten ({len(res)} functions)") + fail = 0 + for n in missing: + print(f"target: FAIL {n} not found in {dis} (renamed? inlined? update FUNCS)") + fail += 1 + for n, r in res.items(): + b = base.get(n) + state = "no budget (BUDGET_UPDATE=1 adds it)" if b is None else "ok" + if b is not None and not os.environ.get("BUDGET_UPDATE"): + if r["cost"] > b * (1 + TOL): + state = f"OVER BUDGET (+{(r['cost'] / b - 1) * 100:.0f} %, limit +{TOL * 100:.0f} %)" + fail += 1 + elif r["cost"] < b * (1 - TOL): + state = f"note: {(r['cost'] / b - 1) * 100:.0f} % (BUDGET_UPDATE=1 to keep it)" + print(f"target: {n:15s} {r['insns']:5d} instructions, {r['loop']:4d} in loops, {r['div']} divides, " + f"{r['call']:2d} calls there: cost {r['cost']:5d} (budget {b if b is not None else '-'}) {state}") + return 1 if fail else 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tests/target_budget.txt b/tests/target_budget.txt new file mode 100644 index 0000000..76f3609 --- /dev/null +++ b/tests/target_budget.txt @@ -0,0 +1,21 @@ +# FELUCCA target cost budget (tests/target_budget.py): instructions in the loops of each +# function in build/felucca.dis, x4 per nesting level, divides x9. The check allows +10 %. +# Rewritten by BUDGET_UPDATE=1. +# SLOOP 2.0 (reviewed): analog +9 % (drive crossfade, phase reset), lofi +4 % (input clamp), slicer on +# the sample-accurate clock (its divides are per step / per block, not per sample: the per-sample +# loop has none), the mix out of the ISR into its own function (fm1_alnk0_irq calls it). +analog_render 638 +digital_render 333 +phase_render 79 +lofi_render 128 +sample_render 126 +formant_render 314 +trio_render 341 +trio_pass 175 +drawbar_render 267 +drawbar_block 102 +grain_render 1734 +grain_block 138 +slicer_track 825 +drums_mix 6153 +fm1_alnk0_irq 174 diff --git a/tests/ui_pages_test.c b/tests/ui_pages_test.c new file mode 100644 index 0000000..9ef4735 --- /dev/null +++ b/tests/ui_pages_test.c @@ -0,0 +1,292 @@ +/* SPDX-License-Identifier: GPL-3.0-only */ +/* The real UI (ui.c, ui_draw.c, ui_studio.c, ui_layers.c, ui_song.c, ui_menu.c, ui_input.c) on a + * framebuffer with panel / flash / storage doubles, the audio (mix_block) running between frames as on + * the device. Renders every screen to PPM for review (DIR/page-*.ppm, live-*.ppm, layer-*.ppm) and + * drives the panel: + * taps a layer button tapped opens its pages; held + a key / knob it does not + * FX held + a white key: punch-in; knobs: filter, dust, duck + * SEQ held: the steps on the white keys (drums: the sound played last), OCT: pages, a step key + * held + KNOB 2 / 3: level / ratchet + * EDIT held + a key: erase; OCT- / OCT+: undo / redo; KNOB 1 shift, 2 length x2 + * ARP held + a key: a roll; KNOB 1 the rate + * SCL held + a key: the key of the song + * GLO held + keys: mute, solo, tap tempo; knobs: levels + * REC press: arm / record at once; held: the clear ring, to the end: cleared (undo brings it back) + * SAVE tapped: the song page; held: the save ring, then saved + * DRUMS the grid: sound / step / hit / level knobs, GRID <-> KIT + * then 20000 frames of random use: every draw stays on the screen. */ +#define FELUCCA_ARRANGER 1 +#define main hostsim_main +#include "hostsim.c" +#undef main +#include +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>11)*255/31,((p>>5)&63)*255/63,(p&31)*255/31}; fwrite(rgb,1,3,f); } + fclose(f); +} +/* one UI frame (~16 ms): the audio between (as the ISR does), then input, LEDs, draw */ +static void frame(void) +{ + uint32_t q; + static int32_t o[CTL * 2]; + for (q = 0; q < 22u; q++) mix_block(o, CTL); + ui_input(); ui_leds(); ui_draw(); fm1_ms += 16; +} +static void frames(uint32_t n) { while (n--) frame(); } +static uint32_t BT(uint32_t b) { return 1u << panel.btn[b]; } +static void press(uint32_t b) { edges_btn |= BT(b); fm1_in.buttons |= BT(b); frame(); } +static void release(uint32_t b) { fm1_in.buttons &= ~BT(b); frame(); } +static void tap(uint32_t b) { press(b); release(b); } +static void key(uint32_t k) { fm1_in.notes |= 1u << k; frame(); fm1_in.notes &= ~(1u << k); frame(); } +static int fails; +static void check(int ok, const char *what) { printf("ui: %-74s %s\n", what, ok ? "ok" : "FAIL"); fails += !ok; } + +int main(int argc, char **argv) +{ + uint32_t i; + 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; + sloop_splash(); ppm("page-splash"); + ui.menu = 2; ui.force = 1; frame(); ppm("page-about"); ui.menu = 0; + go_home(); ui.force = 1; frame(); ppm("page-tracks"); + open_family(FAM_ENV); ui.force = 1; ui.hot_col = 1; ui.hot_t = 30; frame(); ppm("page-env"); + open_family(FAM_EDIT); ui.force = 1; frame(); ppm("page-edit"); + open_family(FAM_FX); ui.force = 1; frame(); ppm("page-fx"); + open_family(FAM_SEQ); ui.force = 1; frame(); ppm("page-step"); + open_family(FAM_GLO); ui.force = 1; frame(); ppm("page-global"); + open_family(FAM_GLO); ui.force = 1; frame(); ppm("page-master"); + open_family(FAM_SCL); ui.force = 1; frame(); ppm("page-scale"); + + /* ---- taps open pages, holds are layers */ + go_home(); ui.force = 1; frame(); + tap(B_SEQ); check(cur_fam() == FAM_SEQ, "SEQ tapped: the SEQ pages"); + go_home(); frame(); + tap(B_FX); check(cur_fam() == FAM_FX, "FX tapped: the FX pages"); + go_home(); frame(); + press(B_FX); frames(12); check(ui.layer == LY_FX && punch.hold, "FX held: the punch layer shows"); + ppm("layer-punch"); + fm1_in.notes = 1u << 4; frame(); check(punch.req == 2, "FX + the 3rd white key: punch effect 3"); + ppm("layer-punch-on"); + fm1_in.notes = 0; frame(); check(punch.req == -1, "key up: the mix comes back"); + encs[panel.enc[EN_K2]] = 10; frame(); check(song.g[G_DUST] > 0, "FX + KNOB 2: DUST"); + encs[panel.enc[EN_K1]] = -10; frame(); check(song.g[G_FILT] < 0, "FX + KNOB 1: the filter (low-pass)"); + release(B_FX); check(cur_page()->scope == SC_TRK && ui.layer == LY_PLAY, "FX used then let go: no FX page"); + song.g[G_DUST] = 0; song.g[G_FILT] = 0; + + /* ---- SEQ layer: drum steps on the white keys */ + song.sel = TRK_DRUM; go_home(); frame(); + key(4); /* A3: the snare, played: the layer's sound */ + check(pen_lane == 2, "a drum key played: the SEQ layer's sound (snare)"); + press(B_SEQ); frames(10); + key(0); key(7); key(14); /* steps 1, 5, 9 */ + check(dstep_has(&TDRUM->dstep[0], 2) && dstep_has(&TDRUM->dstep[4], 2) && dstep_has(&TDRUM->dstep[8], 2) && + !dstep_has(&TDRUM->dstep[1], 2), "SEQ + white keys 1, 5, 9: snare steps"); + ppm("layer-steps"); + fm1_in.notes = 1u << 7; frame(); /* step 5 held + KNOB 2 / 3: level, ratchet */ + encs[panel.enc[EN_K2]] = 1; frame(); + encs[panel.enc[EN_K3]] = 2; frame(); + fm1_in.notes = 0; frame(); + check(dstep_lvl(&TDRUM->dstep[4], 2) == LV_HARD && dstep_rat(&TDRUM->dstep[4], 2) == 2u, + "step 5 held + KNOB 2 / 3: hard, x3"); + key(0); check(!dstep_has(&TDRUM->dstep[0], 2), "step 1 again: off"); + release(B_SEQ); check(ui.layer == LY_PLAY && !on_drum_page(), "SEQ used then let go: no page change"); + + /* ---- EDIT: undo / redo, erase, length */ + press(B_EDIT); frames(10); + edges_btn |= BT(B_OCTDN); fm1_in.buttons |= BT(B_OCTDN); frame(); fm1_in.buttons &= ~BT(B_OCTDN); frame(); + check(!dstep_has(&TDRUM->dstep[4], 2) && !dstep_has(&TDRUM->dstep[8], 2), "EDIT + OCT-: undo (the SEQ hold's steps gone)"); + edges_btn |= BT(B_OCTUP); fm1_in.buttons |= BT(B_OCTUP); frame(); fm1_in.buttons &= ~BT(B_OCTUP); frame(); + check(!dstep_has(&TDRUM->dstep[0], 2) && dstep_lvl(&TDRUM->dstep[4], 2) == LV_HARD, "EDIT + OCT+: redo (back, as left)"); + ppm("layer-erase"); + key(4); /* stopped: every snare goes */ + check(!dstep_has(&TDRUM->dstep[4], 2) && !dstep_has(&TDRUM->dstep[8], 2), "EDIT + snare (stopped): every snare erased"); + encs[panel.enc[EN_K2]] = 1; frame(); + check(TDRUM->p[P_SLEN] == 32, "EDIT + KNOB 2: length x2"); + release(B_EDIT); + edges_btn |= BT(B_EDIT); fm1_in.buttons |= BT(B_EDIT); frame(); /* undo the length too */ + edges_btn |= BT(B_OCTDN); fm1_in.buttons |= BT(B_OCTDN); frame(); fm1_in.buttons &= ~BT(B_OCTDN); frame(); + release(B_EDIT); + check(TDRUM->p[P_SLEN] == 16, "EDIT + OCT-: the length back to 16"); + + /* ---- ARP layer: a roll, rate knob */ + press(B_ARP); frames(10); + encs[panel.enc[EN_K1]] = 1; frame(); + check(song.g[G_ROLL] == 2, "ARP + KNOB 1: the roll rate (1/32)"); + fm1_in.notes = 1u << 7; frames(3); check(roll[0].on, "ARP + a key: it rolls"); + ppm("layer-roll"); + fm1_in.notes = 0; frame(); check(!roll[0].on, "key up: the roll ends"); + release(B_ARP); + + /* ---- SCL: the key of the song; GLO: mute, solo, tap */ + song.sel = 0; go_home(); frame(); + press(B_SCL); frames(10); + key(9); /* D4 */ + check(trk[0].p[P_ROOT] == 2 && trk[1].p[P_ROOT] == 2 && trk[2].p[P_ROOT] == 2, "SCL + D: every part in D"); + encs[panel.enc[EN_K1]] = 2; frame(); + check(trk[0].p[P_CHORD] == 2, "SCL + KNOB 1: chords (7TH) on the track"); + ppm("layer-key"); + release(B_SCL); + press(B_GLO); frames(10); + key(0); check(trk[0].p[P_MUTE] == 1, "GLO + key 1: track 1 muted"); + key(9); check(song.solo == 2u, "GLO + key 6: track 2 soloed"); + ppm("layer-mix"); + for (i = 0; i < 4u; i++) { fm1_in.notes = 1u << 26; frame(); fm1_in.notes = 0; frames(36); } /* ~0.6 s apart */ + check(song.g[G_BPM] >= 95 && song.g[G_BPM] <= 105, "GLO + the last key, tapped at ~0.6 s: ~100 BPM"); + key(0); key(9); + check(!trk[0].p[P_MUTE] && !song.solo, "again: unmuted, no solo"); + release(B_GLO); + trk[0].p[P_CHORD] = 0; + + /* ---- REC: press arms; held: the ring; to the end: cleared */ + go_home(); frame(); + song.playing = 0; song.rec = 0; rec_wait = 0; + tap(B_REC); check(rec_wait == 1, "REC tapped (stopped): armed"); + ui.force = 1; frame(); ppm("live-rec-ready"); + tap(B_REC); check(rec_wait == 0, "REC again: cancelled"); + trk[0].step[3].n = 1, trk[0].step[3].note[0] = 60, trk[0].step[3].time = ST_NOTE; + press(B_REC); frames(50); /* 0.8 s: the ring */ + check(ui.hold_kind == 1u && rec_wait == 0, "REC held: the press undone, the clear ring"); + ppm("hold-clear"); + frames(90); /* to the end */ + check(!trk[0].step[3].n && ui.hold_kind == 0, "REC held to the end: track 1 cleared"); + release(B_REC); + press(B_EDIT); frames(10); + edges_btn |= BT(B_OCTDN); fm1_in.buttons |= BT(B_OCTDN); frame(); fm1_in.buttons &= ~BT(B_OCTDN); frame(); + release(B_EDIT); + check(trk[0].step[3].n == 1, "EDIT + OCT-: the cleared track back"); + press(B_REC); frames(60); release(B_REC); /* let go before the end: nothing */ + check(trk[0].step[3].n == 1 && !rec_wait, "REC let go before the end: nothing cleared"); + + /* ---- SAVE: tap = the song page; hold = saved */ + go_home(); frame(); + press(B_SAVE); frames(40); check(ui.hold_kind == 2u, "SAVE held: the save ring"); ppm("hold-save"); frames(70); release(B_SAVE); + check(saves == 1 && !on_song_page(), "SAVE held: the project saved (no song page)"); + tap(B_SAVE); check(on_song_page(), "SAVE tapped on TRACKS: the song page"); + ui.force = 1; frame(); ppm("page-song"); + + /* ---- the drum screen */ + song.sel = TRK_DRUM; studio_open(SC_DRUM); ui.force = 1; frame(); + check(on_drum_page(), "the drum screen"); + encs[panel.enc[EN_K3]] = 1; frame(); check(dstep_has(&TDRUM->dstep[0], 0), "DRUMS: KNOB 3 adds the kick on step 1"); + encs[panel.enc[EN_K4]] = -1; frame(); check(dstep_lvl(&TDRUM->dstep[0], 0) == LV_SOFT, "DRUMS: KNOB 4 softer"); + encs[panel.enc[EN_K1]] = 100; encs[panel.enc[EN_K2]] = 100; frame(); + check(drum_lane == 15 && drum_cursor == 15, "DRUMS: KNOB 1 / 2 bounded (16 sounds, 16 steps)"); + { /* a scene to look at */ + static const uint8_t BEAT[16] = {0x11, 0x10, 0x10, 0x10, 0x14, 0x10, 0x10, 0x21, 0x11, 0x10, 0x01, 0x10, 0x1C, 0x10, 0x10, 0x20}; + uint32_t j; + for (j = 0; j < 16u; j++) { + memset(&TDRUM->dstep[j], 0, sizeof(dstep_t)); + if (BEAT[j] & 1u) dstep_set(&TDRUM->dstep[j], 0, LV_HARD, 0); + if (BEAT[j] & 4u) dstep_set(&TDRUM->dstep[j], 2, LV_NORM, 0); + if (BEAT[j] & 8u) dstep_set(&TDRUM->dstep[j], 3, LV_GHOST, 0); + if (BEAT[j] & 0x10u) dstep_set(&TDRUM->dstep[j], 4, j % 4u ? LV_SOFT : LV_NORM, j == 14u ? 2u : 0u); + if (BEAT[j] & 0x20u) dstep_set(&TDRUM->dstep[j], 5, LV_NORM, 0); + } + for (j = 0; j < 16u; j += 3u) { trk[0].step[j].n = 1; trk[0].step[j].note[0] = 36; trk[0].step[j].time = ST_NOTE; } + for (j = 0; j < 16u; j += 4u) { trk[1].step[j].n = 3; trk[1].step[j].time = ST_NOTE; } + drum_lane = 4; drum_cursor = 6; drum_page = 0; ui.force = 1; ui.msg_t = 0; + drums.hits = 1u | 1u << 4; frame(); ppm("live-grid"); + drum_page = 1; ui.force = 1; drums.hits = 1u | 1u << 4; frame(); ppm("live-kit"); + drum_page = 0; song.sel = 1; go_home(); ui.force = 1; + transport_req = 1; frames(30); song.rec = 2u; frame(); ui.force = 1; frame(); ppm("live-tracks"); + song.rec = 0; transport_req = 2; frames(2); + song.sel = TRK_DRUM; + } + { /* the free take screens */ + static track_t keep[NTRK]; + memcpy(keep, trk, sizeof keep); + for (i = 0; i < NTRK; i++) steps_clear(&trk[i]); + rec_wait = 1; ui.force = 1; frame(); ppm("live-rec-free"); + rec_wait = 0; ft_on = 1; ft_t = (uint32_t)(5.4 * FS / CTL); ui.force = 1; ui_draw(); ppm("live-free-take"); + ft_on = 0; ft_t = 0; memcpy(trk, keep, sizeof keep); + rec_wait = 0; frame(); + } + for (i = 0; i < DRUM_KITS; i++) { TDRUM->p[P_E0] = (int16_t)i; ui.force = 1; drum_page = 1; frame(); } + drum_page = 0; + + { /* fuzz: 20000 frames of random buttons (held or tapped), knobs and keys, with the audio running + * between frames; every draw stays on the screen (lcd_blit / lcd_fill assert it) */ + uint32_t f, seed = 777, held = 0; + #define R(n) ((seed = seed * 1664525u + 1013904223u) >> 8) % (n) + song.sel = 0; go_home(); ui.force = 1; + for (f = 0; f < 20000u; f++) { + if (R(6) == 0) { + uint32_t bt = R(NB); + edges_btn |= 1u << panel.btn[bt]; + if (bt != B_HOME && R(3) == 0) held ^= 1u << panel.btn[bt]; + } + if (R(30) == 0) held = 0; + fm1_in.buttons = held & ~(1u << panel.btn[B_HOME]); + if (R(4) == 0) encs[R(7)] += (int32_t)R(5) - 2; + fm1_in.notes = R(10) == 0 ? (1u << R(27)) : (R(3) ? fm1_in.notes : 0); + frame(); + if (ui.menu) { ui.menu = 0; ui.force = 1; } /* (the menu is tested above) */ + } + fm1_in.buttons = 0; fm1_in.notes = 0; frames(4); + #undef R + } + printf("ui: %s\n", fails ? "FAILED" : "pages, layers (punch, steps, erase, roll, key, mix), holds (clear, save), drums, REC, 20000-frame fuzz PASS"); + return fails; +} diff --git a/tests/upreset_test.c b/tests/upreset_test.c new file mode 100644 index 0000000..d0af207 --- /dev/null +++ b/tests/upreset_test.c @@ -0,0 +1,189 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */ +/* Host test of the user preset record (firmware/src/upreset.c, -DUP_HOST part): + * UP_PUT parsing, a bank round trip through storage.c on a simulated NOR, + * bank / record version checks, map-by-count, pattern <-> steps. */ +#include +#include +#include +#define __attribute__(x) +#define UP_HOST 1 +#include "../firmware/src/core.h" + +static uint8_t nor[0x100000]; +static int st_read(uint32_t off, void *dst, uint32_t n) { memcpy(dst, nor + off, n); return 0; } +static int st_erase(uint32_t off) { memset(nor + off, 0xFF, 4096); return 0; } +static int st_prog(uint32_t off, const void *src, uint32_t n) +{ + const uint8_t *s = src; + uint32_t i; + for (i = 0; i < n; i++) + nor[off + i] &= s[i]; + return 0; +} +#include "../firmware/src/storage.c" +#include "../firmware/src/upreset.c" + +static int check(const char *what, int ok) +{ + printf("%-46s %s\n", what, ok ? "ok" : "FAIL"); + return ok ? 0 : 1; +} + +static uint32_t put_frame(uint8_t *a, uint32_t slot, uint32_t eng, const char *name, int32_t base) +{ + uint32_t n = 0, i; + a[n++] = (uint8_t)slot; + a[n++] = (uint8_t)eng; + for (i = 0; name[i]; i++) + a[n++] = (uint8_t)name[i]; + a[n++] = 0; + for (i = 0; i < P_COUNT; i++) { + uint32_t u = (uint32_t)(base + (int32_t)i + 8192); + a[n++] = u & 127u; + a[n++] = (u >> 7) & 127u; + } + for (i = 0; i < 16u; i++) { + a[n++] = (uint8_t)(i % 3u ? 40u + i : 0u); /* rests on 0, 3, 6 .. */ + a[n++] = (uint8_t)(i == 3u ? 4u : i % 3u ? 1u : 2u); /* step 3: tie; slide on a rest drops */ + } + return n; +} + +int main(void) +{ + uint8_t a[640]; + up_rec_t r, got; + uint32_t n, slot = 99, i; + int bad = 0, len, ok; + int16_t v[P_COUNT], def[P_COUNT]; + memset(nor, 0xFF, sizeof nor); + + n = put_frame(a, 5, 2, "Bass One", -40); + bad += check("UP_PUT frame < 640 bytes", 5u + n + 1u < 640u); + bad += check("UP_PUT parses", up_parse(a, n, &r, &slot) == 0 && slot == 5u && r.engine == 2u && + up_valid(&r) && !memcmp(r.name, "Bass One", 8) && !r.name[8]); + ok = 1; + for (i = 0; i < P_COUNT; i++) + ok &= r.p[i] == (int16_t)(-40 + (int32_t)i); + bad += check("UP_PUT values (negative v14 too)", ok); + bad += check("pattern: rest drops flags, tie has no note", + r.note[0] == 0 && r.flags[0] == 0 && r.note[1] == 41 && r.flags[1] == 1 && r.note[3] == 0 && + r.flags[3] == 4); + bad += check("UP_PUT short frame -> args", up_parse(a, n - 1u, &r, &slot) == 1); + n = put_frame(a, 32, 0, "X", 0); + bad += check("UP_PUT slot 32 -> args", up_parse(a, n, &r, &slot) == 1); + n = put_frame(a, 0, NENGINES, "X", 0); + bad += check("UP_PUT bad engine -> args", up_parse(a, n, &r, &slot) == 1); + n = put_frame(a, 0, 0, "", 0); + bad += check("UP_PUT empty name -> args", up_parse(a, n, &r, &slot) == 1); + n = put_frame(a, 0, 0, "THIRTEEN CHRS", 0); + bad += check("UP_PUT 13-char name -> args", up_parse(a, n, &r, &slot) == 1); + n = put_frame(a, 0, 0, "TWELVE CHARS", 0); + bad += check("UP_PUT 12-char name ok", up_parse(a, n, &r, &slot) == 0 && !memcmp(r.name, "TWELVE CHARS", 12)); + { + char nm[13]; + *up_rec(31) = r; + memcpy(up_rec(31)->name, "Low case", 9); + up_name(31, nm); + bad += check("name shown upper case", !strcmp(nm, "LOW CASE")); + } + + /* bank round trip through storage.c */ + n = put_frame(a, 17, 3, "Keys", 7); + up_parse(a, n, &r, &slot); + up_bank[1].magic = UP_BANK_MAGIC; + up_bank[1].rsize = sizeof(up_rec_t); + up_bank[1].nslot = UP_PER_BANK; + *up_rec(17) = r; + bad += check("bank fits one object", sizeof(up_bank_t) <= ST_PAYLOAD_MAX); + bad += check("bank save", st_save(OBJ_UPRESET0 + 1, &up_bank[1], sizeof up_bank[1]) == 0); + memset(up_bank, 0, sizeof up_bank); + len = st_load(OBJ_UPRESET0 + 1, &up_bank[1], sizeof up_bank[1]); + up_bank_check(1, len); + got = *up_rec(17); + bad += check("bank load: the record is back", up_used(17) && !memcmp(&got, &r, sizeof r)); + bad += check("other slots empty", !up_used(16) && !up_used(18) && !up_used(0)); + len = st_load(OBJ_UPRESET0, &up_bank[0], sizeof up_bank[0]); + up_bank_check(0, len); + bad += check("bank 0 never written -> empty", len < 0 && !up_used(0) && up_bank[0].magic == 0); + bad += check("banks in 0xDC000..0xDFFFF", st_sector(OBJ_UPRESET0, 0) == 0xDC000u && + st_sector(OBJ_UPRESET0 + 1, 1) == 0xDF000u && + st_sector(OBJ_PROJECT0 + 3, 1) + 4096u <= 0xA0000u); + up_bank[1].rsize = 190; /* another record layout */ + up_bank_check(1, (int)sizeof up_bank[1]); + bad += check("bank with another record size -> empty", !up_used(17)); + up_bank[1].magic = UP_BANK_MAGIC; + up_bank[1].rsize = sizeof(up_rec_t); + up_bank[1].nslot = UP_PER_BANK; + *up_rec(17) = r; + up_rec(17)->ver = UP_VER + 1u; + bad += check("record with another version -> empty", !up_used(17)); + + /* map by count: a record from a build with 2 parameters fewer */ + for (i = 0; i < P_COUNT; i++) + def[i] = (int16_t)(1000 + i); + r.np = P_COUNT - 2u; + for (i = 0; i < P_COUNT; i++) + r.p[i] = (int16_t)i; + up_params(&r, v, def); + ok = 1; + for (i = 0; i < P_E0; i++) + ok &= v[i] == (i < P_E0 - 2u ? (int16_t)i : def[i]); + for (i = 0; i < 8u; i++) + ok &= v[P_E0 + i] == (int16_t)(P_E0 - 2u + i); + bad += check("np < P_COUNT: mapped by count", ok); + /* a record saved before the SLICER (P_COUNT 53, P_E0 45): the four SLICER parameters (just + * before P_E0) take their defaults, everything else keeps its id */ + r.np = 53; + for (i = 0; i < 53u; i++) + r.p[i] = (int16_t)(2000 + i); + up_params(&r, v, def); + ok = P_SLCR == 45 && P_SLDEPTH + 1 == P_CHORD && P_CHORD == 49 && P_E0 == 50; + for (i = 0; i < 45u; i++) + ok &= v[i] == (int16_t)(2000 + i); + for (i = P_SLCR; i <= P_CHORD; i++) + ok &= v[i] == def[i]; + for (i = 0; i < 8u; i++) + ok &= v[P_E0 + i] == (int16_t)(2000 + 45 + i); + bad += check("old record (np 53): SLICER and CHORD defaults, E0..E7 kept", ok); + /* a record of SLOOP 1.0 (P_COUNT 57, P_E0 49): CHORD (SLOOP 2.0) takes its default */ + r.np = 57; + for (i = 0; i < 57u; i++) + r.p[i] = (int16_t)(3000 + i); + up_params(&r, v, def); + ok = 1; + for (i = 0; i < P_CHORD; i++) + ok &= v[i] == (int16_t)(3000 + i); + ok &= v[P_CHORD] == def[P_CHORD]; + for (i = 0; i < 8u; i++) + ok &= v[P_E0 + i] == (int16_t)(3000 + 49 + i); + bad += check("SLOOP 1.0 record (np 57): CHORD default, the rest kept", ok); + r.np = P_COUNT; + for (i = 0; i < P_COUNT; i++) + r.p[i] = (int16_t)i; + up_params(&r, v, def); + ok = 1; + for (i = 0; i < P_COUNT; i++) + ok &= v[i] == (int16_t)i; + bad += check("np == P_COUNT: as stored", ok); + + { /* steps -> pattern (UP_STORE) */ + step_t st[NSTEP]; + memset(st, 0, sizeof st); + for (i = 0; i < 16u; i++) + st[i].time = ST_REST; + st[0] = (step_t){{60, 64, 67, 0}, 3, ST_NOTE, SF_ACCENT | SF_SLIDE, 100}; + st[1] = (step_t){{0}, 0, ST_TIE, 0, 0}; + st[2] = (step_t){{50}, 0, ST_NOTE, SF_ACCENT, 0}; /* n = 0: empty */ + st[20] = (step_t){{70}, 1, ST_NOTE, 0, 90}; /* beyond 16: not stored */ + up_pat_from(&r, st); + bad += check("steps -> pattern", r.note[0] == 60 && r.flags[0] == 3 && r.note[1] == 0 && r.flags[1] == 4 && + r.note[2] == 0 && r.flags[2] == 0 && !up_pat_empty(&r)); + memset(st, 0, sizeof st); + up_pat_from(&r, st); + bad += check("empty sequencer -> empty pattern", up_pat_empty(&r)); + } + printf("%s\n", bad ? "USER PRESET TEST FAILED" : "user preset test passed"); + return bad != 0; +} diff --git a/tools/build.py b/tools/build.py new file mode 100644 index 0000000..5131e99 --- /dev/null +++ b/tools/build.py @@ -0,0 +1,347 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-3.0-only +# Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments +"""Build Felucca: the app, the update loader and an installable .fwsc package. + + tools/build.py [--release X.Y[-suffix]] + +Outputs in build/: felucca.bin (app), loader/ota.bin (update loader), +felucca.fwsc (package). See BUILDING.md for the toolchain and the SDK. + +The JieLi toolchain is Linux x86-64 only. JIELI_TOOLCHAIN points at it; on +macOS (or with JIELI_DOCKER=1) each tool runs in a linux/amd64 container. +""" +import argparse +import hashlib +import os +import platform +import re +import shutil +import struct +import subprocess +import sys +from concurrent.futures import ThreadPoolExecutor +from pathlib import Path + +SRC = Path(__file__).resolve().parents[1] +FW = SRC / "firmware" +OUT = SRC / "build" +GEN = OUT / "gen" +LDR = OUT / "loader" +sys.path.insert(0, str(SRC / "tools")) +import fm1pkg_make # noqa: E402 +import lz4blk # noqa: E402 + +APP_XIP = 0x02000120 # app.bin offset 0 in the XIP map; the SPL jumps here +APP_SLOT = fm1pkg_make.APP_SLOT +LOADER_LOAD = 0x01C0A800 +LOADER_NAME = b"usb_hid_ota.bin" # the file name the SPL looks for +DOCKER_IMAGE = os.environ.get("JIELI_DOCKER_IMAGE", "debian:bookworm-slim") +CFLAGS = ["-Os", "-ffunction-sections", "-fno-builtin", "-Wall", "-Wno-unused-function"] +LINE = re.compile(r"^\s*([0-9a-f]+):\s+((?:[0-9a-f]{2} )+)\s*\t(.*)$") + +# SDK files of AC79NN_SDK_V1.2.1_2023-12-13 (the tested version) +SDK_SHA256 = { + "uboot.boot": "4e3b4c220dc96641cb5a723f41e68ce41d5261ae9434bb33fbd7f2c59976ded4", + "cfg_tool.bin": "276579954f076886a6a7694f65dc71c034a63a2c204b76749065c0ac7b010d1b", + "cfg/eq_cfg_hw.bin": "41167491bffed4651750719c973d2758adeb9021a5670d02d6a53c85ed80ea7d", +} + +PRODUCT = "FM-1_900" # package identity; release builds are FM-1_9XY +VERSION = None # FELUCCA_VERSION for release builds (default: firmware/src/ui.c) + + +def toolchain(): + tc = os.environ.get("JIELI_TOOLCHAIN") + if not tc or not (Path(tc) / "pi32v2" / "bin" / "clang").exists(): + raise SystemExit("JIELI_TOOLCHAIN must point at the JieLi Linux toolchain " + "(the directory with pi32v2/ and common/; see tools/get_toolchain.sh)") + return Path(tc).resolve() + + +def use_docker(): + native = platform.system() == "Linux" and platform.machine() in ("x86_64", "AMD64") + return os.environ.get("JIELI_DOCKER", "0" if native else "1") == "1" + + +def tc(tool, *args): + """run a toolchain binary (pi32v2/bin/..., common/bin/...) with cwd SRC; paths relative to SRC""" + rel = [str(Path(a).resolve().relative_to(SRC)) if isinstance(a, Path) else a for a in args] + if tool == "cc": # the toolchain's cc wrapper needs python3; call clang directly + tool, rel = "pi32v2/bin/clang", ["-target", "pi32v2", *rel] + if use_docker(): + cmd = ["docker", "run", "--rm", "--platform", "linux/amd64", "-v", f"{SRC}:/work", + "-v", f"{toolchain()}:/opt/jieli:ro", "-w", "/work", DOCKER_IMAGE, f"/opt/jieli/{tool}", *rel] + else: + cmd = [str(toolchain() / tool), *rel] + r = subprocess.run(cmd, cwd=SRC, capture_output=True, text=True) + if r.returncode: + sys.stderr.write(r.stdout + r.stderr) + raise SystemExit(f"build: {tool} failed") + if r.stderr.strip(): + sys.stderr.write(r.stderr) + return r.stdout + + +def tc_all(*cmds): + with ThreadPoolExecutor(len(cmds)) as ex: + return list(ex.map(lambda c: tc(*c), cmds)) + + +def generate(): + """generated headers (fonts, icons, tables, samples)""" + GEN.mkdir(parents=True, exist_ok=True) + tools = SRC / "tools" + cmds = [[tools / "gen_font.py", GEN / "felucca_font.h"], + [tools / "gen_icons.py", GEN / "felucca_icons.h"], + [tools / "gen_tables.py", GEN / "felucca_tables.h"], + [tools / "gen_samples.py", GEN / "felucca_samples.h"], + [tools / "gen_drumkits.py", GEN / "felucca_drumkits.h"], + [tools / "gen_logo.py", GEN / "sloop_logo.h"]] + procs = [subprocess.Popen([sys.executable, *map(str, c)], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, + text=True) for c in cmds] + failed = [] + for c, p in zip(cmds, procs): + sys.stdout.write(p.communicate()[0]) + if p.returncode: + failed.append(c[0].name) + if failed: + raise SystemExit(f"build: {', '.join(failed)} failed") + + +# ---- update loader + +def crc16(d, c=0): + for b in d: + c ^= b << 8 + for _ in range(8): + c = ((c << 1) ^ 0x1021) if c & 0x8000 else c << 1 + c &= 0xFFFF + return c + + +def ldr_head(dcrc, a, b, attr, name): + body = struct.pack(" 4096 or lz4blk.decompress(c) != raw: + raise SystemExit(f"loader: block {i // 4096} does not compress below 4096 B") + blocks += struct.pack(" 4 and p[1].startswith(".") and int(p[3], 16) >= 0x02000000 and int(p[2], 16): + raise SystemExit(f"loader: section {p[1]} at {p[3]} is outside RAM") + image = (LDR / "loader.bin").read_bytes() + if not image or len(image) > 0x14000: + raise SystemExit("loader: image empty or too big") + ota = ldr_wrap(image) + (LDR / "ota.bin").write_bytes(ota) + bss = [int(ln.split()[0], 16) for ln in syms.splitlines() if ln.rstrip().endswith("_bss_end")] + print(f"loader: image {len(image)} B at {LOADER_LOAD:#x}" + (f", bss end {bss[0]:#x}" if bss else "")) + print(f"loader: ota.bin {len(ota)} B") + return ota + + +# ---- app + +def build_app(): + flags = [*CFLAGS, "-Ifirmware/hal", "-Ifirmware/src", "-Ibuild/gen"] + for flag in ("FELUCCA_FLASH", "FELUCCA_OTA", "FELUCCA_OTA_DRYRUN", "FELUCCA_CDC", "FELUCCA_UART", + "FELUCCA_ICONS", "FELUCCA_SLICE"): + v = os.environ.get(flag) # unset: the default in firmware/src/felucca.c + if v in ("0", "1"): + flags.append(f"-D{flag}={v}") + flags.append(f'-DFELUCCA_ID="{PRODUCT}"') + if VERSION: + flags.append(f'-DFELUCCA_VERSION="{VERSION}"') + tc_all(("cc", "-c", FW / "crt0.S", "-o", OUT / "crt0.o"), + ("cc", "-c", FW / "hal" / "fm1_vec.S", "-o", OUT / "fm1_vec.o"), + ("cc", "-c", FW / "hal" / "fm1_isr.S", "-o", OUT / "fm1_isr.o"), + ("cc", *flags, "-c", FW / "src" / "felucca.c", "-o", OUT / "felucca.o")) + elf = OUT / "felucca.elf" + tc("pi32v2/bin/ld", "-T", FW / "app.ld", OUT / "crt0.o", OUT / "fm1_vec.o", OUT / "fm1_isr.o", + OUT / "felucca.o", "-o", elf) + for sect in ("text.bin", "data.bin", "ramtext.bin"): + (OUT / sect).unlink(missing_ok=True) + *_, syms, dis, rt = tc_all(("common/bin/objcopy", "-O", "binary", "-j", ".text", elf, OUT / "text.bin"), + ("common/bin/objcopy", "-O", "binary", "-j", ".data", elf, OUT / "data.bin"), + ("common/bin/objcopy", "-O", "binary", "-j", ".ram_text", elf, OUT / "ramtext.bin"), + ("common/bin/objdump", "-t", elf), + ("common/bin/objdump", "-d", elf), + ("common/bin/objdump", "-d", "-j", ".ram_text", elf)) + (OUT / "felucca.dis").write_text(dis) + + def symv(name): + return int(re.search(r"^([0-9a-f]+) .*\s" + name + r"$", syms, re.M).group(1), 16) + img = bytearray((OUT / "text.bin").read_bytes()) + # .ram_text and .data follow .text at their load addresses; crt0 copies them by words + for sect, lname in (("ramtext.bin", "_rt_load"), ("data.bin", "_data_load")): + load = symv(lname) + if load % 4: + raise SystemExit(f"{lname} {load:#x} is not word aligned") + blob = (OUT / sect).read_bytes() if (OUT / sect).exists() else b"" + if blob: + if load - APP_XIP < len(img): + raise SystemExit(f"{lname} overlaps the image") + img += b"\xff" * (load - APP_XIP - len(img)) + img += blob + img += b"\xff" * (-len(img) % 4) + (OUT / "felucca.bin").write_bytes(img) + return bytes(img), syms, dis, rt + + +def check(img, syms, dis, rt): + errors, notes = [], [] + m = re.search(r"^([0-9a-f]+) .*\s_start$", syms, re.M) + if not m or int(m.group(1), 16) != APP_XIP: + errors.append(f"_start is not at {APP_XIP:#x}") + if img[:4] != bytes.fromhex("04818000"): + errors.append(f"image starts with {img[:4].hex()}, not the entry stub") + rt_calls = [ln for ln in rt.splitlines() if re.search(r"\bcall\b", ln)] + if rt_calls: # RAM code runs with the flash off: no calls into XIP + errors.append(f".ram_text contains calls: {rt_calls[:3]}") + else: + notes.append(f".ram_text: {len([ln for ln in rt.splitlines() if LINE.match(ln)])} insns, no calls") + for ln in dis.splitlines(): # nothing may call or load an address in the chip ROM + mm = LINE.match(ln) + if not mm: + continue + for v in re.findall(r"= (-?\d+) <|call -?\d+ <[^:>]*: ([0-9a-f]+) >", mm.group(3)): + val = (int(v[0]) & 0xFFFFFFFF) if v[0] else int(v[1], 16) & 0xFFFFFFFF + if 0xFFC00000 <= val < 0xFFD00000: + errors.append(f"reference to ROM address {val:#010x}") + if len(img) > APP_SLOT: + errors.append(f"image {len(img)} B exceeds the app slot") + + def sym(name): + mm = re.search(r"^([0-9a-f]+) .*\s" + name + r"$", syms, re.M) + return int(mm.group(1), 16) if mm else 0 + bss = sym("_bss_end") - 0x01C08000 + pool = sym("_pool_end") - sym("_pool_start") + notes.append(f"image {len(img)} B; RAM .data+.bss {bss} B of 98304; pool {pool} B of {0x54000}") + if bss > 96 * 1024: + errors.append("RAM region overflow") + if 0x54000 - pool < 8192: # keep >= 8 KiB of the pool spare + errors.append(f"pool headroom {0x54000 - pool} B < 8192 B") + return errors, notes + + +# Every hardware register access lives in hal/. In src/ and loader/ (comments stripped): +# - no volatile pointer cast, except of a C object's address (`*(volatile T *)&x`: a read-once +# of a RAM flag shared with an ISR, e.g. usb.c ota_wire_send); +# - no literal in a register or reserved window (core SFRs 0x10000-0x13FFF, SFC 0x40000-0x43FFF, +# GPIO/IOMAP 0x50000-0x51FFF, CPU 0x1EE0000-0x1EEFFFF, RAM top 0x01C7F000- (boot info, +# mailbox, vectors), XIP 0x02000000-0x020FFFFF); +# - no inline asm, except the empty compiler barrier RING_PUBLISH() (emits no instruction); +# - no HAL register macro (a hal/ #define that is, or expands to, a volatile access). +# Linker symbols (_bss_start[], _rt_load[], ...) are plain C objects and pass. +MMIO_LIT = re.compile(r"\b0x0*(1[0-3][0-9a-f]{3}|4[0-3][0-9a-f]{3}|5[01][0-9a-f]{3}|1ee[0-9a-f]{4}|" + r"1c7f[0-9a-f]{3}|20[0-9a-f]{5})u?l?\b", re.I) +MMIO_CAST = re.compile(r"\(\s*(?:const\s+)?volatile\b[^()]*\*\s*\)(?!\s*&)") +MMIO_ASM = re.compile(r"\b(?:__asm__|asm)\b(?!\s+volatile\s*\(\s*\"\"\s*:::\s*\"memory\"\s*\))") + + +def mmio_check(): + def strip(s): + s = re.sub(r"/\*.*?\*/", lambda m: "\n" * m.group(0).count("\n"), s, flags=re.S) + return re.sub(r"//[^\n]*", "", s) + defs = {} + for h in sorted((FW / "hal").glob("*.h")): + for m in re.finditer(r"^#define\s+(\w+)(?:\([^)]*\))?\s+(.*)$", strip(h.read_text()), re.M): + defs[m.group(1)] = m.group(2) + regs = {n for n, b in defs.items() if re.search(r"\bvolatile\b", b)} + while True: # macros built on register macros (FM1_WR_LIMIT_H -> FM1_X2) + more = {n for n, b in defs.items() if n not in regs and set(re.findall(r"\w+", b)) & regs} + if not more: + break + regs |= more + errors = [] + for f in sorted([*(FW / "src").glob("*.[ch]"), *(FW / "loader").glob("*.c")]): + for no, ln in enumerate(strip(f.read_text()).splitlines(), 1): + where = f"{f.relative_to(FW)}:{no}" + for rx, what in ((MMIO_LIT, "register/window address"), (MMIO_CAST, "volatile pointer cast"), + (MMIO_ASM, "inline asm")): + m = rx.search(ln) + if m: + errors.append(f"{where}: {what} outside hal/ ({m.group(0).strip()}); add a hal/ helper") + used = set(re.findall(r"\b[A-Z_][A-Z0-9_]*\b", ln)) & regs + if used: + errors.append(f"{where}: HAL register macro {sorted(used)[0]} outside hal/; use a hal/ helper") + return errors + + +def main(): + global PRODUCT, VERSION + ap = argparse.ArgumentParser() + ap.add_argument("--release", metavar="X.Y", help="release build: identity FM-1_9XY, version string X.Y") + ap.add_argument("--sdk", type=Path, help="JieLi AC79 SDK checkout (default: $AC79_SDK)") + a = ap.parse_args() + name = "felucca.fwsc" + if a.release: # one digit each: the identity has room for two + m = re.fullmatch(r"(\d)\.(\d)(-[A-Za-z0-9]+)?", a.release) + if not m: + raise SystemExit(f"--release {a.release}: use X.Y or X.Y-suffix, one digit each") + PRODUCT = "FM-1_9" + m[1] + m[2] + VERSION = a.release.upper() if "BETA" in a.release.upper() else a.release.upper() + " BETA" + name = f"felucca-{a.release}.fwsc" + fm1pkg_make.SDK = a.sdk + for rel, sha in SDK_SHA256.items(): # fail early without the SDK + if hashlib.sha256(fm1pkg_make.sdk_file(rel)).hexdigest() != sha: + print(f"warning: SDK {rel} differs from AC79NN_SDK_V1.2.1; the package will not match the reference") + OUT.mkdir(parents=True, exist_ok=True) + with ThreadPoolExecutor(2) as ex: + gen, ldr = ex.submit(generate), ex.submit(build_loader) + gen.result() + ota = ldr.result() + img, syms, dis, rt = build_app() + errors, notes = check(img, syms, dis, rt) + hal_err = mmio_check() + errors += hal_err + if not hal_err: + notes.append("register access: hal/ only (src/, loader/ clean)") + for n in notes: + print(" ok ", n) + for e in errors: + print(" FAIL ", e) + if errors: + raise SystemExit("build: checks failed") + pkg = fm1pkg_make.ufw(fm1pkg_make.flash_image(img, fm1pkg_make.KEY), ota, PRODUCT) + (OUT / name).write_bytes(pkg) + att = SRC / "assets" / "samples-cc0" / "ATTRIBUTION.txt" + if att.exists(): + shutil.copy(att, OUT / "ATTRIBUTION.txt") + print(f"app {OUT / 'felucca.bin'} {len(img)} B") + print(f"loader {LDR / 'ota.bin'} {len(ota)} B") + print(f"package {OUT / name} {len(pkg)} B, identity {PRODUCT}") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tools/build_windows.py b/tools/build_windows.py new file mode 100644 index 0000000..00d4cc2 --- /dev/null +++ b/tools/build_windows.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python3 +"""Generate assets on Windows, then compile with the JieLi toolchain in WSL. + +No system packages are installed. --toolchain is an existing Linux path; +--sdk is a Windows directory containing cpu/wl82/tools from the pinned SDK. +""" +import argparse +import os +from pathlib import Path +import subprocess +import sys + +ROOT = Path(__file__).resolve().parents[1] + +def main(): + ap = argparse.ArgumentParser(description=__doc__) + ap.add_argument('--distro', required=True) + ap.add_argument('--toolchain', required=True) + ap.add_argument('--sdk', type=Path, required=True) + ap.add_argument('--skip-generate', action='store_true') + args = ap.parse_args() + os.chdir(ROOT) + import build + if not args.skip_generate: + build.generate() + wsl = ['wsl', '-d', args.distro, '--exec'] + def linux_path(p): + return subprocess.check_output(wsl + ['wslpath', '-a', p.resolve().as_posix()], text=True).strip() + src, sdk = linux_path(ROOT), linux_path(args.sdk) + code = 'import sys;sys.path.insert(0,"tools");import build;build.generate=lambda:None;sys.exit(build.main())' + subprocess.run(['wsl', '-d', args.distro, '--cd', src, '--exec', 'env', + 'JIELI_TOOLCHAIN=' + args.toolchain, 'AC79_SDK=' + sdk, + 'python3', '-c', code], check=True) + +if __name__ == '__main__': + main() diff --git a/tools/fetch_cc0.py b/tools/fetch_cc0.py new file mode 100644 index 0000000..959e968 --- /dev/null +++ b/tools/fetch_cc0.py @@ -0,0 +1,91 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-3.0-only +# Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments +"""Download the CC0 samples of the FLUTE set and the GM kit's hand percussion into +assets/samples-cc0/ (the other built-in sets: tools/gen_builtin_hiphop.py). + +The files are already in the tree; this re-creates them from the source: + https://github.com/sgossner/VSCO-2-CE (CC0 1.0) + https://github.com/sgossner/VCSL (CC0 1.0) +Only the first RANGE bytes of each WAV are downloaded. +""" +import json +import re +import sys +import urllib.parse +import urllib.request +from pathlib import Path + +DEST = Path(__file__).resolve().parents[1] / "assets" / "samples-cc0" +RANGE = 420_000 + +VCSL = "VCSL" +VSCO = "VSCO-2-CE" +# set: (repo, directory, [filename regexes, one file per regex, first match wins]) +PICK = { + "FLUTE": (VSCO, "Woodwinds/Flute/susvib", [r"_C4_v1_1", r"_C5_v1_1", r"_C6_v1_1"]), + "KIT": (VCSL, None, [ + ("Idiophones/Struck Idiophones/Tambourine 1", r"Tamb1_Hit_v2"), + ("Idiophones/Struck Idiophones/Shaker, Small", r"ShakerDouble_Down_rr1"), + ("Membranophones/Struck Membranophones/Conga", r"Conga_HitN_v2_rr1"), + ("Idiophones/Struck Idiophones/Claves", r"Claves1_Hit_v2"), + ("Idiophones/Struck Idiophones/Woodblock", r"wood_click_mp"), + ]), +} + + +def tree(repo, cache={}): + if repo not in cache: + url = f"https://api.github.com/repos/sgossner/{repo}/git/trees/master?recursive=1" + with urllib.request.urlopen(url) as r: + cache[repo] = [e["path"] for e in json.load(r)["tree"] if e["path"].lower().endswith(".wav")] + return cache[repo] + + +def fetch(repo, path, dest): + if dest.exists(): + return 0 + url = f"https://raw.githubusercontent.com/sgossner/{repo}/master/" + urllib.parse.quote(path) + req = urllib.request.Request(url, headers={"Range": f"bytes=0-{RANGE - 1}"}) + with urllib.request.urlopen(req) as r: + data = r.read() + dest.parent.mkdir(parents=True, exist_ok=True) + dest.write_bytes(data) + return len(data) + + +def main(): + total, credits = 0, [] + for name, (repo, folder, pats) in PICK.items(): + files = tree(repo) + for k, p in enumerate(pats): + d, rx = (folder, p) if folder else p + cand = sorted(f for f in files if f.rsplit("/", 1)[0] == d and re.search(rx, f.rsplit("/", 1)[1])) + if not cand: + print(f" {name}: no match for {rx} in {d}") + continue + src = cand[0] + dest = DEST / name / f"{k:02d}_{src.rsplit('/', 1)[1]}" + n = fetch(repo, src, dest) + total += n + credits.append(f"{name}/{dest.name} <- sgossner/{repo}: {src}") + print(f" {name:8s} {dest.name} {n // 1024} KiB") + import datetime + (DEST / "ATTRIBUTION.txt").write_text( + "Felucca SAMPLE engine - source material\n" + f"Retrieved: {datetime.date.today().isoformat()} (first ~400 KB of each file)\n" + "Licence: CC0 1.0 Universal (public domain dedication)\n" + " https://creativecommons.org/publicdomain/zero/1.0/\n" + "Sources: Versilian Studios (Sam Gossner)\n" + " VSCO-2 Community Edition https://github.com/sgossner/VSCO-2-CE (repository licence: CC0-1.0)\n" + " VCSL https://github.com/sgossner/VCSL (repository licence: CC0-1.0)\n\n" + + "\n".join(credits) + "\n") + (DEST / "CREDITS.txt").write_text( + "Samples from Versilian Studios' VSCO-2 Community Edition and VCSL, both released\n" + "under CC0 1.0 (public domain). Thanks to Versilian Studios / Sam Gossner.\n" + "Only the first ~1 s of each file is used.\n\n" + "\n".join(credits) + "\n") + print(f"fetched {total / 1e6:.1f} MB into {DEST}") + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tools/fm1_install.py b/tools/fm1_install.py new file mode 100644 index 0000000..da85e8b --- /dev/null +++ b/tools/fm1_install.py @@ -0,0 +1,478 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-3.0-only +# Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments +"""Install a Felucca package (.fwsc) on an FM-1 over USB-MIDI. + +The same update as the web installer (web/fm1ota.js): step 1, the +running firmware reads parts of the package and starts the update loader; +step 2, the loader reads the whole package and writes it. In both steps the +device asks (SysEx read requests on the logical image) and we answer. Then +the FM-1 restarts and the installed identity is checked. + + fm1_install.py PACKAGE.fwsc [--port NAME] [--yes] [--force] + fm1_install.py --info [--port NAME] + +If the FM-1 is still in update mode (an earlier install was cut off), the +install finishes the write. Needs mido with python-rtmidi. + +Exit codes: 0 done, 1 cancelled or other error, 2 bad arguments or package, +3 FM-1 not found, 4 connection lost or the device stopped, 5 timeout (no +loader / no restart), 6 wrong model, another identity after the install, or the +FM-1 is in the update mode of another firmware (only SLOOP's own loader, +ota-FM-1_9XX, is resumed). +""" +import argparse +import queue +import re +import sys +import time + +HS_QUERY = bytes([0xF0, 0x00, 0x32, 0x45, 0x00, 0x00, 0x00, 0x40, 0x7F, 0xF7]) +UPGRADE = bytes([0xF0, 0x22, 0x24, 0x35, 0x7F, 0xF7]) +FINISH_CHECK, FINISH_WRITE = 0xE0000000, 0xF0000000 +MAXDATA = 512 +BLOCKS, BLK, KEEP = 20, 0x30, 0x2F +LOADER_MARK = b"FELUCCA-LOADER-1" +PORT_RE = re.compile(r"fm-1|felucca|ota|composite|sinco|usb-midi", re.I) # never probe other gear + +# seconds; the tests shorten them +DELAY = {"open": 0.3, "start": 2.0, "reply": 0.01, "loader": 3.0, "reboot": 3.0, "retry": 1.0, + "poll": 1.0, "hs": 1.0, "idle_check": 8.0, "idle_write": 180.0, + "wait_loader": 30.0, "wait_reboot": 40.0} + +EXIT = {"usage": 2, "badpkg": 2, "notfound": 3, "model": 6, "lost": 4, "stopped": 4, "badreq": 4, + "noloader": 5, "noreturn": 5, "mismatch": 6, "foreign": 6} + + +class InstallError(Exception): + def __init__(self, code, msg): + super().__init__(msg) + self.code = code + + +# ------------------------------------------------------------ wire format --- + +def pack7(data): + out, acc, nb = [], 0, 0 + for b in data: + acc |= b << nb + nb += 8 + while nb >= 7: + out.append(acc & 0x7F) + acc >>= 7 + nb -= 7 + if nb: + out.append(acc & 0x7F) + return bytes(out) + + +def unpack7(s): + out, acc, nb = [], 0, 0 + for b in s: + acc |= (b & 0x7F) << nb + nb += 7 + while nb >= 8: + out.append(acc & 0xFF) + acc >>= 8 + nb -= 8 + return bytes(out) + + +def response(addr, data, fl=0): + n = len(data) + body = bytearray([0x00, 0x59, 0x30, (n + 8) & 0xFF, ((n + 8) >> 8) & 0xFF, 0, fl]) + body += addr.to_bytes(4, "little") + bytes([n & 0xFF, (n >> 8) & 0xFF, 0]) + bytes(data) + body.append(~sum(body[6:]) & 0xFF) + return b"\xF0" + pack7(body) + b"\xF7" + + +def parse_request(pkt): + """-> (flags, addr, len) or None""" + if len(pkt) < 2 or pkt[0] != 0xF0 or pkt[-1] != 0xF7: + return None + u = unpack7(pkt[1:-1]) + if len(u) != 15 or u[:3] != b"\x00\x59\x30" or ~sum(u[6:14]) & 0xFF != u[14]: + return None + return u[6], int.from_bytes(u[7:11], "little"), int.from_bytes(u[11:14], "little") + + +class Identity: + def __init__(self, text, model, version): + self.text, self.model, self.version = text, model, version + + @property + def loader(self): + return self.model.lower().startswith("ota-") + + +def parse_identity(pkt): + if len(pkt) < 2 or pkt[0] != 0xF0 or pkt[-1] != 0xF7: + return None + d = unpack7(pkt[1:-1]) + if len(d) != 34 or d[:3] != b"\x00\x59\x11": + return None + txt = d[6:33].rstrip(b"\0").decode("latin-1") + m = re.fullmatch(r"([^_]+)_(\d+)", txt) + return Identity(txt, m[1], int(m[2])) if m else None + + +# --------------------------------------------------------------- package --- + +def product_of(raw): + """the package identity ("FM-1_906"): one marker byte after each of the first 20 blocks""" + if len(raw) < BLOCKS * BLK: + raise InstallError("badpkg", "not an FM-1 package (too short)") + return "".join(chr((m - i - 1) & 0xFF) for i in range(BLOCKS) if (m := raw[i * BLK + KEEP]) != 0x7D) + + +def logical_image(raw): + """the image the device reads during an update: the package without the 20 marker bytes""" + out = bytearray() + for i in range(BLOCKS): + out += raw[i * BLK:i * BLK + KEEP] + return bytes(out + raw[BLOCKS * BLK:]) + + +def model_of(text): + return text.split("_")[0].removeprefix("ota-") + + +# ------------------------------------------------------------------ MIDI --- + +class MidoLink: + """one MIDI in/out pair with a SysEx queue""" + + def __init__(self, backend, in_name, out_name): + import mido + self.backend, self.name, self.mido = backend, in_name, mido + self.q = queue.Queue() + self.inp = mido.open_input(in_name, callback=self._rx) + try: + self.out = mido.open_output(out_name) + except Exception: + self.inp.close() + raise + time.sleep(DELAY["open"]) # CoreMIDI may drop a message sent just after opening + + def _rx(self, msg): + if msg.type == "sysex": + self.q.put(bytes([0xF0, *msg.data, 0xF7])) + + @property + def lost(self): + return self.name not in self.backend.input_names() + + def send(self, pkt): + try: + self.out.send(self.mido.Message("sysex", data=pkt[1:-1])) + return True + except Exception: + return False + + def read(self, timeout): + try: + return self.q.get(timeout=max(timeout, 0)) + except queue.Empty: + return None + + def drain(self): + while not self.q.empty(): + self.q.get_nowait() + + def close(self): + for p in (self.inp, self.out): + try: + p.close() + except Exception: + pass + + +class MidoBackend: + def __init__(self): + import mido + self.mido = mido + + def input_names(self): + return list(dict.fromkeys(self.mido.get_input_names())) + + def output_names(self): + return list(dict.fromkeys(self.mido.get_output_names())) + + def open(self, in_name, out_name): + return MidoLink(self, in_name, out_name) + + +def pair_output(name, outs): + if name in outs: + return name + base = re.sub(r"\s+\d+$", "", name) # Windows numbers each port + same = [o for o in outs if re.sub(r"\s+\d+$", "", o) == base] + if len(same) == 1: + return same[0] + return outs[0] if len(outs) == 1 else None + + +# --------------------------------------------------------------- updater --- + +class Device: + def __init__(self, link, ident, name): + self.link, self.id, self.name = link, ident, name + + +def handshake(link, tries=3): + link.drain() + for _ in range(tries): + if not link.send(HS_QUERY): + return None + end = time.monotonic() + DELAY["hs"] + while (left := end - time.monotonic()) > 0: + p = link.read(left) + if p is None: + break + ident = parse_identity(p) + if ident: + return ident + return None + + +class Updater: + def __init__(self, backend, port=None): + self.backend = backend + self.port = port + + def candidates(self, only_port): + names = self.backend.input_names() + if self.port: + mine = [n for n in names if self.port.lower() in n.lower()] + if only_port: + return mine + return mine + [n for n in names if n not in mine and PORT_RE.search(n)] + return [n for n in names if PORT_RE.search(n)] + + def find(self, want=None, only_port=True): + """the first matching port that answers the handshake (and want(identity))""" + outs = self.backend.output_names() + for name in self.candidates(only_port): + out = pair_output(name, outs) + if not out: + continue + try: + link = self.backend.open(name, out) + except Exception: + continue + ident = handshake(link, 2) + if ident and (want is None or want(ident)): + return Device(link, ident, name) + link.close() + return None + + def wait_for(self, want, secs): + end = time.monotonic() + secs + while time.monotonic() < end: + dev = self.find(want, only_port=False) + if dev: + return dev + time.sleep(DELAY["retry"]) + return None + + def serve(self, link, image, finish, idle, progress): + """answer read requests until the device asks for `finish`; -> (served, finished, lost)""" + served, last = 0, time.monotonic() + while True: + pkt = link.read(DELAY["poll"]) + if pkt is None: + if link.lost: + return served, False, True + if time.monotonic() - last > idle: + return served, False, False + continue + r = parse_request(pkt) + if not r: + continue + fl, addr, n = r + last = time.monotonic() + if addr in (FINISH_CHECK, FINISH_WRITE): + link.send(response(addr, b"success\0")) + if addr == finish: + return served, True, False + continue + if n > MAXDATA or addr + n > len(image): + raise InstallError("badreq", f"the device asked for {addr:#x}+{n}, outside the package") + time.sleep(DELAY["reply"]) + if not link.send(response(addr, image[addr:addr + n], fl)): + return served, False, True + served += 1 + progress(served, addr + n) + + def check(self, dev, image, step): + """step 1: the running firmware checks the package and starts the loader""" + step("start", dev.id.text) + dev.link.send(UPGRADE) + time.sleep(DELAY["start"]) + served, finished, lost = self.serve(dev.link, image, FINISH_CHECK, DELAY["idle_check"], + lambda k, end: step("check", k)) + dev.link.close() + if not finished: + raise InstallError("lost" if lost else "stopped", + f"the FM-1 {'was disconnected' if lost else 'stopped answering'} after " + f"{served} requests; nothing was written") + step("loader") + time.sleep(DELAY["loader"]) + ota = self.wait_for(lambda i: i.loader, DELAY["wait_loader"]) + if not ota: + raise InstallError("noloader", "the update loader did not appear. Replug the USB cable and " + "run the install again: the FM-1 stays in update mode until it is done") + return ota + + def write(self, ota, image, step): + """step 2: the loader reads and writes the whole package, then restarts""" + step("write", 0) + ota.link.send(UPGRADE) + time.sleep(DELAY["start"]) + served, finished, lost = self.serve(ota.link, image, FINISH_WRITE, DELAY["idle_write"], + lambda k, end: step("write", min(99, end * 100 // len(image)))) + ota.link.close() + if not finished: + raise InstallError("lost" if lost else "stopped", + f"the loader {'was disconnected' if lost else 'stopped answering'} after " + f"{served} requests. Replug the USB cable and run the install again to finish") + step("write", 100) + + def verify(self, product, step): + step("reboot") + time.sleep(DELAY["reboot"]) + back = self.wait_for(lambda i: not i.loader, DELAY["wait_reboot"]) + if not back: + raise InstallError("noreturn", "the FM-1 did not come back: power-cycle it") + back.link.close() + if back.id.text != product: + raise InstallError("mismatch", f"written, but the FM-1 reports {back.id.text} (expected {product})") + step("done", back.id.text) + return back.id.text + + def install(self, dev, image, product, step=lambda *a: None): + """running firmware -> loader -> new firmware; dev from find(). A device already in + update mode only needs the write.""" + if model_of(dev.id.text) != model_of(product): + dev.link.close() + raise InstallError("model", f"the device is {dev.id.text}, the package is for {product}") + if dev.id.loader and not re.fullmatch(r"ota-FM-1_9\d\d", dev.id.text, re.I): + dev.link.close() # another firmware's loader: its image layout may differ + raise InstallError("foreign", f"the FM-1 is in the update mode of another firmware ({dev.id.text}): " + "finish that update with its own updater (M-UPGRADE), then install again") + ota = dev if dev.id.loader else self.check(dev, image, step) + self.write(ota, image, step) + return self.verify(product, step) + + +# ------------------------------------------------------------------- CLI --- + +def load_package(path, force): + try: + raw = open(path, "rb").read() + except OSError as e: + raise InstallError("badpkg", f"cannot read {path}: {e.strerror}") + product = product_of(raw) + if not re.fullmatch(r"[^_]+_\d+", product): + raise InstallError("badpkg", f"{path}: not an FM-1 package (identity {product!r})") + if LOADER_MARK not in raw and not force: + raise InstallError("badpkg", f"{path}: no Felucca update loader in this package; " + "only Felucca's own packages are installed (--force overrides)") + return product, logical_image(raw) + + +def not_found(up): + names = up.backend.input_names() + where = f"no MIDI port matching {up.port!r} answered" if up.port else "FM-1 not found" + return InstallError("notfound", f"{where} (USB data cable? another app using it?)" + f"\n MIDI inputs: {', '.join(names) if names else '(none)'}") + + +class Progress: + def __init__(self, out): + self.out, self.line = out, False + + def __call__(self, k, a=None): + if k == "check": + self.put(f"checking the package ({a} reads)") + elif k == "write": + self.put(f"writing {a:3d}%") + else: + self.end() + msg = {"start": f"starting the update on {a}", "loader": "switching to update mode", + "reboot": "restarting", "done": f"done: the FM-1 runs {a}"}[k] + print(msg, file=self.out, flush=True) + + def put(self, s): + print(f"\r{s}\033[K", end="", file=self.out, flush=True) + self.line = True + + def end(self): + if self.line: + print(file=self.out, flush=True) + self.line = False + + +def run(a, backend, out, ask): + up = Updater(backend, a.port) + if a.info: + dev = up.find() + if not dev: + raise not_found(up) + dev.link.close() + mode = "update loader (update not finished)" if dev.id.loader else "running" + print(f"{dev.id.text} [{mode}] port: {dev.name}", file=out) + return 0 + product, image = load_package(a.package, a.force) + print(f"package: {product} ({a.package})", file=out) + dev = up.find() + if not dev: + raise not_found(up) + print(f"device: {dev.id.text} ({dev.name})" + (" in update mode: the write will be finished" if dev.id.loader else ""), + file=out) + if not a.yes and not ask("Install? Do not unplug the FM-1 while writing. [y/N] "): + dev.link.close() + print("cancelled", file=out) + return 1 + prog = Progress(out) + try: + up.install(dev, image, product, prog) + finally: + prog.end() + return 0 + + +def ask_tty(prompt): + try: + return input(prompt).strip().lower() in ("y", "yes") + except EOFError: + return False + + +def main(argv=None, backend=None, out=sys.stdout, ask=ask_tty): + ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) + ap.add_argument("package", nargs="?", help="Felucca package (.fwsc)") + ap.add_argument("--info", action="store_true", help="print the identity of the connected FM-1") + ap.add_argument("--port", metavar="NAME", help="MIDI port to use (part of its name)") + ap.add_argument("--yes", action="store_true", help="do not ask for confirmation") + ap.add_argument("--force", action="store_true", help="install a package without the Felucca loader marker") + a = ap.parse_args(argv) + if bool(a.info) == bool(a.package): + ap.error("give a PACKAGE.fwsc or --info") + try: + if backend is None: + try: + backend = MidoBackend() + except ImportError: + raise InstallError("usage", "needs mido and python-rtmidi (pip install mido python-rtmidi)") + return run(a, backend, out, ask) + except InstallError as e: + print(f"error: {e}", file=sys.stderr) + return EXIT.get(e.code, 1) + except KeyboardInterrupt: + print("\ninterrupted: if the FM-1 is in update mode, run the install again to finish", file=sys.stderr) + return 130 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tools/fm1_sample_upload.py b/tools/fm1_sample_upload.py new file mode 100644 index 0000000..24c1621 --- /dev/null +++ b/tools/fm1_sample_upload.py @@ -0,0 +1,141 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-3.0-only +# Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments +"""Load WAV files into a Felucca user sample slot (USR1..USR3) over USB-MIDI. + + fm1_sample_upload.py info + fm1_sample_upload.py load SLOT NAME file.wav[:ROOT[:LO-HI]] ... (SLOT 1..3) + fm1_sample_upload.py erase SLOT + fm1_sample_upload.py build NAME OUT_PREFIX file.wav[...] ... (no device: writes OUT_PREFIX.hdr / .bin) + +Each file becomes one zone: mono, 22050 Hz, IMA ADPCM (sampleio.py, the same encoder +as the built-in sets and the web editor). ROOT is a MIDI note (default: from the file +name, C4 = 60, else 60); without LO-HI the zones split the keyboard between their roots. +A slot holds 80 KiB (about 7 s at 22050 Hz). Protocol: web/EDITOR_PROTOCOL.md, cmds 11..15. +Needs mido (and a backend such as python-rtmidi) for the device commands. +""" +import sys +import time +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent)) +import sampleio as sio # noqa: E402 + +HDR = [0x7D, 0x46, 0x4C] +RC = {1: "size", 2: "header", 3: "data CRC", 4: "flash", 5: "zones"} + + +def pack7(b): + """groups of up to 7 bytes, each preceded by their top bits""" + out = [] + for i in range(0, len(b), 7): + g = b[i:i + 7] + out.append(sum(((x >> 7) & 1) << j for j, x in enumerate(g))) + out += [x & 0x7F for x in g] + return out + + +class Link: + def __init__(self): + try: + import mido + except ImportError: + sys.exit("needs mido: pip install mido python-rtmidi") + self.mido = mido + outs = [n for n in mido.get_output_names() if "Felucca" in n] + ins = [n for n in mido.get_input_names() if "Felucca" in n] + if not outs or not ins: + sys.exit("no MIDI port named Felucca: connect the FM-1 (running Felucca) by USB") + self.o = mido.open_output(outs[0]) + self.i = mido.open_input(ins[0]) + for _ in range(3): # the first frame after opening the port can be lost + try: + self.req(1, [], 1.0) + break + except TimeoutError: + pass + + def req(self, cmd, args, timeout=3.0): + for _ in self.i.iter_pending(): + pass + self.o.send(self.mido.Message("sysex", data=HDR + [cmd] + list(args))) + t0 = time.time() + while time.time() - t0 < timeout: + for m in self.i.iter_pending(): + if m.type == "sysex" and list(m.data[:4]) == HDR + [cmd]: + return list(m.data[4:]) + time.sleep(0.002) + raise TimeoutError(f"no reply to cmd {cmd}") + + +def build(name, specs): + """specs: "file.wav[:ROOT[:LO-HI]]" -> (header, ADPCM data) for SMP_END / SMP_WRITE""" + zones = [] + for spec in specs: + parts = spec.split(":") + # Keep a Windows drive prefix separate from the optional :ROOT:LO-HI suffix. + if len(parts) > 1 and len(parts[0]) == 1 and parts[0].isalpha() and parts[1].startswith(("/", "\\")): + parts = [parts[0] + ":" + parts[1], *parts[2:]] + path = Path(parts[0]) + root = int(parts[1]) if len(parts) > 1 and parts[1] else sio.note_from_name(path.stem) + lo, hi = (int(v) for v in parts[2].split("-")) if len(parts) > 2 else (None, None) + sr, x = sio.read_any_wav(path) + x = sio.resample(x, sr, sio.SLOT_RATE) + if not x: + raise ValueError(f"{path}: no audio") + zones.append((sio.to_int16(x), root, lo, hi)) + return sio.user_slot(name, zones) + + +def main(): + if len(sys.argv) < 2 or sys.argv[1] not in ("info", "load", "erase", "build"): + sys.exit(__doc__) + cmd = sys.argv[1] + if cmd in ("load", "build"): + if len(sys.argv) < 5: + sys.exit(__doc__) + try: + hdr, data = build(sys.argv[3] if cmd == "load" else sys.argv[2], sys.argv[4:]) + except (OSError, ValueError) as e: + sys.exit(f"cannot build the slot: {e}") + if cmd == "build": + Path(sys.argv[3] + ".hdr").write_bytes(hdr) + Path(sys.argv[3] + ".bin").write_bytes(data) + print(f"{sys.argv[2]}: {len(data)} B ADPCM, {hdr[6]} zones") + return + if cmd != "info": + if len(sys.argv) < 3 or sys.argv[2] not in ("1", "2", "3"): + sys.exit("SLOT is 1, 2 or 3") + slot = int(sys.argv[2]) - 1 + link = Link() + if cmd == "info": + r = link.req(15, []) + n, i = r[0], 2 + for k in range(n): + nz = r[i] + j = r.index(0, i + 1) + print(f"USR{k + 1}: {'empty' if not nz else f'{nz} zones, {bytes(r[i + 1:j]).decode()}, {r[j + 1]} KiB'}") + i = j + 2 + return + if cmd == "erase": + print("erase:", "ok" if link.req(14, [slot], 10)[1] == 0 else "FAILED") + return + print(f"USR{slot + 1} {sys.argv[3]}: {len(data)} B ADPCM, {hdr[6]} zones") + if link.req(11, [slot])[1]: + sys.exit("begin failed") + t0 = time.time() + for off in range(0, len(data), 256): + a = sio.SLOT_DATA_OFF + off + r = link.req(12, [slot, a & 0x7F, (a >> 7) & 0x7F, (a >> 14) & 0x7F] + pack7(data[off:off + 256])) + if r[4]: + sys.exit(f"write at {a:#x} failed ({r[4]})") + print(f"\r {min(off + 256, len(data))} / {len(data)}", end="", flush=True) + r = link.req(13, [slot] + pack7(hdr), 5) + print(f"\n {time.time() - t0:.1f} s, end:", "ok" if r[1] == 0 else f"FAILED ({r[1]}, {RC.get(r[1], '?')})") + + +if __name__ == "__main__": + try: + main() + except TimeoutError as e: + sys.exit(f"{e}: is Felucca running, and no other app using its MIDI port?") diff --git a/tools/fm1pkg_make.py b/tools/fm1pkg_make.py new file mode 100644 index 0000000..200ee89 --- /dev/null +++ b/tools/fm1pkg_make.py @@ -0,0 +1,206 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-3.0-only +# Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments +"""Build an FM-1 update package (.fwsc) from the Felucca app and update loader. + + flash.bin head [0, 0x4000): flash header (JieLi SDK default values), JLFS + entries, the SDK SPL (uboot.boot, Apache-2.0) and an isd_config + blob that decodes to the chip key. The update loader never writes + the head. + app area 0x4000..: app_area_head, app.bin, the SDK cfg_tool.bin and + eq_cfg_hw.bin, the region descriptors; SFC-encrypted with the chip key + ota.bin the Felucca update loader (firmware/loader) + +The SDK files come from the JieLi AC79 SDK (AC79_SDK, or --sdk). +All integrity checks in the format are CRC16 (poly 0x1021, init 0). + + fm1pkg_make.py APP.bin OTA.bin OUT.fwsc [--product FM-1_9XY] [--sdk DIR] +""" +import argparse +import os +import struct +from pathlib import Path + +APP_SLOT = 0x8DFBC +FLASH_SIZE = 0x93000 +KEY = 0x980F +# flash header: JieLi SDK defaults (burner_size 544, VID "0.01", flash_size 0xFF000, +# fs_ver 0x10, PID "AC791N_STORY"), plain, without its CRC +FLASH_HDR = bytes.fromhex("20022f104cc900f00f001010a4ff4e5d0b41e0cd781dc856417fb367cf9f") +UFW_CHIP = b"AC791N" +SDK = None + + +def _crc_table(): + t = [] + for i in range(256): + c = i << 8 + for _ in range(8): + c = ((c << 1) ^ 0x1021) if c & 0x8000 else (c << 1) + t.append(c & 0xFFFF) + return t + + +_T = _crc_table() + + +def crc16(data, crc=0): + for b in data: + crc = ((crc << 8) & 0xFFFF) ^ _T[((crc >> 8) ^ b) & 0xFF] + return crc + + +def enc(buf, off, size, key=0xFFFF): + """JieLi ENC stream cipher (in place)""" + for i in range(size): + buf[off + i] ^= key & 0xFF + key = ((key << 1) ^ (0x1021 if key & 0x8000 else 0)) & 0xFFFF + + +def sfc(buf, off, size, base, key): + """SFC cipher: ENC per 32-byte block, key mixed with the block address""" + for i in range(0, size, 32): + enc(buf, off + i, min(size - i, 32), key ^ ((off + i - base) >> 2)) + + +def chipkey_decode(d): + """chip key from the 32-byte isd_config blob""" + thesum = sum(d[:16]) & 0xFF + thesum = 0xAA if thesum >= 0xE0 else 0x55 if thesum <= 0x10 else thesum + return sum(1 << i for i in range(16) if (d[16 + i] ^ d[15 - i]) < thesum) + + +def entry(dcrc, offset, size, flags, resvd, index, name, fill=0xFF): + if isinstance(name, bytes): # 16 raw bytes: name + the packer's trailing fields + nm = name + else: + nm = name.encode() + b"\0" + nm = nm + bytes([fill]) * (16 - len(nm)) + body = struct.pack(" threshold 0x55 + for i in range(16): + d[16 + i] = d[15 - i] ^ (0x00 if key >> i & 1 else 0xFF) + assert chipkey_decode(bytes(d)) == key + return bytes(d) + struct.pack(" APP_SLOT: + raise SystemExit(f"app is {len(app)} B, the slot is {APP_SLOT} B") + app = app + b"\xFF" * (APP_SLOT - len(app)) + blk = 0x120 + APP_SLOT + len(cfg_tool) # app_area_head block size + area = bytearray(b"\xFF" * blk) + area[0x120:0x120 + APP_SLOT] = app + area[0x120 + APP_SLOT:blk] = cfg_tool + ents = [entry(crc16(app), 0x120, APP_SLOT, 0x82, 0xFF, 0, "app.bin"), + entry(crc16(cfg_tool), 0x120 + APP_SLOT, len(cfg_tool), 0x82, 0xFF, 0, "cfg_tool.bin"), + # region descriptors; the bytes after the names are SDK packer fields (VM size, "CODE", "AUTO") + entry(0xFFFF, 0x93000, 352256, 0x12, 0x80, 0, bytes.fromhex("564d00ffffffffffffffffff00800000")), + entry(0xFFFF, 0, FLASH_SIZE, 0x92, 0x82, 0, bytes.fromhex("5052435400ffffffffffffff434f4445")), + entry(0xFFFF, 0xE9000, 0x1000, 0x92, 0x80, 0, bytes.fromhex("4254494600ffffffffffffff4155544f")), + entry(0xFFFF, 0xEA000, 0x12000, 0x92, 0x81, 1, "USR")] + area[32:32 + len(b"".join(ents))] = b"".join(ents) + area[0:32] = entry(crc16(area[32:blk]), 0x02000120, blk, 0x83, 0xFF, 0, "app_area_head") + # nested cfg directory right after the block: SDK default EQ table + eq_e = entry(crc16(eq), 0x40, len(eq), 0x82, 0xFF, 1, "eq_cfg_hw.bin") + cfg_body = eq_e + eq + cfg = entry(crc16(cfg_body), 0x20, 0x20 + len(cfg_body), 0x83, 0xFF, 1, "cfg") + cfg_body + region = bytearray(area + cfg) + sfc(region, 0, len(region), 0, key) + f[0x4000:0x4000 + len(region)] = region + return bytes(f) + + +def ufw(flash, ota, product): + files = [(0, "flash.bin", flash), (100, "ota.bin", ota)] + off, ents, data = 0x400, [], bytearray() + for i, (typ, name, d) in enumerate(files): + off = (off + 0xFF) & ~0xFF + e = bytearray(0x50) + struct.pack_into(" 20 or any((ord(c) + i + 1) & 0xFF == 0x7D for i, c in enumerate(product)): + raise SystemExit(f"product {product!r}: at most 20 characters, none encoding to the unused marker") + raw = bytearray() + for i in range(20): + ch = product[i] if i < len(product) else None + m = (ord(ch) + i + 1) & 0xFF if ch else 0x7D + raw += logical[i * 0x2F:(i + 1) * 0x2F] + bytes([m]) + raw += logical[20 * 0x2F:] + return bytes(raw) + + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("app", type=Path) + ap.add_argument("ota", type=Path) + ap.add_argument("out", type=Path) + ap.add_argument("--product", default="FM-1_900") + ap.add_argument("--key", type=lambda s: int(s, 0), default=KEY) + ap.add_argument("--sdk", type=Path, help="JieLi AC79 SDK checkout (default: $AC79_SDK)") + a = ap.parse_args() + global SDK + SDK = a.sdk + pkg = ufw(flash_image(a.app.read_bytes(), a.key), a.ota.read_bytes(), a.product) + a.out.write_bytes(pkg) + print(f"package {a.out}: {len(pkg)} B, identity {a.product}, chip key {a.key:#06x}") + + +if __name__ == "__main__": + main() diff --git a/tools/gen_builtin_hiphop.py b/tools/gen_builtin_hiphop.py new file mode 100644 index 0000000..301e557 --- /dev/null +++ b/tools/gen_builtin_hiphop.py @@ -0,0 +1,110 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-3.0-only +"""The SAMPLE engine's built-in sets, hip-hop edition: writes the WAVs gen_samples.py builds into +the firmware, under assets/samples-cc0// (all CC0; CREDITS.txt next to them). + + python tools/gen_builtin_hiphop.py (numpy, scipy, soundfile; fetches the sources once) + +Sets (gen_samples.py CC0_SETS gives their order and kind): + DUSTY a dusty upright piano (VCSL Upright Piano, Knight) + BASS jazz upright bass, pizz (VSCO-2 CE Solo Contrabass) - two octaves under the keys + VIBES vibraphone, hard mallets (VCSL) + HORNS trumpet + trombone stabs (VSCO-2 CE) + STRGS violin + viola stabs (VSCO-2 CE) + FLUTE kept as it was (VSCO-2 CE, tools/fetch_cc0.py) + SCRCH scratch, backspin, rewind (Sonic Pi sample set, CC0) +Every file is named NN__m.wav: gen_samples.py takes the root from _m. +The chain (retune to A440, then the "dusty" record / old sampler colour) is gen_hiphop_pack.py's. +""" +import shutil +import sys +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent)) +import gen_hiphop_pack as g # noqa: E402 + +CC0 = g.ROOT / "assets" / "samples-cc0" + +# set: (zones [(MIDI root it sounds at, seconds)], builder, chain, transpose of the stored root) +SETS = { + "DUSTY": ([(48, 1.0), (57, 1.0), (66, 1.0), (75, 1.0)], g.UPR, dict(lp=9500, drive=1.3, warm=2.0, wow=0.0008), 0), + "BASS": ([(28, 0.9), (35, 0.9), (42, 0.9), (49, 0.85)], g.CB, dict(lp=4500, drive=1.8, warm=3.0, wow=0.0), 24), + "VIBES": ([(53, 1.0), (62, 1.0), (71, 1.0)], g.VIB, dict(lp=10000, drive=1.2, warm=1.0), 0), + "HORNS": ([(55, 0.6), (62, 0.6), (69, 0.6), (76, 0.6)], + g.section((g.TPT, 0, 1.0), (g.TBN, 12, 0.75)), dict(lp=9500, drive=2.2, warm=1.5), 0), + "STRGS": ([(55, 0.6), (64, 0.6), (73, 0.6)], + g.section((g.VLN, 0, 1.0), (g.VLA, 12, 0.7)), dict(lp=10000, drive=1.8, warm=1.5), 0), +} +SCRATCH = [("vinyl_scratch", 57, 0.8), ("vinyl_backspin", 65, 0.8), ("vinyl_rewind", 72, 1.0)] + +CREDITS = """Samples in the SAMPLE engine's built-in sets. All CC0 1.0 (public domain). + +DUSTY VCSL (Versilian Community Sample Library), Upright Piano (Knight) +VIBES VCSL, Vibraphone (hard mallets) https://github.com/sgossner/VCSL +BASS VSCO-2 Community Edition, Solo Contrabass pizzicato +HORNS VSCO-2 Community Edition, Trumpet + Tenor Trombone staccato +STRGS VSCO-2 Community Edition, Violin + Viola sections spiccato +FLUTE VSCO-2 Community Edition, Flute (susvib) https://github.com/sgossner/VSCO-2-CE +SCRCH Sonic Pi sample set (freesound.org CC0 recordings): vinyl_scratch (hello_flowers), + vinyl_backspin (il112), vinyl_rewind (TasmanianPower) + https://github.com/sonic-pi-net/sonic-pi/tree/main/etc/samples +KIT VCSL hand percussion (tambourine, shaker, conga, claves, woodblock) for the GM kit + +Thanks to Versilian Studios / Sam Gossner and to the Sonic Pi project. +Retuned, cut and coloured by tools/gen_builtin_hiphop.py (gen_hiphop_pack.py's chain). +""" + + +ATT_HEAD = """SLOOP SAMPLE engine - built-in sets: source material +Licence: CC0 1.0 Universal (public domain dedication) + https://creativecommons.org/publicdomain/zero/1.0/ +Sources: + VSCO-2 Community Edition https://github.com/sgossner/VSCO-2-CE (Versilian Studios, CC0-1.0) + VCSL https://github.com/sgossner/VCSL (Versilian Studios, CC0-1.0) + Sonic Pi sample set https://github.com/sonic-pi-net/sonic-pi/tree/main/etc/samples (CC0, freesound.org) +Each file is retuned, cut and coloured (tools/gen_builtin_hiphop.py) from: + +""" + + +def main(): + used, real = [], g.source + + def source(url, nominal, target): # (records what each file is made of) + used.append(url[len(g.RAW):]) + return real(url, nominal, target) + g.source = source + att = [] + for old in ("PIANO", "TRANH", "SAX"): # (TRANH and SAX are gone; PIANO is new) + shutil.rmtree(CC0 / old, ignore_errors=True) + total = 0 + for name, (zones, make, chain, tr) in SETS.items(): + d = CC0 / name + shutil.rmtree(d, ignore_errors=True) + print(name) + for k, (root, sec) in enumerate(zones): + used.clear() + x = g.shape(g.dusty(make(root), seed=k, **chain), sec, fade=0.25) + fn = f"{k:02d}_{g.note_name(root).replace('#', 's')}_m{root + tr}.wav" + g.write(d / fn, x) + att.append(f"{name}/{fn} <- " + " + ".join(used)) + total += len(x) + d = CC0 / "SCRCH" + shutil.rmtree(d, ignore_errors=True) + print("SCRCH") + for k, (src, root, sec) in enumerate(SCRATCH): + x, sr = g.load(g.SONICPI + f"{src}.flac") + x = g.to_rate(x[g.onset(x):], sr) + x = g.shape(g.dusty(x, lp=11000, drive=1.4, warm=1.5, wow=0.0, seed=k), sec, fade=0.15) + g.write(d / f"{k:02d}_{src}_m{root}.wav", x) + att.append(f"SCRCH/{k:02d}_{src}_m{root}.wav <- sonic-pi-net/sonic-pi/main/etc/samples/{src}.flac") + total += len(x) + (CC0 / "CREDITS.txt").write_text(CREDITS, encoding="utf-8") + keep = [ln for ln in (CC0 / "ATTRIBUTION.txt").read_text(encoding="utf-8").splitlines() + if ln.startswith(("FLUTE/", "KIT/"))] if (CC0 / "ATTRIBUTION.txt").exists() else [] + (CC0 / "ATTRIBUTION.txt").write_text(ATT_HEAD + "\n".join(att + keep) + "\n", encoding="utf-8") + print(f"built-in sets: {total / g.RATE:.1f} s written (FLUTE and KIT kept)") + + +if __name__ == "__main__": + main() diff --git a/tools/gen_drumkits.py b/tools/gen_drumkits.py new file mode 100644 index 0000000..2f14e33 --- /dev/null +++ b/tools/gen_drumkits.py @@ -0,0 +1,290 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-3.0-only +"""Synthesised drum kits for firmware/src/drum_synth.c -> felucca_drumkits.h + +Each kit has 14 sounds (lanes): KICK SNARE CLAP CHH OHH TOMLO TOMHI CRASH RIDE SHAKER +CONGA RIM COWBELL CLAVE. A sound is written in musical units (Hz, ms) and converted to +the table indices the firmware uses (MIDI note, DECAY_K and CUTOFF_HZ indices). + + tools/gen_drumkits.py OUT.h +""" +import copy +import math +import sys +from pathlib import Path + +LANES = ["KICK", "SNARE", "CLAP", "CHH", "OHH", "TOMLO", "TOMHI", "CRASH", "RIDE", "SHAKER", + "CONGA", "RIM", "COWBELL", "CLAVE"] +WAVE = {None: 0, "sine": 1, "tri": 2, "square": 3, "fm": 4, "bell": 5} +SRC = {None: 0, "white": 1, "metal": 2, "cym": 3, "chip": 4, "clap": 0x11} + + +def note(hz): + return max(0, min(127, int(round(69 + 12 * math.log2(hz / 440.0))))) + + +def dec(ms): # DECAY_K: 5 ms .. 4 s, index 0..127 + ms = max(5.0, min(4000.0, ms)) + return int(round(127 * math.log(ms / 5.0) / math.log(800))) + + +def cut(hz): # CUTOFF_HZ: 30 Hz .. 16 kHz + hz = max(30.0, min(16000.0, hz)) + return int(round(127 * math.log(hz / 30.0) / math.log(16000 / 30))) + + +def S(wave=None, hz=100, bend=0, bt=20, decay=100, tlev=110, src=None, nlev=0, ndec=50, + lpf=None, hpf=None, drive=0, chip=None): + return dict(wave=wave, hz=hz, bend=bend, bt=bt, decay=decay, tlev=tlev, src=src, nlev=nlev, + ndec=ndec, lpf=lpf, hpf=hpf, drive=drive, chip=chip) + + +def enc(s): + lpf = 127 if s["lpf"] is None else cut(s["lpf"]) + if s["src"] == "chip": + lpf = s["chip"] if s["chip"] is not None else 100 # CHIP: clock note + return [WAVE[s["wave"]], SRC[s["src"]], note(s["hz"]), int(s["bend"]), dec(s["bt"]), dec(s["decay"]), + int(s["tlev"]) if s["wave"] else 0, int(s["nlev"]) if s["src"] else 0, dec(s["ndec"]), lpf, + 0 if s["hpf"] is None else cut(s["hpf"]), int(s["drive"])] + + +def kit(base, **mods): + k = copy.deepcopy(base) + for lane, ch in mods.items(): + if isinstance(ch, dict) and "wave" in ch: + k[lane] = ch + else: + k[lane].update(ch) + return k + + +# ---- base kits --------------------------------------------------------------------------- +K808 = dict( + KICK=S("sine", 49, 26, 45, 750, 122, "white", 22, 4, 3000), + SNARE=S("tri", 180, 4, 20, 110, 80, "white", 92, 170, 9000, 1500), + CLAP=S(None, src="clap", nlev=122, ndec=210, lpf=2400, hpf=800), + CHH=S(None, 205, src="metal", nlev=118, ndec=45, hpf=7000), + OHH=S(None, 205, src="metal", nlev=112, ndec=380, hpf=6500), + TOMLO=S("sine", 98, 5, 60, 380, 115, "white", 14, 25, 2000), + TOMHI=S("sine", 147, 5, 60, 320, 112, "white", 14, 25, 2500), + CRASH=S(None, 205, src="cym", nlev=104, ndec=1700, hpf=4500), + RIDE=S(None, 260, src="metal", nlev=112, ndec=1100, lpf=12000, hpf=3500), + SHAKER=S(None, src="white", nlev=84, ndec=55, hpf=6000), + CONGA=S("sine", 310, 3, 25, 200, 112), + RIM=S("tri", 1700, 0, 5, 22, 92, "white", 50, 5, None, 2500), + COWBELL=S("bell", 540, 0, 5, 280, 104, lpf=4000, hpf=500), + CLAVE=S("sine", 2500, 0, 5, 45, 104), +) +K909 = kit(K808, + KICK=S("sine", 55, 36, 28, 320, 122, "white", 70, 7, 6000, None, 40), + SNARE=S("sine", 190, 7, 15, 110, 88, "white", 115, 230, 12000, 1000, 20), + CLAP=dict(nlev=124, ndec=260, lpf=2600, hpf=900), + CHH=S(None, 230, src="cym", nlev=112, ndec=55, hpf=8000), + OHH=S(None, 230, src="cym", nlev=108, ndec=420, hpf=7500), + TOMLO=S("sine", 110, 10, 40, 300, 115, "white", 26, 30, 3000), + TOMHI=S("sine", 165, 10, 40, 260, 112, "white", 26, 30, 3500), + CRASH=S(None, 250, src="cym", nlev=106, ndec=1900, hpf=5000), + RIDE=S(None, 300, src="cym", nlev=110, ndec=1400, lpf=13000, hpf=4000), + RIM=S("tri", 1900, 2, 4, 18, 96, "white", 70, 6, None, 3000), +) +K606 = kit(K808, + KICK=S("sine", 60, 18, 30, 190, 122, "white", 30, 4, 4000), + SNARE=S("tri", 220, 3, 10, 70, 70, "white", 102, 120, 10000, 2500), + CHH=S(None, 260, src="metal", nlev=114, ndec=30, hpf=9000), + OHH=S(None, 260, src="metal", nlev=108, ndec=200, hpf=8500), + TOMLO=S("sine", 150, 4, 30, 180, 112), + TOMHI=S("sine", 220, 4, 30, 160, 110), + CRASH=S(None, 300, src="metal", nlev=100, ndec=900, hpf=6000), +) +KCR78 = kit(K808, + KICK=S("sine", 65, 8, 20, 160, 118, lpf=2000), + SNARE=S("sine", 240, 2, 10, 60, 70, "white", 72, 90, 6000, 2000), + CLAP=S(None, src="white", nlev=90, ndec=140, lpf=8000, hpf=4000), # tambourine-ish + CHH=S(None, 280, src="metal", nlev=106, ndec=25, hpf=9000), + OHH=S(None, 280, src="metal", nlev=100, ndec=160, hpf=8500), + TOMLO=S("sine", 180, 2, 20, 160, 110), + TOMHI=S("sine", 260, 2, 20, 140, 108), + SHAKER=S(None, src="white", nlev=90, ndec=30, hpf=7000), + CONGA=S("sine", 400, 2, 15, 120, 110), + RIM=S("sine", 1600, 0, 5, 30, 100), + COWBELL=S("bell", 800, 0, 5, 160, 100, lpf=5000, hpf=800), +) +KLINN = kit(K808, + KICK=S("sine", 58, 20, 22, 240, 122, "white", 60, 6, 5000, None, 20), + SNARE=S("tri", 200, 6, 15, 120, 86, "white", 112, 260, 10000, 900, 30), + CLAP=dict(nlev=124, ndec=300, lpf=2800), + CHH=S(None, 240, src="cym", nlev=104, ndec=40, hpf=8000), + OHH=S(None, 240, src="cym", nlev=100, ndec=300, hpf=7500), + TOMLO=S("sine", 90, 12, 80, 500, 118, "white", 20, 40, 2500), + TOMHI=S("sine", 140, 12, 80, 420, 115, "white", 20, 40, 3000), +) +KCHIP = dict( + KICK=S("square", 70, 30, 40, 120, 104), + SNARE=S("square", 220, 12, 20, 40, 60, "chip", 106, 130, chip=100), + CLAP=S(None, src="chip", nlev=108, ndec=110, chip=108), + CHH=S(None, src="chip", nlev=96, ndec=30, chip=124), + OHH=S(None, src="chip", nlev=92, ndec=220, chip=122), + TOMLO=S("square", 110, 14, 80, 160, 100), + TOMHI=S("square", 165, 14, 80, 140, 100), + CRASH=S(None, src="chip", nlev=96, ndec=900, chip=112), + RIDE=S("square", 1500, 0, 5, 300, 50, "chip", 60, 200, chip=126), + SHAKER=S(None, src="chip", nlev=84, ndec=45, chip=127), + CONGA=S("tri", 330, 5, 30, 120, 110), + RIM=S("square", 1200, 0, 5, 25, 90), + COWBELL=S("square", 700, 0, 5, 150, 90), + CLAVE=S("square", 2000, 0, 5, 35, 90), +) +KFM = dict( + KICK=S("fm", 55, 40, 30, 220, 120, drive=30), + SNARE=S("fm", 200, 18, 20, 90, 90, "white", 90, 140, 9000, 1500), + CLAP=S(None, src="clap", nlev=118, ndec=180, lpf=3000, hpf=1000), + CHH=S("fm", 4200, 0, 5, 30, 70, "white", 70, 30, None, 8000), + OHH=S("fm", 4200, 0, 5, 220, 64, "white", 64, 220, None, 7000), + TOMLO=S("fm", 120, 30, 120, 260, 110), + TOMHI=S("fm", 200, 30, 120, 220, 108), + CRASH=S("fm", 900, 0, 5, 1200, 50, "cym", 90, 1300, None, 4000), + RIDE=S("fm", 1300, 0, 5, 900, 60, "metal", 50, 700, 9000, 5000), + SHAKER=S(None, src="white", nlev=80, ndec=50, hpf=6000), + CONGA=S("fm", 330, 12, 40, 160, 108), + RIM=S("fm", 1500, 4, 5, 25, 96), + COWBELL=S("fm", 600, 0, 5, 200, 96), + CLAVE=S("fm", 2300, 0, 5, 40, 100), +) + +KITS = [ + ("808", "HIP HOP", 0, K808), + ("909", "HOUSE", 0, K909), + ("606", "ACID", 0, K606), + ("VINTAGE", "RHYTHM BOX", 0, KCR78), + ("80S", "80S POP", 0, KLINN), + ("TRAP", "TRAP", 0, kit(K808, + KICK=dict(hz=46, bend=30, bt=60, decay=1300, drive=34), + SNARE=S("tri", 200, 5, 10, 90, 70, "white", 110, 150, 12000, 2200, 20), + CLAP=dict(nlev=126, ndec=170, lpf=3000, hpf=1100), + CHH=dict(ndec=24, hpf=9000), OHH=dict(ndec=260))), + ("DRILL", "UK DRILL", 0, kit(K808, + KICK=dict(hz=44, bend=12, bt=200, decay=1600, drive=40), + SNARE=S("tri", 270, 8, 8, 60, 84, "white", 104, 110, 12000, 2500, 30), + CHH=dict(ndec=28, hpf=8500), RIM=dict(hz=2000, decay=30, tlev=104))), + ("BOOMBAP", "HIP HOP", 0x13, kit(K909, + KICK=dict(decay=260, drive=70, nlev=80), + SNARE=S("tri", 175, 5, 15, 130, 92, "white", 110, 200, 5000, 700, 50), + CHH=dict(ndec=40, hpf=6000), OHH=dict(ndec=260, hpf=5500))), + ("LO-FI", "LO-FI", 0x34, kit(K808, + KICK=dict(decay=420, lpf=1500, tlev=114), + SNARE=dict(lpf=4500, hpf=900, ndec=150), + CLAP=dict(lpf=1800, hpf=600), + CHH=dict(hpf=4000, nlev=90), OHH=dict(hpf=3800, nlev=86), + CRASH=dict(hpf=3000, nlev=80), RIDE=dict(lpf=6000, hpf=3000, nlev=70))), + ("HOUSE", "HOUSE", 0, kit(K909, + KICK=dict(decay=360, drive=30), OHH=dict(ndec=300, nlev=112), + CLAP=dict(nlev=126, ndec=320), SHAKER=dict(ndec=70, nlev=90))), + ("TECHNO", "TECHNO", 0, kit(K909, + KICK=dict(hz=50, bend=30, bt=24, decay=420, drive=95), + CHH=dict(ndec=35, hpf=9500), OHH=dict(ndec=280, hpf=9000), + RIDE=dict(nlev=96, ndec=900), RIM=dict(drive=40), + CLAP=dict(ndec=200, lpf=2200))), + ("MINIMAL", "MINIMAL", 0, kit(K808, + KICK=S("sine", 60, 20, 10, 150, 122, "white", 50, 3, 7000), + SNARE=S("tri", 1100, 0, 5, 18, 90, "white", 60, 25, None, 3000), + CLAP=dict(ndec=90), CHH=dict(ndec=18, hpf=10000), OHH=dict(ndec=120), + CONGA=dict(decay=90, hz=420), RIM=dict(decay=12))), + ("ELECTRO", "ELECTRO", 0, kit(K808, + KICK=dict(bend=40, bt=70, decay=500), + SNARE=dict(ndec=120, hpf=2000), + TOMLO=S("fm", 130, 30, 120, 240, 110), TOMHI=S("fm", 220, 30, 120, 200, 108), + CHH=K606["CHH"], OHH=K606["OHH"])), + ("JUNGLE", "DRUM & BASS", 0, kit(K909, + KICK=dict(decay=200, drive=50), + SNARE=S("tri", 260, 9, 10, 90, 92, "white", 112, 160, 12000, 1500, 40), + CHH=dict(ndec=30), RIDE=dict(nlev=92))), + ("DUBSTEP", "BASS MUSIC", 0, kit(K909, + KICK=dict(hz=48, decay=420, drive=60), + SNARE=S("tri", 170, 8, 20, 160, 96, "white", 120, 420, 9000, 600, 60), + CLAP=dict(ndec=380), OHH=dict(ndec=300))), + ("DEMBOW", "REGGAETON", 0, kit(K808, + KICK=dict(decay=520, drive=20), + SNARE=S("tri", 230, 5, 10, 80, 84, "white", 100, 130, 11000, 1800, 20), + CLAP=dict(ndec=160), RIM=dict(tlev=104), SHAKER=dict(ndec=70, nlev=96))), + ("AFRO", "AFROBEAT", 0, kit(K808, + KICK=S("sine", 60, 10, 30, 260, 118, lpf=2000), + SNARE=S("tri", 330, 3, 10, 60, 92, "white", 70, 60, 9000, 2500), + CONGA=dict(decay=260, bend=2), TOMLO=S("sine", 160, 2, 20, 260, 112), + TOMHI=S("sine", 230, 2, 20, 220, 110), SHAKER=dict(ndec=80, nlev=100), + COWBELL=dict(hz=900, decay=180))), + ("LATIN", "LATIN", 0, kit(KCR78, + KICK=S("sine", 62, 6, 20, 220, 114, lpf=1800), + TOMLO=S("sine", 200, 3, 15, 200, 112, "white", 20, 15, 4000), # timbales + TOMHI=S("sine", 300, 3, 15, 180, 112, "white", 20, 15, 4500), + CONGA=dict(hz=330, decay=240), COWBELL=dict(hz=650, decay=240), + CLAVE=dict(hz=2400, decay=55))), + ("DISCO", "DISCO", 0, kit(K909, + KICK=dict(decay=260, drive=20), + OHH=dict(ndec=520, nlev=114), + TOMLO=S("sine", 120, 24, 300, 600, 116), TOMHI=S("sine", 180, 24, 300, 520, 114))), + ("SYNTHWV", "SYNTHWAVE", 0, kit(KLINN, + SNARE=dict(ndec=340, drive=50, nlev=118), + TOMLO=S("sine", 85, 18, 160, 600, 118, "white", 24, 50, 2500), + TOMHI=S("sine", 130, 18, 160, 520, 116, "white", 24, 50, 3000))), + ("CHIP", "CHIPTUNE", 0x04, KCHIP), + ("8BIT", "HANDHELD", 0x26, kit(KCHIP, KICK=dict(decay=160), SNARE=dict(ndec=160))), + ("ARCADE", "VIDEO GAME", 0x02, KFM), + ("GLITCH", "GLITCH", 0x25, kit(KFM, + KICK=dict(decay=120, bt=12), SNARE=S(None, src="chip", nlev=112, ndec=70, chip=96), + CHH=S(None, src="chip", nlev=100, ndec=15, chip=127), OHH=S(None, src="chip", nlev=96, ndec=90, chip=125), + CLAP=dict(ndec=80), TOMLO=dict(bt=40, decay=120), TOMHI=dict(bt=40, decay=100))), + ("INDUSTR", "INDUSTRIAL", 0x02, kit(K909, + KICK=dict(drive=127, decay=380), SNARE=dict(drive=110, ndec=260), + CLAP=dict(nlev=127, ndec=280), CHH=dict(src="metal", ndec=60), OHH=dict(src="metal", ndec=500), + TOMLO=S("fm", 90, 24, 200, 400, 118, drive=100), TOMHI=S("fm", 140, 24, 200, 340, 116, drive=100), + CRASH=dict(src="metal", ndec=2200, nlev=118))), + ("TRIBAL", "TRIBAL", 0, kit(K808, + KICK=S("sine", 52, 14, 60, 600, 122, "white", 30, 10, 1500), + SNARE=S("sine", 160, 6, 30, 260, 110, "white", 40, 60, 3000), + TOMLO=S("sine", 75, 8, 90, 600, 120, "white", 26, 30, 1500), + TOMHI=S("sine", 115, 8, 90, 520, 118, "white", 26, 30, 2000), + CHH=S(None, src="white", nlev=86, ndec=40, hpf=5000), + OHH=S(None, src="white", nlev=90, ndec=160, hpf=4000), + CONGA=dict(decay=320))), + ("HYPER", "HYPERPOP", 0, kit(K909, + KICK=dict(drive=110, decay=380, bend=44), + SNARE=S("tri", 300, 10, 10, 90, 100, "white", 120, 180, 14000, 2000, 80), + CLAP=dict(nlev=127, ndec=240, hpf=1300), + CHH=dict(hpf=10000, ndec=30), OHH=dict(hpf=9500))), + ("AMBIENT", "AMBIENT", 0, kit(K808, + KICK=dict(tlev=100, decay=900, nlev=0, lpf=800), + SNARE=dict(lpf=3500, ndec=420, nlev=70, tlev=60), + CLAP=dict(lpf=1500, ndec=500, nlev=90), + CHH=dict(nlev=70, ndec=70, hpf=6000), OHH=dict(nlev=70, ndec=900), + CRASH=dict(nlev=80, ndec=3500), RIDE=dict(nlev=60, ndec=2500, lpf=7000))), + ("JAZZ", "JAZZ", 0, kit(K808, + KICK=S("sine", 62, 8, 20, 220, 96, "white", 30, 8, 1200), + SNARE=S("tri", 210, 2, 10, 60, 40, "white", 90, 320, 5000, 1500), # brushes + CHH=S(None, 300, src="cym", nlev=80, ndec=60, lpf=9000, hpf=5000), + OHH=S(None, 300, src="cym", nlev=80, ndec=500, lpf=9000, hpf=4500), + RIDE=S(None, 320, src="cym", nlev=86, ndec=2400, lpf=8000, hpf=3500), + TOMLO=S("sine", 110, 3, 30, 400, 104, "white", 16, 40, 2000), + TOMHI=S("sine", 160, 3, 30, 340, 102, "white", 16, 40, 2500))), +] + + +def main(path): + L = ["/* generated by tools/gen_drumkits.py */", "#pragma once", + f"#define DS_NKITS {len(KITS)}u", "static const dkit_t DS_KITS[DS_NKITS] = {"] + for name, style, crush, k in KITS: + assert len(name) <= 8 and len(style) <= 12, name + L.append(f' {{"{name}", "{style}", 0x{crush:02X}, {{') + for lane in LANES: + v = enc(k[lane]) + assert all(0 <= x <= 127 for x in v[2:]) and len(v) == 12, (name, lane, v) + L.append(" {" + ", ".join(str(x) for x in v) + f"}}, /* {lane} */") + L.append(" }},") + L.append("};") + L.append("#define DS_KIT_NAME_LIST " + ", ".join(f'"{k[0]}"' for k in KITS)) + L.append("#define DS_KIT_STYLE_LIST " + ", ".join(f'"{k[1]}"' for k in KITS)) + Path(path).write_text("\n".join(L) + "\n") + print(f"drum kits: {len(KITS)} synthesised -> {path}") + + +if __name__ == "__main__": + main(sys.argv[1]) diff --git a/tools/gen_font.py b/tools/gen_font.py new file mode 100644 index 0000000..ac812f6 --- /dev/null +++ b/tools/gen_font.py @@ -0,0 +1,150 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-3.0-only +# Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments +"""Render the bitmap fonts to a C header (assets/fonts/): + S labels / units / status Latin-1 32..255 at 1x + L large values / titles 32..95 (digits, signs, capitals), the same glyphs at 2x +Terminus 8x16 (BDF, SIL OFL 1.1). TTF fonts also work through render() +(anti-aliased, tabular figures via the OpenType `tnum` feature). + +Glyph format: per glyph an advance width, a bitmap width and an offset; the +bitmap starts FONT_PAD pixels left of the pen position (room for side +bearings); rows top to bottom, 2 pixels per byte (high nibble first), +alpha 0..15. +""" +import sys +from pathlib import Path + +from PIL import Image, ImageDraw, ImageFont + +FONTS = Path(__file__).resolve().parents[1] / "assets" / "fonts" +# (name, file, px, scale, pixel, first, last): pixel fonts are rendered without +# anti-aliasing at their design size and enlarged by an integer factor +SIZES = [("S", "ter-u16n.bdf", 16, 1, True, 32, 255), # Latin-1 (Hügelton needs the umlaut) + ("L", "ter-u16n.bdf", 16, 2, True, 32, 95)] # values / titles: digits, signs, capitals +PAD = 2 + + +def upscale(px_, w, h, scale): + """integer nearest-neighbour enlargement of a w x h glyph""" + if scale == 1: + return px_ + big = [] + for y in range(h): + row = [] + for x in range(w): + row += [px_[y * w + x]] * scale + big += row * scale + return big + + +def render_bdf(path, scale, first, last): + """BDF bitmap font (Terminus 8x16): exact pixels, cell = the font bounding box.""" + lines = path.read_text(errors="replace").splitlines() + fbb = next(l for l in lines if l.startswith("FONTBOUNDINGBOX")).split() + cw, ch, fx, fy = int(fbb[1]), int(fbb[2]), int(fbb[3]), int(fbb[4]) + base = ch + fy # rows above the baseline + glyphs, i = {}, 0 + while i < len(lines): + if lines[i].startswith("ENCODING"): + code = int(lines[i].split()[1]) + j = i + while not lines[j].startswith("BBX"): + j += 1 + bw, bh, bx, by = map(int, lines[j].split()[1:5]) + dw = cw + k = i + while not lines[k].startswith("BITMAP"): + if lines[k].startswith("DWIDTH"): + dw = int(lines[k].split()[1]) + k += 1 + rows = [int(r, 16) for r in lines[k + 1:k + 1 + bh]] + nbits = ((bw + 7) // 8) * 8 + cell = [0] * (cw * ch) + top = base - (by + bh) + for r, bits in enumerate(rows): + for c in range(bw): + if bits >> (nbits - 1 - c) & 1: + x, y = bx + c, top + r + if 0 <= x < cw and 0 <= y < ch: + cell[y * cw + x] = 15 + glyphs[code] = (dw, cell) + i = k + bh + i += 1 + if 0xDC not in glyphs and ord("U") in glyphs: # Ü for "HÜGELTON": U with dots on its top row + dw, cell = glyphs[ord("U")] + cell = cell[:] + lit = [x for y in range(ch) for x in range(cw) if cell[y * cw + x]] + if lit: + top = min(y for y in range(ch) for x in range(cw) if cell[y * cw + x]) + for x in range(cw): + cell[top * cw + x] = 15 if x in (min(lit), max(lit)) else 0 + for x in range(cw): + cell[(top + 1) * cw + x] = 0 + glyphs[0xDC] = (dw, cell) + missing = [chr(c) for c in range(first, min(last, 126) + 1) if c not in glyphs] + if missing: + print(f"font {path.name}: no glyph for {''.join(missing)!r} (drawn as '?')") + out = [] + for c in range(first, last + 1): + dw, cell = glyphs.get(c, glyphs[ord("?")]) + bw = cw + 2 * PAD # keep the PAD convention of the TTF path + px_ = [] + for y in range(ch): + px_ += [0] * PAD + cell[y * cw:(y + 1) * cw] + [0] * PAD + out.append((dw * scale, bw * scale, upscale(px_, bw, ch, scale))) + return ch * scale, out + + +def render(ttf, px, scale, pixel, first, last): + if ttf.endswith(".bdf"): + return render_bdf(FONTS / ttf, scale, first, last) + font = ImageFont.truetype(str(FONTS / ttf), px) + feats = None if pixel else ["tnum"] + asc, desc = font.getmetrics() + top = max(0, font.getbbox("A8|(", features=feats)[1] - 1) + h = asc + desc - top + glyphs = [] + for c in range(first, last + 1): + ch = chr(c) + adv = int(round(font.getlength(ch, features=feats))) + bw = adv + 2 * PAD + img = Image.new("L", (bw, asc + desc), 0) + ImageDraw.Draw(img).text((PAD, 0), ch, font=font, fill=255, features=feats) + img = img.crop((0, top, bw, top + h)) + px_ = [(15 if v >= 128 else 0) if pixel else min(15, (v + 8) // 17) for v in img.tobytes()] + glyphs.append((adv * scale, bw * scale, upscale(px_, bw, h, scale))) + return h * scale, glyphs + + +def main(out): + lines = [f"/* generated by tools/gen_font.py from {SIZES[0][1]} */", + "#pragma once", "#include ", f"#define FONT_PAD {PAD} /* x scale for L, see below */", ""] + for name, ttf, px, scale, pixel, first, last in SIZES: + h, glyphs = render(ttf, px, scale, pixel, first, last) + data, offs = [], [] + for adv, bw, g in glyphs: + offs.append(len(data)) + for y in range(h): + row = g[y * bw:(y + 1) * bw] + [0] + for x in range(0, bw, 2): + data.append((row[x] << 4) | row[x + 1]) + assert len(data) < 65536 + lines.append(f"static const uint8_t FONT_{name}_DATA[{len(data)}] = {{") + for i in range(0, len(data), 24): + lines.append(" " + ", ".join(f"0x{b:02x}" for b in data[i:i + 24]) + ",") + lines.append("};") + lines.append(f"static const uint16_t FONT_{name}_OFF[{len(offs)}] = {{" + ", ".join(map(str, offs)) + "};") + lines.append(f"static const uint8_t FONT_{name}_ADV[{len(glyphs)}] = {{" + + ", ".join(str(a) for a, _, _ in glyphs) + "};") + lines.append(f"static const uint8_t FONT_{name}_BW[{len(glyphs)}] = {{" + + ", ".join(str(b) for _, b, _ in glyphs) + "};") + lines.append(f"static const felucca_font_t FONT_{name} = {{ {h}, {PAD * scale}, {first}, {last}, " + f"FONT_{name}_ADV, FONT_{name}_BW, FONT_{name}_OFF, FONT_{name}_DATA }};") + lines.append("") + print(f"font {name}: {ttf} {px}px h {h}, digit adv {glyphs[ord('0') - first][0]}, {len(data)} B") + Path(out).write_text("\n".join(lines)) + + +if __name__ == "__main__": + main(sys.argv[1]) diff --git a/tools/gen_hiphop_pack.py b/tools/gen_hiphop_pack.py new file mode 100644 index 0000000..00c30ac --- /dev/null +++ b/tools/gen_hiphop_pack.py @@ -0,0 +1,330 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-3.0-only +"""Build the SLOOP HIP-HOP PACK: free sounds for the user sample slots USR1..USR3. + + python tools/gen_hiphop_pack.py (needs numpy, scipy, soundfile; network once) + +Every sound comes from a free library and is CC0 (public domain), except E.PIANO +(CC BY 3.0, credit to Greg Sullivan). See assets/hiphop-pack/CREDITS.txt. + +Each sound is a set of zones (one WAV each, mono 16-bit 22050 Hz, the rate of the +slots) written to assets/hiphop-pack//, plus assets/hiphop-pack/pack.json +(roots, key ranges) that the web editor reads to load a sound into a slot in one click +(tools/fm1_sample_upload.py loads them too). A slot holds about 7.4 s in all. + +What makes them sound like a crate-dug record (the boom-bap sound of 1988-1996: a +record sampled into an SP-1200 / MPC60) is done here, not in the firmware: every +zone is retuned to concert pitch, then goes through a "dusty" chain: high-pass, +a warm low shelf, a gentle low-pass (the record and the sampler's filter), tape-style +saturation and a little wow. The slot's own 22 kHz ADPCM adds the rest of the grit. +""" +import json +import math +import sys +import urllib.parse +import urllib.request +from pathlib import Path + +import numpy as np +import soundfile as sf +from scipy import signal + +ROOT = Path(__file__).resolve().parents[1] +OUT = ROOT / "assets" / "hiphop-pack" +CACHE = ROOT / "build" / "hiphop-src" +RATE = 22050 +SLOT_SAMPLES = (0x14000 - 512) * 2 # 4-bit ADPCM: two samples a byte (sampleio.SLOT_MAX_DATA) +SLOT_BUDGET = int(SLOT_SAMPLES * 0.97) # (a margin: the editor resamples the WAVs) + +RAW = "https://raw.githubusercontent.com/" +VSCO = RAW + "sgossner/VSCO-2-CE/master/" +VCSL = RAW + "sgossner/VCSL/master/" +WURLI = RAW + "sfzinstruments/GregSullivan.E-Pianos/master/Wurlitzer EP200/Samples/" +SONICPI = RAW + "sonic-pi-net/sonic-pi/main/etc/samples/" + +NOTE = "C C# D D# E F F# G G# A A# B".split() + + +def note_name(n): + return f"{NOTE[n % 12]}{n // 12 - 1}" + + +def fetch(url): + """the file at url (cached in build/hiphop-src) -> its path""" + p = CACHE / urllib.parse.quote(url[len(RAW):], safe="") + if not p.exists(): + CACHE.mkdir(parents=True, exist_ok=True) + q = url[:len(RAW)] + urllib.parse.quote(url[len(RAW):]) + with urllib.request.urlopen(q, timeout=120) as r: + p.write_bytes(r.read()) + print(f" fetched {url[len(RAW):]} ({p.stat().st_size // 1024} KiB)") + return p + + +def load(url): + """-> (mono float64, rate)""" + x, sr = sf.read(str(fetch(url)), dtype="float64", always_2d=True) + return x.mean(axis=1), sr + + +def onset(x, rel=0.03): + thr = rel * np.max(np.abs(x)) + i = int(np.argmax(np.abs(x) > thr)) + return max(0, i - 32) + + +def detect_midi(x, sr, guess): + """the pitch of x (fractional MIDI note), searched within +-8 semitones of guess: + YIN on 0.25 s from 60 ms after the onset (past the attack)""" + a = onset(x) + int(0.06 * sr) + w = x[a:a + int(0.25 * sr)] + if len(w) < 2048: + w = x[-int(0.25 * sr):] + fmin = 440 * 2 ** ((guess - 8 - 69) / 12) + fmax = 440 * 2 ** ((guess + 8 - 69) / 12) + W = len(w) // 2 + lo, hi = max(2, int(sr / fmax)), min(W - 2, int(sr / fmin) + 1) + d = np.array([np.sum((w[:W] - w[t:t + W]) ** 2) for t in range(hi + 2)]) + cm = np.ones_like(d) + run = np.cumsum(d[1:]) + cm[1:] = d[1:] * np.arange(1, len(d)) / np.where(run > 0, run, 1) + seg = cm[lo:hi] + t = lo + int(np.argmin(seg)) + if 1 <= t < len(cm) - 1: + y0, y1, y2 = cm[t - 1], cm[t], cm[t + 1] + den = y0 - 2 * y1 + y2 + t = t + (0.5 * (y0 - y2) / den if den else 0) + return 12 * math.log2(sr / t / 440.0) + 69 + + +def repitch(x, sr, semis): + """play x semis higher (faster) by interpolation, at sr""" + if abs(semis) < 1e-4: + return x + r = 2 ** (semis / 12) + t = np.arange(0, len(x) - 1, r) + return np.interp(t, np.arange(len(x)), x) + + +def to_rate(x, sr): + g = math.gcd(int(sr), RATE) + return signal.resample_poly(x, RATE // g, int(sr) // g) + + +def source(url, nominal, target): + """the recording at url, retuned to MIDI note target, at RATE, from its onset. The libraries + are tuned: the note of the file name is trusted, the measured pitch only trims it (a + measure further than 0.3 semitone from the name is a wrong measure: mallets, plucks)""" + x, sr = load(url) + x = x[onset(x):] + det = detect_midi(x, sr, nominal) + m = det if abs(det - nominal) <= 0.3 else nominal + y = to_rate(repitch(x, sr, target - m), sr) + print(f" {url.rsplit('/', 1)[-1]:42s} {nominal:3d} (measured {det:6.2f}) -> {note_name(target):4s} " + f"({target - m:+.2f} st)") + return y, m + + +def dusty(x, lp=9000.0, drive=1.6, warm=2.5, hp=35.0, wow=0.0012, seed=1): + """the crate-dug chain: HP, low shelf (+warm dB under ~160 Hz), 2-pole LP, tanh, wow""" + sos = signal.butter(2, hp, "highpass", fs=RATE, output="sos") + x = signal.sosfilt(sos, x) + low = signal.sosfilt(signal.butter(1, 160, "lowpass", fs=RATE, output="sos"), x) + x = x + low * (10 ** (warm / 20) - 1) + if lp: + x = signal.sosfilt(signal.butter(2, lp, "lowpass", fs=RATE, output="sos"), x) + pk = np.max(np.abs(x)) or 1.0 + x = np.tanh(drive * x / pk) / math.tanh(drive) + if wow: # a slow drift of the speed: a record, a tape + rng = np.random.default_rng(seed) + ph = rng.uniform(0, 2 * math.pi) + n = np.arange(len(x)) + dev = wow * RATE / (2 * math.pi * 0.55) * np.sin(2 * math.pi * 0.55 * n / RATE + ph) + x = np.interp(n + dev - dev[0], n, x) + return x + + +def shape(x, seconds, fade=0.3, attack=0.002): + """cut to seconds, short fade in, the last fade x length faded out (cosine)""" + n = min(len(x), int(seconds * RATE)) + x = x[:n].copy() + a = max(1, int(attack * RATE)) + x[:a] *= np.linspace(0, 1, a) + f = max(1, int(n * fade)) + x[n - f:] *= 0.5 * (1 + np.cos(np.linspace(0, math.pi, f))) + return x + + +def mix(*parts): + n = max(len(p) for p, _ in parts) + y = np.zeros(n) + for p, g in parts: + y[:len(p)] += g * p + return y + + +def write(path, x): + pk = np.max(np.abs(x)) or 1.0 + path.parent.mkdir(parents=True, exist_ok=True) + sf.write(str(path), (x / pk * 0.92 * 32767).astype(np.int16), RATE, subtype="PCM_16") + + +# ------------------------------------------------------------------ sounds --- +# zone: (target root, length s, builder(target) -> float array at RATE) + +def midi_of(name): + """"C#3" -> 49 (C4 = 60)""" + k = 2 if len(name) > 2 and name[1] == "#" else 1 + return NOTE.index(name[:k]) + (int(name[k:]) + 1) * 12 + + +def pick(base, fmt, names, offset): + """a builder for target notes from the recording nearest each one: names are the notes of + the files (fmt.format(name); "D#3:eb3" when the file spells it eb3), offset what to add to + them for MIDI (C4 = 60)""" + pool = [(midi_of(n.split(":")[0]) + offset, n.split(":")[-1]) for n in names.split()] + + def make(tgt): + m, n = min(pool, key=lambda q: (abs(q[0] - tgt), q[0])) + return source(base + fmt.format(n), m, tgt)[0] + return make + + +def section(*layers): + """layers: (builder, semitones under the target, gain), mixed from their onsets""" + return lambda tgt: mix(*[(b(tgt - down), g) for b, down, g in layers]) + + +# VSCO-2 CE and VCSL name middle C "C3": their note names are one octave under the MIDI +# names used here (offset 12). Every pick is checked against its measured pitch (source()). +WUR = pick(WURLI, "{}mp.flac", "E2:e2 A2:a2 D#3:eb3 G#3:ab3 C#4:db4 F#4:gb4 B4:b4 C#5:db5 G5:g5", 0) +TPT = pick(VSCO, "Brass/Trumpet/stac/Sum_SHTrumpet_stac_{}_v3_rr1.wav", "F2 A2 C3 D#3 F3 G3 A#3 D4 F4 A4 C5", 12) +TBN = pick(VSCO, "Brass/Tenor Trombone/stac/tenortbn_stac_{}_v3_rr1.wav", "F1 A#1 F2 A#2 D3 F3", 12) +VLN = pick(VSCO, "Strings/Violin Section/Spic/VlnEns_Spic_{}_v2_rr1.wav", + "G2 A2 B2 D3 F#3 A3 C4 E4 G4 B4 D5", 12) +VLA = pick(VSCO, "Strings/Viola Section/spic/Violas_spic_{}_v2_rr1.wav", "C2 E2 G2 B2 D3 F3 A3 C4 E4 G4", 12) +CB = pick(VSCO, "Strings/Solo Contrabass/Pizz/BKCtbss_Pizz_{}_rr1.wav", "E0:E0_v3 A#0:A#0_v3 D1:D1_v1 F#1:F#1_v1 A1:A1_v1 C#2:C#2_v1", 12) +VIB = pick(VCSL, "Idiophones/Struck Idiophones/Vibraphone/Hard Mallets/Vibes_hard_{}_v3_rr1_Main.wav", + "F2 A2 C3 E3 G3 B3 D4 F4 A4 C5 E5", 12) +UPR = pick(VCSL, "Chordophones/Zithers/Upright Piano, Knight/Sustains/Player_vl2_rr1_{}.wav", + "F2 G2 A2 B2 C#3 D#3 F3 G3 A3 B3 C#4 D#4 F4 G4 A4", 12) + +SOUNDS = [ + dict(name="E.PIANO", title="Electric piano (Wurlitzer 200)", + desc="Soul chords, the warm bark of a Wurlitzer through a dusty sampler.", + license="CC BY 3.0 - Greg Sullivan (Wurlitzer EP200 samples)", + chain=dict(lp=8500, drive=1.5, warm=2.0), + zones=[(45, 1.8, WUR), (51, 1.8, WUR), (61, 1.8, WUR), (71, 1.75, WUR)]), + dict(name="BASS", title="Upright bass (pizzicato)", + desc="A jazz upright bass. Plays two octaves under the keys: F3 on the keyboard is F1.", + license="CC0 - VSCO-2 Community Edition (Versilian Studios)", + transpose=24, + chain=dict(lp=4200, drive=2.0, warm=3.0, wow=0.0), + zones=[(28, 1.15, CB), (34, 1.15, CB), (38, 1.1, CB), (42, 1.1, CB), (45, 1.1, CB), (49, 1.05, CB)]), + dict(name="HORNS", title="Horn section stabs", + desc="Trumpet and trombone an octave apart: the stab of a funk record.", + license="CC0 - VSCO-2 Community Edition (Versilian Studios)", + chain=dict(lp=9000, drive=2.2, warm=1.5), + zones=[(t, 0.8, section((TPT, 0, 1.0), (TBN, 12, 0.75))) for t in (53, 57, 60, 63, 67, 70, 74)]), + dict(name="STRINGS", title="String stabs", + desc="Violins and violas, short and hard: the orchestra stab of '90s rap.", + license="CC0 - VSCO-2 Community Edition (Versilian Studios)", + chain=dict(lp=9500, drive=1.8, warm=1.5), + zones=[(t, 0.9, section((VLN, 0, 1.0), (VLA, 12, 0.7))) for t in (55, 59, 62, 66, 69, 72, 76)]), + dict(name="VIBES", title="Vibraphone", + desc="Hard mallets, jazz-rap vibes.", + license="CC0 - VCSL (Versilian Studios)", + chain=dict(lp=10000, drive=1.3, warm=1.0), + zones=[(53, 1.8, VIB), (60, 1.8, VIB), (67, 1.8, VIB), (74, 1.7, VIB)]), + dict(name="UPRIGHT", title="Dusty upright piano", + desc="An old upright, filtered like a loop off a jazz record.", + license="CC0 - VCSL (Versilian Studios)", + chain=dict(lp=6500, drive=1.8, warm=3.0, wow=0.002), + zones=[(53, 1.8, UPR), (59, 1.8, UPR), (65, 1.8, UPR), (73, 1.7, UPR)]), +] + +# The DJ's sounds: one per key range, at their own pitch in the middle of it (CC0, Sonic Pi) +SCRATCH = dict(name="SCRATCH", title="DJ scratches", + desc="Scratch, backspin, rewind and a finger snap, each on its own keys.", + license="CC0 - Sonic Pi sample set (freesound.org CC0 recordings)", + zones=[("vinyl_scratch", 57, 53, 60, 1.6), ("vinyl_backspin", 64, 61, 67, 1.6), + ("vinyl_rewind", 70, 68, 73, 2.2), ("perc_snap", 77, 74, 79, 0.5)]) + + +def build_pitched(snd, report): + d = OUT / snd["dir"] + zones, total = [], 0 + tr = snd.get("transpose", 0) + for k, (tgt, sec, make) in enumerate(snd["zones"]): + x = make(tgt) + x = shape(dusty(x, seed=k, **snd["chain"]), sec) + fn = f"{k:02d}_{note_name(tgt).replace('#', 's')}.wav" # (no '#': the files go in URLs) + write(d / fn, x) + total += len(x) + zones.append(dict(file=f"{snd['dir']}/{fn}", root=tgt + tr)) + report.append(f"{snd['name']:8s} {len(zones)} zones, {total / RATE:.2f} s of {SLOT_SAMPLES / RATE:.2f} s") + if total > SLOT_BUDGET: + raise SystemExit(f"{snd['name']}: {total} samples, a slot holds {SLOT_BUDGET}") + return zones + + +def build_scratch(snd, report): + d = OUT / snd["dir"] + zones, total = [], 0 + for k, (src, root, lo, hi, sec) in enumerate(snd["zones"]): + x, sr = load(SONICPI + f"{src}.flac") + x = to_rate(x[onset(x):], sr) + x = shape(dusty(x, lp=11000, drive=1.4, warm=1.5, wow=0.0, seed=k), sec, fade=0.15) + fn = f"{k:02d}_{src}.wav" + write(d / fn, x) + total += len(x) + zones.append(dict(file=f"{snd['dir']}/{fn}", root=root, + lo=0 if k == 0 else lo, hi=127 if k == len(snd["zones"]) - 1 else hi)) + report.append(f"{snd['name']:8s} {len(zones)} zones, {total / RATE:.2f} s of {SLOT_SAMPLES / RATE:.2f} s") + if total > SLOT_BUDGET: + raise SystemExit(f"{snd['name']}: {total} samples, a slot holds {SLOT_BUDGET}") + return zones + + +CREDITS = """SLOOP HIP-HOP PACK - free sounds for the user sample slots USR1..USR3 +Made by tools/gen_hiphop_pack.py: retuned, cut and processed ("dusty" chain) from: + + E.PIANO Wurlitzer EP200 samples by Greg Sullivan (http://www.sullivang.net/), + mapped by kinwie: https://github.com/sfzinstruments/GregSullivan.E-Pianos + Licence: Creative Commons Attribution 3.0 (CC BY 3.0). Credit: Greg Sullivan. + BASS VSCO-2 Community Edition (Versilian Studios), Solo Contrabass pizzicato. CC0 1.0. + HORNS VSCO-2 Community Edition, Trumpet and Tenor Trombone staccato. CC0 1.0. + STRINGS VSCO-2 Community Edition, Violin and Viola sections spiccato. CC0 1.0. + https://github.com/sgossner/VSCO-2-CE + VIBES VCSL (Versilian Community Sample Library), Vibraphone, hard mallets. CC0 1.0. + UPRIGHT VCSL, Upright Piano (Knight). CC0 1.0. https://github.com/sgossner/VCSL + SCRATCH Sonic Pi sample set, CC0 1.0 (freesound.org): vinyl_scratch (hello_flowers), + vinyl_backspin (il112), vinyl_rewind (TasmanianPower), perc_snap (SoundCollectah). + https://github.com/sonic-pi-net/sonic-pi/tree/main/etc/samples + +CC0 sounds: no conditions. E.PIANO: keep the credit to Greg Sullivan when you share the +samples themselves; music you make with any of them is yours. +No sound here comes from a commercial record. +""" + + +def main(): + report, pack = [], dict(format="sloop-pack", version=1, rate=RATE, + default=["E.PIANO", "BASS", "HORNS"], sounds=[]) + for snd in SOUNDS + [SCRATCH]: + snd["dir"] = snd["name"].replace(".", "") + for snd in SOUNDS: + print(f"{snd['name']}") + pack["sounds"].append(dict(name=snd["name"], title=snd["title"], desc=snd["desc"], + license=snd["license"], zones=build_pitched(snd, report))) + print(SCRATCH["name"]) + pack["sounds"].append(dict(name=SCRATCH["name"], title=SCRATCH["title"], desc=SCRATCH["desc"], + license=SCRATCH["license"], zones=build_scratch(SCRATCH, report))) + (OUT / "pack.json").write_text(json.dumps(pack, indent=1) + "\n", encoding="utf-8") + (OUT / "CREDITS.txt").write_text(CREDITS, encoding="utf-8") + print("\n".join(report)) + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tools/gen_icons.py b/tools/gen_icons.py new file mode 100644 index 0000000..0b46742 --- /dev/null +++ b/tools/gen_icons.py @@ -0,0 +1,91 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-3.0-only +# Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments +"""Turn the icon atlas into a C header (run by tools/build.py). + + gen_icons.py OUT.h [ASSETS_DIR] (default ASSETS_DIR: assets) + +Input + icons.json {"cell": 12, "cols": 16, "names": ["generic", "attack", ...]} + names[i] is the cell i of the atlas, row-major; each becomes ICON_. + icons.png the atlas, cell x cell pixels per icon, cols cells per row. Any mode: + ink = brightness (or alpha, if the PNG has transparency), quantised to + 2 bits: 0 = background, 1 / 2 / 3 = a third / two thirds / full ink. + +Output: per icon cell*cell 2-bit pixels, row-major, 4 pixels per byte, first pixel in the +high bits (12 x 12 -> 36 B), plus the enum ICON_ and FELUCCA_ICONS_N (the number of +drawn icons; 0 when the PNG, the JSON or Pillow is missing, so the firmware builds without). +""" +import json +import re +import sys +from pathlib import Path + +ASSETS = Path(__file__).resolve().parents[1] / "assets" + + +def load(assets): + """-> (cell, names, [cells of 2-bit pixels] or None, note)""" + try: + meta = json.loads((assets / "icons.json").read_text()) + cell, names = int(meta["cell"]), [str(n) for n in meta["names"]] + cols = int(meta.get("cols", 16)) + except (OSError, ValueError, KeyError) as e: + return 12, [], None, f"no icons.json ({e.__class__.__name__})" + try: + from PIL import Image + img = Image.open(assets / "icons.png") + except ImportError: + return cell, names, None, "no Pillow" + except OSError: + return cell, names, None, "no icons.png" + if img.mode in ("RGBA", "LA", "PA") or (img.mode == "P" and "transparency" in img.info): + rgba = img.convert("RGBA") + lum, alpha = rgba.convert("L"), rgba.getchannel("A") + ink = lambda x, y: lum.getpixel((x, y)) * alpha.getpixel((x, y)) // 255 # noqa: E731 + else: + lum = img.convert("L") + ink = lambda x, y: lum.getpixel((x, y)) # noqa: E731 + cells = [] + for i in range(len(names)): + ox, oy = (i % cols) * cell, (i // cols) * cell + px = [] + for y in range(cell): + for x in range(cell): + inside = ox + x < img.width and oy + y < img.height + px.append((ink(ox + x, oy + y) + 42) // 85 if inside else 0) # 0..255 -> 0..3 + cells.append(px) + return cell, names, cells, f"{img.width}x{img.height} {img.mode}" + + +def main(out, assets=ASSETS): + cell, names, cells, note = load(Path(assets)) + lines = ["/* generated by tools/gen_icons.py from assets/icons.png + icons.json */", + "#pragma once", "#include ", f"#define ICON_CELL {cell}"] + ids = [] + for n in names: + ident = "ICON_" + re.sub(r"[^A-Z0-9]", "_", n.upper()) + if ident in ids: + raise SystemExit(f"gen_icons: duplicate icon name {n!r}") + ids.append(ident) + if ids: + lines.append("enum {") + lines += [f" {ident}," for ident in ids] + lines.append(" ICON_COUNT\n};") + n = len(cells) if cells else 0 + lines.append(f"#define FELUCCA_ICONS_N {n}") + if n: + bpi = (cell * cell + 3) // 4 + lines.append(f"#define ICON_BYTES {bpi}") + lines.append(f"static const uint8_t ICON_DATA[{n}][{bpi}] = {{") + for name, px in zip(names, cells): + px = px + [0] * (-len(px) % 4) + b = [(px[i] << 6) | (px[i + 1] << 4) | (px[i + 2] << 2) | px[i + 3] for i in range(0, len(px), 4)] + lines.append(" {" + ", ".join(f"0x{v:02x}" for v in b) + f"}}, /* {name} */") + lines.append("};") + Path(out).write_text("\n".join(lines) + "\n") + print(f"icons: {n} of {len(names)} ({note}), {n * ((cell * cell + 3) // 4)} B") + + +if __name__ == "__main__": + main(*sys.argv[1:]) diff --git a/tools/gen_logo.py b/tools/gen_logo.py new file mode 100644 index 0000000..6d62d28 --- /dev/null +++ b/tools/gen_logo.py @@ -0,0 +1,232 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-3.0-only +"""The SLOOP logo: a four-colour sail (the four tracks: blue, green, yellow, orange) on the +mast of a 270-degree dial (the knobs of the UI), a hull, and a geometric monoline wordmark. + + tools/gen_logo.py OUT.h firmware boot splash (RLE, 16-colour palette, RGB565) + tools/gen_logo.py --assets DIR sloop-logo.svg, sloop-logo.png, sloop-icon.svg/png, sloop-splash.png +""" +import math +import sys +from pathlib import Path + +from PIL import Image, ImageDraw + +BLUE, GREEN, YELLOW, ORANGE = (40, 124, 255), (30, 204, 112), (255, 198, 24), (255, 98, 26) +WHITE, BLACK = (242, 242, 242), (0, 0, 0) +HEX = lambda c: "#%02X%02X%02X" % c +SAIL = [BLUE, GREEN, YELLOW, ORANGE] + +# ---- geometry (units: the icon is 240 x 240, the wordmark x-height is 72) ------------------- +ICON = dict(r=106, w=12, mast_dx=-30, top=-80, bot=38, sail_w=96, gap=6, hull=64) +XH, SW = 72, 12 # wordmark x-height, stroke + + +def sail_bands(cx, cy, k): + g = ICON + mx, top, bot = cx + g["mast_dx"] * k, cy + g["top"] * k, cy + g["bot"] * k + sx, h, wmax, gap = mx + 11 * k, bot - top, g["sail_w"] * k, g["gap"] * k + bh = (h - 3 * gap) / 4 + out = [] + for i, c in enumerate(SAIL): + y0 = top + i * (bh + gap) + y1 = y0 + bh + out.append((c, [(sx, y0), (sx + wmax * (y0 - top) / h, y0), (sx + wmax * (y1 - top) / h, y1), (sx, y1)])) + return mx, top, bot, out + + +def rrect(d, box, r, fill): + """rounded rectangle (ImageDraw.rounded_rectangle needs Pillow 8.2)""" + x0, y0, x1, y1 = box + r = min(r, (x1 - x0) / 2, (y1 - y0) / 2) + d.rectangle([x0 + r, y0, x1 - r, y1], fill=fill) + d.rectangle([x0, y0 + r, x1, y1 - r], fill=fill) + for cx, cy in ((x0 + r, y0 + r), (x1 - r, y0 + r), (x0 + r, y1 - r), (x1 - r, y1 - r)): + d.ellipse([cx - r, cy - r, cx + r, cy + r], fill=fill) + + +def draw_icon(d, ox, oy, k): + g = ICON + cx, cy, r, w = ox + 120 * k, oy + 120 * k, g["r"] * k, g["w"] * k + d.arc([cx - r, cy - r, cx + r, cy + r], start=135, end=405, fill=WHITE, width=max(1, round(w))) + for a in (135, 405): + x = cx + (r - w / 2) * math.cos(math.radians(a)) + y = cy + (r - w / 2) * math.sin(math.radians(a)) + d.ellipse([x - w / 2, y - w / 2, x + w / 2, y + w / 2], fill=WHITE) + mx, top, bot, bands = sail_bands(cx, cy, k) + rrect(d, [mx - 5 * k, top - 4 * k, mx + 5 * k, bot + 14 * k], 5 * k, WHITE) + for c, poly in bands: + d.polygon(poly, fill=c) + rrect(d, [cx - g["hull"] * k, bot + 24 * k, cx + g["hull"] * k, bot + 36 * k], 6 * k, WHITE) + + +def word_width(k): + rx = 0.29 * XH + return (2 * rx + 20 + SW + 20 + 3 * XH + 2 * 18) * k + + +def draw_word(d, ox, oy, k, col=WHITE): + w, xh = SW * k, XH * k + + def cap(x, y): + d.ellipse([x - w / 2, y - w / 2, x + w / 2, y + w / 2], fill=col) + + def line(x0, y0, x1, y1): + d.line([(x0, y0), (x1, y1)], fill=col, width=max(1, round(w))) + cap(x0, y0) + cap(x1, y1) + + base, x = oy + xh, ox + ry, rx = (xh + w) / 4, 0.29 * xh + b1, b2 = [x, oy, x + 2 * rx, oy + 2 * ry], [x, base - 2 * ry, x + 2 * rx, base] + d.arc(b1, start=90, end=335, fill=col, width=max(1, round(w))) + d.arc(b2, start=270, end=515, fill=col, width=max(1, round(w))) + for b, a in ((b1, 335), (b2, 155)): + cx, cy, a = (b[0] + b[2]) / 2, (b[1] + b[3]) / 2, math.radians(a) + cap(cx + (rx - w / 2) * math.cos(a), cy + (ry - w / 2) * math.sin(a)) + x += 2 * rx + 20 * k + line(x + w / 2, oy - 32 * k, x + w / 2, base - w / 2) + x += w + 20 * k + R = xh / 2 + for _ in range(3): + d.ellipse([x, oy, x + 2 * R, oy + 2 * R], outline=col, width=max(1, round(w))) + if _ < 2: + x += 2 * R + 18 * k + line(x + w / 2, oy + R, x + w / 2, base + 36 * k) + + +def render(kind, W, H, k, bg=BLACK, ss=4): + im = Image.new("RGB", (W * ss, H * ss), bg) + d = ImageDraw.Draw(im) + K = k * ss + if kind == "h": # icon + wordmark side by side + draw_icon(d, 10 * K, (H * ss - 240 * K) / 2, K) + draw_word(d, 270 * K, H * ss / 2 - 36 * K, K) + elif kind == "v": # icon over the wordmark (the boot splash) + draw_icon(d, (W * ss - 240 * K) / 2, 0, K) + draw_word(d, (W * ss - word_width(K)) / 2, 262 * K, K) + else: + draw_icon(d, (W * ss - 240 * K) / 2, (H * ss - 240 * K) / 2, K) + return im.resize((W, H), Image.LANCZOS) + + +# ---- SVG (stroke centred on the path) --------------------------------------------------------- +def svg_icon(ox, oy): + g, k = ICON, 1.0 + cx, cy, w = ox + 120, oy + 120, g["w"] + r = g["r"] - w / 2 + a0, a1 = math.radians(135), math.radians(405) + p0 = (cx + r * math.cos(a0), cy + r * math.sin(a0)) + p1 = (cx + r * math.cos(a1), cy + r * math.sin(a1)) + s = [f''] + mx, top, bot, bands = sail_bands(cx, cy, k) + s.append(f'') + for c, poly in bands: + s.append('') + s.append(f'') + return s + + +def svg_word(ox, oy): + w, xh, col = SW, XH, HEX(WHITE) + base, x = oy + xh, ox + ry, rx = (xh + w) / 4 - w / 2, 0.29 * xh - w / 2 + c1 = (x + 0.29 * xh, oy + (xh + w) / 4) + c2 = (x + 0.29 * xh, base - (xh + w) / 4) + + def pt(c, a): + a = math.radians(a) + return c[0] + rx * math.cos(a), c[1] + ry * math.sin(a) + s = [] + # top bowl 90 -> 335 (clockwise on screen), bottom bowl 270 -> 515 + for c, a, b in ((c1, 90, 335), (c2, 270, 515)): + p, q = pt(c, a), pt(c, b) + large = 1 if (b - a) > 180 else 0 + s.append(f'') + x += 2 * 0.29 * xh + 20 + s.append(f'') + x += w + 20 + R = xh / 2 + for i in range(3): + s.append(f'') + if i < 2: + x += 2 * R + 18 + s.append(f'') + return s + + +def svg(kind): + if kind == "h": + W, H = 760, 260 + body = svg_icon(10, 10) + svg_word(270, H / 2 - 36) + else: + W, H = 240, 240 + body = svg_icon(0, 0) + return (f'\n\n' + "\n".join(body) + "\n\n") + + +# ---- firmware splash --------------------------------------------------------------------------- +SPLASH_W, SPLASH_H = 240, 188 + + +def rgb565(c): + r, g, b = c + return ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3) + + +def splash_header(path): + im = render("v", SPLASH_W, SPLASH_H, 0.56) + # a fixed palette: black, and each logo colour at 1/3, 2/3 and full (the anti-aliased edges) + cols = [BLACK] + for c in (WHITE, BLUE, GREEN, YELLOW, ORANGE): + cols += [tuple(round(v * f) for v in c) for f in (1 / 3, 2 / 3, 1.0)] + src = im.tobytes() + px = [] + cache = {} + for i in range(0, len(src), 3): + p = (src[i], src[i + 1], src[i + 2]) + if p not in cache: + cache[p] = min(range(16), key=lambda k: sum((p[j] - cols[k][j]) ** 2 for j in range(3))) + px.append(cache[p]) + rle = bytearray() # (run - 1) << 4 | index, runs of 1..16 + i = 0 + while i < len(px): + j = i + while j < len(px) and px[j] == px[i] and j - i < 16: + j += 1 + rle.append(((j - i - 1) << 4) | px[i]) + i = j + L = ["/* generated by tools/gen_logo.py: the SLOOP boot splash */", "#pragma once", "#include ", + f"#define SLOOP_SPLASH_W {SPLASH_W}", f"#define SLOOP_SPLASH_H {SPLASH_H}", + "static const uint16_t SLOOP_SPLASH_PAL[16] = {" + ", ".join(f"0x{rgb565(c):04X}" for c in cols) + "};", + f"static const uint8_t SLOOP_SPLASH_RLE[{len(rle)}] = {{"] + for k in range(0, len(rle), 24): + L.append(" " + ", ".join(str(b) for b in rle[k:k + 24]) + ",") + L.append("};") + Path(path).write_text("\n".join(L) + "\n") + print(f"logo: splash {SPLASH_W}x{SPLASH_H}, {len(rle)} B RLE -> {path}") + + +def assets(out): + out = Path(out) + out.mkdir(parents=True, exist_ok=True) + (out / "sloop-logo.svg").write_text(svg("h")) + (out / "sloop-icon.svg").write_text(svg("i")) + render("h", 1520, 520, 2.0).save(out / "sloop-logo.png") + render("i", 512, 512, 512 / 240).save(out / "sloop-icon.png") + render("v", SPLASH_W, SPLASH_H, 0.56).resize((SPLASH_W * 2, SPLASH_H * 2), Image.NEAREST).save(out / "sloop-splash.png") + print(f"logo: assets in {out}") + + +if __name__ == "__main__": + if len(sys.argv) == 3 and sys.argv[1] == "--assets": + assets(sys.argv[2]) + elif len(sys.argv) == 2: + splash_header(sys.argv[1]) + else: + sys.exit(__doc__) diff --git a/tools/gen_samples.py b/tools/gen_samples.py new file mode 100644 index 0000000..62ff7f8 --- /dev/null +++ b/tools/gen_samples.py @@ -0,0 +1,427 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-3.0-only +# Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments +"""Build the SAMPLE engine's sample sets from WAV files into a C header. + +Samples are stored as IMA ADPCM (4 bit). Roots come from the file names, loops +from the WAV 'smpl' chunk; the ADPCM state at the loop start is stored so loops +restart exactly. + +Sources: + assets/samples-cc0/ CC0 samples (CREDITS.txt there): DUSTY, BASS, VIBES, HORNS, STRGS, FLUTE, + SCRCH (tools/gen_builtin_hiphop.py makes them; FLUTE and the KIT: + tools/fetch_cc0.py), and hand percussion for the GM kit + gen_waves.py Felucca's own drum sounds (the Hügelton Sample Pack) +One SAMPLE preset is written per set (SET_PRESETS: its name and sound), plus EXTRA_PRESETS. +A file named ..._m.wav has its root given (MIDI note n); else it comes from the note in the name. + +With FELUCCA_SLICE=1 the SLICE engine's built-in BREAK (eng_slice.c) is rendered here +too: one bar of 16ths arranged from Felucca's own generated drums, stored after every set +and not one of the SAMPLE sets. Its slice table (decoder states on a 128-point grid, the hits as AUTO +slices) is written with it: SLC_BREAK_INIT. + +The header is cached in build/gen_samples.cache under a hash of every input. +""" +import hashlib +import os +import re +import subprocess +import sys +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent)) +import sampleio as sio # noqa: E402 +from sampleio import detect_hz, hz_to_midi, ima_encode, key_split, onset, peak, read_any_wav, resample # noqa: E402 + +SRC = Path(__file__).resolve().parents[1] +GENDIR = SRC / "build" / "genwav" +CACHE = SRC / "build" / "gen_samples.cache" +CC0 = SRC / "assets" / "samples-cc0" +TR = 22050 # stored sample rate + +# set -> kind ("oneshot" decaying, "sus" looped sustain, "kit" one sample per key). +# The other slots are user sets loaded from the web editor. +CC0_SETS = [("DUSTY", "oneshot"), ("BASS", "oneshot"), ("VIBES", "oneshot"), ("HORNS", "oneshot"), + ("STRGS", "oneshot"), ("FLUTE", "sus"), ("SCRCH", "oneshot"), ("KIT", "kit")] +MEASURED_TUNING = () # sets recorded off A440 (measured near the named note) + +# the preset of each set: name, {SET (filled in), TUNE, BITS, LOOP (filled in), CUT, -, DRV, -}, env, mono, +# sends (DIST, CHORUS, DELAY, REVERB), more (track parameter, value) pairs (preset_t.x) +SET_PRESETS = { + "DUSTY": ("DUSTY PNO", [0, 0, 20, 0, 104, 0, 14, 0], (0, 127, 127, 52), 0, (0, 8, 10, 22), ()), + "BASS": ("UP BASS", [0, 0, 0, 0, 118, 0, 12, 0], (0, 127, 127, 26), 1, (0, 0, 0, 4), ()), + "VIBES": ("VIBES", [0, 0, 0, 0, 127, 0, 0, 0], (0, 127, 127, 72), 0, (0, 24, 22, 30), ("P_LD_AMP", 18, "P_LRATE", 86)), + "HORNS": ("HORN STAB", [0, 0, 0, 0, 120, 0, 20, 0], (0, 127, 127, 22), 0, (8, 0, 14, 18), ()), + "STRGS": ("STRING STB", [0, 0, 0, 0, 122, 0, 10, 0], (0, 127, 127, 26), 0, (0, 10, 12, 24), ()), + "FLUTE": ("LOFI FLUTE", [0, 0, 12, 0, 100, 0, 0, 0], (12, 80, 120, 60), 1, (0, 16, 26, 30), ("P_LD_PIT", 1, "P_LRATE", 89, "P_LFADE", 40)), + "SCRCH": ("SCRATCH", [0, 0, 0, 0, 127, 0, 8, 0], (0, 127, 127, 18), 0, (0, 0, 0, 0), ()), + "PERC": ("GM KIT", [0, 0, 0, 0, 127, 0, 0, 0], (0, 127, 127, 60), 0, (0, 0, 0, 6), ()), +} +# more presets on a set: (set, name, E[], env, mono, sends, more) +EXTRA_PRESETS = [ + ("DUSTY", "LOFI KEYS", [0, 0, 45, 0, 78, 0, 30, 0], (0, 127, 110, 60), 0, (0, 30, 18, 34), ("P_LD_PIT", 1, "P_LRATE", 38)), + ("BASS", "DEEP BASS", [0, -12, 0, 0, 90, 0, 40, 0], (0, 127, 127, 30), 1, (0, 0, 0, 0), ()), +] + +KIT_BASE = 53 # F3, the lowest FM-1 key + +NOTE = {"C": 0, "C#": 1, "D": 2, "D#": 3, "E": 4, "F": 5, "F#": 6, "G": 7, "G#": 8, "A": 9, "A#": 10, "B": 11} + +# GM drum map (General MIDI percussion, channel 10): role -> [(lo, hi, root)]. +# One sample can serve several GM notes; a range is pitched around its root. +GM_KIT = { + "kick": [(35, 36, 36)], "rim": [(37, 37, 37)], "snare": [(38, 38, 38), (40, 40, 40)], + "clap": [(39, 39, 39)], "chh": [(42, 42, 42), (44, 44, 44)], "ohh": [(46, 46, 46)], + "tomlo": [(41, 45, 43)], "tomhi": [(47, 50, 48)], "tom": [(41, 50, 47)], + "crash": [(49, 49, 49), (52, 52, 52), (55, 55, 55), (57, 57, 57)], + "ride": [(51, 51, 51), (53, 53, 53), (59, 59, 59)], + "tamb": [(54, 54, 54)], "cowbell": [(56, 56, 56)], "conga": [(62, 64, 63)], + "shaker": [(69, 70, 70), (82, 82, 82)], "claves": [(75, 75, 75)], "wood": [(76, 77, 76)], +} +GM_ROLE_WORDS = [("bassdrum", "kick"), ("kick", "kick"), ("snare", "snare"), ("hihat", "chh"), ("chat", "chh"), + ("ohat", "ohh"), ("clap", "clap"), ("tom lo", "tomlo"), ("tom hi", "tomhi"), ("tom", "tom"), + ("rim", "rim"), ("cowbell", "cowbell"), ("tamb", "tamb"), ("shaker", "shaker"), + ("conga", "conga"), ("claves", "claves"), ("wood", "wood"), ("crash", "crash"), ("ride", "ride")] +GM_KEEP = {"crash": 0.8, "ride": 0.8, "ohh": 0.5} +GM_CC0_ROLES = ("tamb", "shaker", "conga", "claves", "wood") # the CC0 set is orchestral: hand percussion only + +# SLICE's BREAK: (step, GM role, gain) on a bar of 16ths; the open hat is choked by the next hat +BREAK_BPM, BREAK_STEPS = 120, 16 +BREAK_HITS = [(0, "kick", 1.0), (0, "chh", 0.55), (2, "kick", 0.7), (2, "chh", 0.4), (4, "snare", 1.0), + (4, "chh", 0.45), (6, "chh", 0.4), (7, "kick", 0.8), (8, "chh", 0.55), (9, "snare", 0.3), + (10, "kick", 0.9), (10, "ohh", 0.4), (12, "snare", 1.0), (12, "chh", 0.45), (14, "chh", 0.4), + (14, "snare", 0.35)] +SLC_GRID, SLC_AUTO = 128, 32 # eng_slice.c slc_src_t + +ENV = {"wave":(5, 80, 100, 50), "kit": (0, 127, 127, 60), "multi": (0, 85, 0, 75), + "oneshot": (0, 127, 127, 70), "sus": (12, 80, 120, 60)} + +_wavs = {} + + +def wav(path): + """read_any_wav, once per file and run (the CC0 pass reads every file twice)""" + if path not in _wavs: + _wavs[path] = read_any_wav(path) + return _wavs[path] + + +def name_note(name): + """'_C#3' in a CC0 file name -> (octave, pitch class)""" + m = re.search(r"_([A-G]#?)(-?\d)", name) + return (int(m.group(2)), NOTE[m.group(1)]) if m else None + + +def cc0_entries(setname, kind): + """-> [(file name, int16 samples at TR, loop or None, root)]""" + files = sorted((CC0 / setname).glob("*.wav")) + out, conv = [], 1 + if kind != "kit" and not all(re.search(r"_m\d+\.wav$", p.name) for p in files): + # octave convention of this set (C4 = 60 or C3 = 60): YIN votes, the names give the notes + votes = {1: 0, 2: 0} + for p in files: + nn = name_note(p.name) + if not nn: + continue + sr, x = wav(p) + det = hz_to_midi(detect_hz(x[onset(x):], sr)) + for o in (1, 2): + if abs(det - ((nn[0] + o) * 12 + nn[1])) < 1.0: + votes[o] += 1 + conv = 2 if votes[2] >= votes[1] else 1 + for k, p in enumerate(files): + sr, x = wav(p) + x = x[max(0, onset(x) - 16):] + nn = name_note(p.name) + given = re.search(r"_m(\d+)\.wav$", p.name) + if given and kind != "kit": + root = int(given.group(1)) # (the file says it) + elif kind == "kit": + root = KIT_BASE + k + elif nn: + root = (nn[0] + conv) * 12 + nn[1] + if setname in MEASURED_TUNING: # tuned off A440: the measured pitch near the named note + det = hz_to_midi(detect_hz(x, sr)) + if abs(det - root) < 1.0: + root = det + else: + root = hz_to_midi(detect_hz(x, sr)) + x = resample(x, sr, TR) + keep = {"oneshot": 1.0, "sus": 0.95, "kit": 0.6}[kind] + x = x[:int(keep * TR)] + n = len(x) + if kind == "sus": # crossfaded sustain loop in the steady part + ls, le, xf = int(0.40 * TR), n - 1, int(0.06 * TR) + for i in range(xf): + a = i / xf + x[le - xf + i] = x[le - xf + i] * (1 - a) + x[ls - xf + i] * a + loop = (ls, le) + else: + fade = int(0.08 * TR) + for i in range(fade): + x[n - fade + i] *= 1 - i / fade + loop = None + pk = peak(x) + out.append((p.name, [int(v * 30000 / pk) for v in x], loop, root)) + return out + + +def gm_role(name): + n = name.lower() + return next((r for w, r in GM_ROLE_WORDS if w in n), None) + + +def gm_kit_sources(have_cc0): + """role -> wav path: Felucca's own synthesized drum kit (generated by + gen_waves.py), plus CC0 hand percussion for the roles it does not make""" + src = {} + for p in sorted(GENDIR.glob("D *.wav")): + r = gm_role(p.stem) + if r and r not in src: + src[r] = p + if have_cc0 and (CC0 / "KIT").exists(): + for p in sorted((CC0 / "KIT").glob("*.wav")): + r = gm_role(p.name) + if r in GM_CC0_ROLES and r not in src: + src[r] = p + if "tomlo" in src or "tomhi" in src: + src.pop("tom", None) + return src + + +def gm_kit_entry(role, path): + sr, x = wav(path) + x = resample(x[max(0, onset(x) - 16):], sr, TR) + x = x[:int(GM_KEEP.get(role, 0.45) * TR)] + pk = peak(x) + end = len(x) # drop the silent tail + while end > 64 and abs(x[end - 1]) < 0.004 * pk: + end -= 1 + x = x[:end] + fade = min(len(x) // 4, int(0.03 * TR)) + for i in range(fade): + x[len(x) - fade + i] *= 1 - i / fade + return [int(v * 30000 / pk) for v in x] + + +def ima_states(data, positions): + """IMA ADPCM decoder state before sample p for each p (ascending), packed as eng_slice.c reads it: + (predictor & 0xFFFF) | index << 16 (segment 0)""" + pred, idx, out, want = 0, 0, [], list(positions) + for n in range(max(want) + 1 if want else 0): + while want and want[0] == n: + out.append((pred & 0xFFFF) | idx << 16) + want.pop(0) + code = (data[n >> 1] >> (4 * (n & 1))) & 15 + step = sio.IMA_STEP[idx] + vd = step >> 3 + if code & 4: + vd += step + if code & 2: + vd += step >> 1 + if code & 1: + vd += step >> 2 + pred = max(-32768, min(32767, pred - vd if code & 8 else pred + vd)) + idx = max(0, min(88, idx + sio.IMA_IDX[code & 7])) + return out + + +def break_loop(): + """SLICE's BREAK: BREAK_HITS from Felucca's generated drums at TR -> (int16 samples, hit positions)""" + src = gm_kit_sources(False) # generated sounds only: the same on every build + n = int(round(TR * 60 / BREAK_BPM * 4)) + x = [0.0] * n + pos = [s * n // BREAK_STEPS for s in range(BREAK_STEPS + 1)] + for step, role, gain in BREAK_HITS: + smp = gm_kit_entry(role, src[role]) + if role == "ohh": # choked by the next hat + nxt = min([s for s, r, _ in BREAK_HITS if r in ("chh", "ohh") and s > step] or [BREAK_STEPS]) + keep, fade = pos[nxt] - pos[step], int(0.004 * TR) + smp = [v * min(1.0, (keep - i) / fade) for i, v in enumerate(smp[:keep])] + for i, v in enumerate(smp): # the tails wrap round: a seamless loop + x[(pos[step] + i) % n] += v * gain + pk = peak(x) + return [int(v * 30000 / pk) for v in x], sorted({pos[s] for s, _, _ in BREAK_HITS}) + + +class Builder: + def __init__(self): + self.zones, self.sets, self.blob, self.kinds = [], [], bytearray(), {} + self.brk = None + + def slice_break(self): + """SLICE's BREAK, after every set; its slice table: decoder states at k * len / SLC_GRID, the hits""" + x, hits = break_loop() + off, _ = self.add(x, 0) + n = len(x) + data = self.blob[off:off + (n + 1) // 2] + grid = ima_states(data, [k * n // SLC_GRID for k in range(SLC_GRID)]) + hits = hits[:SLC_AUTO] + self.brk = dict(off=off, n=n, grid=grid, apos=hits, ast=ima_states(data, hits)) + + def add(self, s, loop_start): + """ADPCM-encode s into the blob (each sample starts on an even offset) -> (offset, state at loop_start)""" + enc, st = ima_encode(s, loop_start) + off = len(self.blob) + self.blob += enc + if len(self.blob) & 1: + self.blob.append(0) + return off, st + + def add_set(self, name, kind, entries): + """entries: zone dicts with root16 (and key for a kit); assigns the key ranges""" + if not entries: + return + if kind == "kit": + for e in entries: + e["lo"] = e["hi"] = e["key"] + else: + entries.sort(key=lambda e: e["root16"]) + for e, (lo, hi) in zip(entries, key_split([e["root16"] // 16 for e in entries])): + e["lo"], e["hi"] = lo, hi + self.sets.append((name, len(self.zones), len(entries))) + self.zones += entries + self.kinds[name] = kind + + def gm_kit(self, have_cc0): + """one GM-mapped kit: generated drums + CC0 hand percussion""" + z0 = len(self.zones) + for role, path in gm_kit_sources(have_cc0).items(): + smp = gm_kit_entry(role, path) + off, st = self.add(smp, len(smp)) + for lo, hi, root in GM_KIT[role]: + self.zones.append(dict(off=off, n=len(smp), ls=len(smp), le=len(smp), looped=False, sr=TR, + root16=root * 16, pred=st[0], idx=st[1], lo=lo, hi=hi)) + self.sets.append(("PERC", z0, len(self.zones) - z0)) + self.kinds["PERC"] = "kit" + + def cc0_set(self, name, kind): + entries = [] + for k, (_, s, loop, root) in enumerate(cc0_entries(name, kind)): + ls, le = loop if loop else (len(s), len(s)) + off, st = self.add(s, ls) + entries.append(dict(off=off, n=len(s), ls=ls, le=le, looped=bool(loop), sr=TR, + root16=int(round(root * 16)), pred=st[0], idx=st[1], + key=KIT_BASE + k if kind == "kit" else None)) + self.add_set(name, kind, entries) + + def header(self): + zones, sets, blob = self.zones, self.sets, self.blob + L = ["/* generated by tools/gen_samples.py: IMA ADPCM sample sets */", "#pragma once", + "#include ", ""] + L.append(f"static const uint8_t SMP_DATA[{max(1, len(blob))}] = {{") + for i in range(0, len(blob), 32): + L.append(" " + ",".join(map(str, blob[i:i + 32])) + ",") + if not blob: + L.append(" 0,") + L.append("};") + L.append("static const smp_zone_t SMP_ZONES[] = {") + for e in zones: + rate = int(round(e["sr"] / 44100 * 65536)) + L.append(f" {{{e['off']}, {e['n']}, {e['ls']}, {e['le']}, {rate}, {e['root16']}, {e['pred']}, " + f"{e['idx']}, {e['lo']}, {e['hi']}, {1 if e['looped'] else 0}}},") + if not zones: + L.append(" {0, 0, 0, 0, 65536, 960, 0, 0, 0, 127, 0},") + L.append("};") + L.append("static const smp_set_t SMP_SETS[] = {") + for name, z0, nz in sets: + L.append(f' {{"{name}", {z0}, {nz}}},') + if not sets: + L.append(' {"NONE", 0, 1},') + L.append("};") + L.append(f"#define SMP_NSETS {max(1, len(sets))}") + L.append("static const preset_t SMP_PRESET_TABLE[] = {") + named = sets or [("NONE", 0, 0)] + + def preset(i, k, pname, e, env, mono, fx, more): + e = list(e) + e[0], e[3] = i, 0 if k == "kit" else 1 + x = ", ".join(f"{more[j]} + 1, {more[j + 1]}" for j in range(0, len(more), 2)) + return (f' {{"{pname}", {{{", ".join(map(str, e))}}}, {{{", ".join(map(str, env))}}}, 0, {mono}, ' + f'FX({", ".join(map(str, fx))}){", .x = {" + x + "}" if x else ""}}},') + for i, (name, _, _) in enumerate(named): + k = self.kinds.get(name, "wave") + if name in SET_PRESETS: + L.append(preset(i, k, *SET_PRESETS[name])) + else: + a, d, s_, r = ENV[k] + L.append(f' {{"{name}", {{{i}, 0, 0, {0 if k == "kit" else 1}, 127, 0, 0, 0}}, {{{a}, {d}, {s_}, {r}}}, 0, 0}},') + for setname, *rest in EXTRA_PRESETS: + i = next((j for j, (n, _, _) in enumerate(named) if n == setname), None) + if i is not None: + L.append(preset(i, self.kinds.get(setname, "wave"), *rest)) + L.append("};") + names = ", ".join(f'"{n}"' for n, _, _ in named) + L.append("#define SMP_SET_NAMES_INIT " + names) + L.append("static const char *const SMP_SET_NAMES[] = {" + names + "};") + L += self.break_header() + return "\n".join(L) + "\n" + + def break_header(self): + """SLC_BREAK_INIT: an eng_slice.c slc_src_t (len, rate, nseg, nauto, seg[], grid[], apos[], ast[])""" + b = self.brk + if not b: + return ["#define SLC_BREAK_INIT {0}"] + rate = int(round(TR / 44100 * 65536)) + + def lst(v, k): + v = list(v) + [0] * (k - len(v)) + return ", \\\n ".join(", ".join(map(str, v[i:i + 12])) for i in range(0, len(v), 12)) + return ["", f"/* SLICE's BREAK: one bar of {BREAK_STEPS} steps at {BREAK_BPM} BPM, {len(b['apos'])} hits */", + f"#define SLC_BREAK_BPM {BREAK_BPM}", f"#define SLC_BREAK_STEPS {BREAK_STEPS}", + f"#define SLC_BREAK_INIT {{{b['n']}, {rate}, 1, {len(b['apos'])}, {{{{{b['off']}, 0, {b['n']}}}}}, {{ \\", + " " + lst(b["grid"], SLC_GRID) + "}, { \\", " " + lst(b["apos"], SLC_AUTO) + "}, { \\", + " " + lst(b["ast"], SLC_AUTO) + "}}"] + + def summary(self): + brk = f", SLICE BREAK {self.brk['n']} samples" if self.brk else "" + return f"samples: {len(self.sets)} sets, {len(self.zones)} zones, {len(self.blob)} B ADPCM{brk}" + + +def input_key(have_cc0): + """hash of everything the header depends on""" + h = hashlib.sha256() + here = Path(__file__).resolve().parent + for p in (here / "gen_samples.py", here / "sampleio.py"): + h.update(p.read_bytes()) + h.update(repr((sys.version_info[:2], have_cc0, os.environ.get("FELUCCA_SLICE") == "1")).encode()) # sum() differs across versions + files = sorted(GENDIR.glob("*.wav")) + if have_cc0: + files += sorted(CC0.glob("*/*.wav")) + for p in files: + h.update(str(p.relative_to(SRC)).encode() + b"\0") + h.update(hashlib.sha256(p.read_bytes()).digest()) + return h.hexdigest() + + +def main(out): + subprocess.run([sys.executable, str(Path(__file__).with_name("gen_waves.py")), str(GENDIR)], check=True) + have_cc0 = CC0.exists() and any(CC0.glob("*/*.wav")) + if not have_cc0: + print("samples: no CC0 samples in assets/samples-cc0 - generated material only") + key = input_key(have_cc0) + try: + ck, summary, text = CACHE.read_text().split("\n", 2) + if ck == key: + Path(out).write_text(text) + print(summary + " (cached)") + return + except (OSError, ValueError): + pass + b = Builder() + if have_cc0: + for name, kind in CC0_SETS: + if kind != "kit": # the CC0 KIT feeds the GM kit + b.cc0_set(name, kind) + b.gm_kit(have_cc0) + if os.environ.get("FELUCCA_SLICE") == "1": # SLICE's BREAK: only when that engine is built + b.slice_break() # last: the sets' offsets stay as they were + text = b.header() + Path(out).write_text(text) + CACHE.parent.mkdir(parents=True, exist_ok=True) + CACHE.write_text(f"{key}\n{b.summary()}\n{text}") + print(b.summary()) + + +if __name__ == "__main__": + main(sys.argv[1]) diff --git a/tools/gen_tables.py b/tools/gen_tables.py new file mode 100644 index 0000000..dfd9814 --- /dev/null +++ b/tools/gen_tables.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-3.0-only +# Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments +"""Fixed-point lookup tables for FELUCCA (no float on the target). + +FS = 44100 Hz, control rate = every CTL (32) samples. All curves map a +0..127 parameter value to the unit the DSP needs, plus a display table. +""" +import math +import sys +from pathlib import Path + +FS = 44100 +CTL = 32 + + +def arr(name, ctype, vals, per=12): + out = [f"static const {ctype} {name}[{len(vals)}] = {{"] + for i in range(0, len(vals), per): + out.append(" " + ", ".join(str(v) for v in vals[i:i + per]) + ",") + out.append("};") + return out + + +def main(path): + L = ["/* generated by tools/gen_tables.py */", "#pragma once", "#include ", + f"#define FS {FS}", f"#define CTL {CTL}", ""] + L += arr("SINE", "int16_t", [int(round(32767 * math.sin(2 * math.pi * i / 1024))) for i in range(1024)]) + # phase increment for pitch in 1/16 semitone, MIDI 0..127 + inc = [] + for p in range(128 * 16): + f = 440.0 * 2 ** ((p / 16 - 69) / 12) + inc.append(min(int(f / FS * 2 ** 32), 0x7FFFFFFF)) + L += arr("PITCH_INC", "uint32_t", inc, 8) + # times 1 ms .. 10 s (exponential), env in Q24 (1.0 = 1<<24) + ms = [1.0 * (10000 ** (v / 127)) for v in range(128)] + L += arr("TIME_MS_X10", "uint32_t", [int(round(m * 10)) for m in ms], 10) + L += arr("ENV_LIN", "uint32_t", [max(1, int((1 << 24) * CTL / (m * FS / 1000))) for m in ms], 8) + exp_k = [] + for m in ms: + tau = m / 1000 / 4.6 # ~99 % of the way after "m" ms + exp_k.append(max(1, min(65535, int(65536 * (1 - math.exp(-CTL / (tau * FS))))))) + L += arr("ENV_EXP", "uint16_t", exp_k) + # LFO 0.05 .. 40 Hz, phase increment per control tick + hz = [0.05 * (800 ** (v / 127)) for v in range(128)] + L += arr("LFO_HZ_X100", "uint32_t", [int(round(h * 100)) for h in hz], 10) + L += arr("LFO_INC", "uint32_t", [int(h * CTL / FS * 2 ** 32) for h in hz], 8) + # filter cutoff 30 Hz .. 16 kHz + fc = [30.0 * ((16000 / 30) ** (v / 127)) for v in range(128)] + L += arr("CUTOFF_HZ", "uint16_t", [int(round(f)) for f in fc]) + # trapezoidal (Simper) SVF: g = tan(pi fc / FS), Q12; stable at any cutoff/resonance + L += arr("SVF_G", "uint16_t", [int(4096 * math.tan(math.pi * min(f, 0.45 * FS) / FS)) for f in fc]) + # level: 0 = off, else dB = (v - 112) / 2 (112 = 0 dB, 127 = +7.5 dB) + db = [None] + [(v - 112) / 2 for v in range(1, 128)] + L += arr("LEVEL_Q12", "uint16_t", [0] + [int(round(4096 * 10 ** (d / 20))) for d in db[1:]]) + L += arr("LEVEL_DB_X10", "int16_t", [-999] + [int(round(d * 10)) for d in db[1:]]) + # per-sample exponential decay for drum voices: 5 ms .. 4 s to -60 dB, Q16 + dms = [5.0 * (800 ** (v / 127)) for v in range(128)] + L += arr("DECAY_K", "uint16_t", [min(65535, int(65536 * math.exp(-6.9 / (m / 1000 * FS)))) for m in dms]) + # soft clip curve for |x| in 0..2 (Q12 in, Q15 out): tanh + L += arr("TANH_Q15", "int16_t", [int(32767 * math.tanh(i / 256 * 2)) for i in range(257)]) + Path(path).write_text("\n".join(L) + "\n") + print(f"tables: {path}") + + +if __name__ == "__main__": + main(sys.argv[1]) diff --git a/tools/gen_waves.py b/tools/gen_waves.py new file mode 100644 index 0000000..94db0dc --- /dev/null +++ b/tools/gen_waves.py @@ -0,0 +1,200 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-3.0-only +# Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments +"""Synthesize Felucca's own sample library (no third-party material). + +Writes 16-bit mono WAVs with 'smpl' loop chunks to the output directory: + single-cycle waves additive synthesis, one 256-sample cycle, looped + drum one-shots kick / snare / hats / clap / toms / rim / cowbell + pluck Karplus-Strong strings at three pitches (one-shots) +Everything here is generated from code in this file and is part of Felucca. +""" +import math +import random +import struct +import sys +from pathlib import Path + +SR = 32000 + + +def write_wav(path, samples, sr, loop=None, root=60): + data = b"".join(struct.pack("= 0.03 else 0.0 + n = random.uniform(-1, 1) + bp1 += 0.3 * (n - bp1) + bp2 += 0.3 * (bp1 - bp2) + out.append((bp1 - bp2) * burst) + return out + + +def drum_tom(f0): + out, ph = [], 0.0 + for i in range(int(0.5 * SR)): + t = i / SR + ph += 2 * math.pi * (f0 + f0 * 0.6 * math.exp(-t * 20)) / SR + out.append(math.sin(ph) * math.exp(-t * 7)) + return out + + +def drum_rim(): + out = [] + for i in range(int(0.08 * SR)): + t = i / SR + out.append((math.sin(2 * math.pi * 1700 * t) + 0.6 * math.sin(2 * math.pi * 520 * t)) * math.exp(-t * 70)) + return out + + +def drum_cowbell(): + out = [] + for i in range(int(0.4 * SR)): + t = i / SR + sq = lambda f: 1.0 if math.sin(2 * math.pi * f * t) > 0 else -1.0 + out.append((sq(562) + sq(845)) * 0.5 * math.exp(-t * 9)) + return out + + +def drum_metal_hat(decay): + """808-style hat: six detuned squares + a little noise, band-passed, short""" + fr = [205.3, 304.4, 369.6, 522.7, 540.0, 800.0] + out, ph, lp, hp = [], [0.0] * 6, 0.0, 0.0 + for i in range(int(decay * 5 * SR)): + t = i / SR + m = 0.0 + for k in range(6): + ph[k] += fr[k] * 3.0 / SR + m += 1.0 if (ph[k] % 1.0) < 0.5 else -1.0 + m /= 6 + x = 0.7 * m + 0.3 * random.uniform(-1, 1) + hp += 0.35 * (x - hp) + y = x - hp # high-pass + lp += 0.6 * (y - lp) # tame the top + out.append(lp * math.exp(-t / decay) * (1 if t > 0.001 else t / 0.001)) + return out + + +def drum_cymbal(decay, bell): + """noise + six inharmonic square partials (the 808 trick), high-passed""" + fr = [205.3, 304.4, 369.6, 522.7, 540.0, 800.0] + out, hp, hp2, ph = [], 0.0, 0.0, [0.0] * 6 + for i in range(int(decay * 4 * SR)): + t = i / SR + m = 0.0 + for k in range(6): + ph[k] += fr[k] * (2.2 if bell else 3.3) / SR + m += 1.0 if (ph[k] % 1.0) < 0.5 else -1.0 + x = 0.55 * m / 6 + 0.45 * random.uniform(-1, 1) + hp += 0.25 * (x - hp) + hp2 += 0.25 * ((x - hp) - hp2) + y = (x - hp) - hp2 + env = math.exp(-t / decay) * (1 if t > 0.002 else t / 0.002) + if bell: + env += 0.6 * math.exp(-t / 0.08) + out.append(y * env) + return out + + +def pluck(freq, secs=1.6): + n = int(SR / freq) + r = random.Random(int(freq)) + buf = [r.uniform(-1, 1) for _ in range(n)] + out, i = [], 0 + for _ in range(int(secs * SR)): + a = buf[i % n] + b = buf[(i + 1) % n] + buf[i % n] = 0.497 * (a + b) + out.append(a) + i += 1 + return out + + +def main(outdir): + out = Path(outdir) + out.mkdir(parents=True, exist_ok=True) + random.seed(1) + for name, parts in WAVES.items(): + write_wav(out / f"W {name}.wav", cycle(parts), SR, loop=(0, 255)) + for k in range(3): + write_wav(out / f"W DIGI{k + 1}.wav", cycle(digi(k + 7)), SR, loop=(0, 255)) + kit = [("KICK", drum_kick()), ("SNARE", drum_snare()), ("CHAT", drum_metal_hat(0.045)), + ("OHAT", drum_metal_hat(0.28)), + ("CLAP", drum_clap()), ("TOM LO", drum_tom(95)), ("TOM HI", drum_tom(150)), ("RIM", drum_rim()), + ("COWBELL", drum_cowbell()), ("CRASH", drum_cymbal(0.25, False)), ("RIDE", drum_cymbal(0.3, True))] + for name, s in kit: + write_wav(out / f"D {name}.wav", norm(s), SR) + for note, f in (("C2", 65.41), ("C3", 130.81), ("C4", 261.63)): # E-mu naming: C3 = MIDI 60 + write_wav(out / f"P PLUCK {note}.wav", norm(pluck(f * 2)), SR) + print(f"generated waves into {out}") + + +if __name__ == "__main__": + main(sys.argv[1]) diff --git a/tools/get_toolchain.sh b/tools/get_toolchain.sh new file mode 100644 index 0000000..ff2eed5 --- /dev/null +++ b/tools/get_toolchain.sh @@ -0,0 +1,12 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-3.0-only +# Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments +# Download JieLi's Linux toolchain (clang 4.0.1 for pi32v2) and link it as DEST/toolchain. +# tools/get_toolchain.sh [DEST] (default: ~/.jieli) +set -e +DEST="${1:-$HOME/.jieli}" +mkdir -p "$DEST" +curl -fL --retry 3 https://pkgman.jieliapp.com/s/linux-toolchain | tar -xJ -C "$DEST" +TC="$(ls -d "$DEST"/jieli-linux-toolchains-* | sort | tail -1)" +ln -sfn "$(basename "$TC")" "$DEST/toolchain" +echo "JIELI_TOOLCHAIN=$DEST/toolchain ($(basename "$TC"))" diff --git a/tools/lz4blk.py b/tools/lz4blk.py new file mode 100644 index 0000000..43fbdaa --- /dev/null +++ b/tools/lz4blk.py @@ -0,0 +1,82 @@ +# SPDX-License-Identifier: GPL-3.0-only +# Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments +"""Minimal LZ4 *block* format (no frame), written for the Felucca loader +wrapper: greedy hash-chain-free compressor and a decoder for self-checks. +Spec: https://github.com/lz4/lz4/blob/dev/doc/lz4_Block_format.md +(min match 4, last 5 bytes literals, last match starts >= 12 bytes before the end).""" + + +def _len_bytes(n): + out = bytearray() + while n >= 255: + out.append(255) + n -= 255 + out.append(n) + return out + + +def compress(src: bytes) -> bytes: + n, out, table = len(src), bytearray(), {} + anchor, i = 0, 0 + limit = n - 12 # matches must start before this + while i < limit: + key = src[i:i + 4] + cand = table.get(key) + table[key] = i + if cand is None or i - cand > 65535: + i += 1 + continue + mlen = 4 # extend; leave the last 5 bytes as literals + while i + mlen < n - 5 and src[cand + mlen] == src[i + mlen]: + mlen += 1 + lit = src[anchor:i] + tok = (min(len(lit), 15) << 4) | min(mlen - 4, 15) + out.append(tok) + if len(lit) >= 15: + out += _len_bytes(len(lit) - 15) + out += lit + off = i - cand + out += bytes((off & 0xFF, off >> 8)) + if mlen - 4 >= 15: + out += _len_bytes(mlen - 4 - 15) + i += mlen + anchor = i + lit = src[anchor:] # final literal run + out.append(min(len(lit), 15) << 4) + if len(lit) >= 15: + out += _len_bytes(len(lit) - 15) + out += lit + return bytes(out) + + +def decompress(blk: bytes, prefix: bytes = b"") -> bytes: + out, i = bytearray(prefix), 0 + while i < len(blk): + tok = blk[i] + i += 1 + ll = tok >> 4 + if ll == 15: + while True: + b = blk[i] + i += 1 + ll += b + if b != 255: + break + out += blk[i:i + ll] + i += ll + if i >= len(blk): + break + off = blk[i] | blk[i + 1] << 8 + i += 2 + ml = tok & 15 + if ml == 15: + while True: + b = blk[i] + i += 1 + ml += b + if b != 255: + break + ml += 4 + for _ in range(ml): + out.append(out[-off]) + return bytes(out[len(prefix):]) diff --git a/tools/make_quickguide.py b/tools/make_quickguide.py new file mode 100644 index 0000000..dd4c9c5 --- /dev/null +++ b/tools/make_quickguide.py @@ -0,0 +1,95 @@ +"""Build the illustrated French quick guide from the actual host-rendered UI.""" +from pathlib import Path +from reportlab.pdfgen import canvas +from reportlab.lib.colors import HexColor +from reportlab.lib.styles import ParagraphStyle +from reportlab.platypus import Paragraph, Table, TableStyle +from reportlab.pdfbase import pdfmetrics +from reportlab.pdfbase.ttfonts import TTFont + +ROOT = Path(__file__).resolve().parents[1] +OUT = ROOT / 'output/pdf/Studio-0.3-guide-rapide-FR.pdf' +OUT.parent.mkdir(parents=True, exist_ok=True) +pdfmetrics.registerFont(TTFont('Guide', 'C:/Windows/Fonts/arial.ttf')) +pdfmetrics.registerFont(TTFont('GuideBold', 'C:/Windows/Fonts/arialbd.ttf')) +pdfmetrics.registerFontFamily('Guide', normal='Guide', bold='GuideBold') +C = canvas.Canvas(str(OUT), pagesize=(595.28, 841.89)) +C.setTitle('Studio 0.3 DEV - Guide rapide du FM-1') +C.setAuthor('Studio - dérivé de Felucca') +INK = HexColor('#142636'); ACC = HexColor('#007b9e'); DIM = HexColor('#4b6171') +STYLE = ParagraphStyle('body', fontName='Guide', fontSize=10, leading=14, textColor=INK) +def p(text, y, x=46, w=503, size=10): + style = ParagraphStyle('p', parent=STYLE, fontSize=size, leading=size*1.4) + para = Paragraph(text, style) + _, h = para.wrap(w, 1000) + assert y-h > 43, (text[:40], y, h) + para.drawOn(C,x,y-h) + return y-h-10 +def title(n, heading, subtitle): + C.setFillColor(ACC);C.rect(0,825,595.28,17,fill=1,stroke=0) + C.setFillColor(DIM);C.setFont('GuideBold',9);C.drawString(46,791,'FM-1 / STUDIO 0.3 DEV') + C.setFillColor(INK);C.setFont('GuideBold',24);C.drawString(46,757,heading) + p(subtitle,739,size=10) + C.setStrokeColor(HexColor('#d5e5eb'));C.line(46,38,549,38) + C.setFont('Guide',8);C.setFillColor(DIM) + C.drawString(46,25,'Guide rapide • Écrans rendus par le firmware • Version expérimentale') + C.drawRightString(549,25,f'{n} / 4') +def heading(s,y): + C.setFont('GuideBold',13);C.setFillColor(ACC);C.drawString(46,y,s);return y-12 +def shot(name,x,y,size): + C.drawImage(str(ROOT/'build/host'/f'{name}.png'),x,y,width=size,height=size) +def table(rows,y,widths): + cells=[[Paragraph(str(c),ParagraphStyle('cell',parent=STYLE,fontSize=9,leading=12)) for c in row] for row in rows] + t=Table(cells,colWidths=widths,hAlign='LEFT') + t.setStyle(TableStyle([('BACKGROUND',(0,0),(-1,0),HexColor('#e7f3f7')),('VALIGN',(0,0),(-1,-1),'TOP'),('TOPPADDING',(0,0),(-1,-1),7),('BOTTOMPADDING',(0,0),(-1,-1),7),('LINEBELOW',(0,0),(-1,-1),.4,HexColor('#d5e5eb'))])) + _,h=t.wrap(503,800);assert y-h>45;t.drawOn(C,46,y-h);return y-h-15 + +title(1,'Votre premier morceau','Trois instruments + une batterie. HOME revient à la vue des quatre pistes.') +shot('studio-tracks',346,489,203) +y=699 +y=p('1. Poser la batterie
Choisir la piste 4 avec ALGORITHM. Appuyer sur SEQ, puis encore SEQ pour ouvrir RYTHME.',y,w=279) +y=p('2. Choisir une base
KNOB 1 : style. KNOB 2 : A ou B. À l’arrêt, REC applique le rythme. S’il existe déjà un motif, confirmer avec un second REC sous 3 secondes.',y,w=279) +y=p('3. Ajouter les instruments
HOME, choisir une piste 1 à 3, puis son son avec PRESETS. Certains presets fournissent déjà un motif.',y,w=279) +y= min(y,470) +y=p('4. Enregistrer vos notes
Depuis HOME, REC arme la piste et démarre la lecture si nécessaire. Jouer le clavier ; REC désarme, PLAY arrête. Les passages s’ajoutent au motif. Pour effacer : à l’arrêt, maintenir REC sur HOME, puis OCT+ confirme ; OCT- annule.',y) +y=p('5. Équilibrer
Sur HOME : KNOB 1 choisit la piste, 2 son volume, 3 sa longueur, 4 son panoramique. SELECT règle le tempo. PLAY commande les quatre pistes ensemble.',y) +y=p('6. Garder votre idée
HOME puis SAVE ouvre CHANSON. Choisir A avec KNOB 2 ; REC mémorise les quatre pistes. Une section occupée demande un second REC. Préparer ensuite B, C et D pour construire la chanson.',y) +y=heading('Lire l’écran',y-5) +y=p('La barre blanche à gauche indique la piste choisie. Les carrés montrent son motif ; le petit trait blanc suit la lecture. La barre à droite indique le volume réglé, pas le niveau audio mesuré. REC signale une piste armée.',y) +C.showPage() + +title(2,'La batterie, pas à pas','Depuis la piste 4 : SEQ ou EDIT ouvre la batterie. SEQ change d’onglet.') +shot('studio-grid',46,475,222) +shot('studio-kit',327,475,222) +y=453 +y=table([['Onglet','KNOB 1','KNOB 2','KNOB 3','KNOB 4'],['GRILLE','Son','Pas','+ ajoute
- retire','Vélocité'],['RYTHME','Style','A / B','Swing','Longueur'],['KIT','Couleur','Volume','Réverb.','Panoramique'] ],y,[90,103,90,110,110]) +y=p('GRILLE : quatre lignes visibles parmi 12 sons. KNOB 1 fait défiler kick, snare, clap, hi-hats, toms, crash, ride, shaker, conga et rim. OCT-/OCT+ déplace le curseur de 16 pas. Un cadre blanc marque la cellule choisie.',y) +y=p('On peut ajouter ou retirer des frappes pendant une boucle. Pendant une chanson, arrêter avant d’éditer les frappes. Un pas accepte 4 sons maximum ; sa vélocité est commune à ces sons.',y) +y=p('Jouer en direct : le clavier reste actif. Les neuf premières touches, de gauche à droite, jouent kick, kick grave, snare, snare alternative, rim, clap, hi-hat fermé, pédale et hi-hat ouvert. Les touches suivantes jouent toms, cymbales et percussions.',y) +y=p('REC dans GRILLE ou KIT arme/désarme l’enregistrement. PRESETS change de kit. SAVE ouvre CHANSON : y utiliser REC pour mémoriser la section. HOME revient aux pistes.',y) +C.showPage() + +title(3,'Explorer plusieurs styles','Les rythmes sont des points de départ éditables, sur deux mesures en 4/4.') +y=700 +y=table([['Style','Tempo conseillé','Couleur appliquée'],['House','124 BPM','Original'],['Techno','132 BPM','Tight'],['Hip hop','90 BPM','Dust'],['Trap','140 BPM','Deep'],['Rock','110 BPM','Original'],['Funk','105 BPM','Tight'],['Reggaeton','96 BPM','Bright'],['Drum & bass','172 BPM','Bright']],y,[196,151,156]) +y=p('A garde la base. B ajoute un fill de toms en fin de deuxième mesure et un crash au début de cette mesure. Dans RYTHME, REC applique votre choix à l’arrêt. Un motif existant demande confirmation.',y) +y=p('Appliquer un style remplace seulement le motif de batterie et choisit son kit/swing : 32 pas, division 1/16. Cela ne modifie pas les trois instruments. Le tempo reste un conseil : le régler avec SELECT. Modifier la longueur ou le swing après l’application si souhaité.',y) +y=heading('Cinq couleurs de kit',y-4) +y=p('ORIGINAL : son existant, équilibré.
DEEP : accordage plus grave et aigus adoucis.
TIGHT : enveloppe raccourcie, frappes plus sèches.
BRIGHT : accordage relevé, caractère plus vif.
DUST : accordage légèrement abaissé, filtre et grain numérique.',y) +y=p('Ces couleurs traitent la même base de samples ; ce ne sont pas cinq banques enregistrées séparément. Le changement agit sur les nouvelles frappes. Le kit se sauvegarde avec la section.',y) +C.showPage() + +title(4,'Assembler une chanson','Une chaîne jusqu’à 16 entrées, avec quatre sections A, B, C et D réutilisables.') +shot('song-screen',346,488,203) +y=700 +y=p('1. Mémoriser les sections
À l’arrêt, HOME puis SAVE. KNOB 2 choisit A-D. REC mémorise les sons et les motifs des quatre pistes. Deux REC sous 3 secondes remplacent une section occupée.',y,w=278) +y=p('2. Construire l’ordre
KNOB 1 : entrée de la chaîne.
KNOB 2 : section A-D.
KNOB 3 : durée, de 1 à 64 mesures.
KNOB 4 : nombre d’entrées, de 1 à 16.',y,w=278) +y=min(y,465) +y=p('3. Sauvegarder et écouter
SAVE mémorise l’ordre ; REC mémorise le contenu d’une section. OCT- passe de BOUCLE à SONG ; PLAY lance la chanson. Toutes les sections utilisées doivent exister. Arrêt automatique à la fin.',y) +y=p('Exemple : A pendant 4 mesures → B pendant 8 → A pendant 4 → C pendant 8. OCT+ recharge la section sélectionnée pour la modifier. Pour composer à nouveau, arrêter et revenir en BOUCLE.',y) +y=heading('Pour aller plus loin',y-2) +y=p('Sur une piste mélodique, SEQ ouvre STEP/PATTERN. STEP : KNOB 1 = pas, 2 = transposition, 3 = note/liaison/silence, 4 = accent/slide ; EDIT efface le pas. ENV, LFO, FX et EDIT donnent accès au son détaillé. HOME maintenu ouvre le menu. Les écrans avancés conservent des libellés Felucca.',y) +y=p('Limites pratiques : 8 voix de synthèse partagées + 6 voix de batterie. Quatre emplacements de section et un ordre de chanson sauvegardé. Tempo et effets globaux communs ; les motifs repartent ensemble à chaque section.',y) +y=heading('Version et secours',y-2) +y=p('Studio 0.3 conserve le secours USB expérimental : maintenir OCT- seul pendant l’allumage. Ce secours dépend d’un firmware suffisamment intact et ne garantit pas la récupération. Les nouveautés de 0.3 sont testées sur ordinateur ; leur essai sur ton FM-1 reste à faire. Studio 0.2 est conservé dans build/releases/studio-0.2-dev/.',y,size=9) +C.showPage();C.save();print(OUT) diff --git a/tools/sampleio.py b/tools/sampleio.py new file mode 100644 index 0000000..29eb0b7 --- /dev/null +++ b/tools/sampleio.py @@ -0,0 +1,295 @@ +# SPDX-License-Identifier: GPL-3.0-only +# Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments +"""Sample helpers shared by gen_samples.py (built-in sets), fm1_sample_upload.py +(user slots) and tests/pitch.py. The web editor (web/editor.html) has a JS port of +read_any_wav / resample / ima_encode / user_slot that must give the same bytes +(web/test_web.mjs checks it). + +The float arithmetic here is part of the generated output: keep the order of +operations (and Python's sum() where it is used) when touching these functions. +""" +import math +import re +import struct +import sys +import zlib +from functools import reduce +from operator import add, sub + +IMA_STEP = [7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 19, 21, 23, 25, 28, 31, 34, 37, 41, 45, 50, 55, 60, 66, 73, 80, 88, + 97, 107, 118, 130, 143, 157, 173, 190, 209, 230, 253, 279, 307, 337, 371, 408, 449, 494, 544, 598, 658, + 724, 796, 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066, 2272, 2499, 2749, 3024, 3327, 3660, + 4026, 4428, 4871, 5358, 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899, 15289, 16818, + 18500, 20350, 22385, 24623, 27086, 29794, 32767] +IMA_IDX = [-1, -1, -1, -1, 2, 4, 6, 8] + + +def wav_chunks(d): + """RIFF/WAVE chunks -> {id: (offset of the body, declared length)}; the first of each id wins""" + if len(d) < 12 or d[:4] != b"RIFF" or d[8:12] != b"WAVE": + raise ValueError("not a WAV file") + out, i = {}, 12 + while i + 8 <= len(d): + cid, n = d[i:i + 4], struct.unpack_from(" (tag, channels, rate, bits); WAVE_FORMAT_EXTENSIBLE resolved to its subformat""" + if b"fmt " not in ch: + raise ValueError("WAV without a fmt chunk") + o = ch[b"fmt "][0] + tag, nch, sr = struct.unpack_from(" (rate, samples, (loop start, loop end) from 'smpl' or None)""" + d = path.read_bytes() + ch = wav_chunks(d) + tag, nch, sr, bits = wav_format(d, ch) + if bits != 16: + raise ValueError(f"{path}: {bits}-bit, expected 16") + o, n = ch.get(b"data", (0, 0)) + s = list(struct.unpack_from("<%dh" % (min(n, len(d) - o) // 2), d, o))[::nch] + loop = None + if b"smpl" in ch: + o = ch[b"smpl"][0] + if struct.unpack_from(" (rate, [float]). + A truncated data chunk is fine.""" + d = path.read_bytes() + ch = wav_chunks(d) + tag, nch, sr, bits = wav_format(d, ch) + bps = bits // 8 + if tag not in (1, 3) or not bps or not nch: + raise ValueError(f"{path}: unsupported WAV format (tag {tag}, {bits} bit)") + o, n = ch.get(b"data", (0, 0)) + frame = bps * nch + nfr = min(n, len(d) - o) // frame + v = _channel_values(tag, bps, d[o:o + nfr * frame]) + if nch == 1: + return sr, v + if nch == 2: # (0.0 + l + r) / 2, as the per-channel sum below + return sr, [(a + b) / 2 for a, b in zip(v[0::2], v[1::2])] + out = [] + for f in range(0, len(v), nch): + acc = 0.0 + for c in range(nch): + acc += v[f + c] + out.append(acc / nch) + return sr, out + + +def resample(x, sr, to): + """crude anti-alias (moving average over the ratio), then linear interpolation""" + if sr == to: + return x + if sr > to: + k = max(1, int(round(sr / to))) + if k == 2: + x = [(a + b) / 2 for a, b in zip(x, x[1:])] + [x[-1] / 2] if x else [] + elif k > 1: # left to right like the editor (not sum(): compensated + x = [reduce(add, x[i:i + k]) / k for i in range(len(x))] # since Python 3.12) + step, out, p, last = sr / to, [], 0.0, len(x) - 1 + append = out.append + while p < last: + i = int(p) + f = p - i + append(x[i] * (1 - f) + x[i + 1] * f) + p += step + return out + + +def _diff_py(w, W, hi): + """d[tau] = sum((w[i] - w[i + tau]) ** 2 for i in range(W)), tau = 1..hi+1""" + head, two = w[:W], [2] * W + return [0.0] + [sum(map(pow, map(sub, head, w[tau:tau + W]), two)) for tau in range(1, hi + 2)] + + +def _diff_np(w, W, hi): + """_diff_py with numpy, all lags at once. Python >= 3.12 sums floats with Neumaier + compensation (Objects/bltinmodule.c builtin_sum); this runs the same steps in the same + order per lag, so the results are the same doubles.""" + a = np.asarray(w, dtype=np.float64) + taus = np.arange(1, hi + 2) + f = (a[0] - a[taus]) ** 2 # sum() starts at int 0: 0 + x == x for x >= 0 + c = np.zeros_like(f) + for i in range(1, W): + x = (a[i] - a[i + taus]) ** 2 + t = f + x + c += np.where(np.abs(f) >= np.abs(x), (f - t) + x, (x - t) + f) + f = t + f = np.where(c != 0, f + c, f) + return [0.0] + f.tolist() + + +try: + import numpy as np + if sys.version_info < (3, 12): # plain left-to-right sum() there + raise ImportError + _diff = _diff_np +except ImportError: + _diff = _diff_py + + +def yin(w, sr, fmax=2000, fmin=30, threshold=0.15, interpolate=True): + """YIN (cumulative-mean-normalised difference) over the window w: the first dip under + the threshold between the periods of fmax and fmin, else the deepest -> Hz""" + W = len(w) // 2 + lo, hi = max(2, int(sr / fmax)), min(W - 1, int(sr / fmin)) + d = _diff(w, W, hi) + cm, run = [1.0] * (hi + 2), 0.0 + for tau in range(1, hi + 2): + run += d[tau] + cm[tau] = d[tau] * tau / run if run else 1.0 + tau = next((t for t in range(lo, hi) if cm[t] < threshold and cm[t] <= cm[t + 1]), None) + if tau is None: + tau = min(range(lo, hi), key=lambda t: cm[t]) + if interpolate and 1 <= tau < hi: + y0, y1, y2 = cm[tau - 1], cm[tau], cm[tau + 1] + den = y0 - 2 * y1 + y2 + tau = tau + (0.5 * (y0 - y2) / den if den else 0) + return sr / tau + + +def detect_hz(x, sr): + """pitch of a recording: YIN on 3000 samples from 0.15 s in (or the last 3000)""" + a = int(0.15 * sr) + return yin(x[a:a + 3000] if len(x) > a + 3000 else x[-3000:], sr) + + +def hz_to_midi(hz): + return 12 * math.log2(hz / 440.0) + 69 + + +def peak(x, floor=1e-9): + return max(floor, max(map(abs, x))) + + +def onset(x, rel=0.02): + """index of the first sample above rel x peak""" + thr = rel * peak(x) + return next((i for i, v in enumerate(x) if abs(v) > thr), 0) + + +def ima_encode(samples, loop_start): + """IMA ADPCM, 4 bit, low nibble first, from predictor 0 / index 0 + -> (bytes, (predictor, index) at loop_start)""" + pred, idx, nib, state_at_loop = 0, 0, bytearray(), (0, 0) + steps, adj = IMA_STEP, IMA_IDX + for n, x in enumerate(samples): + if n == loop_start: + state_at_loop = (pred, idx) + step = steps[idx] + diff = x - pred + code = 0 + if diff < 0: + code = 8 + diff = -diff + vd = step >> 3 + if diff >= step: + code |= 4 + diff -= step + vd += step + if diff >= step >> 1: + code |= 2 + diff -= step >> 1 + vd += step >> 1 + if diff >= step >> 2: + code |= 1 + vd += step >> 2 + pred = pred - vd if code & 8 else pred + vd + if pred > 32767: + pred = 32767 + elif pred < -32768: + pred = -32768 + idx += adj[code & 7] + if idx < 0: + idx = 0 + elif idx > 88: + idx = 88 + nib.append(code) + if len(nib) & 1: + nib.append(0) + return bytes(a | (b << 4) for a, b in zip(nib[0::2], nib[1::2])), state_at_loop + + +def key_split(roots): + """sorted root notes -> [(lo, hi)]: each zone reaches halfway to its neighbours, the + outer zones to the ends of the keyboard""" + n = len(roots) + return [(0 if j == 0 else (roots[j - 1] + r) // 2 + 1, 127 if j == n - 1 else (r + roots[j + 1]) // 2) + for j, r in enumerate(roots)] + + +# ---- user sample slots (firmware/src/eng_sample.c, web/EDITOR_PROTOCOL.md) +SLOT_SIZE, SLOT_DATA_OFF, SLOT_RATE, SLOT_ZONES = 0x14000, 512, 22050, 16 +SLOT_HDR_LEN = 32 + SLOT_ZONES * 28 +SLOT_MAX_DATA = SLOT_SIZE - SLOT_DATA_OFF + + +def note_from_name(name, default=60): + """"C4" / "F#3" / "Bb2" in a file name, C4 = 60 (as the web editor), clamped to 0..127""" + m = re.search(r"(? int16 list, peak normalised to 30000""" + pk = peak(x) + return [max(-32768, min(32767, int(v / pk * 30000))) for v in x] + + +def user_slot(name, zones): + """zones: [(int16 samples at SLOT_RATE, root, lo or None, hi or None)] -> (header bytes, ADPCM data). + Zones without lo/hi split the keyboard between their roots.""" + zs, data = [], bytearray() + for s, root, lo, hi in zones: + adp, st = ima_encode(s, 0) + zs.append(dict(off=len(data), n=len(s), ls=0, le=len(s) - 1, root=root, lo=lo, hi=hi, pred=st[0], idx=st[1])) + data += adp + if len(data) > SLOT_MAX_DATA: + raise ValueError(f"too long: {len(data)} B of ADPCM, a slot holds {SLOT_MAX_DATA} B " + f"({SLOT_MAX_DATA * 2 / SLOT_RATE:.1f} s in all)") + if not 1 <= len(zs) <= SLOT_ZONES: + raise ValueError(f"1..{SLOT_ZONES} files per slot") + zs.sort(key=lambda z: z["root"]) + for z, (lo, hi) in zip(zs, key_split([z["root"] for z in zs])): + if z["lo"] is None: + z["lo"], z["hi"] = lo, hi + rate = int(round(SLOT_RATE / 44100 * 65536)) + zb = b"".join(struct.pack("<5I2h4B", z["off"], z["n"], z["ls"], z["le"], rate, z["root"] * 16, z["pred"], + z["idx"], z["lo"], z["hi"], 0) for z in zs) + nm = re.sub(r"[^\x20-\x7E]", "", name.upper())[:8].encode().ljust(8, b"\0") + hdr = struct.pack(" F7`: + +- `7D` is the non-commercial SysEx ID. +- `46 4C` is "FL". + +Every request gets exactly one reply, with the same header and the same ``. Requests +the device does not understand get no reply. Every data byte is 7 bit. While the editor +watches (v2, `WATCH`), the device also sends push frames (cmds 23, 24, 26) at any time. + +| Item | Encoding | +| --- | --- | +| value (v14) | 2 bytes, LSB first, holding value + 8192, so the range is -8192..8191. `[lo, hi]`: value = (lo \| hi << 7) − 8192 | +| string | ASCII bytes, ended by a 0 byte | +| scope | 0 = parameter of the selected track (`P_*`, 0..P_COUNT−1); 1 = global parameter (`G_*`, 0..G_COUNT−1) | +| track | 0..3: tracks 1..3 (synth parts), 3 = the drum track | +| engine byte | 0..NENGINES−1; NENGINES = the drum track (it has no engine and no presets) | + +The engine parameters are `P_E0..P_E7`: P_COUNT−8 .. P_COUNT−1, and `INFO` gives `P_E0`. +Their meaning, range and names depend on the current engine, so re-read `DESC` for them +after an engine change. + +## Commands + +| cmd | Request args | Reply args | +| --- | --- | --- | +| 1 INFO | — | version string, NENGINES, P_COUNT, G_COUNT, NSTEP, P_E0, then NENGINES engine-name strings, then (v3) NTRK (4), then (v5) the protocol version (5); older firmware ends after the names / NTRK | +| 2 GET | scope, id | scope, id, v14 | +| 3 SET | scope, id, v14 | scope, id, v14 (the value after clamping). Setting global `G_ENGSEL` (id from DESC label "ENG") changes the engine with its defaults | +| 4 DUMP | — | engine, preset, then P_COUNT × v14 (the selected track), then G_COUNT × v14 (globals) | +| 5 DESC | scope, id | scope, id, fmt, min v14, max v14, def v14, label string, unit string, then for an enum (fmt 8) one name string per value (at most 64; firmware before SLOOP sent at most 16) | +| 6 STEP_GET | index 0..NSTEP−1 | index, n (0..4 notes), note0..note3, time (0 NOTE, 1 TIE, 2 REST), flags (1 accent, 2 slide), vel, then (v5) lvl, hi, rat | +| 7 STEP_SET | index, n, note0..3, time, flags, vel [, lvl, hi, rat (v5)] | same as STEP_GET (after the write). Without the v5 bytes the step's levels and ratchets become 0 | +| 8 PRESET | engine, preset | engine, preset (applies the preset: sound, sends, arp; never the pattern, the mix or the key: `LEVEL PAN MUTE`, `LEN DIV SWG GATE`, `ROOT SCL QNT CHORD` stay) | +| 9 PROJECT | op (0 load, 1 save, 2 query), slot 0..3 | op, slot, used (1/0). Save writes flash: allow ~2 s | + +The local Studio build may append status `1` to a PROJECT reply when playback +prevents a load/save. No operation occurred; stop playback and try again. +An absent status byte retains the original reply format. +| 10 NAMES | engine | engine, count, count preset-name strings, then the two edit-page titles | +| 11 SMP_BEGIN | slot 0..2 | slot, rc (0 ok). Erases the slot's header sector: the slot is empty from now on | +| 12 SMP_WRITE | slot, offset (3 × 7 bit, LSB first), pack7 data (≤ 256 bytes) | slot, offset, rc: 0 ok, 1 arguments, 2 erase, 3 write, 4 slot in use (send SMP_BEGIN first). Offset ≥ 512 and a multiple of 256; writes go in increasing order (a write at a 4 KiB boundary erases that sector) | +| 13 SMP_END | slot, pack7 header (480 bytes) | slot, rc: 0 ok, 1 size, 2 header, 3 data CRC, 4 flash, 5 zones | +| 14 SMP_ERASE | slot | slot, rc (erases the whole slot, ~1 s) | +| 15 SMP_INFO | — | slots, slot KiB, then per slot: zone count (0 = empty), name string, data KiB | +| 16 UP_LIST | start, count (1..16) | start, count, total slots, then per slot: used (0/1), engine, name string ("" if unused) | +| 17 UP_GET | slot | slot, used, engine, name, P_COUNT × v14, 16 × (note, flags) | +| 18 UP_PUT | slot, engine, name, P_COUNT × v14, 16 × (note, flags) | slot, rc (0 ok, 1 args, 2 flash). Writes flash: allow 1 s | +| 19 UP_STORE | slot, name | slot, rc. Stores the current sound: engine, parameters, the first 16 sequencer steps as the pattern (TIE steps → flag 4) | +| 20 UP_LOAD | slot | slot, rc (0 ok, 1 empty/invalid). Applies it | +| 21 UP_ERASE | slot | slot, rc | +| 22 WATCH | on (0/1; v4: 3 = also `TRACK_CHANGED`) | on (0/1; v4 firmware: 3 when 3 was asked for). While on, the device pushes cmds 23, 24, 26 (and 32 with bit 1) | +| 23 CHANGED (push) | — | scope, id, v14 | +| 24 RELOAD (push) | — | engine, preset, then (v3) the selected track | +| 25 PING | — | 0 | +| 26 STEP_CHANGED (push) | — | index, then (v3) the selected track | + +| cmd (v3) | Request args | Reply args | +| --- | --- | --- | +| 27 TRACK | — (query), or track (select it) | selected track, NTRK, then per track: engine byte, preset, level v14, mute (0/1), armed (0/1, live recording) | +| 28 TRACK_MIX | track (get), or track, level v14 (0..127), mute (set) | track, level v14, mute. The drum track's level is global `G_DRLVL` (GLO > DRUMS LEVEL); mute is the track's `P_MUTE` | +| 29 TRACK_DUMP | track | track, engine byte, preset, P_COUNT × v14 (that track's parameters; no globals) | +| 30 TRACK_STEP | track, index (get), or track, index, n, note0..3, time, flags, vel [, lvl, hi, rat] (set) | track, index, n, note0..3, time, flags, vel, then (v5) lvl, hi, rat | + +| cmd (v4) | Request args | Reply args | +| --- | --- | --- | +| 31 TRACK_PARAM | track, id (get), or track, id, v14 (set); id = `P_*` (0..P_COUNT−1) | track, id, v14 (the value after clamping, as `SET`). The selection does not change; no push about the editor's own write | +| 32 TRACK_CHANGED (push) | — | track, id, v14: `P_LEVEL`, `P_PAN` or `P_MUTE` of a track that is not selected changed on the device (only while `WATCH` was sent with bit 1) | + +| cmd (v5) | Request args | Reply args | +| --- | --- | --- | +| 33 DRUM_STEP | index (get), or index, on (3 bytes), lvl (5 bytes), rat (5 bytes) (set) | index, on (3 bytes), lvl (5 bytes), rat (5 bytes): the drum track's step, whichever track is selected | + +**pack7:** groups of up to 7 bytes, each preceded by one byte holding their top bits +(bit j = bit 7 of byte j). + +**User sample slot** (80 KiB each, SAMPLE engine sets USR1..USR3; reference uploader +`tools/fm1_sample_upload.py`, slot builder `sampleio.user_slot`; the editor's port of it is +checked byte for byte by `web/test_web.mjs`): header at 0, ADPCM data at 512. + +| Offset | Field | +| --- | --- | +| 0 | magic `"FSMP"` (u32 0x504D5346), u16 version 1, u8 zone count 1..16, u8 0 | +| 8 | name, 8 ASCII bytes (0-padded) | +| 16 | u32 data length (bytes), u32 CRC-32 (zlib) of the data, 8 bytes 0 | +| 32 | 16 zones × 28 bytes: u32 off (in the data), n (samples), loop start, loop end, rate (Hz / 44100 × 65536); i16 root × 16 (MIDI note), ADPCM predictor at the loop start; u8 step index at the loop start, lo note, hi note, looped (0/1) | + +Data is IMA ADPCM, 4 bit, low nibble first, starting from predictor 0 and step index 0. +All little endian. + +`fmt` values (`firmware/src/core.h`): + +| Value | Name | Value | Name | Value | Name | +| --- | --- | --- | --- | --- | --- | +| 0 | INT | 5 | CUTOFF | 10 | NOTE | +| 1 | PCT | 6 | DB | 11 | ONOFF | +| 2 | BIPCT | 7 | SEMI | 12 | OCT | +| 3 | TIME | 8 | ENUM | 13 | STEPS | +| 4 | LFOHZ | 9 | BPM | 14 | SWING | +| | | | | 15 | FILT | + +v5 formats: **SWING** 0..100 shown as the MPC swing, 50 % (straight) + value / 4 (so 75 % at 100); +**FILT** −64..63: 0 OFF, below 0 a low-pass closing (LP 1..100 %), above 0 a high-pass (HP 1..100 %). +**PCT** is the share of the range: value × 100 / max (rounded). + +The editor should show the value with the unit; formatting it exactly like the device does +is not required. + +## v2: user presets + +A user preset = engine (0..NENGINES−1), name (1..12 chars, ASCII 32..126; the device shows it upper +case), all P_COUNT instrument parameters (v14 each, the same order as `DUMP`), and a 16-step pattern: +16 × (note 0..127 (0 = rest), flags: 1 accent, 2 slide, 4 tie). Loading one applies the engine and +the parameters of the sound; the pattern stored with it is never loaded (changing a sound never changes +the sequence), and the mix, pattern and key parameters stay (as `PRESET`). The slots are numbered 0..31 +(the device shows U01..U32). + +- `UP_LIST`: count is cut at 16 and at the last slot (start ≥ 32: count 0, no entries). +- `UP_GET` of an empty slot has the same shape with used 0, engine 0, name "" and all values 0. + Values come back in the current parameter order, inside their ranges. +- `UP_PUT`: rc 1 for a slot ≥ 32, an engine ≥ NENGINES, a name that is empty, longer than 12 or has + bytes outside 32..126, or a frame that is too short. Values are clamped to their ranges for that + engine. A note with flag 4 is stored as a tie (note 0); flags on a rest are dropped. +- `UP_STORE`: name "" stores with the automatic name the device uses (engine name + slot number, + "ANALOG 07"). rc 1 for a bad slot or name. +- rc 2 = the flash write failed or there is no flash; the slot is still changed in RAM until power-off. +- Frames stay below 640 bytes (`UP_PUT` is 5 + 1 + 1 + 13 + 2 × P_COUNT + 32 + 1). + +**On the device:** SAVE > USER page: KNOB 1 picks the slot, KNOB 2 LOAD, KNOB 3 ERASE, KNOB 4 SAVE +(one detent arms, a second one within ~1.5 s acts, as PROJECT LOAD / SAVE). SAVE uses the automatic +name. SELECT and the SAVE > PRESETS browser continue past the factory presets into the used user +presets. + +**Flash** (`firmware/src/upreset.c`): two storage objects (`OBJ_UPRESET0/1`, A/B sector pairs at +0xDC000..0xDFFFF), 16 records of 192 bytes each, behind a bank header (magic "UPB1", record size, +slot count; a mismatch reads as an empty bank). A record keeps its layout version (mismatch: empty) +and the P_COUNT it was stored with; another count is mapped by count (last 8 values = P_E0..P_E7, the +first ones = P_LEVEL.. in order, missing ones = defaults). P_COUNT was 53 (P_E0 45) until the SLICER +parameters (SLCR, PAT, RATE, DEPTH: ids 45..48) went in just before P_E0: P_COUNT 57, P_E0 49; SLOOP 2.0 +added CHORD (id 49): P_COUNT 58, P_E0 50 (and G_COUNT 32: DUST, DUCK, FILT, ROLL, NEW at 27..31). An +editor takes them from `INFO`; older records load with the SLICER off and CHORD off. + +## v2: live sync + +- `WATCH 1` starts the pushes. Watching ends by itself 3 s after the last request of any kind (send + `PING` about every 1 s), on a USB reset, and when the host goes away; `WATCH 0` ends it at once. +- **CHANGED** (scope, id, v14): a parameter changed on the device (knob, menu, sequencer edit of a + `P_*`), not by the editor's own `SET`. Coalesced: each (scope, id) at most every 20 ms, with the + latest value. +- **RELOAD** (engine, preset): the engine, a preset, a user preset or a project was loaded; re-read + `DESC` of the engine parameters, `DUMP` and the steps. It is also sent after loads the editor asked + for (`SET` of G_ENGSEL, `PRESET`, `PROJECT` load, `UP_LOAD`). +- **STEP_CHANGED** (index): a sequencer step changed on the device (record, clear, step edit, + pattern load); not after the editor's own `STEP_SET`. +- Push frames have the normal header. Accept them at any time, also while waiting for a reply: + match replies by cmd (23, 24 and 26 are never replies). The device sends at most a few per + ~5 ms pass, and only when its USB send queue has room, so a push never delays a reply. + +## v3: tracks + +- The drum track: `DUMP` / `RELOAD` / `TRACK` give the engine byte NENGINES. Its `P_*` values exist + (the pattern parameters `LEN DIV SWG GATE`, `PAN`, `MUTE` and `P_E0`, the kit, are used; the rest is + ignored). `PRESET`, `SET` of `G_ENGSEL` and `UP_LOAD` do nothing there (`UP_LOAD` and `UP_STORE` answer + rc 1). `DESC` of `P_E0` is the enum `KIT`; `P_E1..P_E7` describe engine 0. Its steps hold the 16 drum + lanes (v5, `DRUM_STEP`); the v1-v4 step commands see them as GM notes (up to 4 per step). +- Selecting a track with `TRACK` does not push `RELOAD` (the editor re-reads `DUMP`, the steps and the + engine `DESC` itself); selecting one on the device does (`RELOAD` with the new track). +- Pushes are about the selected track only: `CHANGED` (scope 0) and `STEP_CHANGED` refer to it, and + changes to other tracks (live recording from MIDI into another track, `TRACK_*` writes) push nothing. +- Level and mute are also `P_LEVEL` / `P_MUTE` of the selected track (`SET`); `TRACK_MIX` reaches the + others. Presets and user presets change a part's sound but keep its mix (`P_LEVEL`, `P_PAN`, + `P_MUTE`), its pattern parameters (`LEN DIV SWG GATE`) and its key (`ROOT SCL QNT`, `CHORD`). +- Projects (`PROJECT`) save and load all four tracks and the selection (SLOOP 2.0: project format 4, + "FUN4", with the drum lanes, levels and ratchets; formats 3, 2 and 1 from older firmware are converted + when loaded, a format 1 project into track 1). +- Older firmware (no NTRK in `INFO`): one instrument; skip the track UI. + +## v4: any track's parameters + +- **Finding out:** send `WATCH 3`. v4 firmware answers 3; v3 (0.8) firmware answers 1, does not know + cmds 31 / 32 (no reply) and never pushes `TRACK_CHANGED`. `WATCH 1` behaves exactly as in v2 / v3 + (reply 1, no `TRACK_CHANGED`). Match the `WATCH` reply by bit 0. +- `TRACK_PARAM` clamps like `SET` scope 0: to the range of that parameter; the engine parameters + `P_E0..P_E7` to the ranges of that track's engine (the drum track: `P_E0` the kit, the others engine 0, + as `DESC`). A parameter + with a fixed range (min = max) keeps its value. A track ≥ NTRK or an id ≥ P_COUNT gets no reply. + For the selected track it is the same as `SET` scope 0. The drum track's level is still `G_DRLVL` + (`SET` scope 1 or `TRACK_MIX`); its `P_LEVEL` is not used. +- `TRACK_CHANGED` is never about the selected track (its changes stay `CHANGED` scope 0). Coalesced like + `CHANGED` (each track and id at most every 20 ms, latest value), and not sent for the editor's own + `TRACK_PARAM` / `TRACK_MIX` writes. After a selection change (`RELOAD`, or the editor's `TRACK`) the + device takes the current values as known. + +## v5: drum lanes, levels, ratchets (SLOOP 2.0) + +- **Finding out:** `INFO` ends with 5. Older firmware ends after NTRK (or the engine names): use the + v1-v4 commands only. +- **Drum lanes** (`firmware/src/drums.c` `LANE_NOTE`), one per white key from F3: 0 kick (36), 1 kick 2 + (35), 2 snare (38), 3 clap (39), 4 hat (42), 5 open hat (46), 6 pedal (44), 7 rim (37), 8 snare 2 (40), + 9 low tom (43), 10 hi tom (48), 11 crash (49), 12 ride (51), 13 shaker (70), 14 conga (63), 15 cowbell + (56). A black key plays the lane of the white key left of it. +- **Levels** (2 bits): 0 NORM (as played), 1 GHOST, 2 SOFT, 3 HARD. **Ratchets** (2 bits): 0..3 = x1..x4 + hits in the step. +- **`DRUM_STEP`:** `on` is 16 bits (bit l = lane l), sent as 3 × 7 bits LSB first; `lvl` and `rat` are + 32 bits each (lane l in bits 2l..2l+1), sent as 5 × 7 bits LSB first. A set replaces the whole step; + the lanes that are off read back with level and ratchet 0. An index ≥ NSTEP gets no reply. Not a push: + `STEP_CHANGED` with the drum track selected means "re-read `DRUM_STEP` of that index". +- **The drum track through the old commands:** `STEP_GET` / `TRACK_STEP` give its first 4 lanes that are + on as GM notes (lane order), time NOTE (REST if none), flag 1 (accent) if one of them is HARD, vel 100, + and lvl / hi / rat 0. A `STEP_SET` / `TRACK_STEP` write puts each note on its nearest lane (GM 35..81, + `LANE_OF_GM`), level HARD if the accent flag is set, else NORM, ratchet x1; time TIE / REST clears the + step. +- **Synth steps:** `lvl` holds 2 bits per note (note k in bits 2k..2k+1, the same levels), `rat` 2 bits per + note (x1..x4); both 8 bits, sent as 7-bit bytes with their top bits in `hi` (bit 0: lvl bit 7, bit 1: + rat bit 7). +- **`TRACK`** ends with the solo mask (bit per track; GLO + key on the device). A soloed track plays, + the others are faded out unless soloed too; mute and solo do not change `P_MUTE` of other tracks. +- **The kit** is the drum track's `P_E0`: `DESC` of `P_E0` with the drum track selected is the enum + `KIT` (34 kits: ORIGINAL..DUST, the GM sample kit and its treatments, then the synthesised kits from + 808). `DESC` of `P_E1..P_E7` there still describes engine 0 (unused). + +## Notes for the editor + +- **One request at a time.** Wait for the reply, about 10–50 ms, before sending the next. + The device holds only one incoming SysEx frame. +- **Following the device.** With v2 firmware, `WATCH` and `PING` (above). Older firmware pushes + nothing (no reply to `PING`): poll `DUMP` about every 300–500 ms while the page is visible. +- **Port.** The device's MIDI port is named "Felucca" (USB 1209:0001; SLOOP keeps the name so editors + and installers find it). Updates use the same + port with other SysEx (the `F0 22 24 35 …` keys, `00 59 …` frames); never send those + from the editor. +- **Safety.** Only `PROJECT` save, the sample-slot commands and `UP_PUT` / `UP_STORE` / `UP_ERASE` write flash, and only in + Felucca's own storage; never the app or the update area. diff --git a/web/FUKIAI-LICENSE.txt b/web/FUKIAI-LICENSE.txt new file mode 100644 index 0000000..3c7989e --- /dev/null +++ b/web/FUKIAI-LICENSE.txt @@ -0,0 +1,23 @@ +Fukiai icon font (fukiai.ttf), used by the Felucca web editor. + +MIT License + +Copyright (c) 2026 Hügelton Instruments + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/web/editor.html b/web/editor.html new file mode 100644 index 0000000..8b071ed --- /dev/null +++ b/web/editor.html @@ -0,0 +1,4044 @@ + + + + + + + +SLOOP Editor + + + +
+ +

SLOOP Editor

+

+ +
+
+ + + + +
+
+ + +
+ + + + + + + + + + + + + + + + + +
SLOOP, based on Felucca by Leo Kuroshita (@kurogedelic), Hügelton Instruments. GPL-3.0.
+ M-VAVE and FM-1 are trademarks of their respective owners.
+
+
+ + + diff --git a/web/fm1ota.js b/web/fm1ota.js new file mode 100644 index 0000000..57d62e3 --- /dev/null +++ b/web/fm1ota.js @@ -0,0 +1,223 @@ +// SPDX-License-Identifier: GPL-3.0-only +// Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments +// +// The FM-1 USB-MIDI update protocol (M-UPGRADE compatible) over WebMIDI. +// Step 1: the running firmware reads parts of the package and stages the update +// loader. Step 2: the loader reads the whole image and writes it. In both steps +// the device sends cmd 0x30 read requests on the logical image and we answer. + +const HS_QUERY = [0xF0, 0x00, 0x32, 0x45, 0x00, 0x00, 0x00, 0x40, 0x7F, 0xF7]; +const UPGRADE = [0xF0, 0x22, 0x24, 0x35, 0x7F, 0xF7]; +const MAXDATA = 512; +const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); +const IS_OTA = (id) => /^ota-/i.test(id.model); +// the update loader of SLOOP / Felucca packages ("ota-FM-1_9XX"). A device left in the update mode of another +// firmware (the stock updater's loader) is never written: its loader may lay the image out differently. +export const OUR_LOADER = (id) => /^ota-FM-1_9\d\d$/i.test(id.text); + +// errors carry a code the pages translate: notfound, model, stopped, noloader, lost, noreturn, +// mismatch (detail: the identity the device reports), badreq, foreign (detail: the loader's identity) +function fail(code, msg, detail = "") { const e = new Error(msg); e.code = code; e.detail = detail; return e; } + +export function pack7(data) { + const out = []; let acc = 0, nb = 0; + for (const b of data) { + acc |= b << nb; nb += 8; + while (nb >= 7) { out.push(acc & 0x7F); acc >>>= 7; nb -= 7; } + } + if (nb) out.push(acc & 0x7F); + return out; +} + +export function unpack7(s) { + const out = []; let acc = 0, nb = 0; + for (const b of s) { + acc |= (b & 0x7F) << nb; nb += 7; + while (nb >= 8) { out.push(acc & 0xFF); acc >>>= 8; nb -= 8; } + } + return out; +} + +function response(addr, data, fl = 0) { + const len = data.length; + const body = [0x00, 0x59, 0x30, (len + 8) & 0xFF, ((len + 8) >> 8) & 0xFF, 0, fl, + addr & 0xFF, (addr >>> 8) & 0xFF, (addr >>> 16) & 0xFF, (addr >>> 24) & 0xFF, + len & 0xFF, (len >> 8) & 0xFF, 0, ...data]; + let s = 0; + for (let i = 6; i < body.length; i++) s += body[i]; + body.push(~s & 0xFF); + return [0xF0, ...pack7(body), 0xF7]; +} + +function parseRequest(pkt) { + if (pkt[0] !== 0xF0 || pkt[pkt.length - 1] !== 0xF7) return null; + const u = unpack7(pkt.slice(1, -1)); + if (u.length !== 15 || u[0] !== 0 || u[1] !== 0x59 || u[2] !== 0x30) return null; + let s = 0; + for (let i = 6; i < 14; i++) s += u[i]; + if ((~s & 0xFF) !== u[14]) return null; + return { fl: u[6], addr: (u[7] | (u[8] << 8) | (u[9] << 16) | (u[10] << 24)) >>> 0, len: u[11] | (u[12] << 8) | (u[13] << 16) }; +} + +function parseIdentity(pkt) { + const d = unpack7(pkt.slice(1, -1)); + if (d.length !== 34 || d[0] !== 0 || d[1] !== 0x59 || d[2] !== 0x11) return null; + const txt = String.fromCharCode(...d.slice(6, 33)).replace(/\0+$/, ""); + const m = /^([^_]+)_(\d+)$/.exec(txt); + return m ? { text: txt, model: m[1], version: parseInt(m[2], 10) } : null; +} + +// one MIDI in/out pair with a SysEx queue +class Link { + constructor(input, output) { + this.input = input; this.output = output; this.q = []; this.waiter = null; + input.onmidimessage = (ev) => { + if (ev.data[0] !== 0xF0) return; + this.q.push(Array.from(ev.data)); + if (this.waiter) { const w = this.waiter; this.waiter = null; w(); } + }; + } + get lost() { return this.input.state === "disconnected" || this.output.state === "disconnected"; } + // false when the port is gone (unplugged): WebMIDI throws on a disconnected output + send(bytes) { + try { this.output.send(bytes); return true; } catch (_) { return false; } + } + drain() { this.q.length = 0; } + async read(ms) { + if (!this.q.length) { + let tm; + await Promise.race([new Promise((r) => { this.waiter = r; }), new Promise((r) => { tm = setTimeout(r, ms); })]); + clearTimeout(tm); + this.waiter = null; + } + return this.q.shift() || null; + } + close() { this.input.onmidimessage = null; } +} + +async function handshake(link, tries = 3) { + link.drain(); + for (let t = 0; t < tries; t++) { + if (!link.send(HS_QUERY)) return null; + const end = Date.now() + 1000; + while (Date.now() < end) { + const p = await link.read(end - Date.now()); + if (!p) break; + const id = parseIdentity(p); + if (id) return id; + } + } + return null; +} + +export class Updater { + constructor(access, log) { + this.access = access; + this.log = log || (() => {}); + } + + // every in/out pair with the same port name that answers the handshake + async find(filter) { + const outs = [...this.access.outputs.values()]; + for (const input of this.access.inputs.values()) { + if (input.state === "disconnected") continue; + if (!/fm-1|felucca|ota|composite|sinco|usb-midi/i.test(input.name || "")) continue; // never probe other gear + const output = outs.find((o) => o.name === input.name) || (outs.length === 1 ? outs[0] : null); + if (!output) continue; + try { await input.open(); await output.open(); } catch (_) { continue; } + const link = new Link(input, output); + const id = await handshake(link, 2); + if (id && (!filter || filter(id))) return { link, id, name: input.name }; + link.close(); + } + return null; + } + + async waitFor(filter, ms) { + const end = Date.now() + ms; + while (Date.now() < end) { + const dev = await this.find(filter); + if (dev) return dev; + await sleep(1000); + } + return null; + } + + // serve read requests until the device asks for one of the finish addresses; stops early + // when the port disappears (lost: true) instead of waiting out idleMs + async serve(link, image, finishAddr, idleMs, onProgress) { + let served = 0, last = Date.now(); + for (;;) { + const pkt = await link.read(1000); + if (!pkt) { + if (link.lost) return { served, finished: false, lost: true }; + if (Date.now() - last > idleMs) return { served, finished: false }; + continue; + } + const r = parseRequest(pkt); + if (!r) continue; + last = Date.now(); + if (r.addr === 0xE0000000 || r.addr === 0xF0000000) { + link.send(response(r.addr, [...new TextEncoder().encode("success"), 0])); + if (r.addr === finishAddr) return { served, finished: true }; + continue; + } + if (r.len > MAXDATA || r.addr + r.len > image.length) throw fail("badreq", `bad request ${r.addr.toString(16)}+${r.len}`); + await sleep(10); + if (!link.send(response(r.addr, Array.from(image.subarray(r.addr, r.addr + r.len)), r.fl))) { + return { served, finished: false, lost: true }; + } + served++; + if (onProgress) onProgress(served, r.addr); + } + } + + // full install: running firmware -> loader -> new firmware + async install(image, product, onStep) { + const step = onStep || (() => {}); + const dev = await this.find((id) => !IS_OTA(id)); + if (!dev) throw fail("notfound", "FM-1 not found (USB cable, and no other app using it?)"); + const [model] = product.split("_"); + if (dev.id.model !== model) { dev.link.close(); throw fail("model", `the device is ${dev.id.text}, the package is for ${product}`); } + step("start", dev.id.text); + dev.link.send(UPGRADE); + await sleep(2000); + const s1 = await this.serve(dev.link, image, 0xE0000000, 8000, (n) => step("verify", n)); + dev.link.close(); + if (!s1.finished) throw fail(s1.lost ? "lost" : "stopped", `the device ${s1.lost ? "was disconnected" : "stopped"} after ${s1.served} requests: nothing was written`); + step("loader"); + await sleep(3000); + const ota = await this.waitFor(IS_OTA, 30000); + if (!ota) throw fail("noloader", "the update loader did not appear. Replug the USB cable and press Install again: the device stays in update mode until it is finished."); + const s2 = await this.write(ota, image, step); + if (!s2.finished) throw fail(s2.lost ? "lost" : "stopped", `the loader ${s2.lost ? "was disconnected" : "stopped"} after ${s2.served} requests. Replug and press Install again to resume.`); + step("reboot"); + await sleep(3000); + const back = await this.waitFor((id) => !IS_OTA(id), 40000); + if (!back) throw fail("noreturn", "the device did not come back: power-cycle it"); + back.link.close(); + if (back.id.text !== product) throw fail("mismatch", `installed, but the device reports ${back.id.text}`, back.id.text); + step("done", back.id.text); + return back.id.text; + } + + // step 2 with the loader found by find()/waitFor() + async write(ota, image, step) { + ota.link.send(UPGRADE); + await sleep(2000); + const s2 = await this.serve(ota.link, image, 0xF0000000, 180000, (n) => step("write", n)); + ota.link.close(); + return s2; + } + + // resume: the device is already in update mode (loader) -> true when the write finished + async resume(image, onStep) { + const ota = await this.find(IS_OTA); + if (!ota) return false; + if (!OUR_LOADER(ota.id)) { + ota.link.close(); + throw fail("foreign", `the FM-1 is in the update mode of another firmware (${ota.id.text}): finish that update with its own updater`, ota.id.text); + } + return (await this.write(ota, image, onStep || (() => {}))).finished; + } +} diff --git a/web/fm1pkg.js b/web/fm1pkg.js new file mode 100644 index 0000000..0636fd5 --- /dev/null +++ b/web/fm1pkg.js @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: GPL-3.0-only +// Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments +// +// FM-1 .fwsc packages in the browser: the package identity and the image the +// device reads during an update. + +const BLOCKS = 20, BLK = 0x30, KEEP = 0x2F; + +// the package identity ("FM-1_904"): one marker byte after each of the first 20 blocks +export function productOf(fwsc) { + if (fwsc.length < BLOCKS * BLK) throw new Error("not an FM-1 package (too short)"); + let s = ""; + for (let i = 0; i < BLOCKS; i++) { + const m = fwsc[i * BLK + KEEP]; + if (m !== 0x7D) s += String.fromCharCode((m - i - 1) & 0xFF); + } + return s; +} + +// the image the device addresses during an update: the .fwsc without the 20 marker bytes +export function logicalImage(fwsc) { + const out = new Uint8Array(fwsc.length - BLOCKS); + for (let i = 0; i < BLOCKS; i++) out.set(fwsc.subarray(i * BLK, i * BLK + KEEP), i * KEEP); + out.set(fwsc.subarray(BLOCKS * BLK), BLOCKS * KEEP); + return out; +} diff --git a/web/fukiai.ttf b/web/fukiai.ttf new file mode 100644 index 0000000..46efd36 Binary files /dev/null and b/web/fukiai.ttf differ diff --git a/web/index_pkg.html b/web/index_pkg.html new file mode 100644 index 0000000..cca6343 --- /dev/null +++ b/web/index_pkg.html @@ -0,0 +1,208 @@ + + + + + + +SLOOP installer + + + +
+
+
+ +

Firmware for the M-VAVE FM-1

+

Hip-hop on the FM-1: four tracks to play live — three synths and a drum machine — 54 sounds from 808s to Rhodes, 34 drum kits, 16 punch-in effects. No factory patterns, nothing to load: everything you hear, you play.

+
+
54sounds: 808, rhodes, horns
+
34drum kits, 808 to chiptune
+
16punch-in fx: hold fx + key
+
recno click: the loop follows you
+
+

+

+

+ +

+

+  
+  
+

+

+

+ FM-1-transporter

+

+

www.m-vave.com/download

+

SLOOP is based on Felucca by Leo Kuroshita (@kurogedelic), Hügelton Instruments. + Hold OCT− alone while switching on for USB rescue.
+ Font: Terminus (Dimitar Toshkov Zhekov, SIL OFL 1.1). Samples: Versilian Studios VSCO-2 Community Edition and VCSL (CC0 1.0), and the Hügelton Sample Pack (© Hügelton Instruments, not CC0).
+ M-VAVE and FM-1 are trademarks of their respective owners; SLOOP is not affiliated with them.
+ github.com/hugelton/Felucca

+
+ + + diff --git a/web/make_site.py b/web/make_site.py new file mode 100644 index 0000000..926f760 --- /dev/null +++ b/web/make_site.py @@ -0,0 +1,86 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-3.0-only +# Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments +"""Make the site (GitHub Pages): + + index.html redirect to the installer + firmware/felucca-VER.fwsc the package + webapp/installer/index.html index_pkg.html with fm1pkg.js, fm1ota.js and the metadata inlined + webapp/editor/index.html editor.html (+ fukiai.ttf, FUKIAI-LICENSE.txt) + src/ not touched + + web/make_site.py build/felucca-X.Y.fwsc X.Y OUT_DIR + +The package identity (FM-1_9xx) is read from the package; the device reports it +after the install. +""" +import hashlib +import json +import re +import shutil +import sys +from pathlib import Path + +HERE = Path(__file__).resolve().parent +BLOCKS, BLK, KEEP = 20, 0x30, 0x2F + + +def strip_module(src): + src = re.sub(r"^export\s+", "", src, flags=re.M) + return re.sub(r"^import .*?;\n", "", src, flags=re.M) + + +def product_of(raw): + """the package identity: one marker byte after each of the first 20 blocks (fm1pkg.js productOf)""" + return "".join(chr((m - i - 1) & 0xFF) for i in range(BLOCKS) if (m := raw[i * BLK + KEEP]) != 0x7D) + + +def main(pkg, version, out): + pkg, out = Path(pkg), Path(out) + raw = pkg.read_bytes() + product = product_of(raw) + if not re.fullmatch(r"FM-1_9\d\d", product): + raise SystemExit(f"{pkg}: identity {product!r} is not a Felucca package (FM-1_9xx)") + if b"FELUCCA-LOADER-1" not in raw: # marker of firmware/loader + raise SystemExit(f"{pkg}: no Felucca update loader in it") + html = (HERE / "index_pkg.html").read_text(encoding="utf-8") + lib = strip_module((HERE / "fm1pkg.js").read_text(encoding="utf-8")) + "\n" + \ + strip_module((HERE / "fm1ota.js").read_text(encoding="utf-8")) + name = f"sloop-{re.sub(r'[^A-Za-z0-9.-]', '-', version)}.fwsc" + meta = json.dumps({"version": version, "product": product, "pkg": "../../firmware/" + name, + "sha256": hashlib.sha256(raw).hexdigest()}) # the page checks the download against it + for mark in ("/*LIB*/", "/*META*/"): + if html.count(mark) != 1: + raise SystemExit(f"index_pkg.html must contain {mark} once; update make_site.py") + html = html.replace("/*LIB*/", lib).replace("/*META*/", meta) + logo = HERE.parent / "assets" / "logo" / "sloop-logo.svg" # the SLOOP logo, inline + html = html.replace("", logo.read_text(encoding="utf-8") if logo.exists() else "SLOOP") + inst, ed, fw = out / "webapp" / "installer", out / "webapp" / "editor", out / "firmware" + for d in (inst, ed, fw): + d.mkdir(parents=True, exist_ok=True) + guide = HERE.parent / "output/pdf/Studio-0.3-guide-rapide-FR.pdf" + guide_link = "" + if guide.exists() and "--studio-guide" in sys.argv: # LIVE: that guide describes the removed RYTHME tab + shutil.copy(guide, out / guide.name) + guide_link = '

Guide rapide illustré (PDF, 4 pages)

' + html = html.replace("", guide_link) + for old in list(fw.glob("felucca-*.fwsc")) + list(fw.glob("sloop-*.fwsc")): # one package: the current one + old.unlink() + (inst / "index.html").write_text(html, encoding="utf-8") + shutil.copy(pkg, fw / name) + shutil.copy(HERE / "editor.html", ed / "index.html") + for f in ("fukiai.ttf", "FUKIAI-LICENSE.txt"): + if (HERE / f).exists(): + shutil.copy(HERE / f, ed / f) + (out / "index.html").write_text( + 'SLOOP' + '' + 'SLOOP installer\n', encoding="utf-8") + print(f"site: {out}: webapp/installer ({len(html)} B), webapp/editor, firmware/{name} ({len(raw)} B, {product})") + + +if __name__ == "__main__": + args = [a for a in sys.argv[1:] if a != "--studio-guide"] + if len(args) != 3: + sys.exit(__doc__) + main(*args) diff --git a/web/package.json b/web/package.json new file mode 100644 index 0000000..e986b24 --- /dev/null +++ b/web/package.json @@ -0,0 +1,4 @@ +{ + "private": true, + "type": "module" +} diff --git a/web/test_web.mjs b/web/test_web.mjs new file mode 100644 index 0000000..e181c31 --- /dev/null +++ b/web/test_web.mjs @@ -0,0 +1,765 @@ +// SPDX-License-Identifier: GPL-3.0-only +// Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments +// +// Node checks of the web pages' JS (no browser, no hardware). Run from the repo root: +// node web/test_web.mjs +// - editor.html: the protocol section (between PROTO-BEGIN/END) against its mock device (v1 commands, +// the user preset bank / librarian, library files, live pushes, older-firmware fallback, the v3 tracks +// and the mixer), its tab layout and ja/en strings, +// and the user-sample pipeline byte for byte against tools/sampleio.py +// - fm1pkg.js: productOf and logicalImage on build/felucca.fwsc (skipped without a build) +// - fm1ota.js: a full install and an unplug during the write against a simulated FM-1 + +import { execFileSync } from "node:child_process"; +import { existsSync, mkdtempSync, readFileSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { fileURLToPath } from "node:url"; +import vm from "node:vm"; +import { logicalImage, productOf } from "./fm1pkg.js"; +import { Updater, pack7, unpack7 } from "./fm1ota.js"; + +let failed = 0; +const ok = (cond, what) => { console.log(`${what.padEnd(64)} ${cond ? "ok" : "FAIL"}`); if (!cond) failed++; }; +const eq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]); +const PYTHON = process.env.PYTHON || (process.platform === "win32" ? "python" : "python3"); +const py = (code, ...args) => execFileSync(PYTHON, ["-c", code, ...args], { maxBuffer: 1 << 26 }); +const HERE = fileURLToPath(new URL(".", import.meta.url)); + +/* ------------------------------------------------------------ editor protocol --- */ +const html = readFileSync(join(HERE, "editor.html"), "utf8"); +const proto = html.slice(html.indexOf("/*PROTO-BEGIN*/"), html.indexOf("/*PROTO-END*/")); +const E = vm.runInNewContext(proto + ` +;({ frame, unframe, parse, req, Link, parseWav, resample, normalize, rootFromName, buildSlot, makeMockDevice, CMD, SMP, + CHOP, chopNovelty, chopHits, chopSnap, chopGrid, chopEqual, chopList, chopZones, wavFile, zipStore, crc32, + UP, bank, capturePatch, auditionPatch, startWatch, libraryFile, readLibraryFile, paramKeys, patternFromSteps, stepsFromPattern, upName, + mixer, GM_DRUM, drumName, parseNotes, fmtValue, F, DRUM_LANES, LV_NAMES, emptyDrum })`, +{ setTimeout, clearTimeout, setInterval, clearInterval, console, TextEncoder }); + +async function editorMock() { + const m = E.makeMockDevice(); + const inp = [...m.access.inputs.values()][0], out = [...m.access.outputs.values()][0]; + const link = new E.Link((d) => out.send(d), { timeout: 300 }); + inp.onmidimessage = (e) => link.receive(e.data); + const rq = async (r, o) => link.request(r, o); + const info = E.parse[E.CMD.INFO](await rq(E.req.info())); + ok(info.nengines === 9 && info.engines[5] === "VOICE" && info.engines[6] === "TRIO" && info.engines[7] === "WHEEL" && info.engines[8] === "GRAIN" && info.pcount === 58 && info.pe0 === 50 && info.engines[4] === "SAMPLE", + "editor: INFO"); + let descs = 0; + for (let i = 0; i < info.pcount; i++) if (E.parse[E.CMD.DESC](await rq(E.req.desc(0, i))).label) descs++; + ok(descs === info.pcount, "editor: DESC for every parameter"); + { + /* the SLICER (core.h P_SLCR..P_SLDEPTH = 45..48, just before P_E0): the mock as params.c has it, + and a factory preset turns it off as ui.c apply_preset_to does */ + const pc = readFileSync(join(HERE, "../firmware/src/params.c"), "utf8"); + const sd = []; + for (let i = 45; i < 49; i++) sd.push(E.parse[E.CMD.DESC](await rq(E.req.desc(0, i)))); + ok(sd.map((d) => d.label).join() === "SLCR,PAT,RATE,DEPTH" && sd[0].names.join() === "OFF,GATE,STUT" + && sd[2].names.join() === "1/8,1/16,1/32,8T,16T,32T" && sd[2].def === 1 && sd[1].min === 1 && sd[1].max === 16 && sd[3].def === 127 + && /\[P_SLCR\] = PE\("SLCR", N_SLCR, 0\)/.test(pc) && /\[P_SLPAT\] = PD\("PAT", F_INT, 1, 16, 1\)/.test(pc) + && /\[P_SLRATE\] = PE\("RATE", N_SLDIV, 1\)/.test(pc) && /\[P_SLDEPTH\] = PD\("DEPTH", F_PCT, 0, 127, 127\)/.test(pc) + && /N_SLDIV\[\] = \{"1\/8", "1\/16", "1\/32", "8T", "16T", "32T"\}/.test(pc), + "editor: SLICER parameters 45..48 (mock == params.c)"); + await rq(E.req.set(0, 45, 2)); + await rq(E.req.set(0, 46, 7)); + const on = E.parse[E.CMD.DUMP](await rq(E.req.dump()), info); + await rq(E.req.preset(0, 1)); + const off = E.parse[E.CMD.DUMP](await rq(E.req.dump()), info); + ok(on.p[45] === 2 && on.p[46] === 7 && off.p[45] === 0 && off.p[46] === 1, "editor: a factory preset turns the SLICER off"); + } + const scale = E.parse[E.CMD.DESC](await rq(E.req.desc(0, 26))); + const scaleNames = ["CHR", "MAJ", "MIN", "DOR", "MIX", "PEN", "MPEN", "HARM", "PHRY", "LYD", "LOC", "MEL", "BLUES", "WHOLE", "DIMHW", "DIMWH"]; + ok(scale.label === "SCL" && scale.max === 15 && eq(scale.names, scaleNames), "editor: all 16 scale names exposed"); + const scaleSet = E.parse[E.CMD.SET](await rq(E.req.set(0, scale.id, 15))); + ok(scaleSet.value === 15, "editor: new scale selection is not clamped to the old range"); + const dump = E.parse[E.CMD.DUMP](await rq(E.req.dump()), info); + ok(dump.p.length === info.pcount && dump.g.length === info.gcount, "editor: DUMP"); + const set = E.parse[E.CMD.SET](await rq(E.req.set(0, 3, 500))); + ok(set.value === 127, "editor: SET clamps to the range"); + const st = E.parse[E.CMD.STEP_SET](await rq(E.req.stepSet(5, { n: 2, notes: [60, 64], time: 0, flags: 1, vel: 100 }))); + ok(st.n === 2 && st.notes[1] === 64 && st.vel === 100, "editor: STEP_SET"); + const pj = E.parse[E.CMD.PROJECT](await rq(E.req.project(1, 2), { timeout: 4000, retries: 0 })); + ok(pj.used === 1, "editor: PROJECT save"); + /* sample upload as smpUpload() does it */ + const s = Int16Array.from({ length: 3000 }, (_, i) => Math.round(8000 * Math.sin(i / 7))); + const { hdr, data } = E.buildSlot("test", [{ s, root: 60 }]); + let rc = E.parse[E.CMD.SMP_BEGIN](await rq(E.req.smpBegin(1), { timeout: 1000, retries: 0 })).rc; + for (let off = 0; off < data.length && !rc; off += 256) { + rc = E.parse[E.CMD.SMP_WRITE](await rq(E.req.smpWrite(1, E.SMP.DATA_OFF + off, data.subarray(off, off + 256)), { timeout: 1000 })).rc; + } + rc = rc || E.parse[E.CMD.SMP_END](await rq(E.req.smpEnd(1, hdr), { timeout: 2000, retries: 0 })).rc; + const si = E.parse[E.CMD.SMP_INFO](await rq(E.req.smpInfo())); + ok(rc === 0 && si.slots[1].zones === 1 && si.slots[1].name === "TEST", "editor: sample upload (CRC checked by the mock)"); + /* a device that never answers */ + const dead = new E.Link(() => {}, { timeout: 30 }); + const err = await dead.request(E.req.info(), { retries: 1 }).then(() => null, (e) => e.message); + ok(/^timeout/.test(err || ""), "editor: no reply -> timeout after the retries"); + link.close(); + m.stop(); +} + +/* ------------------------------------- editor protocol v2: librarian + live --- */ +const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); +const js = (x) => JSON.stringify(x); +/* a mock + Link pair; counts frames sent per cmd and timeouts reported */ +function attachMock(opt, linkOpt = {}) { + const m = E.makeMockDevice({ auto: false, ...opt }); + const inp = [...m.access.inputs.values()][0], out = [...m.access.outputs.values()][0]; + const sent = {}, ev = { timeouts: 0, unknown: [], pushes: [] }; + const link = new E.Link((d) => { sent[d[4]] = (sent[d[4]] || 0) + 1; out.send(d); }, { + timeout: 300, onTimeout: () => ev.timeouts++, onUnknown: (f) => ev.unknown.push(f), + onPush: (f) => ev.pushes.push({ ...f, pending: link.cur ? link.cur.cmd : 0 }), ...linkOpt }); + inp.onmidimessage = (e) => link.receive(e.data); + const rq = (r, o) => link.request(r, o); + return { m, link, rq, sent, ev, done: () => { link.close(); m.stop(); } }; +} +const emptyStep = { n: 0, notes: [0, 0, 0, 0], time: 2, flags: 0, vel: 0 }; + +async function editorLibrarian() { + const { m, rq, done } = attachMock({}); + const C = E.CMD; + const info = E.parse[C.INFO](await rq(E.req.info())); + const pdesc = []; + for (let i = 0; i < info.pcount; i++) pdesc.push(E.parse[C.DESC](await rq(E.req.desc(0, i)))); + const keys = E.paramKeys(pdesc, info.pe0, info.pcount); + ok(keys[6] === "PIT" && keys[13] === "PIT#2" && keys[info.pe0] === "E0" && new Set(keys).size === keys.length, "librarian: parameter keys unique (label#n, E0..E7)"); + + const b = await E.bank.list(rq); + ok(b.total === 32 && b.slots.length === 32 && b.slots[1].used && b.slots[1].name === "GLASS BELL" && !b.slots[3].used + && b.slots[31].slot === 31, "librarian: UP_LIST, 32 slots in 2 frames"); + + const cap = (await E.capturePatch(rq, info, "acid test")).patch; + ok(cap.engine === 0 && cap.p.length === info.pcount && cap.pattern && cap.pattern[0][0] === 45 && cap.pattern[0][1] === 1, + "librarian: capture = DUMP + first 16 steps"); + let rc = await E.bank.put(rq, 10, cap); + const g = await E.bank.get(rq, info, 10); + ok(rc === 0 && g.used && g.name === "acid test" && g.engine === 0 && eq(g.p, cap.p) && js(g.pattern) === js(cap.pattern), + "librarian: UP_PUT -> UP_GET round trip"); + const bad = E.parse[C.UP_PUT](await rq(E.req.upPut(60, cap), { timeout: 2500, retries: 0 })); + ok(bad.rc === 1, "librarian: UP_PUT to a slot past the bank -> rc 1"); + ok(E.upName("") === "PATCH" && E.upName("abcdefghijklmnop") === "abcdefghijkl" && E.upName("Bäss") === "Bss", "librarian: device names (ASCII, 1..12)"); + + await rq(E.req.set(0, 1, 33)); + rc = await E.bank.store(rq, 11, "STORED"); + const g2 = await E.bank.get(rq, info, 11); + const d1 = E.parse[C.DUMP](await rq(E.req.dump()), info); + ok(rc === 0 && g2.name === "STORED" && g2.engine === d1.engine && eq(g2.p, d1.p) && g2.p[1] === 33, "librarian: UP_STORE keeps the current sound"); + + /* another engine, empty sequencer, then UP_LOAD brings the sound back, not the pattern (LIVE) */ + await rq(E.req.preset(2, 0)); + for (let i = 0; i < info.nstep; i++) await rq(E.req.stepSet(i, emptyStep)); + rc = await E.bank.load(rq, 10); + const d2 = E.parse[C.DUMP](await rq(E.req.dump()), info); + const st = []; + for (let i = 0; i < 16; i++) st.push(E.parse[C.STEP_GET](await rq(E.req.stepGet(i)))); + ok(rc === 0 && d2.engine === 0 && eq(d2.p, cap.p) && st.every((x) => !x.n), "librarian: UP_LOAD applies the sound, the sequencer stays empty (LIVE)"); + + rc = await E.bank.erase(rq, 11); + const b2 = await E.bank.list(rq); + const rcEmpty = await E.bank.load(rq, 11); + ok(rc === 0 && !b2.slots[11].used && b2.slots[10].used && rcEmpty === 1, "librarian: UP_ERASE, UP_LOAD of an empty slot -> rc 1"); + + /* audition: a PHASE patch with a pattern into an empty sequencer: the sound only (as UP_LOAD in SLOOP), never + the pattern, and the mix / pattern / key parameters stay (ui.c param_kept) */ + const bass = await E.bank.get(rq, info, 2); /* PHASE RESO, with the ACID pattern */ + for (let i = 0; i < info.nstep; i++) await rq(E.req.stepSet(i, emptyStep)); + const KEPT = [0, 25, 26, 27, 29, 30, 31, 32, 39, 40, 49]; + for (const [id, v] of [[0, 77], [25, 5], [29, 12], [39, -10], [49, 2]]) await rq(E.req.set(0, id, v)); + const d2b = E.parse[C.DUMP](await rq(E.req.dump()), info); + const flashBefore = js(m.state.bank); + let a = await E.auditionPatch(rq, info, bass, { gEng: 20 }); + const d3 = E.parse[C.DUMP](await rq(E.req.dump()), info); + const st3 = []; + for (let i = 0; i < 16; i++) st3.push(E.parse[C.STEP_GET](await rq(E.req.stepGet(i)))); + const soundOk = (d, pt) => d.p.every((v, i) => (KEPT.includes(i) ? v === d2b.p[i] : v === pt.p[i])); + ok(!a.wrote && d3.engine === bass.engine && soundOk(d3, bass) && st3.every((s) => !s.n) && js(m.state.bank) === flashBefore + && d3.p[0] === 77 && d3.p[25] === 5 && d3.p[29] === 12 && d3.p[49] === 2, + "librarian: audition = G_ENGSEL + SETs of the sound; no pattern, mix, LEN or key; no flash write"); + /* notes in the sequencer stay too */ + await rq(E.req.stepSet(20, { n: 1, notes: [50, 0, 0, 0], time: 0, flags: 0, vel: 90 })); + const bell = await E.bank.get(rq, info, 1); + a = await E.auditionPatch(rq, info, { ...bell, pattern: [[72, 0], [74, 0]] }, { gEng: 20 }); + const s0 = E.parse[C.STEP_GET](await rq(E.req.stepGet(0))), s20 = E.parse[C.STEP_GET](await rq(E.req.stepGet(20))); + const d4 = E.parse[C.DUMP](await rq(E.req.dump()), info); + ok(!a.wrote && !s0.n && s20.notes[0] === 50 && d4.engine === 1 && soundOk(d4, bell), "librarian: audition keeps the sequencer as it is"); + + /* ties as the firmware keeps them: no note; a rest has no flags */ + const tied = [[60, 1], [61, 4], [0, 4], [0, 3], [64, 2]]; + const norm = E.patternFromSteps(E.stepsFromPattern(tied)); + rc = await E.bank.put(rq, 12, { ...cap, name: "TIES", pattern: tied }); + const g3 = await E.bank.get(rq, info, 12); + ok(rc === 0 && js(norm.slice(0, 5)) === js([[60, 1], [0, 4], [0, 4], [0, 0], [64, 2]]) && js(g3.pattern) === js(norm), + "librarian: pattern ties / rests normalised like the firmware"); + rc = await E.bank.store(rq, 13, ""); + ok(rc === 0 && (await E.bank.get(rq, info, 13)).name === `${info.engines[d4.engine]} 14`, "librarian: UP_STORE with no name -> automatic name"); + + /* library files */ + const ctx = { keys, engines: info.engines, firmware: info.version, pe0: info.pe0 }; + const pts = [cap, { ...bass, engineName: info.engines[bass.engine], tags: ["bass", "device"] }]; + const file = JSON.parse(JSON.stringify(E.libraryFile("library", pts, ctx))); + ok(file.format === "felucca-library" && file.version === 1 && file.pCount === 58 && file.paramLabels.length === 58 && file.engines.length === 9, + "library file: versioned, with P_COUNT, labels and engines"); + const back = E.readLibraryFile(file, ctx); + ok(back.patches.length === 2 && !back.skipped && eq(back.patches[0].p, cap.p) && eq(back.patches[1].p, bass.p) + && js(back.patches[1].pattern) === js(bass.pattern) && back.patches[1].tags.join() === "bass,device" && back.patches[1].engineName === "PHASE", + "library file: write -> read round trip"); + /* a future firmware: one more parameter at id 5, engines in another order and one of them gone */ + const keys2 = [...keys.slice(0, 5), "NEW", ...keys.slice(5)]; + const eng2 = ["PHASE", "ANALOG", "SAMPLE"]; + const fut = E.readLibraryFile(file, { keys: keys2, engines: eng2 }); + const p0 = fut.patches[0].p; + ok(fut.patches.length === 2 && p0.length === 59 && p0[5] === null && p0[6] === cap.p[5] && p0[58] === cap.p[57] + && fut.patches[0].engine === 1 && fut.patches[1].engine === 0, "library file: other ids / engine order mapped by label and name"); + const lost = E.readLibraryFile({ ...file, patches: [{ ...file.patches[0], engineName: "WAVETABLE" }] }, ctx); + ok(lost.patches.length === 0 && lost.skipped === 1, "library file: a patch for an unknown engine is skipped"); + const bankFile = E.libraryFile("bank", [{ ...g, engineName: "ANALOG", slot: 10 }], ctx); + ok(bankFile.kind === "bank" && bankFile.patches[0].slot === 10 && E.readLibraryFile(bankFile, ctx).patches[0].slot === 10, "library file: bank export keeps slot numbers"); + const old = E.readLibraryFile({ format: "felucca-patch", version: 1, engine: 0, preset: 4, engineName: "ANALOG", presetName: "ACID", p: d2.p, steps: E.stepsFromPattern(cap.pattern) }, ctx); + ok(old.patches.length === 1 && eq(old.patches[0].p, d2.p) && js(old.patches[0].pattern) === js(cap.pattern), "library file: reads the old \"Save to file\" format"); + let threw = false; + try { E.readLibraryFile({ format: "something" }, ctx); } catch (e) { threw = true; } + ok(threw, "library file: unknown format -> error"); + done(); +} + +async function editorLive() { + const C = E.CMD; + const { m, link, rq, sent, ev, done } = attachMock({ watchMs: 250 }); + const info = E.parse[C.INFO](await rq(E.req.info())); + ok(await E.startWatch(rq), "live: WATCH on"); + + /* a push between a request and its reply */ + const pend = rq(E.req.dump()); + const kn = m.sim.knob(9, 4); + const dump = E.parse[C.DUMP](await pend, info); + const ch = ev.pushes.find((f) => f.cmd === C.CHANGED); + const cv = ch && E.parse[C.CHANGED](ch.a); + ok(dump.p.length === 58 && ch && ch.pending === C.DUMP && cv.scope === 0 && cv.id === 9 && cv.value === kn.value && !ev.unknown.length, + "live: CHANGED while DUMP waits -> push handler, reply still matched"); + const rl = m.sim.reload(); + m.sim.step(3); + const pend2 = rq(E.req.stepGet(7)); + const s7 = E.parse[C.STEP_GET](await pend2); + await sleep(10); + const r = ev.pushes.find((f) => f.cmd === C.RELOAD), sc = ev.pushes.find((f) => f.cmd === C.STEP_CHANGED); + ok(s7.index === 7 && r && E.parse[C.RELOAD](r.a).preset === rl.preset && sc && E.parse[C.STEP_CHANGED](sc.a).index === 3, + "live: RELOAD and STEP_CHANGED routed"); + const nr = ev.pushes.filter((f) => f.cmd === C.RELOAD).length; + await rq(E.req.preset(1, 2)); + await rq(E.req.stepSet(9, { n: 1, notes: [62, 0, 0, 0], time: 0, flags: 0, vel: 90 })); + await sleep(10); + ok(ev.pushes.filter((f) => f.cmd === C.RELOAD).length === nr + 1 && !ev.pushes.some((f) => f.cmd === C.STEP_CHANGED && f.a[0] === 9), + "live: RELOAD after an editor PRESET too, nothing after its STEP_SET"); + + /* PING keeps the watch on; without requests it ends */ + for (let i = 0; i < 4; i++) { await sleep(120); await rq(E.req.ping()); } + let n0 = ev.pushes.length; + m.sim.knob(); + await sleep(10); + ok(ev.pushes.length === n0 + 1, "live: PING keeps WATCH on"); + await sleep(320); + n0 = ev.pushes.length; + m.sim.knob(); + await sleep(10); + ok(ev.pushes.length === n0, "live: WATCH ends by itself without requests"); + + /* a slider drag: 40 values at once -> one SET in flight + one coalesced, the last value wins */ + const before = sent[C.SET] || 0; + const all = []; + for (let v = 0; v < 40; v++) all.push(rq(E.req.set(0, 9, v * 3), { key: "0:9" })); + await Promise.all(all); + ok((sent[C.SET] || 0) - before === 2 && m.state.p[9] === 117 && link.idle, "live: drag SETs coalesce (2 frames for 40 values, latest kept)"); + ok(ev.timeouts === 0, "live: no timeouts"); + done(); + + /* older firmware: no reply to WATCH -> false without a "no reply" message; no bank */ + const o = attachMock({ legacy: true }); + E.parse[C.INFO](await o.rq(E.req.info())); + const w = await o.rq(E.req.watch(1), { timeout: 60, retries: 0, quiet: true }).then(() => true, () => false); + const sw = await E.startWatch(o.rq); + const bl = await E.bank.list((rr, oo) => o.rq(rr, { ...oo, timeout: 60, quiet: true })).then(() => "listed", (e) => e.message); + ok(!w && !sw && /^timeout/.test(bl) && o.ev.timeouts === 0, "live: older firmware -> WATCH unanswered (fall back to polling), no bank"); + o.done(); +} + +/* ------------------------------------------------------ editor protocol v3: tracks --- */ +async function editorTracks() { + const C = E.CMD; + const { m, rq, ev, done } = attachMock({ watchMs: 1000 }); + const info = E.parse[C.INFO](await rq(E.req.info())); + const tr = E.parse[C.TRACK](await rq(E.req.track())); + ok(info.ntrk === 4 && tr.sel === 0 && tr.ntrk === 4 && tr.tracks[0].engine === 0 && tr.tracks[1].engine === 1 + && tr.tracks[3].engine === info.nengines, "tracks: INFO NTRK, TRACK lists 4 (track 4 = drums, engine NENGINES)"); + /* the v1 commands follow the selected track */ + const d0 = E.parse[C.DUMP](await rq(E.req.dump()), info); + const t1 = E.parse[C.TRACK](await rq(E.req.track(1))); + const d1 = E.parse[C.DUMP](await rq(E.req.dump()), info); + await rq(E.req.set(0, 1, 77)); + const td0 = E.parse[C.TRACK_DUMP](await rq(E.req.trackDump(0)), info); + const td1 = E.parse[C.TRACK_DUMP](await rq(E.req.trackDump(1)), info); + ok(t1.sel === 1 && d1.engine === 1 && d0.engine === 0 && td1.p[1] === 77 && td0.p[1] === d0.p[1] && td0.p[1] !== 77, + "tracks: TRACK selects; DUMP / SET act on it, TRACK_DUMP reads any track"); + /* steps of a track that is not selected */ + const w = E.parse[C.TRACK_STEP](await rq(E.req.trackStep(2, 5, { n: 2, notes: [60, 67, 0, 0], time: 0, flags: 1, vel: 99 }))); + const g2 = E.parse[C.TRACK_STEP](await rq(E.req.trackStep(2, 5))); + const s1 = E.parse[C.STEP_GET](await rq(E.req.stepGet(5))); + ok(w.track === 2 && g2.n === 2 && g2.notes[1] === 67 && g2.vel === 99 && s1.n === 0, "tracks: TRACK_STEP set / get on another track"); + /* level / mute; the drum level is GLO > DRUMS LEVEL */ + const mx = E.parse[C.TRACK_MIX](await rq(E.req.trackMix(0, 90, 1))); + const mxd = E.parse[C.TRACK_MIX](await rq(E.req.trackMix(3, 64, 0))); + const mx2 = E.parse[C.TRACK_MIX](await rq(E.req.trackMix(0))); + const tr2 = E.parse[C.TRACK](await rq(E.req.track())); + ok(mx.level === 90 && mx.mute === 1 && mx2.level === 90 && mxd.level === 64 && m.state.g[25] === 64 + && tr2.tracks[0].level === 90 && tr2.tracks[0].mute === 1, "tracks: TRACK_MIX level / mute (drums: G_DRLVL)"); + /* the drum track: no sound to store or load */ + await rq(E.req.track(3)); + const dd = E.parse[C.DUMP](await rq(E.req.dump()), info); + const us = E.parse[C.UP_STORE](await rq(E.req.upStore(20, "X"), { timeout: 2500, retries: 0 })); + const ul = E.parse[C.UP_LOAD](await rq(E.req.upLoad(1), { timeout: 2500, retries: 0 })); + ok(dd.engine === info.nengines && us.rc === 1 && ul.rc === 1, "tracks: drum track selected -> DUMP engine NENGINES, UP_STORE / UP_LOAD rc 1"); + /* pushes carry the selected track */ + await rq(E.req.track(0)); + ok(await E.startWatch(rq), "tracks: WATCH on"); + m.sim.track(2); + m.sim.step(4); + await sleep(10); + const rl = ev.pushes.find((f) => f.cmd === C.RELOAD), sc = ev.pushes.find((f) => f.cmd === C.STEP_CHANGED); + ok(rl && E.parse[C.RELOAD](rl.a).track === 2 && sc && E.parse[C.STEP_CHANGED](sc.a).track === 2 && E.parse[C.STEP_CHANGED](sc.a).index === 4, + "tracks: RELOAD / STEP_CHANGED carry the selected track"); + /* projects keep all four tracks */ + await rq(E.req.project(1, 3), { timeout: 4000, retries: 0 }); + await rq(E.req.trackStep(2, 5, { n: 0, notes: [0, 0, 0, 0], time: 2, flags: 0, vel: 0 })); + await rq(E.req.track(0)); + await rq(E.req.project(0, 3), { timeout: 4000, retries: 0 }); + const back = E.parse[C.TRACK_STEP](await rq(E.req.trackStep(2, 5))); + const sel = E.parse[C.TRACK](await rq(E.req.track())).sel; + ok(back.n === 2 && back.notes[0] === 60 && sel === 2, "tracks: PROJECT save / load keeps every track and the selection"); + /* older firmware: no NTRK in INFO, no RELOAD track byte */ + const o = attachMock({ legacy: true }); + const oi = E.parse[C.INFO](await o.rq(E.req.info())); + ok(oi.ntrk === 0 && E.parse[C.RELOAD]([0, 4]).track === 0 && E.parse[C.STEP_CHANGED]([7]).track === 0, "tracks: older firmware parses (no tracks)"); + o.done(); + done(); +} + +/* ------------------------------------------------ editor v3: the mixer (Tracks tab) --- */ +async function editorMixer() { + const C = E.CMD; + const { m, rq, ev, done } = attachMock({ watchMs: 1000 }); + const info = E.parse[C.INFO](await rq(E.req.info())); + const PAN = 39, MUTE = 40; + const m0 = await E.mixer.read(rq, info, { pan: PAN }); + ok(m0.ntrk === 4 && m0.tracks.length === 4 && m0.tracks[1].pan === -24 && m0.tracks[2].pan === 20 && m0.tracks[3].engine === info.nengines + && m0.tracks.every((x) => Number.isInteger(x.level) && (x.mute === 0 || x.mute === 1)), "mixer: read = TRACK + pan of every track (TRACK_DUMP)"); + /* level / mute of a track that is not selected, and of the drum track (G_DRLVL) */ + const a = await E.mixer.setMix(rq, 2, 70, 1); + const b = await E.mixer.setMix(rq, 3, 200, 0); + const m1 = await E.mixer.read(rq, info, { pan: PAN }); + const td2 = E.parse[C.TRACK_DUMP](await rq(E.req.trackDump(2)), info); + ok(a.level === 70 && a.mute === 1 && b.level === 127 && m.state.g[25] === 127 && m1.tracks[2].level === 70 && m1.tracks[2].mute === 1 + && td2.p[0] === 70 && td2.p[MUTE] === 1 && m1.sel === 0, "mixer: TRACK_MIX level / mute round trip (drums: G_DRLVL, clamped)"); + /* pan of another track: selected for the SET, the selection put back, no RELOAD pushed */ + ok(await E.startWatch(rq), "mixer: WATCH on"); + const pushes = ev.pushes.length; + /* (the v3 path: firmware 0.8 has no TRACK_PARAM) */ + const p2 = await E.mixer.setPan(rq, 2, 0, PAN, -40); + const p0 = await E.mixer.setPan(rq, 0, 0, PAN, 99); + await sleep(10); + const m2 = await E.mixer.read(rq, info, { pan: PAN }); + const d0 = E.parse[C.DUMP](await rq(E.req.dump()), info); + ok(p2 === -40 && p0 === 63 && m2.sel === 0 && m2.tracks[2].pan === -40 && m2.tracks[0].pan === 63 && d0.p[PAN] === 63 && m2.tracks[1].pan === -24 + && ev.pushes.length === pushes, "mixer: pan of any track via SET (other track selected for a moment, then back; no push)"); + /* the device's TRACKS page: level of the selected track pushes CHANGED; REC arm shows in TRACK */ + m.sim.level(33); + m.sim.arm(1); + await sleep(10); + const ch = ev.pushes.filter((f) => f.cmd === C.CHANGED).map((f) => E.parse[C.CHANGED](f.a)).pop(); + const m3 = await E.mixer.read(rq, info, { pan: PAN }); + ok(ch && ch.scope === 0 && ch.id === 0 && ch.value === 33 && m3.tracks[0].level === 33 && m3.tracks[1].armed === 1 && m3.tracks[0].armed === 0, + "mixer: device-side level (CHANGED push) and REC arm read back"); + await rq(E.req.track(3)); + m.sim.level(90); + await sleep(10); + const chd = E.parse[C.CHANGED](ev.pushes.filter((f) => f.cmd === C.CHANGED).pop().a); + ok(chd.scope === 1 && chd.id === 25 && chd.value === 90, "mixer: drum level on the device pushes G_DRLVL"); + /* the drum track's steps: GM notes, shown and typed by name */ + const st = []; + for (let i = 0; i < 16; i++) st.push(E.parse[C.TRACK_STEP](await rq(E.req.trackStep(3, i)))); + const names = st[0].notes.slice(0, st[0].n).map(E.drumName).join(" "); + ok(names === "KICK CHH" && st[4].notes.slice(0, 2).map(E.drumName).join(" ") === "SNARE CHH" && E.drumName(20) === "20", + "mixer: the mock drum track holds a GM pattern (KICK CHH ...)"); + ok(JSON.stringify(E.parseNotes("kick CHH 49")) === "[36,42,49]" && JSON.stringify(E.parseNotes("C4 SNARE")) === "[60,38]" && E.parseNotes("KICKS") === null + && Object.keys(E.GM_DRUM).length === 47 && new Set(Object.values(E.GM_DRUM)).size === 47, "mixer: GM drum names parse (unique, 35..81)"); + done(); +} + +/* ------------------------------------- editor v4: TRACK_PARAM and TRACK_CHANGED --- */ +async function editorTrackParam() { + const C = E.CMD, PAN = 39, MUTE = 40; + const { m, rq, sent, ev, done } = attachMock({ watchMs: 1000 }); + const info = E.parse[C.INFO](await rq(E.req.info())); + const w1 = E.parse[C.WATCH](await rq(E.req.watch(1))); + m.sim.param(2, PAN, 11); + await sleep(10); + ok(w1.on === 1 && !ev.pushes.some((f) => f.cmd === C.TRACK_CHANGED), "v4: WATCH 1 answers 1 as before (no TRACK_CHANGED pushes)"); + ok(await E.startWatch(rq) === 3, "v4: WATCH 3 -> 3 (TRACK_PARAM / TRACK_CHANGED known)"); + const tracks0 = sent[C.TRACK] || 0, pushes = ev.pushes.length; + const g = E.parse[C.TRACK_PARAM](await rq(E.req.trackParam(1, PAN))); + const p2 = await E.mixer.setPan(rq, 2, 0, PAN, -40, true); + const p1 = await E.mixer.setPan(rq, 1, 0, PAN, 99, true); + const alg = E.parse[C.TRACK_PARAM](await rq(E.req.trackParam(1, info.pe0, 50))); /* track 2 is DIGITAL: ALG 0..7 */ + const lv = E.parse[C.TRACK_PARAM](await rq(E.req.trackParam(3, 0, -5))); + const sel = E.parse[C.TRACK](await rq(E.req.track())); + const td2 = E.parse[C.TRACK_DUMP](await rq(E.req.trackDump(2)), info); + await sleep(10); + ok(g.track === 1 && g.id === PAN && g.value === -24 && p2 === -40 && p1 === 63 && alg.value === 7 && lv.value === 0 && td2.p[PAN] === -40 + && sel.sel === 0 && (sent[C.TRACK] || 0) === tracks0 + 1 && ev.pushes.length === pushes, + "v4: TRACK_PARAM get / set on other tracks (clamped as SET, selection kept, no push)"); + const bad = await rq(E.req.trackParam(4, PAN), { timeout: 60, retries: 0, quiet: true }).then(() => "reply", () => "none"); + ok(bad === "none", "v4: TRACK_PARAM of track 5: no reply"); + /* device-side changes: CHANGED for the selected track, TRACK_CHANGED for the others */ + m.sim.param(2, PAN, 30); + m.sim.param(3, MUTE, 1); + m.sim.param(0, PAN, -7); + await sleep(10); + const tc = ev.pushes.filter((f) => f.cmd === C.TRACK_CHANGED).map((f) => E.parse[C.TRACK_CHANGED](f.a)); + const ch = ev.pushes.filter((f) => f.cmd === C.CHANGED).map((f) => E.parse[C.CHANGED](f.a)).pop(); + ok(tc.length === 2 && tc[0].track === 2 && tc[0].id === PAN && tc[0].value === 30 && tc[1].track === 3 && tc[1].id === MUTE && tc[1].value === 1 + && ch && ch.scope === 0 && ch.id === PAN && ch.value === -7 && !ev.unknown.length, "v4: TRACK_CHANGED pushes for the other tracks, CHANGED for the selected one"); + done(); + /* firmware 0.8 (v3): WATCH 3 answers 1, TRACK_PARAM unanswered: the editor keeps the select / restore path */ + const o = attachMock({ v3: true, watchMs: 1000 }); + E.parse[C.INFO](await o.rq(E.req.info())); + const on = await E.startWatch(o.rq); + const tp = await o.rq(E.req.trackParam(1, PAN), { timeout: 60, retries: 0, quiet: true }).then(() => "reply", () => "none"); + const pv = await E.mixer.setPan(o.rq, 2, 0, PAN, 5, false); + ok(on === 1 && tp === "none" && pv === 5 && o.ev.timeouts === 0 && !o.ev.unknown.length, "v4: v3 firmware -> WATCH 1, no TRACK_PARAM (pan by select / restore)"); + o.done(); +} + +/* ------------------------------------- editor v5 (SLOOP 2.0): lanes, levels, ratchets --- */ +async function editorV5() { + const C = E.CMD; + const { m, rq, ev, done } = attachMock({ watchMs: 1000 }); + const info = E.parse[C.INFO](await rq(E.req.info())); + ok(info.proto === 5 && /SLOOP/.test(info.version) && info.pcount === 58 && info.gcount === 32 && info.pe0 === 50, "v5: INFO ends with the protocol version 5"); + /* the firmware says the same: ED_DRUM_STEP is command 33, INFO sends 5, P_CHORD / the master globals as the mock has them */ + const ec = readFileSync(join(HERE, "../firmware/src/editor.c"), "utf8"), pc = readFileSync(join(HERE, "../firmware/src/params.c"), "utf8"); + const en = (/enum \{ ED_INFO = 1,([^}]*)\}/.exec(ec) || [])[1] || ""; + const names = ["ED_INFO", ...en.replace(/\/\*[^*]*\*\//g, "").split(",").map((x) => x.trim()).filter(Boolean)]; + ok(names.indexOf("ED_DRUM_STEP") + 1 === C.DRUM_STEP && names.indexOf("ED_TRACK_CHANGED") + 1 === C.TRACK_CHANGED + && /ed_b\(5\);\s*\/\* v5: the protocol version/.test(ec), "v5: command numbers and INFO == editor.c"); + const enumNames = (id) => (new RegExp(`${id}\\[\\] = \\{([^}]*)\\}`).exec(pc) || [])[1].split(",").map((x) => x.trim().replace(/"/g, "")); + const chord = E.parse[C.DESC](await rq(E.req.desc(0, 49))); + const gd = []; + for (let i = 27; i < 32; i++) gd.push(E.parse[C.DESC](await rq(E.req.desc(1, i)))); + ok(chord.label === "CHORD" && chord.names.join() === enumNames("N_CHORD").join() && /\[P_CHORD\] = PE\("CHORD", N_CHORD, 0\)/.test(pc) + && gd.map((d) => d.label).join() === "DUST,DUCK,FILT,ROLL,NEW" && gd[3].names.join() === enumNames("N_ROLL").join() && gd[3].def === 1 + && /\[G_DUST\] = PD\("DUST", F_PCT, 0, 127, 0\)/.test(pc) && /\[G_FILT\] = PD\("FILT", F_FILT, -64, 63, 0\)/.test(pc) + && /\[G_ROLL\] = PE\("ROLL", N_ROLL, 1\)/.test(pc) && /\[G_NEWPRJ\] = PE\("NEW", N_GO, 0\)/.test(pc), + "v5: CHORD, DUST, DUCK, FILT, ROLL, NEW (mock == params.c)"); + /* the value formats (params.c fmt_value) */ + const fv = (fmt, v, max = 127, min = 0) => E.fmtValue({ fmt, min, max, names: [] }, v).join(""); + ok(fv(E.F.SWING, 0, 100) === "50%" && fv(E.F.SWING, 50, 100) === "63%" && fv(E.F.SWING, 100, 100) === "75%" + && fv(E.F.FILT, 0, 63, -64) === "OFF" && fv(E.F.FILT, -64, 63, -64) === "LP100%" && fv(E.F.FILT, -32, 63, -64) === "LP50%" && fv(E.F.FILT, 63, 63, -64) === "HP100%" + && fv(E.F.PCT, 127) === "100%" && fv(E.F.PCT, 64) === "50%" && fv(E.F.PCT, 60, 120) === "50%", "v5: SWING 50..75 %, FILT LP / OFF / HP, PCT of the range"); + /* a synth step keeps its levels and ratchets; an old-style write clears them (as the firmware) */ + const w = E.parse[C.STEP_SET](await rq(E.req.stepSet(3, { n: 2, notes: [60, 67, 0, 0], time: 0, flags: 0, vel: 100, lvl: 0b11000110, rat: 0b10000011 }))); + const g = E.parse[C.STEP_GET](await rq(E.req.stepGet(3))); + const w2 = E.parse[C.STEP_SET](await rq(E.req.stepSet(3, { n: 1, notes: [62, 0, 0, 0], time: 0, flags: 0, vel: 90 }))); + ok(w.lvl === 0b11000110 && g.lvl === 0b11000110 && g.rat === 0b10000011 && w2.lvl === 0 && w2.rat === 0 && E.req.stepSet(1, { n: 0, notes: [], time: 2, flags: 0, vel: 0 })[1].length === 9, + "v5: STEP_SET / STEP_GET level and ratchet bytes (8 bits each), none for an old step"); + /* the drum track: 16 lanes with their level and ratchet; lane 15 uses the top bits */ + const d = E.emptyDrum(); + d.on = (1 << 0) | (1 << 4) | (1 << 15); d.lvl[0] = 3; d.lvl[4] = 1; d.rat[4] = 3; d.lvl[15] = 2; d.rat[15] = 1; + const ds = E.parse[C.DRUM_STEP](await rq(E.req.drumStep(5, d))); + const dg = E.parse[C.DRUM_STEP](await rq(E.req.drumStep(5))); + ok(ds.index === 5 && dg.on === d.on && dg.lvl.join() === d.lvl.join() && dg.rat.join() === d.rat.join() + && E.req.drumStep(5, d)[1].every((b) => b >= 0 && b < 128) && E.req.drumStep(5, d)[1].length === 14, "v5: DRUM_STEP round trip (16 lanes, levels, ratchets)"); + /* old commands see the lanes as GM notes (the first four, ACC when one is hard); an old write lands on lanes */ + const old = E.parse[C.TRACK_STEP](await rq(E.req.trackStep(3, 5))); + await rq(E.req.trackStep(3, 6, { n: 2, notes: [38, 46, 0, 0], time: 0, flags: 1, vel: 100 })); + const d6 = E.parse[C.DRUM_STEP](await rq(E.req.drumStep(6))); + ok(old.n === 3 && old.notes.slice(0, 3).join() === "36,42,56" && old.flags === 1 && d6.on === ((1 << 2) | (1 << 5)) && d6.lvl[2] === 3 && d6.lvl[5] === 3, + "v5: the drum track through TRACK_STEP: lanes <-> GM notes"); + ok(E.DRUM_LANES.length === 16 && E.DRUM_LANES[0][0] === 36 && E.DRUM_LANES[15][0] === 56 && E.LV_NAMES.join() === "NORM,GHOST,SOFT,HARD", + "v5: the 16 lanes (kick .. cowbell), 4 levels"); + const dc = readFileSync(join(HERE, "../firmware/src/drums.c"), "utf8"); + const lanes = ((/LANE_NOTE\[DRUM_LANES\] = \{([^}]*)\}/.exec(dc) || [])[1] || "").split(",").map((x) => +x); + ok(lanes.join() === E.DRUM_LANES.map((x) => x[0]).join(), "v5: lane notes == drums.c LANE_NOTE"); + /* the kit: the drum track's P_E0 */ + await rq(E.req.track(3)); + const kit = E.parse[C.DESC](await rq(E.req.desc(0, info.pe0))); + const dk = (/DRUM_KIT_NAMES\[\] = \{([^}]*)\}/.exec(dc) || [])[1] || ""; + const gen = join(HERE, "../build/gen/felucca_drumkits.h"); + const dsList = existsSync(gen) ? ((/#define DS_KIT_NAME_LIST (.*)/.exec(readFileSync(gen, "utf8")) || [])[1] || "") : null; + const fwKits = dsList == null ? null : dk.replace("DS_KIT_NAME_LIST", dsList).split(",").map((x) => x.trim().replace(/"/g, "")); + ok(kit.label === "KIT" && kit.names[5] === "808" && kit.names.length === kit.max + 1 && (!fwKits || fwKits.join() === kit.names.join()), + `v5: the drum track's KIT (${kit.names.length} kits${fwKits ? ", == drums.c" : ""})`); + /* TRACK ends with the solo mask */ + m.state.solo = 0b0101; + const tr = E.parse[C.TRACK](await rq(E.req.track())); + ok(tr.solo === 5 && tr.sel === 3 && tr.tracks.length === 4, "v5: TRACK reports the soloed tracks"); + ok(!ev.unknown.length, "v5: no unmatched replies"); + done(); + /* firmware 0.8 (v3): no DRUM_STEP, no protocol byte, steps without the extra bytes */ + const o = attachMock({ v3: true }); + const oi = E.parse[C.INFO](await o.rq(E.req.info())); + const os = E.parse[C.STEP_GET](await o.rq(E.req.stepGet(0))); + const nd = await o.rq(E.req.drumStep(0), { timeout: 60, retries: 0, quiet: true }).then(() => "reply", () => "none"); + ok(oi.proto === 0 && os.lvl === undefined && nd === "none", "v5: older firmware -> proto 0, no DRUM_STEP (the editor keeps GM notes)"); + o.done(); +} + +/* ------------------------------------------------- editor tabs and strings --- */ +function editorTabs() { + const tabs = [...html.matchAll(/