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

Thread: T4 Audio questions (balance with mixers, filters, combine..)

  1. #1
    Junior Member
    Join Date
    Feb 2020
    Posts
    11

    T4 Audio questions (balance with mixers, filters, combine..)

    1) I used two mixers to make an audio "balance" for headphone use (first time in 30 years I have been able to listen to stereo in both sides (bad tinnitus and consequential hearing loss in right ear)).
    Question is: is this the best way? I am only using one channel in each of the two mixers. when balance is centred, the values are both 0.5, full either way is 0.0 to 1.0. It seems a bit (sort of) wasteful, somehow.

    2) I used combine to pull the inputs together for fft (partly for interest at the moment). However, I cannot see what the syntax structure is for combine parameters. Can someone point me at a good example?

    3) I think I want to use filters to try to remove unwanted jangly music from tv broadcasts (if possible) so I can hear the commentary better.
    Is there a laymans guide anywhere for a dumb programmer to read up audio and electronics? I can bluff my way through the c used in Arduino, my background is mainly in various high level languages apart from some ancient assembler code!!

    4) The (old now) audio tutorial mentions (on page 25) the use of bins. It says only the first 30 are important, promises to explain later. I can't find the explanation.... I found that there seemed some useful data in the first 50 in the fft analysis.
    Am I imagining this? Is my code daft? Did I miss the explanation somewhere?

    p.s. I have put together a box with an adafruit MPR121 for 12 capacitive touch buttons (using 3mm bolts as contacts in a circle on lid) (working, but not used yet), and three pots (volume, balance and a spare)

    Click image for larger version. 

Name:	Screenshot_2020-03-12_14-35-47.png 
Views:	11 
Size:	32.4 KB 
ID:	19351

    Code:
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include "Adafruit_MPR121.h"
    
    
    // GUItool: begin automatically generated code
    AudioInputI2S            i2s1;           //xy=79,223
    AudioMixer4              mixer1;         //xy=367,143
    AudioMixer4              mixer2;         //xy=367,270
    AudioEffectDigitalCombine combine1;       //xy=373,387
    AudioAnalyzeFFT1024      fft1024_1;      //xy=627,388
    AudioOutputI2S           i2s2;           //xy=917,149
    AudioConnection          patchCord1(i2s1, 0, mixer1, 0);
    AudioConnection          patchCord2(i2s1, 0, combine1, 0);
    AudioConnection          patchCord3(i2s1, 1, mixer2, 0);
    AudioConnection          patchCord4(i2s1, 1, combine1, 1);
    AudioConnection          patchCord5(mixer1, 0, i2s2, 0);
    AudioConnection          patchCord6(mixer2, 0, i2s2, 1);
    AudioConnection          patchCord7(combine1, fft1024_1);
    AudioControlSGTL5000     sgtl5000_1;     //xy=730,491
    // GUItool: end automatically generated code
    
    Adafruit_MPR121 cap = Adafruit_MPR121();
    static int vol = 0;
    static int bal = 511;
    
    void setup() {
      Serial.begin(115200);
      cap.begin(0x5A);
      AudioMemory(100);
    
      sgtl5000_1.enable();
      sgtl5000_1.volume(0.2);
    
      // Butterworth filter, 12 db/octave
      //  biquad1.setLowpass(0, 800, 0.707);
    
      // Linkwitz-Riley filter, 48 dB/octave
      //biquad1.setLowpass(0, 800, 0.54);
      //biquad1.setLowpass(1, 800, 1.3);
      //biquad1.setLowpass(2, 800, 0.54);
      //biquad1.setLowpass(3, 800, 1.3);
    
      fft1024_1.windowFunction(AudioWindowHanning1024);
    
      mixer1.gain(0, 0.5);
      mixer1.gain(1, 0.0);
      mixer1.gain(2, 0.0);
      mixer1.gain(3, 0.0);
    
      mixer2.gain(0, 0.5);
      mixer2.gain(1, 0.0);
      mixer2.gain(2, 0.0);
      mixer2.gain(3, 0.0);
    
    /*
      mixer3.gain(0, 0.5);
      mixer3.gain(1, 0.5);
      mixer2.gain(2, 0.0);
      mixer2.gain(3, 0.0);
    */
      sgtl5000_1.inputSelect(AUDIO_INPUT_LINEIN);
      //  sgtl5000_1.inputSelect(AUDIO_INPUT_MIC);
      //  sgtl5000_1.micGain(63);
      //  sgtl5000_1.lineInLevel(7,7);
      delay(1000);
    }
    
    void loop() {
      float n;
      int i;
      float gain1;
      float gain2;
    
    // get volume from knob1
      int knob1 = analogRead(A1);
      if ((knob1 < vol-9)||(knob1 > vol+9)) {     // allow for a bit of wobble
        vol = knob1;
        //    Serial.print("vol = ");
        //    Serial.println(vol);
        sgtl5000_1.volume(knob1 / 1023.0); //note decimal point on the float constant
      }
    
    // get balance from knob0
      int knob0 = analogRead(A0);
      if ((knob0 < bal-9)||(knob0 > bal+9)) {     // allow for a bit of wobble
        bal = knob0;
    //        Serial.print("bal = ");
    //        Serial.println(bal);
        gain1 = bal / 1023.0;
    //        Serial.print("gain1 = ");
    //        Serial.print(gain1);
    //        Serial.print("   ");
        gain2 = (1023 - bal) / 1023.0;   //note decimal point on the float constant
    //        Serial.print("gain2 = ");
    //        Serial.println(gain2);
        mixer1.gain(0, gain2);         //left right swapped....
        mixer2.gain(0, gain1);
      }
    
      if (fft1024_1.available()) {
    //    Serial.print("FFT: ");
        for (i = 0; i < 52; i=i+4) {
          n = fft1024_1.read(i);
    //      printNum(n * 1024);
    //      Serial.print(" ");
        }
    //    Serial.println();
      }
    
      if (cap.touched() & (1 << 0)) {
    
      }
    
      if (cap.touched() & (1 << 1)) {
    
      }
    
      if (cap.touched() & (1 << 2)) {
    
      }
    
      if (cap.touched() & (1 << 3)) {
    
      }
    
      if (cap.touched() & (1 << 4)) {
    
      }
    
      if (cap.touched() & (1 << 5)) {
    
      }
    
      if (cap.touched() & (1 << 6)) {
    
      }
    
      if (cap.touched() & (1 << 7)) {
    
      }
    
      if (cap.touched() & (1 << 8)) {
    
      }
    
      if (cap.touched() & (1 << 9)) {
    
      }
    
      if (cap.touched() & (1 << 10)) {
    
      }
    
      if (cap.touched() & (1 << 11)) {
    
      }
    }
    
    void printNum(float n) {
      if (n >= 0.004) {
        Serial.print(n, 2);
        Serial.print(" ");
      } else {
        Serial.print("  "); // don't print "0.00"
      }
    }
    Click image for larger version. 

