Amplitude latency?

Not open for further replies.


Hi all,

I mentioned this down in a buried thread about a month back, but the question has re-arisen. I wrote a script that periodically changes the amplitude of a sine wave generated through the Audio library ("AudioSynthWaveformSine"). I output digital pulses at approximately the same time (a line of code later) that I change the amplitude, so I measured both outputs with an RZ5D TDT system. It appears that changing the amplitude only occurs after, on average, like a 7.5 ms delay. I'm assuming that it's coming from 2 audio blocks (~5.8 seconds), plus the remainder of the current audio block (assuming 1.5 ms average, that puts it us at 7.3 ms). Does this sound right? Here is the output from the digital pulse and the audio pin:
Screenshot from 2018-10-26 14-08-27.png

And here is a plot showing the delays over 50 trials:
Screenshot from 2018-10-26 14-30-20.png

Thanks for any and all help!



  • main_audio.cpp
    4.9 KB · Views: 110
Yes, sounds right.
You can try to use shorter audio-blocks (64 or 32), either by editing AudioStream.h, or by using -DAUDIO_BLOCK_SAMPLES=64 if you use a makefile or this. The downside is, it adds some overhead for processing.
Most of the output objects have 2 buffers. In hindsight, really only 1 is needed. Eventually I'm going to update them all to avoid buffering a 2nd packet, which should gut 2.9 ms from the latency.
Ah thank you both! Very helpful! That was my understanding from running through the code a little bit, but I'm new to C++, so I wasn't confident that was correct.
Yes 2nd packet buffers alot.2nd packet is never needed here,it is just creating glitches.So pls update them.
Hi ! I'd like to set the -DAUDIO_BLOCK_SAMPLES=64 build flag but I don't know how to do this in Visual Code which is my preferred IDE. Is it possible for teensy 4.1 in Visual code ?
Not open for further replies.