aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/sound/pcm.h2
-rw-r--r--sound/core/pcm_misc.c30
2 files changed, 32 insertions, 0 deletions
diff --git a/include/sound/pcm.h b/include/sound/pcm.h
index b0be09279943..af1fb37c6b26 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);
1093unsigned int snd_pcm_rate_bit_to_rate(unsigned int rate_bit); 1093unsigned int snd_pcm_rate_bit_to_rate(unsigned int rate_bit);
1094unsigned int snd_pcm_rate_mask_intersect(unsigned int rates_a, 1094unsigned int snd_pcm_rate_mask_intersect(unsigned int rates_a,
1095 unsigned int rates_b); 1095 unsigned int rates_b);
1096unsigned int snd_pcm_rate_range_to_bits(unsigned int rate_min,
1097 unsigned int rate_max);
1096 1098
1097/** 1099/**
1098 * snd_pcm_set_runtime_buffer - Set the PCM runtime buffer 1100 * 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 ebe8444de6c6..53dc37357bca 100644
--- a/sound/core/pcm_misc.c
+++ b/sound/core/pcm_misc.c
@@ -565,3 +565,33 @@ unsigned int snd_pcm_rate_mask_intersect(unsigned int rates_a,
565 return rates_a & rates_b; 565 return rates_a & rates_b;
566} 566}
567EXPORT_SYMBOL_GPL(snd_pcm_rate_mask_intersect); 567EXPORT_SYMBOL_GPL(snd_pcm_rate_mask_intersect);
568
569/**
570 * snd_pcm_rate_range_to_bits - converts rate range to SNDRV_PCM_RATE_xxx bit
571 * @rate_min: the minimum sample rate
572 * @rate_max: the maximum sample rate
573 *
574 * This function has an implicit assumption: the rates in the given range have
575 * only the pre-defined rates like 44100 or 16000.
576 *
577 * Return: The SNDRV_PCM_RATE_xxx flag that corresponds to the given rate range,
578 * or SNDRV_PCM_RATE_KNOT for an unknown range.
579 */
580unsigned int snd_pcm_rate_range_to_bits(unsigned int rate_min,
581 unsigned int rate_max)
582{
583 unsigned int rates = 0;
584 int i;
585
586 for (i = 0; i < snd_pcm_known_rates.count; i++) {
587 if (snd_pcm_known_rates.list[i] >= rate_min
588 && snd_pcm_known_rates.list[i] <= rate_max)
589 rates |= 1 << i;
590 }
591
592 if (!rates)
593 rates = SNDRV_PCM_RATE_KNOT;
594
595 return rates;
596}
597EXPORT_SYMBOL_GPL(snd_pcm_rate_range_to_bits);