All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Sakamoto <o-takashi@sakamocchi.jp>
To: Michele Perrone <michele.perrone@weiss.ch>
Cc: Takashi Iwai <tiwai@suse.de>,
	Rolf Anderegg <rolf.anderegg@weiss.ch>,
	alsa-devel@alsa-project.org
Subject: Re: Re: MAN301 external clock issues (Re: [PATCH] ALSA: dice: add stream format parameters for Weiss devices)
Date: Sun, 24 Sep 2023 11:16:17 +0900	[thread overview]
Message-ID: <20230924021617.GA298150@workstation.local> (raw)
In-Reply-To: <2644a27e-aa51-4d11-9890-988c02f9631e@weiss.ch>

Hi,

On Wed, Sep 20, 2023 at 12:25:07PM +0200, Michele Perrone wrote:
>    Hi Takashi,
> 
>    On 19/09/23 16:09, Takashi Sakamoto wrote:
> 
> For the case of external source of clock, you need to configure the
> sampling rate in device by your hand, by accesing to GLOBAL_CLOCK_SELECT
> offset in global section of TCAT protocol.
> 
>    I'm able to do this from the kernel space, but I wouldn't know how to
>    achieve this in the user-space without switching back and forth between
>    internal and external clock source.
>    Moreover, there seems to be no 'write' handler installed inside
>    'snd_dice_create_hwdep()'[2], so using 'snd_hwdep_write()' from
>    user-space ALSA is not possible.

>    The only option I see is adding a new control to
>    'snd_kcontrol_new controls[]'[3], inside 'dice_snd_ctl_construct()'[3]
>    in our AV/C code.
>    But I don't think this is the best solution, in view of the fact the we
>    will be switching to snd-firewire-ctl-services[4] in the near future.
>
> I programmed ALSA dice driver to behave like that.
> 
> The driver configures the target device for sampling rate which ALSA PCM
> application expects when the device uses internal source of clock. When
> the device is configured to use external source of clock, the driver
> adds constrains to ALSA PCM hardware configuration so that the application
> works with current sampling rate configured in device.
> 
>    Thanks for explaining this. I have now found the place in the code
>    where
>    you do this[1].
>    May I ask, what is the reason for this limitation? I don't see any
>    relevant connection between that last used internal sampling rate, and
>    the current external sampling rate.
>    Moreover, the DICE driver is able to see the external sampling rate in
>    real-time. So when the external clock rate is selected and locked,
>    wouldn't it make sense that the device rate followed the external rate
>    automatically, without user-space intervention?

In TCAT general protocol, we can find several fields for detected
sampling frequency[1].

* STATUS_NOMINAL_RATE_MASK (offset 0x54 in global section)
* GLOBAL_SAMPLE_RATE (offset 0x5c in global section)
* EXT_SYNC_RATE (offset 0x08 in external sync section)

The last two of them are extension or optional, thus we assume that all of
models with DICE ASICs do not necessarily support them. As long as I
investigate, the first is just for detected nominal sampling transfer
frequency in incoming IEC 61883-6 stream which is locked, against your
expectation.

When supporting all of models with DICE ASICs in market and firmware, it
is inevitable not to rely on the auto-detection you mentioned. Actually,
old version of firmware does not support GLOBAL_SAMPLE_RATE. Furthermore,
we have a few models which support external sync section.

Just for models provided by Weiss Engineering, additional kctl could be
one of solution as you mentioned, but it seems to be hard for upstreaming
due to the reason, sorry.


Well, in the protocol, the device can send notification to registered
offset of node ID for several purposes. You can see below events in the
driver code:

* NOTIFY_RX_CFG_CHG
* NOTIFY_TX_CFG_CHG
* NOTIFY_LOCK_CHG
* NOTIFY_CLOCK_ACCEPTED
* NOTIFY_EXT_STATUS

For your issue, observation of lock-change, clock-accepted, and ext-status
notifications is useful, I think. The ALSA HwDep character device added
by ALSA dice driver is mainly for the notification[2]. When receiving the
notification, the driver cache the message and allow the user space
application to read it.

I maintain libhitaki[3] for convenience to such user space application.
Hitaki.SndDice implements Hitaki.QuadletNotification::notified GObject
signal[4], which is emitted when reading the notification. The library
supports GObject Introspection[5] to provide language bindings such as
PyGObject[6] and gtk-rs/gir[7].

You can see rough Python 3 sample to print the notification[8].


[1] See 'sound/firewire/dice/dice-interface.h' in Linux kernel
[2] https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git/commit/include/uapi/sound/firewire.h?id=82fbb4f7b476
[3] https://github.com/alsa-project/libhitaki
[4] https://alsa-project.github.io/gobject-introspection-docs/hitaki/class.SndDice.html
[5] https://gi.readthedocs.io/en/latest/
[6] https://pygobject.readthedocs.io/en/latest/
[7] https://gtk-rs.org/gir/book/
[8] https://gist.github.com/takaswie/673a7f83964f7986d3f1e4e9b86cde03


Regards

Takashi Sakamoto

      reply	other threads:[~2023-09-24  2:19 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <99c82e03-7323-4d4d-8ced-7fd773138f6e@weiss.ch>
2023-09-20 10:25 ` Fwd: Re: MAN301 external clock issues (Re: [PATCH] ALSA: dice: add stream format parameters for Weiss devices) Michele Perrone
2023-09-24  2:16   ` Takashi Sakamoto [this message]

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=20230924021617.GA298150@workstation.local \
    --to=o-takashi@sakamocchi.jp \
    --cc=alsa-devel@alsa-project.org \
    --cc=michele.perrone@weiss.ch \
    --cc=rolf.anderegg@weiss.ch \
    --cc=tiwai@suse.de \
    /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.