Software Design

Introduction

In this part, we utilized the wave library to extract the wave form data of the wav file, numpy library to do FFT and some other statistics work which required to generate the display data array, and multiprocessing library to realize the real-time display.

FFT

We implemented a 8x8x8 array to store the pattern we would like to display on the LED cube. Every element in the 3D array is corresponded to one LED in the cube and 1 means on and 0 means off. And every 0.11 second, a new computed 3-D array which contains the present frequency distribution image is expected to pass to the LED cube. Since that the front face of the cube corresponds to the frequency distribution at the very moment, and the 2nd face is the frequency distribution 0.11 seconds ago, likewise the 3rd face is the frequency distribution 0.22 seconds ago, etc., we are able to get the new 3-D array simply by shifting the 3-D array of last 0.11 seconds one face back and adding the new-computed present frequency distribution to the front face. So problems come to how to extract the present frequency distribution data.


After analyzing the FFT distributions of several different pieces of music, we decided to display the frequency spectrum in the range 0 to 900Hz for better visual experience. After sampling and quantization, we are able to get the frequency distribution with 8 bins, with each bin having 8 degrees. Thus then the 2-D front face array can be simply generated.

Cube Display

The whole cube is actually flashing all the time at the frequency of 62. A specific line can be enable to set values by controlling the inputs of the 3-8 decoder which selects horizontal layer and the inputs of the 3-8 decoder which selects latch. And the values of 8 eight LEDs on this specific chosen line can be set by controlling the 8 inputs of latches. So all the LEDs are actually continuously light up line by line and layer by layer.


Some details are worth attention during the cube display process. If the inputs of latch selecting 3-8 decoder are change by the order of 000, 001, 010, 011 etc., we are not able precisely control every line. For example, two bits are required to be changed in the process of converting 001 to 010, so there is a middle state after we change 1 bit of the inputs, which actually has selected a latch we don’t mean to for a while. As a result, we pass the wrong value to some of lines. To avoid this situation, we selected the latch with the order of 000, 001, 011, 010, 110, 111, 101, 100, by which every time only 1 bit is required to change. Also, during the interval between we select a new layer and set the values of this layer’s LEDs line by line, the present chosen layer actually shows the wrong values of the last chosen layer, so we are supposed to clear every latch before choosing a layer to accomplish precisely control.


In the part, we implemented a test program which light up the 512 LEDs one by one check all the circuits, LEDs and cube display logic.

Multiprocessing

The raspberry does multiple tasks, including playing the music, processing the audio signals, updating the data of the cube and refreshing the cube at the same time. To make it possible for Pi to handle the heavy work, we allocated the music playing, data processing to a core, and the cube refreshing to a different core. Two cores communicate with each other through a multiprocessing queue.