Skip to content

Commit d66c4f0

Browse files
Bugfix/set audio volume (florian-asche#39)
* fix(audio): correct audio volume initialization and pipewire setup - Add pulseaudio-utils dependency package - Add wireplumber config directory creation - Rewrite audio setup scripts with proper sound card waiting - Replace broken PipeWire running check with hardware detection - Add safe control setter that skips missing audio controls - Set default PipeWire audio sink volume to 100% - Include new pipewire configs for volume and ACP disable - Apply fixes across all audio driver stage variants * fix(audio): remove duplicate install and add wireplumber configs Remove duplicated pipewire config installation line. Add installation of default volume and disabled ACP profile wireplumber configuration files for proper audio setup.
1 parent 758b8e2 commit d66c4f0

7 files changed

Lines changed: 190 additions & 113 deletions

File tree

01-stage-picompose/03-install-pipewire-audio/01-packages

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ wireplumber
33
pipewire-audio-client-libraries
44
libspa-0.2-bluetooth
55
pipewire-audio
6+
pulseaudio-utils
67
pipewire-pulse

01-stage-picompose/03-install-pipewire-audio/02-run.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
#!/bin/bash -e
22

3-
# Create the pipewire directory
3+
# Create directorys
44
mkdir -p "${ROOTFS_DIR}/etc/pipewire"
55
mkdir -p "${ROOTFS_DIR}/etc/pipewire.conf.d"
6+
mkdir -p "${ROOTFS_DIR}/etc/wireplumber/wireplumber.conf.d"
67

7-
# Copy pipewire config
8+
# Copy configs
89
install -v -m 644 files/linux-voice-assistant.conf "${ROOTFS_DIR}/etc/pipewire.conf.d/linux-voice-assistant.conf"
10+
install -v -m 644 files/50-volume.conf "${ROOTFS_DIR}/etc/wireplumber/wireplumber.conf.d/50-volume.conf"
11+
install -v -m 644 files/51-disable-acp.conf "${ROOTFS_DIR}/etc/wireplumber/wireplumber.conf.d/51-disable-acp.conf"
912

1013
on_chroot << EOF
1114
# Activate PipeWire-ALSA Bridge
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
monitor.alsa.rules = [
2+
{
3+
matches = [
4+
{
5+
node.name = "~alsa_output.*"
6+
}
7+
]
8+
actions = {
9+
update-props = {
10+
audio.volume = 1.0
11+
}
12+
}
13+
}
14+
]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
monitor.alsa.rules = [
2+
{
3+
matches = [
4+
{
5+
device.name = "~alsa_card.*"
6+
}
7+
]
8+
actions = {
9+
update-props = {
10+
api.alsa.use-acp = false
11+
}
12+
}
13+
}
14+
]
Lines changed: 52 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,66 @@
11
#!/bin/bash
2+
set -u
23

3-
check_pipewire() {
4-
local MAX_TRIES=30
5-
local SLEEP_SEC=1
6-
local COUNT=0
4+
wait_for_card_and_control() {
5+
local card="$1"
6+
local control="$2"
7+
local max_tries=30
8+
local sleep_sec=1
9+
local count=0
710

8-
while [ $COUNT -lt $MAX_TRIES ]; do
9-
COUNT=$((COUNT + 1))
11+
while [ "$count" -lt "$max_tries" ]; do
12+
count=$((count + 1))
1013

11-
# Check if XDG_RUNTIME_DIR is set
12-
if [ -z "$XDG_RUNTIME_DIR" ]; then
13-
echo "❌ XDG_RUNTIME_DIR is not set"
14-
return 1
14+
if amixer -c "$card" info >/dev/null 2>&1; then
15+
if amixer -c "$card" scontrols | grep -Fq "'$control'"; then
16+
echo "Card $card with control '$control' is ready ($count/$max_tries)"
17+
return 0
18+
fi
19+
echo "Card $card found, but control '$control' not ready yet ($count/$max_tries)"
20+
else
21+
echo "Card $card not ready yet ($count/$max_tries)"
1522
fi
1623

17-
# Check if PipeWire is running
18-
if pw-cli info 0 >/dev/null 2>&1; then
19-
echo "✅ PipeWire is running (checked $COUNT/$MAX_TRIES)"
20-
return 0
21-
fi
22-
23-
echo "⏳ PipeWire not running yet ($COUNT/$MAX_TRIES), retrying in $SLEEP_SEC s..."
24-
sleep $SLEEP_SEC
24+
sleep "$sleep_sec"
2525
done
2626

27-
echo "❌ PipeWire did not start after $MAX_TRIES seconds"
28-
return 2
27+
echo "Card $card with control '$control' did not become ready"
28+
return 1
29+
}
30+
31+
set_control_if_exists() {
32+
local card="$1"
33+
local control="$2"
34+
local value="$3"
35+
36+
if amixer -c "$card" scontrols | grep -Fq "'$control'"; then
37+
echo "Setting $control on $card to $value"
38+
amixer -c "$card" set "$control" "$value"
39+
return 0
40+
fi
41+
42+
echo "Control '$control' not found on $card, skipping"
43+
return 0
2944
}
3045

31-
# Run pipewire check
32-
check_pipewire
33-
34-
# Sleep 2 seconds to give the audio service some time to be fully loaded
35-
sleep 2
36-
37-
if amixer -c seeed2micvoicec info >/dev/null 2>&1; then
38-
echo "seeed2micvoicec found"
39-
amixer -c seeed2micvoicec set Headphone 100%
40-
amixer -c seeed2micvoicec set Speaker 100%
41-
amixer set Master 100%
42-
elif amixer -c Lite info >/dev/null 2>&1; then
43-
echo "Lite found"
44-
amixer -c Lite set Headphone 100%
45-
amixer -c Lite set Speaker 100%
46-
amixer set Master 100%
46+
if wait_for_card_and_control seeed2micvoicec Headphone; then
47+
CARD="seeed2micvoicec"
48+
echo "seeed2micvoicec found"
49+
elif wait_for_card_and_control Lite Headphone; then
50+
CARD="Lite"
51+
echo "Lite found"
4752
else
48-
exit 1
53+
echo "No supported sound card became ready"
54+
exit 1
4955
fi
5056

57+
set_control_if_exists "$CARD" Headphone 100%
58+
set_control_if_exists "$CARD" Speaker 100%
59+
set_control_if_exists "$CARD" Master 100%
60+
set_control_if_exists "$CARD" PCM 100%
61+
62+
# Set pipewire sink to 100%
63+
wpctl set-volume @DEFAULT_AUDIO_SINK@ 1.0
64+
65+
# Alsa save
5166
alsactl store
Lines changed: 52 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,66 @@
11
#!/bin/bash
2+
set -u
23

3-
check_pipewire() {
4-
local MAX_TRIES=30
5-
local SLEEP_SEC=1
6-
local COUNT=0
4+
wait_for_card_and_control() {
5+
local card="$1"
6+
local control="$2"
7+
local max_tries=30
8+
local sleep_sec=1
9+
local count=0
710

8-
while [ $COUNT -lt $MAX_TRIES ]; do
9-
COUNT=$((COUNT + 1))
11+
while [ "$count" -lt "$max_tries" ]; do
12+
count=$((count + 1))
1013

11-
# Check if XDG_RUNTIME_DIR is set
12-
if [ -z "$XDG_RUNTIME_DIR" ]; then
13-
echo "❌ XDG_RUNTIME_DIR is not set"
14-
return 1
14+
if amixer -c "$card" info >/dev/null 2>&1; then
15+
if amixer -c "$card" scontrols | grep -Fq "'$control'"; then
16+
echo "Card $card with control '$control' is ready ($count/$max_tries)"
17+
return 0
18+
fi
19+
echo "Card $card found, but control '$control' not ready yet ($count/$max_tries)"
20+
else
21+
echo "Card $card not ready yet ($count/$max_tries)"
1522
fi
1623

17-
# Check if PipeWire is running
18-
if pw-cli info 0 >/dev/null 2>&1; then
19-
echo "✅ PipeWire is running (checked $COUNT/$MAX_TRIES)"
20-
return 0
21-
fi
22-
23-
echo "⏳ PipeWire not running yet ($COUNT/$MAX_TRIES), retrying in $SLEEP_SEC s..."
24-
sleep $SLEEP_SEC
24+
sleep "$sleep_sec"
2525
done
2626

27-
echo "❌ PipeWire did not start after $MAX_TRIES seconds"
28-
return 2
27+
echo "Card $card with control '$control' did not become ready"
28+
return 1
29+
}
30+
31+
set_control_if_exists() {
32+
local card="$1"
33+
local control="$2"
34+
local value="$3"
35+
36+
if amixer -c "$card" scontrols | grep -Fq "'$control'"; then
37+
echo "Setting $control on $card to $value"
38+
amixer -c "$card" set "$control" "$value"
39+
return 0
40+
fi
41+
42+
echo "Control '$control' not found on $card, skipping"
43+
return 0
2944
}
3045

31-
# Run pipewire check
32-
check_pipewire
33-
34-
# Sleep 2 seconds to give the audio service some time to be fully loaded
35-
sleep 2
36-
37-
if amixer -c seeed2micvoicec info >/dev/null 2>&1; then
38-
echo "seeed2micvoicec found"
39-
amixer -c seeed2micvoicec set Headphone 100%
40-
amixer -c seeed2micvoicec set Speaker 100%
41-
amixer set Master 100%
42-
elif amixer -c Lite info >/dev/null 2>&1; then
43-
echo "Lite found"
44-
amixer -c Lite set Headphone 100%
45-
amixer -c Lite set Speaker 100%
46-
amixer set Master 100%
46+
if wait_for_card_and_control seeed2micvoicec Headphone; then
47+
CARD="seeed2micvoicec"
48+
echo "seeed2micvoicec found"
49+
elif wait_for_card_and_control Lite Headphone; then
50+
CARD="Lite"
51+
echo "Lite found"
4752
else
48-
exit 1
53+
echo "No supported sound card became ready"
54+
exit 1
4955
fi
5056

57+
set_control_if_exists "$CARD" Headphone 100%
58+
set_control_if_exists "$CARD" Speaker 100%
59+
set_control_if_exists "$CARD" Master 100%
60+
set_control_if_exists "$CARD" PCM 100%
61+
62+
# Set pipewire sink to 100%
63+
wpctl set-volume @DEFAULT_AUDIO_SINK@ 1.0
64+
65+
# Alsa save
5166
alsactl store
Lines changed: 52 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,66 @@
11
#!/bin/bash
2+
set -u
23

3-
check_pipewire() {
4-
local MAX_TRIES=30
5-
local SLEEP_SEC=1
6-
local COUNT=0
4+
wait_for_card_and_control() {
5+
local card="$1"
6+
local control="$2"
7+
local max_tries=30
8+
local sleep_sec=1
9+
local count=0
710

8-
while [ $COUNT -lt $MAX_TRIES ]; do
9-
COUNT=$((COUNT + 1))
11+
while [ "$count" -lt "$max_tries" ]; do
12+
count=$((count + 1))
1013

11-
# Check if XDG_RUNTIME_DIR is set
12-
if [ -z "$XDG_RUNTIME_DIR" ]; then
13-
echo "❌ XDG_RUNTIME_DIR is not set"
14-
return 1
14+
if amixer -c "$card" info >/dev/null 2>&1; then
15+
if amixer -c "$card" scontrols | grep -Fq "'$control'"; then
16+
echo "Card $card with control '$control' is ready ($count/$max_tries)"
17+
return 0
18+
fi
19+
echo "Card $card found, but control '$control' not ready yet ($count/$max_tries)"
20+
else
21+
echo "Card $card not ready yet ($count/$max_tries)"
1522
fi
1623

17-
# Check if PipeWire is running
18-
if pw-cli info 0 >/dev/null 2>&1; then
19-
echo "✅ PipeWire is running (checked $COUNT/$MAX_TRIES)"
20-
return 0
21-
fi
22-
23-
echo "⏳ PipeWire not running yet ($COUNT/$MAX_TRIES), retrying in $SLEEP_SEC s..."
24-
sleep $SLEEP_SEC
24+
sleep "$sleep_sec"
2525
done
2626

27-
echo "❌ PipeWire did not start after $MAX_TRIES seconds"
28-
return 2
27+
echo "Card $card with control '$control' did not become ready"
28+
return 1
29+
}
30+
31+
set_control_if_exists() {
32+
local card="$1"
33+
local control="$2"
34+
local value="$3"
35+
36+
if amixer -c "$card" scontrols | grep -Fq "'$control'"; then
37+
echo "Setting $control on $card to $value"
38+
amixer -c "$card" set "$control" "$value"
39+
return 0
40+
fi
41+
42+
echo "Control '$control' not found on $card, skipping"
43+
return 0
2944
}
3045

31-
# Run pipewire check
32-
check_pipewire
33-
34-
# Sleep 2 seconds to give the audio service some time to be fully loaded
35-
sleep 2
36-
37-
if amixer -c seeed2micvoicec info >/dev/null 2>&1; then
38-
echo "seeed2micvoicec found"
39-
amixer -c seeed2micvoicec set Headphone 100%
40-
amixer -c seeed2micvoicec set Speaker 100%
41-
amixer set Master 100%
42-
elif amixer -c Lite info >/dev/null 2>&1; then
43-
echo "Lite found"
44-
amixer -c Lite set Headphone 100%
45-
amixer -c Lite set Speaker 100%
46-
amixer set Master 100%
46+
if wait_for_card_and_control seeed2micvoicec Headphone; then
47+
CARD="seeed2micvoicec"
48+
echo "seeed2micvoicec found"
49+
elif wait_for_card_and_control Lite Headphone; then
50+
CARD="Lite"
51+
echo "Lite found"
4752
else
48-
exit 1
53+
echo "No supported sound card became ready"
54+
exit 1
4955
fi
5056

57+
set_control_if_exists "$CARD" Headphone 100%
58+
set_control_if_exists "$CARD" Speaker 100%
59+
set_control_if_exists "$CARD" Master 100%
60+
set_control_if_exists "$CARD" PCM 100%
61+
62+
# Set pipewire sink to 100%
63+
wpctl set-volume @DEFAULT_AUDIO_SINK@ 1.0
64+
65+
# Alsa save
5166
alsactl store

0 commit comments

Comments
 (0)