[alsa-devel] [PATCH] ALSA: Add params_width() helper

Takashi Iwai tiwai at suse.de
Mon Dec 23 16:01:29 CET 2013


At Mon, 23 Dec 2013 12:48:58 +0000,
Mark Brown wrote:
> 
> From: Mark Brown <broonie at linaro.org>
> 
> Add a helper for obtaining the width of a format directly from params
> since this is expected to become a common operation in ASoC.
> 
> Signed-off-by: Mark Brown <broonie at linaro.org>
> ---
> 
> Just starting on the ASoC changes to use this; I'm not 100% sure on the
> lack of prefixing for the name but it's consistent with the other uses
> so...

It's an inline function, so let's keep the name as is, so far.


>  include/sound/pcm_params.h | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/include/sound/pcm_params.h b/include/sound/pcm_params.h
> index 37ae12e..47b03b4 100644
> --- a/include/sound/pcm_params.h
> +++ b/include/sound/pcm_params.h
> @@ -354,4 +354,10 @@ params_period_bytes(const struct snd_pcm_hw_params *p)
>  		params_channels(p)) / 8;
>  }
>  
> +static inline unsigned int
> +params_width(const struct snd_pcm_hw_params *p)
> +{
> +	return snd_pcm_format_width(params_format(p));
> +}

Better to use (signed) int, as snd_pcm_format_width() may return an
negative error code for some formats.

Also, let's add *_physical_width() variant as well, if we add this.


Takashi


More information about the Alsa-devel mailing list