* How to handle stream rates if CPU supports many channels ?
@ 2017-06-06 0:48 Kuninori Morimoto
2017-06-06 3:41 ` Takashi Sakamoto
0 siblings, 1 reply; 5+ messages in thread
From: Kuninori Morimoto @ 2017-06-06 0:48 UTC (permalink / raw)
To: Mark Brown; +Cc: Linux-ALSA, Hiroyuki Yokoyama
Hi ALSA ML
I want to ask you about struct snd_soc_pcm_stream::rates which
indicates available sampling rates (= SNDRV_PCM_RATE_xxxx).
Basic use case of my CPU driver is 2ch output,
but, it can handle 6ch, 8ch, 16ch sounds.
And it can be clock master.
In this case, for example, if CPU has 12288000 system clock
and it uses 32bit for each 1ch data (it has divider inside).
Max 2ch sound Hz = 12288000 / 32 / 2 = 192000Hz
Max 8ch sound Hz = 12288000 / 32 / 8 = 48000Hz
If my understanding was correct, struct snd_soc_pcm_stream::rates
is needed when sound device "open" timing
(= struct snd_soc_dai_ops::startup), but, we can receive used
channels number when "hw_params" timing ?
My question is that if system has 12288000, and if it can
support both 2ch and 8ch, what struct snd_soc_pcm_stream::rates
should have ??
SNDRV_PCM_RATE_8000_192000 ?
SNDRV_PCM_RATE_8000_48000 ?
Best regards
---
Kuninori Morimoto
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: How to handle stream rates if CPU supports many channels ?
2017-06-06 0:48 How to handle stream rates if CPU supports many channels ? Kuninori Morimoto
@ 2017-06-06 3:41 ` Takashi Sakamoto
2017-06-06 7:04 ` Kuninori Morimoto
0 siblings, 1 reply; 5+ messages in thread
From: Takashi Sakamoto @ 2017-06-06 3:41 UTC (permalink / raw)
To: Kuninori Morimoto, Mark Brown; +Cc: Linux-ALSA, Hiroyuki Yokoyama
On 2017年06月06日 09:48, Kuninori Morimoto wrote:
> Basic use case of my CPU driver is 2ch output,
> but, it can handle 6ch, 8ch, 16ch sounds.
> And it can be clock master.
>
> In this case, for example, if CPU has 12288000 system clock
> and it uses 32bit for each 1ch data (it has divider inside).
>
> Max 2ch sound Hz = 12288000 / 32 / 2 = 192000Hz
> Max 8ch sound Hz = 12288000 / 32 / 8 = 48000Hz
>
> If my understanding was correct, struct snd_soc_pcm_stream::rates
> is needed when sound device "open" timing
> (= struct snd_soc_dai_ops::startup), but, we can receive used
> channels number when "hw_params" timing ?
>
> My question is that if system has 12288000, and if it can
> support both 2ch and 8ch, what struct snd_soc_pcm_stream::rates
> should have ??
> SNDRV_PCM_RATE_8000_192000 ?
> SNDRV_PCM_RATE_8000_48000 ?
If your hardware support the two modes for PCM frame transmission, you
need to describe it correctly into runtime of PCM substream for ALSA PCM
application. No matter whether the driver is in ALSA SoC part or not.
In design of ALSA PCM interface, PCM runtime get constraints and rules
of parameters when applications execute open(2) to ALSA PCM character
device. In this timing, drivers should register the constraints and the
rules in callbacks of 'struct snd_pcm_ops.open'.
Your CPU driver should register them in callback of 'struct
snd_soc_dai.startup()' in a callgraph from open(2). For example with
code snippet:
```
static int hw_rule_rate()
{
unsigned int list[2]
/* when the range of channels include 2, then 192000 is available. */
/* when the range of channels include 8, then 48000 is available. */
snd_interval_list(list)
}
static int hw_rule_channels()
{
unsigned int list[2]
/* when the range of rates include 48000, then 8ch is available. */
/* when the range of rates include 192000, then 2ch is available. */
snd_interval_list(list)
}
static int startup()
{
...
snd_pcm_hw_rule_add(SNDRV_PCM_HW_PARAM_RATE, hw_rule_rate,
SNDRV_PCM_HW_PARAM_CHANNELS)
snd_pcm_hw_rule_add(SNDRV_PCM_HW_PARAM_CHANNELS, hw_rule_channels,
SNDRV_PCM_HW_PARAM_RATE)
...
}
struct snd_soc_dai.startup = startup;
```
Furthermore, PCM runtime require constraints for channels and rates. In
ALSA SoC part, this is done by 'soc_pcm_init_runtime_hw()' in
'sound/soc/soc-pcm.c'. Your driver should have proper values in data of
'struct snd_soc_pcm_stream' as the constraints.
```
(struct snd_soc_dai_driver.playback or capture?)
struct snd_soc_pcm_stream.channels_min = 2
struct snd_soc_pcm_stream.channels_max = 8
struct snd_soc_pcm_stream.rate_min = 48000
struct snd_soc_pcm_stream.rate_max = 192000
struct snd_soc_pcm_stream.rates =
SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_192000
```
When implement these correctly, userspace applications can get enough
information about PCM substream for your hardware by executing ioctl(2)
with HW_REFINE/HW_PARAMS. If you need more combination between channels
and rates, please expand these basic codes as you like. If you need some
examples, please investigate drivers outside of ALSA SoC part.
Regards
Takashi Sakamoto
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: How to handle stream rates if CPU supports many channels ?
2017-06-06 3:41 ` Takashi Sakamoto
@ 2017-06-06 7:04 ` Kuninori Morimoto
2017-06-06 15:22 ` Takashi Sakamoto
0 siblings, 1 reply; 5+ messages in thread
From: Kuninori Morimoto @ 2017-06-06 7:04 UTC (permalink / raw)
To: Takashi Sakamoto; +Cc: Linux-ALSA, Mark Brown, Hiroyuki Yokoyama
Hi Sakamoto-san
Thank you for detail explanation.
> static int hw_rule_rate()
> {
> unsigned int list[2]
> /* when the range of channels include 2, then 192000 is available. */
> /* when the range of channels include 8, then 48000 is available. */
> snd_interval_list(list)
> }
>
> static int hw_rule_channels()
> {
> unsigned int list[2]
> /* when the range of rates include 48000, then 8ch is available. */
> /* when the range of rates include 192000, then 2ch is available. */
> snd_interval_list(list)
> }
>
> static int startup()
> {
> ...
> snd_pcm_hw_rule_add(SNDRV_PCM_HW_PARAM_RATE, hw_rule_rate,
> SNDRV_PCM_HW_PARAM_CHANNELS)
> snd_pcm_hw_rule_add(SNDRV_PCM_HW_PARAM_CHANNELS, hw_rule_channels,
> SNDRV_PCM_HW_PARAM_RATE)
> ...
> }
>
> struct snd_soc_dai.startup = startup;
I didn't know about this.
Thanks. I will implement it.
> Furthermore, PCM runtime require constraints for channels and
> rates. In ALSA SoC part, this is done by 'soc_pcm_init_runtime_hw()'
> in 'sound/soc/soc-pcm.c'. Your driver should have proper values in
> data of 'struct snd_soc_pcm_stream' as the constraints.
>
> ```
> (struct snd_soc_dai_driver.playback or capture?)
> struct snd_soc_pcm_stream.channels_min = 2
> struct snd_soc_pcm_stream.channels_max = 8
> struct snd_soc_pcm_stream.rate_min = 48000
> struct snd_soc_pcm_stream.rate_max = 192000
> struct snd_soc_pcm_stream.rates =
> SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_192000
Here, I'm not yet 100% understanding about these value.
I think, above are constraints of whole driver (= it supports both 2ch, 8ch).
About rate_min/max and rates.
is this "rate_min" 48000 (= maximum rate of min case = 8ch) ?? not 8000 ?
(For example, if 2ch supports 8000-192000, 8ch supports 8000-48000)
And is .rates "SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_192000" ?
not SNDRV_PCM_RATE_8000_192000 ?
Thank you for your help
Best regards
---
Kuninori Morimoto
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: How to handle stream rates if CPU supports many channels ?
2017-06-06 7:04 ` Kuninori Morimoto
@ 2017-06-06 15:22 ` Takashi Sakamoto
2017-06-06 23:41 ` Kuninori Morimoto
0 siblings, 1 reply; 5+ messages in thread
From: Takashi Sakamoto @ 2017-06-06 15:22 UTC (permalink / raw)
To: Kuninori Morimoto; +Cc: Linux-ALSA, Mark Brown, Hiroyuki Yokoyama
On 2017年06月06日 16:04, Kuninori Morimoto wrote:
>> Furthermore, PCM runtime require constraints for channels and
>> rates. In ALSA SoC part, this is done by 'soc_pcm_init_runtime_hw()'
>> in 'sound/soc/soc-pcm.c'. Your driver should have proper values in
>> data of 'struct snd_soc_pcm_stream' as the constraints.
>>
>> ```
>> (struct snd_soc_dai_driver.playback or capture?)
>> struct snd_soc_pcm_stream.channels_min = 2
>> struct snd_soc_pcm_stream.channels_max = 8
>> struct snd_soc_pcm_stream.rate_min = 48000
>> struct snd_soc_pcm_stream.rate_max = 192000
>> struct snd_soc_pcm_stream.rates =
>> SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_192000
>
> Here, I'm not yet 100% understanding about these value.
> I think, above are constraints of whole driver (= it supports both 2ch, 8ch).
It's not my intension. I don't know exactly where you implement 'struct
snd_soc_pcm_stream' data in your driver. Perhaps as a part of 'struct
snd_soc_dai_driver' data.
> About rate_min/max and rates.
> is this "rate_min" 48000 (= maximum rate of min case = 8ch) ?? not 8000 ?
> (For example, if 2ch supports 8000-192000, 8ch supports 8000-48000)
>
> And is .rates "SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_192000" ?
> not SNDRV_PCM_RATE_8000_192000 ?
In my code snippets, I assumed that the hardware supports just two
modes; 8ch/48.0kHz and 2ch/192.0kHz. You can expand the snippets as your
case. Even if using SNDRV_PCM_RATE_8000_192000, role of the
'hw_rule_rate()' and the 'hw_rule_channels()' is invariant. The former
checks channels parameters and constrains rate parameter with valid
interval. The latter checks and constraints vice versa with valid list.
Regards
Takashi Sakamoto
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: How to handle stream rates if CPU supports many channels ?
2017-06-06 15:22 ` Takashi Sakamoto
@ 2017-06-06 23:41 ` Kuninori Morimoto
0 siblings, 0 replies; 5+ messages in thread
From: Kuninori Morimoto @ 2017-06-06 23:41 UTC (permalink / raw)
To: Takashi Sakamoto; +Cc: Linux-ALSA, Mark Brown, Hiroyuki Yokoyama
Hi Sakamoto-san
> > Here, I'm not yet 100% understanding about these value.
> > I think, above are constraints of whole driver (= it supports both 2ch, 8ch).
>
> It's not my intension. I don't know exactly where you implement
> 'struct snd_soc_pcm_stream' data in your driver. Perhaps as a part of
> 'struct snd_soc_dai_driver' data.
OK, thank you for your help
I will investigate it.
> > About rate_min/max and rates.
> > is this "rate_min" 48000 (= maximum rate of min case = 8ch) ?? not 8000 ?
> > (For example, if 2ch supports 8000-192000, 8ch supports 8000-48000)
> >
> > And is .rates "SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_192000" ?
> > not SNDRV_PCM_RATE_8000_192000 ?
>
> In my code snippets, I assumed that the hardware supports just two
> modes; 8ch/48.0kHz and 2ch/192.0kHz. You can expand the snippets as
> your case. Even if using SNDRV_PCM_RATE_8000_192000, role of the
> 'hw_rule_rate()' and the 'hw_rule_channels()' is invariant. The former
> checks channels parameters and constrains rate parameter with valid
> interval. The latter checks and constraints vice versa with valid
> list.
Sorry for my un-understandable example.
Thank you for your detail explanation, it is very helpful for me.
I will invariant and try to implement this feature
Best regards
---
Kuninori Morimoto
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-06-06 23:41 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-06 0:48 How to handle stream rates if CPU supports many channels ? Kuninori Morimoto
2017-06-06 3:41 ` Takashi Sakamoto
2017-06-06 7:04 ` Kuninori Morimoto
2017-06-06 15:22 ` Takashi Sakamoto
2017-06-06 23:41 ` Kuninori Morimoto
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.