Urgent.News

What's breaking now, across thousands of outlets.

Tech

I built a music-looping tool for TTRPGs and game prototypes with Python and Web Audio

The boss finishes their speech. Your players reach for their dice. This is where the music should kick in… …and nothing. Instead, the track enters a quiet interlude. Or the opposite happens: the big musical climax arrives while the party is still arguing about whether to open the door. I've been running tabletop RPGs for five years, and this mismatch kept bothering me. My music library had the…

A tabletop role-playing game (TTRPG) master shared their frustration with how music often fails to match the pacing of gameplay. While their library contained suitable tracks, the music's length and structure did not align with the ebb and flow of the game sessions. Recognizing this issue, the master developed Musslop, a free, open-source tool that allows users to loop segments of existing tracks, cue transitions, and export loops for game audio workflows.

The tool was built using Python, FastAPI, librosa, React, and the Web Audio API. While working on it, the developer learned several key lessons:

1. Good tracks may not necessarily make good loops. Horizontal re-sequencing and vertical layering are common techniques in game music, but ordinary stereo recordings lack the necessary structure for easy looping. To address this, the developer had to find useful musical sections, establish boundaries that work when sections repeat, and accurately schedule playback and transitions.

2. Finding structure without a neural model proved challenging. The developer used classic music information retrieval techniques through librosa, such as self-similarity matrices and novelty curves. However, these methods required further refinement to align with musical grids and identify suitable loop boundaries.

3. Mismatches between section and loop boundaries can lead to awkward jumps in audio playback. The developer added a refinement step that tries nearby downbeat positions and balances several signals, including loop closure compatibility, phrase length preferences, transition evidence, and structural novelty. This approach aims to find a loop cut that maintains the intended musical section while producing a clean transition.

4. Scheduling playback in the browser is crucial. The frontend uses React for the interface, while Web Audio handles playback. The developer differentiated between UI timing and audio timing, scheduling audio transitions against the audio context's clock rather than relying on JavaScript timers. Each loop pass utilizes a new AudioBufferSourceNode with a scheduled start time, ensuring smooth transitions between sections.

By addressing these challenges, Musslop provides a valuable tool for TTRPG masters and game developers, enabling them to create dynamic, music-driven experiences that better align with gameplay pacing.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Mado vs iTerm2 vs Kitty vs Warp vs Ghostty: Which macOS Terminal Is Right for You?

If you've spent any time in the macOS terminal community recently, you know the space is more competitive than it's ever been. For years iTerm2 was the default answer.

  • Mado offers native terminal experience with sidebar plugin system.
  • Uses Rust and Slint UI library for performance and native graphics.
  • Focuses on clean, integrated environment for developers.

More from Monday 28 September →