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

Thread: i2s and DAC/ADC audio + external FX

  1. #1

    i2s and DAC/ADC audio + external FX

    Just I got audio board and try send by i2s, signal from mic to DAC (DAC use like SEND output) for external FX and go back with signal from FX to
    ADC AudioInputAnalog (like RETURN FX) and mixing signals together and send by i2s to line out or headphone. Simple but not working

    if I use i2s to i2s hardware test sketch, all working nice but if connecting ADC/DAC then is no signal on line out audio board. I tried couple wiring method and still no success.
    Click image for larger version. 

Name:	IMG_4125.jpg 
Views:	15 
Size:	154.7 KB 
ID:	15216

    Is possible run ADC DAC and i2s IN/OUT in the same time?

    Code:
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    
    // GUItool: begin automatically generated code
    AudioInputI2S            i2s1;           //xy=306.25000762939453,423.75000381469727
    AudioInputAnalog         adc1;           //xy=307.5000343322754,473.75000762939453
    AudioOutputAnalog        dac1;           //xy=453.75000762939453,255.00000762939453
    AudioMixer4              mixer1;         //xy=473.75000762939453,441.2500057220459
    AudioOutputI2S           i2s2;           //xy=638.7500114440918,416.25000381469727
    AudioConnection          patchCord1(i2s1, 0, mixer1, 0);
    AudioConnection          patchCord2(i2s1, 0, dac1, 0);
    AudioConnection          patchCord3(adc1, 0, mixer1, 1);
    AudioConnection          patchCord4(mixer1, 0, i2s2, 0);
    AudioConnection          patchCord5(mixer1, 0, i2s2, 1);
    AudioControlSGTL5000     sgtl5000_1;     //xy=474.50000762939453,375.0000057220459
    // GUItool: end automatically generated code

  2. #2
    Senior Member
    Join Date
    Jul 2014
    Posts
    1,938
    can you proved also minimal setup() and loop() that demonstrates the problem?

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    18,669
    Quote Originally Posted by Diodac View Post
    Is possible run ADC DAC and i2s IN/OUT in the same time?
    Yes, all 4 of these are able to work simultaneously.

    However, no use of analogRead() is possible if using the ADC input in the audio library. This is the most common misunderstanding.

    Not using enough AudioMemory() for the added features is also a common problem, or crafting a program and forgetting to copy AudioMemory() from the examples has been a common mistake.

    If not those issues, something else must be wrong. But without seeing the whole program, no way to help you.

  4. #4
    Quote Originally Posted by PaulStoffregen View Post
    Yes, all 4 of these are able to work simultaneously.
    I use it like that:
    Line In R - input signal from amplified mic or audio.
    Line Out R,L to send audio to external FX
    Line In L is for return from FX
    Headphone - main stereo output.

    Code:
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    
    // GUItool: begin automatically generated code
    AudioInputI2S              i2s1;  
    AudioOutputI2S             i2s2;           
    AudioMixer4                mixer1;         
    //AudioInputAnalog           adc1(A2);
    AudioOutputAnalog          dac1;  
    
    AudioConnection            patchCord1(i2s1, 0, i2s2, 0);
    AudioConnection            patchCord2(i2s1, 1, dac1, 0);
    AudioConnection            patchCord3(i2s1, 1, mixer1, 1);
    AudioConnection            patchCord4(mixer1, 0, i2s2, 1);
    //AudioConnection            patchCord5(adc1, 0, mixer1, 0);
    AudioControlSGTL5000       sgtl5000_1;    
    // GUItool: end automatically generated code
    
    const int RETURN = A2;
    const int SEND = A14;
    
    elapsedMillis msec = 0;
    int in_gain = 0;
    float vol = 0.0;
    
    void setup() {
      AudioMemory(20);
      pinMode(A1, INPUT);
      pinMode(A2, INPUT);
      pinMode(A3, INPUT);
      pinMode(A14,OUTPUT);
      dac1.analogReference(EXTERNAL);
      sgtl5000_1.enable();
      //sgtl5000_1.inputSelect(AUDIO_INPUT_MIC);
      sgtl5000_1.inputSelect(AUDIO_INPUT_LINEIN);
      sgtl5000_1.volume(1.0);
      mixer1.gain(0, 0.7);
      mixer1.gain(1, 0.7);
    }
    
    void mic_in() {
      if (msec > 30) {
      in_gain = constrain(map(analogRead(A3), 0, 1023, 0, 15),0,15);
        //sgtl5000_1.micGain(in_gain);
        sgtl5000_1.lineInLevel(in_gain);
        vol = analogRead(A1);
        sgtl5000_1.dacVolume(vol / 1023.0);
            msec = 0;
      }
    }
    
    void loop() {
      mic_in();
    
    }
    Working fine, but I prefer use SGTL5000 mic input + AudioAnalogInput adc1(A2) for return from FX and mix it to main output and headphone .
    I want use line out for main output and headphone for monitor.

    When I use SGTL mic input then I cannot use line In L or R for return FX
    When I add AudioAnalogInput then I have no sound anymore.

  5. #5
    And If possible line in for another external signal input. But how to do working simultaneously SGTL mic, line input from audio board + AudioAnalogInput and mix it to dac, line output and headphones.. for now I donít have idea. I need deeper digging. Just I got audio board and second day I have fun with it.

  6. #6
    I digging all night and all day in data sheets and so on and found that SGTL5000 is a piece of nice device. Lots possibilities and easy implementation. This is what I looking for. Iím impressed.
    Now I will try get simultaneous input line and mic and mixing it to headphones and line out.

  7. #7
    There is no chance using simultaneous mic in and line in on single SGTL, for that I need use 2 audio boards, or what already I have done with external amplified mic and return fx connected to the R,L line in. It is pretty good solution but circuit becomes more complex, I need build up really good substitute preamp interface for mic.
    Ehhh that one original from SGTL is perfect working for my project, I have little hope using an ADC for fx return. I tried it, but I have problems using simultaneous AudioInputAnalog on A2,3,6,7 and audio board not working together :-/
    Paul can you tell me please, how I can overcome this?
    Maybe I should use just a classic way, analogRead to get audio return fx and use queue to I2s? or something like that. I not checked it so far.

  8. #8
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    18,669
    AudioInputAnalog only supports 1 signal. It doesn't support using multiple instances of AudioInputAnalog.

    So if you have many signals you want to get into the audio library, your options are limited.

    You can have 4 line-level inputs by using 2 audio shields with the quad I2S. Sparkfun wrote a nice tutorial. Or you could use one shield for 2 line level input and the other shield for the mic input. The SGTL5000 chip can do either mono mic or stereo line in, not both. But if you have 2 SGTL5000, you could configure one of them for stereo line in and the other for mono mic.

    You can have only 1 more lower quality input using an ADC pin with AudioInputAnalog.

    If you need even more inputs, currently the only other supported option is TDM. Theoretically TDM can give 16 inputs. Currently the only well supported TDM hardware is the CS42448 chip.

    https://forum.pjrc.com/threads/41371...l=1#post138705

    This chip gives 6 inputs, and has a secondary I2S port that allows another chip to give 2 more. I have not used the extra 2, so you should consider than option untested... but if you *really* need more than 6 plus 1 on an ADC pin, that expansion on the CS42448 is probably the more viable path.

  9. #9
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    4,765
    I can confirm, the CS42448 is working good!
    I you don't need all signals *in* the audiolibrary/teensy, you can think of external analog switches - there are chips that can be controlled with a pin from the teensy, with a simple digitalWrite.

    https://oshpark.com/shared_projects/2Yj6rFaW
    Last edited by Frank B; 11-26-2018 at 10:14 PM.

  10. #10
    Quote Originally Posted by PaulStoffregen View Post
    AudioInputAnalog only supports 1 signal. It doesn't support using multiple instances of AudioInputAnalog.
    Paul I know that, maximum 2 mono signals if use adcs.


    You can have 4 line-level inputs by using 2 audio shields with the quad I2S. Sparkfun wrote a nice tutorial. Or you could use one shield for 2 line level input and the other shield for the mic input. The SGTL5000 chip can do either mono mic or stereo line in, not both. But if you have 2 SGTL5000, you could configure one of them for stereo line in and the other for mono mic.
    That is nice to use 2 audio shields, I readed Sparkfun's tutorial.

    But.. I was thinking, if SGTL has own build in an ADC and use it for processing then I be able use another mono or stereo Teensy ADC and I tried this;
    Click image for larger version. 

