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

Thread: Issue Subtracting Left Line-In from Right Line-in on Audio Shield to Noise Cancel

Threaded View

  1. #1
    Junior Member
    Join Date
    Jan 2020

    Issue Subtracting Left Line-In from Right Line-in on Audio Shield to Noise Cancel

    Hey All,

    I am been searching the forums and did not see this issue discussed relating to my project. Maybe I missed it, but your help would be appreciated.

    My project is to remove ambient noise from a mic input, so that the output is *nearly* voice only. I have two mics, one that is for my voice and one is for background noise. I am using a custom preamp board to bring the sound into Line-in Left and Right on the Audio Shield from the mics. I have a Teensy 4.0 performing the math to subtract the ambient noise mic (Line-in Left) from the voice mic (Line-in Right) and my output is through the headphone jack on the Audio Shield. See block diagram below for set up. Also picture below for actual board setup. Code is also below.

    My issue:
    I cannot seem to get Line-in Left (background noise) to subtract from Line-in Right (voice + background noise) to produce my voice only output.

    What I have verified:
    1. I verified receiving sound through both mics independently to my headphones using Audio Shield and Teensy.
    2. I verified reducing output to zero volume (verified by rms1) via subtraction if: (1) I use just one channel (e.g. ch0 of i2s1) as the source to both inputs to Mixer 1 (0 and 1).

    #2 tells me that what I am trying to do is possible. So that is encouraging.

    What I am having trouble with:
    1. See above - Pass
    2. See above - Pass
    3. Using the same sound through both mics to reduce output to zero volume via subtraction - Fail
    4. Using one mic for voice + background sound and the other for background sound to output voice only via subtraction
    5. Testing outside in real world

    I would appreciate any direction or help in this manner to solve issue #3. I will do the homework to figure this out, just need to know where to look.


    Block diagram
    Click image for larger version. 

Name:	BackgroundNoiseRemovalSetup.jpg 
Views:	9 
Size:	50.7 KB 
ID:	18854

    Actual board setup
    Click image for larger version. 

Name:	actualsetup2.jpg 
Views:	10 
Size:	71.8 KB 
ID:	18855

    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    // GUItool: begin automatically generated code
    AudioInputI2S            i2s1;           
    AudioAmplifier           amp1;           
    AudioMixer4              mixer1;         
    AudioOutputI2S           i2s2;
    AudioAnalyzeRMS          rms1;
    AudioAnalyzePeak         peak1;
    AudioConnection          patchCord1(i2s1, 0, amp1, 0);
    //AudioConnection          patchCord2(i2s1, 0, mixer1, 1);   //same Channel, test cancelation
    AudioConnection          patchCord2(i2s1, 1, mixer1, 1); //Two channels
    AudioConnection          patchCord3(amp1, 0, mixer1, 0);
    AudioConnection          patchCord4(mixer1, 0, i2s2, 0);
    AudioConnection          patchCord5(mixer1, 0, i2s2, 1);
    AudioConnection          patchCord6(mixer1, rms1);
    AudioConnection          patchCord7(mixer1, peak1);
    AudioControlSGTL5000     sgtl5000_1; 
    // GUItool: end automatically generated code
    void setup() {
      // Audio connections require memory to work.  For more
      // detailed information, see the MemoryAndCpuUsage example
      // Enable the audio shield, select input, and enable output
      //Amplify channel 0
      //Mixer setting
      mixer1.gain(0, 0.5);
      mixer1.gain(1, 0.5);
    elapsedMillis volmsec=0;
    String amp_text;
    float amp_value;
    float rms_amp;
    float peak_amp;
    void loop() {
      // Adjust amp of background noise coming in
      // Keyboard input for amp value
      // Run every 50 msecs
      if (volmsec > 50) 
        if (Serial.available())
            amp_text = Serial.readStringUntil('\n');
            Serial.print(amp_text + " ");
            amp_value = amp_text.toFloat();
        // Result - verify cancelation of sound
        rms_amp = * 30.0;
        Serial.print(" ");
        peak_amp = * 30.0;
        volmsec = 0;
    Last edited by enphoti; 01-24-2020 at 08:23 PM. Reason: Clarification

Posting Permissions

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