* Is there a way to figure out if the clocks of two snd_pcm_t's deviate? (snd_pcm_info_get_sync?)
@ 2009-09-03 23:03 Lennart Poettering
2009-09-04 6:44 ` Jaroslav Kysela
2009-09-04 12:52 ` pl bossart
0 siblings, 2 replies; 7+ messages in thread
From: Lennart Poettering @ 2009-09-03 23:03 UTC (permalink / raw)
To: ALSA Development Mailing List
Heya!
I am looking for a way to find out whether the clocks of two
snd_pcm_t's are perfectly in sync and don't deviate (or only deviate
by a constant phase).
i.e. for real duplex devices that use the same crystal for input and
output this should tell me "Yes" for the playback snd_pcm_t tested
against the recording snd_pcm_t; and for all other, unrelated audio
devices it should return "No".
I found snd_pcm_info_get_sync() in the docs, but its documentation is
a bit terse, so I am wondering if this might be what I want. Is it?
Does this (untested) code snippet do what I hope it does?
<snip>
snd_pcm_info(a, info_a);
snd_pcm_info(b, info_b);
in_sync = memcmp(&snd_pcm_info_get_sync(info_a), &snd_pcm_info_get_sync(info_b)) == 0;
</snip>
Thanks,
Lennart
--
Lennart Poettering Red Hat, Inc.
lennart [at] poettering [dot] net
http://0pointer.net/lennart/ GnuPG 0x1A015CC4
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Is there a way to figure out if the clocks of two snd_pcm_t's deviate? (snd_pcm_info_get_sync?)
2009-09-03 23:03 Is there a way to figure out if the clocks of two snd_pcm_t's deviate? (snd_pcm_info_get_sync?) Lennart Poettering
@ 2009-09-04 6:44 ` Jaroslav Kysela
2009-09-04 11:44 ` Mark Brown
2009-09-08 23:13 ` Lennart Poettering
2009-09-04 12:52 ` pl bossart
1 sibling, 2 replies; 7+ messages in thread
From: Jaroslav Kysela @ 2009-09-04 6:44 UTC (permalink / raw)
To: Lennart Poettering; +Cc: ALSA Development Mailing List
On Fri, 4 Sep 2009, Lennart Poettering wrote:
> Heya!
>
> I am looking for a way to find out whether the clocks of two
> snd_pcm_t's are perfectly in sync and don't deviate (or only deviate
> by a constant phase).
>
> i.e. for real duplex devices that use the same crystal for input and
> output this should tell me "Yes" for the playback snd_pcm_t tested
> against the recording snd_pcm_t; and for all other, unrelated audio
> devices it should return "No".
>
> I found snd_pcm_info_get_sync() in the docs, but its documentation is
> a bit terse, so I am wondering if this might be what I want. Is it?
>
> Does this (untested) code snippet do what I hope it does?
Hi,
Nope. The snd_pcm_info_get_sync() function identifies streams with
"sample sync and sample synchronized start".
All standard soundcards have only one clock source, so if
snd_pcm_info_get_card() number matches, the streams will most probably
run in sync.
I cannot recall from my mind, if any card has two clock sources - maybe
only old Gravis UltraSound hardware with GF1 and CS4231 chips, but it's
history. Also, professional hardware can run with word clock sync (wire
connection carrying sample clock) or S/PDIF clock sync. But it's matter of
user configuration.
I would suggest to match card number as default for used streams and add
an user option to modify the stream word clock configuration for your app.
Jaroslav
-----
Jaroslav Kysela <perex@perex.cz>
Linux Kernel Sound Maintainer
ALSA Project, Red Hat, Inc.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Is there a way to figure out if the clocks of two snd_pcm_t's deviate? (snd_pcm_info_get_sync?)
2009-09-04 6:44 ` Jaroslav Kysela
@ 2009-09-04 11:44 ` Mark Brown
2009-09-08 23:13 ` Lennart Poettering
1 sibling, 0 replies; 7+ messages in thread
From: Mark Brown @ 2009-09-04 11:44 UTC (permalink / raw)
To: Jaroslav Kysela; +Cc: ALSA Development Mailing List, Lennart Poettering
On Fri, Sep 04, 2009 at 08:44:50AM +0200, Jaroslav Kysela wrote:
> I cannot recall from my mind, if any card has two clock sources - maybe
> only old Gravis UltraSound hardware with GF1 and CS4231 chips, but it's
> history. Also, professional hardware can run with word clock sync (wire
> connection carrying sample clock) or S/PDIF clock sync. But it's matter of
> user configuration.
Several of the embedded CODECs can have multiple master clocks active
simultaneously within just that device and even more embedded systems
are able to run with multiple masters.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Is there a way to figure out if the clocks of two snd_pcm_t's deviate? (snd_pcm_info_get_sync?)
2009-09-03 23:03 Is there a way to figure out if the clocks of two snd_pcm_t's deviate? (snd_pcm_info_get_sync?) Lennart Poettering
2009-09-04 6:44 ` Jaroslav Kysela
@ 2009-09-04 12:52 ` pl bossart
2009-09-08 23:18 ` Lennart Poettering
1 sibling, 1 reply; 7+ messages in thread
From: pl bossart @ 2009-09-04 12:52 UTC (permalink / raw)
To: ALSA Development Mailing List
> I am looking for a way to find out whether the clocks of two
> snd_pcm_t's are perfectly in sync and don't deviate (or only deviate
> by a constant phase).
short answer:no
You would need hardware that would count the bit clock transitions and
provide the delta. Few devices provide this in the consumer space, and
when they do they actually perform an asynchronous sample-rate
conversion on the fly (cf. Freescale DSP563xx). Analog Devices also
provides dedicated sample-rate converters that perform this comparison
and resampling; they are typically used when multiple masters are
present.
All this nice hardware wouldn't work anyway for USB where audio is
transmitted in packets every ms; it's hard to guess what the real
audio speed is.
That's the reason why I introduced the resampling enable/disable in
the PA module-loopback code, only the user/system designer will know
if you have one master or more, and whether you should enable
variable-rate interpolation.
Cheers
- PL
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Is there a way to figure out if the clocks of two snd_pcm_t's deviate? (snd_pcm_info_get_sync?)
2009-09-04 6:44 ` Jaroslav Kysela
2009-09-04 11:44 ` Mark Brown
@ 2009-09-08 23:13 ` Lennart Poettering
1 sibling, 0 replies; 7+ messages in thread
From: Lennart Poettering @ 2009-09-08 23:13 UTC (permalink / raw)
To: ALSA Development Mailing List
On Fri, 04.09.09 08:44, Jaroslav Kysela (perex@perex.cz) wrote:
> All standard soundcards have only one clock source, so if
> snd_pcm_info_get_card() number matches, the streams will most probably
> run in sync.
Hmm, does this also mean that SPDIF output and analog output of the
same sound card stay in sync on most cards?
> I would suggest to match card number as default for used streams and add
> an user option to modify the stream word clock configuration for your
> app.
OK, sounds good.
Lennart
--
Lennart Poettering Red Hat, Inc.
lennart [at] poettering [dot] net
http://0pointer.net/lennart/ GnuPG 0x1A015CC4
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Is there a way to figure out if the clocks of two snd_pcm_t's deviate? (snd_pcm_info_get_sync?)
2009-09-04 12:52 ` pl bossart
@ 2009-09-08 23:18 ` Lennart Poettering
2009-09-09 16:03 ` pl bossart
0 siblings, 1 reply; 7+ messages in thread
From: Lennart Poettering @ 2009-09-08 23:18 UTC (permalink / raw)
To: alsa-devel
On Fri, 04.09.09 07:52, pl bossart (bossart.nospam@gmail.com) wrote:
>
> > I am looking for a way to find out whether the clocks of two
> > snd_pcm_t's are perfectly in sync and don't deviate (or only deviate
> > by a constant phase).
>
> short answer:no
> You would need hardware that would count the bit clock transitions and
> provide the delta. Few devices provide this in the consumer space, and
> when they do they actually perform an asynchronous sample-rate
> conversion on the fly (cf. Freescale DSP563xx). Analog Devices also
> provides dedicated sample-rate converters that perform this comparison
> and resampling; they are typically used when multiple masters are
> present.
> All this nice hardware wouldn't work anyway for USB where audio is
> transmitted in packets every ms; it's hard to guess what the real
> audio speed is.
But that should already be good enough for my purposes. I mostly care
that over a longer period of time the deviation between input and
output (or two outputs) is bounded. That means, if there is a fixed
time deviation between recording and playback and I know only that it
is fixed but don't know exactly what it is I am already a happier man.
> That's the reason why I introduced the resampling enable/disable in
> the PA module-loopback code, only the user/system designer will know
> if you have one master or more, and whether you should enable
> variable-rate interpolation.
but why shouldn't this information be queriable from the drivers?
Drivers do know a lot about the hardware they drive, so they should
now about clocks, too.
Lennart
--
Lennart Poettering Red Hat, Inc.
lennart [at] poettering [dot] net
http://0pointer.net/lennart/ GnuPG 0x1A015CC4
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Is there a way to figure out if the clocks of two snd_pcm_t's deviate? (snd_pcm_info_get_sync?)
2009-09-08 23:18 ` Lennart Poettering
@ 2009-09-09 16:03 ` pl bossart
0 siblings, 0 replies; 7+ messages in thread
From: pl bossart @ 2009-09-09 16:03 UTC (permalink / raw)
To: alsa-devel
> but why shouldn't this information be queriable from the drivers?
> Drivers do know a lot about the hardware they drive, so they should
> now about clocks, too.
You are correct, drivers typically configure serial audio links to be
master or slave, and what is the clock source. In SoC this would be
done in the dai link configurations. If you had a means to report this
information to userspace then yes you could find out if two interfaces
are in sync. It might be a bit more complex for USB since the standard
specifies different ways of sending audio out.
Cheers
- Pierre
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2009-09-09 16:03 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-03 23:03 Is there a way to figure out if the clocks of two snd_pcm_t's deviate? (snd_pcm_info_get_sync?) Lennart Poettering
2009-09-04 6:44 ` Jaroslav Kysela
2009-09-04 11:44 ` Mark Brown
2009-09-08 23:13 ` Lennart Poettering
2009-09-04 12:52 ` pl bossart
2009-09-08 23:18 ` Lennart Poettering
2009-09-09 16:03 ` pl bossart
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.