I have built a Raspberry Pi music player, with volume control. The issue is that when the volume is very low or very high, the sound effects (button press bleeps, etc.) are also too weak or too loud. The Raspberry Pi uses PulseAudio (system daemon), and this is its PulseAudio set-up:
# pactl list short
0 module-udev-detect
1 module-alsa-card device_id="0" name="platform-soc_sound" card_name="alsa_card.platform-soc_sound" namereg_fail=false tsched=yes fixed_latency_range=no ignore_dB=no deferred_volume=yes use_ucm=yes card_properties="module-udev-detect.discovered=1"
2 module-native-protocol-unix auth-cookie-enabled=0
3 module-stream-restore
4 module-device-restore
5 module-default-device-restore
6 module-bluetooth-policy
7 module-bluetooth-discover
8 module-bluez5-discover
9 module-rescue-streams
10 module-always-sink
11 module-switch-on-connect
0 alsa_output.platform-soc_sound.analog-stereo module-alsa-card.c s16le 2ch 44100Hz RUNNING
0 alsa_output.platform-soc_sound.analog-stereo.monitor module-alsa-card.c s16le 2ch 44100Hz IDLE
1 0 0 protocol-native.c s24-32le 2ch 44100Hz
0 protocol-native.c mpd
48 protocol-native.c pactl
0 startup float32le 2ch 44100Hz 3.279
1 beep_60 float32le 1ch 44100Hz 0.119
2 beep_70 float32le 1ch 44100Hz 0.119
3 beep_60_70 float32le 1ch 44100Hz 0.166
4 error float32le 2ch 44100Hz 0.702
5 bt float32le 1ch 44100Hz 0.264
0 alsa_card.platform-soc_sound module-alsa-card.c
I play the samples, using:
pactl play-sample startup
This command can take an additional parameter, namely the PulseAudio sink on which to play.
The solution seems to, somehow, create a sink, attach it to the Alsa card and use that to play the samples. I assume this sink would have its own volume control.