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

Thread: Equalizer using Tympan Audio Library

  1. #1
    Junior Member
    Join Date
    Jun 2022
    Posts
    4

    Equalizer using Tympan Audio Library

    Hello,

    I'm currently trying to use some Tympan audio library functions on a Teensy 4.1 + Audio Shield to create an 8-band equalizer. I've gone through the src of the Tympan library and to the best of my ability checked which functions didn't rely on the Tympan's AIC. I'm currently using some filterbanks, mixer8s, and a ton of gain objects along with I16 to F32 and vice versa conversion.

    It compiles fine and there don't seem to be any errors thrown to the serial monitor, but there is no output, just silence. I confirmed my actual Teensy setup works, so it's something with the sketch.

    Can anyone with some experience with this library take a look? Thanks!

    Code:
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    #include <Tympan_Library.h>
    
    //Constants
    const int myInput = AUDIO_INPUT_LINEIN;
    const float samplerate = 44100.0f ;  
    const int num_blocks = 128;
    
    //Objects
    AudioSettings_F32             audio_settings(samplerate, num_blocks);
    AudioControlSGTL5000          sgtl5000_1;  
    AudioInputI2S                 i2s_in;
    AudioConvert_I16toF32         convertIN_L;
    AudioConvert_I16toF32         convertIN_R;
    AudioConvert_F32toI16         convertOUT_L;
    AudioConvert_F32toI16         convertOUT_R;
    AudioFilterbankBiquad_F32     filterbank_L(audio_settings);
    AudioFilterbankBiquad_F32     filterbank_R(audio_settings);
    AudioEffectGain_F32           gain_L_0;
    AudioEffectGain_F32           gain_L_1;
    AudioEffectGain_F32           gain_L_2;
    AudioEffectGain_F32           gain_L_3;
    AudioEffectGain_F32           gain_L_4;
    AudioEffectGain_F32           gain_L_5;
    AudioEffectGain_F32           gain_L_6;
    AudioEffectGain_F32           gain_L_7;
    AudioEffectGain_F32           gain_R_0;
    AudioEffectGain_F32           gain_R_1;
    AudioEffectGain_F32           gain_R_2;
    AudioEffectGain_F32           gain_R_3;
    AudioEffectGain_F32           gain_R_4;
    AudioEffectGain_F32           gain_R_5;
    AudioEffectGain_F32           gain_R_6;
    AudioEffectGain_F32           gain_R_7;
    AudioMixer8_F32               mixer_L(audio_settings);
    AudioMixer8_F32               mixer_R(audio_settings);
    AudioEffectGain_F32           gainFINAL_L;
    AudioEffectGain_F32           gainFINAL_R;
    AudioOutputI2S                i2s_out;
    
    //Wire Time
    AudioConnection           patchCord1(i2s_in, 0, convertIN_L, 0);
    AudioConnection           patchCord2(i2s_in, 1, convertIN_R, 0);
    
    AudioConnection_F32       patchCord3(convertIN_L, 0, filterbank_L, 0);
    AudioConnection_F32       patchCord4(convertIN_R, 0, filterbank_R, 0);
    
    AudioConnection_F32       patchCord11(filterbank_L, 0, gain_L_0, 0);
    AudioConnection_F32       patchCord12(filterbank_L, 1, gain_L_1, 0);
    AudioConnection_F32       patchCord13(filterbank_L, 2, gain_L_2, 0);
    AudioConnection_F32       patchCord14(filterbank_L, 3, gain_L_3, 0);
    AudioConnection_F32       patchCord15(filterbank_L, 4, gain_L_4, 0);
    AudioConnection_F32       patchCord16(filterbank_L, 5, gain_L_5, 0);
    AudioConnection_F32       patchCord17(filterbank_L, 6, gain_L_6, 0);
    AudioConnection_F32       patchCord18(filterbank_L, 7, gain_L_7, 0);
    
    AudioConnection_F32       patchCord21(filterbank_R, 0, gain_R_0, 0);
    AudioConnection_F32       patchCord22(filterbank_R, 1, gain_R_1, 0);
    AudioConnection_F32       patchCord23(filterbank_R, 2, gain_R_2, 0);
    AudioConnection_F32       patchCord24(filterbank_R, 3, gain_R_3, 0);
    AudioConnection_F32       patchCord25(filterbank_R, 4, gain_R_4, 0);
    AudioConnection_F32       patchCord26(filterbank_R, 5, gain_R_5, 0);
    AudioConnection_F32       patchCord27(filterbank_R, 6, gain_R_6, 0);
    AudioConnection_F32       patchCord28(filterbank_R, 7, gain_R_7, 0);
    
    AudioConnection_F32       patchCord31(gain_L_0, 0, mixer_L, 0);
    AudioConnection_F32       patchCord32(gain_L_1, 0, mixer_L, 1);
    AudioConnection_F32       patchCord33(gain_L_2, 0, mixer_L, 2);
    AudioConnection_F32       patchCord34(gain_L_3, 0, mixer_L, 3);
    AudioConnection_F32       patchCord35(gain_L_4, 0, mixer_L, 4);
    AudioConnection_F32       patchCord36(gain_L_5, 0, mixer_L, 5);
    AudioConnection_F32       patchCord37(gain_L_6, 0, mixer_L, 6);
    AudioConnection_F32       patchCord38(gain_L_7, 0, mixer_L, 7);
    
    AudioConnection_F32       patchCord41(gain_R_0, 0, mixer_R, 0);
    AudioConnection_F32       patchCord42(gain_R_1, 0, mixer_R, 1);
    AudioConnection_F32       patchCord43(gain_R_2, 0, mixer_R, 2);
    AudioConnection_F32       patchCord44(gain_R_3, 0, mixer_R, 3);
    AudioConnection_F32       patchCord45(gain_R_4, 0, mixer_R, 4);
    AudioConnection_F32       patchCord46(gain_R_5, 0, mixer_R, 5);
    AudioConnection_F32       patchCord47(gain_R_6, 0, mixer_R, 6);
    AudioConnection_F32       patchCord48(gain_R_7, 0, mixer_R, 7);
    
    
    AudioConnection_F32       patchCord51(mixer_L, 0, gainFINAL_L, 0);
    AudioConnection_F32       patchCord52(mixer_R, 0, gainFINAL_R, 0);
    
    AudioConnection_F32       patchCord61(gainFINAL_L, 0, convertOUT_L, 0);
    AudioConnection_F32       patchCord62(gainFINAL_R, 1, convertOUT_R, 0);
    
    AudioConnection           patchCord71(convertOUT_L, 0, i2s_out, 0);
    AudioConnection           patchCord72(convertOUT_R, 0, i2s_out, 1);
    
    void setup() {
      // put your setup code here, to run once:
      //AudioMemory(12);
      AudioMemory(12);
    
      sgtl5000_1.enable();
      sgtl5000_1.adcHighPassFilterDisable();
      sgtl5000_1.inputSelect(myInput);
      sgtl5000_1.volume(0.5);
      
      float crossfreq[7]={125.0, 250.0, 500.0, 1000.0, 2000.0, 4000.0, 8000.0}; 
      int test_L = filterbank_L.designFilters(7, 6, samplerate, num_blocks, crossfreq);
      int test_R = filterbank_R.designFilters(7, 6, samplerate, num_blocks, crossfreq);
      
      if (test_L < 0 || test_R < 0){
        Serial.println("It broke :(");
      }
      else{
        Serial.println("It didn't break :)");
      }
    
      gain_L_0.setGain_dB(0.0);
      gain_L_1.setGain_dB(0.0);
      gain_L_2.setGain_dB(0.0);
      gain_L_3.setGain_dB(0.0);
      gain_L_4.setGain_dB(0.0);
      gain_L_5.setGain_dB(0.0);
      gain_L_6.setGain_dB(0.0);
      gain_L_7.setGain_dB(0.0);
      gain_R_0.setGain_dB(0.0);
      gain_R_1.setGain_dB(0.0);
      gain_R_2.setGain_dB(0.0);
      gain_R_3.setGain_dB(0.0);
      gain_R_4.setGain_dB(0.0);
      gain_R_5.setGain_dB(0.0);
      gain_R_6.setGain_dB(0.0);
      gain_R_7.setGain_dB(0.0);
      
      Serial.println("Done!");
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
      // TO DO: Adjustable gains
    }

  2. #2
    Senior Member
    Join Date
    Oct 2015
    Location
    Vermont, USA
    Posts
    318
    Hi!

    For your AudioMemory allacoation, your only creating the regular (Teensy Audio) blocks. You also need to create the F32 audio blocks via AudioMemory_F32. So, you should do something like:

    AudioMemory(12);. //I16 mem blocks
    AudioMemory_F32(32);. //F32 mem blocks

    Without allocating the F32 memory, none of the F32 audio classes will work.

    Chip

Posting Permissions

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