alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v5] ASoC: Apply msbits constraint for sample size bigger than the msbits
@ 2012-01-18 15:05 Peter Ujfalusi
  2012-01-18 15:29 ` Mark Brown
  2012-01-18 15:35 ` Clemens Ladisch
  0 siblings, 2 replies; 11+ messages in thread
From: Peter Ujfalusi @ 2012-01-18 15:05 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood; +Cc: alsa-devel

In order to avoid confusing the applications with msbits bigger
than the selected sample size apply the msbits constraint only
to sample seze bigger than the requested msbits.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---

Hi Mark,

Converted to use while loop.
We run the loop as long as the sample size is bigger than the requested
msbits.
Most of the drivers require 24/32 configuration, so not point of looping
for smaller sample sizes.

Regards,
Peter

 sound/soc/soc-pcm.c |   17 +++++++++--------
 1 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
index 8bb1793..ef41a39 100644
--- a/sound/soc/soc-pcm.c
+++ b/sound/soc/soc-pcm.c
@@ -68,13 +68,14 @@ static int soc_pcm_apply_symmetry(struct snd_pcm_substream *substream,
  * like the DAC/ADC resolution to use but there isn't right now.
  */
 static int sample_sizes[] = {
-	8, 16, 24, 32,
+	32, 24, 16, 8,
 };
 
 static void soc_pcm_apply_msb(struct snd_pcm_substream *substream,
 			      struct snd_soc_dai *dai)
 {
-	int ret, i, bits;
+	int ret, bits;
+	int i = 0;
 
 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
 		bits = dai->driver->playback.sig_bits;
@@ -84,14 +85,14 @@ static void soc_pcm_apply_msb(struct snd_pcm_substream *substream,
 	if (!bits)
 		return;
 
-	for (i = 0; i < ARRAY_SIZE(sample_sizes); i++) {
-		ret = snd_pcm_hw_constraint_msbits(substream->runtime,
-						   0, sample_sizes[i],
-						   bits);
+	/* Apply constraint only for sample size bigger than requested msbits */
+	while (sample_sizes[i] > bits && i < ARRAY_SIZE(sample_sizes)) {
+		ret = snd_pcm_hw_constraint_msbits(substream->runtime, 0,
+						   sample_sizes[i], bits);
 		if (ret != 0)
-			dev_warn(dai->dev,
-				 "Failed to set MSB %d/%d: %d\n",
+			dev_warn(dai->dev, "Failed to set MSB %d/%d: %d\n",
 				 bits, sample_sizes[i], ret);
+		i++;
 	}
 }
 
-- 
1.7.8.3

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH v5] ASoC: Apply msbits constraint for sample size bigger than the msbits
  2012-01-18 15:05 [PATCH v5] ASoC: Apply msbits constraint for sample size bigger than the msbits Peter Ujfalusi
@ 2012-01-18 15:29 ` Mark Brown
  2012-01-18 16:43   ` Peter Ujfalusi
  2012-01-18 15:35 ` Clemens Ladisch
  1 sibling, 1 reply; 11+ messages in thread
From: Mark Brown @ 2012-01-18 15:29 UTC (permalink / raw)
  To: Peter Ujfalusi; +Cc: alsa-devel, Liam Girdwood

On Wed, Jan 18, 2012 at 04:05:14PM +0100, Peter Ujfalusi wrote:

> Converted to use while loop.
> We run the loop as long as the sample size is bigger than the requested
> msbits.

I'm not sure this is actually a legibility improvement, if anything it's
probably less clear than the original as now the setup of the loop is
spread even further around the function.

> Most of the drivers require 24/32 configuration, so not point of looping
> for smaller sample sizes.

Performance isn't really a concern in this path unless we do something
totally insane.  Thinking time on the part of the reader needs to be
considered too...

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v5] ASoC: Apply msbits constraint for sample size bigger than the msbits
  2012-01-18 15:05 [PATCH v5] ASoC: Apply msbits constraint for sample size bigger than the msbits Peter Ujfalusi
  2012-01-18 15:29 ` Mark Brown
@ 2012-01-18 15:35 ` Clemens Ladisch
  2012-01-18 15:43   ` Peter Ujfalusi
  1 sibling, 1 reply; 11+ messages in thread
From: Clemens Ladisch @ 2012-01-18 15:35 UTC (permalink / raw)
  To: Peter Ujfalusi; +Cc: alsa-devel, Mark Brown, Liam Girdwood

Peter Ujfalusi wrote:
> We run the loop as long as the sample size is bigger than the requested
> msbits.

> +	while (sample_sizes[i] > bits && i < ARRAY_SIZE(sample_sizes)) {

This will overrun sample_sizes[] if bits < 8.


Regards,
Clemens

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v5] ASoC: Apply msbits constraint for sample size bigger than the msbits
  2012-01-18 15:35 ` Clemens Ladisch
@ 2012-01-18 15:43   ` Peter Ujfalusi
  2012-01-18 15:49     ` Peter Ujfalusi
  0 siblings, 1 reply; 11+ messages in thread
From: Peter Ujfalusi @ 2012-01-18 15:43 UTC (permalink / raw)
  To: Clemens Ladisch; +Cc: alsa-devel, Mark Brown, Liam Girdwood

On 01/18/2012 04:35 PM, Clemens Ladisch wrote:
> Peter Ujfalusi wrote:
>> We run the loop as long as the sample size is bigger than the requested
>> msbits.
> 
>> +	while (sample_sizes[i] > bits && i < ARRAY_SIZE(sample_sizes)) {
> 
> This will overrun sample_sizes[] if bits < 8.

which is prevented by the: && i < ARRAY_SIZE(sample_sizes)

-- 
Péter

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v5] ASoC: Apply msbits constraint for sample size bigger than the msbits
  2012-01-18 15:43   ` Peter Ujfalusi
@ 2012-01-18 15:49     ` Peter Ujfalusi
  0 siblings, 0 replies; 11+ messages in thread
From: Peter Ujfalusi @ 2012-01-18 15:49 UTC (permalink / raw)
  To: Clemens Ladisch; +Cc: alsa-devel, Mark Brown, Liam Girdwood

On 01/18/2012 04:43 PM, Peter Ujfalusi wrote:
> On 01/18/2012 04:35 PM, Clemens Ladisch wrote:
>> Peter Ujfalusi wrote:
>>> We run the loop as long as the sample size is bigger than the requested
>>> msbits.
>>
>>> +	while (sample_sizes[i] > bits && i < ARRAY_SIZE(sample_sizes)) {
>>
>> This will overrun sample_sizes[] if bits < 8.
> 
> which is prevented by the: && i < ARRAY_SIZE(sample_sizes)

I take it back. True, we overrun. These need to be swapped.

-- 
Péter

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v5] ASoC: Apply msbits constraint for sample size bigger than the msbits
  2012-01-18 15:29 ` Mark Brown
@ 2012-01-18 16:43   ` Peter Ujfalusi
  2012-01-18 17:46     ` Mark Brown
  0 siblings, 1 reply; 11+ messages in thread
From: Peter Ujfalusi @ 2012-01-18 16:43 UTC (permalink / raw)
  To: Mark Brown; +Cc: alsa-devel, Liam Girdwood

On 01/18/2012 04:29 PM, Mark Brown wrote:
> I'm not sure this is actually a legibility improvement, if anything it's
> probably less clear than the original as now the setup of the loop is
> spread even further around the function.

Would it make it clearer if I set i to 0 right before the while?

>> Most of the drivers require 24/32 configuration, so not point of looping
>> for smaller sample sizes.
> 
> Performance isn't really a concern in this path unless we do something
> totally insane.  Thinking time on the part of the reader needs to be
> considered too...

Sure it is not a concern. These small 'Performance isn't really a
concern in this path' at the end ads up that we need faster CPUs to have
the same perceived perfomrance.

-- 
Péter

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v5] ASoC: Apply msbits constraint for sample size bigger than the msbits
  2012-01-18 16:43   ` Peter Ujfalusi
@ 2012-01-18 17:46     ` Mark Brown
  2012-01-19  8:27       ` Peter Ujfalusi
  0 siblings, 1 reply; 11+ messages in thread
From: Mark Brown @ 2012-01-18 17:46 UTC (permalink / raw)
  To: Peter Ujfalusi; +Cc: alsa-devel, Liam Girdwood

On Wed, Jan 18, 2012 at 05:43:28PM +0100, Peter Ujfalusi wrote:
> On 01/18/2012 04:29 PM, Mark Brown wrote:
> > I'm not sure this is actually a legibility improvement, if anything it's
> > probably less clear than the original as now the setup of the loop is
> > spread even further around the function.

> Would it make it clearer if I set i to 0 right before the while?

That'd help a bit.  Though I'd just go with a for loop, the while
clearly doesn't look any better - I was just suggesting it without
actually having tried writing it out.

> > Performance isn't really a concern in this path unless we do something
> > totally insane.  Thinking time on the part of the reader needs to be
> > considered too...

> Sure it is not a concern. These small 'Performance isn't really a
> concern in this path' at the end ads up that we need faster CPUs to have
> the same perceived perfomrance.

Yeah, but if that percieved performance is already instantaneous there's
no need to worry :)  My first thought would've been to just continue on
sample rates we don't like rather than trying to break out of an
iteration of 4 steps early.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v5] ASoC: Apply msbits constraint for sample size bigger than the msbits
  2012-01-18 17:46     ` Mark Brown
@ 2012-01-19  8:27       ` Peter Ujfalusi
  2012-01-19 10:48         ` Mark Brown
  0 siblings, 1 reply; 11+ messages in thread
From: Peter Ujfalusi @ 2012-01-19  8:27 UTC (permalink / raw)
  To: Mark Brown; +Cc: alsa-devel, Liam Girdwood

On 01/18/2012 06:46 PM, Mark Brown wrote:
> That'd help a bit.  Though I'd just go with a for loop, the while
> clearly doesn't look any better - I was just suggesting it without
> actually having tried writing it out.

Are you going to take the for version of patch, or should I resend it?
I can add a comment to explain that we bail out, and not checking the
sample sizes lower than the requested msbits, if it helps.

-- 
Péter

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v5] ASoC: Apply msbits constraint for sample size bigger than the msbits
  2012-01-19  8:27       ` Peter Ujfalusi
@ 2012-01-19 10:48         ` Mark Brown
  2012-01-19 12:40           ` Peter Ujfalusi
  0 siblings, 1 reply; 11+ messages in thread
From: Mark Brown @ 2012-01-19 10:48 UTC (permalink / raw)
  To: Peter Ujfalusi; +Cc: alsa-devel, Liam Girdwood

On Thu, Jan 19, 2012 at 09:27:33AM +0100, Peter Ujfalusi wrote:

> Are you going to take the for version of patch, or should I resend it?
> I can add a comment to explain that we bail out, and not checking the
> sample sizes lower than the requested msbits, if it helps.

I'd just replace it with a continue on sizes we don't want, much
simpler.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v5] ASoC: Apply msbits constraint for sample size bigger than the msbits
  2012-01-19 10:48         ` Mark Brown
@ 2012-01-19 12:40           ` Peter Ujfalusi
  2012-01-19 15:39             ` Mark Brown
  0 siblings, 1 reply; 11+ messages in thread
From: Peter Ujfalusi @ 2012-01-19 12:40 UTC (permalink / raw)
  To: Mark Brown; +Cc: alsa-devel, Liam Girdwood

On 01/19/2012 11:48 AM, Mark Brown wrote:
> On Thu, Jan 19, 2012 at 09:27:33AM +0100, Peter Ujfalusi wrote:
> 
>> Are you going to take the for version of patch, or should I resend it?
>> I can add a comment to explain that we bail out, and not checking the
>> sample sizes lower than the requested msbits, if it helps.
> 
> I'd just replace it with a continue on sizes we don't want, much
> simpler.

If I can do this (bits == 24):
i = 0
check (i < ARRAY_SIZE(sample_sizes))
check (sample_sizes[i] <= bits)
 apply constraint
i++
check (i < ARRAY_SIZE(sample_sizes))
check (sample_sizes[i] <= bits)
 go out

--------------------------------------
I will not do this (bits == 24):
static int sample_sizes[] = {
	8, 16, 24, 32,
};

i = 0
check (i < ARRAY_SIZE(sample_sizes))
check (sample_sizes[i] > bits)
i++
check (i < ARRAY_SIZE(sample_sizes))
check (sample_sizes[i] > bits)
i++
check (i < ARRAY_SIZE(sample_sizes))
check (sample_sizes[i] > bits)
i++
check (i < ARRAY_SIZE(sample_sizes))
check (sample_sizes[i] > bits)
 apply constraint
i++
check (i < ARRAY_SIZE(sample_sizes))
 go out

--------------------------------------
nor this (bits == 24):
static int sample_sizes[] = {
	32, 24, 16, 8,
};

i = 0
check (i < ARRAY_SIZE(sample_sizes))
check (sample_sizes[i] <= bits)
 apply constraint
i++
check (i < ARRAY_SIZE(sample_sizes))
check (sample_sizes[i] <= bits)
i++
check (i < ARRAY_SIZE(sample_sizes))
check (sample_sizes[i] <= bits)
i++
check (i < ARRAY_SIZE(sample_sizes))
check (sample_sizes[i] <= bits)
i++
check (i < ARRAY_SIZE(sample_sizes))
 go out

-- 
Péter

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v5] ASoC: Apply msbits constraint for sample size bigger than the msbits
  2012-01-19 12:40           ` Peter Ujfalusi
@ 2012-01-19 15:39             ` Mark Brown
  0 siblings, 0 replies; 11+ messages in thread
