Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Alexander Tsoy <alexander@tsoy.me>
Cc: Gregor Pintar <grpintar@gmail.com>, alsa-devel@alsa-project.org
Subject: Re: [PATCH] ALSA: usb-audio: Apply async workaround for Scarlett 2i4 2nd gen
Date: Wed, 22 Apr 2020 22:28:15 +0200	[thread overview]
Message-ID: <s5heesfxo2o.wl-tiwai@suse.de> (raw)
In-Reply-To: <a45d18d7922d780f29f89cff855eb30fbdd1fce8.camel@tsoy.me>

On Wed, 22 Apr 2020 21:26:23 +0200,
Alexander Tsoy wrote:
> 
> В Ср, 22/04/2020 в 20:55 +0200, Gregor Pintar пишет:
> > On Wed, 22 Apr 2020 Alexander Tsoy wrote:
> > > В Вт, 21/04/2020 в 21:31 +0200, Takashi Iwai пишет:
> > > > I wonder, though, whether we can correct the rounding error in
> > > > the
> > > > driver code, too.
> > > 
> > > I'm not sure if it's possible with currently used Q16.16
> > > arithmetic.
> > 
> > Maybe calculate fixed correction shifts (like it would be feedback)?
> > Something like leap year.
> > 
> > In endpoint.c:
> > static inline unsigned get_usb_high_speed_rate(unsigned int rate)
> > {
> > 	return ((rate << 10) + 62) / 125;
> > }
> > I guess 62 tries to round it, but exact number is needed. So exact
> > value for
> > 44100 should be 361267.2. For 48000 it is 360448.
> > If only we can deliver that 0.2 by shifting rate somehow?
> > 
> > At least maybe it would be better to disable sample rates that do not
> > divide
> > by 1000 on SYNC playback endpoints, if there are others sample rates.
> > 
> > But I'm not familar with the code or USB.
> 
> I think instead of accumulating the fractional part of fs/fps in Q16.16
> format we should accumulating remainder of division fs/fps.
> 
> So for 44100 Hz and High Speed USB the calculations would be:
> 
> fs = 44100
> fps = 8000
> rem = 44100 % 8000 = 4100
> accum = 0
> packet_size_min = 44100 / 8000 = 5
> packet_size_max = 44100 + (8000 - 1) / 8000 = 6
> 
> 
> 1. accum += rem = 4100
>    accum < fps => packet_size = packet_size_min = 5
> 
> 2. accum += rem = 8200
>    accum >= fps => {
>        packet_size = packet_size_max = 6
>        accum -= fps = 200
>    }
> 
> 3. accum += rem = 4300
>    accum < fps => packet_size = packet_size_min = 5
> 
> ...
> 
> 80. accum += rem = 8000
>     accum >= fps => {
>         packet_size = packet_size_max = 6
>         accum -= fps = 0
>     }
> ...

Yeah, something like that is what I had in my mind.
It'd be greatly appreciated if someone can experiment it.
Unfortunately I have no proper USB-audio device now at hands...


thanks,

Takashi

  parent reply	other threads:[~2020-04-22 20:29 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-21 19:09 [PATCH] ALSA: usb-audio: Apply async workaround for Scarlett 2i4 2nd gen Alexander Tsoy
2020-04-21 19:31 ` Takashi Iwai
2020-04-22  3:57   ` Alexander Tsoy
2020-04-22 18:55     ` Gregor Pintar
2020-04-22 19:26       ` Alexander Tsoy
2020-04-22 20:19         ` Alexander Tsoy
2020-04-22 20:28         ` Takashi Iwai [this message]
2020-04-22 23:45           ` Alexander Tsoy
2020-04-23  7:22             ` Takashi Iwai
2020-04-23 11:22               ` Takashi Iwai
2020-04-23 15:10                 ` Alexander Tsoy
2020-04-23 16:57                   ` Alexander Tsoy
2020-04-23 17:29                     ` Takashi Iwai
2020-04-23 17:35                       ` Takashi Iwai
2020-04-23 18:24                         ` Alexander Tsoy
2020-04-26 17:12                           ` Alexander Tsoy
2020-04-27  7:08                             ` Takashi Iwai
2020-04-23 17:32                   ` Takashi Iwai
2020-04-23 11:46             ` Gregor Pintar
2020-04-23 14:01               ` Alexander Tsoy

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=s5heesfxo2o.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alexander@tsoy.me \
    --cc=alsa-devel@alsa-project.org \
    --cc=grpintar@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox