Apalis-imx8 SGTL5000 codec issues

Hi @mike-foundries,
I was doing a little bit more research on this and I figured out something interesting. The default pcm output device that’s configured on the apalis is a plug device. Plug devices can make automatic format conversions when needed in order to make sure that the format is supported by the underlying hardware.
If we just use the default device (without using the -Dsysdefault:CARD) options, your examples all work correctly and I can hear audio coming out of the headphone output.
Based on that I compiled your java application to check if for some reason it wasn’t possible to just let the default device (plug device instead of hw device) to be used.
I ran some tests with it and found out that indeed it is possible to play audio from the java app by doing something like:

 java ClipPlayerDemo "default" "/usr/share/sounds/alsa/Front_Left.wav"

I also did a quick change to the app in order to print out the selected mixer device, when found:

145                 if (mixers[i].getName().contains(args[0])) {                                          
146                     outputMixerInfo = mixers[i];                                                      
147                                                                                                       
148                     System.out.println("selected: " + outputMixerInfo.getName());                     
149                     break;                                                                            
150                 }

After doing that I could see that when I run the example with the same command line you did I get the following:

root@apalis-imx8:/tmp# java ClipPlayerDemo "hw:2,0" "/usr/share/sounds/alsa/Front_Left.wav"    
Usage: device:[hw:2,0] file:[/usr/share/sounds/alsa/Front_Left.wav]
=MI name=[apalisimx8qmsgt [default]], desc=[Direct Audio Device: apalis-imx8qm-sgtl5000, 59050000.sai-sgtl5000 sgtl5000-0, ]
=MI name=[imxspdif [plughw:0,0]], desc=[Direct Audio Device: imx-spdif, S/PDIF PCM snd-soc-dummy-dai-0, S/PDIF PCM snd-soc-dummy-dai-0]
=MI name=[apalisimx8qmsgt [plughw:1,0]], desc=[Direct Audio Device: apalis-imx8qm-sgtl5000, 59050000.sai-sgtl5000 sgtl5000-0, ]
=MI name=[imxaudiohdmitx [plughw:2,0]], desc=[Direct Audio Device: imx-audio-hdmi-tx, imx8 hdmi i2s-hifi-0, ]
selected: imxaudiohdmitx [plughw:2,0]
Playing /usr/share/sounds/alsa/Front_Left.wav ...
ERROR: CLIP: Audio line for playing back is unavailable.
javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 48000.0 Hz, 16 bit, mono, 2 bytes/frame, little-endian not supported.
	at com.sun.media.sound.DirectAudioDevice$DirectDL.implOpen(Unknown Source)
	at com.sun.media.sound.DirectAudioDevice$DirectClip.implOpen(Unknown Source)
	at com.sun.media.sound.AbstractDataLine.open(Unknown Source)
	at com.sun.media.sound.DirectAudioDevice$DirectClip.open(Unknown Source)
	at com.sun.media.sound.DirectAudioDevice$DirectClip.open(Unknown Source)
	at ClipPlayerDemo.playClip(ClipPlayerDemo.java:39)
	at ClipPlayerDemo.play(ClipPlayerDemo.java:111)
	at ClipPlayerDemo.main(ClipPlayerDemo.java:153)
ERROR: LINE: Audio line for playing back is unavailable.
javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 48000.0 Hz, 16 bit, mono, 2 bytes/frame, little-endian not supported.
	at com.sun.media.sound.DirectAudioDevice$DirectDL.implOpen(Unknown Source)
	at com.sun.media.sound.AbstractDataLine.open(Unknown Source)
	at com.sun.media.sound.AbstractDataLine.open(Unknown Source)
	at ClipPlayerDemo.playSourceDataLine(ClipPlayerDemo.java:77)
	at ClipPlayerDemo.play(ClipPlayerDemo.java:112)
	at ClipPlayerDemo.main(ClipPlayerDemo.java:153)

In this specific case the audio output that’s being selected is the hdmi one, instead of the headphone one. Calling it like this plays audio but still gives me an error:

root@apalis-imx8:/tmp# java ClipPlayerDemo "hw:1,0" "/usr/share/sounds/alsa/Front_Left.wav"
Usage: device:[hw:1,0] file:[/usr/share/sounds/alsa/Front_Left.wav]
=MI name=[apalisimx8qmsgt [default]], desc=[Direct Audio Device: apalis-imx8qm-sgtl5000, 59050000.sai-sgtl5000 sgtl5000-0, ]
=MI name=[imxspdif [plughw:0,0]], desc=[Direct Audio Device: imx-spdif, S/PDIF PCM snd-soc-dummy-dai-0, S/PDIF PCM snd-soc-dummy-dai-0]
=MI name=[apalisimx8qmsgt [plughw:1,0]], desc=[Direct Audio Device: apalis-imx8qm-sgtl5000, 59050000.sai-sgtl5000 sgtl5000-0, ]
selected: apalisimx8qmsgt [plughw:1,0]
Playing /usr/share/sounds/alsa/Front_Left.wav ...
ERROR: CLIP: Audio line for playing back is unavailable.
javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 48000.0 Hz, 16 bit, mono, 2 bytes/frame, little-endian not supported.
	at com.sun.media.sound.DirectAudioDevice$DirectDL.implOpen(Unknown Source)
	at com.sun.media.sound.DirectAudioDevice$DirectClip.implOpen(Unknown Source)
	at com.sun.media.sound.AbstractDataLine.open(Unknown Source)
	at com.sun.media.sound.DirectAudioDevice$DirectClip.open(Unknown Source)
	at com.sun.media.sound.DirectAudioDevice$DirectClip.open(Unknown Source)
	at ClipPlayerDemo.playClip(ClipPlayerDemo.java:39)
	at ClipPlayerDemo.play(ClipPlayerDemo.java:111)
	at ClipPlayerDemo.main(ClipPlayerDemo.java:153)
===C desc=[Master Gain with current value: 0.0 dB (range: -80.0 - 6.0206)]
===C desc=[Mute Control with current value: False]
SourceDataLine opened.
SourceDataLine started.
SourceDataLine stopped.
SourceDataLine closed.

So, with this I have a followup question:
Do you have a specific reason why you’re trying to use the hardware device directly, or would it suffice to use the “default” device (or a previously configured “plug” device, which could be done in /etc/asound.conf).

Please let me know what are your thoughts about this.

Regards,
Rafael Beims