Developer Log Made by Rehan Bharwani Nov 29, 2026
I wanted a completely automated, zero-API-cost pipeline that composes an hour of smooth background jazz or lobby funk, masters seamless crossfades, pairs the mix with a clean visual, generates a vertical Short funnel, and publishes everything to YouTube—without waiting hours per render or melting an 8 GB Apple Silicon machine.
The initial prototype used facebook/musicgen-small on PyTorch MPS (float16). Generating 15 seconds of audio at batch=1 took 32.8 seconds (0.46x real-time), projecting over 2 hours to render a single 1-hour mix. Because MusicGen decodes sequentially at 50 frames per second across 4 codebooks, every 20 ms slice forces the GPU to stream ~600 MB of weights from unified memory.
Batching 4 prompts simultaneously lifted throughput 2.65x to 1.21x real-time (~49 minutes per hour), but sub-minute generation required changing the architecture entirely.
Instead of predicting raw audio samples 50 times a second, I built a harmonic Markov chain over jazz functions (Imaj9, ii9, V13, tritone substitutions, and borrowed minor iv9) arranged into structured 32-bar AABA song forms with voice-led Rhodes voicings, bass octave pickups, sparse leads, and brushed drums. Rendering 45+ unique MIDI compositions in parallel via FluidSynth (GeneralUser_GS.sf2) and FFmpeg tape EQ dropped 64 minutes of stereo audio synthesis from 131 minutes down to 16.8 seconds.
Along the way, profiling exposed three subtle production bugs: repeated NumPy concatenate calls during 45-track crossfading triggered 14 GB of swap copies (fixed by streaming PCM16 frames directly to disk in O(1) memory); FFmpeg zoompan caused integer-rounding jitter on static frames (replaced with a single-pass bottom progress-bar overlay); and stock/API image fetchers returned meme text or occluded subjects (solved with Tesseract TSV OCR plus Apple Vision VNRecognizeAnimalsRequest bounding-box framing).
Tech Stack: Python 3.12, FluidSynth, FFmpeg, PyTorch / Transformers (MPS), Apple Vision, Tesseract OCR, YouTube Data API v3. View Repository ↗