building musicMixer
music has been a huge part of my life since i can remember. ive always dreamed of a day when we could take our favorite songs and make them our own?
at the moment my favorite song is all along the watchtower by jimi hendrix. what if i could sprinkle some reggae on top? or blend it with some rap?
now don't get too excited, i didn't build this(yet!). regardless of copyright, something like this would require tons of training to get right. and even then, who knows
instead, i decided to build something simple. a mashup creator. take lyrics from one song, instrumentals from another. mix them together, match the key, BPM. wa-lah.
now, its not perfect. but theres a glimmer of the future inside of it.
two fundamental question that arose in my mind while building this was - how much of DJing/mashing is taste? can we give LLMs 'taste'?
manufacturing music taste in LLMs
how i built a music mashup web app - all from a few python libraries and prompting sonnet-4 to act as a DJ
the goal
build a mashup mixer that takes vocals from one song, instrumentals from another and mixes the together. AND make it sound good - handle EQ balancing, key convergence, BPM stretching. all to produce a product that sounds like an average DJ made(again fix later).
architecture

first, it is important to ground our knowledge what is a song made up of, what are its parts/pieces?
- vocals
- lyrics
- key
- instruments(stems)
- key
- relative DB
- tempo
- 120 BPM vs 80 BPM
- composition
- intro
- chorus
- outtro
part 1 - making two songs play together
stem splitting
the first step was just getting it working end to end. how do we strip vocals from one song and overlay it with instrumentals from another?
initially, i tried using htdemucs_ft stem splitter from meta but it only gave us 4 stems:
- vocals, drum, bass, other
this limited our ability to analyze and adjust different instruments. so i switched to the BS-Roformer-SW which has 6 stems:
- vocals, drum, bass, guitar, piano, other
BS-Roformer both allowed for better song manipulation AND better separation quality.
- stat about BS-Roformer vs htdemucs
audio mixing
after we split the stems up, we have to combine them back together.
i could have used pydub, but it only has 16 bit integers. this meant that we would lose percision at every step....quiet details like the trickle of a guitar might get lost in the mix.
instead i used float32 - this gives you WAY more precision...the guitar trickle actually stays the same.
LUFS normalization
LUFS is loudness units full scale. it models how humans actually hear, and helps us know the perceived loudness of a given stem.
initially i used pyloudnorm to normalize all the stems to the same LUFS target of -14db. then AI would apply relative volume adjustments on top.
but it also removed the original internal balance within each song, so we switched to cross-song level matching.
instead of normalizing stems, we measured the LUFS of the vocal stem and the instrumentals.
THEN we set the vocal gain to instrumental_lufs + 2 dB.
typically audio engineers will make vocals 1-4 dB higher depending on the genre, but we decided to keep it fixed for now.
BPM detection + tempo matching
we initially used the librosa library for BPM detection - returning a BPM estimate and an array of beat frame positions.
for tempo matching we used the rubberband CLI in fine mode. it time stretches audio to change its tempo without changing the pitch.
but librosa generatedf incorrect BPM estimates 30% of the time. after doing some research, file2Beats had much better accuracy.
librosa just used signal processing - applying math to the audio waveform.
alternatively, file2beats feeds the audio into a transformer that looks at full song context, then makes two predictions:
- beat probability: how likely each frame is a beat
- downbeat probability: how likely each frame is a beat 1 of a measure
then filebeats gets the local maximum of all beat probabilities(most likely frame to be a beat in between two other frames). THEN takes the median time gaps, and divides 60 by it to get the BPM.
this approach is much more accurate and does not make incorrect predictions.
part 2 - adding the model, teaching how to DJ
lyrics, song structure, sys prompt.
next was adding the ml model. but to gi
how it sounded after part 2:
part 3
EQ balancing
handling backing vocals
part 4
dynamic EQ
key convergence
part 5
iterations
LUFS fix
lessons learned/reflections
- claude does not have musical taste and does not have a good musical judgement ability
- initially, i had it spin up audio engineer experts, to teach me things and consult on decisions. this did not work well.
- consulting my brother and friends was more valuable.
- instrumentals/vocals, which is better to stretch?
- speedup vs slowdown.
