The BongTech GhettoMachine replaces the FM-1's own software with ours. It has one drum track (a 909 or an 808), three instrument tracks that can each be a mono synth, a poly synth or a sampler, a sequencer, effects, and a mastering chain. It's about 430 KB of code, and the same code runs in your browser, right here.
This is the tour: what runs where, how a note becomes sound, where things are saved, and how we build and test it. Each chapter is coloured the way the FM-1's screen colours that part of the instrument.
This is GhettoMachine itself, compiled to WebAssembly: the same sequencer, drums, synth, effects and screen as on the FM-1, drawn as its panel. Press Switch on, then play it with the mouse or your computer's keyboard. Your work is kept in this browser.
Inside the FM-1 is a JieLi WL82 chip: two processor cores, a floating-point unit that does single precision only, and 1 MB of flash memory. The screen is a 240 × 240 colour panel on a fast serial line. The front panel has 27 keys (16 white, 11 black), 14 buttons and 7 knobs: SELECT, ALGORITHM, PRESETS and K1 to K4.
We don't talk to that hardware directly. We build on fm1-base, a platform by Charles Vestal that grew out of the Felucca firmware. It gives us a small set of functions for the things every instrument needs: here are the buttons and keys, here's the screen, fill this audio buffer, save this file, send this MIDI. Our code is the app on top: one large file, app.c, for the instrument, plus a folder of sound engines.
app.c and dsp/.The most important idea in the whole program is that it runs as two separate loops that never wait for each other.
The audio loop is an interrupt: when the codec needs more sound, the chip stops whatever it's doing and runs it. If it ever ran late you'd hear a click, so it does nothing slow. No drawing, no saving, no waiting. Everything slow happens in the main loop, in the time left over.
Both loops touch the same project, so when the main loop changes something the audio loop reads, like a step or a knob, it takes a short lock (it holds off the interrupt for a few microseconds) so the sound never sees half an edit.
The synth is the heaviest work. The 16 voices are split in two: one core renders half while the other renders the rest, and the halves are added together. They hand work back and forth every 32 samples (0.73 ms). Some FM-1 units have faults on the second core, so if it doesn't answer, everything runs on one core instead.
The main loop watches how busy the processor is. Above 85%, it takes a voice away from the pool every 40 ms; below 65%, it gives one back. You'd hear notes drop out of a big chord before you'd hear the audio break up. HOME shows the load as CPU.
A pattern holds all four tracks. There are 16 patterns. Each track's part of a pattern has its own length (1 to 64 steps) and its own rate (1/16, 1/8, 1/32 or triplets), so a 12-step bassline can run against 16-step drums and drift in and out of phase. That's called polymeter.
Inside the audio loop, each track keeps a countdown in samples to its next step. Every 256-sample block is cut into pieces at exactly the samples where a step or a bar begins, so a hit lands on its sample, not on the next block. SWING (50 to 75%) pushes every second step later.
The start of a bar is where things change. A pattern you picked while playing waits for it (the band shows >02), then every track restarts at step 1. The song chain moves to its next entry there. LFOs set to restart each bar do so. The metronome's first beat is the bar's start.
Before an edit to a pattern, the sequencer takes a copy of that pattern. EDIT + OCT− puts the copy back; EDIT + OCT+ redoes. It keeps 8 copies. Edits of the same kind close together, like several turns of one knob, share one copy.
The drum sounds come from X0X, another FM-1 firmware: its models of the 909 (after 9W9) and the 808 (after 8W8). They're synthesised the way the originals worked: oscillators, noise and envelopes, with a few short recorded samples for the 909's cymbals and hats. Both kits share one layout of 11 pads, so a beat keeps its meaning when you switch kits:
| Pad | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 909 | BD | SD | LT | MT | HT | RS | CP | CH | OH | CR | RD |
| 808 | BD | SD | LT | MT | HT | RS | CP | CH | OH | CY | CB |
Every pad has its own knobs (tune, tone, decay and so on) and its own reverb and delay sends. A tail keeps ringing when you change kits mid-note, because the other kit keeps rendering until it's quiet.
The drums' LFO is a trick on top of the locks: at each hit of the pad you picked, it writes a new value into one of that pad's knobs, then puts the knob back. That's how sample-and-hold on the closed hat's decay makes every hat different.
The kick also feeds the master bus's PUMP: the sequencer tells the compressor a kick is coming, and it ducks the whole mix, the sidechain pump of house music without needing to listen for it.
Each instrument track is MONO, POLY or SAMPLER. All three use the same voice: a sound source, then a filter, then an amplifier, each with its own envelope. Only the source changes.
The synth engine is Felucca-Engines' ANALOG voice. It works in whole numbers rather than floating point, which is fast on this chip, and it updates its slower controls (envelopes, the filter's setting) once every 32 samples instead of every sample. We added a sub oscillator and a second oscillator you can tune in intervals.
The three tracks share one pool of 16 voices. POLY takes a voice per note, up to 8. MONO uses one voice, or up to 4 stacked and detuned (unison), and remembers which keys are still held, so letting go of a note falls back to the one underneath. When the pool is full, a new note takes a voice from one already sounding (voice stealing).
Samples live in flash, not in memory, and they're played straight out of flash while the sound runs. To fit more in, each sample is stored at 12 bits: two samples packed into three bytes. That gives about 3.3 seconds at 44.1 kHz shared by the three tracks, or 6.6 seconds at 22 kHz.
A recording (hold REC, press SEL) goes into a 132 KB buffer in memory first: up to 2 seconds of the FM-1's own mix. When it's kept, it's written into the sample bank, with a small header written last. If the power goes mid-write, the bank still holds a complete old sample rather than half a new one. That same buffer is the delay's memory the rest of the time, which is why the delay pauses while you sample.
The synth update added two things to the ANALOG voice: more character in the sound itself, and much more movement. A sound went from 26 settings to 64.
FM here is phase modulation, the way Yamaha's DX synths did it: OSC 2's output nudges where OSC 1 is in its cycle, which adds harmonics without changing the pitch. INTERVAL sets the ratio between the two (+12 is 2:1, odd intervals sound clangy and bell-like). The amount is squared, so the low end of the knob is fine-grained, and the top notes get less, because FM at high pitches makes frequencies above what 44.1 kHz can hold and they fold back as grit.
The wavefolder comes from Felucca's PHASE engine: the wave goes through a sine, so a loud peak folds back down instead of clipping, and more gain means more folds. It's the West Coast synth sound. A small filter after it removes the slow offset that folding a lopsided wave creates.
Before, each track had one LFO that could move one thing. Now each sound has a matrix of six slots, each one "this source moves that destination by this much". Sources are the LFOs, the three envelopes, velocity, the note, a random value per note and four macro knobs; destinations are nearly every knob of the voice.
The matrix is worked out for each voice separately, 1,378 times a second (every 32 samples). That's what makes per-note things possible: the third envelope (MOD ENV) and LFO 2 belong to the note, not the track, so a chord's notes each shimmer on their own. Working it out is cheap, a few multiplications per slot. When the matrix moves something the engine reads, like FM or resonance, that voice gets its own copy of the settings for the next 32 samples.
Pitch needed one trick. The engine's pitch steps are 1/16 of a semitone, too coarse for a gentle vibrato. The matrix's pitch goes through the voice's fine tune as well, the same path unison detune uses, so it moves smoothly.
Every new feature is switched off by a zero: FM 0, RING 0, AMOUNT 0, an empty matrix slot. When they're all off, the voice runs exactly the code it ran before. We checked: 0.2's 15 factory sounds, rendered by the old synth and the new one, come out byte for byte identical. When a feature is on, the voice runs a second, richer loop; on the Mac that costs about 1.5 times a plain voice.
The testing found two old integer overflows (a very loud unison voice could overflow its pan multiply, and the sampler shifted a negative number). Both fixed, without changing any sound.
Roland's TB-303 bass line owes as much of its sound to its sequencer as to its synth. Every step is a short note, a note held on into the next, or a slide that glides into the next pitch without starting again, and some notes are accented: louder, with the filter thrown open for a moment. The ACID pages (SEQ, after STEPS, on T2–T4) write lines like that into a track's part, from a handful of knobs.
Each step's dice come from a hash of the seed and the step's number, so they never change unless you ask for a new line (OCT+) or a mutation (OCT−). The knobs only move the line each die has to beat. Turn DENSITY up and more steps play while the ones already there stay; turn any knob back and you get exactly the line you had. The root is three times as likely as any other note, and NOTES picks a bass player's favourites first: root, fifth, third, seventh.
A 303's note lasts half a step. A whole note is held until just before the next note, across any rests, which is a 303's tie. A slide holds the note past the start of the next step, so the next note arrives while it's still sounding and glides in from its pitch. On STEPS you can set any step by hand: hold it, press OCT+ for HALF, WHOLE or SLIDE, and turn VELOCITY past 127 for an accent.
The two marks live in bits each step already had spare (a velocity only needs 7 bits, a chance too), so the save format didn't change for them, and nothing saved before has them set. The sequencer passes them to the synth with each note. A slide takes the voice that's still holding the last note, whatever kind of sound it is (a mono bass, a poly pad, a sample), and moves its pitch over 58 ms, or the sound's own GLIDE time. An accent makes the note 1.4 times louder and opens the filter by about an octave, falling back over 200 ms, which is roughly what the 303's accent circuit does.
An unmarked note takes exactly the old path: 0.2's factory sounds still render byte for byte the same.
These all run inside the audio loop, block by block, so they stay in time with the sequencer.
Every track has one: sine, triangle, ramps, square, sample-and-hold or smooth random, free or synced to the tempo (4 bars down to 1/32), restarting freely, on each note, or each bar. On T2 to T4 it moves one thing: cutoff, pitch, level, pulse width, resonance, detune, mix, drive, noise, sub, or a sample's start. It's also a source in the matrix (above), alongside LFO 2, which each note has its own of.
It collects the notes you hold (and the sequencer's chords) and plays them one at a time: up, down, both, random or as played, over 1 to 4 octaves, at a note value you pick. LATCH keeps them going after you let go.
A key plays a chord built on it: one of 12 shapes, from major and minor to sevenths, sus chords and power chords, inverted up to three times. The chord is stored as a list of intervals; the key you pressed is remembered with the chord it started, so it lets go of the same notes even if you change the chord while holding it. Chords go into the arpeggiator like held notes, so one key can play an arpeggiated chord.
A lock is a knob's value for one step. It's stored as a small list per part (step, which knob, value) rather than a copy of every knob on every step, which keeps a pattern small. When the step plays, its locks are applied just before the note, and the knob goes back to its own value at the next step.
With REC on and the pattern playing, a note goes to the nearest point of the grid you chose: a step, or every 2 or 4 steps. Its gate is how long you held the key. If the nearest point is just ahead, the sequencer is told to skip it once, so you don't hear it twice. With the pattern stopped, on the KEYS page, notes go in one step at a time.
The metronome counts quarters of the bar. It's synced to the sequencer at each bar's start and counts the other three beats itself. Each click is a short sine burst, 1.5 kHz on beat 1 and 1 kHz on the rest, made by a two-line recurrence (no sine table needed). It's added after the master bus, so it's never in a recording or the loudness meter.
The count-in is a countdown in samples. The audio loop clicks the beats and starts the sequencer in the block where the countdown runs out. A note you play in the last half beat is put on step 1, and step 1 is skipped once at the start so you don't hear it twice.
QUANTIZE moves every note of the part to the nearest point of the grid, merging notes that meet into a chord and moving their locks with them. LEGATO sets each note's gate to reach the next note, plus one eighth of a step of overlap, so a MONO sound with LEGATO on ties them together. Both take an undo copy first.
HOME is a scene grid: 16 patterns across, a track a row. Under it is one small change to the sequencer: each track has its own pointer to the pattern it plays, its clip. A scene sets all four pointers; a clip sets one. Everything that edits (steps, notes, locks, undo) follows the pointer, so you always edit what you hear.
Changes wait for a boundary. The audio loop already cuts its blocks where a bar starts, so a waiting clip or scene starts there, on its sample. With LAUNCH at BEAT it also cuts at quarter bars; at NOW the main loop switches at once and restarts the bar from there. A scene's follow action is a counter of bars: when it reaches the number you set, the next scene is queued as if you'd pressed it.
The main loop only sets a bit for each perform key held. The audio loop compares the bits with what it saw last block and switches the effect on or off at the block's start.
When a track moves to another pattern, its sound (a few dozen bytes of knob values) is copied into the pattern it leaves, and the new pattern's sound is copied out and handed to the synth. It's small enough to happen inside the audio loop at the bar, with no gap. The drums store just which kit.
A MIDI clock is 24 pulses a beat. The FM-1 reads MIDI once a block, so it only knows a pulse came within some 5.8 ms. Instead of trusting single gaps, it notes the time of every 6th pulse (a 16th note) and measures the tempo across the last four beats, where 5.8 ms is a fraction of a percent. Then at every 16th it compares where its own sequencer is with where the clock says it should be, and shifts the whole groove an eighth of the way there (a quarter if it's more than 10 ms off). That's the same shift as NUDGE. So the two can't drift apart, and the block's uncertainty shrinks to a millisecond or two.
Building this turned up an older bug. When the tempo changed mid-bar, each track took the new tempo at its next step, but the bar's countdown kept the old one until the bar ended, so step 1 and the bar could slip apart. Now any tempo change stretches every countdown together.
The new settings were added at the end of the project. A project saved before them reads in shorter, and the missing end is filled with zeros, which mean "off". The project now uses 32,680 of its 32,736 bytes, so the next big addition will need a second file.
Each track has a level, a pan and two sends. The sends are added into two buses, one for the reverb and one for the delay, and what comes back is added to the dry mix.
The reverb and the delay are from X0X. The delay's 1.5 seconds of memory is the sampler's recording buffer, lent back and forth. The DJ filter on the FX pages sits on the master bus: left of centre it's a low-pass that closes, right of centre a high-pass that opens.
Everything you hear goes through one chain, in this order:
The loudness meter follows the broadcast standard (ITU-R BS.1770): it filters the sound the way the ear weighs it, averages the power over 3 seconds (and 0.4 for M), and shows LUFS. A 1 kHz tone at −20 dBFS on both sides reads −20.0, which is how we checked it.
The seven presets set the chain at once, and they're level-matched by measurement: on the demo groove, bypassed reads −15.1 LUFS and CLEAN −15.2, so switching compares the sound, not the volume. LOUD reaches −9.
Every page has three parts. The dark band on top says where you are and shows the output meters; turn a knob and it shows the change large for a moment. The page in the middle draws what you're editing: steps, a filter curve, an envelope, a sample. The knob strip at the bottom is four cards in the same order as K1 to K4.
The colour is the section: 909 orange, 808 blue, T2 green, T3 purple, T4 yellow, HOME and the mixer cream, FX cyan, the master bus rose, recording red. The type is Barlow Semi Condensed, turned into compact bitmap fonts at build time.
Sending a full screen down the serial line takes about 21 ms, longer than a frame. So the screen redraws fully only when something changes. The meters redraw about 30 times a second, and only the band (about 4 ms) plus the page if it has moving parts. The knob cards wait for a knob to turn.
The page's drawing code can't use the maths library the sound engines use (their names clash with the platform's), so the curves get their sine, log and tanh from a small separate unit.
The FM-1 has no file system for us; it has 1 MB of flash with fixed areas. To scale:
The project (patterns, song, sounds, mixer, effects, master bus, LFOs, arps, recording settings) is saved when you press SAVE, in one of two copies, alternately, each with a checksum. If the power goes during a save, the other copy is still whole and loads instead. A project file must be exactly the size a version expects. Small additions went into spare bytes or onto the end, which is why saved projects survived the earlier updates. The synth update needed more room than that (38 new settings for each of 51 sounds), so it has a new format: each step gave up a spare byte it never used (3 KB in all), which paid for the bigger sounds with 1.2 KB to spare. A file in the old format is read a piece at a time straight from flash and rearranged as it loads, with the new settings at values that sound the same. The first SAVE writes the new format. 0.4 put the 303 generator's settings onto the end again (format 3), and a project saved by 0.3 loads as it was.
Samples are kept the moment they're recorded or sent from the Mac. Presets are kept the moment you save one. Neither waits for SAVE.
Flash can only be erased 4 KB at a time and wears out after many erases, which is part of why saving is a button rather than automatic.
The same code builds three ways. For the FM-1, a JieLi compiler (running in Docker) makes the firmware image. For the Mac, an ordinary compiler builds a simulator: the same app, with fm1-base faking the buttons, keys, screen and audio. The simulator even avoids the one floating-point instruction the FM-1 lacks, so it computes the same samples. And Emscripten compiles it to WebAssembly for the emulator at the top of this page, its sound made in an audio worklet.
The simulator runs scripts that press buttons, turn knobs, play keys and send MIDI, wait, and then check what happened through hooks in the app: which step a note landed on, a gate's length, the output's peak level, how many dB the compressor took off.
| Script | What it covers | Checks |
|---|---|---|
| drums | the grid, accents, chance, locks, mutes, kits | 59 |
| tracks | four tracks, patterns, live and step recording | 99 |
| synth | MONO, POLY, glide, unison, envelopes, the voice pool | 86 |
| sampler | recording, playback, loops, the bank filling up | 74 |
| mod | LFOs, the arpeggiator, step locks | 87 |
| fx | the mixer, sends, reverb, delay, the limiter | 77 |
| release | presets and the song chain | 71 |
| master | the master bus's pages, presets, bypass | 103 |
| rec | metronome, count-in, quantize, legato, chords, long gates | 80 |
| scenes | clips, scenes, stopping a track, LAUNCH | 44 |
| perform | each perform key held and let go, tap tempo, solo | 48 |
| live | sounds per pattern, follow actions, motion, reload, MIDI clock | 120 |
| convert | a project and presets saved by 0.2 loading into the new format | 65 |
| synth2 | the new pages, the matrix playing, locks and motion on it, the new sounds | 101 |
| acid | the 303 generator: lines, scales, half, whole, slides and accents, playing on a poly sound | 170 |
| convert3 | a project saved by 0.3 loading into 0.4 | 28 |
That's 1,400 checks (with a few demos and a screen tour). Separate C tests feed sine waves through the master bus (48 checks) and through the synth (39: FM's harmonics, each shaper, the matrix, slides and accents, everything at maximum at once, built with a checker that stops on any integer overflow), and compare the old and new synth byte for byte. Another sends a WAV to the simulator over its MIDI link and reads it back byte for byte. Demo scripts render WAV files we can listen to, like the master bus comparison.
The build ends in a .fwsc package with an identity, FM-1_800. Installing it over USB works because the firmware already on the FM-1 (X0X the first time, GhettoMachine since) includes an updater. The Mac sends the package over MIDI; the FM-1 checks it, restarts into a small loader, compares the flash 4 KB at a time and rewrites only what changed, then starts the new firmware.
The ESP32-S3 board is the rescue route. When an install is cut off and the FM-1 won't start, the S3 talks to the chip's built-in boot mode directly: it can read the whole flash for a backup and write the firmware area back. That's how the FM-1 came back on 18 November.
Not measured yet on the FM-1 itself: how busy the processor gets with all 16 voices, a dense 808 and every effect on. The voice limiter is there for that.