To allow for stereo operation, the TEENSY 4.0 Buffer size must be a minimum of 16 for each channel or a total of 32 so reducing the buffer size to 32 is as far as it goes resulting in a latency of 2 ms.
I found the code that controls latency in the TEENSY Audio Stream. It is in the Audiostream.h file. When I discovered how to reduce audio latency from input to output, I did not consider if the TEENSY was dropping portions of the audio stream, which sounds like clicking or buzzing in the output. Dropout or what is called UNDRRUN is caused by the audio buffer reaching its end before it is refreshed with new samples from the input. By reducing the #define AUDIO_BLOCK_SAMPLES to 32 from its default of 128, the TEENSY was dropping the output stream periodically.
So there is a direct relationship between UNDERRUN and System clock speed.
The default system clock is 600 MHz.
The TEENSY has a feature that allows it to be Overclocked. I increased the system clock frequency to the default 800 MHz resulting in no UNDERRUN dropout of the output stream with the #define AUDIO_BLOCK_SAMPLES size of 32.
I do anticipate the the TEENSY will have UNDERRUN problems when I start programming complex operations.
I was using the PassThroughStereo.ino example to test latency. With AUDIO_BLOCK_SAMPLES set to 128, the latency was about 6.8 milliseconds. I added a delay to adjust the latency to exact millisecond values. Even with zero delay with AUDIO_BLOCK_SAMPLES set to 16 or 32 caused UNDERRUN dropout at 600 MHz System Clock. Overclocking prevented UNDERRUN dropout. My objective is stereo delay of precise durations.
After preliminary testing for UNDERRUN errors, I have determined that there is a direct/indirect relationship between:
1. #define AUDIO_BLOCK_SAMPLES size in the AudioStream.h Library.
2. CPU speed.
3. AudioMemory(XXX); size in the sketch.
4. delay1.delay(0, XXX); size in the sketch
5. the amount or number and complexity of the effects in the sketch
Modified PassThroughStereo.ino with no UNDERRUN errors: AudioMemory(200); delay1.delay(0, 100); (#define AUDIO_BLOCK_SAMPLES 32)(CPU speed 600 MHz)
I found the code that controls latency in the TEENSY Audio Stream. It is in the Audiostream.h file. When I discovered how to reduce audio latency from input to output, I did not consider if the TEENSY was dropping portions of the audio stream, which sounds like clicking or buzzing in the output. Dropout or what is called UNDRRUN is caused by the audio buffer reaching its end before it is refreshed with new samples from the input. By reducing the #define AUDIO_BLOCK_SAMPLES to 32 from its default of 128, the TEENSY was dropping the output stream periodically.
So there is a direct relationship between UNDERRUN and System clock speed.
The default system clock is 600 MHz.
The TEENSY has a feature that allows it to be Overclocked. I increased the system clock frequency to the default 800 MHz resulting in no UNDERRUN dropout of the output stream with the #define AUDIO_BLOCK_SAMPLES size of 32.
I do anticipate the the TEENSY will have UNDERRUN problems when I start programming complex operations.
I was using the PassThroughStereo.ino example to test latency. With AUDIO_BLOCK_SAMPLES set to 128, the latency was about 6.8 milliseconds. I added a delay to adjust the latency to exact millisecond values. Even with zero delay with AUDIO_BLOCK_SAMPLES set to 16 or 32 caused UNDERRUN dropout at 600 MHz System Clock. Overclocking prevented UNDERRUN dropout. My objective is stereo delay of precise durations.
After preliminary testing for UNDERRUN errors, I have determined that there is a direct/indirect relationship between:
1. #define AUDIO_BLOCK_SAMPLES size in the AudioStream.h Library.
2. CPU speed.
3. AudioMemory(XXX); size in the sketch.
4. delay1.delay(0, XXX); size in the sketch
5. the amount or number and complexity of the effects in the sketch
Modified PassThroughStereo.ino with no UNDERRUN errors: AudioMemory(200); delay1.delay(0, 100); (#define AUDIO_BLOCK_SAMPLES 32)(CPU speed 600 MHz)
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SerialFlash.h>
// GUItool: begin automatically generated code
AudioInputI2S i2s1;
AudioEffectDelay delay1;
AudioOutputI2S i2s2;
AudioConnection patchCord1(i2s1, 1, delay1, 0);
AudioConnection patchCord2(delay1, 0, i2s2, 1);
AudioControlSGTL5000 sgtl5000_1;
// GUItool: end automatically generated code
const int myInput = AUDIO_INPUT_LINEIN;
void setup() {
// Audio connections require memory to work. For more
// detailed information, see the MemoryAndCpuUsage example
AudioMemory(200);
// Enable the audio shield, select input, and enable output
sgtl5000_1.enable();
sgtl5000_1.inputSelect(myInput);
sgtl5000_1.volume(0.5);
delay1.delay(0, 100);
}
elapsedMillis volmsec=0;
void loop() {
// every 50 ms, adjust the volume
if (volmsec > 50) {
float vol = analogRead(15);
vol = vol / 1023.0;
//audioShield.volume(vol); // <-- uncomment if you have the optional
volmsec = 0; // volume pot on your audio shield
}
}