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

Thread: strong noises while adding patchcords to fft256 objects

  1. #1

    strong noises while adding patchcords to fft256 objects

    Hi,
    I've got some strange noises while adding patchcord\AudioConnection to fft256 module..
    if I remove this patchcords the noise disappear.
    I have recorded the sound with and without the patchcords please :
    https://drive.google.com/open?id=0B9...TkzTWJ4RUlLWHM
    Any idea what is wrong?
    This is my code :
    Code:
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    //#include <SD.h>
    #include <SerialFlash.h>
    // 1 Left
    // 2 Right
    // 3 Center
    
    AudioInputI2SQuad        i2s_quad2;    
    AudioOutputI2SQuad       i2s_quad1;      
    AudioAnalyzeFFT256      fft256_1;      
    AudioAnalyzeFFT256      fft256_3;      
    AudioAnalyzeFFT256      fft256_2;      
    AudioMixer4              mixer2; 
    AudioMixer4              mixer1;       
    
    AudioOutputUSB           usb1;          
    AudioConnection          patchCord1(i2s_quad2, 1, fft256_1, 0);    <----------
    AudioConnection          patchCord2(i2s_quad2, 1, mixer1, 1);
    AudioConnection          patchCord3(i2s_quad2, 1, mixer2, 1);
    AudioConnection          patchCord4(i2s_quad2, 2, fft256_2, 0);    <----------
    AudioConnection          patchCord5(i2s_quad2, 2, mixer1, 2);
    AudioConnection          patchCord6(i2s_quad2, 2, mixer2, 2);
    AudioConnection          patchCord7(i2s_quad2, 3, fft256_3, 0);    <----------
    AudioConnection          patchCord8(i2s_quad2, 3, mixer1, 3);
    AudioConnection          patchCord9(i2s_quad2, 3, mixer2, 3);
    AudioConnection          patchCord11(mixer1, 0, usb1, 1);
    AudioConnection          patchCord12(mixer2, 0, usb1, 0);
    AudioControlSGTL5000     sgtl5000_1;     //xy=173.03053283691406,88.90054130554199
    AudioControlSGTL5000     sgtl5000_2;     //xy=183.1610044313146,142.78680452978827
    
    const int myInput = AUDIO_INPUT_LINEIN;
    //const int myInput = AUDIO_INPUT_MIC;
    String val;
    
    void setup() {
      // Audio connections require memory to work.  For more
      // detailed information, see the MemoryAndCpuUsage example
      AudioMemory(12);
    
      // Enable the first audio shield, select input, and enable output
      sgtl5000_1.setAddress(LOW);
      sgtl5000_1.enable();
      sgtl5000_1.inputSelect(myInput);
      sgtl5000_1.lineInLevel(15);
      sgtl5000_1.volume(1);
    
      // Enable the second audio shield, select input, and enable output
      sgtl5000_2.setAddress(HIGH);
      sgtl5000_2.enable();
      sgtl5000_2.inputSelect(myInput);
      sgtl5000_2.lineInLevel(15);
      sgtl5000_2.volume(1);
    
      sgtl5000_1.adcHighPassFilterDisable();
      sgtl5000_2.adcHighPassFilterDisable();
    
      fft256_1.windowFunction(AudioWindowHanning256);
      fft256_2.windowFunction(AudioWindowHanning256);
      fft256_3.windowFunction(AudioWindowHanning256);
    //  filter1.frequency(100);
    //  filter1.resonance(0.707);
    //  mixer1 LEFT
      mixer1.gain(1, 0);
      mixer1.gain(2, 0);
      mixer1.gain(3, 0);
    //  mixer2 RIGHT
      mixer2.gain(1, 0);
      mixer2.gain(2, 0);
      mixer2.gain(3, 0);
    //  mixer2.gain(3, 0.5);
      Serial.begin(9600);
      Serial.flush();
      establishContact();
    }
    void establishContact() {
      while (Serial.available() <= 0) {
      Serial.println("A");   // send a capital A
      delay(300);
      }
    }
    //bool one=false;
    void loop() {
    //  Serial.flush(); //flush all previous received and transmitted data
      if(Serial.available() > 0){
        val = Serial.readStringUntil('\n');
        String sensCode = val.substring(0,3);
        if(sensCode == "L1:"){
          String l1= val.substring(3,7);
          mixer1.gain(1, l1.toFloat());
        } else if(sensCode == "L2:"){
          String l1= val.substring(3,7);
          mixer1.gain(2, l1.toFloat());
        } else if(sensCode == "L3:"){
          String l1= val.substring(3,7);
          mixer1.gain(3, l1.toFloat());
        } else if(sensCode == "R1:"){
          String l1= val.substring(3,7);
          mixer2.gain(1, l1.toFloat());
        } else if(sensCode == "R2:"){
          String l1= val.substring(3,7);
          mixer2.gain(2, l1.toFloat());
        } else if(sensCode == "R3:"){
          String l1= val.substring(3,7);
          mixer2.gain(3, l1.toFloat());
        }
      }
      else {
        int n;
        int i;
        if (fft256_1.available()) {
          // each time new FFT data is available
          // print it all to the Arduino Serial Monitor
          Serial.print("FFT1: ");
          for (i=0; i<128; i++) {
            n = fft256_1.output[i];
              Serial.print(n);
              Serial.print(",");
              delay(2);
            }
          Serial.println();
          delay(2);
        }
        if (fft256_2.available()) {
          // each time new FFT data is available
          // print it all to the Arduino Serial Monitor
          Serial.print("FFT2: ");
          for (i=0; i<128; i++) {
            n = fft256_2.output[i];
              Serial.print(n);
              Serial.print(",");
              delay(2);
            }
          Serial.println();
          delay(2);
        }
        if (fft256_3.available()) {
          // each time new FFT data is available
          // print it all to the Arduino Serial Monitor
          Serial.print("FFT3: ");
          for (i=0; i<128; i++) {
            n = fft256_3.output[i];
              Serial.print(n);
              Serial.print(",");
              delay(2);
            }
          Serial.println();
          delay(2);
        }    
      }
    }


    Thanks in advance..

  2. #2
    I think you are short on audio memory.
    You are allocating 12 blocks (AudioMemory(12)) for 11 objects.
    Progressively add more memory compile and try until there is no noise. Then add a few more blocks to be safe.

  3. #3
    Quote Originally Posted by Stendall View Post
    I think you are short on audio memory.
    You are allocating 12 blocks (AudioMemory(12)) for 11 objects.
    Progressively add more memory compile and try until there is no noise. Then add a few more blocks to be safe.

    Thanks a lot!
    changing to 13 solved the problem~~!!

  4. #4
    You welcome.
    Just remember that no all audio objects use the same amount of audio blocks (AudioMemory).

  5. #5
    I will pay attention from now on.

    one more question..
    Once in a few minutes I've got "buffering noises" for a few seconds, and if I reset the ASIO4ALL everything back to normal...
    I tried playing with the buffer size and this affects the latency..more than 512 cause more latency, less than 512 cause higher frequent buffering noises..
    Do you have any idea how can I solve it?

    Thanks again

  6. #6
    There is a physical law you cannot escape.
    If the latency of the teensy+audio adapter+usb host+PC usb drivers it's for instance 10ms, you cannot configure in ASIO a buffer value that it's less than the overall delay for that audio interface.
    Paul said in other threads that teensy audio library has a delay of ~5ms.
    But you have to add more delays to that number,

    If the audio rate it's 44100 for a buffer of 512 (mono) have space to 11.6 milliseconds of audio.
    So you cannot have in all audio chain accumulative delay of less that number of milliseconds or you will lose audio data.
    The only way to overcome this it's use another audio adapter, another usbhost hardware, another OS or another drivers.
    Every one of them have impact on the total delay, but there's no one alone that will give you for instance 10ms less of delay. Because the overall delay you have now it's already small. Not the best but small.
    You can for instance use a professional sound DAC like Focusrite cards. But even the cheapest will cost you more money than 3 teensys+audio-adapter.
    So it's up to you. If you are not gonna make professional stuff teensy it's really great for the money. And have a lot of capabilities that you will not find in professional sound hardware.

  7. #7
    @Stendall
    thanks for such detailed explanation.
    I understand that I cannot escape from system natural latency
    but If I understood right, 512 buffer should be enough to avoid lagging, but it still got those lags\buffering noises once in a few minutes..
    any idea what could result this?
    maybe there is another solution than the ASIO4ALL?

  8. #8
    Sorry alonper, I don't know what it's the real number of total delay. Because among other things depends on your hardware (PC USB host chipset, OS, drivers, USB ubs you use... and so on).
    In fact it's much faster get the number by trial and error than trying to calculate the whole chain delay.
    Just increase progressively the buffer value. Play and record until there's no buffering issues and then increase the buffer just a bit more. Let's say 32 more.
    Even professional audio latencies depend on not just high end audio hardware but also on OS. Drivers, etc...

    ASIO4ALL it's great. But does not reduce latency on audio hardware driver (teensy in this case).
    Professional audio cards use ASIO not only because it have much less latency than Windows audio service, but also because they develop audio drivers for his hardware specifically for ASIO.
    With ASIO4ALL you have just one part of two.
    You will need someone develop a low latency audio driver ASIO compatible with the teensy/USB audio.
    I have a friend that uses VST Protools and have one Focusrite Scarlet 2i2. That low latency USB professional audio card don't have the same latency with his ASIO driver than with ASIO4ALL.

    You can improve a lot some things (and I'm a hard core tuner/tweaker), but at a given point there's no more room for improvement and the only way it's switch tools.

Posting Permissions

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