alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
* first and last audio sample timestamp
@ 2018-06-22 14:00 Subhashini Rao Beerisetty
  2018-06-25 14:34 ` Takashi Iwai
  0 siblings, 1 reply; 6+ messages in thread
From: Subhashini Rao Beerisetty @ 2018-06-22 14:00 UTC (permalink / raw)
  To: alsa-devel, linux-sound

[ Please keep me in CC as I'm not subscribed to the list]

Hi All,



Hello all,


I’m using aplay and arecord utilities for playback and capture. I need to
capture the timestamps for the first and last audio samples that arrive at
the driver level.

For this I’m capturing the CLOCK_MONOTONIC_RAW timestamp at the
.trigger(for playback & capture) callback in SNDRV_PCM_TRIGGER_START  case
– is it the correct timestamp for the first audio sample arrived at the
driver level?

Similarly does .trigger callbacks SNDRV_PCM_TRIGGER_STOP gives the last
audio sample timestamp?
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: first and last audio sample timestamp
  2018-06-22 14:00 first and last audio sample timestamp Subhashini Rao Beerisetty
@ 2018-06-25 14:34 ` Takashi Iwai
  2018-06-25 14:50   ` Subhashini Rao Beerisetty
  0 siblings, 1 reply; 6+ messages in thread
From: Takashi Iwai @ 2018-06-25 14:34 UTC (permalink / raw)
  To: Subhashini Rao Beerisetty; +Cc: alsa-devel, linux-sound

On Fri, 22 Jun 2018 16:00:10 +0200,
Subhashini Rao Beerisetty wrote:
> 
> [ Please keep me in CC as I'm not subscribed to the list]
> 
> Hi All,
> 
> 
> 
> Hello all,
> 
> 
> I’m using aplay and arecord utilities for playback and capture. I need to
> capture the timestamps for the first and last audio samples that arrive at
> the driver level.
> 
> For this I’m capturing the CLOCK_MONOTONIC_RAW timestamp at the
> .trigger(for playback & capture) callback in SNDRV_PCM_TRIGGER_START  case
> – is it the correct timestamp for the first audio sample arrived at the
> driver level?
> 
> Similarly does .trigger callbacks SNDRV_PCM_TRIGGER_STOP gives the last
> audio sample timestamp?

No, it's the timestamp upon calling the trigger callback.
It has nothing to do directly with the first or the last sample.
(But usually the start trigger is the time of the first sample for
 capture, though.)


Takashi
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: first and last audio sample timestamp
  2018-06-25 14:34 ` Takashi Iwai
@ 2018-06-25 14:50   ` Subhashini Rao Beerisetty
  2018-06-25 14:53     ` Takashi Iwai
  0 siblings, 1 reply; 6+ messages in thread
From: Subhashini Rao Beerisetty @ 2018-06-25 14:50 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel, linux-sound

On Mon, Jun 25, 2018 at 8:04 PM, Takashi Iwai <tiwai@suse.de> wrote:

