kcat / openal-soft

OpenAL Soft is a software implementation of the OpenAL 3D audio API.
Other
2.2k stars 530 forks source link

Pipewire: Doesn't respect default device #643

Open mazunki opened 2 years ago

mazunki commented 2 years ago

I am running the current upstream version of OpenAL, which has (some) support for Pipewire, on Gentoo.

I have a set of duplex devices which act as my default nodes, which I then link up to my physical I/O devices.

When using ALSOFT_DRIVERS=pipewire openal-info it does not seem to care about my default.configured.audio.source. It works fine if I use ALSOFT_DRIVERS=pulse, and in that case even displays my custom node.description labels.

I am guessing this is simply not implemented yet, and thus will fall back to PulseAudio as my driver until it is implemented.

Following are some relevant infodumps:

$ pw-metadata 0     
Found "default" metadata 36
update: id:0 key:'default.configured.audio.sink' value:'{ "name": "only-me" }' type:'Spa:String:JSON'
update: id:0 key:'default.configured.audio.source' value:'{ "name": "others" }' type:'Spa:String:JSON'
update: id:0 key:'default.audio.sink' value:'{ "name": "only-me" }' type:'Spa:String:JSON'
update: id:0 key:'default.audio.source' value:'{ "name": "others" }' type:'Spa:String:JSON'
update: id:0 key:'default.video.source' value:'{ "name": "v4l2_input.pci-0000_07_00.3-usb-0_6.2_1.0" }' type:'Spa:String:JSON'

pipewire.conf

{ factory = adapter
    args = {
        factory.name = support.null-audio-sink
            node.name = "both-me-and-others"
            node.description = "Sharing is caring"
            media.class = "Audio/Duplex"
            object.linger = true
            audio.position = [ FL, FR ]
    }
}
{ factory = adapter
    args = {
        factory.name = support.null-audio-sink
            node.name = "others"
            node.description = "The outside world"
            media.class = "Audio/Duplex"
            object.linger = true
            audio.position = [ FL, FR ]
    }
}
{ factory = adapter
    args = {
        factory.name = support.null-audio-sink
            node.name = "only-me"
            node.description = "Voices in my head"
            media.class = "Audio/Duplex"
            object.linger = true
            audio.position = [ FL, FR ]
    }
}

Pipewire output

$ ALSOFT_DRIVERS=pipewire openal-info 
Available playback devices:
    Starship/Matisse HD Audio Controller
    Starship/Matisse HD Audio Controller (ALC1220 Digital)
Available capture devices:
    USB PnP Audio Device
    Starship/Matisse HD Audio Controller
    Starship/Matisse HD Audio Controller (ALC1220 Alt Analog)
    Monitor of Starship/Matisse HD Audio Controller
    Monitor of Starship/Matisse HD Audio Controller (ALC1220 Digital)
Default playback device: Starship/Matisse HD Audio Controller
Default capture device: USB PnP Audio Device
ALC version: 1.1

** Info for device "Starship/Matisse HD Audio Controller" **
ALC version: 1.1
ALC extensions:
    ALC_ENUMERATE_ALL_EXT, ALC_ENUMERATION_EXT, ALC_EXT_CAPTURE,
    ALC_EXT_DEDICATED, ALC_EXT_disconnect, ALC_EXT_EFX,
    ALC_EXT_thread_local_context, ALC_SOFT_device_clock, ALC_SOFT_HRTF,
    ALC_SOFT_loopback, ALC_SOFT_loopback_bformat, ALC_SOFT_output_limiter,
    ALC_SOFTX_output_mode, ALC_SOFT_pause_device, ALC_SOFTX_reopen_device
Available HRTFs:
    Default HRTF
    Built-In HRTF
OpenAL vendor string: OpenAL Community
OpenAL renderer string: OpenAL Soft
OpenAL version string: 1.1 ALSOFT 1.21.1
OpenAL extensions:
    AL_EXT_ALAW, AL_EXT_BFORMAT, AL_EXT_DOUBLE, AL_EXT_EXPONENT_DISTANCE,
    AL_EXT_FLOAT32, AL_EXT_IMA4, AL_EXT_LINEAR_DISTANCE, AL_EXT_MCFORMATS,
    AL_EXT_MULAW, AL_EXT_MULAW_BFORMAT, AL_EXT_MULAW_MCFORMATS, AL_EXT_OFFSET,
    AL_EXT_source_distance_model, AL_EXT_SOURCE_RADIUS, AL_EXT_STEREO_ANGLES,
    AL_LOKI_quadriphonic, AL_SOFT_bformat_ex, AL_SOFTX_bformat_hoa,
    AL_SOFT_block_alignment, AL_SOFTX_callback_buffer,
    AL_SOFTX_convolution_reverb, AL_SOFT_deferred_updates,
    AL_SOFT_direct_channels, AL_SOFT_direct_channels_remix,
    AL_SOFT_effect_target, AL_SOFT_events, AL_SOFTX_filter_gain_ex,
    AL_SOFT_gain_clamp_ex, AL_SOFTX_hold_on_disconnect, AL_SOFT_loop_points,
    AL_SOFTX_map_buffer, AL_SOFT_MSADPCM, AL_SOFT_source_latency,
    AL_SOFT_source_length, AL_SOFT_source_resampler, AL_SOFT_source_spatialize,
    AL_SOFTX_UHJ
