Skip to content

Commit

Permalink
ALSA: Introduce 'snd_interval_rate_bits'
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Povišer <[email protected]>
  • Loading branch information
povik authored and jannau committed Oct 6, 2024
1 parent d74fa5b commit 978787a
Show file tree
Hide file tree
Showing 2 changed files with 38 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 @@ -1066,6 +1066,7 @@ int snd_interval_ranges(struct snd_interval *i, unsigned int count,
int snd_interval_ratnum(struct snd_interval *i,
unsigned int rats_count, const struct snd_ratnum *rats,
unsigned int *nump, unsigned int *denp);
int snd_interval_rate_bits(struct snd_interval *i, unsigned int rate_bits);

void _snd_pcm_hw_params_any(struct snd_pcm_hw_params *params);
void _snd_pcm_hw_param_setempty(struct snd_pcm_hw_params *params, snd_pcm_hw_param_t var);
Expand Down
37 changes: 37 additions & 0 deletions sound/core/pcm_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,43 @@ static int snd_interval_step(struct snd_interval *i, unsigned int step)
return changed;
}

/**
* snd_interval_rate_bits - refine the rate interval from a rate bitmask
* @i: the rate interval to refine
* @mask: the rate bitmask
*
* Refines the interval value, assumed to be the sample rate, according to
* a bitmask of available rates (an ORed combination of SNDRV_PCM_RATE_*).
*
* Return: Positive if the value is changed, zero if it's not changed, or a
* negative error code.
*/
int snd_interval_rate_bits(struct snd_interval *i, unsigned int mask)
{
unsigned int k;
struct snd_interval mask_range;

if (!mask)
return -EINVAL;

snd_interval_any(&mask_range);
mask_range.min = UINT_MAX;
mask_range.max = 0;
for (k = 0; k < snd_pcm_known_rates.count; k++) {
unsigned int rate = snd_pcm_known_rates.list[k];
if (!(mask & (1 << k)))
continue;

if (rate > mask_range.max)
mask_range.max = rate;

if (rate < mask_range.min)
mask_range.min = rate;
}
return snd_interval_refine(i, &mask_range);
}
EXPORT_SYMBOL(snd_interval_rate_bits);

/* Info constraints helpers */

/**
Expand Down

0 comments on commit 978787a

Please sign in to comment.