[alsa-devel] [RESEND PATCH 3/5] ALSA: pcm: Add snd_pcm_rate_range_to_bits()

Takashi Iwai tiwai at suse.de
Mon Jan 11 09:55:00 CET 2016


On Mon, 11 Jan 2016 06:22:19 +0100,
mengdong.lin at linux.intel.com wrote:
> 
> From: Mengdong Lin <mengdong.lin at linux.intel.com>
> 
> This helper function can convert a given sample rate range to
> SNDRV_PCM_RATE_xxx bits.
> 
> Signed-off-by: Mengdong Lin <mengdong.lin at linux.intel.com>

This function has an implicit assumption: the rates in the given range
have only the pre-defined rates like 44100 or 16000.

In anyway, feel free to take my ack:
  Acked-by: Takashi Iwai <tiwai at suse.de>


Takashi

> 
> diff --git a/include/sound/pcm.h b/include/sound/pcm.h
> index b0be092..af1fb37 100644
> --- a/include/sound/pcm.h
> +++ b/include/sound/pcm.h
> @@ -1093,6 +1093,8 @@ unsigned int snd_pcm_rate_to_rate_bit(unsigned int rate);
>  unsigned int snd_pcm_rate_bit_to_rate(unsigned int rate_bit);
>  unsigned int snd_pcm_rate_mask_intersect(unsigned int rates_a,
>  					 unsigned int rates_b);
> +unsigned int snd_pcm_rate_range_to_bits(unsigned int rate_min,
> +					unsigned int rate_max);
>  
>  /**
>   * snd_pcm_set_runtime_buffer - Set the PCM runtime buffer
> diff --git a/sound/core/pcm_misc.c b/sound/core/pcm_misc.c
> index ebe8444..0b98f51 100644
> --- a/sound/core/pcm_misc.c
> +++ b/sound/core/pcm_misc.c
> @@ -565,3 +565,30 @@ unsigned int snd_pcm_rate_mask_intersect(unsigned int rates_a,
>  	return rates_a & rates_b;
>  }
>  EXPORT_SYMBOL_GPL(snd_pcm_rate_mask_intersect);
> +
> +/**
> + * snd_pcm_rate_range_to_bits - converts rate range to SNDRV_PCM_RATE_xxx bit
> + * @rate_min: the minimum sample rate
> + * @rate_max: the maximum sample rate
> + *
> + * Return: The SNDRV_PCM_RATE_xxx flag that corresponds to the given rate range,
> + * or SNDRV_PCM_RATE_KNOT for an unknown range.
> + */
> +unsigned int snd_pcm_rate_range_to_bits(unsigned int rate_min,
> +	unsigned int rate_max)
> +{
> +	unsigned int rates = 0;
> +	int i;
> +
> +	for (i = 0; i < snd_pcm_known_rates.count; i++) {
> +		if (snd_pcm_known_rates.list[i] >= rate_min
> +			&& snd_pcm_known_rates.list[i] <= rate_max)
> +			rates |= 1 << i;
> +	}
> +
> +	if (!rates)
> +		rates = SNDRV_PCM_RATE_KNOT;
> +
> +	return rates;
> +}
> +EXPORT_SYMBOL_GPL(snd_pcm_rate_range_to_bits);
> -- 
> 2.5.0
> 


More information about the Alsa-devel mailing list