From: Mark Brown @ 2012-01-19 15:39 UTC (permalink / raw)
  To: Peter Ujfalusi; +Cc: alsa-devel, Liam Girdwood

On Thu, Jan 19, 2012 at 01:40:35PM +0100, Peter Ujfalusi wrote:
> On 01/19/2012 11:48 AM, Mark Brown wrote:

> > I'd just replace it with a continue on sizes we don't want, much
> > simpler.

> If I can do this (bits == 24):

This mail took me a little while to parse but I think you're trying to
say you insist on the microoptimisation.  Unless you can come up with a
microoptimisation which doesn't take effort to read please write
something simple.  The reason I wasn't happy with the original patch was
that what should be a trivial bit of code took far too long to check.
Maintainability is vastly more important than microoptimising a slow
path, having to read things again later was the whole reason I didn't do
any filtering in the first place.

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2012-01-19 15:39 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-18 15:05 [PATCH v5] ASoC: Apply msbits constraint for sample size bigger than the msbits Peter Ujfalusi
2012-01-18 15:29 ` Mark Brown
2012-01-18 16:43   ` Peter Ujfalusi
2012-01-18 17:46     ` Mark Brown
2012-01-19  8:27       ` Peter Ujfalusi
2012-01-19 10:48         ` Mark Brown
2012-01-19 12:40           ` Peter Ujfalusi
2012-01-19 15:39             ` Mark Brown
2012-01-18 15:35 ` Clemens Ladisch
2012-01-18 15:43   ` Peter Ujfalusi
2012-01-18 15:49     ` Peter Ujfalusi

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).