project-owner / peppyalsa.doc

GNU General Public License v3.0
13 stars 6 forks source link

Peppyalsa-Plugin for pulseaudio #4

Closed reparator closed 11 months ago

reparator commented 11 months ago

Good evening, I have a question regarding peppyalsa-plugin. Hopefully you can help. Sorry for the long text, I wanted to provide as much information as possible in the first step. I am on my way to build my own squeezebox on a RPi 3+. The linux I use is:

pi@squeezebox5:~ $ cat /proc/version Linux version 5.10.103-v7+ (dom@buildbot) (arm-linux-gnueabihf-gcc-8 (Ubuntu/Linaro 8.4.0-3ubuntu1) 8.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #1529 SMP Tue Mar 8 12:21:37 GMT 2022

Unfortunately it is using Pulseaudio for playback music by default. As Soundcard I have:

pi@squeezebox5:~ $ aplay -l
**** Liste der Hardware-Geräte (PLAYBACK) ****
Karte 0: sndrpihifiberry [snd_rpi_hifiberry_dacplus], Gerät 0: HiFiBerry DAC+ HiFi pcm512x-hifi-0 [HiFiBerry DAC+ HiFi pcm512x-hifi-0]
  Sub-Geräte: 1/1
  Sub-Gerät #0: subdevice #0

Playback works with cvlc, aplay and the java application SoftSqueeze. Sound comes in good quality from the speakers.

Now I want to adapt the peppyalsa plugin because I want use my DIY Nixxie-style arduino based VU-Meter. So I setup peppyalsa-plugin and configured it. It works, but only if I playback with aplay with explicite given device:

pi@squeezebox5:~ $ aplay -vD softvol_and_peppyalsa ~/Music/Maple\ Leaf\ Rag.wav 
Wiedergabe: WAVE '/home/pi/Music/Maple Leaf Rag.wav' : Signed 16 bit Little Endian, Rate: 44100 Hz, stereo
Soft volume PCM
Control: PCM
min_dB: -51
max_dB: 0
resolution: 256
Its setup is:
  stream       : PLAYBACK
  access       : RW_INTERLEAVED
  format       : S16_LE
  subformat    : STD
  channels     : 2
  rate         : 44100
  exact rate   : 44100 (44100/1)
  msbits       : 16
  buffer_size  : 22052
  period_size  : 5513
  period_time  : 125011
  tstamp_mode  : NONE
  tstamp_type  : MONOTONIC
  period_step  : 1
  avail_min    : 5513
  period_event : 0
  start_threshold  : 22052
  stop_threshold   : 22052
  silence_threshold: 0
  silence_size : 0
  boundary     : 1445199872
Slave: Meter PCM
Its setup is:
  stream       : PLAYBACK
  access       : MMAP_INTERLEAVED
  format       : S16_LE
  subformat    : STD
  channels     : 2
  rate         : 44100
  exact rate   : 44100 (44100/1)
  msbits       : 16
  buffer_size  : 22052
  period_size  : 5513
  period_time  : 125011
  tstamp_mode  : NONE
  tstamp_type  : MONOTONIC
  period_step  : 1
  avail_min    : 5513
  period_event : 0
  start_threshold  : 22052
  stop_threshold   : 22052
  silence_threshold: 0
  silence_size : 0
  boundary     : 1445199872
Slave: Hardware PCM card 0 'snd_rpi_hifiberry_dacplus' device 0 subdevice 0
Its setup is:
  stream       : PLAYBACK
  access       : MMAP_INTERLEAVED
  format       : S16_LE
  subformat    : STD
  channels     : 2
  rate         : 44100
  exact rate   : 44100 (44100/1)
  msbits       : 16
  buffer_size  : 22052
  period_size  : 5513
  period_time  : 125011
  tstamp_mode  : NONE
  tstamp_type  : MONOTONIC
  period_step  : 1
  avail_min    : 5513
  period_event : 0
  start_threshold  : 22052
  stop_threshold   : 22052
  silence_threshold: 0
  silence_size : 0
  boundary     : 1445199872
  appl_ptr     : 0
  hw_ptr       : 0

The fifo-pipe is filled and peppyalsa-client shows VU signals.

When I play with default device, playback works (sound comes out of the speakers) but the fifo pipe stays empty. Either it is not rebuild if I delete it before playing.

pi@squeezebox5:~ $ aplay -v ~/Music/Maple\ Leaf\ Rag.wav 
Wiedergabe: WAVE '/home/pi/Music/Maple Leaf Rag.wav' : Signed 16 bit Little Endian, Rate: 44100 Hz, stereo
ALSA <-> PulseAudio PCM I/O Plugin
Its setup is:
  stream       : PLAYBACK
  access       : RW_INTERLEAVED
  format       : S16_LE
  subformat    : STD
  channels     : 2
  rate         : 44100
  exact rate   : 44100 (44100/1)
  msbits       : 16
  buffer_size  : 22050
  period_size  : 5512
  period_time  : 125000
  tstamp_mode  : NONE
  tstamp_type  : GETTIMEOFDAY
  period_step  : 1
  avail_min    : 5512
  period_event : 0
  start_threshold  : 22050
  stop_threshold   : 22050
  silence_threshold: 0
  silence_size : 0
  boundary     : 1445068800

I think the problem is that the sound goes directly from Pulseaudio to the ALSA <-> PulseAudio PCM I/O Plugin without using the inputs given in ~/.asoundrc. The same happens when I playback with cvlc or Softsqueeze. ~/.asoundrc looks like this:

   type plug
   slave.pcm softvol_and_peppyalsa;
}
ctl.!default {
   type pulse
   card sndrpihifiberry
}
pcm.peppyalsa {
   type meter
   slave.pcm "hw:0,0"
   scopes.0 peppyalsa
}
pcm.softvol_and_peppyalsa {
   type softvol
   slave.pcm "peppyalsa"
   control {name "PCM" card 0 }
}
pcm_scope.peppyalsa {
   type peppyalsa
   decay_ms 400
   meter "/home/pi/myfifo"
   meter_max 100
   meter_show 0
#        spectrum "/home/pi/myfifosa"
#        spectrum_max 100
#        spectrum_size 30
}
pcm_scope_type.peppyalsa {
        lib /usr/local/lib/libpeppyalsa.so
}
pcm.dsp0 peppyalsa

