Forum Rule: Always post complete source code & details to reproduce any issue!
Page 2 of 2 FirstFirst 1 2
Results 26 to 38 of 38

Thread: Latency and Jitter values for Teensy 3.2 DAC and for the Audio Board's i2s

  1. #26
    I have fixed it hardcoding (hammering my head against the code)
    in the play method of the AudioPlayMemory class I added a simple "length *= 2;" line

    Code:
    void AudioPlayMemory::play(const unsigned int *data)
    {
    	uint32_t format;
    
    	playing = 0;
    	prior = 0;
    	format = *data++;
    	next = data;
    	beginning = data;
    	length = format & 0xFFFFFF;
    	length *= 2;
    	playing = format >> 24;
    }
    I don't know anything about pointers, and I didn't understand what I did, but I believe that if I add a generic line "length *= 128/AUDIO_BLOCK_SAMPLES;"
    would that be it?

    It worked for 64 samples and 32.
    But not with 16 samples... It just gave an annoying 2781 Hz + harmonics beep...
    but 32 is already good enough for me!
    Last edited by joaotragtenberg; 12-07-2016 at 08:43 PM.

  2. #27
    Nice Paul,
    didn't see your fast reply!
    it worked perfectly, thank you!
    much more elegant than my crappy solution.

  3. #28
    It works with an audio block as low as 32 samples.
    It gives an annoying beep with the audio block on 16 samples. It only starts after pressing the button that plays the sample

  4. #29
    And just for the record, the error message on the analyze_fft256 class persists...

    Code:
    /.../Arduino.app/Contents/Java/hardware/teensy/avr/libraries/Audio/analyze_fft256.cpp:33:13: warning: 'void copy_to_fft_buffer(void*, const void*)' defined but not used [-Wunused-function]
     static void copy_to_fft_buffer(void *destination, const void *source)
                 ^
    /.../Arduino.app/Contents/Java/hardware/teensy/avr/libraries/Audio/analyze_fft256.cpp:43:13: warning: 'void apply_window_to_fft_buffer(void*, const void*)' defined but not used [-Wunused-function]
     static void apply_window_to_fft_buffer(void *buffer, const void *window)
                 ^

  5. #30
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,679
    Quote Originally Posted by joaotragtenberg View Post
    It works with an audio block as low as 32 samples.
    It gives an annoying beep with the audio block on 16 samples. It only starts after pressing the button that plays the sample
    Hm, yes, that's possible - perhaps another change in the memcpy - routines for less than 32 samples is needed.
    I can look on sunday, not earlier (sorry).

  6. #31
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,556
    I've added a comment in the code, which hopefully will help guide people who wish to edit the block size.

    https://github.com/PaulStoffregen/co...83efb9cf65b11d

  7. #32
    Quote Originally Posted by duff View Post
    Can you post the exact program you used to measure this? Are you sure the square wave object starts with high signal? I don't know but I'm willing to try to reproduce this also if i had a program to test?
    Duff, I made another system for measuring latency on teensy! Now instead of having to use a logic analyser you can just use another teensy!

    Here are the codes (I'm using teensyduino 1.31 now):

    Teensy with audio board (I'm using 3.2)
    Code:
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    
    // GUItool: begin automatically generated code
    AudioSynthWaveformDc     dc1;            //xy=226,198
    AudioOutputI2S           i2s1;           //xy=616,194
    AudioConnection          patchCord3(dc1, 0, i2s1, 0);
    AudioConnection          patchCord4(dc1, 0, i2s1, 1);
    AudioControlSGTL5000     sgtl5000_1;     //xy=77,24
    // GUItool: end automatically generated code
    
    int button0 = 0;
    int button0Pin = 2;
    
    void setup() {
      pinMode(button0Pin, INPUT);
      AudioMemory(10);
      sgtl5000_1.enable();
      sgtl5000_1.volume(1);
    }
    
    void loop() {
      button0 = digitalRead(button0Pin);
      if (button0 == HIGH) {
        dc1.amplitude(1);
        delay(66);
        dc1.amplitude(-1);
      }
    }
    And here is the code to put in the other Teensy (I'm with another 3.2), I'm calling it the measurer
    Code:
    #define OUT_PIN 13
    #define IN_PIN_SOUND 12
    #define IN_PIN_BUTTON 11
    
    void setup() {
      Serial.begin(115200);
    
      pinMode(OUT_PIN, OUTPUT);
      pinMode(IN_PIN_SOUND, INPUT);
      pinMode(IN_PIN_BUTTON, INPUT);
    
      attachInterrupt(IN_PIN_BUTTON, isrServiceButton, RISING);
      attachInterrupt(IN_PIN_SOUND, isrServiceSound, RISING);
    }
    
    elapsedMillis blinkTime;
    
    unsigned long outputTriggerTime = 0;
    unsigned long latencyTime = 0;
    unsigned int randomDelay;
    
    
    
    void loop() {
        if (blinkTime < 100) {
          digitalWrite(OUT_PIN, HIGH);
        } else if (blinkTime < 200) {
          digitalWrite(OUT_PIN, LOW);
        } else {
          blinkTime = 0; // start blink cycle over again
        }
    }
    
    void isrServiceButton()
    {
      cli();
      outputTriggerTime = micros();
      sei();
    }
    
    void isrServiceSound()
    {
      cli();
      latencyTime = micros() - outputTriggerTime;
      Serial.println(latencyTime);
      sei();
    }
    you just connect GND's and 3v3's of both teensies
    pin11 and pin13 of the measurer to pin2 of the teensy with the audio board
    pin 12 of the measurer to the L or R pin of the headphone pin (those tiny holes)

    you just check the serial data that is coming in from the measurer. 1000 values is good enough but it actually stabilizes around 7000 values... You just copy and paste them in excel, matlab or wherever you want to analyse it...

  8. #33
    Quote Originally Posted by PaulStoffregen View Post
    I've added a comment in the code, which hopefully will help guide people who wish to edit the block size.

    https://github.com/PaulStoffregen/co...83efb9cf65b11d
    Great Paul!
    Thank you!

  9. #34
    Quote Originally Posted by Frank B View Post
    Hm, yes, that's possible - perhaps another change in the memcpy - routines for less than 32 samples is needed.
    I can look on sunday, not earlier (sorry).
    Nice, thank you!

  10. #35
    Senior Member duff's Avatar
    Join Date
    Jan 2013
    Location
    Las Vegas
    Posts
    969
    Quote Originally Posted by joaotragtenberg View Post
    Duff, I made another system for measuring latency on teensy! Now instead of having to use a logic analyser you can just use another teensy!
    .
    Ok thanks, i'll check it out I have a scope so I'll use that.

  11. #36
    Quote Originally Posted by duff View Post
    Ok thanks, i'll check it out I have a scope so I'll use that.
    This version doesn't need any scope and is almost effortless...

  12. #37
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,679
    Quote Originally Posted by joaotragtenberg View Post
    Nice, thank you!
    Smaller blocksizes are working now - i don't have a scope, but it sounds okay for me.

  13. #38
    Quote Originally Posted by Frank B View Post
    Smaller blocksizes are working now - i don't have a scope, but it sounds okay for me.
    Yes Frank!
    Its amazing. Thank you so much for your collective effort!

Posting Permissions

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