Skip to main content

SonicLab

CI PyPI version Python versions License: MIT

SonicLab is a modular Python DSP / audio synthesis engine: vectorized oscillators, envelopes, filters, effects, sequencing, optional realtime audio I/O, and MIDI adapters.

Status: Beta. Public APIs may still evolve; see docs/stability.md and CHANGELOG.md.

Features

  • Oscillators: sine, square, sawtooth, triangle, PolyBLEP bandlimited variants
  • Modulation: ADSR / decay envelopes, modulated oscillators & frequency helpers
  • Modifiers: volume, panning, clipping, frequency processors
  • Composition: Chain (serial), WaveAdder (parallel mix)
  • Noise: white, pink, brownian, blue, grey, velvet, sample-and-hold, Perlin
  • Filters: Butterworth utilities, biquad resonant, acid/303-style filter
  • Effects: distortion, delay, reverb, compressor
  • Sequencing: step sequencers, arpeggiator, clock, accent/slide, TB-303 helpers
  • Presets: PresetBuilder / PresetLibrary
  • I/O (optional): AudioOutput via the audio-io extra
  • MIDI (optional): input/files, mono & poly synths (velocity, sustain, bend), mono note-stack CV and multi-voice PolyphonicMIDIToCV via the midi extra

Install

From PyPI:

pip install soniclab

Optional extras:

pip install "soniclab[audio-io]"   # sounddevice + numba speed path
pip install "soniclab[midi]"       # mido + python-rtmidi
pip install "soniclab[speed]"      # numba only
pip install "soniclab[examples]"   # notebooks / plotting
pip install "soniclab[full]"       # audio-io + midi + examples

From a checkout (recommended while developing):

uv sync
# or:
python -m pip install -e ".[dev]"

Notes:

  • Base install is the core NumPy/SciPy engine only.
  • Realtime device playback needs working system audio drivers plus audio-io.
  • MIDI needs local MIDI ports/backends plus the midi extra.

Minimal example

from soniclab import SineOscillator, __version__

print(__version__)
osc = SineOscillator(frequency=440, amplitude=0.3)
samples = osc.get_samples(44100)  # 1 second @ 44.1 kHz, float32
print(samples.shape, samples.dtype)

Chain + stereo pan:

from soniclab import SineOscillator, Chain, Volume, Panner

chain = Chain(
    SineOscillator(frequency=440, amplitude=0.4),
    Volume(0.8),
    Panner(0.25),
)
stereo = chain.get_samples(2048, mode="vectorized")  # shape (2048, 2)

PolyBLEP oscillator:

from soniclab import PolyBLEPOscillator, WaveShape

osc = PolyBLEPOscillator(
    frequency=110,
    amplitude=0.5,
    wave_shape=WaveShape.SAWTOOTH_UP,
)
samples = osc.get_samples(1024, mode="vectorized")

Optional audio output:

from soniclab.audio_io import AudioOutput
# See examples/ and soniclab/audio_io for callback-based playback.

Sample generation modes

Most generators support:

Mode Behavior
"vectorized" NumPy block rendering (preferred for production)
"iterator" Python sample loop (flexible, slower)
"auto" oscillators: vectorized when n >= 512, else iterator; composers (Chain / WaveAdder) always use vectorized so small realtime buffers stay on the fast path

For realtime or offline renderers, prefer "vectorized" (or "auto" with buffer sizes ≥ 512).

Documentation

Testing

uv run pytest tests -q
uv run ruff check soniclab tests
uv run mypy soniclab

Project layout

soniclab/          # installable package
tests/             # pytest suite (mirrors soniclab/ packages)
examples/          # demos & notebooks (not in sdist)
docs/              # user documentation (MkDocs)
scripts/           # benchmarks & local tooling

Public API

Import the stable surface from the top-level package:

from soniclab import (
    SineOscillator,
    SquareOscillator,
    TriangleOscillator,
    SawtoothOscillator,
    PolyBLEPOscillator,
    ADSREnvelope,
    Chain,
    WaveAdder,
    Volume,
    Panner,
    Delay,
    Reverb,
)

Optional subsystems stay in subpackages so the core install stays light:

from soniclab.audio_io import AudioOutput
from soniclab.midi_io import MIDIInput  # requires midi extra

