No sound in LXC container

DocMAX

Member
Jan 30, 2023
214
16
23
Bremen
I added my sound card to my LXC container with

Code:
lxc.cgroup2.devices.allow: c 116:* rwm
lxc.mount.entry: /dev/snd dev/snd none bind,optional,create=dir

Code:
[docmax@desktop ~]$ aplay -L
null
    Discard all samples (playback) or generate zero samples (capture)
lavrate
    Rate Converter Plugin Using Libav/FFmpeg Library
samplerate
    Rate Converter Plugin Using Samplerate Library
speexrate
    Rate Converter Plugin Using Speex Resampler
jack
    JACK Audio Connection Kit
oss
    Open Sound System
pipewire
    PipeWire Sound Server
pulse
    PulseAudio Sound Server
speex
    Plugin using Speex DSP (resample, agc, denoise, echo, dereverb)
upmix
    Plugin for channel upmix (4,6,8)
vdownmix
    Plugin for channel downmix (stereo) with a simple spacialization
default
    Default ALSA Output (currently PipeWire Media Server)
hdmi:CARD=Generic,DEV=0
    HD-Audio Generic, HDMI 0
    HDMI Audio Output
hdmi:CARD=Generic,DEV=1
    HD-Audio Generic, SONY TV  *00
    HDMI Audio Output
hdmi:CARD=Generic,DEV=2
    HD-Audio Generic, HDMI 2
    HDMI Audio Output
hdmi:CARD=Generic,DEV=3
    HD-Audio Generic, HDMI 3
    HDMI Audio Output
usbstream:CARD=Generic
    HD-Audio Generic
    USB Stream Output
sysdefault:CARD=Generic_1
    HD-Audio Generic, ALC255 Analog
    Default Audio Device
front:CARD=Generic_1,DEV=0
    HD-Audio Generic, ALC255 Analog
    Front output / input
surround21:CARD=Generic_1,DEV=0
    HD-Audio Generic, ALC255 Analog
    2.1 Surround output to Front and Subwoofer speakers
surround40:CARD=Generic_1,DEV=0
    HD-Audio Generic, ALC255 Analog
    4.0 Surround output to Front and Rear speakers
surround41:CARD=Generic_1,DEV=0
    HD-Audio Generic, ALC255 Analog
    4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=Generic_1,DEV=0
    HD-Audio Generic, ALC255 Analog
    5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=Generic_1,DEV=0
    HD-Audio Generic, ALC255 Analog
    5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=Generic_1,DEV=0
    HD-Audio Generic, ALC255 Analog
    7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
usbstream:CARD=Generic_1
    HD-Audio Generic
    USB Stream Output

and i can hear audio with
Code:
speaker-test -c6 -D hdmi:CARD=Generic,DEV=1

the problem is, pipewire and pulseaudio do not detect the cards:

Code:
[docmax@desktop ~]$ pactl list cards
[docmax@desktop ~]$ pactl info
Server String: /run/user/1000/pulse/native
Library Protocol Version: 35
Server Protocol Version: 35
Is Local: yes
Client Index: 69
Tile Size: 65472
User Name: docmax
Host Name: desktop
Server Name: PulseAudio (on PipeWire 0.3.67)
Server Version: 15.0.0
Default Sample Specification: float32le 2ch 48000Hz
Default Channel Map: front-left,front-right
Default Sink: auto_null
Default Source: auto_null.monitor
Cookie: f98e:d48b

here is the log of pulseauudio:

