Grain Cloud instrument: ECHOFIELD's granular engine ported to Kotlin (0.31.0)

A granular drone machine from ECHOFIELD FM-1 (Philip Bos, MIT): six modes
(Cloud, Dust, Tape, Bloom, Pulse, Drift), up to 32 grains, held notes pitch
the grains, freeze, auto-level. One shared cloud per mixer channel (plus one
for editor audition) with note ownership, so sequencer releases never cut a
held MIDI note. Ten built-in sources synthesised at startup (GrainSources,
GPL), or a loaded/recorded sample kept across restarts. 14 factory presets.
The echofield/ package stays MIT, LICENSES/MIT.txt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Reactorcoremeltdown
2026-11-13 09:18:04 +01:00
co-authored by Claude Opus 5.5
parent 2d59b0429d
commit aa023d1f01
18 changed files with 1594 additions and 12 deletions
+55
View File
@@ -213,6 +213,7 @@ cc.tiredsysadmin.android.sizzle
├── audio/ The real-time sound engine (own thread)
│ ├── Transport.kt TransportState snapshot published to the UI
│ ├── SynthVoice.kt One synth note (3-osc subtractive), or a Morph Pad note via FrasilVoice
│ ├── GrainSources.kt The Grain Cloud's ten built-in sources, synthesised in the background
│ ├── SampleVoice.kt Pitched + sliced playback of a decoded sample
│ ├── SampleStore.kt Process-wide decoded-PCM cache + WAV encode/decode
│ ├── SampleRecorder.kt Ad-hoc mic/USB capture into a sample
@@ -228,6 +229,10 @@ cc.tiredsysadmin.android.sizzle
│ ├── FrasilPatch.kt Parsed slot snapshot (+ morph target); FrasilClock (the shared TIDE time)
│ └── FrasilVoice.kt One pad note: choir + partials + breath, drift, tide, warmth
│
├── echofield/ MIT: the Grain Cloud, ported from ECHOFIELD (see §5.8)
│ ├── EchofieldDefs.kt Its settings, editor pages, 14 factory presets, the source list
│ └── GrainCloud.kt GrainPatch + one channel's cloud: modes, scheduler, grains, gate, auto-level
│
├── cpp/native_audio.cpp Low-latency Oboe stream; RT callback pulls audio via JNI
│
├── io/ Human-readable text persistence
@@ -467,6 +472,56 @@ are interpolated; the choir filter TYPE switches at the halfway point.
real time (`FrasilVoiceTest.cpuBudgetForFullPolyphony`). The level of a held pad
is matched to a synth note (`aHeldPadIsAboutAsLoudAsASynthNote`).
### 5.8 The Grain Cloud (ECHOFIELD port, MIT)
The **Grain Cloud** instrument (`ToolboxType.GRAIN_CLOUD`) is the granular engine of
[ECHOFIELD FM-1](https://github.com/Philip-Bos/echofield-fm1) (commit `4734e97`) by
Philip Bos, translated from C to Kotlin. It was picked as the granular drone machine
from the FM-1 firmware hub because it is a real sample-to-cloud instrument with note
pitch, float maths, and the **MIT** licence: the two ported files keep the MIT notice
and Philip Bos's copyright (`LICENSES/MIT.txt`); nothing else is affected.
**Ported** (`app/dsp/engine.c`, `app/params.c`, `app/presets.c`): the six modes
(CLOUD, DUST, TAPE, BLOOM, PULSE, DRIFT) and their control laws (`compute_ctl`), the
asynchronous scheduler and PULSE's euclidean 16 steps, grain spawning (size,
pitch, harmony intervals, reverse, scatter, the colour filter, overlap-normalised
level), the five windows, the gate (ATTACK/RELEASE), the source swap fade, the
random walks and LFOs, FREEZE, and the auto-level that keeps the cloud near one
loudness. **Left out:** ECHOFIELD's effects (filter, drive, echo, reverb with
shimmer, tape), WIDTH/pan (Sizzle's channels are mono), the DRIFT ORACLE, LATCH and
the performance effects. Put Ambience / Tape Delay / Tape Engine on the channel.
**One cloud per mixer channel, not a voice per note.** ECHOFIELD has a single cloud
whose grains take their pitch from the held notes in turn (round robin, up to 8);
eight independent clouds would cost eight times as much and break the overlap
normalisation. So `AudioEngine` owns `clouds[4]` (one per channel) plus an
`auditionCloud` for the editor keyboard, outside the voice pools: `playNote`,
`busNoteOn/Off`, `releaseBus`, `releaseTrackVoices`, `allSeqVoicesOff` and `panic`
route notes to the cloud. Notes carry an owner (a tracker track, `OWNER_SEQ` for an
arpeggio's, `OWNER_LIVE` for keys/MIDI), so a track's next note and the transport
stop release only the sequencer's notes and never a note held on a MIDI keyboard.
A cloud renders while its channel's instrument is a Grain Cloud (`cloudOn`), every
sample into `channelSum` like a voice; its patch (`GrainPatch.from`) is rebuilt
only when the slot's version or the tempo changes.
**Sources.** ECHOFIELD's own factory sounds come from a generator outside its
public repository, and its published copies are 16–22 kHz ADPCM, so Sizzle makes
ten sources of its own (`audio/GrainSources.kt`, GPL): felt piano, bowed glass,
music box, warm pad, strings, low drone, rain field, kalimba, breath choir, glass
tines — six seconds each at 24 kHz, pitched material on C (note C4 plays a source
at its own pitch), rendered on a background thread at startup (`prewarm`).
`GrainSources.get` never blocks; the cloud asks every control block, so a source
that is still rendering simply starts when ready. SOURCE "Custom" plays the slot's
own sample, loaded (WAV, or an SF2/XI's sample) or recorded in the editor. It is
kept under the SF2/XI loader's keys (`sfSample` / `sfFile`), so preset saving,
project bundles and startup rehydration handle it with the same code, and
`AppViewModel.setGrainSample` writes the WAV into the preset folder at once, so a
custom source survives a restart without saving a preset.
**Level and cost.** The auto-level holds a sounding cloud near RMS 0.126, which is
about a synth note's level (`GrainCloudTest.aCloudIsAboutAsLoudAsASynthNote`).
Four dense clouds (32 grains each) took about 1.3 % of real time on a desktop JVM.
---
## 6. How to extend