Name:	IMG_0063s.JPG 
Views:	10 
Size:	141.7 KB 
ID:	19352

  2. #2
    Member houtson's Avatar
    Join Date
    Aug 2015
    Location
    Scotland
    Posts
    53
    Hi

    1) The mixers are fine, you can use two amp objects instead of mixers if you want, it will look neater but it will not really make any difference to performance

    2) Combine does a binary combine (rather than what you'd expect for a normal audio signal combination) - it is good for making weird effects. I'm not really sure what you are doing with the FFT but I think you may be better using a mixer to combine left and right. If you really want to do a binary combination then use something like :
    Code:
      combine1.setCombineMode(AudioEffectDigitalCombine::OR);
    to set the combination mode ( or AudioEffectDigitalCombine::XOR or AudioEffectDigitalCombine::AND or AudioEffectDigitalCombine::MODULO)

    3) I'd use a filters for each channel, something like
    Code:
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    
    // GUItool: begin automatically generated code
    AudioInputI2S            i2s1;           //xy=164,271
    AudioEffectDigitalCombine combine1;       //xy=458,435
    AudioAmplifier           amp2;           //xy=529,320
    AudioAmplifier           amp1;           //xy=532,196
    AudioAnalyzeFFT1024      fft1024_1;      //xy=712,436
    AudioFilterStateVariable filter1;        //xy=724,196
    AudioFilterStateVariable filter2;        //xy=730,322
    AudioOutputI2S           i2s2;           //xy=960,260
    AudioConnection          patchCord1(i2s1, 0, combine1, 0);
    AudioConnection          patchCord2(i2s1, 0, amp1, 0);
    AudioConnection          patchCord3(i2s1, 1, combine1, 1);
    AudioConnection          patchCord4(i2s1, 1, amp2, 0);
    AudioConnection          patchCord5(combine1, fft1024_1);
    AudioConnection          patchCord6(amp2, 0, filter2, 0);
    AudioConnection          patchCord7(amp1, 0, filter1, 0);
    AudioConnection          patchCord8(filter1, 0, i2s2, 0);
    AudioConnection          patchCord9(filter2, 0, i2s2, 1);
    AudioControlSGTL5000     sgtl5000_1;     //xy=815,539
    // GUItool: end automatically generated code

    4) not sure what you're trying to do with the FFT

    cheers, Paul

  3. #3
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,578
    If it is just for the fft, you don't need to "combine" (i think the name is misleading you - you want to convert to "mono"-right?).
    You can use a mixer instead (left+right to channel 0+1) or just use only left, since the channels are normally very similar.

  4. #4
    Junior Member
    Join Date
    Feb 2020
    Posts
    11

    Thanks

    Thanks for those replies - lots to think about.

    I am really still just playing with the possibilities, especially with the fft....I spent a while admiring the output to the Arduino plotter, while listening to music (T4 can easily generate enough data to keep my Linux core I5 warm).

    Every time I look at the forum I see another project I want to try!!
    I believe my current box will possibly be playing guitar notes soon ( re: this https://github.com/PaulStoffregen/TouchGuitar )

    I may have to get some more hardware .....

Posting Permissions

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