Hello, I am implementing a method to calculate the delay between speaker and mic. The concept is very simple. Output callback is set on a audio manager (without input channels). Once the callback is called a sine wave of 160 samples is written to the output buffer. Before returning, the input call back (audio manager and not output channels) is set and the time is marker as Tout.
Input callback receives the first 2048 samples and removes itself form callback. The Tin is also marked. Input samples are band pass filtered (matching output frequency). Cross correlation co-efficiency is calculated between out and in and a matching position (with correlation above 0.9) of the 160 out samples is found within the 2048 filtered samples. So, if we calculate Tin-Tout-(2048-position)/frameRate we shall get the delay from speaker to mic. The strange thing is that there several cases where the delay is negative. Tout is the earliest (as there is the buffer handling and playing delay) possible and Tin is the latest possible moment (when we have a buffer in which we spot the output). So, although we may not be 100% accurate in calculating sound air travel time, we shall, at least, not calculate any negative values.
If there are any ideas, I would appreciate it.