Polyphonic MIDI synth (velocity-sensitive voices):

from soniclab import ADSREnvelope, Chain, ModulatedVolume, SineOscillator
from soniclab.midi_io import PolyphonicSynth  # requires midi extra

def voice_factory():
    osc = SineOscillator(440, amplitude=0.25)
    env = ADSREnvelope(attack_duration=0.01, release_duration=0.2)
    return Chain(osc, ModulatedVolume(env))

synth = PolyphonicSynth(voice_factory, max_voices=8)
synth.note_on(60, 100)
synth.note_on(64, 80)
samples = synth.get_samples(2048)

See examples/midi/polyphony_usage.py and docs/recipes.md.

Contributing

  1. Prefer uv for environments (uv sync --group dev).
  2. Keep changes covered by tests under tests/.
  3. Run pytest, ruff, and mypy before opening a PR.
  4. Follow existing module patterns (component descriptor + registry registration).
  5. See CONTRIBUTING.md for details.

Publishing a release

Version is read from soniclab/_version.py (CalVer-style YYYY.MINOR.MICRO). Publishing uses GitHub Actions (Trusted Publisher) on a GitHub Release.

  1. Prep

    • Bump major / minor / micro in soniclab/_version.py.
    • Move the matching section in CHANGELOG.md from Unreleased to a dated heading (e.g. ## [2026.1.3] - 2026-07-31).
    • Commit on main and push so CI is green (pytest, ruff, mypy, build).
  2. Local sanity (optional but recommended)

    uv run pytest tests -q
    uv run ruff check soniclab tests
    uv run mypy soniclab
    uv build
    uv run --with twine twine check dist/*
    
  3. Tag & release (creates the PyPI publish)

    git tag 2026.1.3
    git push origin main --tags
    # Then publish a GitHub Release for that tag (UI or gh):
    # gh release create 2026.1.3 --title "2026.1.3" --notes-file CHANGELOG.md
    

    The Publish to PyPI workflow builds the sdist/wheel and uploads to PyPI when the release is published. For a dry run, use Actions → Publish to PyPI → Run workflow with target testpypi.

  4. Verifypypi.org/project/soniclab shows the new version; pip install -U soniclab installs it.

Do not upload the same version twice to PyPI (versions are immutable).

Changelog

See CHANGELOG.md.

License

See LICENSE.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

soniclab-2026.1.5.tar.gz (330.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

soniclab-2026.1.5-py3-none-any.whl (281.8 kB view details)

Uploaded Python 3

File details

Details for the file soniclab-2026.1.5.tar.gz.

File metadata

  • Download URL: soniclab-2026.1.5.tar.gz
  • Upload date:
  • Size: 330.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for soniclab-2026.1.5.tar.gz
Algorithm Hash digest
SHA256 5932b846d9d296875a27084bf9b9fdcf038f928f3cfa13c54d7cf1ffe9655b87
MD5 10994e30eb0bb96665cbb274f02dc37e
BLAKE2b-256 3d457eadee9ec0562e0fc53ed137819a0b955b40eeabbbc5636a0fa71056baa2

See more details on using hashes here.

Provenance

The following attestation bundles were made for soniclab-2026.1.5.tar.gz:

Publisher: publish.yml on rasigle/soniclab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file soniclab-2026.1.5-py3-none-any.whl.

File metadata

  • Download URL: soniclab-2026.1.5-py3-none-any.whl
  • Upload date:
  • Size: 281.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for soniclab-2026.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 f6f7576a6ea4efd66820387b28625d0ac8bf7a67d3f6d9ac4756820f2e583aff
MD5 2698ff1341d436a4816d12c9dd4ffe82
BLAKE2b-256 f4b660d61903dd8166a9b930d32dddf54df6670261e6005171a526d26cc93ae1

See more details on using hashes here.

Provenance

The following attestation bundles were made for soniclab-2026.1.5-py3-none-any.whl:

Publisher: publish.yml on rasigle/soniclab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

2026.2.0

2 files

This release

2026.1.5 This release

2 files

2026.1.4

2 files

2026.1.3

2 files

2026.1.2

2 files

2026.1.1

2 files

2026.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page