Available resamplers:
    Nearest
    Linear *
    Cubic
    11th order Sinc (fast)
    11th order Sinc
    23rd order Sinc (fast)
    23rd order Sinc
EFX version: 1.0
Max auxiliary sends: 2
Supported filters:
    Low-pass, High-pass, Band-pass
Supported effects:
    EAX Reverb, Reverb, Chorus, Distortion, Echo, Flanger, Frequency Shifter,
    Vocal Morpher, Pitch Shifter, Ring Modulator, Autowah, Compressor,
    Equalizer, Dedicated Dialog, Dedicated LFE

ALSA output

$ ALSOFT_DRIVERS=alsa openal-info        
Available playback devices:
    ALSA Default
    HDA ATI HDMI, HDMI 0 (CARD=HDMI,DEV=3)
    HDA ATI HDMI, HDMI 1 (CARD=HDMI,DEV=7)
    HDA ATI HDMI, HDMI 2 (CARD=HDMI,DEV=8)
    HDA ATI HDMI, HDMI 3 (CARD=HDMI,DEV=9)
    HDA ATI HDMI, HDMI 4 (CARD=HDMI,DEV=10)
    HDA ATI HDMI, HDMI 5 (CARD=HDMI,DEV=11)
    HD-Audio Generic, ALC1220 Analog (CARD=Generic,DEV=0)
    HD-Audio Generic, ALC1220 Digital (CARD=Generic,DEV=1)
Available capture devices:
    ALSA Default
    HD-Audio Generic, ALC1220 Analog (CARD=Generic,DEV=0)
    HD-Audio Generic, ALC1220 Alt Analog (CARD=Generic,DEV=2)
    HD Pro Webcam C920, USB Audio (CARD=C920,DEV=0)
    USB PnP Audio Device, USB Audio (CARD=Device,DEV=0)
Default playback device: ALSA Default
Default capture device: ALSA Default
ALC version: 1.1

** Info for device "ALSA Default" **
ALC version: 1.1
ALC extensions:
    ALC_ENUMERATE_ALL_EXT, ALC_ENUMERATION_EXT, ALC_EXT_CAPTURE,
    ALC_EXT_DEDICATED, ALC_EXT_disconnect, ALC_EXT_EFX,
    ALC_EXT_thread_local_context, ALC_SOFT_device_clock, ALC_SOFT_HRTF,
    ALC_SOFT_loopback, ALC_SOFT_loopback_bformat, ALC_SOFT_output_limiter,
    ALC_SOFTX_output_mode, ALC_SOFT_pause_device, ALC_SOFTX_reopen_device
Available HRTFs:
    Default HRTF
    Built-In HRTF
OpenAL vendor string: OpenAL Community
OpenAL renderer string: OpenAL Soft
OpenAL version string: 1.1 ALSOFT 1.21.1
OpenAL extensions:
    AL_EXT_ALAW, AL_EXT_BFORMAT, AL_EXT_DOUBLE, AL_EXT_EXPONENT_DISTANCE,
    AL_EXT_FLOAT32, AL_EXT_IMA4, AL_EXT_LINEAR_DISTANCE, AL_EXT_MCFORMATS,
    AL_EXT_MULAW, AL_EXT_MULAW_BFORMAT, AL_EXT_MULAW_MCFORMATS, AL_EXT_OFFSET,
    AL_EXT_source_distance_model, AL_EXT_SOURCE_RADIUS, AL_EXT_STEREO_ANGLES,
    AL_LOKI_quadriphonic, AL_SOFT_bformat_ex, AL_SOFTX_bformat_hoa,
    AL_SOFT_block_alignment, AL_SOFTX_callback_buffer,
    AL_SOFTX_convolution_reverb, AL_SOFT_deferred_updates,
    AL_SOFT_direct_channels, AL_SOFT_direct_channels_remix,
    AL_SOFT_effect_target, AL_SOFT_events, AL_SOFTX_filter_gain_ex,
    AL_SOFT_gain_clamp_ex, AL_SOFTX_hold_on_disconnect, AL_SOFT_loop_points,
    AL_SOFTX_map_buffer, AL_SOFT_MSADPCM, AL_SOFT_source_latency,
    AL_SOFT_source_length, AL_SOFT_source_resampler, AL_SOFT_source_spatialize,
    AL_SOFTX_UHJ
