Triggering problem


Active member
I am trying to do a synchronized emission and reception between two teensy 4.1 (I use the SPH0645 as the microphone and the MAX98357A as an amplifier for the speakers).

Here is my code for recording :


for (i = 0; i < nfor; i++) {
    while(Q_in_L.available() < 1);
    sp_L = Q_in_L.readBuffer();
    arm_q15_to_float (sp_L, &float_buffer_L[partitionsize * i], partitionsize);

And for playing :

while(digitalRead(0) == HIGH);

So for triggering, the teensy which is recording put, it's pin 1 on LOW (it was previously on HIGH) and the second teensy is waiting for it.

This approximatively works... but I have a random variation of delay in the recordings. So, I performed 50 measures for a pure sin wave at 1000Hz and it Seems VERY random :

You're not synchronizing to the audio system I think. Since blocks by default are about 3ms that's enough jitter to fully randomize the phase of a 1kHz signal. The audio chain updates on that 3ms period with the default 128 samples-per-block setup.
This sounds as tricky as USB audio synchronization. You have two independent instances of the audio chain on the two boards.

BTW why are you wanting this to work to better than 3ms resolution - that's usually fine for the human ear.
So, perhaps a class which pass it's input to it's output only when triggered (and placed between the output queue and I2S) could work ?
I guess an input class that samples a pin using DMA and sets the output stream to 0 or 1 audio values, then that could be handled like any other audio stream. But that would have different latency from any particular ADC or DAC...

But I'm not sure what you are trying to do exactly, Can you explain #5 in more detail?
Actually, in reality, I have 12 teensy for emission, so I really need the delay to be constant every time and everywhere...

Also, my microphones and amplifiers are I2S.

For the time reversal stuff:
1-The teensy (only one at a time) play a chirp, which is recorded and logged into a PC.
2-The PC perfermorm a deconvolution and obtain the impulse response.
3-The impulse response is flipped and logged into the teensy.
4-The teensy play it.

If all is ok, the recorded signal must be a single peak.

It works fine with only one teensy.