diff --git a/BUILDING.md b/BUILDING.md index 5dd6072..d42c62f 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -10,11 +10,14 @@ The build makes three files in `build/`: ## Windows (WSL) -`INSTALL-CLIPPER.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. +`INSTALL-CLIPPER.bat` (`INSTALL-CLIPPER.bat 12` or `16` for more voices) runs `build-clipper.ps1`: +it builds in the WSL distribution `MinUI-Build` with the JieLi toolchain at +`/root/fm1-codex-deps/jieli/toolchain` (SLOOP's setup; edit the `build_windows.py` line of +`build-clipper.ps1` if yours differ), makes the site and opens the installer on +`http://localhost:8767/webapp/installer/` (SLOOP uses 8766). It needs Python 3 with Pillow on +Windows and the three SDK files (below) in `build/deps/ac79`: the first run copies them from a +SLOOP folder next to this one (`..\sloop-fm1`, `..\SLOOP`) or from `CLIPPER_SDK`. +`OPEN-EDITOR.bat` serves the editor of the last build on the same port. ## Prerequisites (macOS) @@ -64,10 +67,11 @@ Build options (environment, `0` or `1`; defaults in `firmware/src/felucca.c`): ## 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. +The Clipper synth (`CLIPPER_SYNTH 1`, the default) has no built-in samples: SAMPLE and GRAIN +play the four user slots sent from the editor, and the flash goes to synthesis. The CC0 +instrument and drum samples in `assets/samples-cc0/` (Versilian Studios VSCO-2 CE and VCSL, +Sonic Pi for SCRCH: see `ATTRIBUTION.txt` there) are only built into the groovebox +(`CLIPPER_SYNTH 0`, which the tests use). ## Tests @@ -76,12 +80,16 @@ 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` +loader, every synth engine and page, the modulation matrix, the MOD SEQ, the filter models, +VINTAGE, the tunings, the arpeggiator, both cores, a click test of the whole mix, project +formats, the groovebox's 4-track mix, the regression suite, the command-line installer) +and, with Node.js, the web page tests. `HOST_ONLY=1` skips what needs the JieLi toolchain. 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 +The regression suite (`tests/regress.c`, built as the groovebox, `CLIPPER_SYNTH 0`) renders +each of its 13 engines and their presets and compares a hash of each render with +`tests/golden.txt` (the synth's own engines and presets have their own tests: `synth*_test`, +`hybrid_test`, `wave_test`, `clean_test`...); it also checks levels, voices and the CPU cost (`tests/cpu_baseline.txt`, `tests/target_budget.txt`). The host CPU cost is relative to the idle + drums mix, counted by the kernel on macOS and under callgrind on Linux when valgrind is installed (exact, about 45 s more); without either it is timed, a rough check. diff --git a/DEMARRAGE-RAPIDE-FR.md b/DEMARRAGE-RAPIDE-FR.md index 5ee3a9c..1a49f2e 100644 --- a/DEMARRAGE-RAPIDE-FR.md +++ b/DEMARRAGE-RAPIDE-FR.md @@ -1,8 +1,20 @@ # Clipper — démarrage rapide (version de test 0.9) -**Clipper** est un firmware de **synthétiseur** pour le M-VAVE FM-1 : un seul instrument, comme le firmware d'origine, Felucca ou Baudgirl. Ce n'est plus une groovebox : pas de pistes, pas de boîte à rythmes, pas de mode song, pas de samples intégrés. Il garde de SLOOP les 12 moteurs, les effets, l'arpégiateur, le séquenceur de pas, l'audio USB et le MIDI. Il ajoute **HYBRID**, une voix à 3 oscillateurs, 2 filtres et une matrice de modulation de 16 slots, avec 24 sons d'usine. Il ajoute aussi le pitch bend, la molette, l'aftertouch et la pédale de sustain sur tous les moteurs. +**Clipper** est un firmware de **synthétiseur** pour le M-VAVE FM-1 : un seul instrument, comme le firmware d'origine, Felucca ou Baudgirl. Ce n'est plus une groovebox : pas de pistes, pas de boîte à rythmes, pas de mode song, pas de samples intégrés. Il garde de SLOOP les 12 moteurs, les effets, l'arpégiateur, le séquenceur de pas, l'audio USB et le MIDI. Il ajoute **HYBRID**, une voix à 3 oscillateurs, 2 filtres et une matrice de modulation de 16 slots, avec 32 sons d'usine. Il ajoute aussi le pitch bend, la molette, l'aftertouch et la pédale de sustain sur tous les moteurs. -> **C'est une première version de test** : elle n'a encore jamais tourné sur une vraie FM-1. Avant d'installer, fais une **sauvegarde** dans l'éditeur SLOOP (Projects → Backup → *Save a backup*). +> **C'est une version de test.** Avant d'installer, fais une **sauvegarde** dans l'éditeur (celui de Clipper ou de SLOOP, selon ce qui est installé) : Projects → Backup → *Save a backup*. + +## En bref + +**23 moteurs, 409 sons**, tous au même niveau : + +- **HYBRID** (3 oscillateurs, 2 filtres, matrice de 16 slots, 4 macros), **FMX** (6 opérateurs façon opsix, routage libre, PM / FM / RING), **FM6** (DX7, banques `.syx`), **DIGITAL** (FM 4 opérateurs), **WAVE** (tables d'ondes, et les tiennes), **WSEQ** (wave sequencing façon Wavestation), **VECTOR** (Prophet VS / joystick du Wavestation), **JUNO** (Juno-6 / 60 / 106 et son chorus I / II / I+II), **ANALOG** (analogique virtuel, 8 modèles de filtre), **ACID** (303), **STRINGS** (string machine), **MACRO** (façon Plaits), **PHASE** (façon CZ), **VPS** (vector phaseshaping), **TERRAIN** (wave terrain), **PHYS** (modèles physiques), **TRIO** (puce 8 bits), **LOFI** (chiptune), **WHEEL** (orgue à roues phoniques), **VOICE** (voyelles chantées), **NOISE**, **GRAIN** et **SAMPLE** (sur quatre sources synthétisées de Clipper, VOX, GLASS, PAD et AIR, ou sur tes propres samples). +- **Sculpter le son** (tous les moteurs) : une **matrice de modulation** de 6 slots, **LFO 2**, **ENV 2**, le **MOD SEQ** (séquenceur de modulation à 4 pistes), **8 modèles de filtre** sur ANALOG, WAVE et VECTOR (SVF, ladder Moog, MS-20, ladder à diodes, SEM, notch, passe-bande, passe-haut), **VINTAGE** (chaque voix dérive comme sur un vrai polyphonique analogique), un effet **INSERT** par son (SOFT, HARD, FOLD, FUZZ, CRUSH, PHASER, FLANGER, CHORUS et le chorus JUNO). +- **Effets** : distorsion, chorus stéréo, delay synchronisé, réverbs room et plate, filtre DJ, EQ 3 bandes, compresseur de bus et limiteur. Les réglages glissent au lieu de claquer. +- **Accordage** : égal, juste, Pythagore, mésotonique, Werckmeister III, Kirnberger III, maqams Rast et Bayati, slendro, pelog, 19 / 24 / 31-EDO, et toute gamme **Scala `.scl`** envoyée depuis l'éditeur. +- **Jouer** : 8 voix (12 ou 16 en option, sur les deux cœurs), POLY, MONO, LEGATO, UNISON et unisson polyphonique, glide ; **LAYER**, **SPLIT** et **MULTI** (deux parties sur deux canaux MIDI) ; un **arpégiateur** à 15 modes, dont une **machine de Turing** (TURNG), et les variations **SPICE / DICE** ; le séquenceur de pas avec accords et enregistrement ; gammes et accords sur les touches, KBD HOLD ; **MPE** ; MIDI USB et TRS ; interface audio USB. +- **Travailler** : **UNDO** et **COMPARE** sur la FM-1, favoris, **MORPH** entre deux versions d'un son, **randomiseur** par section, presets utilisateur et projets qui gardent tout. +- **L'éditeur web** (Chrome ou Edge) : chaque paramètre en direct, les patchs HYBRID et FMX en entier, les pistes du MOD SEQ, l'accordage et les fichiers `.scl`, les banques DX7, tables d'ondes et samples, une bibliothèque de sons, des outils undo / compare / A-B / random, la sauvegarde complète de la FM-1. ## Un dossier à part @@ -30,8 +42,11 @@ Sur la FM-1, Clipper se reconnaît à son écran de démarrage et à HOME (maint - **VINTAGE** (VOICE 2 → **VINTG**, tous les moteurs) : chaque voix a sa propre petite erreur d'accord et de filtre (sa « carte de voix »), une lente dérive de hauteur, et chaque note un peu de la sienne. À 127 : carte ±6 cents, dérive ±5, note ±2, coupure ±1,5 pas. À 0 : identique à avant, au bit près. - **TUNING** (GLO → **TUNING**, pour tous les sons, gardé avec les réglages) : **EQUAL**, **JUST** (intonation juste), **PYTHA**gore, **MEANT**one (1/4 de comma), **WERCK**meister III, **KIRNB**erger III, les maqams **RAST** et **BAYAT**i (tierces neutres), **SLEND**ro et **PELOG** (gamelan), **19**, **24** et **31-EDO**, et **USER** : n'importe quelle gamme **Scala .scl** (jusqu'à 48 notes par période, n'importe quelle période, même la tritave de Bohlen-Pierce) envoyée depuis l'éditeur web. ROOT choisit la tonique. - **TURNG**, une machine de Turing dans l'arpégiateur (ARP MODE → TURNG, d'après la Turing Machine de Music Thing) : un registre à décalage en boucle choisit parmi les notes tenues. Sur la page SPICE : **MUTAT** (0 figé, 127 aléatoire), **SEED** (un autre motif), **LOOP** (longueur 1..16). LOOP fixe aussi sur combien de notes SPICE / DICE varient avant de se répéter. -- **Un son propre, sans clics** (un nouveau test de 45 cas rend chaque changement et vérifie qu'aucun échantillon ne saute) : le limiteur de sortie bouge en courbe en S ; les envois (CHOR / DLY / REV) et la DIST de l'INSERT glissent au lieu de sauter ; le TIME du delay passe en fondu de l'ancienne à la nouvelle prise ; la DEPTH du chorus glisse ; le FILT du master passe par le milieu entre LP et HP ; FLANG / CHOR de l'INSERT attendent que leur ligne soit pleine ; une table WAVE, un patch FMX ou un modèle de filtre changés sur une note tenue font un creux et reviennent. -- **3 nouveaux sons** (TURING JUNO, MS20 VECTOR, DIODE VS BASS). **395 sons, 23 moteurs.** +- **Un son propre, sans clics** (un nouveau test de 46 cas rend chaque changement et vérifie qu'aucun échantillon ne saute) : le limiteur de sortie bouge en courbe en S ; les envois (CHOR / DLY / REV) et la DIST de l'INSERT glissent au lieu de sauter ; le TIME du delay passe en fondu de l'ancienne à la nouvelle prise ; la DEPTH du chorus glisse ; le FILT du master passe par le milieu entre LP et HP ; FLANG / CHOR de l'INSERT attendent que leur ligne soit pleine ; une table WAVE, un patch FMX ou un modèle de filtre changés sur une note tenue font un creux et reviennent. +- **GRAIN et SAMPLE sonnent dès l'installation** : quatre sources propres à Clipper, synthétisées (aucun enregistrement, 25 Ko de flash) : **VOX** (un petit chœur qui s'ouvre de « ou » à « a » : le POS de GRAIN parcourt la voyelle), **GLASS** (un harmonica de verre), **PAD** (sept dents de scie, le filtre qui s'ouvre), **AIR** (du souffle sur les harmoniques de la note). Dix sons GRAIN (VOX CLOUD, VOWEL DRIFT, ANGEL HALO, GLASS RAIN, CRYSTAL SWELL, FROZEN PAD, DARK DRONE, SCAN PAD, WIND CHOIR, BREATH GRAIN) et quatre SAMPLE (SAMPLE CHOIR, GLASS HARP, SAW ENSEMBLE, AIR FLUTE). SET / SRC 0 à 3 restent tes emplacements USR1 à USR4 ; les sources viennent après. +- **17 nouveaux sons** (ceux-là, TURING JUNO, MS20 VECTOR, DIODE VS BASS). **409 sons, 23 moteurs.** +- **Une passe sur tous les sons** (chacun rendu, mesuré et son spectre regardé) : la FM de DIGITAL ne se replie plus en bruit dans les aigus (son index tenu sous la limite de Nyquist, et qui glisse dans chaque bloc : plus de marche quand une basse mono redéclenche) ; CLAV moins agressif ; les plateaux de l'EQ master font glisser leur fréquence aussi. +- **Un nouveau logo** : un clipper sous voiles, dans la ligne de celui de SLOOP (sa voile devient quatre, une par couleur de piste), sur l'écran de démarrage, l'installeur, l'éditeur et ici. - **Corrigé** : un projet SLOOP 2.6 chargé dans Clipper lisait ses valeurs MOD SEQ / SPICE au-delà de celles de son INSERT (maintenant leurs valeurs par défaut). - **L'éditeur web** (protocole 14) : une carte **Tuning** (système, tonique, charger un .scl) et les nouveaux réglages. @@ -125,7 +140,7 @@ Tous deux proposés dans les discussions de Felucca (#145, #146) comme des faço | **HOME** | L'écran du synthé : le nom du son, sa famille, son numéro dans la liste, le moteur et un oscilloscope. Les 4 knobs règlent les contrôles principaux du son. | | **PRESETS** | Tous les sons, un par un. | | **ALGORITHM** | Saute à la famille suivante (PAD, BASS, LEAD, PLCK, KEYS, STAB, FX…). | -| **FX, EDIT, ARP, GLO, SAVE** | Un appui ouvre les pages. Bouton maintenu, le clavier joue toujours. Pages FX : FX, FILTER (avec MODL), DLY, REVERB, CHORUS. | +| **FX, EDIT, ARP, GLO, SAVE** | Un appui ouvre les pages. Bouton maintenu, le clavier joue toujours. Pages FX : FX, FILTER (avec MODL, le modèle de filtre), INSERT, INSERT 2, DLY, REVERB, CHORUS, EQ+COMP. Pages GLO : GLOBAL (tempo, swing, métronome, accord fin), MASTER, **TUNING** (l'accordage), SYSTEM (MIDI, synchro, CPU / LATE / PEAK). | | **SEQ, SEL** | Maintenus : SEQ montre les 16 pas sur les touches, SEL la tonalité et les accords. Un appui ouvre leurs pages. | | **REC** | Enregistre ce que tu joues dans le pattern. REC maintenu efface le pattern. | | **MIDI** | Omni : tous les canaux jouent le synthé. | @@ -134,7 +149,7 @@ Un projet de SLOOP se charge avec seulement sa première piste. ## 3. Jouer HYBRID -- Tourne **PRESETS** (ou **ALGORITHM** pour changer de famille). Les sons HYBRID sont rangés dans les familles : **CLIPPER**, POLY PAD, STRINGS, VOX, GLASS PAD et DRONE (PAD) ; ACID, WOBBLE, REESE, FOLD BASS et 808 SUB (BASS) ; SYNC LEAD, HOOVER, CHIP LEAD et TRANCE (LEAD) ; PLUCK, SAW PLUCK, FM BELL, SPACE BEL et METAL (PLCK) ; FM KEYS (KEYS) ; BRASS (STAB) ; RISER et INIT (FX). +- Tourne **PRESETS** (ou **ALGORITHM** pour changer de famille). Les sons HYBRID sont rangés dans les familles : **CLIPPER**, POLY PAD, STRINGS, VOX, GLASS PAD et DRONE (PAD) ; ACID, WOBBLE, REESE, FOLD BASS et 808 SUB (BASS) ; SYNC LEAD, HOOVER, CHIP LEAD et TRANCE (LEAD) ; PLUCK, SAW PLUCK, FM BELL, SPACE BEL et METAL (PLCK) ; FM KEYS (KEYS) ; BRASS (STAB) ; RISER et INIT (FX) ; et aussi MOOG BASS, MOOG LEAD, LADDER PAD, CLIP WIDE, DARK PAD, ACID HARD, BRIGHT BEL et SOFT SYNC. - Sur **HOME**, les 4 knobs règlent **CUT**, **RES**, **M1** et **M2**. - Page **EDIT** : CUT, RES, FENV (décalages sur les deux filtres), **PTCH** (le patch d'usine), et **M1 à M4**, quatre macros dont chaque patch choisit l'effet. Par exemple, sur CLIPPER, M1 ouvre le filtre et M2 élargit les supersaws. - Avec un clavier MIDI : pitch bend, molette (vibrato sur plusieurs patchs), aftertouch, sustain, et M1 à M4 sur les CC 16 à 19. @@ -149,6 +164,8 @@ Les autres boutons du panneau : Un projet garde le PTCH, mais pas le patch modifié : exporte-le pour le garder. +Les autres panneaux de l'onglet **Sound** : **FMX patch** (les six opérateurs, le routage en grille, STORE dans la banque, fichiers `.clipper-fmx.json`), **FM6** (les banques DX7 `.syx`), **MOD SEQ** (les quatre pistes à dessiner), **Tuning** (le système, la tonique, charger une gamme `.scl`), **Sound tools** (undo / redo, comparer, A / B, randomiser, ce qui a changé, l'enveloppe dessinée). Les onglets **Library**, **Samples** (samples et tables d'ondes) et **Projects** (sauvegarde complète) complètent. + Pour essayer l'éditeur sans la FM-1, ouvre `web/editor.html?mock=1` dans Chrome. ## 5. Le test dont j'ai besoin : les deux cœurs et la charge processeur @@ -161,9 +178,11 @@ C'est ce qui décide combien de voix Clipper peut jouer. La FM-1 doit être bran 4. Refais avec **POLY PAD**, **TRANCE**, un son **FMX** (FMX EP) et **ENSEMBLE** (STRINGS). 5. Si PEAK reste sous ~70 % et LATE ne monte pas, ferme la fenêtre, puis lance **`INSTALL-CLIPPER.bat 12`** (12 voix) et refais la mesure avec 12 notes. Si ça tient encore, essaie **`INSTALL-CLIPPER.bat 16`**. +Pour la 0.9, refais aussi la mesure avec **VINTAGE** à 127 et le filtre en **MOOG** ou **DIODE** sur un son ANALOG (8 notes), et tourne les réglages pendant qu'un accord est tenu (MODL, les envois, TIME du delay, INSERT FLANG / CHOR) : aucun clic ne doit s'entendre. + Envoie-moi les chiffres (avec et sans 2ND CORE). Signale aussi un son qui craque, une note qui reste coincée, un écran **FELUCCA CRASH** (prends-le en photo : il reste 10 s) ou un écran bizarre. ## Revenir en arrière - **Vers SLOOP** : lance `INSTALL-SLOOP.bat` depuis le dossier de SLOOP. Un son réglé sur HYBRID y jouera un autre moteur. -- **Vers le firmware officiel** : passe par la page d'installation (« back to the official V15 »), après avoir fait une sauvegarde. +- **Vers le firmware officiel** : passe par la page d'installation (« Revenir au firmware officiel (V15) »), après avoir fait une sauvegarde. diff --git a/README.md b/README.md index 8c5df96..febe3f8 100644 --- a/README.md +++ b/README.md @@ -7,9 +7,50 @@ Free and open source (GPL-3.0). It grew out of - - - - - - - - - - - - - - - + + + + + + + + + diff --git a/assets/logo/clipper-logo.png b/assets/logo/clipper-logo.png index c6e1aed..f1e8aee 100644 Binary files a/assets/logo/clipper-logo.png and b/assets/logo/clipper-logo.png differ diff --git a/assets/logo/clipper-logo.svg b/assets/logo/clipper-logo.svg index 13ff870..2c5bc52 100644 --- a/assets/logo/clipper-logo.svg +++ b/assets/logo/clipper-logo.svg @@ -1,21 +1,15 @@ - - - - - - - - - - - - - - - + + + + + + + + + diff --git a/assets/logo/clipper-splash.png b/assets/logo/clipper-splash.png index 23c8157..0a5bf98 100644 Binary files a/assets/logo/clipper-splash.png and b/assets/logo/clipper-splash.png differ diff --git a/firmware/src/bus.c b/firmware/src/bus.c index a3e9ab5..dd6a99c 100644 --- a/firmware/src/bus.c +++ b/firmware/src/bus.c @@ -69,10 +69,11 @@ static const uint16_t BUS_HI_K[25] = {5395, 5997, 6660, 7388, 8187, 9062, 10018, static struct { int32_t lo[2], hi[2], m1[2], m2[2]; /* the states, << 8 */ int32_t gl, gm, gh; /* the band gains now (10^(dB/20) - 1, Q12 << 4) */ + int32_t kl, kh; /* (0.9) the shelves' corners now (they glide too) */ int32_t env; /* the compressor's detector (Q15 peak, << 8) */ int32_t gc; /* its gain now, Q14 */ uint8_t eq_on; -} bus = {{0, 0}, {0, 0}, {0, 0}, {0, 0}, 0, 0, 0, 0, 16384, 0}; +} bus = {{0, 0}, {0, 0}, {0, 0}, {0, 0}, 0, 0, 0, 0, 0, 0, 16384, 0}; /* a TPT one-pole low-pass (k = g / (1 + g), Q16) of x; the state << 8 */ static inline int32_t bus_lp(int32_t x8, int32_t *s, int32_t k) @@ -89,7 +90,7 @@ static void bus_eq(int32_t *l, int32_t *r, uint32_t n) int32_t dl = bus_db(song.g[G_EQLOW], EQ_LOW_C), dm = bus_db(song.g[G_EQMID], EQ_MID_C), dh = bus_db(song.g[G_EQHIGH], EQ_HIGH_C); int32_t tl = BUS_DB[dl] << 4, tm = BUS_DB[dm] << 4, th = BUS_DB[dh] << 4, kl = BUS_LO_K[dl], kh = BUS_HI_K[dh]; - int32_t gl0 = bus.gl, gm0 = bus.gm, gh0 = bus.gh, gl1, gm1, gh1; + int32_t gl0 = bus.gl, gm0 = bus.gm, gh0 = bus.gh, gl1, gm1, gh1, kl0, kh0; uint32_t i, c; if (!tl && !tm && !th && !bus.gl && !bus.gm && !bus.gh) { if (bus.eq_on) { /* flat: off, the states cleared for the next time */ @@ -99,6 +100,8 @@ static void bus_eq(int32_t *l, int32_t *r, uint32_t n) } return; } + if (!bus.eq_on) /* (coming on: the corners from where they go) */ + bus.kl = BUS_LO_K[dl], bus.kh = BUS_HI_K[dh]; bus.eq_on = 1; /* the gains glide: an eighth of the way a block (~6 ms), the last step exact */ gl1 = bus.gl = gl0 + ((tl - gl0) >> 3) + (tl > gl0 ? 1 : tl < gl0 ? -1 : 0); @@ -108,6 +111,11 @@ static void bus_eq(int32_t *l, int32_t *r, uint32_t n) kl = gl1 < 0 ? BUS_LO_K[11] : BUS_LO_K[13]; if ((gh0 < 0) != (gh1 < 0) && gh1) kh = gh1 < 0 ? BUS_HI_K[11] : BUS_HI_K[13]; + /* (0.9) the corners glide as the gains do, sample by sample: a corner that jumped with a 12 dB turn moved the + * shelf's output at once (a click on a pad) */ + kl0 = bus.kl, kh0 = bus.kh; + bus.kl = kl0 + ((kl - kl0) >> 3) + (kl > kl0 ? 1 : kl < kl0 ? -1 : 0); + bus.kh = kh0 + ((kh - kh0) >> 3) + (kh > kh0 ? 1 : kh < kh0 ? -1 : 0); for (c = 0; c < 2u; c++) { int32_t *x = c ? r : l; for (i = 0; i < n; i++) { @@ -115,8 +123,8 @@ static void bus_eq(int32_t *l, int32_t *r, uint32_t n) int32_t g_l = gl0 + (((gl1 - gl0) * (int32_t)i) >> CTL_LOG2); int32_t g_m = gm0 + (((gm1 - gm0) * (int32_t)i) >> CTL_LOG2); int32_t g_h = gh0 + (((gh1 - gh0) * (int32_t)i) >> CTL_LOG2); - lo = bus_lp(s8, &bus.lo[c], kl) >> 8; - hp = s - (bus_lp(s8, &bus.hi[c], kh) >> 8); + lo = bus_lp(s8, &bus.lo[c], kl0 + (((bus.kl - kl0) * (int32_t)i) >> CTL_LOG2)) >> 8; + hp = s - (bus_lp(s8, &bus.hi[c], kh0 + (((bus.kh - kh0) * (int32_t)i) >> CTL_LOG2)) >> 8); v3 = s8 - bus.m2[c]; v1 = (int32_t)(((int64_t)BUS_A1 * bus.m1[c] + (int64_t)BUS_A2 * v3) >> 16); v2 = bus.m2[c] + (int32_t)(((int64_t)BUS_A2 * bus.m1[c] + (int64_t)BUS_A3 * v3) >> 16); diff --git a/firmware/src/eng_digital.c b/firmware/src/eng_digital.c index 0e410af..b315475 100644 --- a/firmware/src/eng_digital.c +++ b/firmware/src/eng_digital.c @@ -16,6 +16,7 @@ static void digital_note_on(track_t *t, voice_t *v) v->s[7] = 0; /* op 4 phase */ v->s[4] = 1 << 24; /* modulator envelope, Q24 */ v->s[5] = v->s[6] = 0; /* feedback history */ + v->s[3] = -1; /* the index of the block before (-1: none, a new note) */ } /* operator increment = carrier * ratio (Q8) without 32-bit overflow; kept below Nyquist */ @@ -34,21 +35,48 @@ static void digital_render(track_t *t, voice_t *v, int32_t *out, uint32_t n, con 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 */ + int32_t me, idx, fb = p[P_E6], fb1, fb2, didx, idq; /* 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); + { /* (Clipper 0.9) anti-aliasing: the index held where the sidebands (Carson: (index + 1) x the modulator) + * would pass ~16 kHz, from the fastest operator that modulates in this algorithm; a high note gets a + * little less bright instead of folding back as noise */ + static const uint8_t MODS[8] = {14, 14, 14, 14, 10, 8, 8, 0}; /* bit 1: op 2, 2: op 3, 3: op 4 */ + uint32_t mk = MODS[alg], im = 0, fm; + if (mk & 2u) + im = i2; + if ((mk & 4u) && i3 > im) + im = i3; + if ((mk & 8u) && i4 > im) + im = i4; + fm = ((im >> 16) * 44100u) >> 16; /* Hz */ + if (fm > 0u) { + int32_t cap = (int32_t)(161760u / fm) - 10; /* 16 kHz / fm - 1, in index steps (0.0989 rad) */ + idx = idx < cap ? idx : (cap > 0 ? cap : 0); + } + } + { /* (0.9) the index glides through the block from the last one: a new modulator envelope (a retriggered + * mono bass) or a fast decay no longer steps the waveform at the block's edge */ + int32_t i0 = v->s[3] < 0 ? idx : v->s[3]; + v->s[3] = idx; + idx = i0; + didx = ((v->s[3] - i0) * 2048) / (int32_t)(n ? n : 1u); /* Q11 per sample */ + } 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]; + idq = idx << 11; for (i = 0; i < n; i++) { int32_t o1, o2, o3, o4, s; + idx = idq >> 11; + idq += didx; o4 = sine_i((ph4 + digital_mod((fb1 + fb2) >> 1, fb))); fb2 = fb1; fb1 = o4; @@ -117,7 +145,7 @@ static const preset_t DIGITAL_PRESETS[] = { {"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, 58, 34, 18}, 0, 0, FX(10, 10, 6, 10)}, + {"CLAV", {3, 1, 3, 5, 84, 25, 7, 0}, {0, 58, 34, 18}, 0, 0, FX(10, 10, 6, 10)}, /* house piano: bright, fast hammer, the tine stack for the attack */ {"M1 PIANO", {4, 1, 2, 13, 74, 30, 12, 0}, {0, 86, 30, 48}, 0, 0, FX(0, 24, 14, 26)}, /* afro house / amapiano: round keys with a bell on top */ diff --git a/firmware/src/eng_grain.c b/firmware/src/eng_grain.c index b76b00e..ad0f52e 100644 --- a/firmware/src/eng_grain.c +++ b/firmware/src/eng_grain.c @@ -37,6 +37,11 @@ * (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 */ +#if CLIPPER_SYNTH +#define GR_OUT_SH 2 /* (0.9) Clipper: +6 dB, its clouds as loud as its other pads within the trims */ +#else +#define GR_OUT_SH 1 +#endif #define GR_NG 12 /* grains per part */ #define GR_SEG_LOG2 8 #define GR_SEG (1u << GR_SEG_LOG2) /* seek index interval, source samples */ @@ -99,14 +104,14 @@ typedef struct { } gr_part_t; /* (its state: the part's engine arena, engines.c eng_arena_of) */ -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 uint32_t gr_nz(uint32_t src) { return SMP_IS_SET(src) ? SMP_SETS[SMP_SET_OF(src)].nz : usr_nz[SMP_USR_OF(src) % 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]; + return SMP_IS_SET(src) ? &SMP_ZONES[SMP_SETS[SMP_SET_OF(src)].z0 + zl] : &usr_zone[SMP_USR_OF(src) % 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; + return SMP_IS_SET(src) ? 0u : usr_nz[SMP_USR_OF(src) % 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); } @@ -132,7 +137,7 @@ static inline int32_t gr_dec(const smp_zone_t *z, uint32_t pos, int32_t *pred, i 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; + int32_t zl = SMP_IS_SET(src) ? 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) @@ -414,13 +419,29 @@ static void grain_render(track_t *t, voice_t *v, int32_t *out, uint32_t n, const 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; + out[i] += mulq15(mulq15(y, amp_at(m, i)), VOICE_FS) << GR_OUT_SH; } v->s[2] = y; } -#if CLIPPER_SYNTH /* Clipper: no built-in samples: a cloud of the user's slot 1 */ +#if CLIPPER_SYNTH +/* Clipper (0.9): clouds of its own synthesized sources (SRC 4 VOX: "oo" opening to "ah", 5 GLASS: a glass harmonica, + * 6 PAD: seven saws, the filter opening, 7 AIR: breath on the note's harmonics; tools/gen_clipper_sets.py), then the + * user's slot 1 (SRC 0..3: USR1..USR4). POS moves through each source: LFO DEST SHP scans it */ static const preset_t GRAIN_PRESETS[] = { + /* name, {SRC, POS, SIZE, DENS, PTCH, SPRD, RAND, TONE}, {A D S R}, fenv, mono, sends */ + {"VOX CLOUD", {4, 85, 96, 92, 0, 30, 8, 96}, {70, 100, 120, 95}, 0, 0, FX(0, 40, 18, 72)}, + {"VOWEL DRIFT", {4, 34, 104, 86, 0, 18, 5, 100}, {80, 100, 124, 100}, 0, 0, FX(0, 34, 22, 74), + .x = {P_LD_SHP + 1, 44, P_LRATE + 1, 24, P_LWAVE + 1, 1}}, + {"ANGEL HALO", {4, 90, 72, 108, 12, 56, 12, 108}, {90, 100, 127, 108}, 0, 0, FX(0, 52, 30, 92)}, + {"GLASS RAIN", {5, 18, 30, 86, 0, 104, 30, 118}, {6, 100, 120, 96}, 0, 0, FX(0, 22, 46, 74)}, + {"CRYSTAL SWELL", {5, 96, 110, 100, 12, 14, 4, 112}, {96, 100, 127, 104}, 0, 0, FX(0, 36, 24, 84)}, + {"FROZEN PAD", {6, 108, 127, 127, 0, 4, 0, 100}, {80, 100, 127, 100}, 0, 0, FX(0, 50, 14, 70)}, + {"DARK DRONE", {6, 14, 116, 90, -12, 24, 18, 64}, {100, 100, 127, 110}, 0, 0, FX(0, 30, 14, 82)}, + {"SCAN PAD", {6, 60, 100, 96, 0, 12, 6, 104}, {70, 100, 124, 96}, 0, 0, FX(0, 46, 20, 70), + .x = {P_LD_SHP + 1, 52, P_LRATE + 1, 20, P_LWAVE + 1, 1}}, + {"WIND CHOIR", {7, 60, 100, 96, 0, 44, 10, 100}, {84, 100, 124, 100}, 0, 0, FX(0, 40, 24, 86)}, + {"BREATH GRAIN", {7, 50, 26, 94, 0, 110, 40, 110}, {10, 100, 120, 90}, 0, 0, FX(0, 20, 40, 72)}, {"USER GRAIN", {0, 40, 100, 90, 0, 30, 12, 80}, {70, 100, 120, 95}, 0, 0, FX(0, 50, 20, 75)}, }; #else diff --git a/firmware/src/eng_sample.c b/firmware/src/eng_sample.c index 28ee20d..07b4939 100644 --- a/firmware/src/eng_sample.c +++ b/firmware/src/eng_sample.c @@ -58,10 +58,19 @@ typedef struct { } 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]; -#if SMP_NSETS +/* SET (SAMPLE) / SRC (GRAIN) -> a built-in set or a user slot. The groovebox: the sets, then USR1..USR4. Clipper + * (0.9: its own synthesized sets, tools/gen_clipper_sets.py): USR1..USR4 first (0..3: what 0.2 .. 0.9 stored, the + * user's slots only), then the sets */ +#if CLIPPER_SYNTH +#define SMP_IS_SET(si) ((si) >= SMP_USER_SLOTS) +#define SMP_SET_OF(si) ((si) - SMP_USER_SLOTS) +#define SMP_USR_OF(si) (si) +static const char *const SMP_ALL_NAMES[SMP_NALL] = {"USR1", "USR2", "USR3", "USR4", SMP_SET_NAMES_INIT}; +#else +#define SMP_IS_SET(si) ((si) < SMP_NSETS) +#define SMP_SET_OF(si) (si) +#define SMP_USR_OF(si) ((si) - SMP_NSETS) static const char *const SMP_ALL_NAMES[SMP_NALL] = {SMP_SET_NAMES_INIT, "USR1", "USR2", "USR3", "USR4"}; -#else /* (Clipper: no built-in sets, the user's slots only) */ -static const char *const SMP_ALL_NAMES[SMP_NALL] = {"USR1", "USR2", "USR3", "USR4"}; #endif #ifndef SMP_USER_XIP /* host tests: a RAM image of the slots */ @@ -149,14 +158,14 @@ static inline int32_t sample_next(const smp_zone_t *z, voice_t *v, int loop) 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]; + if (SMP_IS_SET(si)) { + const smp_set_t *set = &SMP_SETS[SMP_SET_OF(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; + uint32_t k = SMP_USR_OF(si); 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; diff --git a/firmware/src/preset_trim_clipper.h b/firmware/src/preset_trim_clipper.h index 9c88a99..eaa3c62 100644 --- a/firmware/src/preset_trim_clipper.h +++ b/firmware/src/preset_trim_clipper.h @@ -8,11 +8,11 @@ static const int8_t PRESET_TRIM_CL[PTC_ENGINES][PTC_MAX] = { {/* 1.0 RHODES */ 23, /* 1.1 DX RHODES */ 16, /* 1.2 WURLI */ 23, /* 1.3 CLAV */ 14, /* 1.4 M1 PIANO */ 20, /* 1.5 AFRO KEYS */ 23, /* 1.6 TRAP BELL */ 6, /* 1.7 MUSIC BOX */ 7, /* 1.8 MARIMBA */ 23, /* 1.9 KALIMBA */ 23, /* 1.10 PLUGG BELL */ 16, /* 1.11 GLASS PAD */ -17, /* 1.12 FM BASS */ 11, /* 1.13 STEEL DRUM */ 23, /* 1.14 GLOCKEN */ 7, /* 1.15 CELESTA */ 12, /* 1.16 XYLOPHONE */ 23, /* 1.17 HARP */ 9, /* 1.18 BASS GTR */ 17, /* 1.19 TUBE BELL */ 1, /* 1.20 FM PLUCK */ 23, /* 1.21 FM GRAND */ 9, /* 1.22 DX BASS */ 9, /* 1.23 SUITCASE */ 11, /* 1.24 CHURCH BEL */ 0, /* 1.25 FM BRASS */ -9, /* 1.26 FM LEAD */ -4, /* 1.27 TOY PIANO */ 23, /* 1.28 SYN VIBES */ 16, /* 1.29 PERC ORGAN */ -18}, {/* 2.0 CZ BASS */ 23, /* 2.1 SOFT KEYS */ 23, /* 2.2 CZ STRING */ -21, /* 2.3 RESO PLUCK */ 19, /* 2.4 CZ BRASS */ 15, /* 2.5 CZ LEAD */ -9, /* 2.6 CZ PAD */ -23, /* 2.7 CZ RESO */ 5, /* 2.8 CZ SYNBASS */ 1, /* 2.9 CZ ORGAN */ -30, /* 2.10 CZ BELLS */ 23, /* 2.11 CZ SWEEP */ -5, /* 2.12 CZ CHOIR */ -18, /* 2.13 CZ PLUCK */ 23, /* 2.14 CZ SOLO */ 3, /* 2.15 CZ EPIANO */ 18}, {/* 3.0 GAME LEAD */ -4, /* 3.1 GB BASS */ 15, /* 3.2 8BIT ARP */ -4, /* 3.3 NES BASS */ 13, /* 3.4 CHIP CHORD */ 4, /* 3.5 1BIT BEEP */ 2, /* 3.6 WAVE LEAD */ 0, /* 3.7 CHIP NOISE */ 23, /* 3.8 GB PAD */ -12, /* 3.9 NES LEAD */ -6, /* 3.10 ZAP */ 23, /* 3.11 CHIP ARP */ -4}, - {/* 4.0 USER SMP */ 0}, + {/* 4.0 SAMPLE CHOIR */ 9, /* 4.1 GLASS HARP */ -9, /* 4.2 SAW ENSEMBLE */ -9, /* 4.3 AIR FLUTE */ 18, /* 4.4 USER SMP */ 0}, {/* 5.0 CHOIR AAH */ -26, /* 5.1 SOUL OOH */ -24, /* 5.2 TALKBOX */ -7, /* 5.3 WOW BASS */ 6, /* 5.4 HARMONICA */ -5, /* 5.5 ROBOT */ -2, /* 5.6 VOX PAD */ -21, /* 5.7 MALE CHOIR */ -23, /* 5.8 WHISPER */ 13, /* 5.9 ROBO VOX */ -16, /* 5.10 AAH LEAD */ -18, /* 5.11 UH BASS */ 0}, {/* 6.0 FAT BASS */ 23, /* 6.1 MIN STAB */ 23, /* 6.2 MIN7 STAB */ 23, /* 6.3 RAVE STAB */ 23, /* 6.4 DUB CHORD */ 23, /* 6.5 SAW PAD */ -11, /* 6.6 SYNC LEAD */ -3, /* 6.7 HOOVER */ 5, /* 6.8 ACCORDION */ 23, /* 6.9 ENSEMBLE */ -11, /* 6.10 80S POLY */ 23, /* 6.11 SQR LEAD */ -8, /* 6.12 POWER STAB */ 23, /* 6.13 PULSE PAD */ -16, /* 6.14 C64 BASS */ 4, /* 6.15 SID LEAD */ -13, /* 6.16 MAJ STAB */ 23, /* 6.17 SUS STAB */ 23, /* 6.18 BP PAD */ -8, /* 6.19 RING BELL */ 10}, {/* 7.0 SOUL ORGAN */ -14, /* 7.1 GOSPEL */ -10, /* 7.2 JAZZ ORGAN */ -8, /* 7.3 DIRTY B3 */ -10, /* 7.4 HOUSE ORGN */ -7, /* 7.5 ROCK ORGAN */ -12, /* 7.6 CHAPEL */ 11, /* 7.7 REGGAE ORG */ 23, /* 7.8 JAZZ PERC */ 2, /* 7.9 FULL ORGAN */ -9, /* 7.10 SOFT FLUTE */ -1, /* 7.11 BLUES ORGN */ -7, /* 7.12 STRING ORG */ -9, /* 7.13 REED ORGAN */ -14}, - {/* 8.0 USER GRAIN */ 0}, + {/* 8.0 VOX CLOUD */ 8, /* 8.1 VOWEL DRIFT */ 13, /* 8.2 ANGEL HALO */ 3, /* 8.3 GLASS RAIN */ 23, /* 8.4 CRYSTAL SWELL */ 18, /* 8.5 FROZEN PAD */ 23, /* 8.6 DARK DRONE */ 14, /* 8.7 SCAN PAD */ -5, /* 8.8 WIND CHOIR */ 16, /* 8.9 BREATH GRAIN */ 23, /* 8.10 USER GRAIN */ 0}, {/* 9.0 TINE EP */ 0, /* 9.1 GLASS BELL */ 4, /* 9.2 ROUND BASS */ 14, /* 9.3 BRASS SECT */ 23, /* 9.4 SOFT PAD */ 2, /* 9.5 WOOD BARS */ 23, /* 9.6 DRAWBARS */ 11, /* 9.7 NYLON PICK */ 23}, {/* 10.0 BELL TREE */ -10, /* 10.1 MODAL BAR */ 23, /* 10.2 STR PLUCK */ 17, /* 10.3 BOWED MTL */ -5, /* 10.4 THUMB PNO */ 23, /* 10.5 HAND DRUM */ 8, /* 10.6 MEMB TOMS */ 14, /* 10.7 SITAR */ 23, /* 10.8 PHYS HARP */ 14, /* 10.9 NYLON GTR */ 17, /* 10.10 STEEL GTR */ 23, /* 10.11 MUTED GTR */ 23, /* 10.12 PLUCK BASS */ 23, /* 10.13 KOTO */ 3, /* 10.14 BANJO */ 23, /* 10.15 CELLO BOW */ 3, /* 10.16 TANPURA */ -24, /* 10.17 CHIMES */ -15, /* 10.18 BIG BELL */ -12, /* 10.19 VIBRA BAR */ 3, /* 10.20 GLASS BOWL */ -7, /* 10.21 STEEL PAN */ -8, /* 10.22 WOOD BLOCK */ 23, /* 10.23 TABLA */ 3, /* 10.24 CONGA */ 7, /* 10.25 TIMPANI */ -15, /* 10.26 DULCIMER */ 20, /* 10.27 WOOD MALLET */ 13, /* 10.28 GAMELAN */ -5, /* 10.29 VIOLIN BOW */ 9, /* 10.30 MBIRA */ 4, /* 10.31 HARPSICH */ 23}, {/* 11.0 WIND */ -1, /* 11.1 RAIN */ 0, /* 11.2 NZ ARCADE */ 14, /* 11.3 NZ METAL */ 23, /* 11.4 OCEAN */ 23, /* 11.5 VINYL */ 23, /* 11.6 HISS */ -12, /* 11.7 RISER */ 0, /* 11.8 NZ SNARE */ 23, /* 11.9 BITCRUSH */ 17, /* 11.10 RADIO */ -9, /* 11.11 STATIC */ 23, /* 11.12 WHOOSH */ 10, /* 11.13 TONAL NZ */ 4}, diff --git a/firmware/src/ui.c b/firmware/src/ui.c index 1d9c2bc..8943696 100644 --- a/firmware/src/ui.c +++ b/firmware/src/ui.c @@ -544,6 +544,12 @@ static const struct { uint8_t kind, e; const char *name; } BANK[] = { {BK_PAD, ENGI_VECTOR, "CHOIR VS"}, /* Clipper 0.9 (appended: the favourites keep their places) */ {BK_PLUCK, ENGI_JUNO, "TURING JUNO"}, {BK_LEAD, ENGI_VECTOR, "MS20 VECTOR"}, {BK_BASS, ENGI_VECTOR, "DIODE VS BASS"}, + /* Clipper 0.9: GRAIN and SAMPLE on Clipper's own synthesized sources (tools/gen_clipper_sets.py) */ + {BK_PAD, ENGI_GRAIN, "VOX CLOUD"}, {BK_PAD, ENGI_GRAIN, "VOWEL DRIFT"}, {BK_PAD, ENGI_GRAIN, "ANGEL HALO"}, + {BK_FX, ENGI_GRAIN, "GLASS RAIN"}, {BK_PAD, ENGI_GRAIN, "CRYSTAL SWELL"}, {BK_PAD, ENGI_GRAIN, "FROZEN PAD"}, + {BK_PAD, ENGI_GRAIN, "DARK DRONE"}, {BK_PAD, ENGI_GRAIN, "SCAN PAD"}, {BK_PAD, ENGI_GRAIN, "WIND CHOIR"}, + {BK_FX, ENGI_GRAIN, "BREATH GRAIN"}, {BK_PAD, 4, "SAMPLE CHOIR"}, {BK_PAD, 4, "GLASS HARP"}, + {BK_PAD, 4, "SAW ENSEMBLE"}, {BK_LEAD, 4, "AIR FLUTE"}, #endif }; #define NBANK (sizeof BANK / sizeof BANK[0]) diff --git a/firmware/src/voice.c b/firmware/src/voice.c index 309e3be..5887f10 100644 --- a/firmware/src/voice.c +++ b/firmware/src/voice.c @@ -293,7 +293,7 @@ static void voice_start(track_t *t, voice_t *v, uint32_t note, uint32_t vel, int 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]; + int32_t s0 = v->s[0], s1 = v->s[1], s3 = v->s[3], 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; @@ -335,6 +335,7 @@ static void voice_start(track_t *t, voice_t *v, uint32_t note, uint32_t vel, int v->s[5] = s5; v->s[6] = s6; v->s[7] = s7; /* op 4 phase; the modulator envelope restarts */ + v->s[3] = s3; /* (0.9) the index glides there from where it was */ } else if (e == &ENG_LOFI) { v->s[0] = s0; v->s[4] = s4; diff --git a/tests/clean_test.c b/tests/clean_test.c index ea28cb4..372b597 100644 --- a/tests/clean_test.c +++ b/tests/clean_test.c @@ -58,6 +58,7 @@ static void neutral(track_t *t) t->p[P_LD_PIT] = 0, t->p[P_AMODE] = 0, t->p[P_ATK] = t->p[P_ATK] > 40 ? 40 : t->p[P_ATK]; } typedef void (*change_fn)(track_t *t, uint32_t k); +static int attacks_ok; /* (sounds loaded: from silence, a new sound's own attack is not a click) */ /* hold a chord, the steady sound, k changes (each followed by settle blocks), the steady sound again */ static void check(const char *what, uint32_t eng, uint32_t pi, change_fn fn, uint32_t k, uint32_t settle) { @@ -80,7 +81,7 @@ static void check(const char *what, uint32_t eng, uint32_t pi, change_fn fn, uin s = d2max(); run(150); steady = d2max(); - if (s > 2 * (steady > before ? steady : before) + 400 && s > worst) + if (s > 2 * (steady > before ? steady : before) + 400 && s > worst && !(attacks_ok && before < 8)) worst = s, at = (int32_t)j; before = steady; } @@ -151,11 +152,11 @@ int main(void) trk[1].p[P_LYMODE] = LY_OFF; song.g[G_BPM] = 120; for (e = 0; e < NENGINES; e++) { /* a sound loaded under the chord, every engine */ - char w[80]; - if (e == 4u || e == ENGI_GRAIN) - continue; /* (the user's samples: none here) */ + char w[80]; /* (0.9: SAMPLE and GRAIN too, on Clipper's own sources) */ + attacks_ok = 1; snprintf(w, sizeof w, "%s: sounds loaded under a held chord", ENGINES[e]->name); check(w, e, 0, ch_preset, ENGINES[e]->npresets < 6u ? ENGINES[e]->npresets - 1u : 5u, 40); + attacks_ok = 0; } check("ANALOG: VOICE steals (9 .. 12 notes on 8 voices)", 0, 12, ch_steal, 9, 30); check("ANALOG: MUTE on and off", 0, 13, ch_mute, 6, 30); diff --git a/tests/golden.txt b/tests/golden.txt index 190091d..ee8ef1b 100644 --- a/tests/golden.txt +++ b/tests/golden.txt @@ -24,28 +24,28 @@ preset/ANALOG/20_SAW_BASS 647eb690094b0b06 preset/ANALOG/21_SINE_PAD 225be334e8cf72a7 preset/ANALOG/22_MINI_BASS cb40c9b848c2d80b preset/ANALOG/23_MINI_LEAD 3f6c3247b4e038f1 -preset/DIGITAL/00_RHODES b62083dd25231ad8 -preset/DIGITAL/01_DX_RHODES 81f42b810b490c21 -preset/DIGITAL/02_WURLI 634a2f11a3cca298 -preset/DIGITAL/03_CLAV bed5aa5ec1585ac2 -preset/DIGITAL/04_M1_PIANO 7bf97161428c5789 -preset/DIGITAL/05_AFRO_KEYS c849c9df5be53a46 -preset/DIGITAL/06_TRAP_BELL 70196d4ee2763876 -preset/DIGITAL/07_MUSIC_BOX fca4c22c68ae3a49 -preset/DIGITAL/08_MARIMBA 07eeca1bab86ce40 -preset/DIGITAL/09_KALIMBA 9104dc667795cadb -preset/DIGITAL/10_PLUGG_BELL d614915cc4dfea42 -preset/DIGITAL/11_GLASS_PAD f33fd03c45bc6e7b -preset/DIGITAL/12_FM_BASS e702f105b4e31be7 -preset/DIGITAL/13_STEEL_DRUM dca4fd954c04785a -preset/DIGITAL/14_GLOCKEN 3df59ffe630e6ea9 -preset/DIGITAL/15_CELESTA eead7459b3169f76 -preset/DIGITAL/16_XYLOPHONE 3cbc70dc8dec34eb -preset/DIGITAL/17_HARP 5ff3af4fdc27390c -preset/DIGITAL/18_BASS_GTR 7734e26632d230ef -preset/DIGITAL/19_TUBE_BELL 65e97324d50298da -preset/DIGITAL/20_FM_PLUCK 93ca32163f7028b5 -preset/DIGITAL/21_FM_GRAND 74d924abd7c27f75 +preset/DIGITAL/00_RHODES f7254fef6dbfe89e +preset/DIGITAL/01_DX_RHODES b3e11ac32c635a74 +preset/DIGITAL/02_WURLI 9394537d7f061bb1 +preset/DIGITAL/03_CLAV dcea84e34c6a7f80 +preset/DIGITAL/04_M1_PIANO a8dd45927ce42a74 +preset/DIGITAL/05_AFRO_KEYS 01f1715ad85b2efa +preset/DIGITAL/06_TRAP_BELL 4dee306a492459dd +preset/DIGITAL/07_MUSIC_BOX 3d8ec11511247465 +preset/DIGITAL/08_MARIMBA 7529b44f60f28622 +preset/DIGITAL/09_KALIMBA cb8e5deeb0d07631 +preset/DIGITAL/10_PLUGG_BELL d5b4291ac17ac596 +preset/DIGITAL/11_GLASS_PAD a4daa58074964bf9 +preset/DIGITAL/12_FM_BASS 25c7bb8546717bc7 +preset/DIGITAL/13_STEEL_DRUM b56752a03118f544 +preset/DIGITAL/14_GLOCKEN 7f7fbf491a3a4c97 +preset/DIGITAL/15_CELESTA 9f128432693e9bc4 +preset/DIGITAL/16_XYLOPHONE 55e9b99c4faca223 +preset/DIGITAL/17_HARP 3b1739b1ca299551 +preset/DIGITAL/18_BASS_GTR d10a78e5027f1830 +preset/DIGITAL/19_TUBE_BELL 9f13b4a739281c77 +preset/DIGITAL/20_FM_PLUCK e43dcb4120bd6e50 +preset/DIGITAL/21_FM_GRAND 3aabba535f98be01 preset/PHASE/00_CZ_BASS e96706957d91ecae preset/PHASE/01_SOFT_KEYS 5f0e4fe55c4ce76a preset/PHASE/02_CZ_STRING 7db0fca714217b45 @@ -187,10 +187,10 @@ mode/ANALOG/POLY a7a9ef2a2e63290c mode/ANALOG/MONO 9583d8d67d814abc mode/ANALOG/LEGATO 688683752bbf85f8 mode/ANALOG/UNISON 8bb858f31b261198 -mode/DIGITAL/POLY 81f42b810b490c21 -mode/DIGITAL/MONO e79a15b9af2d8570 -mode/DIGITAL/LEGATO 979838bb49ba2760 -mode/DIGITAL/UNISON 3195a4d97b069829 +mode/DIGITAL/POLY b3e11ac32c635a74 +mode/DIGITAL/MONO 259a9063e578f0f3 +mode/DIGITAL/LEGATO af2ac0d2e697b81e +mode/DIGITAL/UNISON c623eda546eb4034 mode/VOICE/POLY 9d631818998e4fcf mode/VOICE/MONO 9450adb85fb70d90 mode/VOICE/LEGATO 1a04dbc937476869 @@ -201,13 +201,13 @@ sends/ANALOG/delay afca9fa890650d3c sends/ANALOG/reverb 7a9ee7a261797e1e sends/ANALOG/all a392a524049f8e91 sends/ANALOG/dist 917a9fdf6aa27763 -sends/DIGITAL/dry 3f72412f9006460c -sends/DIGITAL/chorus def2c63365cee4da -sends/DIGITAL/delay 0b232f20f9015c90 -sends/DIGITAL/reverb 29b9c515f012bd0c -sends/DIGITAL/all 25e149e3a2567b5e -sends/DIGITAL/dist dc90f710521f8da1 -song/4track_mix f2c14e52d7d380ce +sends/DIGITAL/dry 25f613bc779a9c24 +sends/DIGITAL/chorus 52c8d28f04b3cc3a +sends/DIGITAL/delay 820d0499a03b854c +sends/DIGITAL/reverb 14246300e567c350 +sends/DIGITAL/all d45af383afcc168a +sends/DIGITAL/dist 873e64bb5e5d9d2c +song/4track_mix 7790b3cf8db30236 slicer/gate/ANALOG_DARK_STR 23376a6defb8ab6f -slicer/stut/DIGITAL_RHODES 692678a659332022 -slicer/song_gate_stut 1f6869b794a1e026 +slicer/stut/DIGITAL_RHODES 8918a6dcb14114e9 +slicer/song_gate_stut ce6b4ce66d669330 diff --git a/tests/preset_level.c b/tests/preset_level.c index 7974dda..89843dd 100644 --- a/tests/preset_level.c +++ b/tests/preset_level.c @@ -16,7 +16,8 @@ static int role_of(const char *n) if (has(n, "PAD") || has(n, "STR") || has(n, "CHOIR") || has(n, "OOH") || has(n, "ORGAN") || has(n, "ORGN") || has(n, "GOSPEL") || has(n, "B3") || has(n, "CLOUD") || has(n, "HAZE") || has(n, "ATMOS") || has(n, "ENSEMBLE") || has(n, "DRONE") || has(n, "SHIMMER") || has(n, "OCEAN") || has(n, "RISER") || has(n, "WIND") || has(n, "HISS") || has(n, "VINYL") || - has(n, "RAIN") || has(n, "BOWL") || has(n, "BOW") || has(n, "TANPURA")) + has(n, "RAIN") || has(n, "BOWL") || has(n, "BOW") || has(n, "TANPURA") || has(n, "HALO") || has(n, "SWELL") || + has(n, "VOWEL") || has(n, "GLASS HARP")) /* (0.9: GRAIN's and SAMPLE's slow pads) */ return R_HELD; if ((has(n, "STAB") && !has(n, "HORN") && !has(n, "STRING")) || has(n, "CHORD")) return R_ONE; /* TRIO stabs: one key plays the chord */ diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 840c785..e792976 100644 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -181,7 +181,7 @@ if $SYN_UB -o "$OUT/synth9_ub" tests/synth9_test.c -lm 2>/dev/null; then run "Clipper 0.9 under ASan + UBSan" sh -c "'$OUT/synth9_ub' >/dev/null && echo clean" fi $SYN -o "$OUT/clean_test" tests/clean_test.c -lm -run "Clipper 0.9 audio: no click or crackle (45 cases: presets of every engine, steals, mute, level, pan, INSERT, DIST, the sends, FILT, MODL, CHOR, VINTAGE, delay TIME, reverb SIZE, EQ, WAVE TABL, FMX PTCH, engine switch, TUNING, LAYER, MOD SEQ)" "$OUT/clean_test" +run "Clipper 0.9 audio: no click or crackle (46 cases: presets of every engine, steals, mute, level, pan, INSERT, DIST, the sends, FILT, MODL, CHOR, VINTAGE, delay TIME, reverb SIZE, EQ, WAVE TABL, FMX PTCH, engine switch, TUNING, LAYER, MOD SEQ)" "$OUT/clean_test" if $SYN_UB -o "$OUT/clean_ub" tests/clean_test.c -lm 2>/dev/null; then run "Clipper 0.9 audio under ASan + UBSan" sh -c "'$OUT/clean_ub' >/dev/null && echo clean" fi diff --git a/tools/gen_clipper_sets.py b/tools/gen_clipper_sets.py new file mode 100644 index 0000000..6957655 --- /dev/null +++ b/tools/gen_clipper_sets.py @@ -0,0 +1,234 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-3.0-only +# Copyright (C) 2026 3dSam (Clipper) +"""Clipper's built-in sources for GRAIN and SAMPLE, synthesized here (no recording, no third party): + + VOX a small choir, "oo" opening to "ah" (the vowel moves through the first third: GRAIN's POS scans it) + GLASS a glass harmonica: beating inharmonic partials, the top fading slowly (POS: bright to pure) + PAD a seven-saw ensemble, its low-pass opening through the first half (POS: dark to bright) + AIR breath through resonances on the note's harmonics: a flute / whistle of air + + tools/gen_clipper_sets.py [OUT_DIR] (default assets/clipper-sets): one mono 16-bit WAV a set and sets.json + (name, file, rate, root, loop start / end in samples, the last one played). tools/gen_samples.py reads them + into the Clipper build (IMA ADPCM, ~25 KB of flash). Needs numpy and scipy; the WAVs are in the tree, so the + build does not run this. Deterministic (fixed seeds). + +Each sound sustains on a loop whose seam is cross-faded (equal power over 90 ms): SAMPLE holds a note on it. +Stored at 16 kHz with nothing above ~6.3 kHz: a note two octaves over the root still stays under 22 kHz. +""" +import json +import sys +import wave +from pathlib import Path + +import numpy as np +from scipy.signal import butter, resample_poly, sosfiltfilt, sosfilt + +FS = 48000 # synthesis rate +OUT_SR = 16000 # stored rate +TOP = 6300.0 # nothing above (Hz) +ROOT = Path(__file__).resolve().parents[1] + + +def hz(m): + return 440.0 * 2 ** ((m - 69) / 12) + + +def smooth_noise(rng, n, rate_hz, fs=FS): + """slow random curve, -1..1, about rate_hz wiggles a second""" + k = max(2, int(n / fs * rate_hz) + 3) + pts = rng.uniform(-1, 1, k) + x = np.linspace(0, k - 1, n) + i = np.floor(x).astype(int).clip(0, k - 2) + f = x - i + f = f * f * (3 - 2 * f) + return pts[i] * (1 - f) + pts[i + 1] * f + + +def vib(rng, n, rate, depth_ct, onset_s): + """vibrato in cents: a slightly wandering rate, fading in""" + t = np.arange(n) / FS + r = rate * (1 + 0.06 * smooth_noise(rng, n, 0.7)) + ph = 2 * np.pi * np.cumsum(r) / FS + rng.uniform(0, 2 * np.pi) + fade = np.clip(t / onset_s, 0, 1) ** 2 + return depth_ct * fade * np.sin(ph) + 3.0 * smooth_noise(rng, n, 3.0) + + +def additive(f0_t, amp_fn, nmax, rng): + """harmonics of a time-varying f0 (array, Hz), amp_fn(k, fk) -> per-sample amplitude; band-limited to TOP""" + phase0 = 2 * np.pi * np.cumsum(f0_t) / FS + out = np.zeros_like(f0_t) + for k in range(1, nmax + 1): + fk = k * f0_t + if fk.min() > TOP: + break + a = amp_fn(k, fk) * np.clip((TOP - fk) / 400.0, 0, 1) + out += a * np.sin(k * phase0 + rng.uniform(0, 2 * np.pi)) + return out + + +def fenv(f, formants): + """vowel envelope at f: sum of resonance peaks (freq, bandwidth, dB)""" + e = np.zeros_like(f) + for fc, bw, db in formants: + e += 10 ** (db / 20) / (1 + ((f - fc) / (bw / 2)) ** 2) + return e + + +A_ = [(800, 110, 0), (1150, 120, -6), (2800, 160, -26), (3500, 180, -32), (4950, 200, -48)] +O_ = [(450, 90, 0), (800, 100, -10), (2830, 150, -28), (3500, 170, -32), (4950, 200, -50)] +U_ = [(350, 80, 0), (650, 90, -16), (2700, 150, -34), (3300, 170, -40), (4950, 200, -56)] + + +def vowel_mix(t, dur): + """weights of U, O, A over time: oo .. oh .. ah through the first third, then ah""" + x = np.clip(t / (0.34 * dur), 0, 1) + x = x * x * (3 - 2 * x) + wu = np.clip(1 - 2 * x, 0, 1) + wa = np.clip(2 * x - 1, 0, 1) + wo = 1 - wu - wa + return wu, wo, wa + + +def vox(rng, dur=0.92, root=57): + n = int(dur * FS) + t = np.arange(n) / FS + wu, wo, wa = vowel_mix(t, dur) + out = np.zeros(n) + for v, dt in enumerate([-9, -4, 0, 3, 7, 11]): + cents = dt + vib(rng, n, 5.1 + 0.35 * v % 1.1, 13, 0.25) + f0 = hz(root + (12 if v % 3 == 2 else 0)) * 2 ** (cents / 1200) # two of six an octave up (altos) + + kk = np.arange(1, 60) + f_mean = kk * float(np.mean(f0)) + norm = [np.sqrt(np.sum((fenv(f_mean, V) / kk ** 1.15 * (f_mean < TOP)) ** 2)) for V in (U_, O_, A_)] + + def amp(k, fk): # each vowel as loud as the others (ah is quieter: its F1 is high) + src = 1.0 / k ** 1.15 + return src * (wu * fenv(fk, U_) / norm[0] + wo * fenv(fk, O_) / norm[1] + wa * fenv(fk, A_) / norm[2]) + sh = 1 + 0.12 * smooth_noise(rng, n, 4.0) + out += additive(f0, amp, 60, rng) * sh * (0.7 if v % 3 == 2 else 1.0) + br = rng.standard_normal(n) # breath: noise through the formants + spec = np.fft.rfft(br) + fr = np.fft.rfftfreq(n, 1 / FS) + br = np.fft.irfft(spec * (fenv(fr, A_) * 0.7 + fenv(fr, O_) * 0.3) * (fr < TOP), n) + out = out / np.max(np.abs(out)) + 0.035 * br / np.std(br) + return out, root + + +def glass(rng, dur=0.8, root=72): + """synthesized straight at OUT_SR, its sustain exactly periodic over the loop (N samples): every partial and + every beat a whole number of turns in it, so the loop needs no cross-fade (two sines cross-faded out of phase + dip and smear)""" + f0 = hz(root) + m = round(f0 * 0.44) # the root's turns in the loop (~0.44 s) + N = round(m * OUT_SR / f0) # the loop, samples (the root off by < 0.5 cent) + T = N / OUT_SR + n = int(dur * OUT_SR) + ls = n - N + t = np.arange(n) / OUT_SR + parts = [(1.0, 1.0, 1), (2.005, 0.42, 1), (2.99, 0.30, 0), (4.02, 0.18, 1), (5.41, 0.11, 0), + (6.79, 0.065, 1), (8.21, 0.04, 0), (10.5, 0.02, 1)] + x = np.clip(t / (ls / OUT_SR), 0, 1) + x = x * x * (3 - 2 * x) # 0 .. 1 by the loop's start, then held + out = np.zeros(n) + for i, (r, a, beat) in enumerate(parts): + k = round(f0 * r * T) # turns in the loop + if k / T > TOP: + continue + level = 1.0 - (0.15 + 0.6 * i / len(parts)) * x # the top fades towards the loop, then holds + for s in ((-1, 1) if beat else (0,)): + kk = k + s # a beating pair: one turn apart over the loop (~2.3 Hz) + out += (0.5 if beat else 1.0) * a * level * np.sin(2 * np.pi * kk / T * t + rng.uniform(0, 2 * np.pi)) + fi = int(0.05 * OUT_SR) + out[:fi] *= (np.arange(fi) / fi) ** 1.5 + return out, root, ls + + +def pad(rng, dur=0.82, root=60): + n = int(dur * FS) + t = np.arange(n) / FS + cut = 700 * (4.2 ** np.clip(t / (0.45 * dur), 0, 1) ** 1.2) # 700 Hz .. ~2.9 kHz, then held + out = np.zeros(n) + for v, dt in enumerate([-21, -13, -6, 0, 6, 13, 21]): + cents = dt + 4 * smooth_noise(rng, n, 1.5) + f0 = hz(root) * 2 ** (cents / 1200) + + def amp(k, fk): + return (1.0 / k) / np.sqrt(1 + (fk / cut) ** 4) # 12 dB / octave over the cut + out += additive(f0, amp, 40, rng) * (0.8 if v in (0, 6) else 1.0) + out += 0.25 * additive(np.full(n, hz(root - 12)), lambda k, fk: (k == 1) * 1.0, 1, rng) # a little sub + return out, root + + +def air(rng, dur=0.62, root=72): + n = int(dur * FS) + t = np.arange(n) / FS + f0 = hz(root) * 2 ** (vib(rng, n, 4.6, 6, 0.3) / 1200) + w = rng.standard_normal(n) + out = np.zeros(n) + for k, (q, g) in enumerate([(70, 1.0), (55, 0.45), (45, 0.22), (40, 0.1)], start=1): # resonances on the harmonics + fc = f0 * k + if fc.max() > TOP: + break + y = np.zeros(n) # a two-pole resonator, its frequency moving with f0 + y1 = y2 = 0.0 + for i in range(n): + th = 2 * np.pi * fc[i] / FS + rr = 1 - th / (2 * q) * 2 + b = (1 - rr * rr) * 0.5 + yi = b * w[i] + 2 * rr * np.cos(th) * y1 - rr * rr * y2 + y2, y1 = y1, yi + y[i] = yi + out += g * y / np.std(y) + breath = sosfilt(butter(2, [300, 5500], btype="band", fs=FS, output="sos"), rng.standard_normal(n)) + swell = 0.8 + 0.2 * smooth_noise(rng, n, 2.5) + out = (out + 0.28 * breath / np.std(breath)) * swell + return out, root + + +def finish(x, loop_from): + """to OUT_SR, nothing above TOP, a 5 ms fade in, the loop [ls, le] with its seam cross-faded, -1 dBFS""" + x = sosfiltfilt(butter(8, TOP, fs=FS, output="sos"), x) + x = sosfiltfilt(butter(2, 40, btype="high", fs=FS, output="sos"), x) + y = resample_poly(x, OUT_SR // 1000, FS // 1000) + n = len(y) + fi = int(0.005 * OUT_SR) + y[:fi] *= np.linspace(0, 1, fi) + ls, le = int(loop_from * n), n - 1 + L = int(0.09 * OUT_SR) + j = np.arange(L) + w = np.sin(0.5 * np.pi * (j + 1) / L) + k = le - L + 1 + j + y[k] = y[k] * np.cos(0.5 * np.pi * (j + 1) / L) + y[ls - L + j] * w # y[le] flows into y[ls] + y *= 0.89 * 32767 / np.max(np.abs(y)) + return np.round(y).astype(np.int16), ls, le + + +def main(out_dir): + out_dir = Path(out_dir) + out_dir.mkdir(parents=True, exist_ok=True) + meta = [] + for name, fn, loop_from, seed in (("VOX", vox, 0.5, 11), ("GLASS", glass, None, 12), ("PAD", pad, 0.55, 13), + ("AIR", air, 0.3, 14)): + r = fn(np.random.default_rng(seed)) + if loop_from is None: # (already at OUT_SR, its loop exact) + x, root, ls = r + y = np.round(x * 0.89 * 32767 / np.max(np.abs(x))).astype(np.int16) + le = len(y) - 1 + else: + x, root = r + y, ls, le = finish(x, loop_from) + f = out_dir / f"{name.lower()}.wav" + with wave.open(str(f), "wb") as w: + w.setnchannels(1) + w.setsampwidth(2) + w.setframerate(OUT_SR) + w.writeframes(y.tobytes()) + meta.append(dict(name=name, file=f.name, rate=OUT_SR, root=root, ls=ls, le=le)) + print(f"{name}: {len(y)} samples, {len(y) / OUT_SR:.2f} s, root {root}, loop {ls}..{le}") + (out_dir / "sets.json").write_text(json.dumps(meta, indent=1) + "\n") + + +if __name__ == "__main__": + main(sys.argv[1] if len(sys.argv) > 1 else ROOT / "assets" / "clipper-sets") diff --git a/tools/gen_logo.py b/tools/gen_logo.py index c6a41ec..1aec80a 100644 --- a/tools/gen_logo.py +++ b/tools/gen_logo.py @@ -1,8 +1,9 @@ #!/usr/bin/env python3 # SPDX-License-Identifier: GPL-3.0-only -"""The Clipper logo: a three-masted clipper, its square sails in the four track colours (blue, green, yellow, -orange) inside a 270-degree dial (the knobs of the UI), a hull, and a geometric monoline wordmark "clipper" -(the line of SLOOP's, from which Clipper comes). +"""The Clipper logo: a clipper under sail inside a 270-degree dial (the knobs of the UI), in the line of SLOOP's +logo: the sloop's one triangular sail becomes four, a jib and three fore-and-aft sails filled by the wind, one per +track colour (orange, yellow, green, blue), three raked masts on a long low hull with a sharp bow, and a geometric +monoline wordmark "clipper" (SLOOP's). tools/gen_logo.py OUT.h firmware boot splash (RLE, 16-colour palette, RGB565) tools/gen_logo.py --assets DIR clipper-logo.svg/png, clipper-icon.svg/png, clipper-splash.png @@ -67,26 +68,65 @@ class Pen: self.svg.append('') -# ---- the icon: the dial, three masts with their sails, the hull --------------------------------- -MASTS = [(-46, -58, 3), (0, -84, 4), (46, -58, 3)] # x from the centre, top, tiers of sails -SAIL_COLS = [ORANGE, YELLOW, GREEN, BLUE] # from the lowest tier up -BOT, HULL = 38, 52 +# ---- the icon: the dial (the UI's knobs) round a clipper under sail, the line of SLOOP's logo: its sloop's one +# triangular sail becomes a clipper's four, one per track colour, the leeches filled by the wind; the bow to the left +# (as the sloop sails), a jib out to the bowsprit, three raked masts, a long low hull -------------------------- +RAKE = 4 # the masts lean aft: their tops this far to the right + + +def curve(p0, p1, bulge, n=10): + """points from p0 to p1 bowed out to the right of the travel by bulge (a quadratic)""" + (x0, y0), (x1, y1) = p0, p1 + mx, my = (x0 + x1) / 2, (y0 + y1) / 2 + dx, dy = x1 - x0, y1 - y0 + L = math.hypot(dx, dy) + cx, cy = mx - dy / L * bulge * 2, my + dx / L * bulge * 2 + return [((1 - t) ** 2 * x0 + 2 * (1 - t) * t * cx + t * t * x1, (1 - t) ** 2 * y0 + 2 * (1 - t) * t * cy + t * t * y1) + for t in (i / n for i in range(n + 1))] + + +class Ship: + """the ship drawn scaled about the dial's centre (S) and moved (SX, SY), so it sits clear inside the dial""" + + def __init__(self, pen, cx, cy, k=0.86, sx=4, sy=8): + self.pen, self.cx, self.cy, self.k, self.sx, self.sy = pen, cx, cy, k, sx, sy + + def T(self, x, y): + return self.cx + (x - self.cx) * self.k + self.sx, self.cy + (y - self.cy) * self.k + self.sy + + def line(self, x0, y0, x1, y1, w): + self.pen.line(*self.T(x0, y0), *self.T(x1, y1), w=w) + + def poly(self, pts, col): + self.pen.poly([self.T(x, y) for x, y in pts], col) def icon(pen, ox, oy): cx, cy = ox + 120, oy + 120 pen.arc(cx, cy, 100, 135, 405) - for dx, top, n in MASTS: - mx, y0, y1 = cx + dx, cy + top, cy + BOT - pen.line(mx, y0 - 2, mx, y1 + 12, w=8) - gap, h = 5, (y1 - y0 - 4 * 5) / 4 # tiers of the same height on every mast - for i in range(n): # i = 0 the lowest - b = y1 - i * (h + gap) - t = b - h - wb, wt = 19 - 2.5 * i, 17 - 2.5 * i # half widths: narrower up the mast - pen.poly([(mx - wt, t), (mx + wt, t), (mx + wb, b), (mx - wb, b)], SAIL_COLS[i]) - pen.line(cx - HULL, cy + BOT + 18, cx + HULL, cy + BOT + 18, w=12) - pen.line(cx - HULL + 14, cy + BOT + 32, cx + HULL - 14, cy + BOT + 32, w=8) + sh = Ship(pen, cx, cy) + deck, foot = cy + 52, cy + 40 # the deck; the sails' feet, over the deck + masts = [(-38, -66), (2, -88), (40, -60)] # fore, main, mizzen: x from the centre, top + tops = [] + for dx, top in masts: + x0, x1 = cx + dx, cx + dx + RAKE + sh.line(x0, deck - 2, x1, cy + top, w=7) + tops.append((x1, cy + top)) + # the sails: luff on the mast (clear of it), foot over the deck, leech bowed by the wind + widths = [30, 34, 28] + for (x1, ty), (dx, top), w, col in zip(tops, masts, widths, (YELLOW, GREEN, BLUE)): + xb = cx + dx + 7 # the luff at the foot (the mast leans) + luff_top = (x1 + 7 - 1, ty + 8) + clew = (xb + w, foot) + sh.poly([luff_top] + curve(luff_top, clew, 5)[1:] + [(xb, foot)], col) + fx, fty = tops[0] # the jib: from the foremast's head to the bowsprit + head, tack = (fx - 7, fty + 12), (cx - 90, foot - 4) + sh.poly([head, (fx - 7, foot), tack] + curve(tack, head, 3)[1:-1], ORANGE) + sh.line(cx - 70, deck - 8, cx - 96, foot - 6, w=5) # the bowsprit + # the hull: long and low, a raised sharp bow forward (the clipper's), a sheer that falls aft, a short counter + hull = curve((cx - 88, deck - 12), (cx + 78, deck - 3), 2)[:-1] + [(cx + 78, deck - 3), (cx + 72, deck + 11)] + \ + curve((cx + 72, deck + 11), (cx - 58, deck + 15), -2)[1:] + sh.poly(hull, WHITE) # ---- the wordmark "clipper": circles of the x-height, verticals, round ends ----------------------- diff --git a/tools/gen_samples.py b/tools/gen_samples.py index c996a95..519fbfb 100644 --- a/tools/gen_samples.py +++ b/tools/gen_samples.py @@ -24,6 +24,7 @@ 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 json import math import os import re @@ -442,26 +443,61 @@ def input_key(have_cc0): return h.hexdigest() -CLIPPER_EMPTY = """ -/* Clipper (CLIPPER_SYNTH): no built-in samples (~300 KB of flash for synthesis): SAMPLE and GRAIN play the user's - * slots USR1..4 (sent from the editor). The groovebox (CLIPPER_SYNTH 0, the tests) keeps the sets above. */ -static const uint8_t SMP_DATA[4] = {0, 0, 0, 0}; -static const smp_zone_t SMP_ZONES[] = {{0, 0, 0, 0, 65536, 960, 0, 0, 0, 127, 0}}; -static const smp_set_t SMP_SETS[] = {{"NONE", 0, 1}}; -#define SMP_NSETS 0 -static const preset_t SMP_PRESET_TABLE[] = { - {"USER SMP", {0, 0, 0, 1, 127, 0, 0, 0}, {0, 110, 110, 40}, 0, 0, FX(0, 10, 12, 24)}, -}; -#define SMP_SET_NAMES_INIT -static const char *const SMP_SET_NAMES[] = {"NONE"}; -#define SLC_BREAK_INIT {0} -""" +CLIPPER_SETS = SRC / "assets" / "clipper-sets" # Clipper's own synthesized sources (tools/gen_clipper_sets.py) +# Clipper's SAMPLE presets: name, set, {SET (filled in), TUNE, BITS, LOOP, CUT, -, DRV, -}, env, mono, sends, more +CLIPPER_SMP_PRESETS = [ + ("SAMPLE CHOIR", "VOX", [0, 0, 0, 1, 108, 0, 0, 0], (58, 100, 122, 84), 0, (0, 34, 18, 66), ("P_VINT", 40)), + ("GLASS HARP", "GLASS", [0, 0, 0, 1, 118, 0, 0, 0], (18, 100, 116, 80), 0, (0, 22, 30, 66), ()), + ("SAW ENSEMBLE", "PAD", [0, 0, 0, 1, 104, 0, 0, 0], (34, 100, 120, 60), 0, (0, 44, 14, 48), ("P_VINT", 50)), + ("AIR FLUTE", "AIR", [0, 0, 0, 1, 112, 0, 0, 0], (22, 100, 120, 42), 1, (0, 12, 26, 52), + ("P_LD_PIT", 1, "P_LRATE", 88, "P_LFADE", 50)), +] + + +def clipper_block(): + """Clipper (CLIPPER_SYNTH): no recorded samples (~300 KB of flash for synthesis); four small synthesized sources + for SAMPLE and GRAIN (~25 KB), then the user's slots USR1..4 (sent from the editor). The SET / SRC values: 0..3 + the user's slots (as before), 4.. these sets (eng_sample.c SMP_IS_SET)""" + meta = json.loads((CLIPPER_SETS / "sets.json").read_text()) + blob, zones, sets = bytearray(), [], [] + for e in meta: + sr, x = read_any_wav(CLIPPER_SETS / e["file"]) + x = [max(-32768, min(32767, int(round(v * 32768)))) for v in x] # (read_any_wav: -1..1) + enc, st = ima_encode(x, e["ls"]) + off = len(blob) + blob += enc + if len(blob) & 1: + blob.append(0) + rate = int(round(sr / 44100 * 65536)) + sets.append((e["name"], len(zones), 1)) + zones.append(f" {{{off}, {len(x)}, {e['ls']}, {e['le']}, {rate}, {e['root'] * 16}, {st[0]}, {st[1]}, 0, 127, 1}},") + L = ["", "/* Clipper (CLIPPER_SYNTH): its own synthesized sources (tools/gen_clipper_sets.py, assets/clipper-sets),", + " * SET / SRC 4.. (0..3: the user's slots USR1..4, sent from the editor) */"] + L.append(f"static const uint8_t SMP_DATA[{len(blob)}] = {{") + for i in range(0, len(blob), 32): + L.append(" " + ",".join(map(str, blob[i:i + 32])) + ",") + L += ["};", "static const smp_zone_t SMP_ZONES[] = {"] + zones + ["};", "static const smp_set_t SMP_SETS[] = {"] + L += [f' {{"{n}", {z0}, {nz}}},' for n, z0, nz in sets] + ["};", f"#define SMP_NSETS {len(sets)}"] + L.append("static const preset_t SMP_PRESET_TABLE[] = {") + names = [n for n, _, _ in sets] + for pname, setname, e, env, mono, fx, more in CLIPPER_SMP_PRESETS: + e = list(e) + e[0] = 4 + names.index(setname) + x = ", ".join(f"{more[j]} + 1, {more[j + 1]}" for j in range(0, len(more), 2)) + L.append(f' {{"{pname}", {{{", ".join(map(str, e))}}}, {{{", ".join(map(str, env))}}}, 0, {mono}, ' + f'FX({", ".join(map(str, fx))}){", .x = {" + x + "}" if x else ""}}},') + L.append(' {"USER SMP", {0, 0, 0, 1, 127, 0, 0, 0}, {0, 110, 110, 40}, 0, 0, FX(0, 10, 12, 24)},') + L.append("};") + L.append("#define SMP_SET_NAMES_INIT " + ", ".join(f'"{n}"' for n in names)) + L.append("static const char *const SMP_SET_NAMES[] = {SMP_SET_NAMES_INIT};") + L.append("#define SLC_BREAK_INIT {0}") + return "\n".join(L) + "\n" def clipper_wrap(text): """the sets for the groovebox; none for the Clipper synth (CLIPPER_SYNTH, core.h, defined before this header)""" head, sep, body = text.partition("#include \n") - return head + sep + "#if !CLIPPER_SYNTH\n" + body + "#else" + CLIPPER_EMPTY + "#endif\n" + return head + sep + "#if !CLIPPER_SYNTH\n" + body + "#else" + clipper_block() + "#endif\n" def main(out): diff --git a/web/editor.html b/web/editor.html index 1bb71e7..0fde683 100644 --- a/web/editor.html +++ b/web/editor.html @@ -463,21 +463,15 @@

@@ -596,6 +591,13 @@

+ +