Skip to contentSkip to conversation

Specifying supported hw params (channels, format, etc.) by the plug plugin in alsa config?

DISCUSSION Pavel Hofman 2 participants 5 messages Aug 25, 2024 – Aug 27, 2024

lore
Share & tools
lore
#0 lore raw

Hi,

Please is it possible to restrict the hw params space for the plug plugin by some alsa configuration, so that it reports/accepts only a specific number of channels/specific sample format? I was not able to figure it out, I apologize if it's trivial :-)

Thanks a lot.

With regards,

Pavel.

#1 lore raw
Quoted 6 lines · Pavel Hofman

Hi,

Please is it possible to restrict the hw params space for the plug plugin by some alsa configuration, so that it reports/accepts only a specific number of channels/specific sample format? I was not able to figure it out, I apologize if it's trivial :-)

Hi,

here's a quick example:

===
pcm.hubcap {
type plug

  slave {
    pcm "hw:Loopback,1,0"
    rate 48000
    format S16_LE

}
}
===

Documentation: https://www.alsa-project.org/alsa-doc/alsa-lib/pcm_plugins.html

Jaroslav

Signature · 2 lines
Jaroslav Kysela <[email protected]>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.
#2 lore raw

Hi Jaroslav,

Quoted 23 lines · Jaroslav Kysela
Quoted 6 lines · Pavel Hofman

Hi,

Please is it possible to restrict the hw params space for the plug plugin by some alsa configuration, so that it reports/accepts only a specific number of channels/specific sample format? I was not able to figure it out, I apologize if it's trivial :-)

Hi,

    here's a quick example:

===
pcm.hubcap {
  type plug
  slave {
    pcm "hw:Loopback,1,0"
    rate 48000
    format S16_LE
  }
}
===

Quoted 3 lines

Documentation:
https://www.alsa-project.org/alsa-doc/alsa-lib/pcm_plugins.html

Thanks a lot for your quick response. IIUC this config specifies params for the slave, but the plug's input hw params remain unrestricted:

aplay -v --dump-hw-params -D hubcap /dev/zero
HW Params of device "hubcap":
--------------------
ACCESS: MMAP_INTERLEAVED MMAP_NONINTERLEAVED MMAP_COMPLEX RW_INTERLEAVED RW_NONINTERLEAVED
FORMAT: S8 U8 S16_LE S16_BE U16_LE U16_BE S24_LE S24_BE U24_LE U24_BE S32_LE S32_BE U32_LE U32_BE FLOAT_LE FLOAT_BE FLOAT64_LE FLOAT64_BE MU_LAW A_LAW IMA_ADPCM S20_LE S20_BE U20_LE U20_BE S24_3LE S24_3BE U24_3LE U24_3BE S20_3LE S20_3BE U20_3LE U20_3BE S18_3LE S18_3BE U18_3LE U18_3BE
SUBFORMAT: STD
SAMPLE_BITS: [4 64]
FRAME_BITS: [4 640000]
CHANNELS: [1 10000]
RATE: [4000 4294967295)
PERIOD_TIME: (20 10922667)
PERIOD_SIZE: (0 4294967295)
PERIOD_BYTES: (0 4294967295)
PERIODS: (0 4294967295]
BUFFER_TIME: [1 4294967295]
BUFFER_SIZE: [1 4294967294]
BUFFER_BYTES: [1 4294967295]
TICK_TIME: ALL
--------------------
Plug PCM: Rate conversion PCM (48000, sformat=S16_LE)
...

I am looking for restricting the params offered by the plug plugin to upstream.

Sometimes it's useful to fix the input channels or sample format, while keeping the plug conversion capabilities. An example is the a52 plugin which accepts only non-interleaved access. For clients which support only interleaved access (e.g. java alsa interface), the plug will do the conversion, but will also obscure the fact that a52 works with 6 channels and S16_LE, runs preferrably at 48kHz, etc. Yes, it will any of the conversions necessary, but sometimes the client would prefer knowing the optimal format instead.

I tried wrapping the plug with empty plugin which according to the docs should be able to limit the plug input format
https://www.alsa-project.org/alsa-doc/alsa-lib/pcm_plugins.html#pcm_plugins_empty
but those slave params format/channels were refused by snd config.

Thanks a lot for any help.

With regards,

Pavel.

#3 lore raw
Quoted 26 lines · Pavel Hofman

Hi Jaroslav,

Quoted 23 lines · Jaroslav Kysela
Quoted 6 lines · Pavel Hofman

Hi,

Please is it possible to restrict the hw params space for the plug plugin by some alsa configuration, so that it reports/accepts only a specific number of channels/specific sample format? I was not able to figure it out, I apologize if it's trivial :-)

Hi,

    here's a quick example:

===
pcm.hubcap {
  type plug
  slave {
    pcm "hw:Loopback,1,0"
    rate 48000
    format S16_LE
  }
}
===

Quoted 8 lines
Quoted 3 lines

Documentation:
https://www.alsa-project.org/alsa-doc/alsa-lib/pcm_plugins.html

Thanks a lot for your quick response. IIUC this config specifies params for the slave, but the plug's input hw params remain unrestricted:

It's true.

Quoted 11 lines

I am looking for restricting the params offered by the plug plugin to upstream.

Sometimes it's useful to fix the input channels or sample format, while keeping the plug conversion capabilities. An example is the a52 plugin which accepts only non-interleaved access. For clients which support only interleaved access (e.g. java alsa interface), the plug will do the conversion, but will also obscure the fact that a52 works with 6 channels and S16_LE, runs preferrably at 48kHz, etc. Yes, it will any of the conversions necessary, but sometimes the client would prefer knowing the optimal format instead.

It would be better to use 'copy' plugin instead 'plug' in this case to do just interleaved/non-interleaved stream conversion.

Quoted 3 lines

I tried wrapping the plug with empty plugin which according to the docs
should be able to limit the plug input format
https://www.alsa-project.org/alsa-doc/alsa-lib/pcm_plugins.html#pcm_plugins_empty > but those slave params format/channels were refused by snd config.

Yes, there's missing code implementing this feature in the empty plugin.

Jaroslav

Signature · 2 lines
Jaroslav Kysela <[email protected]>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.
#4 lore raw
Quoted 13 lines · Jaroslav Kysela
Quoted 4 lines

I am looking for restricting the params offered by the plug plugin to upstream.

Quoted 8 lines

Sometimes it's useful to fix the input channels or sample format, while keeping the plug conversion capabilities. An example is the a52 plugin which accepts only non-interleaved access. For clients which support only interleaved access (e.g. java alsa interface), the plug will do the conversion, but will also obscure the fact that a52 works with 6 channels and S16_LE, runs preferrably at 48kHz, etc. Yes, it will any of the conversions necessary, but sometimes the client would prefer knowing the optimal format instead.

Quoted 2 lines

It would be better to use 'copy' plugin instead 'plug' in this case to do just interleaved/non-interleaved stream conversion.

Excellent, that works perfectly for this case. I always wondered about purpose of the copy plugin :-) Thanks a lot!

With regards,

Pavel.