janvda / balena-pulseaudio

Is a balena application running a pulseaudio server and demonstrating how it can be used for playing and recording audio on a raspberry pi. It also supports bluetooth audio devices.
Eclipse Public License 2.0
6 stars 2 forks source link

pulseaudio-server service is not automatically recognizing all connected audio sources/sinks #1

Open janvda opened 5 years ago

janvda commented 5 years ago

Although module module-udev-detectis loaded at startup only the raspberry audio jack is recognized as sink.

The connected USB microphone and the hdmi audio are not automatically recognized by the pulseaudio-service although they are properly configured as alsa device as can be checked by executing command aplay -land arecord -l in an pulseaudio-serverterminal window as you can see below.

bash-5.0# aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
  Subdevices: 7/7
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
card 0: ALSA [bcm2835 ALSA], device 1: bcm2835 ALSA [bcm2835 IEC958/HDMI]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

bash-5.0# arecord -l
**** List of CAPTURE Hardware Devices ****
card 1: CameraB409241 [USB Camera-B4.09.24.1], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
janvda commented 5 years ago

To fix this the following 2 lines are added to default.pa:

# JVA 2019-08-24: assure connected USB microphone is properly defined as pulseaudio source.
load-module module-alsa-source device=hw:1,0

# JVA 2019-08-24: tried to define without succes the rapberry pi hdmi port as a pulseaudio sink.
load-module module-alsa-sink device=hw:0,1

Note that only the first load-module seemed to work as can be seen by the following command:

bash-5.0# pactl list sources short
1       alsa_output.default.monitor     module-alsa-sink.c      s16le 2ch 44100Hz       SUSPENDED
2       alsa_input.hw_1_0       module-alsa-source.c    s16le 4ch 16000Hz       SUSPENDED

The 2nd load module didn't work as can be seen by following command.

bash-5.0# pactl list sinks short
1       alsa_output.default     module-alsa-sink.c      s16le 2ch 44100Hz       SUSPENDED
janvda commented 5 years ago

Manually adding the hdmi sink by command pactl load-module module-alsa-sink device=hw:0,1 did work as can be seen by following trace.

bash-5.0# pactl load-module module-alsa-sink device=hw:0,1
27
bash-5.0# pactl list sinks short
1       alsa_output.default     module-alsa-sink.c      s16le 2ch 44100Hz       SUSPENDED
2       alsa_output.hw_0_1      module-alsa-sink.c      s16le 2ch 44100Hz       SUSPENDED
bash-5.0# pactl list sinks
Sink #1
        State: SUSPENDED
        Name: alsa_output.default
        Description: bcm2835 ALSA
        Driver: module-alsa-sink.c
        Sample Specification: s16le 2ch 44100Hz
        Channel Map: front-left,front-right
        Owner Module: 22
        Mute: no
        Volume: front-left: 65536 / 100% / 0.00 dB,   front-right: 65536 / 100% / 0.00 dB
                balance 0.00
        Base Volume: 65536 / 100% / 0.00 dB
        Monitor Source: alsa_output.default.monitor
        Latency: 0 usec, configured 0 usec
        Flags: HARDWARE DECIBEL_VOLUME LATENCY 
        Properties:
                alsa.resolution_bits = "16"
                device.api = "alsa"
                device.class = "sound"
                alsa.class = "generic"
                alsa.subclass = "generic-mix"
                alsa.name = "bcm2835 ALSA"
                alsa.id = "bcm2835 ALSA"
                alsa.subdevice = "0"
                alsa.subdevice_name = "subdevice #0"
                alsa.device = "0"
                alsa.card = "0"
                alsa.card_name = "bcm2835 ALSA"
                alsa.long_card_name = "bcm2835 ALSA"
                device.bus_path = "/devices/platform/soc/soc:audio/bcm2835_alsa/sound/card0"
                sysfs.path = "/devices/platform/soc/soc:audio/bcm2835_alsa/sound/card0"
                device.string = "default"
                device.buffering.buffer_size = "17632"
                device.buffering.fragment_size = "4416"
                device.access_mode = "mmap"
                device.description = "bcm2835 ALSA"
                device.icon_name = "audio-card"
        Formats:
                pcm

Sink #2
        State: SUSPENDED
        Name: alsa_output.hw_0_1
        Description: bcm2835 ALSA
        Driver: module-alsa-sink.c
        Sample Specification: s16le 2ch 44100Hz
        Channel Map: front-left,front-right
        Owner Module: 27
        Mute: no
        Volume: front-left: 65536 / 100% / 0.00 dB,   front-right: 65536 / 100% / 0.00 dB
                balance 0.00
        Base Volume: 65536 / 100% / 0.00 dB
        Monitor Source: alsa_output.hw_0_1.monitor
        Latency: 0 usec, configured 0 usec
        Flags: HARDWARE DECIBEL_VOLUME LATENCY 
        Properties:
                alsa.resolution_bits = "16"
                device.api = "alsa"
                device.class = "sound"
                alsa.class = "generic"
                alsa.subclass = "generic-mix"
                alsa.name = "bcm2835 IEC958/HDMI"
                alsa.id = "bcm2835 ALSA"
                alsa.subdevice = "0"
                alsa.subdevice_name = "subdevice #0"
                alsa.device = "1"
                alsa.card = "0"
                alsa.card_name = "bcm2835 ALSA"
                alsa.long_card_name = "bcm2835 ALSA"
                device.bus_path = "/devices/platform/soc/soc:audio/bcm2835_alsa/sound/card0"
                sysfs.path = "/devices/platform/soc/soc:audio/bcm2835_alsa/sound/card0"
                device.string = "hw:0,1"
                device.buffering.buffer_size = "131072"
                device.buffering.fragment_size = "131072"
                device.access_mode = "mmap+timer"
                device.description = "bcm2835 ALSA"
                device.icon_name = "audio-card"
        Formats:
                pcm
bash-5.0# 
janvda commented 5 years ago

Manually adding the hdmi sink by command pactl load-module module-alsa-sink device=hw:0,1 did also worked on the branch no_alpine_pulseaudio_image.

janvda commented 5 years ago

alsa in pulseaudio-server is also not recognizing USB audio devices that are connected on the fly - for that you need to restart the pulseaudio-server

root@ba7c427:/# arecord -l
**** List of CAPTURE Hardware Devices ****
card 1: CameraB409241 [USB Camera-B4.09.24.1], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
root@ba7c427:/# aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
  Subdevices: 7/7
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
card 0: ALSA [bcm2835 ALSA], device 1: bcm2835 ALSA [bcm2835 IEC958/HDMI]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
root@ba7c427:/# arecord -l
**** List of CAPTURE Hardware Devices ****
card 1: CameraB409241 [USB Camera-B4.09.24.1], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
root@ba7c427:/# 

and after restart of the pulseaudio-server we get (so you can see that is recognizing card 2)

root@ba7c427:/# aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
  Subdevices: 7/7
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
card 0: ALSA [bcm2835 ALSA], device 1: bcm2835 ALSA [bcm2835 IEC958/HDMI]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 2: Device [USB2.0 Device], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
root@ba7c427:/# arecord -l
**** List of CAPTURE Hardware Devices ****
card 1: CameraB409241 [USB Camera-B4.09.24.1], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 2: Device [USB2.0 Device], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
root@ba7c427:/#