@Ludwig I did some further testing and I believe I know what the issue is. It seems what card number the audio codec is, is not consistent across boots. On one boot I observed the card number for the proper audio codec is card 2:
torizon@apalis-imx8-06738453:~$ cat /proc/asound/cards
0 [imxspdif ]: imx-spdif - imx-spdif
imx-spdif
1 [imxaudiohdmitx ]: imx-audio-hdmi- - imx-audio-hdmi-tx
imx-audio-hdmi-tx
2 [apalisimx8qmsgt]: simple-card - apalis-imx8qm-sgtl5000
apalis-imx8qm-sgtl5000
Which is what I based my code changes on. However, on another boot the same audio codec is now card number 0:
torizon@apalis-imx8-06738453:~$ cat /proc/asound/cards
0 [apalisimx8qmsgt]: simple-card - apalis-imx8qm-sgtl5000
apalis-imx8qm-sgtl5000
1 [imxaudiohdmitx ]: imx-audio-hdmi- - imx-audio-hdmi-tx
imx-audio-hdmi-tx
2 [imxspdif ]: imx-spdif - imx-spdif
imx-spdif
In the case where the audio codec enumerated itself as card 0, I got the same error as you since my code was expecting it as card 2.
The proper way to handle this would be to use the audio codec name instead of the card number as this should be consistent across boots. To do this let’s use aplay
like so:
root@9ddc62c7d762:/# aplay -L
null
Discard all samples (playback) or generate zero samples (capture)
hw:CARD=apalisimx8qmsgt,DEV=0
apalis-imx8qm-sgtl5000, 59050000.sai-sgtl5000 sgtl5000-0
Direct hardware device without any conversions
plughw:CARD=apalisimx8qmsgt,DEV=0
apalis-imx8qm-sgtl5000, 59050000.sai-sgtl5000 sgtl5000-0
Hardware device with all software conversions
default:CARD=apalisimx8qmsgt
apalis-imx8qm-sgtl5000, 59050000.sai-sgtl5000 sgtl5000-0
Default Audio Device
sysdefault:CARD=apalisimx8qmsgt
apalis-imx8qm-sgtl5000, 59050000.sai-sgtl5000 sgtl5000-0
Default Audio Device
dmix:CARD=apalisimx8qmsgt,DEV=0
apalis-imx8qm-sgtl5000, 59050000.sai-sgtl5000 sgtl5000-0
Direct sample mixing device
hw:CARD=imxaudiohdmitx,DEV=0
imx-audio-hdmi-tx, i.MX HDMI i2s-hifi-0
Direct hardware device without any conversions
plughw:CARD=imxaudiohdmitx,DEV=0
imx-audio-hdmi-tx, i.MX HDMI i2s-hifi-0
Hardware device with all software conversions
default:CARD=imxaudiohdmitx
imx-audio-hdmi-tx, i.MX HDMI i2s-hifi-0
Default Audio Device
sysdefault:CARD=imxaudiohdmitx
imx-audio-hdmi-tx, i.MX HDMI i2s-hifi-0
Default Audio Device
dmix:CARD=imxaudiohdmitx,DEV=0
imx-audio-hdmi-tx, i.MX HDMI i2s-hifi-0
Direct sample mixing device
hw:CARD=imxspdif,DEV=0
imx-spdif, S/PDIF PCM snd-soc-dummy-dai-0
Direct hardware device without any conversions
plughw:CARD=imxspdif,DEV=0
imx-spdif, S/PDIF PCM snd-soc-dummy-dai-0
Hardware device with all software conversions
default:CARD=imxspdif
imx-spdif, S/PDIF PCM snd-soc-dummy-dai-0
Default Audio Device
sysdefault:CARD=imxspdif
imx-spdif, S/PDIF PCM snd-soc-dummy-dai-0
Default Audio Device
dmix:CARD=imxspdif,DEV=0
imx-spdif, S/PDIF PCM snd-soc-dummy-dai-0
Direct sample mixing device
Here we see the name for the device is default:CARD=apalisimx8qmsgt
. Use this name in the amixer
command and in the SoundCardPortName[]
variable instead of the card number as we were before. After doing this change audio plays for me no matter which card number the audio codec enumerates with.
So now the code changes should be something like this:
static const char SoundCardPortName[] = "default:CARD=apalisimx8qmsgt";
...
system("amixer -D default:CARD=apalisimx8qmsgt set Headphone unmuted 50%");
Best Regards,
Jeremias