For 6.115 (Microcomputer Project Laboratory), I was tasked with using the Cypress PSoC-059 (Programmable System on Chip) and a $20 budget to propose, design, and develop a project. My project was a Bluetooth speaker and visualizer capable of streaming music from Bluetooth and displaying a music spectrum analyzer. 

Goal: A phone sends an audio signal to the PSoC-059 through Bluetooth. The PSoC generates the audio through an on-board DAC (digital-to-analog converter) and sends it to an op-amp for amplification and pass-through to a 3.5mm audio jack. Simultaneously, the PSoC will compute a Fast Fourier Transform (FFT) on a buffer of the signal to generate a spectrum analyzer.

Demo of the project playing Tití Me Preguntó by Bad Bunny

Parts:
I used the HC-05 to receive Bluetooth data and stream it to the PSoC through serial UART. I also used an ILI 9341 TFT LCD display to present the spectrum analyzer using SPI (Serial Peripherial Interface). For audio, I used an LM386 to amplify the PSoC's generated output.

Getting Started:
To easily debug, I began by trying to play wired audio through an FTDI USB to Serial converter using a Python program I wrote to transmit a given wave file. 
Why Wave? Easiest way to play music would be to use WAV files since they are a simple array of waveform data points ranging from 0 to 255. Although this is generally not a great idea due to bandwidth, it sufficed for this project. Mp3 file decoding would have been too complex for the PSoC and my time frame, while a dedicated decoder would have been out of the budget range.
Wave file format diagram from https://www.videoproc.com/resource/wav-file.htm

Wave file format and byte sequence from videoproc

I began by playing a hard-coded 1 second 6 kHz 8-bit mono audio clip on repeat and verifying that the sound could be played and accurately resembled the audio file. This meant that I would have to transmit (8 bits+1 start bit + 1 stop bit)*(6000 points/second)*(1 channel) = 60,000 bits every second.

To play longer than this, I needed to stream music data. Using the USB-Serial connector previously mentioned, I was able to feed the music data. At 115,200 baud, 1.92 seconds of music data could stream every second. To ensure the correct music tempo was preserved, I used a linked list queue to store the incoming data and dequeued at the specified sampling rate of 6kHz from an internal clock.

Since data is entering the queue faster than it is being used, eventually the queue will overflow. To resolve this, I programmed the PSoC to send a "STOP" signal to the computer once it neared overflow. After enough data was dequeued, the PSoC would send a "START" signal to continue receiving data. This back-and-forth of starting and stopping continues until there is no more data left. With this logic, my DAC (digital-to-analog converter) was able to mimic the same signals as my audio file as shown below. My DAC output is shown on the left while the right displays the original file in Audacity.
LED Visuals:
To display an LED synchronized with the music, I first tried to determine the LED brightness based on the audio amplitude. However, I found an LED that synchronized with beat drops to give a better effect, so I set the LED brightness based on volume deltas.

Fast Fourier Transform:
To determine the audio spectrum of the song being played, I applied an open source fast fourier transform to the audio signal and mapped its output to pixels on the TFT LCD display, giving the result in the video above.

You may also like

Back to Top