If a 8×8 LED matrix audio level meter is insufficient for you, I’ll show you in this article how to use a small 128×32 display to view an audio spectrum.
How the visual representation of the spectrum should look like, you can set yourself. My version is a bar graph.
What you need
The hardware you need is the display itself. But in the I2C version with the driver IC SSD1306.
Like the 8×8 LED matrix there is needed a component of TMS software to control the 128×32 display. How to install it in Lazarus, I described in the article 8×8 LED matrix with Raspberry and Lazarus.
The components of TMS have been developed for the hardware of adafruit. But it also works with other manufacturers.
I’m using a display with 128×64 pixels. Which unfortunately can be addressed only for 32 lines. But the result looks pretty useful too.
The great thing is that the program works just as you learned at the audio level meter article.
The connection to the display is done via the component TTMSLCLAdaDispl128x32. In the app sample I use the instance display, so that the amount of writing is a little smaller.
Initializing works very similar to the 8×8 LED matrix. The address for the I2C is hexadecimal 3C (or as decimal number: 60).
display.I2CAddress:=Hex2Dec('$3c'); display.Open; display.Clear;
You can use the command i2cdetect -y 1 in a shell to get the address of your device.
The basic functions of the MP3 processing are the same as in the previous article. For the MP3 output the BASS library of un4seen.com is used again.
The visualization of the audio spectrum is triggered by a timer event. As timer interval I use 100 ms.
In order to get the appropriate data in parallel to the sound output, the BASS library provides the function ChannelGetData.
BASS_ChannelGetData(Channel, @FFTData, 1024);
With a few instructions, an audio spectrum can be generated from the data.
//Clear bitmap for screen output
if CheckboxFilled.Checked=true then Bitmap.Canvas.Brush.Color:=clWhite;
if j*SpinEditColWidth.Value>127 then j:=j-1;
for i := 0 to j do begin
if YPosI>MaxBar then MaxBar:=YPosI;
if YPos>SpecHeight then YPos:=SpecHeight;
if YPos>=FFTPeacks[i] then FFTPeacks[i]:=YPos
if YPos>=FFTFallOff[i] then FFTFallOff[i]:=YPos
if (SpecHeight-FFTPeacks[i])>SpecHeight then FFTPeacks[i]:=0;
if (SpecHeight-FFTFallOff[i])>SpecHeight then FFTFallOff[i]:=0;
//128x32 display output
if CheckboxFilled.Checked=true then
For your first tests it’s best to download the sample app and have a look at my spectrum display.
Have fun experimenting!
Source code of the sample app Miniplayer2
(with a directly executable application miniplayer2)
BASS library for Lazarus: http://www.un4seen.com/
The basic routine for my app is based of the example Spectrum Visualyzation of Alessandro Cappellozza. Which is part of the BASS library.
Website of TMS Software: https://www.tmssoftware.com/site/tmslclhwpack.asp
TMS package on github: https://github.com/tmssoftware/TMS-LCL-HW-Pack-for-Raspberry-Pi
The MP3 sample files come from FRAMETRAXX : GEMA-free music