An audio spectrum analyzer for the Raspberry Pi, using a soundcard and an addressable LED strip on the GPIO ports. Additionally a second waterfall-style effect on a second strip is included.
sudo apt-get install libasound2-dev scons
-
Plug 2 strips to the GPIO pins. Not all are usable, sticking with Pins 13 and 18 is safe. Enter the length of the strips to LED_COUNT, the pin to GPIO_PIN and whether you want to reverse the order into REVERSE. Hereby the defines with "_0" are for the spectrum and "_1" for the waterfall. Also you may want to change the STRIP_TYPE and TARGET_FREQ. Defaults are for a generic ws2812b.
-
Plug in a soundcard and either a microphone or use an audio splitter to route the sound going to your speakers into the soundcard (use the cyan Line port in that case)
-
Determine the card and subdevice ID of your soundcard through
arecord -l
-
Use
alsamixer -D hw:k
where k is your device ID. Make sure "PCM Capture" is set to the correct port. Go to the capture devices and enable your chosen device by pressing space such that it says "CAPTURE" in red at the bottom. Also make sure to set the volume of the device to no more than 0.0dB (otherwise you may get a heavily distorted output). Save the settings withsudo alsactl store
. If they revert after reboot, use this. -
Optional. Run
sudo ./raspthetics -i
once while nothing is played back to determine the background noise level. The main code will then be able to disable the LEDs if only noise is present.
Use scons
to compile and run the code with sudo ./raspthetics -c1 -d0
if 1 is your card ID and 0 is your device ID. Card 1 and device 0 are the default.