Skip to content

Commit e3a9269

Browse files
larsclausenbroonie
authored andcommitted
ALSA: Add helper function for intersecting two rate masks
A bit of special care is necessary when creating the intersection of two rate masks. This comes from the special meaning of the SNDRV_PCM_RATE_CONTINUOUS and SNDRV_PCM_RATE_KNOT bits, which needs special handling when intersecting two rate masks. SNDRV_PCM_RATE_CONTINUOUS means the hardware supports all rates in a specific interval. SNDRV_PCM_RATE_KNOT means the hardware supports a set of discrete rates specified by a list constraint. For all other cases the supported rates are specified directly in the rate mask. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Reviewed-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Mark Brown <broonie@linaro.org>
1 parent bf103eb commit e3a9269

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

‎include/sound/pcm.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,8 @@ extern const struct snd_pcm_hw_constraint_list snd_pcm_known_rates;
901901
int snd_pcm_limit_hw_rates(struct snd_pcm_runtime *runtime);
902902
unsigned int snd_pcm_rate_to_rate_bit(unsigned int rate);
903903
unsigned int snd_pcm_rate_bit_to_rate(unsigned int rate_bit);
904+
unsigned int snd_pcm_rate_mask_intersect(unsigned int rates_a,
905+
unsigned int rates_b);
904906

905907
static inline void snd_pcm_set_runtime_buffer(struct snd_pcm_substream *substream,
906908
struct snd_dma_buffer *bufp)

‎sound/core/pcm_misc.c‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,3 +514,42 @@ unsigned int snd_pcm_rate_bit_to_rate(unsigned int rate_bit)
514514
return 0;
515515
}
516516
EXPORT_SYMBOL(snd_pcm_rate_bit_to_rate);
517+
518+
static unsigned int snd_pcm_rate_mask_sanitize(unsigned int rates)
519+
{
520+
if (rates & SNDRV_PCM_RATE_CONTINUOUS)
521+
return SNDRV_PCM_RATE_CONTINUOUS;
522+
else if (rates & SNDRV_PCM_RATE_KNOT)
523+
return SNDRV_PCM_RATE_KNOT;
524+
return rates;
525+
}
526+
527+
/**
528+
* snd_pcm_rate_mask_intersect - computes the intersection between two rate masks
529+
* @rates_a: The first rate mask
530+
* @rates_b: The second rate mask
531+
*
532+
* This function computes the rates that are supported by both rate masks passed
533+
* to the function. It will take care of the special handling of
534+
* SNDRV_PCM_RATE_CONTINUOUS and SNDRV_PCM_RATE_KNOT.
535+
*
536+
* Return: A rate mask containing the rates that are supported by both rates_a
537+
* and rates_b.
538+
*/
539+
unsigned int snd_pcm_rate_mask_intersect(unsigned int rates_a,
540+
unsigned int rates_b)
541+
{
542+
rates_a = snd_pcm_rate_mask_sanitize(rates_a);
543+
rates_b = snd_pcm_rate_mask_sanitize(rates_b);
544+
545+
if (rates_a & SNDRV_PCM_RATE_CONTINUOUS)
546+
return rates_b;
547+
else if (rates_b & SNDRV_PCM_RATE_CONTINUOUS)
548+
return rates_a;
549+
else if (rates_a & SNDRV_PCM_RATE_KNOT)
550+
return rates_b;
551+
else if (rates_b & SNDRV_PCM_RATE_KNOT)
552+
return rates_a;
553+
return rates_a & rates_b;
554+
}
555+
EXPORT_SYMBOL_GPL(snd_pcm_rate_mask_intersect);

0 commit comments

Comments
 (0)