fm1-dockfm1-dock

Developer's guide

A synth for fm1-dock is a module: a small C program built into a .dock file. Players add it to their FM-1 or SMK-37 next to the other synths, without replacing any firmware, and switch to it with HOME. This page is the way from an idea to a synth anyone can add with one click.

  1. 1Write Copy modules/sine/ (150 lines), fill in render() and note(), build it with tools/hbmod.py.
  2. 2Test In the fm1-emu emulator first, then on your own unit: a deploy is a few seconds and changes nothing else.
  3. 3Share Put the .dock in a GitHub release for anyone to deploy, or bring it into the page's catalog for one-click Add.

Write a module

What a module is

A table of functions at the start of its image, linked against nothing of the host's. fm1-dock checks its header, ABI and CRC before any of it runs.

  • render() adds 256 stereo frames, Q15, in the audio interrupt (5.8 ms).
  • note(), cc(), ui() and draw() run in the main loop.
  • The host gives the time, the log, the screen, the LEDs, a 240-byte settings record, flash banks for presets, MIDI out and the keys' pressure: every call is in hb_module.h.

Build it

cp -r modules/sine modules/mysynth
# module.cfg:
#   name = MYSYNTH
#   version = 1
python3 tools/hbmod.py modules/mysynth
# -> build/modules/mysynth.dock

A module needs only JieLi's toolchain (tools/get_toolchain.sh), not the SDK; the README's Build it has the setup. The module's directory can live in your own repository (includes = and sources = point outside fm1-dock's tree).

The chip's rules

  • One core at 240 MHz (a second one for voices, optional), integers only, no 64-bit division.
  • 272 KiB of RAM, 16 KiB of code in RAM (HB_FAR).
  • Keep it small: the add-ons share 296 KiB of flash on the FM-1 (from 0.10 more with fewer built-in synths), and most synths take 6 to 60 KiB.
  • The build refuses what would crash the chip: RULES.md.

Or write an effect

The Effects page has the four newest to listen to, and a short guide to adding and developing one.

From fm1-dock 0.10 an add-on can also be an effect. It runs on what the playing synth renders, under every synth, and the player picks it and sets its values under OPTIONS > EFFECT. It is built, tested and shared exactly like a synth; the difference is one line in module.cfg and a much smaller interface.

# modules/fxtremolo/module.cfg
name = TREMOLO
version = 1
kind = effect

The whole effect, modules/fxtremolo/tremolo.c:

#include "hb_module.h"

static volatile uint32_t inc;                   /* the triangle's phase a sample (2^32 a turn) */
static volatile int32_t depth;                  /* Q16 */
static uint32_t ph;

static int init(void) { return 0; }

static void set(uint32_t k, int32_t v)          /* the main loop's: a value turned (or kept from before) */
{
    if (k == 0) inc = (uint32_t)v * 9739u;      /* v / 10 Hz: 2^32 / 44100 a Hz */
    else depth = v * 65536 / 100;
}

static void run(int32_t *lr, uint32_t n)        /* the audio interrupt's: n frames, L R, in place */
{
    uint32_t i;
    for (i = 0; i < n; i++, ph += inc) {
        uint32_t t = ph >> 15;
        int32_t g;
        if (t > 65535u) t = 131071u - t;        /* a triangle, 0..65535 */
        g = 65536 - (int32_t)(((int64_t)depth * (int32_t)t) >> 16);
        lr[2 * i] = (int32_t)(((int64_t)lr[2 * i] * g) >> 16);
        lr[2 * i + 1] = (int32_t)(((int64_t)lr[2 * i + 1] * g) >> 16);
    }
}

static const hb_fx_param_t PARAMS[] = {
    {"RATE", "/10 Hz", 1, 100, 40, 1},          /* name, unit, from, to, where it starts, a detent's step */
    {"DEPTH", "%", 0, 100, 60, 1}};
