Synchronizing teensies (again)

TeensyPhonon

Active member
Hello everyone,

I have a project where I need to record the Green's functions in two rooms. For those who don't know what it is, it’s basically what you hear if you play a brief impulse like an explosion.

To do this, I just have an I2S amplifier and an I2S microphone on two separate Teensies. One Teensy is able to trigger the second one using its pin 0.

The problem is that the Teensy is using DMA, so there is some jitter introducing a random delay... It’s not a problem with one microphone, but with 32 (and the same number of Teensies), it completely breaks the relations between the Green's functions. (It is a bit like trying to measure the speed of sound, the travel time is messed up and you obtain the wrong speed.)

I have been able to correct that in software, but it is really inelegant and not robust as it requires additional measurements.

So, I am looking again at another solution! What I want is simply to start recording sound into an array on the Teensy when the trigger signal is detected (or at least with a fixed delay) with microsecond precision.

I am thinking of two solutions:
- Using I2S with one sample at a time: inefficient (later code is using blocks, so...) and not super precise (22 µs maximum).
- Controlling the DMA to make it start at the right time. How?

Is that even possible at all?
 
I don't really understand how DMA can cause a recording delay? While its timing can be non-deterministic, it's typically only used to move recorded samples from one hardware buffer to RAM, while recording continues to another hardware buffer... Recording begins before any DMA takes place so it makes no sense that DMA could be responsible for a delay.
 
The different Teensy's will be clocking at slightly different rates as well, since there is variability in crystals. Why not synchronize by injecting a small short electrical pulse into the microphone analog signal simultaneously for each of them - then you have that in the audio data stream as a reference, and can tune out timing skew and drift later.
 
Ironically this would be so much simpler using analog microphones wired to a central logger...
 
Also the SPH0645 (especially the board from Adafruit) needs some 'tolerant' users (large negative offset)
DMA does give a fixed delay , so only 'jitter' is driven by asynchronous frame-sync.
 
As MarkT already mentioned, why not use one device for playback and record? If you have a wire connection to the second teensy anyway you could also use a line signal oder the microphone signal. Or what is the reason to have two Teensies?
 
The 32 Teensies also have 32 speakers to do it the other way.

Also, later code is basically a partitioned convolution filter made with the Green's functions. It is really heavy, so it can't run on a single Teensy.

Also, we decided that each Teensy should be independent (it's a metasurface), yes I know it sucks, but my advisor wanted it that way, so...
 
Schematic for better understanding:

schematic.png



I am measuring gej(t) and gjr(t) (32 of each).

Code for recording:

C:
while(digitalRead(0) == HIGH);
        
Q_in_L.begin();
Q_in_L.clear();

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

}
 
Last edited:
Back
Top