Is there a chance to switch of the pulseaudio-alsa-plugin or redirect it to use the .asoundrc-config-file? Or simply said: How can I use peppyalsa-plugin with Pulseaudio? If I understand it right, ALSA is the base which communicates with the hardware (soundcard) whereas PA resides on top of Alsa as a higher level layer. Your help would be appreciated! Regards Stefan

project-owner commented 11 months ago

Hi,

I've never dealt with Pulseaudio. As far as I know there is no Pulseaudio involved if you have a no-desktop OS like Raspberry Pi OS Lite. What will happen if you specify 'default' device explicitly:

pi@squeezebox5:~ $ aplay -D default ~/Music/Maple\ Leaf\ Rag.wav 

Best regards

reparator commented 11 months ago

Hi, thanks for your quick response!

pi@squeezebox5:~ $ aplay -vD default ~/Music/Maple\ Leaf\ Rag.wav
Wiedergabe: WAVE '/home/pi/Music/Maple Leaf Rag.wav' : Signed 16 bit Little Endian, Rate: 44100 Hz, stereo
ALSA <-> PulseAudio PCM I/O Plugin
Its setup is:
  stream       : PLAYBACK
  access       : RW_INTERLEAVED
  format       : S16_LE
  subformat    : STD
  channels     : 2
  rate         : 44100
  exact rate   : 44100 (44100/1)
  msbits       : 16
  buffer_size  : 22050
  period_size  : 5512
  period_time  : 125000
  tstamp_mode  : NONE
  tstamp_type  : GETTIMEOFDAY
  period_step  : 1
  avail_min    : 5512
  period_event : 0
  start_threshold  : 22050
  stop_threshold   : 22050
  silence_threshold: 0
  silence_size : 0
  boundary     : 1445068800

Musik plays ok, but no pipe filled!

As far as I know there is no Pulseaudio involved if you have a no-desktop OS like Raspberry Pi OS Lite.

Good point! I use the desktop-os because I need X11 for the Squeezebox-Software. I searched the pulseaudio pages on https://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/SystemWide/. There is described how to stop pulseaudio. I will try that and hope that alsa will do the job than. I will come up with a report ... Regards Stefan

reparator commented 11 months ago

