alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: mengdong.lin@linux.intel.com
To: alsa-devel@alsa-project.org, broonie@kernel.org
Cc: Mengdong Lin <mengdong.lin@linux.intel.com>,
	tiwai@suse.de, mengdong.lin@intel.com,
	liam.r.girdwood@linux.intel.com, vinod.koul@intel.com,
	jeeja.kp@intel.com, subhransu.s.prusty@intel.com
Subject: [RESEND PATCH 3/5] ALSA: pcm: Add snd_pcm_rate_range_to_bits()
Date: Mon, 11 Jan 2016 13:22:19 +0800	[thread overview]
Message-ID: <1452489739-25720-1-git-send-email-mengdong.lin@linux.intel.com> (raw)
In-Reply-To: <712e57698a4144889318549d3b20ba2eaaa9c36b.1451550513.git.mengdong.lin@linux.intel.com>

From: Mengdong Lin <mengdong.lin@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@linux.intel.com>

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

  parent reply	other threads:[~2016-01-11  5:22 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-31  8:35 [PATCH 0/5] ASoC: topology: Add support for FE DAI & DAI links mengdong.lin
2015-12-31  8:40 ` [PATCH 1/5] ASoC: Define soc_add_dai() to add a DAI to a component mengdong.lin
2016-01-10 12:07   ` Applied "ASoC: Define soc_add_dai() to add a DAI to a component" to the asoc tree Mark Brown
2015-12-31  8:40 ` [PATCH 2/5] ASoC: Support registering a DAI dynamically mengdong.lin
2016-01-10 12:07   ` Applied "ASoC: Support registering a DAI dynamically" to the asoc tree Mark Brown
2015-12-31  8:40 ` [PATCH 3/5] ALSA: pcm: Add snd_pcm_rate_range_to_bits() mengdong.lin
2016-01-10 12:03   ` Mark Brown
2016-01-11  5:22   ` mengdong.lin [this message]
2016-01-11  8:55     ` [RESEND PATCH " Takashi Iwai
2015-12-31  8:41 ` [PATCH 4/5] ASoC: topology: Add FE DAIs dynamically mengdong.lin
2016-02-15 20:25   ` Applied "ASoC: topology: Add FE DAIs dynamically" to the asoc tree Mark Brown
2015-12-31  8:41 ` [PATCH 5/5] ASoC: topology: Add FE DAI links dynamically mengdong.lin
2016-02-15 20:25   ` Applied "ASoC: topology: Add FE DAI links dynamically" to the asoc tree Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1452489739-25720-1-git-send-email-mengdong.lin@linux.intel.com \
    --to=mengdong.lin@linux.intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=jeeja.kp@intel.com \
    --cc=liam.r.girdwood@linux.intel.com \
    --cc=mengdong.lin@intel.com \
    --cc=subhransu.s.prusty@intel.com \
    --cc=tiwai@suse.de \
    --cc=vinod.koul@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).