A Python command-line tool that turns Demucs-separated audio stems into a compact sample pack and a generated arrangement.
The script searches each stem for loopable regions, exports loops of several lengths, slices the longest available loops into beat-sized chops, and layers selected loops into an arrangement with simple filtering, saturation, fades, and vinyl-style texture.
- Loads standard Demucs stems:
drums.wav,bass.wav,other.wav, andvocals.wav - Searches for useful 1-, 2-, 4-, and 8-bar loop regions
- Scores candidates using energy, short-term stability, and loop-boundary similarity
- Exports normalized loops and beat-sized chops
- Creates a layered arrangement from the selected loops
- Supports custom search ranges, loop lengths, BPM, and output duration
- Python 3.10 or newer
- NumPy
- SoundFile
- Demucs, only if you still need to separate a source track into stems
Install the required Python packages:
pip install -r requirements.txtPlace the separated WAV files in one directory:
stems/
├── bass.wav
├── drums.wav
├── other.wav
└── vocals.wav
The script can run with missing individual stems, but all available stems must use the same sample rate. At least other.wav or drums.wav is required to build the arrangement.
To separate a track with Demucs first, install Demucs and run it separately according to its command-line documentation. Then pass the directory containing the resulting stem files to this script.
python sample_creator.py \
--stem-dir path/to/stems \
--out-dir output \
--bpm 92.29 \
--target-seconds 90On Windows PowerShell, the same command can be written on one line:
python sample_creator.py --stem-dir "C:\path\to\stems" --out-dir "C:\path\to\output" --bpm 92.29 --target-seconds 90| Option | Description | Default |
|---|---|---|
--stem-dir |
Directory containing Demucs stem WAV files | Required |
--out-dir |
Directory for generated files | Required |
--bpm |
Tempo of the source track | Required |
--target-seconds |
Arrangement length in seconds | 90 |
--search-start-sec |
Earliest timestamp considered during loop search | 0 |
--search-end-sec |
Latest timestamp considered during loop search | End of track |
--loop-bars |
Space-separated loop lengths in bars | 1 2 4 8 |
Example with a restricted search window and custom loop lengths:
python sample_creator.py \
--stem-dir stems \
--out-dir output \
--bpm 120 \
--search-start-sec 20 \
--search-end-sec 100 \
--loop-bars 2 4 8output/
├── arrangement.wav
└── sample_pack/
├── chops/
│ ├── bass_chop_00.wav
│ ├── drums_chop_00.wav
│ └── ...
└── loops/
├── bass_4bars_start_42.31s.wav
├── drums_8bars_start_18.25s.wav
└── ...
For each requested loop length, the script examines candidate regions at half-beat intervals. Each region receives a heuristic score based on:
- Energy: favors regions with audible content.
- Stability: favors regions whose short-time RMS level remains relatively consistent.
- Boundary similarity: penalizes large differences between the beginning and end of the candidate.
The highest-scoring candidate for each stem and loop length is exported.
- The BPM must be supplied manually and should match the source track closely.
- The loop score is heuristic and does not perform beat tracking, key detection, or semantic music analysis.
- The generated arrangement uses fixed layering rules rather than a learned composition model.
- This project processes existing audio; make sure you have permission to use and distribute any source material or generated samples.