Skip to content

Commit 6125bc0

Browse files
povikjannau
authored andcommitted
ALSA: Introduce 'snd_interval_rate_bits'
Signed-off-by: Martin Povišer <povik+lin@cutebit.org>
1 parent 8b5a66d commit 6125bc0

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

include/sound/pcm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,7 @@ int snd_interval_ranges(struct snd_interval *i, unsigned int count,
10651065
int snd_interval_ratnum(struct snd_interval *i,
10661066
unsigned int rats_count, const struct snd_ratnum *rats,
10671067
unsigned int *nump, unsigned int *denp);
1068+
int snd_interval_rate_bits(struct snd_interval *i, unsigned int rate_bits);
10681069

10691070
void _snd_pcm_hw_params_any(struct snd_pcm_hw_params *params);
10701071
void _snd_pcm_hw_param_setempty(struct snd_pcm_hw_params *params, snd_pcm_hw_param_t var);

sound/core/pcm_lib.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,43 @@ static int snd_interval_step(struct snd_interval *i, unsigned int step)
11291129
return changed;
11301130
}
11311131

1132+
/**
1133+
* snd_interval_rate_bits - refine the rate interval from a rate bitmask
1134+
* @i: the rate interval to refine
1135+
* @mask: the rate bitmask
1136+
*
1137+
* Refines the interval value, assumed to be the sample rate, according to
1138+
* a bitmask of available rates (an ORed combination of SNDRV_PCM_RATE_*).
1139+
*
1140+
* Return: Positive if the value is changed, zero if it's not changed, or a
1141+
* negative error code.
1142+
*/
1143+
int snd_interval_rate_bits(struct snd_interval *i, unsigned int mask)
1144+
{
1145+
unsigned int k;
1146+
struct snd_interval mask_range;
1147+
1148+
if (!mask)
1149+
return -EINVAL;
1150+
1151+
snd_interval_any(&mask_range);
1152+
mask_range.min = UINT_MAX;
1153+
mask_range.max = 0;
1154+
for (k = 0; k < snd_pcm_known_rates.count; k++) {
1155+
unsigned int rate = snd_pcm_known_rates.list[k];
1156+
if (!(mask & (1 << k)))
1157+
continue;
1158+
1159+
if (rate > mask_range.max)
1160+
mask_range.max = rate;
1161+
1162+
if (rate < mask_range.min)
1163+
mask_range.min = rate;
1164+
}
1165+
return snd_interval_refine(i, &mask_range);
1166+
}
1167+
EXPORT_SYMBOL(snd_interval_rate_bits);
1168+
11321169
/* Info constraints helpers */
11331170

11341171
/**

0 commit comments

Comments
 (0)