All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Dylan Reid <dgreid@chromium.org>
Cc: alsa-devel@alsa-project.org, pierre-louis.bossart@linux.intel.com
Subject: Re: [PATCH] ALSA: hda - Apply codec delay to wallclock.
Date: Sun, 07 Apr 2013 09:41:10 +0200	[thread overview]
Message-ID: <s5hehem3i09.wl%tiwai@suse.de> (raw)
In-Reply-To: <1365207724-6288-1-git-send-email-dgreid@chromium.org>

At Fri,  5 Apr 2013 17:22:04 -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 <dgreid@chromium.org>
> ---
>  sound/pci/hda/hda_intel.c | 22 ++++++++++++++++++++++
>  1 file changed, 22 insertions(+)
> 
> diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
> index 735567e..ec8ac71 100644
> --- a/sound/pci/hda/hda_intel.c
> +++ b/sound/pci/hda/hda_intel.c
> @@ -1889,6 +1889,27 @@ static void azx_timecounter_init(struct snd_pcm_substream *substream,
>  		tc->cycle_last = last;
>  }
>  
> +static u64 azx_add_codec_delay_nsec(struct snd_pcm_substream *substream,
> +				u64 nsec)
> +{
> +	struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
> +	int stream = substream->stream;
> +	struct hda_pcm_stream *hinfo = apcm->hinfo[stream];
> +	struct hda_codec *codec = apcm->codec;
> +	u64 codec_nsec;
> +
> +	if (hinfo->ops.get_delay) {
> +		codec_nsec =
> +			hinfo->ops.get_delay(hinfo, codec, substream) * 1000000;
> +		if (stream == SNDRV_PCM_STREAM_CAPTURE)
> +			nsec = (nsec > codec_nsec) ? nsec - codec_nsec : 0;
> +		else if (stream == SNDRV_PCM_STREAM_PLAYBACK)
> +			nsec += codec_nsec;

I think the compensation is applied in a wrong direction.

For the playback, the wallclock indicates the timestamp corresponding
to the position currently being played.  With the codec delay, the
position is back more, i.e. the timestamp has to be subtracted.


Takashi

> +	}
> +
> +	return nsec;
> +}
> +
>  static int azx_get_wallclock_tstamp(struct snd_pcm_substream *substream,
>  				struct timespec *ts)
>  {
> @@ -1897,6 +1918,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_add_codec_delay_nsec(substream, nsec);
>  
>  	*ts = ns_to_timespec(nsec);
>  
> -- 
> 1.8.1.3.605.g02339dd
> 

  reply	other threads:[~2013-04-07  7:41 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-06  0:22 [PATCH] ALSA: hda - Apply codec delay to wallclock Dylan Reid
2013-04-07  7:41 ` Takashi Iwai [this message]
2013-04-08 15:44   ` Dylan Reid
2013-04-08 16:31 ` Pierre-Louis Bossart
2013-04-08 16:34   ` Takashi Iwai
2013-04-08 16:56     ` Dylan Reid
2013-04-08 23:37       ` Pierre-Louis Bossart
2013-04-09  0:05         ` Dylan Reid

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=s5hehem3i09.wl%tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=dgreid@chromium.org \
    --cc=pierre-louis.bossart@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.