Skip to content

Commit d5b702a

Browse files
cladischtiwai
authored andcommitted
ALSA: pcm: add snd_pcm_hw_rule_noresample()
Add a helper function to allow drivers to disable hardware resampling when the application has specified the SNDRV_PCM_HW_PARAMS_NORESAMPLE flag. Signed-off-by: Clemens Ladisch <clemens@ladisch.de> Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 84f9df1 commit d5b702a

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

‎include/sound/pcm.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,8 @@ int snd_pcm_hw_constraint_step(struct snd_pcm_runtime *runtime,
825825
int snd_pcm_hw_constraint_pow2(struct snd_pcm_runtime *runtime,
826826
unsigned int cond,
827827
snd_pcm_hw_param_t var);
828+
int snd_pcm_hw_rule_noresample(struct snd_pcm_runtime *runtime,
829+
unsigned int base_rate);
828830
int snd_pcm_hw_rule_add(struct snd_pcm_runtime *runtime,
829831
unsigned int cond,
830832
int var,

‎sound/core/pcm_lib.c‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,6 +1399,32 @@ int snd_pcm_hw_constraint_pow2(struct snd_pcm_runtime *runtime,
13991399

14001400
EXPORT_SYMBOL(snd_pcm_hw_constraint_pow2);
14011401

1402+
static int snd_pcm_hw_rule_noresample_func(struct snd_pcm_hw_params *params,
1403+
struct snd_pcm_hw_rule *rule)
1404+
{
1405+
unsigned int base_rate = (unsigned int)(uintptr_t)rule->private;
1406+
struct snd_interval *rate;
1407+
1408+
rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
1409+
return snd_interval_list(rate, 1, &base_rate, 0);
1410+
}
1411+
1412+
/**
1413+
* snd_pcm_hw_rule_noresample - add a rule to allow disabling hw resampling
1414+
* @runtime: PCM runtime instance
1415+
* @base_rate: the rate at which the hardware does not resample
1416+
*/
1417+
int snd_pcm_hw_rule_noresample(struct snd_pcm_runtime *runtime,
1418+
unsigned int base_rate)
1419+
{
1420+
return snd_pcm_hw_rule_add(runtime, SNDRV_PCM_HW_PARAMS_NORESAMPLE,
1421+
SNDRV_PCM_HW_PARAM_RATE,
1422+
snd_pcm_hw_rule_noresample_func,
1423+
(void *)(uintptr_t)base_rate,
1424+
SNDRV_PCM_HW_PARAM_RATE, -1);
1425+
}
1426+
EXPORT_SYMBOL(snd_pcm_hw_rule_noresample);
1427+
14021428
static void _snd_pcm_hw_param_any(struct snd_pcm_hw_params *params,
14031429
snd_pcm_hw_param_t var)
14041430
{

0 commit comments

Comments
 (0)