Skip to content

Commit

Permalink
ALSA: pcm: Add snd_pcm_rate_bit_to_rate()
Browse files Browse the repository at this point in the history
This is essentially the reverse of snd_pcm_rate_to_rate_bit().

This is generally useful as the Compress API uses the rate bit
directly and it helps to be able to map back to the actual sample
rate.

Signed-off-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
  • Loading branch information
Dimitris Papastamos authored and Takashi Iwai committed Jun 18, 2012
1 parent 989b013 commit 4be77a5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/sound/pcm.h
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,7 @@ extern const struct snd_pcm_hw_constraint_list snd_pcm_known_rates;

int snd_pcm_limit_hw_rates(struct snd_pcm_runtime *runtime);
unsigned int snd_pcm_rate_to_rate_bit(unsigned int rate);
unsigned int snd_pcm_rate_bit_to_rate(unsigned int rate_bit);

static inline void snd_pcm_set_runtime_buffer(struct snd_pcm_substream *substream,
struct snd_dma_buffer *bufp)
Expand Down
18 changes: 18 additions & 0 deletions sound/core/pcm_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -488,3 +488,21 @@ unsigned int snd_pcm_rate_to_rate_bit(unsigned int rate)
return SNDRV_PCM_RATE_KNOT;
}
EXPORT_SYMBOL(snd_pcm_rate_to_rate_bit);

/**
* snd_pcm_rate_bit_to_rate - converts SNDRV_PCM_RATE_xxx bit to sample rate
* @rate_bit: the rate bit to convert
*
* Returns the sample rate that corresponds to the given SNDRV_PCM_RATE_xxx flag
* or 0 for an unknown rate bit
*/
unsigned int snd_pcm_rate_bit_to_rate(unsigned int rate_bit)
{
unsigned int i;

for (i = 0; i < snd_pcm_known_rates.count; i++)
if ((1u << i) == rate_bit)
return snd_pcm_known_rates.list[i];
return 0;
}
EXPORT_SYMBOL(snd_pcm_rate_bit_to_rate);

0 comments on commit 4be77a5

Please sign in to comment.