Available resamplers:
    Nearest
    Linear *
    Cubic
    11th order Sinc (fast)
    11th order Sinc
    23rd order Sinc (fast)
    23rd order Sinc
EFX version: 1.0
Max auxiliary sends: 2
Supported filters:
    Low-pass, High-pass, Band-pass
Supported effects:
    EAX Reverb, Reverb, Chorus, Distortion, Echo, Flanger, Frequency Shifter,
    Vocal Morpher, Pitch Shifter, Ring Modulator, Autowah, Compressor,
    Equalizer, Dedicated Dialog, Dedicated LFE

Pulse output:

$ ALSOFT_DRIVERS=pulse openal-info 
Available playback devices:
    Voices in my head
    Sharing is caring
    The outside world
    Starship/Matisse HD Audio Controller
    Starship/Matisse HD Audio Controller (ALC1220 Digital)
Available capture devices:
    The outside world
    Sharing is caring
    Voices in my head
    USB PnP Audio Device
    Monitor of Starship/Matisse HD Audio Controller
    Starship/Matisse HD Audio Controller
    Monitor of Starship/Matisse HD Audio Controller (ALC1220 Digital)
    Starship/Matisse HD Audio Controller (ALC1220 Alt Analog)
Default playback device: Voices in my head
Default capture device: The outside world
ALC version: 1.1

** Info for device "Voices in my head" **
ALC version: 1.1
ALC extensions:
    ALC_ENUMERATE_ALL_EXT, ALC_ENUMERATION_EXT, ALC_EXT_CAPTURE,
    ALC_EXT_DEDICATED, ALC_EXT_disconnect, ALC_EXT_EFX,
    ALC_EXT_thread_local_context, ALC_SOFT_device_clock, ALC_SOFT_HRTF,
    ALC_SOFT_loopback, ALC_SOFT_loopback_bformat, ALC_SOFT_output_limiter,
    ALC_SOFTX_output_mode, ALC_SOFT_pause_device, ALC_SOFTX_reopen_device
Available HRTFs:
    Default HRTF
    Built-In HRTF
OpenAL vendor string: OpenAL Community
OpenAL renderer string: OpenAL Soft
OpenAL version string: 1.1 ALSOFT 1.21.1
OpenAL extensions:
    AL_EXT_ALAW, AL_EXT_BFORMAT, AL_EXT_DOUBLE, AL_EXT_EXPONENT_DISTANCE,
    AL_EXT_FLOAT32, AL_EXT_IMA4, AL_EXT_LINEAR_DISTANCE, AL_EXT_MCFORMATS,
    AL_EXT_MULAW, AL_EXT_MULAW_BFORMAT, AL_EXT_MULAW_MCFORMATS, AL_EXT_OFFSET,
    AL_EXT_source_distance_model, AL_EXT_SOURCE_RADIUS, AL_EXT_STEREO_ANGLES,
    AL_LOKI_quadriphonic, AL_SOFT_bformat_ex, AL_SOFTX_bformat_hoa,
    AL_SOFT_block_alignment, AL_SOFTX_callback_buffer,
    AL_SOFTX_convolution_reverb, AL_SOFT_deferred_updates,
    AL_SOFT_direct_channels, AL_SOFT_direct_channels_remix,
    AL_SOFT_effect_target, AL_SOFT_events, AL_SOFTX_filter_gain_ex,
    AL_SOFT_gain_clamp_ex, AL_SOFTX_hold_on_disconnect, AL_SOFT_loop_points,
    AL_SOFTX_map_buffer, AL_SOFT_MSADPCM, AL_SOFT_source_latency,
    AL_SOFT_source_length, AL_SOFT_source_resampler, AL_SOFT_source_spatialize,
    AL_SOFTX_UHJ
Available resamplers:
    Nearest
    Linear *
    Cubic
    11th order Sinc (fast)
    11th order Sinc
    23rd order Sinc (fast)
    23rd order Sinc
EFX version: 1.0
Max auxiliary sends: 2
Supported filters:
    Low-pass, High-pass, Band-pass
Supported effects:
    EAX Reverb, Reverb, Chorus, Distortion, Echo, Flanger, Frequency Shifter,
    Vocal Morpher, Pitch Shifter, Ring Modulator, Autowah, Compressor,
    Equalizer, Dedicated Dialog, Dedicated LFE
kcat commented 2 years ago

Can you provide a full trace log? The output of ALSOFT_LOGLEVEL=3 ALSOFT_DRIVERS=pipewire openal-info.

kcat commented 2 years ago

Also, try latest master. Audio/Duplex devices are now handled.

mazunki commented 2 years ago

I was looking at it some more afterwards, and found the loglevel variable after digging through the source code. Would be nice if alsoft-info --help had that info too.

