[alsa-devel] How exactly snd_pcm_hw_rule_add() should to be used?
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
At Tue, 5 Feb 2013 11:24:45 +0100, Peter Ujfalusi wrote:
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);
It's: snd_pcm_hw_rule_add(substream->runtime, 0, SNDRV_PCM_HW_PARAM_FORMAT, hw_rule_format_by_channels, 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.
The definitions of hw_rule_channels_by_format and hw_rule_format_by_channels are placed wrongly. And the description isn't clear, which function is for what, indeed. So, overall it's confusing, yes.
But the code written there is correct, at least :)
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.
This is correct.
The third argument of snd_pcm_hw_rule_add() is the parameter to be refined, following the function to call, the private data pointer, and the dependent parameters. In the case above,
I'll try to improve the text (and correct the definitions).
thanks,
Takashi
participants (2)
-
Peter Ujfalusi
-
Takashi Iwai