From: Takashi Iwai Subject: Re: [PATCH v2] ALSA: hda - Apply codec delay to wallclock. Date: Tue, 09 Apr 2013 08:03:46 +0200 Message-ID: References: <1365470430-22292-1-git-send-email-dgreid@chromium.org> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mx2.suse.de (cantor2.suse.de [195.135.220.15]) by alsa0.perex.cz (Postfix) with ESMTP id 8701C265D77 for ; Tue, 9 Apr 2013 08:03:47 +0200 (CEST) In-Reply-To: <1365470430-22292-1-git-send-email-dgreid@chromium.org> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org To: Dylan Reid Cc: alsa-devel@alsa-project.org, pierre-louis.bossart@linux.intel.com List-Id: alsa-devel@alsa-project.org At Mon, 8 Apr 2013 18:20:30 -0700, Dylan Reid wrote: > > For playback add the codec-side delay to the timestamp, for capture > subtract it. This brings the timestamps in line with the time that > was recently added to the delay reporting. > > Signed-off-by: Dylan Reid Thanks, applied now. Takashi > --- > Changes since v1: > Calculate nsec from frames, subtract delay for playback as well as > capture. > > sound/pci/hda/hda_intel.c | 18 ++++++++++++++++++ > 1 file changed, 18 insertions(+) > > diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c > index 735567e..3e6f2c6 100644 > --- a/sound/pci/hda/hda_intel.c > +++ b/sound/pci/hda/hda_intel.c > @@ -1889,6 +1889,23 @@ static void azx_timecounter_init(struct snd_pcm_substream *substream, > tc->cycle_last = last; > } > > +static u64 azx_subtract_codec_delay(struct snd_pcm_substream *substream, > + u64 nsec) > +{ > + struct azx_pcm *apcm = snd_pcm_substream_chip(substream); > + struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream]; > + u64 codec_frames, codec_nsecs; > + > + if (!hinfo->ops.get_delay) > + return nsec; > + > + codec_frames = hinfo->ops.get_delay(hinfo, apcm->codec, substream); > + codec_nsecs = div_u64(codec_frames * 1000000000LL, > + substream->runtime->rate); > + > + return (nsec > codec_nsecs) ? nsec - codec_nsecs : 0; > +} > + > static int azx_get_wallclock_tstamp(struct snd_pcm_substream *substream, > struct timespec *ts) > { > @@ -1897,6 +1914,7 @@ static int azx_get_wallclock_tstamp(struct snd_pcm_substream *substream, > > nsec = timecounter_read(&azx_dev->azx_tc); > nsec = div_u64(nsec, 3); /* can be optimized */ > + nsec = azx_subtract_codec_delay(substream, nsec); > > *ts = ns_to_timespec(nsec); > > -- > 1.8.1.3.605.g02339dd >