Anyway, I saw the "Got default %s device" appeared correctly, followed by detection of some other devices, similar to below, yet after displaying the new devices it displayed the wrong "Default %s device", but otherwise everything else seemed okay.

After updating to new version,

$ ALSOFT_DRIVERS=pipewire ALSOFT_LOGLEVEL=3 telegram-desktop 
...
[ALSOFT] (II) Got duplex device "both-me-and-others"
[ALSOFT] (II)   "Sharing is caring" = ID 30
[ALSOFT] (II) Device ID 30 sample rate: 44100 (range: 1 -> 2147483647)
[ALSOFT] (II) Device ID 30 got 2 positions for Stereo
[ALSOFT] (II) Got duplex device "others"
[ALSOFT] (II)   "The outside world" = ID 31
[ALSOFT] (II) Device ID 31 sample rate: 44100 (range: 1 -> 2147483647)
[ALSOFT] (II) Device ID 31 got 2 positions for Stereo
[ALSOFT] (II) Got duplex device "only-me"
[ALSOFT] (II)   "Voices in my head" = ID 32
[ALSOFT] (II) Device ID 32 sample rate: 44100 (range: 1 -> 2147483647)
[ALSOFT] (II) Device ID 32 got 2 positions for Stereo
[ALSOFT] (II) Got default playback device "only-me"
[ALSOFT] (II) Got default capture device "others"
[ALSOFT] (II) Got source device "alsa_input.usb-0c76_USB_PnP_Audio_Device-00.capture.0.0"
[ALSOFT] (II)   "USB PnP Audio Device" = ID 75
[ALSOFT] (II) Device ID 75 sample rate: 48000
[ALSOFT] (II) Got sink device "alsa_output.pci-0000_0e_00.4.playback.0.0"
[ALSOFT] (II)   "Starship/Matisse HD Audio Controller" = ID 109
[ALSOFT] (II) Device ID 109 sample rate: 48000 (range: 44100 -> 192000)
[ALSOFT] (II) Got source device "alsa_input.pci-0000_0e_00.4.capture.0.0"
[ALSOFT] (II)   "Starship/Matisse HD Audio Controller" = ID 73
[ALSOFT] (II) Device ID 73 sample rate: 48000 (range: 44100 -> 192000)
[ALSOFT] (II) Got sink device "alsa_output.pci-0000_0e_00.4.playback.1.0"
[ALSOFT] (II)   "Starship/Matisse HD Audio Controller (ALC1220 Digital)" = ID 90
[ALSOFT] (II) Device ID 90 sample rate: 48000 (range: 32000 -> 192000)
[ALSOFT] (II) Got source device "alsa_input.pci-0000_0e_00.4.capture.2.0"
[ALSOFT] (II)   "Starship/Matisse HD Audio Controller (ALC1220 Alt Analog)" = ID 135
[ALSOFT] (II) Device ID 135 sample rate: 48000 (range: 44100 -> 192000)
    Voices in my head
    Sharing is caring
    The outside world
    Starship/Matisse HD Audio Controller (ALC1220 Digital)
    Starship/Matisse HD Audio Controller
Available capture devices:
    The outside world
    Sharing is caring
    Voices in my head
    Starship/Matisse HD Audio Controller
    USB PnP Audio Device
    Starship/Matisse HD Audio Controller (ALC1220 Alt Analog)
    Monitor of Starship/Matisse HD Audio Controller (ALC1220 Digital)
    Monitor of Starship/Matisse HD Audio Controller
Default playback device: Voices in my head
Default capture device: The outside world
...

This looks promising. From openal-info everything seems to be in order... but.

When I try to use it in Telegram Desktop it now displays the duplex nodes, with the proper description label, yay! Regardless, setting the input/output to "Default device" still uses the wrong devices. I'm not entirely sure how to debug whether or not this is a bug in Telegram or here. I could test some other apps, if you know about some.

mazunki commented 2 years ago

I can confirm ALSOFT_DRIVERS=pipewire mpv . uses the default device correctly, when built with USE='openal -alsa'.

Thanks for the help, I will report to Telegram.

mazunki commented 2 years ago

Perhaps I was too quick on my toes. The output device had been working already, the problem was with input. Got to keep testing the source device.

amano-kenji commented 1 year ago

The current problem of openal pipewire backend is that it sets target.object to the object.serial of default.audio.sink, which is a number. I can't match object.serial of a node in pipewire stream.rules because it changes over time.

default.audio.sink on my system is null-sink which is useless.

In pipewire stream.rules, I have a rule for assigning default-sink to target.object if target.object is missing for a new stream.

If openal pipewire backend just doesn't set target.object when it wants the default, target.object will be chosen by pipewire stream.rules.

Just don't set target.object if openal wants the default.

Because of the current openal behavior, I had to configure openal to use pulseaudio backend which works correctly.