Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: Room analysis for room correction

  1. #1

    Room analysis for room correction

    I am working on a project to measure the acoustics of a room by playing a test tone through a speaker and analyzing FFT from the input of a mic. I want to generate correction filters using the biquad filters. Well I designed a complicated circuit in the GUI that will help me run the analysis as intended in order to prove that it is working as intended. I am using a Teensy 3.2 with a single audio shield attached. The speaker and mic are connected I2s line in and out ports on the shield.

    Right now I have the controller first sending pink noise for 15 seconds and measuring the time domain audio amplitude coming in from the mic. This is simply a comparative number for when I generate the filters (during tonesweep3). Then I am playing tonesweep1 straight from computer to computer to receive a "perfect world" what the tonesweep should look like when playing through my speakers. Next I play the tonesweep2 through the speakers and record the FFT of the mic input to see the "distortion created by the room and speakers." And that's when I intend on generating correction filters, from parallel biquad filters and adjust gains through mixers they are connected to. After generating the filters and their desired gains, I will play the tonesweep3 through the filters out the speaker and back into the mic to see the FFT one more time to compare to tonesweep1.

    I am pretty sure I have designed something to complex for Teensy's capability on the 3.2. I wasn't looking for the most accurate room correction, meaning the frequecy resolution of the FFT is 43Hz and it is sampling the FFT apporx 86 times a second instead of the same sampling frequency of the ADC/DAC, and thats all ok with me. The code I am uploading for you to help me with doesnt have the filters changing any gains because as soon as I introduced the amount of filters I am using there was instant distortion to the tonesweep signal. After increasing the Audiomemory() to allow for more audio processing, it still has distortion. Is this distortion fixable?

    Here are some picture of my giant circuit in case you don't want to upload the auto-generated code that is clearly noted within the code. The code is also below.

    Attachment 8792
    Attachment 8793
    Attachment 8794
    Attachment 8795
    Attachment 8796
    Attachment 8797


    Code:
    //     Steven's Room Analyzer and Room Correction Filter Generation
    //     
    //     
    //     A special thank you to Paul Stoffregen and his team for 
    //     developing such a great open source device that supports audio
    //     DSP. This project was developed on Teensy 3.2 with and audio
    //     shield
    
    
     #include <LiquidCrystal.h>
    #include <Bounce.h>
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    #include <Time.h>
    #include <TimeAlarms.h>
    
    
    
    
    
    
    // GUItool: begin automatically generated code
    AudioInputAnalog         adc1;           //xy=81,20
    AudioInputI2S            i2s1;           //xy=80.88336181640625,296.8833312988281
    AudioSynthNoisePink      pink1;          //xy=84.00003051757812,160
    AudioSynthNoisePink      pink3;          //xy=83.88333129882812,232.88333129882812
    AudioSynthNoisePink      pink2;          //xy=84.88333129882812,196.88333129882812
    AudioSynthToneSweep      tonesweep1;     //xy=87.00003051757812,52
    AudioSynthToneSweep      tonesweep2;     //xy=88.88333129882812,85.88333129882812
    AudioSynthToneSweep      tonesweep3;     //xy=93.88333129882812,120.88333129882812
    AudioMixer4              mixer1;         //xy=111.00003051757812,408
    AudioFilterBiquad        biquad79;       //xy=267.8833770751953,1577.883316040039
    AudioFilterBiquad        biquad77;       //xy=269.8833770751953,1544.883316040039
    AudioFilterBiquad        biquad75;       //xy=272.8833770751953,1511.883316040039
    AudioFilterBiquad        biquad73;       //xy=273.8833770751953,1475.883316040039
    AudioFilterBiquad        biquad69;       //xy=274.8833770751953,1403.883316040039
    AudioFilterBiquad        biquad71;       //xy=274.8833770751953,1440.883316040039
    AudioFilterBiquad        biquad67;       //xy=276.8833770751953,1366.883316040039
    AudioFilterBiquad        biquad63;       //xy=279.8833770751953,1299.883316040039
    AudioFilterBiquad        biquad1;        //xy=286.0000762939453,209.99998474121094
    AudioFilterBiquad        biquad15;       //xy=285.8833770751953,452.8833465576172
    AudioFilterBiquad        biquad17;       //xy=285.8833923339844,488.88331604003906
    AudioFilterBiquad        biquad3;        //xy=286.8833770751953,245.88328552246094
    AudioFilterBiquad        biquad61;       //xy=282.8833770751953,1266.883316040039
    AudioFilterBiquad        biquad11;       //xy=286.8833770751953,381.8833465576172
    AudioFilterBiquad        biquad59;       //xy=283.8833770751953,1229.883316040039
    AudioFilterBiquad        biquad5;        //xy=287.8833770751953,277.8833465576172
    AudioFilterBiquad        biquad13;       //xy=287.8833770751953,417.8833465576172
    AudioFilterBiquad        biquad57;       //xy=284.8833770751953,1196.883316040039
    AudioFilterBiquad        biquad19;       //xy=287.8833923339844,521.8833160400391
    AudioFilterBiquad        biquad7;        //xy=288.8833770751953,312.8833465576172
    AudioFilterBiquad        biquad9;        //xy=288.8833770751953,345.8833465576172
    AudioFilterBiquad        biquad21;       //xy=288.8833923339844,556.8833160400391
    AudioFilterBiquad        biquad23;       //xy=288.8833770751953,590.8833160400391
    AudioFilterBiquad        biquad25;       //xy=288.8833770751953,625.8832550048828
    AudioFilterBiquad        biquad27;       //xy=288.8833770751953,661.8832550048828
    AudioFilterBiquad        biquad65;       //xy=286.8833770751953,1330.883316040039
    AudioFilterBiquad        biquad39;       //xy=288.8833770751953,871.8833160400391
    AudioFilterBiquad        biquad55;       //xy=287.8833770751953,1161.883316040039
    AudioFilterBiquad        biquad37;       //xy=289.8833770751953,836.8833160400391
    AudioFilterBiquad        biquad51;       //xy=288.8833770751953,1089.883316040039
    AudioFilterBiquad        biquad53;       //xy=288.8833770751953,1124.883316040039
    AudioFilterBiquad        biquad41;       //xy=289.8833770751953,909.8833160400391
    AudioFilterBiquad        biquad29;       //xy=290.8833770751953,694.8832550048828
    AudioFilterBiquad        biquad33;       //xy=290.8833770751953,766.8832550048828
    AudioFilterBiquad        biquad35;       //xy=290.8833770751953,802.8832550048828
    AudioFilterBiquad        biquad49;       //xy=290.8833770751953,1053.883316040039
    AudioFilterBiquad        biquad47;       //xy=291.8833770751953,1016.8832550048828
    AudioFilterBiquad        biquad43;       //xy=292.8833770751953,943.8833160400391
    AudioFilterBiquad        biquad31;       //xy=293.8833770751953,731.8832550048828
    AudioFilterBiquad        biquad45;       //xy=294.8833770751953,980.8833160400391
    AudioMixer4              mixer5;         //xy=407.88336181640625,262.8833770751953
    AudioMixer4              mixer23;        //xy=405.88336181640625,1532.883316040039
    AudioMixer4              mixer33;        //xy=412.8833312988281,34.883331298828125
    AudioMixer4              mixer21;        //xy=410.88336181640625,1384.883316040039
    AudioMixer4              mixer7;         //xy=414.88336181640625,402.8833465576172
    AudioMixer4              mixer19;        //xy=414.88336181640625,1252.2833404541016
    AudioMixer4              mixer34;        //xy=420.8833312988281,173.88333129882812
    AudioMixer4              mixer9;         //xy=419.88336181640625,538.8833160400391
    AudioMixer4              mixer13;        //xy=418.88336181640625,816.8832550048828
    AudioMixer4              mixer11;        //xy=420.88336181640625,676.8833160400391
    AudioMixer4              mixer17;        //xy=421.88336181640625,1108.683364868164
    AudioMixer4              mixer15;        //xy=427.88336181640625,966.6833038330078
    AudioMixer4              mixer2;         //xy=587,464
    AudioAnalyzeFFT1024      fft1024_2;      //xy=737.8833312988281,86.88333129882812
    AudioAnalyzeFFT1024      fft1024_1;      //xy=739,27
    AudioFilterBiquad        biquad6;        //xy=755.88330078125,287.88330078125
    AudioFilterBiquad        biquad36;       //xy=753.88330078125,840.8833312988281
    AudioFilterBiquad        biquad32;       //xy=754.88330078125,765.8832702636719
    AudioFilterBiquad        biquad34;       //xy=754.88330078125,800.8833312988281
    AudioFilterBiquad        biquad8;        //xy=756.88330078125,326.88330078125
    AudioFilterBiquad        biquad10;       //xy=756.8833312988281,362.8833312988281
    AudioFilterBiquad        biquad14;       //xy=757.88330078125,431.8832702636719
    AudioFilterBiquad        biquad2;        //xy=759,214.00003051757812
    AudioFilterBiquad        biquad24;       //xy=757.88330078125,618.8833618164062
    AudioFilterBiquad        biquad12;       //xy=758.88330078125,396.8832702636719
    AudioFilterBiquad        biquad28;       //xy=757.88330078125,694.8833312988281
    AudioFilterBiquad        biquad30;       //xy=757.88330078125,730.8832702636719
    AudioFilterBiquad        biquad4;        //xy=759.88330078125,250.88330078125
    AudioFilterBiquad        biquad22;       //xy=758.88330078125,578.8833618164062
    AudioFilterBiquad        biquad26;       //xy=758.88330078125,655.8833312988281
    AudioFilterBiquad        biquad16;       //xy=759.88330078125,468.88336181640625
    AudioFilterBiquad        biquad18;       //xy=759.88330078125,504.8833312988281
    AudioFilterBiquad        biquad20;       //xy=759.88330078125,544.8833312988281
    AudioFilterBiquad        biquad44;       //xy=762.88330078125,997.8832702636719
    AudioFilterBiquad        biquad38;       //xy=763.88330078125,880.8832702636719
    AudioFilterBiquad        biquad42;       //xy=763.88330078125,959.8832702636719
    AudioFilterBiquad        biquad40;       //xy=764.88330078125,918.8833312988281
    AudioFilterBiquad        biquad46;       //xy=764.88330078125,1034.8833312988281
    AudioFilterBiquad        biquad48;       //xy=764.88330078125,1071.8833312988281
    AudioFilterBiquad        biquad50;       //xy=768.88330078125,1110.8833312988281
    AudioFilterBiquad        biquad52;       //xy=769.88330078125,1154.8833312988281
    AudioFilterBiquad        biquad64;       //xy=769.88330078125,1382.8833312988281
    AudioFilterBiquad        biquad66;       //xy=770.88330078125,1418.8833312988281
    AudioFilterBiquad        biquad60;       //xy=771.88330078125,1311.8833312988281
    AudioFilterBiquad        biquad78;       //xy=770.88330078125,1635.8833312988281
    AudioFilterBiquad        biquad68;       //xy=771.88330078125,1456.8833312988281
    AudioFilterBiquad        biquad58;       //xy=772.88330078125,1272.8833312988281
    AudioFilterBiquad        biquad72;       //xy=771.88330078125,1527.8833312988281
    AudioFilterBiquad        biquad62;       //xy=772.88330078125,1348.8833312988281
    AudioFilterBiquad        biquad80;       //xy=771.88330078125,1673.8833312988281
    AudioFilterBiquad        biquad70;       //xy=772.88330078125,1492.8833312988281
    AudioFilterBiquad        biquad74;       //xy=772.88330078125,1560.8833312988281
    AudioFilterBiquad        biquad54;       //xy=775.88330078125,1192.8833923339844
    AudioFilterBiquad        biquad56;       //xy=775.88330078125,1232.8833312988281
    AudioFilterBiquad        biquad76;       //xy=774.88330078125,1598.8833312988281
    AudioMixer4              mixer8;         //xy=903.88330078125,423.88330078125
    AudioMixer4              mixer22;        //xy=902.88330078125,1474.8832397460938
    AudioMixer4              mixer20;        //xy=903.88330078125,1332.8832397460938
    AudioMixer4              mixer24;        //xy=902.88330078125,1614.8832397460938
    AudioMixer4              mixer14;        //xy=906.88330078125,864.88330078125
    AudioMixer4              mixer12;        //xy=907.88330078125,724.88330078125
    AudioMixer4              mixer6;         //xy=909.88330078125,248.88333129882812
    AudioMixer4              mixer18;        //xy=907.88330078125,1169.8832397460938
    AudioMixer4              mixer16;        //xy=910.88330078125,1016.88330078125
    AudioMixer4              mixer10;        //xy=919.88330078125,557.88330078125
    AudioMixer4              mixer29;        //xy=1217.7167053222656,281.0834655761719
    AudioMixer4              mixer27;        //xy=1221.7167053222656,209.48336791992188
    AudioMixer4              mixer25;        //xy=1222.7167053222656,125.48333740234375
    AudioMixer4              mixer26;        //xy=1227.7166748046875,429.88323974609375
    AudioMixer4              mixer30;        //xy=1227.7166748046875,581.0833129882812
    AudioMixer4              mixer28;        //xy=1228.7166748046875,506.2833251953125
    AudioMixer4              mixer31;        //xy=1538.88330078125,203.28326416015625
    AudioMixer4              mixer32;        //xy=1551.88330078125,414.28326416015625
    AudioMixer4              mixer3;         //xy=1848.88330078125,292.08331298828125
    AudioMixer4              mixer4;         //xy=1850.8832702636719,364.08331298828125
    AudioAnalyzeRMS         rms_L;          //xy=1977.9999694824219,270.1999816894531
    AudioAnalyzeRMS         rms_R;          //xy=1980.9999694824219,391.1999816894531
    AudioAnalyzePeak     peak_L;
    AudioAnalyzePeak     peak_R;
    AudioAnalyzeRMS         rms_L1;          //xy=1977.9999694824219,270.1999816894531
    AudioAnalyzeRMS         rms_R1;          //xy=1980.9999694824219,391.1999816894531
    AudioAnalyzePeak     peak_L1;
    AudioAnalyzePeak     peak_R1;
    AudioOutputI2S           i2s2;           //xy=1981.8832702636719,334.08331298828125
    
    
    
    
    
    
    AudioConnection         c1(i2s1, 0, peak_L, 0);
    AudioConnection          c2(i2s1, 1, peak_R, 0);
    AudioConnection         c3(i2s1,0,rms_L,0);
    AudioConnection         c4(i2s1,1,rms_R,0);
    AudioConnection         c5(tonesweep1, 0, peak_L1, 0);
    AudioConnection          c6(tonesweep1, 1, peak_R1, 0);
    AudioConnection         c7(tonesweep1,0,rms_L1,0);
    AudioConnection         c8(tonesweep1,1,rms_R1,0);
    AudioConnection          patchCord1(adc1, 0, mixer33, 3);
    AudioConnection          patchCord2(i2s1, 0, mixer33, 0);
    AudioConnection          patchCord3(i2s1, 1, mixer33, 1);
    AudioConnection          patchCord4(pink1, 0, mixer34, 1);
    AudioConnection          patchCord5(pink3, 0, mixer1, 1);
    AudioConnection          patchCord6(pink3, 0, mixer2, 1);
    AudioConnection          patchCord7(pink2, 0, mixer29, 3);
    AudioConnection          patchCord8(pink2, 0, mixer30, 3);
    AudioConnection          patchCord9(tonesweep1, 0, mixer34, 0);
    AudioConnection          patchCord10(tonesweep2, 0, mixer31, 3);
    AudioConnection          patchCord11(tonesweep2, 0, mixer32, 3);
    AudioConnection          patchCord12(tonesweep3, 0, mixer1, 0);
    AudioConnection          patchCord13(tonesweep3, 0, mixer2, 0);
    AudioConnection          patchCord14(mixer1, biquad1);
    AudioConnection          patchCord15(mixer1, biquad3);
    AudioConnection          patchCord16(mixer1, biquad5);
    AudioConnection          patchCord17(mixer1, biquad7);
    AudioConnection          patchCord18(mixer1, biquad9);
    AudioConnection          patchCord19(mixer1, biquad11);
    AudioConnection          patchCord20(mixer1, biquad13);
    AudioConnection          patchCord21(mixer1, biquad15);
    AudioConnection          patchCord22(mixer1, biquad79);
    AudioConnection          patchCord23(mixer1, biquad77);
    AudioConnection          patchCord24(mixer1, biquad75);
    AudioConnection          patchCord25(mixer1, biquad73);
    AudioConnection          patchCord26(mixer1, biquad71);
    AudioConnection          patchCord27(mixer1, biquad69);
    AudioConnection          patchCord28(mixer1, biquad67);
    AudioConnection          patchCord29(mixer1, biquad65);
    AudioConnection          patchCord30(mixer1, biquad63);
    AudioConnection          patchCord31(mixer1, biquad61);
    AudioConnection          patchCord32(mixer1, biquad59);
    AudioConnection          patchCord33(mixer1, biquad57);
    AudioConnection          patchCord34(mixer1, biquad55);
    AudioConnection          patchCord35(mixer1, biquad53);
    AudioConnection          patchCord36(mixer1, biquad51);
    AudioConnection          patchCord37(mixer1, biquad49);
    AudioConnection          patchCord38(mixer1, biquad47);
    AudioConnection          patchCord39(mixer1, biquad45);
    AudioConnection          patchCord40(mixer1, biquad43);
    AudioConnection          patchCord41(mixer1, biquad41);
    AudioConnection          patchCord42(mixer1, biquad39);
    AudioConnection          patchCord43(mixer1, biquad37);
    AudioConnection          patchCord44(mixer1, biquad35);
    AudioConnection          patchCord45(mixer1, biquad33);
    AudioConnection          patchCord46(mixer1, biquad31);
    AudioConnection          patchCord47(mixer1, biquad29);
    AudioConnection          patchCord48(mixer1, biquad27);
    AudioConnection          patchCord49(mixer1, biquad25);
    AudioConnection          patchCord50(mixer1, biquad23);
    AudioConnection          patchCord51(mixer1, biquad21);
    AudioConnection          patchCord52(mixer1, biquad19);
    AudioConnection          patchCord53(mixer1, biquad17);
    AudioConnection          patchCord54(biquad79, 0, mixer23, 3);
    AudioConnection          patchCord55(biquad77, 0, mixer23, 2);
    AudioConnection          patchCord56(biquad75, 0, mixer23, 1);
    AudioConnection          patchCord57(biquad73, 0, mixer23, 0);
    AudioConnection          patchCord58(biquad69, 0, mixer21, 2);
    AudioConnection          patchCord59(biquad71, 0, mixer21, 3);
    AudioConnection          patchCord60(biquad67, 0, mixer21, 1);
    AudioConnection          patchCord61(biquad63, 0, mixer19, 3);
    AudioConnection          patchCord62(biquad1, 0, mixer5, 0);
    AudioConnection          patchCord63(biquad15, 0, mixer7, 3);
    AudioConnection          patchCord64(biquad17, 0, mixer9, 0);
    AudioConnection          patchCord65(biquad3, 0, mixer5, 1);
    AudioConnection          patchCord66(biquad61, 0, mixer19, 2);
    AudioConnection          patchCord67(biquad11, 0, mixer7, 1);
    AudioConnection          patchCord68(biquad59, 0, mixer19, 1);
    AudioConnection          patchCord69(biquad5, 0, mixer5, 2);
    AudioConnection          patchCord70(biquad13, 0, mixer7, 2);
    AudioConnection          patchCord71(biquad57, 0, mixer19, 0);
    AudioConnection          patchCord72(biquad19, 0, mixer9, 1);
    AudioConnection          patchCord73(biquad7, 0, mixer5, 3);
    AudioConnection          patchCord74(biquad9, 0, mixer7, 0);
    AudioConnection          patchCord75(biquad21, 0, mixer9, 2);
    AudioConnection          patchCord76(biquad23, 0, mixer9, 3);
    AudioConnection          patchCord77(biquad25, 0, mixer11, 0);
    AudioConnection          patchCord78(biquad27, 0, mixer11, 1);
    AudioConnection          patchCord79(biquad65, 0, mixer21, 0);
    AudioConnection          patchCord80(biquad39, 0, mixer13, 3);
    AudioConnection          patchCord81(biquad55, 0, mixer17, 3);
    AudioConnection          patchCord82(biquad37, 0, mixer13, 2);
    AudioConnection          patchCord83(biquad51, 0, mixer17, 1);
    AudioConnection          patchCord84(biquad53, 0, mixer17, 2);
    AudioConnection          patchCord85(biquad41, 0, mixer15, 0);
    AudioConnection          patchCord86(biquad29, 0, mixer11, 2);
    AudioConnection          patchCord87(biquad33, 0, mixer13, 0);
    AudioConnection          patchCord88(biquad35, 0, mixer13, 1);
    AudioConnection          patchCord89(biquad49, 0, mixer17, 0);
    AudioConnection          patchCord90(biquad47, 0, mixer15, 3);
    AudioConnection          patchCord91(biquad43, 0, mixer15, 1);
    AudioConnection          patchCord92(biquad31, 0, mixer11, 3);
    AudioConnection          patchCord93(biquad45, 0, mixer15, 2);
    AudioConnection          patchCord94(mixer5, 0, mixer25, 0);
    AudioConnection          patchCord95(mixer23, 0, mixer29, 1);
    AudioConnection          patchCord96(mixer33, fft1024_2);
    AudioConnection          patchCord97(mixer21, 0, mixer29, 0);
    AudioConnection          patchCord98(mixer7, 0, mixer25, 1);
    AudioConnection          patchCord99(mixer19, 0, mixer27, 3);
    AudioConnection          patchCord100(mixer34, fft1024_1);
    AudioConnection          patchCord101(mixer9, 0, mixer25, 2);
    AudioConnection          patchCord102(mixer13, 0, mixer27, 0);
    AudioConnection          patchCord103(mixer11, 0, mixer25, 3);
    AudioConnection          patchCord104(mixer17, 0, mixer27, 2);
    AudioConnection          patchCord105(mixer15, 0, mixer27, 1);
    AudioConnection          patchCord106(mixer2, biquad2);
    AudioConnection          patchCord107(mixer2, biquad80);
    AudioConnection          patchCord108(mixer2, biquad78);
    AudioConnection          patchCord109(mixer2, biquad76);
    AudioConnection          patchCord110(mixer2, biquad74);
    AudioConnection          patchCord111(mixer2, biquad72);
    AudioConnection          patchCord112(mixer2, biquad70);
    AudioConnection          patchCord113(mixer2, biquad68);
    AudioConnection          patchCord114(mixer2, biquad66);
    AudioConnection          patchCord115(mixer2, biquad64);
    AudioConnection          patchCord116(mixer2, biquad62);
    AudioConnection          patchCord117(mixer2, biquad60);
    AudioConnection          patchCord118(mixer2, biquad58);
    AudioConnection          patchCord119(mixer2, biquad56);
    AudioConnection          patchCord120(mixer2, biquad54);
    AudioConnection          patchCord121(mixer2, biquad52);
    AudioConnection          patchCord122(mixer2, biquad50);
    AudioConnection          patchCord123(mixer2, biquad48);
    AudioConnection          patchCord124(mixer2, biquad46);
    AudioConnection          patchCord125(mixer2, biquad44);
    AudioConnection          patchCord126(mixer2, biquad42);
    AudioConnection          patchCord127(mixer2, biquad40);
    AudioConnection          patchCord128(mixer2, biquad38);
    AudioConnection          patchCord129(mixer2, biquad36);
    AudioConnection          patchCord130(mixer2, biquad34);
    AudioConnection          patchCord131(mixer2, biquad32);
    AudioConnection          patchCord132(mixer2, biquad30);
    AudioConnection          patchCord133(mixer2, biquad28);
    AudioConnection          patchCord134(mixer2, biquad26);
    AudioConnection          patchCord135(mixer2, biquad24);
    AudioConnection          patchCord136(mixer2, biquad22);
    AudioConnection          patchCord137(mixer2, biquad20);
    AudioConnection          patchCord138(mixer2, biquad18);
    AudioConnection          patchCord139(mixer2, biquad16);
    AudioConnection          patchCord140(mixer2, biquad14);
    AudioConnection          patchCord141(mixer2, biquad12);
    AudioConnection          patchCord142(mixer2, biquad10);
    AudioConnection          patchCord143(mixer2, biquad8);
    AudioConnection          patchCord144(mixer2, biquad6);
    AudioConnection          patchCord145(mixer2, biquad4);
    AudioConnection          patchCord146(biquad6, 0, mixer6, 2);
    AudioConnection          patchCord147(biquad36, 0, mixer14, 1);
    AudioConnection          patchCord148(biquad32, 0, mixer12, 3);
    AudioConnection          patchCord149(biquad34, 0, mixer14, 0);
    AudioConnection          patchCord150(biquad8, 0, mixer6, 3);
    AudioConnection          patchCord151(biquad10, 0, mixer8, 0);
    AudioConnection          patchCord152(biquad14, 0, mixer8, 2);
    AudioConnection          patchCord153(biquad2, 0, mixer6, 0);
    AudioConnection          patchCord154(biquad24, 0, mixer10, 3);
    AudioConnection          patchCord155(biquad12, 0, mixer8, 1);
    AudioConnection          patchCord156(biquad28, 0, mixer12, 1);
    AudioConnection          patchCord157(biquad30, 0, mixer12, 2);
    AudioConnection          patchCord158(biquad4, 0, mixer6, 1);
    AudioConnection          patchCord159(biquad22, 0, mixer10, 2);
    AudioConnection          patchCord160(biquad26, 0, mixer12, 0);
    AudioConnection          patchCord161(biquad16, 0, mixer8, 3);
    AudioConnection          patchCord162(biquad18, 0, mixer10, 0);
    AudioConnection          patchCord163(biquad20, 0, mixer10, 1);
    AudioConnection          patchCord164(biquad44, 0, mixer16, 1);
    AudioConnection          patchCord165(biquad38, 0, mixer14, 2);
    AudioConnection          patchCord166(biquad42, 0, mixer16, 0);
    AudioConnection          patchCord167(biquad40, 0, mixer14, 3);
    AudioConnection          patchCord168(biquad46, 0, mixer16, 2);
    AudioConnection          patchCord169(biquad48, 0, mixer16, 3);
    AudioConnection          patchCord170(biquad50, 0, mixer18, 0);
    AudioConnection          patchCord171(biquad52, 0, mixer18, 1);
    AudioConnection          patchCord172(biquad64, 0, mixer20, 3);
    AudioConnection          patchCord173(biquad66, 0, mixer22, 0);
    AudioConnection          patchCord174(biquad60, 0, mixer20, 1);
    AudioConnection          patchCord175(biquad78, 0, mixer24, 2);
    AudioConnection          patchCord176(biquad68, 0, mixer22, 1);
    AudioConnection          patchCord177(biquad58, 0, mixer20, 0);
    AudioConnection          patchCord178(biquad72, 0, mixer22, 3);
    AudioConnection          patchCord179(biquad62, 0, mixer20, 2);
    AudioConnection          patchCord180(biquad80, 0, mixer24, 3);
    AudioConnection          patchCord181(biquad70, 0, mixer22, 2);
    AudioConnection          patchCord182(biquad74, 0, mixer24, 0);
    AudioConnection          patchCord183(biquad54, 0, mixer18, 2);
    AudioConnection          patchCord184(biquad56, 0, mixer18, 3);
    AudioConnection          patchCord185(biquad76, 0, mixer24, 1);
    AudioConnection          patchCord186(mixer8, 0, mixer26, 1);
    AudioConnection          patchCord187(mixer22, 0, mixer30, 0);
    AudioConnection          patchCord188(mixer20, 0, mixer28, 3);
    AudioConnection          patchCord189(mixer24, 0, mixer30, 1);
    AudioConnection          patchCord190(mixer14, 0, mixer28, 0);
    AudioConnection          patchCord191(mixer12, 0, mixer26, 3);
    AudioConnection          patchCord192(mixer6, 0, mixer26, 0);
    AudioConnection          patchCord193(mixer18, 0, mixer28, 2);
    AudioConnection          patchCord194(mixer16, 0, mixer28, 1);
    AudioConnection          patchCord195(mixer10, 0, mixer26, 2);
    AudioConnection          patchCord196(mixer29, 0, mixer31, 2);
    AudioConnection          patchCord197(mixer27, 0, mixer31, 1);
    AudioConnection          patchCord198(mixer25, 0, mixer31, 0);
    AudioConnection          patchCord199(mixer26, 0, mixer32, 0);
    AudioConnection          patchCord200(mixer30, 0, mixer32, 2);
    AudioConnection          patchCord201(mixer28, 0, mixer32, 1);
    AudioConnection          patchCord202(mixer31, 0, mixer3, 0);
    AudioConnection          patchCord203(mixer32, 0, mixer4, 0);
    AudioConnection          patchCord204(mixer3, 0, i2s2, 0);
    AudioConnection          patchCord205(mixer3, rms_L);
    AudioConnection          patchCord206(mixer4, 0, i2s2, 1);
    AudioConnection          patchCord207(mixer4, rms_R);
    AudioControlSGTL5000     sgtl5000_1;     //xy=1903.8832397460938,49.88328552246094
    // GUItool: end automatically generated code
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    /*
    *
    *   Pete’s Tonesweep starts here
    *
    
    
    
    
    
    
    
    
    // GUItool: begin automatically generated code
    AudioSynthToneSweep      tonesweep1;     //xy=255,382
    //AudioOutputI2S           i2s3;           //xy=763,360
    AudioConnection          patchCord6(tonesweep1, 0, i2s2, 0);
    AudioConnection          patchCord7(tonesweep1, 0, i2s2, 1);
    //AudioControlSGTL5000     sgtl5000_1;     //xy=242,174
    // GUItool: end automatically generated code
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    *
    *   Pete’s Tonesweep ends here
    *
    */
    
    
    
    
    
    
    
    
    
    
    
    
    //const int myInput = AUDIO_INPUT_LINEIN;
    const int myInput = AUDIO_INPUT_MIC;
    
    
    
    
    
    
    
    
    // The scale sets how much sound is needed in each frequency range to
    // show all 8 bars.  Higher numbers are more sensitive.
    float scale = 60.0;
    
    
    
    
    // An array to hold the 16 frequency bands
    float level[16];
    
    
    
    
    // This array holds the on-screen levels.  When the signal drops quickly,
    // these are used to lower the on-screen level 1 bar per update, which
    // looks more pleasing to corresponds to human sound perception.
    int   shown[16];
    
    
    
    
    
    
    
    
    
    
    
    
    // Use the LiquidCrystal library to display the spectrum
    //
    LiquidCrystal lcd(0, 1, 2, 3, 4, 5);
    byte bar1[8] = {0,0,0,0,0,0,0,255};
    byte bar2[8] = {0,0,0,0,0,0,255,255};        // 8 bar graph
    byte bar3[8] = {0,0,0,0,0,255,255,255};      // custom
    byte bar4[8] = {0,0,0,0,255,255,255,255};    // characters
    byte bar5[8] = {0,0,0,255,255,255,255,255};
    byte bar6[8] = {0,0,255,255,255,255,255,255};
    byte bar7[8] = {0,255,255,255,255,255,255,255};
    byte bar8[8] = {255,255,255,255,255,255,255,255};
    
    
    
    /*
    void pinkOFF(){
    
     
    
      pink2.amplitude(0.00);
      Serial.println("Pink off initialized");
     
    }
    
    */
    
    
    
    
    
    
    
    void setup() {
    
    
    
    
     
      Serial.begin(115200);
      while(!Serial);
      sgtl5000_1.enable();
      sgtl5000_1.volume(0.5);
      //AudioMemory(4);
      AudioProcessorUsageMaxReset();
      AudioMemoryUsageMaxReset();
    
    
    
    
     
     
      // Audio memory allocation
      AudioMemory(95);
    
    
    
    
      // Enable the audio shield and set the output volume.
      sgtl5000_1.enable();
      sgtl5000_1.inputSelect(myInput);
      sgtl5000_1.volume(0.5);
    
    
    
    
      // turn on the LCD and define the custom characters
      lcd.begin(16, 2);
      lcd.print("Audio Spectrum");
      lcd.createChar(0, bar1);
      lcd.createChar(1, bar2);
      lcd.createChar(2, bar3);
      lcd.createChar(3, bar4);
      lcd.createChar(4, bar5);
      lcd.createChar(5, bar6);
      lcd.createChar(6, bar7);
      lcd.createChar(7, bar8);
    
    
    /*
    
      // configure the mixer to equally add left & right
      mixer1.gain(0, 0.5);
      mixer1.gain(1, 0.5);
    
    */
      // Compensation gain for additive gain from filters
      // Reduce signal on Left and right channels by -9dB
      mixer1.gain(0, powf(10.0f, -9 / 20.0f)); // any # between 0 and 1 instead of powf(10.0f, -9 / 20.0f)
      mixer1.gain(1, powf(10.0f, -9 / 20.0f)); 
      mixer2.gain(0,  powf(10.0f, -9 / 20.0f) );
      mixer2.gain(1,  powf(10.0f, -9 / 20.0f));
    
    
      // pin 21 will select rapid vs animated display
      pinMode(21, INPUT_PULLUP);
    
     
          // Butterworth filter, 12 db/octave
      biquad1.setBandpass(0, 43, 0.716667);
      biquad2.setBandpass(0, 43, 0.716667);
      biquad3.setBandpass(0, 108, 2.5116);
      biquad4.setBandpass(0, 108, 2.5116);
      biquad5.setBandpass(0, 215, 2.5);
      biquad6.setBandpass(0, 215, 2.5);
      biquad7.setBandpass(0, 365, 2.829);
      biquad8.setBandpass(0, 365, 2.829);
      biquad9.setBandpass(0, 559, 3.25);
      biquad10.setBandpass(0, 559, 3.25);
      biquad11.setBandpass(0, 817, 3.16667);
      biquad12.setBandpass(0, 817, 3.16667);
      biquad13.setBandpass(0, 1182, 3.05);
      biquad14.setBandpass(0, 1182, 3.05);
      biquad15.setBandpass(0, 1699, 3);
      biquad16.setBandpass(0, 1699, 3);
      biquad17.setBandpass(0, 2430, 2.974);
      biquad18.setBandpass(0, 2430, 2.974);
      biquad19.setBandpass(0, 3440, 3.08);
      biquad20.setBandpass(0, 3440, 3.08);
      biquad21.setBandpass(0, 4838, 3);
      biquad22.setBandpass(0, 4838, 3);
      biquad23.setBandpass(0, 6816, 3);
      biquad24.setBandpass(0, 6816, 3);
      biquad25.setBandpass(0, 9546, 3.08);
      biquad26.setBandpass(0, 9546, 3.08);
      biquad27.setBandpass(0, 13309, 3.06);
      biquad28.setBandpass(0, 13309, 3.06);
      biquad29.setBandpass(0, 18770, 2.89);
      biquad30.setBandpass(0, 18770, 2.89);
    
     
    }
    
    
    
    
    
    
    
    
    elapsedMillis fps;
    uint8_t cnt=0;
    
    
    
    void loop() {
    float max1[20] = {0};
    float max2[20] = {0};
    delay[2500];
    elapsedMillis pinkOFF;
    while (pinkOFF < 15000){
    pink2.amplitude(0.25);
    if(fps > 24) {
         
        if (peak_L.available() && peak_R.available() && rms_L.available() && rms_R.available()) {
          fps=0;
          uint8_t leftPeak = peak_L.read() * 30.0;
          uint8_t rightPeak = peak_R.read() * 30.0;
          float leftRMS = rms_L.read() * 30.0;
          float rightRMS = rms_R.read() * 30.0;
    
    
    
    
          for (cnt=0; cnt < 30-leftPeak; cnt++) {
            Serial.print(" ");
          }
          while (cnt++ < 29 && cnt < 30-leftRMS) {
            Serial.print("<");
          }
          while (cnt++ < 30) {
            Serial.print("=");
          }
         
          Serial.print("||");
         
          for(cnt=0; cnt < rightRMS; cnt++) {
            Serial.print("=");
          }
          for(; cnt < rightPeak; cnt++) {
           Serial.print(">");
          }
          while(cnt++ < 30) {
           Serial.print(" ");
          }
          Serial.print("   ");
          Serial.print(leftRMS / 30);
         Serial.print("||");
          Serial.print(rightRMS / 30);
          Serial.print("   ");
        
          Serial.print(AudioProcessorUsage());
          Serial.print("/");
          Serial.print(AudioProcessorUsageMax());
          Serial.println();
        }
    
       
        }
       
     
      }
    
    
    // Stop the Pink noise
           pink2.amplitude(0.00);
           delay(5000);
         
    
    
    
     
    // First Analysis
    delay[2500];
     tonesweep1.play(1.0, 10, 22050, 30);
      while(tonesweep1.isPlaying()){
    
    
    
    
      //pink2.amplitude(0.5);
       //while(pink2.amplitude(0.5)){
     
    
    
    if (fps >24){
     
     
      if (fft1024_1.available()) {
        // read the 512 FFT frequencies into 16 levels
        // music is heard in octaves, but the FFT data
        // is linear, so for the higher octaves, read
        // many FFT bins together.
        level[0] =  fft1024_1.read(0);
        level[1] =  fft1024_1.read(1);
        level[2] =  fft1024_1.read(2, 3);
        level[3] =  fft1024_1.read(4, 6);
        level[4] =  fft1024_1.read(7, 10);
        level[5] =  fft1024_1.read(11, 15);
        level[6] =  fft1024_1.read(16, 22);
        level[7] =  fft1024_1.read(23, 32);
        level[8] =  fft1024_1.read(33, 46);
        level[9] =  fft1024_1.read(47, 66);
        level[10] = fft1024_1.read(67, 93);
        level[11] = fft1024_1.read(94, 131);
        level[12] = fft1024_1.read(132, 184);
        level[13] = fft1024_1.read(185, 257);
        level[14] = fft1024_1.read(258, 359);
        level[15] = fft1024_1.read(360, 511);
        // See this conversation to change this to more or less than 16 log-scaled bands?
        // https://forum.pjrc.com/threads/32677-Is-there-a-logarithmic-function-for-FFT-bin-selection-for-any-given-of-bands
    
    
    
    
        // if you have the volume pot soldered to your audio shield
        // uncomment this line to make it adjust the full scale signal
        //scale = 8.0 + analogRead(A1) / 5.0;
    
    
    
    
        // begin drawing at the first character on the 2nd row
        lcd.setCursor(0, 1);
     
        for (int i=0; i<16; i++) {
          Serial.print(level[i]);
    if ( max1[i] < level[i])
    {
      max1[i] = level[i];
    }
    
    
    
    
          // TODO: conversion from FFT data to display bars should be
          // exponentially scaled.  But how keep it a simple example?
          int val = level[i] * scale;
          if (val > 8) val = 8;
    
    
    
    
          if (val >= shown[i]) {
            shown[i] = val;
          } else {
            if (shown[i] > 0) shown[i] = shown[i] - 1;
            val = shown[i];
          }
    
    
    
    
          //Serial.print(shown[i]);
          Serial.print(" ");
    
    
    
    
          // print each custom digit
          if (shown[i] == 0) {
            lcd.write(' ');
          } else {
            lcd.write(shown[i] - 1);
          }
        }
     if (peak_L.available() && peak_R.available() && rms_L.available() && rms_R.available()) {
          fps=0;
          uint8_t leftPeak = peak_L1.read() * 30.0;
          uint8_t rightPeak = peak_R1.read() * 30.0;
          float leftRMS = rms_L1.read() * 30.0;
          float rightRMS = rms_R1.read() * 30.0;
    
    
    
    
          for (cnt=0; cnt < 30-leftPeak; cnt++) {
            Serial.print(" ");
          }
          while (cnt++ < 29 && cnt < 30-leftRMS) {
            Serial.print("<");
          }
          while (cnt++ < 30) {
            Serial.print("=");
          }
         
          Serial.print("||");
         
          for(cnt=0; cnt < rightRMS; cnt++) {
            Serial.print("=");
          }
          for(; cnt < rightPeak; cnt++) {
           Serial.print(">");
          }
          while(cnt++ < 30) {
           Serial.print(" ");
          }
          Serial.print("   ");
          Serial.print(leftRMS / 30);
         Serial.print("||");
          Serial.print(leftRMS / 30);
          Serial.print("   ");
        
          Serial.print(AudioProcessorUsage());
          Serial.print("/");
          Serial.print(AudioProcessorUsageMax());
          Serial.println();
        }
    
    
       
        Serial.print(" cpu:");
        Serial.println(AudioProcessorUsageMax());
     
    // This is the end of the max audio
      }}
    
    
    
    
      }
      Serial.println("Your Maximum Value:");
      for (int j=0;j<16;j++)
      {
        Serial.print(max1[j]);
        Serial.print("  ");
      }
      delay(5000);
    Serial.println("");
    
    
    // Second Part starts Here
    delay[2500];
    
    
    
    //////////////////////////  Sweep 2  ////////////////////////////////
    ////////////////////////////////////////////////////////////////////
     tonesweep2.play(0.25, 10, 22050, 30);
      while(tonesweep2.isPlaying()){
    
    
    
    
    if (fps >24){
     
     
      if (fft1024_2.available()) {
        // read the 512 FFT frequencies into 16 levels
        // music is heard in octaves, but the FFT data
        // is linear, so for the higher octaves, read
        // many FFT bins together.
        level[0] =  fft1024_2.read(0);
        level[1] =  fft1024_2.read(1);
        level[2] =  fft1024_2.read(2, 3);
        level[3] =  fft1024_2.read(4, 6);
        level[4] =  fft1024_2.read(7, 10);
        level[5] =  fft1024_2.read(11, 15);
        level[6] =  fft1024_2.read(16, 22);
        level[7] =  fft1024_2.read(23, 32);
        level[8] =  fft1024_2.read(33, 46);
        level[9] =  fft1024_2.read(47, 66);
        level[10] = fft1024_2.read(67, 93);
        level[11] = fft1024_2.read(94, 131);
        level[12] = fft1024_2.read(132, 184);
        level[13] = fft1024_2.read(185, 257);
        level[14] = fft1024_2.read(258, 359);
        level[15] = fft1024_2.read(360, 511);
        // See this conversation to change this to more or less than 16 log-scaled bands?
        // https://forum.pjrc.com/threads/32677-Is-there-a-logarithmic-function-for-FFT-bin-selection-for-any-given-of-bands
    
    
    
    
        // if you have the volume pot soldered to your audio shield
        // uncomment this line to make it adjust the full scale signal
        //scale = 8.0 + analogRead(A1) / 5.0;
    
    
    
    
        // begin drawing at the first character on the 2nd row
        lcd.setCursor(0, 1);
     
        for (int i=0; i<16; i++) {
          Serial.print(level[i]);
    if ( max2[i] < level[i])
    {
      max2[i] = level[i];
    }
    
    
    
    
          // TODO: conversion from FFT data to display bars should be
          // exponentially scaled.  But how keep it a simple example?
          int val = level[i] * scale;
          if (val > 8) val = 8;
    
    
    
    
          if (val >= shown[i]) {
            shown[i] = val;
          } else {
            if (shown[i] > 0) shown[i] = shown[i] - 1;
            val = shown[i];
          }
    
    
    
    
          //Serial.print(shown[i]);
          Serial.print(" ");
    
    
    
    
          // print each custom digit
          if (shown[i] == 0) {
            lcd.write(' ');
          } else {
            lcd.write(shown[i] - 1);
          }
        }
     if (peak_L.available() && peak_R.available() && rms_L.available() && rms_R.available()) {
          fps=0;
          uint8_t leftPeak = peak_L.read() * 30.0;
          uint8_t rightPeak = peak_R.read() * 30.0;
          float leftRMS = rms_L.read() * 30.0;
          float rightRMS = rms_R.read() * 30.0;
    
    
    
    
          for (cnt=0; cnt < 30-leftPeak; cnt++) {
            Serial.print(" ");
          }
          while (cnt++ < 29 && cnt < 30-leftRMS) {
            Serial.print("<");
          }
          while (cnt++ < 30) {
            Serial.print("=");
          }
         
          Serial.print("||");
         
          for(cnt=0; cnt < rightRMS; cnt++) {
            Serial.print("=");
          }
          for(; cnt < rightPeak; cnt++) {
           Serial.print(">");
          }
          while(cnt++ < 30) {
           Serial.print(" ");
          }
          Serial.print("   ");
          Serial.print(leftRMS / 30);
         Serial.print("||");
          Serial.print(rightRMS / 30);
          Serial.print("   ");
        
          Serial.print(AudioProcessorUsage());
          Serial.print("/");
          Serial.print(AudioProcessorUsageMax());
          Serial.println();
        }
    
    
       
        Serial.print(" cpu:");
        Serial.println(AudioProcessorUsageMax());
     
    // This is the end of the max audio
      }}
    
    
    
    
      }
      Serial.println("Your Maximum Value:");
      for (int j=0;j<16;j++)
      {
        Serial.print(max2[j]);
        Serial.print("  ");
      }
      delay(5000);
    Serial.println("");
    
    
    
    /*
    // Filter 1 Gain
    mixer5.gain(0,  filter1gain_L );
    mixer6.gain(0,  filter1gain_R );
    
    
    // Filter 2 Gain
    mixer5.gain(1,  filter2gain_L );
    mixer6.gain(1,  filter2gain_R );
    
    
    // Filter 3 Gain
    mixer5.gain(2,  filter3gain_L );
    mixer6.gain(2,  filter3gain_R );
    
    
    // Filter 4 Gain
    mixer5.gain(3,  filter4gain_L );
    mixer6.gain(3,  filter4gain_R );
    
    
    // Filter 5 Gain
    mixer7.gain(0,  filter5gain_L );
    mixer8.gain(0,  filter5gain_R );
    
    
    // Filter 6 Gain
    mixer7.gain(1,  filter6gain_L );
    mixer8.gain(1,  filter6gain_R );
    
    
    // Filter 7 Gain
    mixer7.gain(2,  filter7gain_L );
    mixer8.gain(2,  filter7gain_R );
    
    
    // Filter 8 Gain
    mixer7.gain(3,  filter8gain_L );
    mixer8.gain(3,  filter8gain_R );
    
    
    // Filter 9 Gain
    mixer9.gain(0,  filter9gain_L );
    mixer10.gain(0,  filter9gain_R );
    
    
    // Filter 10 Gain
    mixer9.gain(1,  filter10gain_L );
    mixer10.gain(1,  filter10gain_R );
    
    
    // Filter 11 Gain
    mixer9.gain(2,  filter11gain_L );
    mixer10.gain(2,  filter11gain_R );
    
    
    // Filter 12 Gain
    mixer9.gain(3,  filter12gain_L );
    mixer10.gain(3,  filter12gain_R );
    
    
    // Filter 13 Gain
    mixer11.gain(0,  filter13gain_L );
    mixer12.gain(0,  filter13gain_R );
    
    
    // Filter 14 Gain
    mixer11.gain(1,  filter14gain_L );
    mixer12.gain(1,  filter14gain_R );
    
    
    // Filter 15 Gain
    mixer11.gain(2,  filter15gain_L );
    mixer12.gain(2,  filter15gain_R );
    */
    
    
    
    
    /////////////////////////////// Sweep 3  /////////////////////////////////////
    /////////////////////////////////////////////////////////////////////////////
     tonesweep3.play(0.25, 10, 22050, 30);
      while(tonesweep3.isPlaying()){
    
    
     
      if (fft1024_2.available()) {
        // read the 512 FFT frequencies into 16 levels
        // music is heard in octaves, but the FFT data
        // is linear, so for the higher octaves, read
        // many FFT bins together.
        level[0] =  fft1024_2.read(0);
        level[1] =  fft1024_2.read(1);
        level[2] =  fft1024_2.read(2, 3);
        level[3] =  fft1024_2.read(4, 6);
        level[4] =  fft1024_2.read(7, 10);
        level[5] =  fft1024_2.read(11, 15);
        level[6] =  fft1024_2.read(16, 22);
        level[7] =  fft1024_2.read(23, 32);
        level[8] =  fft1024_2.read(33, 46);
        level[9] =  fft1024_2.read(47, 66);
        level[10] = fft1024_2.read(67, 93);
        level[11] = fft1024_2.read(94, 131);
        level[12] = fft1024_2.read(132, 184);
        level[13] = fft1024_2.read(185, 257);
        level[14] = fft1024_2.read(258, 359);
        level[15] = fft1024_2.read(360, 511);
        // See this conversation to change this to more or less than 16 log-scaled bands?
        // https://forum.pjrc.com/threads/32677-Is-there-a-logarithmic-function-for-FFT-bin-selection-for-any-given-of-bands
    
    
    
    
        // if you have the volume pot soldered to your audio shield
        // uncomment this line to make it adjust the full scale signal
        //scale = 8.0 + analogRead(A1) / 5.0;
    
    
    
    
        // begin drawing at the first character on the 2nd row
        lcd.setCursor(0, 1);
     
        for (int i=0; i<16; i++) {
          Serial.print(level[i]);
    if ( max2[i] < level[i])
    {
      max2[i] = level[i];
    }
    
    
    
    
          // TODO: conversion from FFT data to display bars should be
          // exponentially scaled.  But how keep it a simple example?
          int val = level[i] * scale;
          if (val > 8) val = 8;
    
    
    
    
          if (val >= shown[i]) {
            shown[i] = val;
          } else {
            if (shown[i] > 0) shown[i] = shown[i] - 1;
            val = shown[i];
          }
    
    
    
    
          //Serial.print(shown[i]);
          Serial.print(" ");
    
    
    
    
          // print each custom digit
          if (shown[i] == 0) {
            lcd.write(' ');
          } else {
            lcd.write(shown[i] - 1);
          }
        }
     if (peak_L.available() && peak_R.available() && rms_L.available() && rms_R.available()) {
          fps=0;
          uint8_t leftPeak = peak_L.read() * 30.0;
          uint8_t rightPeak = peak_R.read() * 30.0;
          float leftRMS = rms_L.read() * 30.0;
          float rightRMS = rms_R.read() * 30.0;
    
    
    
    
          for (cnt=0; cnt < 30-leftPeak; cnt++) {
            Serial.print(" ");
          }
          while (cnt++ < 29 && cnt < 30-leftRMS) {
            Serial.print("<");
          }
          while (cnt++ < 30) {
            Serial.print("=");
          }
         
          Serial.print("||");
         
          for(cnt=0; cnt < rightRMS; cnt++) {
            Serial.print("=");
          }
          for(; cnt < rightPeak; cnt++) {
           Serial.print(">");
          }
          while(cnt++ < 30) {
           Serial.print(" ");
          }
          Serial.print("   ");
          Serial.print(leftRMS / 30);
         Serial.print("||");
          Serial.print(rightRMS / 30);
          Serial.print("   ");
        
          Serial.print(AudioProcessorUsage());
          Serial.print("/");
          Serial.print(AudioProcessorUsageMax());
          Serial.println();
        }
    
    
       
        Serial.print(" cpu:");
        Serial.println(AudioProcessorUsageMax());
     
    // This is the end of the max audio
      }}
    
    
    
    
      //}
      Serial.println("Your Maximum Value:");
      for (int j=0;j<16;j++)
      {
        Serial.print(max2[j]);
        Serial.print("  ");
      }
      delay(5000);
    Serial.println("");
    
    
    }

  2. #2
    Senior Member DD4WH's Avatar
    Join Date
    Oct 2015
    Location
    Central Europe
    Posts
    696
    Hi Steven,

    sounds like a nice project! I have not been able to exactly spot your audio connections ;-).

    But you are running simultaneously two really big FFTs with 1024 points each and about 50 biquads. I think, the processor usage of a Teensy 3.2 is more than 100% with that. So I suspect the cause of your distorted audio is processor "overload".

    You use only 16 bands, but you calculate 511 bands with your FFT, so that´s a waste of processing power. Try using one FFT with 256points and test whether the Teensy works with one 256point FFT and all the biquads and produces nice audio.

    Also try first a version with audio-only. All these Serial.prints could also slow down your Teensy considerably.

    Good luck!

    Frank

  3. #3
    Senior Member
    Join Date
    Jul 2014
    Posts
    3,459
    Quote Originally Posted by steven32bits View Post
    I am working on a project to measure the acoustics of a room by playing a test tone through a speaker and analyzing FFT from the input of a mic. I want to generate correction filters using the biquad filters. Well I designed a complicated circuit in the GUI that will help me run the analysis as intended in order to prove that it is working as intended. I am using a Teensy 3.2 with a single audio shield attached. The speaker and mic are connected I2s line in and out ports on the shield.
    Would the complexity be reduced, if you were to transmit short pulses to obtain the room impulse function? By setting the pulse rep-rate such that longest reverb is coming back you could avoid aliasing effects (reverb delay foldings), which IMO could be an issue with spectral analysis. You may need FrankB's memory board to store the time series.

  4. #4
    Quote Originally Posted by WMXZ View Post
    You may need FrankB's memory board to store the time series.
    Just barely looking into Franks memory board, I would have to ask again, is it worth just upgrading to Teensy 3.6 with the audio adapter to handle the DSP I want it to?

    Frank, I tried changing the FFT to 256 and I still had distortion issues. I believe you have convinced me I have pushed the envelope with Teensy 3.2. What do you think I should do to remedy the situation, upgrade to FrankB's memory board or the Teensy 3.6 controller?

    Thanks for your advise,

    Steven

  5. #5
    Senior Member DD4WH's Avatar
    Join Date
    Oct 2015
    Location
    Central Europe
    Posts
    696
    Steven,
    I would start from a very basic version and build it up to the more complex version. Also investigate the following:

    - add a serial printout of the memory and processor usages, so you can monitor whether your Teensy 3.2 is at its limits
    - check your gain calculations (mixing int with float etc. could be a problem, maybe just insert gain value 0.35 for a trial)
    - check your bandpass filters (how did you derive the Q values? Maybe I am wrong, but shouldn´t Q always be the same, if you need butterworth response?)
    - for frequencies under 400Hz, be careful with biquads, because they could perform poorly (use other filters instead)

    Good luck!

    P.S.: Only AFTER you have checked all those issues, I would recommend to start thinking about using other hardware.
    P.P.S.: Edit: By the way: you could also possibly run into trouble, because you use more than one audio INPUT! Try using i2s_In exclusively.
    Last edited by DD4WH; 11-16-2016 at 10:35 AM.

  6. #6
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    26,806
    Yeah, 50 biquads and two FFTs might be more than Teensy 3.2 can handle. Definitely use the max CPU usage functions to make sure you're not pushing close to 100%.

    Eventually, we probably need to add a hires biquad object with 64 bit coefficients and internal state....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •