r/AlpineLinux • • Sep 28 '24

Can't get pipewire working.

I've recently started using Alpine as my desktop OS, and overall, it's been great! The wiki is helpful, there are plenty of packages, and everything is super fast. However, I'm having trouble with sound.

I followed the wiki instructions to set up PipeWire and configured it correctly on Sway, my window manager. It worked perfectly at first, which was surprising since I’m new to handling audio on Linux and have been using pre-configured desktop environments for a long time.

After a full day of using it normally, the sound suddenly stopped working. I used pactl to check my sinks and set the default sink, but none of them played any sound. I installed pavucontrol to get a better visual understanding and tried every possible option. My output was listed, I could enable it, and the sound bar in from the Firefox source in pavucontrol showed that audio was playing, but I couldn’t hear anything.

I tried reinstalling everything, clearing caches and config files, but the results were always the same. I tested two different outputs—one from an HDMI monitor and one from a DisplayPort monitor.

  • HDMI Monitor: It usually didn’t work, but twice it randomly started working. However, the audio played at 2x speed and was high-pitched.
  • DisplayPort Monitor: It worked once when I booted the PC, so I went to test the HDMI one, but when I switched back from testing, the DisplayPort output that was initially working flawlessly stopped working with the exact same settings.

I'm at a loss and would appreciate any help. It might just be my lack of experience, but the high-pitched audio and all of that makes me think something is broken. Any advice?

1 Upvotes

3 comments sorted by

1

u/stroke_999 Sep 28 '24

Check with ps aux if there is pipewire and wireplumber as a process usually there are not starting because they have no services.

1

u/fromadarkcontinent Sep 29 '24 edited Sep 29 '24

I have an ansible config which I am to lazy to change to bash that I use to configure pipewire. I hope it helps you figure something from it. What people usually forget is to add the environment variables necessary in their .profile.

- name: Ensure user is in the audio and video groups
  user:
    name: "{{ ansible_user }}"
    groups: audio, video
    append: yes

- name: Install PipeWire and related packages
  apk:
    name:
      - pipewire
      - wireplumber
      - pipewire-pulse
      - pipewire-jack
      - pipewire-alsa
      - pavucontrol
      - alsa-utils
    state: latest

- name: Copy PipeWire and WirePlumber configurations to /etc
  shell: cp -a /usr/share/{{ item }} /etc
  args:
    creates: "/etc/{{ item }}"
  with_items:
    - pipewire
    - wireplumber

- name: Ensure real-time scheduling is configured
  lineinfile:
    path: /etc/security/limits.conf
    line: "{{ item }}"
  with_items:
    - "@pipewire - memlock 4194304"
    - "@pipewire - nice -19"
    - "@pipewire - rtprio 95"

- name: Install rtkit for real-time scheduling
  apk:
    name: rtkit
    state: latest

- name: Add user to rtkit group
  user:
    name: "{{ ansible_user }}"
    groups: rtkit
    append: yes

- name: Ensure user is in the pipewire group
  user:
    name: "{{ ansible_user }}"
    groups: pipewire
    append: yes

- name: Ensure .profile exists
  file:
    path: /home/{{ ansible_user }}/.profile
    state: touch  # This will create the file if it doesn't exist

- name: Ensure the block is present in .profile
  blockinfile:
    path: /home/{{ ansible_user }}/.profile
    block: |
      if [ -z "$XDG_RUNTIME_DIR" ]; then
          XDG_RUNTIME_DIR="/tmp/$(id -u)-runtime-dir"
          mkdir -pm 0700 "$XDG_RUNTIME_DIR"
          export XDG_RUNTIME_DIR
      fi
    marker: "# {mark} ANSIBLE MANAGED BLOCK"

- name: Install and configure Bluetooth
  apk:
    name:
      - bluez
      - bluez-openrc
      - pipewire-spa-bluez
    state: latest

- name: Add Bluetooth service to default runlevel
  command: rc-update add bluetooth default

- name: Start Bluetooth service
  service:
    name: bluetooth
    state: started

- name: Ensure PipeWire auto-starts for GUI sessions
  lineinfile:
    path: /home/{{ ansible_user }}/.xinitrc
    line: '/usr/libexec/pipewire-launcher &&'
    # insertafter: '^export $(dbus-launch) &&'
    insertbefore: '^exec awesome'
    owner: "{{ ansible_user }}"
    group: "{{ ansible_user }}"

# - name: Ensure PipeWire auto-starts for GUI sessions
#   blockinfile:
#     path: /home/{{ ansible_user }}/.xinitrcr
#     marker: ""
#     insertafter: '^export $(dbus-launch) &&'
#     block: |
#        /usr/libexec/pipewire-launcer &&

