Somnia
Somnia: a procedural engine for microprocessors and low-resource hardware. Gothic ruins and spider lilies under a crimson moon.
Core Red Project

Procedural audio engine

Music that never ends. Fits on an Arduino.

Somnia is an open source procedural audio engine in C++20: from a seed it generates endless ambient melodies on Arduino, ESP32, Raspberry Pi Pico and your terminal, with no heap and no dependencies.

Open source MPL-2.0 · AVR · ESP32 · RP2040 · Linux · macOS · Windows

Scroll

Plant a seed.

The Somnia core, ported to your browser. The same notes as somnia‑cli, and the same MIDI, WAV, JSON and CSV files.

Paused

Numeric seed: 424242

Scale
Root
Mode
Meter

How far the noise travels per note

Piano roll

The noise behind it

Dream log

#NoteMIDIHzmsVel
This page timbre

Take your dream with you

Identical to somnia-cli export. The MIDI declares 4/4, as the CLI does.

The same dream, in your terminal

somnia-cli play --scale dorian --root C --bpm 96 --seed 424242 -n 32 --rests
Keyboard shortcuts
Space
Pause
S
Scale
R
Seed
M
Mode
+ −
Tempo

Ten constellations.

Each scale draws a different figure across the twelve semitones. Touch one and hear it.

How it dreams.

Nothing prerecorded and no AI. Deterministic math you can read from start to end.

  1. Seed

    A 32-bit integer. Keep it and the dream comes back identical.

  2. Noise

    1D Value Noise with fractal Brownian motion: smooth curves that do not wrap into a short loop.

  3. Scale

    The curve is quantized to 10 scales with precomputed 12-TET tables. Zero calls to pow.

  4. Sound

    Each event goes to speakers, buzzer, MIDI, WAV, JSON or CSV.

Read the architecture

Where it dreams.

One core. Five places to leave it playing.

Take it. It is free.

Pick where it is going to live. Then run your first dream.

Binaries ready to run · v0.6.0

macOS

With Homebrew

brew install sxnnyside-project/tap/somnia-cli

After downloading the binary

chmod +x somnia-cli-aarch64-apple-darwin ./somnia-cli-aarch64-apple-darwin play --scale dorian --seed 424242

Your first dream

somnia-cli stream --scale dorian --bpm 96 --rests

Linux

With Homebrew

brew install sxnnyside-project/tap/somnia-cli

After downloading the binary

chmod +x somnia-cli-x86_64-unknown-linux-gnu ./somnia-cli-x86_64-unknown-linux-gnu play --scale dorian --seed 424242

Your first dream

somnia-cli stream --scale dorian --bpm 96 --rests

Windows

With Scoop

scoop bucket add sxnnyside-project https://github.com/sxnnyside-project/scoop-bucket scoop install somnia

After downloading the .exe, in PowerShell

.\somnia-cli-x86_64-pc-windows-msvc.exe play --scale dorian --seed 424242

Your first dream

somnia-cli stream --scale dorian --bpm 96 --rests

Python

The PyPI package does not ship the native library: build it from source and point SOMNIA_LIB_PATH at it. The steps are in Docs.

With pip

pip install somnia-audio

With uv

uv add somnia-audio

JavaScript

With npm

npm install @sxnnyside/somnia

With Bun

bun add @sxnnyside/somnia

Embedded

In your platformio.ini

[env:my_board] lib_deps = sxnnyside/somnia

Arch · AUR Coming soon

In review: available once the pull request is approved.

From the AUR

yay -S somnia-bin

Arduino IDE Coming soon

In review: available once the pull request is approved.

In the Library Manager, search for

Somnia

Source code

Clone and build. Needs CMake 3.21+, a C++20 compiler and just.

git clone https://github.com/core-red-project/somnia.git cd somnia just install just build

Frequently asked.

Worth knowing before you plant the first seed.

If a line of code requires dynamic memory to express art, the problem is the line, not the hardware.

If Somnia kept you company for a while, give it a star. If you found a strange use for it, tell us.