All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Cc: ffado-devel@lists.sourceforge.net, alsa-devel@alsa-project.org,
	clemens@ladisch.de
Subject: Re: [PATCH v2 04/13] ALSA: dice: cache stream formats at current mode of sampling transmission frequency
Date: Tue, 01 May 2018 08:54:59 +0200	[thread overview]
Message-ID: <s5ho9hzvpa4.wl-tiwai@suse.de> (raw)
In-Reply-To: <2a3d530a-5a03-0760-21b5-6e74fd2503e5@sakamocchi.jp>

On Tue, 01 May 2018 05:02:09 +0200,
Takashi Sakamoto wrote:
> 
> Hi,
> 
> On May 1 2018 00:10, Takashi Iwai wrote:
> > On Sun, 29 Apr 2018 08:50:23 +0200,
> > Takashi Sakamoto wrote:
> >>
> >> In former commits, proxy structure get members for cache of stream
> >> formats. This commit fills the cache with stream formats at current mode
> >> of sampling transmission frequency.
> >>
> >> Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
> >> ---
> >>   sound/firewire/dice/dice-stream.c | 76 +++++++++++++++++++++++++++++++++++++++
> >>   sound/firewire/dice/dice.c        |  4 +++
> >>   sound/firewire/dice/dice.h        |  3 ++
> >>   3 files changed, 83 insertions(+)
> >>
> >> diff --git a/sound/firewire/dice/dice-stream.c b/sound/firewire/dice/dice-stream.c
> >> index 928a255bfc35..2a9f0cd994a5 100644
> >> --- a/sound/firewire/dice/dice-stream.c
> >> +++ b/sound/firewire/dice/dice-stream.c
> >> @@ -30,6 +30,24 @@ const unsigned int snd_dice_rates[SND_DICE_RATES_COUNT] = {
> >>   	[6] = 192000,
> >>   };
> >>   +int snd_dice_stream_get_rate_mode(struct snd_dice *dice,
> >> unsigned int rate,
> >> +				  unsigned int *mode)
> >> +{
> >> +	int i;
> >> +
> >> +	for (i = 0; i < ARRAY_SIZE(snd_dice_rates); i++) {
> >> +		if (!(dice->clock_caps & BIT(i)))
> >> +			continue;
> >> +		if (snd_dice_rates[i] != rate)
> >> +			continue;
> >> +
> >> +		*mode = (i - 1) / 2;
> >
> > What if i=0?  It'll be a negative value?
> 
> Yes. But division by 2 to -1 results in 0 because in C language
> specification 'truncate toward zero'[1] is applied to discard
> fractional part. Then, the result is assigned to value of 'unsigned int'
> type. As a result:
> 
> 0: 32000/44100/48000
> 1: 88200/96000
> 2: 176400/192000
> 
> This is what I expect.
> 
> [1] footnote for '6.5.5 Multiplicative operators' clause in ISO/IEC 9899.

This is too tricky.  The result would change dramatically when i were
declared as unsigned.

And I can think of someone trying to change it unsigned because of the
comparison against ARRAY_SIZE() (we've got gcc warnings for that in
the past).

Please make either it more robust or put a proper comment.


thanks,

Takashi

  reply	other threads:[~2018-05-01  6:55 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-29  6:50 [PATCH v2 00/13] ALSA: dice: use cache of stream formats to generate PCM rules/constraints Takashi Sakamoto
2018-04-29  6:50 ` [PATCH v2 01/13] ALSA: dice: add cache of stream formats Takashi Sakamoto
2018-04-29  6:50 ` [PATCH v2 02/13] ALSA: dice: add 'firewire' directory for proc nodes Takashi Sakamoto
2018-04-29  6:50 ` [PATCH v2 03/13] ALSA: dice: add proc node for stream formation Takashi Sakamoto
2018-04-30 15:12   ` Takashi Iwai
2018-05-01  3:06     ` Takashi Sakamoto
2018-04-29  6:50 ` [PATCH v2 04/13] ALSA: dice: cache stream formats at current mode of sampling transmission frequency Takashi Sakamoto
2018-04-30 15:10   ` Takashi Iwai
2018-05-01  3:02     ` Takashi Sakamoto
2018-05-01  6:54       ` Takashi Iwai [this message]
2018-05-01  9:14         ` Takashi Sakamoto
2018-05-01  9:25           ` Takashi Iwai
2018-04-29  6:50 ` [PATCH v2 05/13] ALSA: dice: add parameters of stream formats for models produced by TC Electronic Takashi Sakamoto
2018-04-29  6:50 ` [PATCH v2 06/13] ALSA: dice: add parameters of stream formats for models produced by Alesis Takashi Sakamoto
2018-04-29  6:50 ` [PATCH v2 07/13] ALSA: dice: use extended protocol to detect available stream formats Takashi Sakamoto
2018-04-29  6:50 ` [PATCH v2 08/13] ALSA: dice: use cache of stream format to check running stream Takashi Sakamoto
2018-04-29  6:50 ` [PATCH v2 09/13] ALSA: dice: add a helper function to restart all of available streams Takashi Sakamoto
2018-04-29  6:50 ` [PATCH v2 10/13] ALSA: dice: enable to change current sampling transmission frequency Takashi Sakamoto
2018-04-29  6:50 ` [PATCH v2 11/13] ALSA: dice: use stream formats to add MIDI substreams Takashi Sakamoto
2018-04-29  6:50 ` [PATCH v2 12/13] ALSA: dice: use cache for PCM constraints and rules Takashi Sakamoto
2018-04-29  6:50 ` [PATCH v2 13/13] ALSA: dice: remove local frag of force_two_pcms Takashi Sakamoto

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=s5ho9hzvpa4.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=clemens@ladisch.de \
    --cc=ffado-devel@lists.sourceforge.net \
    --cc=o-takashi@sakamocchi.jp \
    /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.