Hi,
Apologies in advance for a longish post but I want to put in as much details as I can. I was not sure if I should start a new topic since the question relates to the same project but involves the code and I did not want to cross post.
The idea of the project was to make a 16x64 audio spectrum analyzer with the FFT running on a laptop on processing sending data to an HC-05 BT module to a standalone Arduino that drives the Max7219 displays. I have been able to verify that the 8x8 modules work fine. The processing code that I am using is adapted from here:
import processing.serial.*;
//import processing.sound.*;
import ddf.minim.analysis.*;
import ddf.minim.*;
Minim minim;
AudioInput in;
FFT fft;
int buffer_size = 4096;
float sample_rate = 200000;
int freq_width = 150;
int bands = 64;
Serial port1;
float[] spectrum = new float[bands];
int [ ]freq_array = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
float[] freq_height = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
void settings()
{
size(512, 360);
}
void setup() {
background(255);
// Create an Input stream which is routed into the Amplitude analyzer
minim = new Minim(this);
// start the Audio Input
in = minim.getLineIn(Minim.MONO,buffer_size, sample_rate);
// patch the AudioIn
// create an FFT object that has a time-domain buffer
// the same size as line-in's sample buffer
fft = new FFT(in.bufferSize(), in.sampleRate());
// Tapered window important for log-domain display
fft.window(FFT.HAMMING);
port1 = new Serial (this, "COM5", 115200);
}
void draw() {
background(255);
for(int k=0; k<64; k++){
freq_array[k] = 0;
}
fft.forward(in.mix);
freq_height[0] = fft.calcAvg((float) 0, (float) 30);
freq_height[1] = fft.calcAvg((float) 31, (float) 60);
freq_height[2] = fft.calcAvg((float) 61, (float) 100);
freq_height[3] = fft.calcAvg((float) 101, (float) 150);
freq_height[4] = fft.calcAvg((float) 151, (float) 200);
freq_height[5] = fft.calcAvg((float) 201, (float) 250);
freq_height[6] = fft.calcAvg((float) 251, (float) 300);
freq_height[7] = fft.calcAvg((float) 301, (float) 350);
freq_height[8] = fft.calcAvg((float) 351, (float) 400);
for(int n = 9; n < 63; n++)
{
freq_height[n] = fft.calcAvg((float) (351+(freq_width*(n-9))), (float) (500+(freq_width*(n-9))));
}
freq_height[63] = (fft.calcAvg((float) 20, (float) 60));
float x = 8;
float y = 3;
for(int j=0; j<64; j++){
freq_height[j] = freq_height[j]*(log(x)/y);
x = x + (x);
}
for(int j=0; j<64; j++){
if (freq_height[j] < 2000 && freq_height[j] > 180){freq_array[j] = 16;}
else{ if (freq_height[j] <= 180 && freq_height[j] > 160){freq_array[j] = 15;}
else{ if (freq_height[j] <= 160 && freq_height[j] > 130){freq_array[j] = 14;}
else{ if (freq_height[j] <= 130 && freq_height[j] > 110){freq_array[j] = 13;}
else{ if (freq_height[j] <= 110 && freq_height[j] > 90){freq_array[j] = 12;}
else{ if (freq_height[j] <= 90 && freq_height[j] > 70){freq_array[j] = 11;}
else{ if (freq_height[j] <= 70 && freq_height[j] > 60){freq_array[j] = 10;}
else{ if (freq_height[j] <= 60 && freq_height[j] > 50){freq_array[j] = 9;}
else{ if (freq_height[j] <= 50 && freq_height[j] > 40){freq_array[j] = 8;}
else{ if (freq_height[j] <= 40 && freq_height[j] > 30){freq_array[j] = 7;}
else{ if (freq_height[j] <= 30 && freq_height[j] > 20){freq_array[j] = 6;}
else{ if (freq_height[j] <= 20 && freq_height[j] > 15){freq_array[j] = 5;}
else{ if (freq_height[j] <= 15 && freq_height[j] > 11){freq_array[j] = 4;}
else{ if (freq_height[j] <= 11 && freq_height[j] > 8){freq_array[j] = 3;}
else{ if (freq_height[j] <= 8 && freq_height[j] > 5){freq_array[j] = 2;}
else{ if (freq_height[j] <= 5 && freq_height[j] > 2){freq_array[j] = 1;}
else{ if (freq_height[j] <= 2 && freq_height[j] > 0){freq_array[j] = 0;}
}}}}}}}}}}}}}}}}}
String sta = "M";
String aa = str(freq_array[0]);
String bb = str(freq_array[1]);
String cc = str(freq_array[2]);
String dd = str(freq_array[3]);
String ee = str(freq_array[4]);
String ff = str(freq_array[5]);
String gg = str(freq_array[6]);
String hh = str(freq_array[7]);
String ii = str(freq_array[8]);
String jj = str(freq_array[9]);
String kk = str(freq_array[10]);
String ll = str(freq_array[11]);
String mm = str(freq_array[12]);
String nn = str(freq_array[13]);
String oo = str(freq_array[14]);
String pp = str(freq_array[15]);
String qq = str(freq_array[16]);
String rr = str(freq_array[17]);
String ss = str(freq_array[18]);
String tt = str(freq_array[19]);
String uu = str(freq_array[20]);
String vv = str(freq_array[21]);
String ww = str(freq_array[22]);
String xx = str(freq_array[23]);
String yy = str(freq_array[24]);
String zz = str(freq_array[25]);
String aaa = str(freq_array[26]);
String bbb = str(freq_array[27]);
String ccc = str(freq_array[28]);
String ddd = str(freq_array[28]);
String eee = str(freq_array[30]);
String fff = str(freq_array[31]);
String ggg = str(freq_array[32]);
String hhh = str(freq_array[33]);
String iii = str(freq_array[34]);
String jjj = str(freq_array[35]);
String kkk = str(freq_array[36]);
String lll = str(freq_array[37]);
String mmm = str(freq_array[38]);
String nnn = str(freq_array[39]);
String ooo = str(freq_array[40]);
String ppp = str(freq_array[41]);
String qqq = str(freq_array[42]);
String rrr = str(freq_array[43]);
String sss = str(freq_array[44]);
String ttt = str(freq_array[45]);
String uuu = str(freq_array[46]);
String vvv = str(freq_array[47]);
String www = str(freq_array[48]);
String xxx = str(freq_array[49]);
String yyy = str(freq_array[50]);
String zzz = str(freq_array[51]);
String aaaa = str(freq_array[52]);
String bbbb = str(freq_array[53]);
String cccc = str(freq_array[54]);
String dddd = str(freq_array[55]);
String eeee = str(freq_array[56]);
String ffff = str(freq_array[57]);
String gggg = str(freq_array[58]);
String hhhh = str(freq_array[59]);
String iiii = str(freq_array[60]);
String jjjj = str(freq_array[61]);
String kkkk = str(freq_array[62]);
String llll = str(freq_array[63]);
String com = ",";
String newl = "\n";
String send1 = sta + com + aa + com + bb + com + cc + com + dd + com + ee + com + ff + com + gg + com + hh + com + ii + com + jj + com + kk + com + ll + com + mm + com + nn + com + oo + com + pp + com + qq + com + rr + com + ss + com + tt + com + uu + com + vv + com + ww + com + xx + com + yy + com + zz + com + aaa + com + bbb + com + ccc + com + ddd + com + eee + com + fff + com + ggg + com + hhh + com + iii + com+ jjj + com + kkk + com + lll + com + mmm + com + nnn + com + ooo + com + ppp + com + qqq + com + rrr + com + sss + com + ttt + com + uuu + com + vvv + com + www + com + xxx + com + yyy + com + zzz + com + aaaa + com + bbbb + com + cccc + com + dddd + com + eeee + com + ffff + com + gggg + com + hhhh + com + iiii + com + jjjj + com + kkkk + com + llll + newl;
port1.write(send1);
port1.clear();
}
void stop()
{
in.close();
minim.stop();
super.stop();
}
Continued below: