Hi!
Your code posting on GitHub seems to work great. Nice work!
I’m glad to hear that you’ve had success with measuring the transfer function. Would it be possible for you to share any graphs or figures of your findings? I’m super interested!
As for the changing latency due to adding the SD card, that does not have to be the case. It is not inherent in doing SD recording. So, if you are seeing an extra delay due to adding SD recording, we should find out why!
How can we figure this out…
In the Tympan code, the overall delay does depend upon the order in which the audio processing classes are executed. If the system tries to execute them in the wrong order, the input data for a given class might not yet be available. The system will have to wait, adding delay. So, the key is to try to get all the processing blocks to get called in the right order so as to avoid any extra delays.
It may be helpful for you to know that the audio processing classes are executed in the order that you create them in your code. So, if you make an edit to your code where you change the order that you create them, you will change the order of their execution. This might change the overall delay.
For a simple (sequential) audio processing chain, were you simply have audio going in a straight line through each audio processing step, it’s easy to see how to create them in the right order. But, the SD class is tricky. It is tricky because it has two inputs (for stereo audio recording). If you care about delay, then you need to make sure that both audio paths are computed prior to the SD class is called. If you get the wrong order, you risk one of the channels being delayed relative to the other in the SD recording.
Because you saw the delay change when adding the SD recorder, I’m thinking that your are seeing this out-of-order issue. Perhaps, if we change the order in which you create your audio classes, we can make the extra delay to go away.
Can you share your version of the code where you have included the SD writing?
Also, even if you get the order of the classes perfect, there is still a certain amount of delay that you will experience. That minimum delay is described by the blog post that I linked. Under ideal conditions, your delay will be at least: delay_seconds = (2*audio_block_samples + 38 samples) / sample_rate_Hz
Per this equation, if you want to reduce the delay, the easiest two things to do are: (1) increase the sample rate, and (2) reduce the audio block size. You can do both at the top of your code where you set sample_rate_Hz
and audio_block_samples
.
Chip