Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hw: add option to specify dynamic DAPM routing to apply when the plugin is opened #192

Closed
wants to merge 1 commit into from

Conversation

bku-sue
Copy link
Contributor

@bku-sue bku-sue commented Nov 15, 2021

The kernel's sound soc subsystem has a DAPM functionality, which makes complex audio routing easy, and most of it is done inside the kernel. However, in the case of dynamic routing (when there is a multiplexer in the signal path), the multiplexer is exposed as an enum MIXER control which must be set from userspace. As the selection of these controls directly influences what audio path is captured/played, the sensible thing to do is to create multiple HW plugins in the ALSA conf, each referring to the same HW device number, but with different routing parameters.

…in is opened

Signed-off-by: Benedek Kupper <benedek.kupper@streamunlimited.com>
@perexg
Copy link
Member

perexg commented Nov 15, 2021

It's already implemented: https://www.alsa-project.org/alsa-doc/alsa-lib/pcm_plugins.html (look for pcm_hooks)

@bku-sue
Copy link
Contributor Author

bku-sue commented Nov 15, 2021

I'm not familiar with that method, how would one set the "Mux1" enum control to "IN2" using that syntax?

@perexg
Copy link
Member

perexg commented Nov 15, 2021

See the example:

  name "Mux1"
  value "IN2"

The parser is in src/control/setup.c .

@perexg
Copy link
Member

perexg commented Nov 15, 2021

EDIT: changed slave "hw:0" to slave.pcm "hw:0"

pcm.selmux {
    type hooks
    slave.pcm "hw:0"
    hooks.0 {
        type ctl_elems
        hook_args [
            {
                name "Mux1"
                value "IN2"
            }
        ]
    }
}

@bku-sue
Copy link
Contributor Author

bku-sue commented Nov 15, 2021

The hooks API looks very promising, but unfortunately I cannot get it to work on my setup, based on alsa-lib 1.1.6 the device is opened but the ctls aren't changed.

@perexg
Copy link
Member

perexg commented Nov 16, 2021

My test

Added to ~/.asoundrc (with the slave definition correction):

pcm.selmux1 {
    type hooks
    slave.pcm "hw:1"
    hooks.0 {
        type ctl_elems
        hook_args [
            {
                name "Auto-Mute Mode"
                value "Enabled"
            }
        ]
    }
}
pcm.selmux2 {
    type hooks
    slave.pcm "hw:1"
    hooks.0 {
        type ctl_elems
        hook_args [
            {
                name "Auto-Mute Mode"
                value "Disabled"
            }
        ]
    }
}

Test commands:

aplay -Dplug:selmux1 /dev/zero
aplay -Dplug:selmux2 /dev/zero

Event verification:

amixer -c 1 events

output:
Ready to listen...
Poll ok: 1
event value: numid=5,iface=MIXER,name='Auto-Mute Mode'
event value: numid=5,iface=MIXER,name='Auto-Mute Mode'

Value verification:

amixer -c 1 cget name='Auto-Mute Mode'

output:
numid=5,iface=MIXER,name='Auto-Mute Mode'
  ; type=ENUMERATED,access=rw------,values=1,items=2
  ; Item #0 'Disabled'
  ; Item #1 'Enabled'
  : values=0

amixer -c 2 cget name='Auto-Mute Mode'

output:
numid=5,iface=MIXER,name='Auto-Mute Mode'
  ; type=ENUMERATED,access=rw------,values=1,items=2
  ; Item #0 'Disabled'
  ; Item #1 'Enabled'
  : values=1

@perexg
Copy link
Member

perexg commented Jan 1, 2022

Stale. Closing.

@perexg perexg closed this Jan 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants