Song Visualiser

or Explorations into the Slow Fourier Transform...

Dec 2018
PythonPygame

A program to visualise songs using a Fourier transform written from scratch.

During the summer break between high school and starting university I was watching this 3Blue1Brown video on a visual introduction to the Fourier transform, which is essentially a method of extracting the component frequencies of some function.

He does a really good job of explaining it, because it was enough for me to intutively understand the algorithm enough to directly translate it into code (which is arguably the ultimate test for understanding an algorithm).

I figured frequency deconstruction was how YouTube videos like these were produced, so in order to prove my algorithm works I set myself the goal of recreating these animations on another song by reading the individual samples of a .wav file.

Video demo

The first 60 seconds of "Exit the Premises" by Kevin MacLeod.

Update: The actual Kevin MacLeod somehow found this video (Content ID?) at 14 views and commented on it.. 😍

At this point I could probably have gone much further with the visualisation and produced something that looks like the music videos, as I had finished the challenging part of getting the core algorithm to work. But apparently I completed what I originally wanted to achieve and moved right onto my next project 🤷.

Programming

Algorithm

As mentioned, the entire algorithm is just my visual understanding of the Fourier transform from this 3Blue1Brown video, translated into code form. Being manually written and therefore horribly slow, I shall coin the algorithm as I have written it the "Slow Fourier Transform" (in contrast to the Fast Fourier Transform, which is actually used for this sort of task).

It is essentially lots of iterative "wrapping" of a waveform (as sourced from the samples of a .wav file) around the origin at different speeds (frequencies), where the deviation of the mean of the wrapped waveform from the origin represents the magnitude of that particular wrapping frequency in the waveform.

I could attempt to explain it property with diagrams, but I'd strongly recommend you just watch this video if you are curious.

Source Code

Source code can be found on GitHub.