From a288430e282dac3ffae004a95d39b411171c1dff Mon Sep 17 00:00:00 2001 From: J C Dutton Date: Sat, 28 Jan 2006 14:58:55 +0000 Subject: [PATCH] Summary: Improve accuracy of capture timestamps. The time stamps should be accurate to within about +-1ms now. git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/trunk@120 ab8295b8-cf94-4d9e-aec4-7959e3be5d79 --- start_alsa.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/start_alsa.c b/start_alsa.c index 824ef477b..4174a26a9 100644 --- a/start_alsa.c +++ b/start_alsa.c @@ -391,6 +391,7 @@ int capture_callback(alsa_driver_t *alsa_driver_capture) { struct timeval tv; double stime; int ib; + snd_pcm_sframes_t delay; #ifdef ALSA_CAPTURE_LOG printf("capture callback %d samples\n", this->period_size); #endif @@ -400,12 +401,16 @@ int capture_callback(alsa_driver_t *alsa_driver_capture) { snd_pcm_status(this->audio_fd, pcm_stat); snd_pcm_status_dump(pcm_stat, jcd_out); #endif + snd_pcm_delay(this->audio_fd, &delay); gettimeofday(&tv, NULL); stime = (double) tv.tv_sec + ((double)tv.tv_usec / 1000000.0) + *(this->ndsec) * 0.1; + stime = stime - ((double)delay / (double)(this->output_sample_rate)); *(this->Tsec) = stime; ib=*(this->ibuf); - this->tbuf[ib++] = stime; + this->tbuf[ib] = stime; + //printf("CAP:TIME, %d, %lf, %ld, %ld, %d\n",ib, stime, delay, this->output_sample_rate, *this->ndsec); + ib++; if(ib>=1024) ib = 0; *(this->ibuf) = ib;