linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jerome Brunet <jbrunet@baylibre.com>
To: Pavel Hofman <pavel.hofman@ivitera.com>,
	Ruslan Bilovol <ruslan.bilovol@gmail.com>,
	balbi@kernel.org, Takashi Iwai <tiwai@suse.de>
Cc: linux-usb@vger.kernel.org, gschmottlach@gmail.com
Subject: Re: [RFC PATCH v2 3/3] usb: gadget: u_audio: .... PCM Rate Shift for playback too?
Date: Mon, 24 May 2021 17:40:39 +0200	[thread overview]
Message-ID: <1jk0nob0nc.fsf@starbuckisacylon.baylibre.com> (raw)
In-Reply-To: <266cc181-04ed-3204-148a-c658ac35a09f@ivitera.com>


On Mon 24 May 2021 at 14:29, Pavel Hofman <pavel.hofman@ivitera.com> wrote:

> Dne 30. 04. 21 v 16:26 Jerome Brunet napsal(a):
>> From: Ruslan Bilovol <ruslan.bilovol@gmail.com>
>> 
>> This adds interface between userspace and feedback endpoint to report real
>> feedback frequency to the Host.
>> 
>> Current implementation adds new userspace interface ALSA mixer control
>> "Capture Pitch 1000000" (similar to aloop driver's "PCM Rate Shift 100000"
>> mixer control)
>> 
>> Value in PPM is chosen to have correction value agnostic of the actual HW
>> rate, which the application is not necessarily dealing with, while still
>> retaining a good enough precision to allow smooth clock correction on the
>> playback side, if necessary.
>> 
>> Similar to sound/usb/endpoint.c, a slow down is allowed up to 25%. This
>> has no impact on the required bandwidth. Speedup correction has an impact
>> on the bandwidth reserved for the isochronous endpoint. The default
>> allowed speedup is 500ppm. This seems to be more than enough but, if
>> necessary, this is configurable through a module parameter. The reserved
>> bandwidth is rounded up to the next packet size.
>> 
>> Usage of this new control is easy to implement in existing userspace tools
>> like alsaloop from alsa-utils.
>> 
>> Signed-off-by: Ruslan Bilovol <ruslan.bilovol@gmail.com>
>> Signed-off-by: Jerome Brunet <jbrunet@baylibre.com>
>
>
> Hi, the existing patches solve the Host -> Gadget -> capturing
> application direction, controlling the host playback rate. The other
> direction (playback app -> gadget -> capturing host) is still paced by
> the host USB controller. Packet size is pre-calculated in
> u_audio_start_playback  as rate/p_interval
> https://github.com/pavhofman/linux-rpi/blob/rpi-5.10.y/drivers/usb/gadget/function/u_audio.c#L441
> and this fixed value is used for copying the audio data in
> u_audio_iso_complete
> https://github.com/pavhofman/linux-rpi/blob/rpi-5.10.y/drivers/usb/gadget/function/u_audio.c#L124
> .
>
> That means if the gadget has a physical duplex audio device with single
> clock and runs a duplex operation, the path gadget-> host  will not run
> synchronously with the physical audio device (the host -> gadget has
> already the feedback control implemented).
>
> How about "duplicating" the existing ALSA mixer control
> "Capture Pitch 1000000" to "Playback Pitch 1000000" and using
> pitch-adjusted p_srate in the above-linked calculations? That should
> make the playback side run at the playback pitch requested by gadget
> userspace, IIUC.
>
> For the duplex operation with single clock, the capture pitch value
> determined by the userspace chain (alsaloop, CamillaDSP, etc.) would be
> used for setting both the capture and playback pitch controls, making
> both directions run synchronously.
>
> I can prepare patches based on Jerome's patchset should you find this
> solution acceptable.

Well I have experimented with pitch on the playback path.
It does work but I'm not sure if it actually makes sense which is why I
have not not included it in RFC

If you need the playback and capture to run synchronously, you'd be
better off with implicit feedback (In which the host will provide the
same number of samples it received from the device)

With explicit feedback, we are (supposed) to tell the host to speed up
or slow down to match the device clock. This means the device run
asynchronously, and the host does the adaptation (if necessary). In such
case, I'm not sure adding pitch control on the playback path is a good
idea.

Having pitch control on the playback side allows to forward the audio
captured by the physical interface of the device (like I2S) to USB
without performing any resampling between the two (when USB and I2S are
not in sync). It's nice and convenient ... but I wonder if this is a
feature or a hack ;)

>
> Thanks a lot,
>
> Pavel.


  reply	other threads:[~2021-05-24 16:09 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-30 14:26 [RFC PATCH v2 0/3] UAC2 Gadget: feedback endpoint support Jerome Brunet
2021-04-30 14:26 ` [RFC PATCH v2 1/3] usb: gadget: f_uac2/u_audio: add " Jerome Brunet
2021-04-30 14:55   ` Pavel Hofman
2021-04-30 17:09     ` Jerome Brunet
2021-04-30 17:11       ` Jerome Brunet
2021-04-30 20:41         ` Pavel Hofman
2021-05-24 12:04         ` Pavel Hofman
2021-04-30 14:26 ` [RFC PATCH v2 2/3] usb: gadget: f_uac2: add adaptive sync support for capture Jerome Brunet
2021-04-30 14:26 ` [RFC PATCH v2 3/3] usb: gadget: u_audio: add real feedback implementation Jerome Brunet
2021-05-24 12:29   ` [RFC PATCH v2 3/3] usb: gadget: u_audio: .... PCM Rate Shift for playback too? Pavel Hofman
2021-05-24 15:40     ` Jerome Brunet [this message]
2021-05-24 16:09       ` Pavel Hofman
2021-05-27  6:52         ` Pavel Hofman
2021-05-27  9:52           ` Jerome Brunet
2021-05-27 12:36             ` Pavel Hofman

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=1jk0nob0nc.fsf@starbuckisacylon.baylibre.com \
    --to=jbrunet@baylibre.com \
    --cc=balbi@kernel.org \
    --cc=gschmottlach@gmail.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=pavel.hofman@ivitera.com \
    --cc=ruslan.bilovol@gmail.com \
    --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 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).