Skip to content

Commit 12e720e

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

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

include/sound/pcm.h

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

10701071
void _snd_pcm_hw_params_any(struct snd_pcm_hw_params *params);
10711072
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
@@ -1146,6 +1146,43 @@ static int snd_interval_step(struct snd_interval *i, unsigned int step)
11461146
return changed;
11471147
}
11481148

1149+
/**
1150+
* snd_interval_rate_bits - refine the rate interval from a rate bitmask
1151+
* @i: the rate interval to refine
1152+
* @mask: the rate bitmask
1153+
*
1154+
* Refines the interval value, assumed to be the sample rate, according to
1155+
* a bitmask of available rates (an ORed combination of SNDRV_PCM_RATE_*).
1156+
*
1157+
* Return: Positive if the value is changed, zero if it's not changed, or a
1158+
* negative error code.
1159+
*/
1160+
int snd_interval_rate_bits(struct snd_interval *i, unsigned int mask)
1161+
{
1162+
unsigned int k;
1163+
struct snd_interval mask_range;
1164+
1165+
if (!mask)
1166+
return -EINVAL;
1167+
1168+
snd_interval_any(&mask_range);
1169+
mask_range.min = UINT_MAX;
1170+
mask_range.max = 0;
1171+
for (k = 0; k < snd_pcm_known_rates.count; k++) {
1172+
unsigned int rate = snd_pcm_known_rates.list[k];
1173+
if (!(mask & (1 << k)))
1174+
continue;
1175+
1176+
if (rate > mask_range.max)
1177+
mask_range.max = rate;
1178+
1179+
if (rate < mask_range.min)
1180+
mask_range.min = rate;
1181+
}
1182+
return snd_interval_refine(i, &mask_range);
1183+
}
1184+
EXPORT_SYMBOL(snd_interval_rate_bits);
1185+
11491186
/* Info constraints helpers */
11501187

11511188
/**

0 commit comments

Comments
 (0)