Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Getting sound from jack with ALSA instead of PulseAudio



  • Goodmorning,
    I'm using a Raspberrypi0-wifi connect to an audio board via I2S. The QT version is 5.12.0. I installed all the stuff that I can find on the net concerning this topic but still I cannot make the app to play the sound through the analog output. Here some information:

    • If I try to play a song with mpg123 program the sound comes correctly from the jack output.

    • Trying to print out the available audio devices with the following code:

    QList<QAudioDeviceInfo> devices = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput);
        foreach (QAudioDeviceInfo i, devices){
            qDebug()<<i.deviceName();
        }
    

    I get the following:
    "default"
    "sysdefault:CARD=sndrpihifiberry"

    • With the command aplay -l, I get the following:
      **** List of PLAYBACK Hardware Devices ****
      card 0: sndrpihifiberry [snd_rpi_hifiberry_dac], device 0: HifiBerry DAC HiFi p]
      Subdevices: 1/1
      Subdevice #0: subdevice #0

    • My code consists in a MediaPlayer with playlist made in QML:

        MediaPlayer {
            id: playMusic
            autoLoad: true
            autoPlay: true
            playlist: Playlist { id:playerList; }
            Component.onCompleted: volumeMeter.initVolume(playMusic);
        }
    
    • For creating the image and the cross-compiling toolchain I used Yocto with b2qt.
      Adding the following lines in local.conf:
    PACKAGECONFIG_append_pn-qtmultimedia = " gstreamer alsa"
    PACKAGECONFIG_append_pn-gstreamer1.0-plugins-ugly = "a52dec lame mad mpeg2dec x264" 
    PACKAGECONFIG_remove_pn-qtmultimedia = " pulseaudio"
    DISTRO_FEATURES_remove = " pulseaudio" 
    
    IMAGE_INSTALL += "alsa-lib alsa-plugins alsa-utils alsa-state alsa-tools alsa-oss"
    IMAGE_INSTALL += " \
    	gst-meta-video \
    	gst-plugins-base-app \
    	gst-plugins-base \
    	gst-plugins-good \
    	gst-plugins-good-rtsp \
    	gst-plugins-good-udp \
    	gst-plugins-good-rtpmanager \
    	gst-plugins-good-rtp \
    	gst-plugins-good-video4linux2 \
    	gstreamer1.0-plugins-good \
    	gstreamer1.0-plugins-base \
    	gstreamer1.0-plugins-ugly \
    	gstreamer1.0-libav \
    	gst-fluendo-mp3 \ 
    "
    

    I wonder if there are some libraries/plugins that can let qt to work with the analog audio. At the moment I have found installed libqtaudio_alsa.so and libasound.so,
    May they be useful? And if yes, how should I use them?

    Thank you.

    Regards,
    Davide Brunelli



  • Hello @MangoCat ,
    thank you for your message. Actually it's different installing directly to the Raspberry than using Yocto, but for sure it can be useful.
    At the end I sorted out, installing the following including pulseaudio (maybe several of all are unnecessary but I installed whatever I found on the net):

    PACKAGECONFIG_append_pn-qtmultimedia = " gstreamer alsa"
    PACKAGECONFIG_append_pn-gstreamer1.0-plugins-ugly = "a52dec lame mpeg2dec x264" 
    #PACKAGECONFIG_remove_pn-qtmultimedia = " pulseaudio"
    #DISTRO_FEATURES_remove = " pulseaudio" 
    
    IMAGE_INSTALL += "alsa-lib alsa-plugins alsa-utils-speakertest alsa-utils alsa-state alsa-tools"
    
    IMAGE_INSTALL += "\
    	gstreamer1.0 \ 
            gstreamer1.0-plugins-base-meta \
    	gstreamer1.0-plugins-good-meta \
            gstreamer1.0-plugins-bad-meta \
            gstreamer1.0-plugins-bad \
            gstreamer1.0-plugins-base-playback \
            gstreamer1.0-plugins-ugly-meta \	
    	gst-meta-video \
    	gst-plugins-base-app \
    	gst-plugins-base \
    	gst-plugins-good \
    	gst-plugins-good-rtsp \
    	gst-plugins-good-udp \
    	gst-plugins-good-rtpmanager \
    	gst-plugins-good-rtp \
    	gst-plugins-good-video4linux2 \
    	gstreamer1.0-plugins-good \
    	gstreamer1.0-plugins-base \
    	gstreamer1.0-plugins-ugly \
    	gstreamer1.0-libav \
    	gst-fluendo-mp3 \ 
    "
    
    DISTRO_FEATURES_append = " pulseaudio dbus"
    IMAGE_INSTALL_append = " pulseaudio pulseaudio-server \
    qtmultimedia qtmultimedia-plugins qtmultimedia-qmlplugins dbus pulseaudio-misc"
    PACKAGECONFIG_append_pn-qtmultimedia = " pulseaudio"
    #PACKAGECONFIG_pn-pulseaudio_append
    
    

    Besides pulseaudio is called together with the main application, with the following bash script:

    #!/bin/bash
    
    sleep 10
    
    # Maybe we can do a separate service
    # forum.qt.io/topic/108039/unable-to-play-audio-on-embedded-device-using-pulseaudio-audi$
    if test -z "$DBUS_SESSION_BUS_ADDRESS" ; then
         echo "Starting dbus"
         export $(dbus-launch)
    fi
    
    /usr/bin/pulseaudio -D --start
    
    #/usr/bin/psplash
    
    #Main application
    /usr/bin/gallery-mobile
    
    

    Hope it helps whoever is facing the same issue as mine.

    Regards,
    Davidino



  • I had your same problem, no output from QMediaPlayer on a RaspiZeroW with a Hifiberry-MiniAmp (same driver as their DAC) - solution at bottom.

    This code works on my desktop system in both modes, but in the Rpi only in the mplayer mode:

    void PlayController::play( QFileInfo fi )
    { if ( soundPlayer == 2 )
        { QMediaPlayer *player = new QMediaPlayer;
          player->setMedia(QUrl::fromLocalFile( fi.absoluteFilePath() ));
          // player->setVolume(50);
          player->play();
        }
       else
        QProcess::execute( "/usr/bin/mplayer", QStringList( fi.absoluteFilePath() ) );
    }
    

    I have installed:

    sudo apt install qt5-default cmake qtcreator qtmultimedia5-dev libqt5multimedia5-plugins mpg321 lame pulseaudio 
    

    adding

    sudo apt install gstreamer1.0-tools 
    

    did not help... of course, my aplay -l is the same as yours:

    pi@blueberry:~ $ aplay -l
    **** List of PLAYBACK Hardware Devices ****
    card 0: sndrpihifiberry [snd_rpi_hifiberry_dac], device 0: HifiBerry DAC HiFi pcm5102a-hifi-0 [HifiBerry DAC HiFi pcm5102a-hifi-0]
      Subdevices: 1/1
      Subdevice #0: subdevice #0
    

    My Pi is setup with fresh Raspbian, which comes with Qt 5.11

    Solved my issue with a:

    sudo apt install gstreamer1.0-pulseaudio
    

    hope this helps...



  • Hello @MangoCat ,
    thank you for your message. Actually it's different installing directly to the Raspberry than using Yocto, but for sure it can be useful.
    At the end I sorted out, installing the following including pulseaudio (maybe several of all are unnecessary but I installed whatever I found on the net):

    PACKAGECONFIG_append_pn-qtmultimedia = " gstreamer alsa"
    PACKAGECONFIG_append_pn-gstreamer1.0-plugins-ugly = "a52dec lame mpeg2dec x264" 
    #PACKAGECONFIG_remove_pn-qtmultimedia = " pulseaudio"
    #DISTRO_FEATURES_remove = " pulseaudio" 
    
    IMAGE_INSTALL += "alsa-lib alsa-plugins alsa-utils-speakertest alsa-utils alsa-state alsa-tools"
    
    IMAGE_INSTALL += "\
    	gstreamer1.0 \ 
            gstreamer1.0-plugins-base-meta \
    	gstreamer1.0-plugins-good-meta \
            gstreamer1.0-plugins-bad-meta \
            gstreamer1.0-plugins-bad \
            gstreamer1.0-plugins-base-playback \
            gstreamer1.0-plugins-ugly-meta \	
    	gst-meta-video \
    	gst-plugins-base-app \
    	gst-plugins-base \
    	gst-plugins-good \
    	gst-plugins-good-rtsp \
    	gst-plugins-good-udp \
    	gst-plugins-good-rtpmanager \
    	gst-plugins-good-rtp \
    	gst-plugins-good-video4linux2 \
    	gstreamer1.0-plugins-good \
    	gstreamer1.0-plugins-base \
    	gstreamer1.0-plugins-ugly \
    	gstreamer1.0-libav \
    	gst-fluendo-mp3 \ 
    "
    
    DISTRO_FEATURES_append = " pulseaudio dbus"
    IMAGE_INSTALL_append = " pulseaudio pulseaudio-server \
    qtmultimedia qtmultimedia-plugins qtmultimedia-qmlplugins dbus pulseaudio-misc"
    PACKAGECONFIG_append_pn-qtmultimedia = " pulseaudio"
    #PACKAGECONFIG_pn-pulseaudio_append
    
    

    Besides pulseaudio is called together with the main application, with the following bash script:

    #!/bin/bash
    
    sleep 10
    
    # Maybe we can do a separate service
    # forum.qt.io/topic/108039/unable-to-play-audio-on-embedded-device-using-pulseaudio-audi$
    if test -z "$DBUS_SESSION_BUS_ADDRESS" ; then
         echo "Starting dbus"
         export $(dbus-launch)
    fi
    
    /usr/bin/pulseaudio -D --start
    
    #/usr/bin/psplash
    
    #Main application
    /usr/bin/gallery-mobile
    
    

    Hope it helps whoever is facing the same issue as mine.

    Regards,
    Davidino


Log in to reply