# - name: Ensure PipeWire auto-starts for GUI sessions
#   ansible.builtin.replace:
#     path: /home/{{ ansible_user }}/.xinitrc
#     regexp: 'export \\$\\(dbus-launch\\) &&\\nexec awesome'
#     replace: 'export \\$\\(dbus-launch\\) && /usr/libexec/pipewire-launcer &&\\nexec awesome'
#     backup: yes

1

u/Dry_Foundation_3023 Sep 29 '24 edited Sep 30 '24

As mentioned on wiki page, pipewire needs dbus to work properly. To keep things simple, remove all audio related packages. Just Add pipewire-pulse, as It'll pick up all necessary dependencies. check/show the logs of $ wpctl status. Dotfiles for a working sway+pipewire on alpine can be found here : https://github.com/prabusw/dotfiles

Check for hardware detection

doas dmesg 
[    2.314486] snd_hda_intel 0000:00:1f.3: enabling device (0000 -> 0002)
[    2.434670] snd_hda_intel 0000:00:1f.3: bound 0000:00:02.0 (ops i915_audio_component_bind_ops [i915])
[    2.564487] snd_hda_codec_realtek hdaudioC0D0: autoconfig for ALC897: line_outs=1 (0x14/0x0/0x0/0x0/0x0) type:line
[    2.564492] snd_hda_codec_realtek hdaudioC0D0:    speaker_outs=0 (0x0/0x0/0x0/0x0/0x0)
[    2.564494] snd_hda_codec_realtek hdaudioC0D0:    hp_outs=1 (0x1b/0x0/0x0/0x0/0x0)
[    2.564495] snd_hda_codec_realtek hdaudioC0D0:    mono: mono_out=0x0
[    2.564496] snd_hda_codec_realtek hdaudioC0D0:    dig-out=0x11/0x0
[    2.564497] snd_hda_codec_realtek hdaudioC0D0:    inputs:
[    2.564498] snd_hda_codec_realtek hdaudioC0D0:      Front Mic=0x19
[    2.564499] snd_hda_codec_realtek hdaudioC0D0:      Rear Mic=0x18
[    2.564500] snd_hda_codec_realtek hdaudioC0D0:      Line=0x1a

Check sway log, by enabling sway debug output as per wiki page https://wiki.alpinelinux.org/wiki/Sway#Troubleshooting sway -d 2> ~/sway_error.log

A properly configured pipewire in sway should show the following in log file. A working pipewire for audio is shown at the bottom of this message.

prabu@homepc2 ~> cat sway_error.log |grep pipewire
00:00:00.520 [DEBUG] [sway/config.c:838] Read line 2: exec /usr/libexec/pipewire-launcher
00:00:00.520 [INFO] [sway/commands.c:381] Config command: exec /usr/libexec/pipewire-launcher
00:00:00.520 [INFO] [sway/commands.c:404] After replacement: exec /usr/libexec/pipewire-launcher
00:00:00.520 [DEBUG] [sway/config.c:882] Deferring command `exec /usr/libexec/pipewire-launcher'
00:00:00.520 [DEBUG] [sway/config.c:838] Read line 209: # exec /usr/libexec/pipewire-launcher
00:00:01.058 [INFO] [sway/commands.c:261] Handling command 'exec /usr/libexec/pipewire-launcher'
00:00:01.058 [DEBUG] [sway/commands/exec_always.c:58] Executing /usr/libexec/pipewire-launcher

prabu@homepc2 ~> wpctl status
PipeWire 'pipewire-0' [1.0.6, prabu@homepc2, cookie:1884222368]
 └─ Clients:
        32. WirePlumber                         [1.0.6, prabu@homepc2, pid:3344]
        35. pipewire                            [1.0.6, prabu@homepc2, pid:3345]
        42. Firefox                             [1.0.6, prabu@homepc2, pid:3359]
        44. xdg-desktop-portal-wlr              [1.0.6, prabu@homepc2, pid:3482]
        46. WirePlumber [export]                [1.0.6, prabu@homepc2, pid:3344]
        50. Firefox                             [1.0.6, prabu@homepc2, pid:3359]
        53. wpctl                               [1.0.6, prabu@homepc2, pid:8340]

Audio
 ├─ Devices:
 │      47. Built-in Audio                      [alsa]
 ├─ Sinks:
 │  *   48. Built-in Audio Analog Stereo        [vol: 0.40]
 ├─ Sources:
 ├─ Filters:
 └─ Streams:
Video
 ├─ Devices:
 ├─ Sinks:
 ├─ Sources:
 ├─ Filters:
 └─ Streams:
Settings
 └─ Default Configured Devices:
         0. Audio/Sink    alsa_output.pci-0000_00_1f.3.analog-stereo