]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - sound/core/pcm_misc.c
[ALSA] Changed Jaroslav Kysela's e-mail from perex@suse.cz to perex@perex.cz
[net-next-2.6.git] / sound / core / pcm_misc.c
index 9142fce4dda2c70f3e7b8dda31093613065661ef..dd9aa51d8c820b0ecfcf1d6999daf50008a41427 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  PCM Interface - misc routines
- *  Copyright (c) 1998 by Jaroslav Kysela <perex@suse.cz>
+ *  Copyright (c) 1998 by Jaroslav Kysela <perex@perex.cz>
  *
  *
  *   This library is free software; you can redistribute it and/or modify
@@ -433,21 +433,16 @@ EXPORT_SYMBOL(snd_pcm_format_set_silence);
  */
 int snd_pcm_limit_hw_rates(struct snd_pcm_runtime *runtime)
 {
-       static unsigned rates[] = {
-               /* ATTENTION: these values depend on the definition in pcm.h! */
-               5512, 8000, 11025, 16000, 22050, 32000, 44100, 48000,
-               64000, 88200, 96000, 176400, 192000
-       };
        int i;
-       for (i = 0; i < (int)ARRAY_SIZE(rates); i++) {
+       for (i = 0; i < (int)snd_pcm_known_rates.count; i++) {
                if (runtime->hw.rates & (1 << i)) {
-                       runtime->hw.rate_min = rates[i];
+                       runtime->hw.rate_min = snd_pcm_known_rates.list[i];
                        break;
                }
        }
-       for (i = (int)ARRAY_SIZE(rates) - 1; i >= 0; i--) {
+       for (i = (int)snd_pcm_known_rates.count - 1; i >= 0; i--) {
                if (runtime->hw.rates & (1 << i)) {
-                       runtime->hw.rate_max = rates[i];
+                       runtime->hw.rate_max = snd_pcm_known_rates.list[i];
                        break;
                }
        }
@@ -455,3 +450,21 @@ int snd_pcm_limit_hw_rates(struct snd_pcm_runtime *runtime)
 }
 
 EXPORT_SYMBOL(snd_pcm_limit_hw_rates);
+
+/**
+ * snd_pcm_rate_to_rate_bit - converts sample rate to SNDRV_PCM_RATE_xxx bit
+ * @rate: the sample rate to convert
+ *
+ * Returns the SNDRV_PCM_RATE_xxx flag that corresponds to the given rate, or
+ * SNDRV_PCM_RATE_KNOT for an unknown rate.
+ */
+unsigned int snd_pcm_rate_to_rate_bit(unsigned int rate)
+{
+       unsigned int i;
+
+       for (i = 0; i < snd_pcm_known_rates.count; i++)
+               if (snd_pcm_known_rates.list[i] == rate)
+                       return 1u << i;
+       return SNDRV_PCM_RATE_KNOT;
+}
+EXPORT_SYMBOL(snd_pcm_rate_to_rate_bit);