Ok, seems to be difficult: The Squeezebox-Software needs X11, X11 is configured to use pulseaudio and I'm too stupid to see through this forest of configuration files in pulseaudio. Pulseaudio seems to speak directly to the sound-cards via this module "module-alsa-sink". Here https://wiki.debianforum.de/MPD_als_Systemdienst_mit_ALSA_und_Pulseaudio is described a similar problem as far as I can see. The .asoundrc is not noticed by Pulseaudio-ALSA-Plu, means although the integration of the meters and peppyalsa-plugin throuh .asoundrc is not conducted. The only solution seems to be a new peppy-pulseaudio-plugin-module .-) Regards Stefan

project-owner commented 11 months ago

Sorry, I cannot help you with Pulseaudio. If you will find a solution please let me know.

Best regards

reparator commented 11 months ago

I'll do some more studies. Regards Stefan

reparator commented 11 months ago

OK, I solved it :-) The problem is, that Pulseaudio catches the sound-output-device and uses its own plugin to play the sound. The responsible plugin is the ALSA <-> PulseAudio PCM I/O Plugin. This is a good method in principle as the user (or the sound playing application) has not to care for it. The plugin works flawless and silent with most applications. But: In our case we want to smuggle our own output device (the fifo filling peppy-alsa-plugin) in the stream. As we don´t have a pulseaudio-like plugin with peppyalsa functionality, we need to redirect the pulseaudio-sound-stream to the standard ALSA-plugin module-alsa-sink. Here is a description how I solved it for me: Install peppyalsa-plugin as described (get it, compile it and install it). https://github.com/project-owner/peppyalsa.doc/wiki/Installation Create a file .asoundrc in the users home directory with the content as described here https://github.com/project-owner/peppyalsa.doc/wiki/Configuration Compile the peppyalsa-client:

pi@squeezebox:~ $ cd /home/pi/peppyalsa/src
pi@squeezebox:~/peppyalsa/src $ gcc peppyalsa-client.c -o peppyalsa-client
pi@squeezebox:~/peppyalsa/src $ ./peppyalsa-client

Add a pulseaudio configuration file to the users config files:

pi@squeezebox5:~ $ cd ~/.config/pulse/
pi@squeezebox5:~/.config/pulse $ nano default.pa 

with the following content:

# include the standard file 
# .include /etc/pulse/default.pa 
# unload-module module-udev-detect 
# unload-module module-card-restore 
# unload-module module-detect 
load-module module-alsa-sink device=softvol_and_peppyalsa 
load-module module-native-protocol-unix 
load-module module-always-sink 
# load-module module-suspend-on-idle

The file ~/.config/pulse/default.pa is read at login time if it exists and replaces the standard pa-configuration file which resides in /etc/pulse/. Our file redirects the output of the stream via the module module-alsa-sink to the device softvol_and_peppyalsa which is described in ~/.asoundrc.

To test it, start the peppyalsa-client:

pi@squeezebox5:~ $ ~/peppyalsa/src/peppyalsa-client  
Peppy ALSA Client. Goya Edition. 2018/09/08 
No pipe name provided, defaulting to /home/pi/myfifo
L:
R:

Now play some music from your favorite X11 player (e.g. vlc - I used my java app softsqueeze). You should see some jitters of the meters. If not, try to increase the volume by:

  1. Increasing the volume of the Alsa-sink: (in a second terminal)
    
    pi@squeezebox5:~ $ pactl set-sink-volume @DEFAULT_SINK@ +20% 
    pi@squeezebox5:~ $ pactl set-sink-volume @DEFAULT_SINK@ +20% 
    pi@squeezebox5:~ $ pactl set-sink-volume @DEFAULT_SINK@ +20% 

or 2.
`
pi@squeezebox5:~ $ alsamixer
`
Choose with F6 your output soundcard and increase the pcm-channel (e.g. to 80 %)

or 3.
Change the value for meter_max in ~/.asoundrc:
In the device "pcm_scope.peppyalsa" write 
`meter_max 1000`

I hope this helps somebody. It took me some days to look through the audio forest. Even if the documentations of alsa and pulseaudio are really comprehensive it is not easy to understand for a simple user.
Regards 
Stefan
reparator commented 11 months ago

Thanks to peppyowner for his efforts and continuous enhancement of the fantastic peppyplayer project!

project-owner commented 11 months ago

Great job! Hopefully it will be helpful for somebody else. Thank you!