> On Fri, 22 Jun 2018 16:00:10 +0200,
> Subhashini Rao Beerisetty wrote:
> >
> > [ Please keep me in CC as I'm not subscribed to the list]
> >
> > Hi All,
> >
> >
> >
> > Hello all,
> >
> >
> > I’m using aplay and arecord utilities for playback and capture. I need to
> > capture the timestamps for the first and last audio samples that arrive
> at
> > the driver level.
> >
> > For this I’m capturing the CLOCK_MONOTONIC_RAW timestamp at the
> > .trigger(for playback & capture) callback in SNDRV_PCM_TRIGGER_START
> case
> > – is it the correct timestamp for the first audio sample arrived at the
> > driver level?
> >
> > Similarly does .trigger callbacks SNDRV_PCM_TRIGGER_STOP gives the last
> > audio sample timestamp?
>
> No, it's the timestamp upon calling the trigger callback.
> It has nothing to do directly with the first or the last sample.
> (But usually the start trigger is the time of the first sample for
>  capture, though.)
>

Okay then if start trigger is the time of the first sample for capture,
then is stop trigger is for last sample? For example, i'm printing the
timestamp as given below. Similarly in which call back I can use the
getrawmonotonic()
for playback case.

static int snd_mychip_capture_trigger(struct snd_pcm_substream *substream,
int cmd)

{

    struct timespec ts;



    switch(cmd) {

        case SNDRV_PCM_TRIGGER_START:

            getrawmonotonic(&ts);

            printk("1st audio sample received time:
[%.6lu:%.9lu]\n",ts.tv_sec, ts.tv_nsec);

            break;

        case SNDRV_PCM_TRIGGER_STOP:

            getrawmonotonic(&ts);

            printk("Last audio sample received time:
[%.6lu:%.9lu]\n",ts.tv_sec, ts.tv_nsec);

            break;

    }



}


>
>
> Takashi
>
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: first and last audio sample timestamp
  2018-06-25 14:50   ` Subhashini Rao Beerisetty
@ 2018-06-25 14:53     ` Takashi Iwai
  2018-06-25 14:58       ` Subhashini Rao Beerisetty
  0 siblings, 1 reply; 6+ messages in thread
From: Takashi Iwai @ 2018-06-25 14:53 UTC (permalink / raw)
  To: Subhashini Rao Beerisetty; +Cc: alsa-devel, linux-sound

On Mon, 25 Jun 2018 16:50:20 +0200,
Subhashini Rao Beerisetty wrote:
> 
> On Mon, Jun 25, 2018 at 8:04 PM, Takashi Iwai <tiwai@suse.de> wrote:
> 
> > On Fri, 22 Jun 2018 16:00:10 +0200,
> > Subhashini Rao Beerisetty wrote:
> > >
> > > [ Please keep me in CC as I'm not subscribed to the list]
> > >
> > > Hi All,
> > >
> > >
> > >
> > > Hello all,
> > >
> > >
> > > I’m using aplay and arecord utilities for playback and capture. I need to
> > > capture the timestamps for the first and last audio samples that arrive
> > at
> > > the driver level.
> > >
> > > For this I’m capturing the CLOCK_MONOTONIC_RAW timestamp at the
> > > .trigger(for playback & capture) callback in SNDRV_PCM_TRIGGER_START
> > case
> > > – is it the correct timestamp for the first audio sample arrived at the
> > > driver level?
> > >
> > > Similarly does .trigger callbacks SNDRV_PCM_TRIGGER_STOP gives the last
> > > audio sample timestamp?
> >
> > No, it's the timestamp upon calling the trigger callback.
> > It has nothing to do directly with the first or the last sample.
> > (But usually the start trigger is the time of the first sample for
> >  capture, though.)
> >
> 
> Okay then if start trigger is the time of the first sample for capture,
> then is stop trigger is for last sample?

No, it's not necessarily the last sample.  It's the just time you stop
the stream.  The stop might happen some time after the last sample got
received.  The accuracy in that regard pretty much depends on the
hardware and the driver implementation.


Takashi

> For example, i'm printing the
> timestamp as given below. Similarly in which call back I can use the
> getrawmonotonic()
> for playback case.
> 
> static int snd_mychip_capture_trigger(struct snd_pcm_substream *substream,
> int cmd)
> 
> {
> 
>     struct timespec ts;
> 
> 
> 
>     switch(cmd) {
> 
>         case SNDRV_PCM_TRIGGER_START:
> 
>             getrawmonotonic(&ts);
> 
>             printk("1st audio sample received time:
> [%.6lu:%.9lu]\n",ts.tv_sec, ts.tv_nsec);
> 
>             break;
> 
>         case SNDRV_PCM_TRIGGER_STOP:
> 
>             getrawmonotonic(&ts);
> 
>             printk("Last audio sample received time:
> [%.6lu:%.9lu]\n",ts.tv_sec, ts.tv_nsec);
> 
>             break;
> 
>     }
> 
> 
> 
> }
> 
> 
> >
> >
> > Takashi
> >
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: first and last audio sample timestamp
  2018-06-25 14:53     ` Takashi Iwai
@ 2018-06-25 14:58       ` Subhashini Rao Beerisetty
  2018-06-25 15:08         ` Takashi Iwai
  0 siblings, 1 reply; 6+ messages in thread
From: Subhashini Rao Beerisetty @ 2018-06-25 14:58 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel, linux-sound

On Mon, Jun 25, 2018 at 8:23 PM, Takashi Iwai <tiwai@suse.de> wrote:

> On Mon, 25 Jun 2018 16:50:20 +0200,
> Subhashini Rao Beerisetty wrote:
> >
> > On Mon, Jun 25, 2018 at 8:04 PM, Takashi Iwai <tiwai@suse.de> wrote:
> >
> > > On Fri, 22 Jun 2018 16:00:10 +0200,
> > > Subhashini Rao Beerisetty wrote:
> > > >
> > > > [ Please keep me in CC as I'm not subscribed to the list]
> > > >
> > > > Hi All,
> > > >
> > > >
> > > >
> > > > Hello all,
> > > >
> > > >
> > > > I’m using aplay and arecord utilities for playback and capture. I
> need to
> > > > capture the timestamps for the first and last audio samples that
> arrive
> > > at
> > > > the driver level.
> > > >
> > > > For this I’m capturing the CLOCK_MONOTONIC_RAW timestamp at the
> > > > .trigger(for playback & capture) callback in SNDRV_PCM_TRIGGER_START
> > > case
> > > > – is it the correct timestamp for the first audio sample arrived at
> the
> > > > driver level?
> > > >
> > > > Similarly does .trigger callbacks SNDRV_PCM_TRIGGER_STOP gives the
> last
> > > > audio sample timestamp?
> > >
> > > No, it's the timestamp upon calling the trigger callback.
> > > It has nothing to do directly with the first or the last sample.
> > > (But usually the start trigger is the time of the first sample for
> > >  capture, though.)
> > >
> >
> > Okay then if start trigger is the time of the first sample for capture,
> > then is stop trigger is for last sample?
>
> No, it's not necessarily the last sample.  It's the just time you stop
> the stream.  The stop might happen some time after the last sample got
> received.  The accuracy in that regard pretty much depends on the
> hardware and the driver implementation.
>
Thanks for the clarification. What about for playback scenario?


>
>
> Takashi
>
> > For example, i'm printing the
> > timestamp as given below. Similarly in which call back I can use the
> > getrawmonotonic()
> > for playback case.
> >
> > static int snd_mychip_capture_trigger(struct snd_pcm_substream
> *substream,
> > int cmd)
> >
> > {
> >
> >     struct timespec ts;
> >
> >
> >
> >     switch(cmd) {
> >
> >         case SNDRV_PCM_TRIGGER_START:
> >
> >             getrawmonotonic(&ts);
> >
> >             printk("1st audio sample received time:
> > [%.6lu:%.9lu]\n",ts.tv_sec, ts.tv_nsec);
> >
> >             break;
> >
> >         case SNDRV_PCM_TRIGGER_STOP:
> >
> >             getrawmonotonic(&ts);
> >
> >             printk("Last audio sample received time:
> > [%.6lu:%.9lu]\n",ts.tv_sec, ts.tv_nsec);
> >
> >             break;
> >
> >     }
> >
> >
> >
> > }
> >
> >
> > >
> > >
> > > Takashi
> > >
>
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: first and last audio sample timestamp
  2018-06-25 14:58       ` Subhashini Rao Beerisetty
@ 2018-06-25 15:08         ` Takashi Iwai
  0 siblings, 0 replies; 6+ messages in thread
From: Takashi Iwai @ 2018-06-25 15:08 UTC (permalink / raw)
  To: Subhashini Rao Beerisetty; +Cc: alsa-devel, linux-sound

On Mon, 25 Jun 2018 16:58:26 +0200,
Subhashini Rao Beerisetty wrote:
> 
> On Mon, Jun 25, 2018 at 8:23 PM, Takashi Iwai <tiwai@suse.de> wrote:
> 
> > On Mon, 25 Jun 2018 16:50:20 +0200,
> > Subhashini Rao Beerisetty wrote:
> > >
> > > On Mon, Jun 25, 2018 at 8:04 PM, Takashi Iwai <tiwai@suse.de> wrote:
> > >
> > > > On Fri, 22 Jun 2018 16:00:10 +0200,
> > > > Subhashini Rao Beerisetty wrote:
> > > > >
> > > > > [ Please keep me in CC as I'm not subscribed to the list]
> > > > >
> > > > > Hi All,
> > > > >
> > > > >
> > > > >
> > > > > Hello all,
> > > > >
> > > > >
> > > > > I’m using aplay and arecord utilities for playback and capture. I
> > need to
> > > > > capture the timestamps for the first and last audio samples that
> > arrive
> > > > at
> > > > > the driver level.
> > > > >
> > > > > For this I’m capturing the CLOCK_MONOTONIC_RAW timestamp at the
> > > > > .trigger(for playback & capture) callback in SNDRV_PCM_TRIGGER_START
> > > > case
> > > > > – is it the correct timestamp for the first audio sample arrived at
> > the
> > > > > driver level?
> > > > >
> > > > > Similarly does .trigger callbacks SNDRV_PCM_TRIGGER_STOP gives the
> > last
> > > > > audio sample timestamp?
> > > >
> > > > No, it's the timestamp upon calling the trigger callback.
> > > > It has nothing to do directly with the first or the last sample.
> > > > (But usually the start trigger is the time of the first sample for
> > > >  capture, though.)
> > > >
> > >
> > > Okay then if start trigger is the time of the first sample for capture,
> > > then is stop trigger is for last sample?
> >
> > No, it's not necessarily the last sample.  It's the just time you stop
> > the stream.  The stop might happen some time after the last sample got
> > received.  The accuracy in that regard pretty much depends on the
> > hardware and the driver implementation.
> >
> Thanks for the clarification. What about for playback scenario?

A similar situation.  The timestamp at stop trigger is the time you
stopped the stream, and it's not about the "last" sample time.

BTW, for the accurate timestamping, check
Documentation/sound/design/timestamping.rst.


Takashi


> 
> 
> >
> >
> > Takashi
> >
> > > For example, i'm printing the
> > > timestamp as given below. Similarly in which call back I can use the
> > > getrawmonotonic()
> > > for playback case.
> > >
> > > static int snd_mychip_capture_trigger(struct snd_pcm_substream
> > *substream,
> > > int cmd)
> > >
> > > {
> > >
> > >     struct timespec ts;
> > >
> > >
> > >
> > >     switch(cmd) {
> > >
> > >         case SNDRV_PCM_TRIGGER_START:
> > >
> > >             getrawmonotonic(&ts);
> > >
> > >             printk("1st audio sample received time:
> > > [%.6lu:%.9lu]\n",ts.tv_sec, ts.tv_nsec);
> > >
> > >             break;
> > >
> > >         case SNDRV_PCM_TRIGGER_STOP:
> > >
> > >             getrawmonotonic(&ts);
> > >
> > >             printk("Last audio sample received time:
> > > [%.6lu:%.9lu]\n",ts.tv_sec, ts.tv_nsec);
> > >
> > >             break;
> > >
> > >     }
> > >
> > >
> > >
> > > }
> > >
> > >
> > > >
> > > >
> > > > Takashi
> > > >
> >
> [2  <text/html; UTF-8 (quoted-printable)>]
> 
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-06-25 15:09 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-06-22 14:00 first and last audio sample timestamp Subhashini Rao Beerisetty
2018-06-25 14:34 ` Takashi Iwai
2018-06-25 14:50   ` Subhashini Rao Beerisetty
2018-06-25 14:53     ` Takashi Iwai
2018-06-25 14:58       ` Subhashini Rao Beerisetty
2018-06-25 15:08         ` Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).