Saltar a contenido

Instrumental Lab

DAW-like fragment library and composer. Ingests instrumental recordings, separates stems, segments into musical fragments, classifies instruments, clusters timbres, and assembles new tracks from the resulting library (with a synthesized fallback for missing timbres).

Why this stack

Need Choice Reason
DSP + MIR librosa, soundfile, scipy Battle-tested, CPU-only, covers 90% of analysis needs.
Stem separation Demucs v4 (optional) Current SOTA for music source separation. Fallback to HPSS.
Instrument labels PANNs CNN14 (optional) Pretrained on AudioSet → 527 labels including many instrument classes.
Clustering HDBSCAN (optional, sklearn KMeans fallback) Discovers timbral sub-categories without fixing K.
Index SQLite + BLOB features Zero-ops, fits millions of fragments, still kNN-searchable.
Compose Rule-based fragment assembly + synth Deterministic, musical, and extensible. Neural sequencer can slot in later.

Architecture

raw .wav ──► preprocess ──► separate ──► segment ──► featurize ──► classify ──► cluster ──► library.db
                                                                                               │
                                                                                               ▼
                                                                                            compose ──► new .wav

Every stage lives in instrumental_lab/pipeline/ and is pure: inputs → outputs, side effects only under instrumental_lab/data/.

Install

# Required (you already have most of these):
pip install librosa soundfile scipy scikit-learn pydub

# Optional, enable deeper analysis:
pip install demucs                 # SOTA stem separation
pip install panns-inference        # Pretrained AudioSet embedding + tagger
pip install hdbscan                # Density-based timbre clustering
pip install pyloudnorm             # ITU-R BS.1770 loudness normalization
pip install pedalboard             # DAW-grade effects / rendering

Quick start

# 1. Ingest all your WAVs (HPSS backend by default; add Demucs with --no-separate flipped off).
python -m instrumental_lab.cli.main ingest "C:/Users/User/Documents/INSTRUMENTAL/*.wav"

# 2. Check library stats.
python -m instrumental_lab.cli.main stats

# 3. Query the library.
python -m instrumental_lab.cli.main query --family=drums --bpm=90,110 --limit=20

# 4. Compose a new instrumental.
python -m instrumental_lab.cli.main compose --bpm=95 --key=A --mode=minor --bars=16 --out=composed.wav

Roadmap

  • [ ] FastAPI + minimal web UI for timeline-style arrangement.
  • [ ] MusicGen hook for neural completion from seed fragments.
  • [ ] Chord-conditioned fragment retrieval (go beyond key matching).
  • [ ] Live ReWire / JACK backend for real-time playback in a host DAW.
  • [ ] User-labeled correction loop → fine-tune the family classifier on this specific genre (música popular).