Playing sound files through Qt with an IMX8

Hello,

I am running the oecore tdx-reference-multimedia-image on my Toradex Apalis-IMX8. I have developed a Qt5 application that I configured a service for to start on bootup. When using the simulator in Qt I am able to play a .“wav” file through the use of the QSoundEffect class, but for some reason when trying to do the same on my Toradex Apalis-IMX8 I am unable to get any sound. I have tested playing the “.wav” file manually through the terminal with “aplay” so I know that I am able to get sound out of the audio jack on the board. I have posted a snippet of my QUrl code for how I am looking for the “.wav” file below. I have tried pulling from the resources.qrc and from the hardcoded path.

audibleAlarm->setSource(QUrl::fromLocalFile(“:/Audio/StarWars60.wav”));
audibleAlarm->setSource(QUrl::fromLocalFile(“/home/root/sounds/StarWars60.wav”));

Let me know if you have any questions and thank you in advance for the help!

-Andy

Hi @axl3738,

Are you using BSP 5 for Apalis iMX8?
Another question from my side, have you tried the QSound Class from QT?
https://doc.qt.io/qt-5/qsound.html

In this case, as the “aplay” works, I would also recommend you post your question to the QT community since it appears this is a QT issue.

Best Regards,
Hiago.

Hey hfranco,

It has been awhile since I built the image in Yocto but I built the “5.7.0-devel-20220807183747+build.0 (dunfell)” version which I believe uses BSP 5? I have also not tried the QSound Class yet but I can give that a go and I can post this question to the QT community also.

Thanks,
Andy

Hi @axl3738,

Thanks for the information. Yes, 5.7.0 is BSP 5.

Ok, let me know if that works for you.

Best Regards,
Hiago.

Hey hfranco,

I switched to a QMediaPlaylist and QMediaPlayer and with some fidgeting it seems to work on the IMX8. I am now running into the same issue, now using the QMediaPlaylist and QMediaPlayer with an older TK1. This looks to use the old Angstrom Distribution v2017.12 and was built in the same Yocto environment a long time ago. Would you have any idea or leads to how to debug it for the TK1.

Thanks,
Andy

Hi @axl3738,

Can you please share which version of BSP you are using? Is it BSP 2.8 for Apalis TK1?

There is BSP 5 also available for TK1, which is our latest BSP for the TK1. It uses the kernel mainline instead of the downstream kernel that comes from Nvidia.

Best Regards,
Hiago.

Hey hfranco,
I believe that the BSP version is 2.8 for the TK1. For me to run BSP 5 for the TK1, I would need to build this image again through yocto I believe which I currently do not have the time to. Would the BSP 2.8 be the cause for this issue with audio output?

Thanks,
Andy

Hi @axl3738,

Not sure yet, but it shouldn’t be. I will try to reproduce the issue on my side and get back to you as soon as I have something.

Best Regards,
Hiago.

Appreciate it and thanks a lot.

Hi @axl3738,

I’ve installed BSP 2.8 with LXDE using Toradex Easy Installer.

root@apalis-tk1:~# uname -a
Linux apalis-tk1 3.10.40-2.8.7+g063d16eceb57 #1 SMP PREEMPT Wed Jun 10 16:02:37 UTC 2020 armv7l GNU/Linux

Next, I wanted to make sure that the audio was playing fine, without using QT. So I ran the following commands:

root@apalis-tk1:~# cat /proc/asound/card
cat: can't open '/proc/asound/card': No such file or directory
root@apalis-tk1:~# cat /proc/asound/cards
 0 [SGTL5000       ]: Toradex_Apalis_ - Toradex Apalis TK1 SGTL5000
                      Toradex Apalis TK1 SGTL5000
 1 [Tegra          ]: HDA-Intel - HDA NVIDIA Tegra
                      HDA NVIDIA Tegra at 0x70038000 irq 113
root@apalis-tk1:~# amixer -c 0 sset Headphone unmute
Simple mixer control 'Headphone',0
  Capabilities: pvolume pswitch pswitch-joined
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 127
  Mono:
  Front Left: Playback 113 [89%] [5.00dB] [on]
  Front Right: Playback 113 [89%] [5.00dB] [on]
root@apalis-tk1:~# speaker-test --device hw:0,0 --rate 48000 --channels 0 --format S16_LE --test wav

speaker-test 1.1.4

Playback device is hw:0,0
Stream parameters are 48000Hz, S16_LE, 1 channels
WAV file(s)
Rate set to 48000Hz (requested 48000Hz)
Buffer size range from 64 to 16384
Period size range from 64 to 4096
Using max buffer size 16384
Periods = 4
was set period_size = 4096
was set buffer_size = 16384
 0 - Front Left
Time per period = 1.197849
 0 - Front Left
Time per period = 1.457851
 0 - Front Left
Time per period = 1.525081
 0 - Front Left

I’m using the Apalis Evaluation Board with a speaker connected to the green audio jack. Everything worked fine. Can you also test if your speaker is working?

If you’re using a different board, please make sure you have the correct device tree enabled.

Reference: Audio (Linux)

I’m not a QT expert, so I don’t know exactly how the QT libraries work for sound. In general, TK1 uses the Alsa library to play audio, so if QT also calls Alsa to play audio (which is basically what we’re doing with the speaker-test), it should work. Otherwise, if it still doesn’t work, I would recommend you ask for help from the AT community or instead of using the AT library, you could also call these alsa commands directly with your app. It may also work as well.

Let me know if the audio works for you.

Best Regards,
Hiago.