tg icon indicating copy to clipboard operation
tg copied to clipboard

[Feature] Continuous auto-calibration using audio timestamps

Open xyzzy42 opened this issue 4 years ago • 0 comments

The audio buffers as supplied by PortAudio should have timestamps. If the computer's clock is being synchronized with NTP, then these timestamps should be very accurate. More accurate than a typical quartz watch.

So it should be possible to use these timestamps to calibrate tg. The number of samples received vs the timestamps between those samples should give the actual sampling rate.

This can be done continuously, so that as the sampling rate changes with temperature the calibration changes too.

For this to work, it requires:

  • PortAudio's timestamps are based on the computer's system clock and not PortAudio synthetically constructing them based on the samples received since the previous timestamp. On Linux, ALSA does provide real timestamps, generated in the kernel from the audio driver's interrupt code. PortAudio would need to use these.
  • The system clock is more accurate over the τ of interest than the audio hardware's clock. With NTP, even with an internet based NTP server, this should be the case.
  • That there is not a source of error (over the appropriate τ) prior to the timestamp of the audio. An example would be buffering in the microcontroller used in a USB audio device, to buffer data between each isochronous USB frame, which allows for unmeasured error on the computer's side of the USB interface. USB audio devices shouldn't do this.

xyzzy42 avatar Jan 26 '21 23:01 xyzzy42