<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Will Garrido on Medium]]></title>
        <description><![CDATA[Stories by Will Garrido on Medium]]></description>
        <link>https://medium.com/@will.bypass?source=rss-27055f909820------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ZnQ9xuySnzbxLCUcT-6YpQ.jpeg</url>
            <title>Stories by Will Garrido on Medium</title>
            <link>https://medium.com/@will.bypass?source=rss-27055f909820------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 06:25:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@will.bypass/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building an audio alchemy engine: 38 effect modules, irrational numbers, and a 56-bit seed]]></title>
            <link>https://medium.com/@will.bypass/building-an-audio-alchemy-engine-38-effect-modules-irrational-numbers-and-a-56-bit-seed-5f71a9ce166b?source=rss-27055f909820------2</link>
            <guid isPermaLink="false">https://medium.com/p/5f71a9ce166b</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[audio]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[audio-engineering]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Will Garrido]]></dc:creator>
            <pubDate>Mon, 30 Mar 2026 10:11:39 GMT</pubDate>
            <atom:updated>2026-03-30T10:11:39.010Z</atom:updated>
            <content:encoded><![CDATA[<h4>How I turned a Python script into a desktop app that generates ambient soundscapes from any audio</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s5vD_RKzO9Mah6jzHGNZ8Q.png" /></figure><p>I started with a dumb idea: what if I could feed any song into a script and get back something that sounds like it belongs in a Brian Eno album?</p><p>That script turned into 38 audio effect modules, a composite seed system packed into 56 bits, and eventually a desktop app called <strong>Reverie</strong>. Here’s what I learned building it.</p><h4><strong>It started as one Python function</strong></h4><p>The core of the whole thing is paulstretch an algorithm that stretches audio to extreme lengths while keeping it musical. The basic idea is simple:</p><p>1. Take a chunk of audio<br>2. FFT it (convert to frequency domain)<br>3. Keep the magnitudes (that’s the “timbre”)<br>4. Randomize the phases (this is the key it destroys transients and creates a continuous drone)<br>5. IFFT back to time domain<br>6. Overlap-add the frames together</p><p>My first version was a naive Python loop processing one frame at a time. It worked, but stretching a 3-minute song to 30 minutes took forever.</p><p>The fix was batch vectorization, process 500 frames at once using scipy.fft with `workers=-1` for multi-threaded FFT. That alone gave me roughly a 10x speedup. I also made the FFT size adaptive: 8192 for normal stretches, 16384 above 50x, 32768 above 80x. Bigger windows mean smoother results at extreme ratios.</p><h4><strong>38 modules and a constraint system</strong></h4><p>One stretched drone gets boring fast. So I started stacking effects: reverb after stretch, then a lowpass filter, then some chorus. Each combination sounded completely different.</p><p>This turned into a modular system. Each effect is a standalone Python file with the same interface:</p><pre>def process(audio, sr, params=None, rng=None):<br>    # do stuff to audio<br>    return audio, params</pre><p>I kept adding modules. Spectral freeze, ring modulation, harmonic shift with 13 scale modes, a formant filter that morphs between vowel shapes, a glitch engine that layers stutters + micro-silences + reversals…</p><p>At 38 modules, random selection became a problem. Some combinations are terrible , highpass + lowpass fighting each other, or shimmer reverb + spectral freeze creating mush. So I built a constraint system:</p><ul><li><strong>Conflict pairs</strong>: certain modules can’t coexist in the same chain-</li><li><strong>Required groups</strong>: each chain must include at least one from [paulstretch | spectral_freeze] and one from [reverb | shimmer_reverb | delay]</li><li><strong>Chain positioning</strong>: modules are tagged as early/middle/late/last, with some randomization to avoid rigid ordering</li><li><strong>Unique modules</strong>: some can only appear once per chain</li></ul><p>It’s basically a mini constraint satisfaction solver for audio effect chains.</p><h4><strong>The variation slider is a beta distribution</strong></h4><p>Each style has a fixed effect chain , a curated sequence of modules that defines its sound. But within that chain, every parameter is randomized. The question was: how do you let users control <em>how much </em>randomness they want?</p><p>The answer is a variation slider (0–100) that changes the shape of the probability distribution used to sample parameters. Instead of uniform random, I use a beta distribution:</p><ul><li>Low variation (alpha=5, beta=5): bell curve, parameters cluster around safe middle values</li><li>Medium variation (alpha=2, beta=2): roughly uniform</li><li>High variation (alpha=0.5, beta=0.5): U-shaped, parameters are pushed toward extremes</li></ul><p>The U-shape at high variation is what makes it interesting. Instead of everything being randomly mediocre, you get modules running at their extremes, which creates much more dramatic results than uniform random ever could.</p><p>There’s also a fully random mode where even the chain itself is generated from scratch, effect count, module selection, ordering. But for most users, the curated styles with variable parameters hit the sweet spot between control and surprise.</p><h4><strong>Defeating periodicity with irrational numbers</strong></h4><p>The hardest problem with generative ambient is making it feel alive over long durations. Loops are the enemy. Even subtle loops that repeat every 30 seconds become obvious after a few minutes.</p><p>My spectral freeze module (v5.0 at this point) solves this with a trick I&#39;m pretty happy with: irrational LFO rates.</p><p>The module captures 10+ spectral snapshots from the source audio, then traverses between them using LFOs. But instead of rational frequency ratios (which would eventually sync up and create a loop point), the LFO rates use phi (1.618...), sqrt(2), and sqrt(3).</p><pre>sin(2*pi * (1/90) * phi * t)  # period ~145 seconds, never exactly repeats</pre><p>Since irrational numbers never produce exact ratios with each other, the five frequency bands modulated by different combinations of these LFOs will technically never repeat the same pattern. Combined with per-bin micro-drift (random +/-1% variation per frame), the result is a pad that genuinely evolves and never loops.</p><h4><strong>Packing reproducibility into 56 bits</strong></h4><p>Every output is random, which is the point, but users also need to be able to recreate an exact result. The seed system went through three versions before I got it right.</p><p>Version 3 packs everything into a single integer:</p><pre>Bits 0-6    (7 bits):   Variation (0-100)<br>Bits 7-14   (8 bits):   Brightness (-100 to +100, stored as 0-200)<br>Bits 15-23  (9 bits):   Stretch intensity (0-511)<br>Bits 24-55  (32 bits):  RNG seed</pre><p>One number. Copy it, share it, paste it back in, you get the exact same output.</p><p>The tricky part was module-level RNG isolation. If module A makes 5 random calls and module B makes 3, adding a new parameter to module A would shift all of module B’s values. So each module gets its own RNG seeded from `hash(main_seed + module_name + chain_position)`. They’re completely independent.</p><h4><strong>The 5.5 GB problem</strong></h4><p>Everything worked great until someone tried a 2-hour input file.</p><p>120 minutes of stereo audio at 48kHz is 345 million samples per channel. As float64, that’s 5.5 GB just for the raw audio. Any operation that allocates a new array (and most numpy operations do) doubles that immediately.</p><p>I rewrote the critical paths to use block-based processing, 30 second chunks with filter state propagation between blocks. Switched from `filtfilt` (which needs the full array twice) to `sosfilt` with the `zi` state parameter. Replaced `signal.convolve` with `signal.fftconvolve` for O(n log n) instead of O(n²).</p><p>Not glamorous work, but it’s the difference between “crashes on large files” and “just works.”</p><h4><strong>From script to desktop app</strong></h4><p>Wrapping Python DSP in Electron was its own adventure. <br>The architecture is:</p><ul><li>React frontend with sliders for chaos, brightness, stretch, duration-</li><li>Electron main process managing the window and file system</li><li>Python subprocess doing all the actual audio processing</li><li>IPC bridge passing progress updates back to the UI</li></ul><p>The timeout system resets on every progress message from Python, so a 30-minute render doesn’t get killed as long as it’s still making progress.</p><p>The preset system has three layers: module defaults, style overrides, and factory preset overrides, each cascading. It took a few iterations to get the override priority right without making it a mess to maintain.</p><h4><strong>What I’d do differently</strong></h4><p>Start with the constraint system earlier. I spent too long debugging weird-sounding chains that were just bad module combinations.</p><p>Block-based processing from day one. Retrofitting it was painful.</p><p>The seed system should have been v3 from the start. Versions 1 and 2 didn’t encode enough state.</p><h3><strong>Try it</strong></h3><p>The app is called <strong>Reverie</strong>. There’s a demo you can try for free.</p><p><a href="https://reverie.parallel-minds.studio/">https://reverie.parallel-minds.studio</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5f71a9ce166b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>