Name:	testaudio.png 
Views:	4 
Size:	29.2 KB 
ID:	15242
    And working! until I not use any other ADC in any way. I need to know, why is like that

    Sine>>DAC >---wirring by ---||---10uF and feeding ---ADC1
    MIC IN audio board by i2s
    Mixing to i2s OUT

    AND I got simultaneously ADC1 and working MIC from audio board, even if I use stereo adcs object also working! I got stereo + mic from audio board, that is 3 signal simultaneously and I get also these signals on headphones and line out.
    For me ideal, I don't want more inputs and quality is enough. But is one problem in this solution... if I want use more analog inputs, for control function SGTL or frequency of sine object or any other knob, I cannot because ADC1 stop working, even DAC1 too. Any control knobs also stop..
    I can only use MIC IN but without knob control volume.

    If someone want try, code is here and working until uncomment lines for control.

    Code:
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    
    // GUItool: begin automatically generated code
    AudioInputI2S            i2s2;           //xy=140,64
    AudioInputAnalog         adc1(A2);           //xy=141,30
    AudioSynthWaveformSine   sine1;          //xy=278,143
    AudioMixer4              mixer1;         //xy=347,49
    AudioOutputAnalog        dac1;           //xy=407,143
    AudioOutputI2S           i2s1;           //xy=537,47
    AudioConnection          patchCord1(i2s2, 0, mixer1, 1);
    AudioConnection          patchCord2(i2s2, 1, mixer1, 2);
    AudioConnection          patchCord3(adc1, 0, mixer1, 0);
    AudioConnection          patchCord4(sine1, dac1);
    AudioConnection          patchCord5(mixer1, 0, i2s1, 0);
    AudioConnection          patchCord6(mixer1, 0, i2s1, 1);
    AudioControlSGTL5000     sgtl5000_1;     //xy=343,103
    // GUItool: end automatically generated code
    
    void setup() {
      Serial.begin(9600);
      AudioMemory(40);
      dac1.analogReference(EXTERNAL);
      
      sgtl5000_1.enable();
      sgtl5000_1.volume(0.5);
      sgtl5000_1.micGain(5);
      sgtl5000_1.inputSelect(AUDIO_INPUT_MIC);
      
      mixer1.gain(0, 0.4);
      mixer1.gain(1, 0.4);
      mixer1.gain(2, 0.4);
      
    }
    
    elapsedMillis msc = 0;
    int in_gain = 0;
    float vol = 0.0;
    
    void loop() {
      
    /*
     if (msc > 30) {
        in_gain = map(analogRead(A3),0,1023,0,64);
        sgtl5000_1.micGain(in_gain);
        sgtl5000_1.lineInLevel(in_gain);
        vol = analogRead(A1);
        sgtl5000_1.dacVolume(vol / 1023.0);
        msc = 0;
      }
     */
     
     int f = 0;
     //f = analogRead(A6)<<2;
     sine1.amplitude(0.5);
     sine1.frequency(80.000+f);
     }

  11. #11
    Even if I passed stereo by line in on audio board and passed another stereo by ADCs object, I got 4 signals simultaneously on headphones and line out until I added any control functions :/

  12. #12
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    4,765
    Knobs do not need to be analog. Digital encoders are even better, often.

  13. #13
    Yeah, I will use encoder with menu for setting couple of things but in my project I will use also 3 soft pots and octo board too for leds. Pretty hard coding I need to do. But teensy audio stuff is little bit new to me, before I doing just midi project and sometimes led. I need digging deeper for doing things better. And still I not figure why my code not working after adding another ordinary analog input.

Posting Permissions

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