HB_FX = {HB_FX_ABI, "TREMOLO", 2, PARAMS, init, set, run};
python3 tools/hbmod.py modules/fxtremolo        # -> build/modules/fxtremolo.dock
tools/dock.py deploy build/modules/fxtremolo.dock   # added, and picked as the effect at once
  • Three functions. init() when the effect is picked (its RAM is cleared first), set(k, value) for each of its values (once after init(), then whenever the player turns one), and run(block, frames) in the audio interrupt: up to 256 stereo frames, each sample within ±32767, changed in place.
  • Up to four values. Each has a name, a unit, a range, a start and a step. fm1-dock draws the page, puts them on KNOB1–4, and keeps them.
  • Its own 24 KiB of RAM. The synth keeps all of its 272 KiB. No code in RAM, integers only, no call into fm1-dock from run().
  • set() can be interrupted by run(). Write each value as one word, as the tremolo does, or prepare a set and flag it last, as modules/fxdelay does.
  • Keep it light. Its time counts with the synth's. When the blocks run late with an effect on, fm1-dock drops the effect (TOO SLOW) and the synth plays on.
  • One effect runs at a time. To offer several kinds in one add-on, give it a MODE value: modules/fxtrio is a chorus, a flanger or a delay that way. Its optional label() and show() tell fm1-dock what a line is called in the current mode and how its value reads ("FLANGER", "185 ms").
  • If it crashes, that is charged to the effect, not to the synth: fm1-dock leaves it off until the player picks it again or switches the unit off.

More examples: modules/fxchorus, fxflanger and fxdelay, 40 to 80 lines each. The interface is hb_fx_t in firmware/dock/hb_module.h, "Effects". In the catalog an effect's entry has "kind": "effect".

Test it

In the emulator

fm1-emu runs fm1-dock and your module as the chip would, with the screen, the sound and the log; no unit needed, nothing to brick.

tools/dock.py emu \
  --fwsc fm1-dock.fwsc \
  --deploy mysynth.dock \
  --ms 6000

On your FM-1 or SMK-37

With fm1-dock installed: drop the .dock on the console's Deploy a module, or

tools/dock.py deploy \
  mysynth.dock
tools/dock.py logs

A module that crashes twice is skipped at boot until it is picked again, and tools/dock.py logs has the address. Hold OCT+ at power-on for the safe start.

Before you share

  • Full chords at full velocity don't clip: tests/level_test.py plays it in fm1-emu and checks.
  • The CPU on the top line stays under about 80 % with all voices playing.
  • HOME, presets and the settings come back after a power-off.
  • On an SMK-37 too if you can; say so if you couldn't.

Share it

Two ways. You can do the first today on your own; the second puts your synth on the page.

A Your own release

  1. Put the source on GitHub with a licence (GPL-3.0, MIT or another open one).
  2. Attach mysynth.dock to a release.
  3. Tell players: install fm1-dock from the page, then drop the .dock on the console's Deploy a module.

No one has to approve it. It doesn't show in the catalog, and players update it by hand.

B In the catalog

Your synth gets a card with Add, Try it in the browser emulator, the room it takes, updates with one click, and a place in the README.

What it takes

Into the catalog

The easy way: an issue

Open an issue titled New module: NAME with a link to your source, its licence, a few lines on what it is, and what you tested it on. We build it, check it in the emulator and on hardware, and add it; you see the pull request.

Or a pull request

  • modules/NAME/: the source and its module.cfg (or a wrapper that builds yours from your repository).
  • docs/modules/NAME.dock: the built module.
  • docs/media/screen_NAME.png: its screen, from the emulator.
  • An entry in docs/modules/modules.json (copy ARP 2600's): title, by, licence, voices, a description, tags, kind.
  • A line in LICENSING.md and the README's table.

What we check

  • An open-source licence, and that you may share everything in it: no manufacturer's ROMs or factory banks.
  • It builds from source, and the .dock matches.
  • It fits next to the others, plays without clipping, and survives HOME and a power-off.
  • Until it has played on a real FM-1, its card says untested.

Port a firmware you already have

Most of the catalog began as its own FM-1 firmware: OberVave, CS-1, AMB-1, FiMba-1, GATOR, PROPHET and others. The synth engine stays as its author wrote it; a small wrapper turns its main loop into render(), note() and ui(), and its screen and buttons into the host's calls.

Look at one

modules/fimba and modules/obervave are small wrappers around their authors' code; modules/cs1 plays half its voices on the second core.

Not your code?

Porting someone else's open-source synth is welcome: keep their copyright and licence, credit them on the card, and tell them. Ask before bringing a firmware whose licence doesn't allow it.

Stuck?

Ask in the issues: a port often needs only a hint about the screen, the banks or the second core.