using AEC code with Audio shild and teensy3.2

barry

New member
Hello there,
I´m new heir! and have not many experience with teensy and Audio shield , could some Body tell me how can I use AEC code with Audio shield , so my Project is: i will make an Audio System for Intercom communication and it must be work in Full duplex mode, my Audio Amp has 1 Watt but i´m not sure that the AEC Algorithm can work correctly!
 
Hello, could you please see my code, i want use two Audio Adapter with one Teensy4.0, in Photo can you see my GUI,
the Sound Quallity is very bad!! Tkans in advance.
GUI Setting.PNG
Code:
// 10_8_22_ver2
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
//*****functions**********
void getBuffer1();
void getBuffer2();
void playData_mic();
void playData_LS();

// GUItool: begin automatically generated code
AudioInputI2S            i2s_mic_in;           
AudioInputI2S2           i2s2_Ls_in;         
AudioRecordQueue         Mic_queue_Record;         
AudioRecordQueue         Ls_queue_Record;         
AudioPlayQueue           Mic_queue_Play;        
AudioPlayQueue           Ls_queue_Play;         
AudioOutputI2S           i2s2_HP;           
AudioOutputI2S2          i2s2_2_HP;         
AudioConnection          patchCord1(i2s_mic_in, 0, Mic_queue_Record, 0);
AudioConnection          patchCord2(i2s2_Ls_in, 0, Ls_queue_Record, 0);
AudioConnection          patchCord3(Mic_queue_Play, 0, i2s2_HP, 0);
AudioConnection          patchCord4(Mic_queue_Play, 0, i2s2_HP, 1);
AudioConnection          patchCord5(Ls_queue_Play, 0, i2s2_2_HP, 0);
AudioConnection          patchCord6(Ls_queue_Play, 0, i2s2_2_HP, 1);
AudioControlSGTL5000     sgtl5000_2;     
AudioControlSGTL5000     sgtl5000_1;     
// GUItool: end automatically generated code

const int numBlocks = 4;              //min block 
const int nummBlocks = 4;             //min block 
int16_t *pAddr;                       //pointer to 128 block of getBuffer
int16_t *pAddrs;                      //pointer to 128 block of getBuffer
int16_t lblock = numBlocks*128;       //length of arrays
int16_t lblock_0 = nummBlocks*128;    //length of arrays
int16_t ablock[128*numBlocks];        // set an array block
int16_t bblock[128*nummBlocks];       // set an array block
int16_t *pablock;                     // pointer to an array block
int16_t *pbblock;                     // pointer to an array block
int16_t *pp;                          // pointer to getBuffer
int16_t *pp1;                         // pointer to getBuffer1
int n;
unsigned long time1;                  // time variable
//***************define input/source************************
const int mic_Input = AUDIO_INPUT_MIC;
const int LS_Input = AUDIO_INPUT_LINEIN;

void setup() 
{
  AudioMemory(64); 
  memset(ablock,100,128*numBlocks*2);
  memset(bblock,100,128*nummBlocks*2);
 
  //Enable the first audio shield1, select input, and enable output
  sgtl5000_1.setAddress(LOW);
  sgtl5000_1.enable();
  sgtl5000_1.inputSelect(mic_Input);
  sgtl5000_1.micGain(36); // mic gain
  sgtl5000_1.volume(0.6);
  //Enable the second audio shield2, select input, and enable output
  sgtl5000_2.setAddress(HIGH);
  sgtl5000_2.enable();
  sgtl5000_2.inputSelect(mic_Input);
  sgtl5000_1.micGain(36); // mic gain
  sgtl5000_2.volume(0.6);
  //set array values to zero
  pablock = ablock; // assign pointer to array
  pbblock = bblock; // assign pointer to array
  delay(1000);
}
//***************************MAIN LOOP********************************************************************
void loop() 
{
  getBuffer1(numBlocks);
  getBuffer2(nummBlocks); 
}
//**************************************************
void getBuffer1(int x) 
{
  int l = 0;
  Mic_queue_Record.begin(); 
  memcpy((byte*)pablock,(byte*)pablock+256,256*(x-1));
  while(l == 0)
  { 
      if(Mic_queue_Record.available() >=1)  
      {     
        memcpy((byte*)pablock+(256*(x-1)),Mic_queue_Record.readBuffer(),256);
        Mic_queue_Record.freeBuffer(); 
        l = 1; 
      }
  }
  playData_mic(pablock,0); 
  Mic_queue_Record.clear(); 
  Mic_queue_Record.end();
}
//**************************************************
void getBuffer2(int x) 
{
  int l = 0;
  Ls_queue_Record.begin(); 
  memcpy((byte*)pbblock,(byte*)pbblock+256,256*(x-1));
  while(l == 0)// wait until block samples are available
  { 
      if(Ls_queue_Record.available() >=1) 
      {     
        memcpy((byte*)pbblock+(256*(x-1)),Ls_queue_Record.readBuffer(),256);
        Ls_queue_Record.freeBuffer(); 
        l = 1; 
      }
  }
  playData_Ls(pbblock,0); 
  Ls_queue_Record.clear(); 
  Ls_queue_Record.end();
}
//************************************************
// play data to speaker1
void playData_mic(int16_t *data, int i)
{
    pAddr = Mic_queue_Play.getBuffer(); 
    memcpy((byte*)pAddr,(byte*)data+(256*i),256);
    Mic_queue_Play.playBuffer();
}
//************************************************
// play data to speaker2
void playData_Ls(int16_t *data, int i)
{
    pAddrs = Ls_queue_Play.getBuffer(); 
    memcpy((byte*)pAddrs,(byte*)data+(256*i),256);
    Ls_queue_Play.playBuffer();
}
 
Last edited:
Back
Top