Overview
This site documents an approach to remixing arbitrary audio into tracker modules in the XM format. It is written for chiptune artists, developers, and audio-hackers who want a reproducible pipeline to transform audio files (WAV/MP3/OGG) into a module-based representation with patterns, instruments and samples.
The project contains: a long-form explanation of goals and algorithms, a practical "how it works" section, and a lightweight, client-side prototype that demonstrates the pipeline in the browser.
Background: Chiptune Modules and the XM Format
Tracker formats such as XM (FastTracker II Extended Module) represent music as a list of patterns. Each pattern contains rows of note events, instrument numbers and effect commands. Instruments reference samples (raw PCM data) which the tracker plays back at different periods to achieve different pitches.
The fundamental idea in converting audio to XM is to analyze the incoming sound and create an arrangement expressed in patterns and instruments. The conversion usually involves:
- segmentation and onset detection (where to place notes)
- pitch detection (what note each segment corresponds to)
- sample creation (slicing or resynthesizing audio segments into samples)
- pattern generation (mapping notes into tracker rows)
Design Goals
- Produce an arrangement that preserves the character of the source audio while being playable in trackers.
- Create small, efficient module files suitable for chiptune aesthetics.
- Offer an interactive experiment (browser-based) to iterate quickly.
Pipeline (Conceptual)
Here is a high-level pipeline for audio → XM conversion:
- Preprocessing: normalize, downmix to mono, resample to tracker-friendly rates (e.g. 22kHz or 16kHz).
- Onset & segmentation: find transient points to slice audio into 'samples' or short grains.
- Pitch estimation: for each segment, estimate the predominant pitch (e.g. via autocorrelation or FFT-based harmonic peak detection).
- Mapping to notes: quantize estimated pitch to nearest tracker note (e.g. C-0 ... B-7) and choose an instrument/sample.
- Sample creation: create short loopable samples from segments (optionally apply envelope, bitcrush, lowpass).
- Pattern creation: arrange quantized notes into patterns (64 rows typical), apply effects (vol slides, retrig) to emulate remixes.
- XM export: build the module file with header, patterns and instruments + samples.
Each step has many tradeoffs: how long should samples be, whether to preserve timbre vs. compress size, and how much automation versus manual editing to allow.
Key Algorithms (Detailed)
1) Onset Detection
Compute a short-time energy or spectral flux over frames (e.g. 10–30 ms windows with 50% overlap) and mark peaks that exceed a threshold. These peaks become candidate slice points. Adaptive thresholds or median filters reduce false detections from noise.
2) Pitch Detection
For each slice, find the fundamental frequency. Methods:
- Autocorrelation: robust for monophonic parts, returns a lag corresponding to pitch period.
- FFT / Harmonic Product Spectrum: find spectral peaks and infer fundamentals.
Translate frequency (Hz) to tracker note numbers by mapping to semitone scale: note = round(12 * log2(freq / A4)) + offset.
3) Sample Creation and Conditioning
Slices can be used as raw samples or resynthesized:
- Trim leading/trailing silence, apply fade in/out to avoid clicks.
- Normalize amplitude, optionally apply bit depth reduction (8-bit/12-bit) and downsampling for chiptune flavor.
- For sustain, try extracting single-cycle waveforms or loopable segments for stable notes.
4) Pattern Generation
Decide how dense the patterns should be: place notes on quantized grid (16th/8th notes), derive velocity/volume from segment energy, and apply simple tracker effects:
- Volume column for dynamics
- Arpeggio effect: emulate chords by rapid note changes in effect columns
- Portamento or retrigger: for repeated slices
Practical Limitations & Tradeoffs
Converting dense polyphonic, reverb-heavy, or complex mixes into discrete tracker instruments is lossy. This workflow shines when:
- Source contains rhythmic elements or distinct melodic lines.
- Artist accepts chiptune-style artifacts (limited sample rate, bit-depth, looped samples).
The goal is often to create a playable aesthetic remix rather than a faithful reconstruction.
Experimental Browser Prototype
Below is a small in-browser prototype. It's educational: it demonstrates the pipeline steps (decode, segment, estimate pitch, build a small module descriptor) — but it doesn't (yet) produce a full, standards-compliant XM binary that every tracker will load. Use the generator to create a prototype "XM descriptor" that you can import into a tracker-authoring tool or iterate on.
Note: This generator outputs a descriptive prototype file (JSON) with the .xm extension. It is intended for experimentation and to show how patterns & instruments might be created. Converting that descriptor to a full binary XM is left as an exercise and a future enhancement.
How to Use this Repo & Deploy
- To host this site on GitHub Pages: push to a repository named YOUR-USERNAME.github.io or enable Pages on any repository and
set the appropriate branch (usually main) and folder (/ or /docs).
- The prototype runs fully client-side; no server is required. Upload audio, tweak sensitivity, and press generate.
Next Steps & Roadmap
- Produce a full XM binary exporter that writes valid instrument/sample blocks.
- Improve pitch detection and separation for polyphonic material.
- Provide presets (lo-fi, chip-8, 8-bit, SID-like).
- Allow manual editing of slices, mapping and patterns before export.