[alsa-devel] How exactly snd_pcm_hw_rule_add() should to be used?

Peter Ujfalusi peter.ujfalusi at ti.com
Tue Feb 5 11:24:45 CET 2013


Hi,

I got confused (again) regarding to how to use correctly the
snd_pcm_hw_rule_add(). Looking at the documentation [1] and to the code in
kernel seams to be suggesting the opposite.

[A]
using the 5.6. example from [1]:
snd_pcm_hw_rule_add(substream->runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
		    hw_rule_channels_by_format, 0, SNDRV_PCM_HW_PARAM_FORMAT,
		    -1);

The [1] tells me that the SNDRV_PCM_HW_PARAM_FORMAT will be refined based on
the SNDRV_PCM_HW_PARAM_CHANNELS.

In 5.7. of [1] the reverse rule is placed:
snd_pcm_hw_rule_add(substream->runtime, 0, SNDRV_PCM_HW_PARAM_FORMAT,
		    hw_rule_channels_by_format, 0,
		    SNDRV_PCM_HW_PARAM_CHANNELS, -1);

Which according to the example will refine the SNDRV_PCM_HW_PARAM_CHANNELS
based on the SNDRV_PCM_HW_PARAM_FORMAT.

However when looking at the code in the kernel the opposite seams to be what
is actually happening.

[B]
using the same 5.6. example from [1]:
snd_pcm_hw_rule_add(substream->runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
		    hw_rule_channels_by_format, 0, SNDRV_PCM_HW_PARAM_FORMAT,
		    -1);

It looks like the SNDRV_PCM_HW_PARAM_CHANNELS should be refined based on the
SNDRV_PCM_HW_PARAM_FORMAT.

Which one is the correct interpretation?

The reason I'm asking is that I need to have a rule which would place
constraint (step) on the BUFFER_SIZE based on the used RATE, but I can not use
a single snd_pcm_hw_constraint_step(,,BUFFER_TIME,) because of HW limitation.

Thank you,
Péter

[1] http://www.alsa-project.org/~tiwai/writing-an-alsa-driver/ch05s09.html


More information about the Alsa-devel mailing list