unexpected delay

TeensyPhonon

Active member
I am trying to do a synchronized emission en reception with 2 teensy 4.1.

The first code, for the "master", which put it's pin 1 to LOW (to trigger the second teensy) and play a signal (chirp[12800], here some dummy sine at 500Hz) stored in memory.

C:
digitalWrite(1,LOW);
        
for (i = 0; i < nfor; i++) {
    sp_L = Q_out_L.getBuffer();
    arm_float_to_q15 (&chirp[partitionsize * i], sp_L, partitionsize);
    Q_out_L.playBuffer();
}

digitalWrite(1,HIGH);

And the second code for the "slave", which wait the signal from the master, record the sound with the microphone and transmit it to a PC.

C:
while(digitalRead(0) == HIGH);
        
for (i = 0; i < nfor; i++) {
    while(Q_in_L.available() < 1);
    digitalWrite(1,LOW);
    sp_L = Q_in_L.readBuffer();
    arm_q15_to_float (sp_L, &float_buffer_L[partitionsize * i], partitionsize);
    Q_in_L.freeBuffer();
}



bool wait = true;
while(wait){
    if(Serial.available() > 0){
        command = Serial.readString();
        if(command.startsWith("ready")){wait = false;}
    }
}


char conv[4];
for(i=0;i<nc;i++){
    memcpy(conv,&float_buffer_L[i],4);
    Serial.write(conv,4);
    delay(0.5); 
}

Unfortunately, I see that the recording begin 30ms too early...

test_emission.png

No, it is not due to the propagation of sound, as the microphone and the speaker are really close to each other.

I thought it was due to the audio memory (10 blocks of 128) as 10*128/44100 = 0.029s, but it seems that delaying the recording has no effect...
 
Back
Top