Code:
I: [pulseaudio] main.c: setrlimit(RLIMIT_NICE, (31, 31)) failed: Operation not permitted
I: [pulseaudio] main.c: setrlimit(RLIMIT_RTPRIO, (9, 9)) failed: Operation not permitted
I: [pulseaudio] core-util.c: Failed to acquire high-priority scheduling: Permission denied
I: [pulseaudio] main.c: This is PulseAudio 16.1
I: [pulseaudio] main.c: Page size is 4096 bytes
I: [pulseaudio] main.c: Machine ID is d7dc72d3681a47a2aec8a419dfbd03fd.
I: [pulseaudio] main.c: Session ID is 1183.
I: [pulseaudio] main.c: Using runtime directory /run/user/1000/pulse.
I: [pulseaudio] main.c: Using state directory /home/docmax/.config/pulse.
I: [pulseaudio] main.c: Using modules directory /usr/lib/pulseaudio/modules.
I: [pulseaudio] main.c: Running in system mode: no
I: [pulseaudio] main.c: System supports high resolution timers
I: [pulseaudio] cpu-x86.c: CPU flags: CMOV MMX SSE SSE2 SSE3 SSSE3 SSE4_1 SSE4_2 MMXEXT
I: [pulseaudio] svolume_mmx.c: Initialising MMX optimized volume functions.
I: [pulseaudio] remap_mmx.c: Initialising MMX optimized remappers.
I: [pulseaudio] svolume_sse.c: Initialising SSE2 optimized volume functions.
I: [pulseaudio] remap_sse.c: Initialising SSE2 optimized remappers.
I: [pulseaudio] sconv_sse.c: Initialising SSE2 optimized conversions.
I: [pulseaudio] svolume_orc.c: Initialising ORC optimized volume functions.
I: [pulseaudio] database.c: Successfully opened 'device-volumes' database file '/home/docmax/.config/pulse/d7dc72d3681a47a2aec8a419dfbd03fd-device-volumes.tdb'.
I: [pulseaudio] module.c: Loaded "module-device-restore" (index: #0; argument: "").
I: [pulseaudio] database.c: Successfully opened 'stream-volumes' database file '/home/docmax/.config/pulse/d7dc72d3681a47a2aec8a419dfbd03fd-stream-volumes.tdb'.
I: [pulseaudio] module.c: Loaded "module-stream-restore" (index: #1; argument: "").
I: [pulseaudio] database.c: Successfully opened 'card-database' database file '/home/docmax/.config/pulse/d7dc72d3681a47a2aec8a419dfbd03fd-card-database.tdb'.
I: [pulseaudio] module.c: Loaded "module-card-restore" (index: #2; argument: "").
I: [pulseaudio] module.c: Loaded "module-augment-properties" (index: #3; argument: "").
I: [pulseaudio] module.c: Loaded "module-switch-on-port-available" (index: #4; argument: "").
I: [pulseaudio] module-udev-detect.c: Found 0 cards.
I: [pulseaudio] module.c: Loaded "module-udev-detect" (index: #5; argument: "").
I: [pulseaudio] module.c: Loaded "module-dbus-protocol" (index: #6; argument: "").
E: [pulseaudio] socket-server.c: bind(): Address already in use
E: [pulseaudio] module.c: Failed to load module "module-native-protocol-unix" (argument: ""): initialization failed.
I: [pulseaudio] module.c: Loaded "module-gsettings" (index: #8; argument: "").
I: [pulseaudio] module-default-device-restore.c: No previous default sink setting, ignoring.
I: [pulseaudio] module-default-device-restore.c: No previous default source setting, ignoring.
I: [pulseaudio] module.c: Loaded "module-default-device-restore" (index: #9; argument: "").
I: [pulseaudio] sink.c: Created sink 0 "auto_null" with sample spec s16le 2ch 44100Hz and channel map front-left,front-right
I: [pulseaudio] sink.c:     device.description = "Dummy Output"
I: [pulseaudio] sink.c:     device.class = "abstract"
I: [pulseaudio] sink.c:     device.icon_name = "audio-card"
I: [pulseaudio] source.c: Created source 0 "auto_null.monitor" with sample spec s16le 2ch 44100Hz and channel map front-left,front-right
I: [pulseaudio] source.c:     device.description = "Monitor of Dummy Output"
I: [pulseaudio] source.c:     device.class = "monitor"
I: [pulseaudio] source.c:     device.icon_name = "audio-input-microphone"
I: [null-sink] util.c: Failed to acquire real-time scheduling: Permission denied
I: [pulseaudio] core.c: default_source: (unset) -> auto_null.monitor
I: [pulseaudio] core.c: default_sink: (unset) -> auto_null
I: [pulseaudio] module.c: Loaded "module-null-sink" (index: #11; argument: "sink_name=auto_null sink_properties='device.description="Dummy Output"'").
I: [pulseaudio] module.c: Loaded "module-always-sink" (index: #10; argument: "").
I: [pulseaudio] module.c: Loaded "module-intended-roles" (index: #12; argument: "").
I: [pulseaudio] module.c: Loaded "module-suspend-on-idle" (index: #13; argument: "").
I: [pulseaudio] module.c: Loaded "module-console-kit" (index: #14; argument: "").
I: [pulseaudio] client.c: Created 0 "Login Session 1184"
I: [pulseaudio] core.c: exit_idle_time: 20 -> 0
I: [pulseaudio] client.c: Created 1 "Login Session 1183"
I: [pulseaudio] module.c: Loaded "module-systemd-login" (index: #15; argument: "").
I: [pulseaudio] module.c: Loaded "module-position-event-sounds" (index: #16; argument: "").
I: [pulseaudio] module.c: Loaded "module-role-cork" (index: #17; argument: "").
I: [pulseaudio] module.c: Loaded "module-filter-heuristics" (index: #18; argument: "").
I: [pulseaudio] module.c: Loaded "module-filter-apply" (index: #19; argument: "").
W: [pulseaudio] cli-command.c: stat('/etc/pulse/default.pa.d'): No such file or directory
I: [pulseaudio] main.c: Daemon startup complete.
I: [pulseaudio] module-suspend-on-idle.c: Sink auto_null idle for too long, suspending ...


has anyone suceeded in getting sound this way? my lxc container is arch linux, but shouln't be the problem.

edit: found a workaround with pulseaudio.
added load-module module-alsa-sink device=hw:0,7 to default.pa to at least get the alsa sink.
but udev autodetect still doesnt work.

pipewire somehow does not detect the hw:0,7. probably some kind of bug?!
api.alsa.path = "hw:0,7" in pipewire.conf

thanks,
docmax
 
Last edited:
Glad someone is interested in this.
No - i am not able to FULLY passthough all audio hardware and get it detected by pulseaudio or pipewire.
If someone did please reply.
 
Workaround with Pipewire:

/home/docmax/.config/pipewire/pipewire.conf
Code:
...

    { factory = adapter
        args = {
            factory.name           = api.alsa.pcm.sink
            node.name              = "alsa-sink"
            node.description       = "PCM Sink"
            media.class            = "Audio/Sink"
            api.alsa.path          = "hw:0,3"
            api.alsa.period-size   = 1024
            api.alsa.headroom      = 0
            api.alsa.disable-mmap  = false
            api.alsa.disable-batch = false
            audio.format           = "S16LE"
            audio.rate             = 48000
            audio.channels         = 6
            #audio.position         = "FL,FR"
        }
    }
...

but really, i would like to get it "autodetected" by pipewire.