Skip to content

dbeckwith/LED-Music-Visualizer

Repository files navigation

LED Music Visualizer 💡🎵💡

I created this project as part of my Humanities & Arts Practicum at Worcester Polytechnic Institute. The practicum was called "Light Art" and was directed by Prof. Joshua Rosenstock.

The goal behind the project was to try to find a way to map the sounds we hear and the feelings evoked in us by music to light. I wanted to try to use light to convey the same emotions that I was feeling from listening to a song.

How It Works

First, the program loads the given audio file and does some pre-processing on it. The pre-processing involves creating a spectrogram of the audio using the Discrete Fourier Transform and applying a Mel Filter. Using this high-level information about the component frequencies of the audio, the program generates an animation. The animation is drawn for each frame on a canvas in memory, mapping different frequencies to different properties of the "blips" that are drawn. Then each frame is converted into RGB pixel data that is sent to a FadeCandy LED controller, which controls an LED matrix that displays the animation. The animation is partly reactive to the spectrogram, and partly hand-choreographed. The audio file is also played along with the animation to make sure that the two are perfectly synchronized.

Demo

Demo video

Blog post

Try It Out

Hardware

I used all the same materials from Adafruit's excellent tutorial on how to use their FadeCandy LED controller board. Simply follow this tutorial and you'll have the same electronics set-up I used. The only other material I used was the translucent white acrylic from Delvie's Plastics, which I cut to make an enclosure around the LED matrix. This allows the piercing, direct light of the LEDs to be diffused and softend a bit, which creates a more pleasing display.

Software

At the moment, the visualization is specifically coreographed to the song "Such Great Heights" by The Postal Service, so you'll need an MP3 file of that song.

You'll need to install the following software in order to run the code:

Make sure Python and ffmpeg are in your system path. Then, clone this repo or download and unzip the code. In the top directory, use the following command to install the required Python libraries with pip:

python -m pip install -r requirements.txt

You may want to do this in a Virtual Environment to avoid library version conflicts.

Usage

First, launch the FadeCandy server by running the appriopriate fcserver executable for your platform in the bin folder of the FadeCandy download. Once the server is running, connect the FadeCandy board by USB to your computer. You should see a message on the server saying it has connected to a board. If it's your first time connecting a FadeCandy board, you may have wait a minute for your OS to install the drivers.

Next, open config.py and make sure that the values there match your setup. DISPLAY_SHAPE should be a tuple of the number of columns and rows in your LED matrix (probably just 8 by 8), CHANNELS_PER_PIXEL should be 3 for the RGB pixels, and FADECANDY_HOST and FADECANDY_PORT should match the values shown when the FadeCandy server was launched.

Next, run the main script from the repo's top level directory to get help on its usage:

python main.py -h

At the moment, the visualization is specifically coreographed to the song "Such Great Heights" by The Postal Service, so if you own an MP3 of that song, supply a path to it for the --audio-path argument.