Problems getting QAuidioOutput working on Pi



  • Hi, first I apologize for the massive post..., I'm dividing it in 2 parts, I hope I don't break rules with that... I just think it's best to be as detailed as possible.

    I intend to start developing on Qt 5 on a RPi, I was interested in producing audio at a low level programatically, so for my first experiments I was trying out QAudioOutput, as documented on "QAudioOutput reference":http://qt-project.org/doc/qt-5.0/qtmultimedia/qaudiooutput.html but I was not able to get any audio out. So I went out to google and tried to understand my options or possible mistakes. I compiled QT for the Pi on a Ubuntu 12.04 virtualbox machine.

    After following a number of blog posts/tutorials like ("this":http://jeffskinnerbox.wordpress.com/2012/11/15/getting-audio-out-working-on-the-raspberry-pi/ and "this":http://thebugfreeblog.blogspot.com/2013/03/bring-up-qt-501-on-raspberry-pi-with.html ) I'm still stuck.

    Some note worthy things I've tried:

    • I first noticed I had not included the multimedia module so I compiled it with the following configuration:
      @./configure -opengl es2 -device linux-rasp-pi-g++ -device-option CROSS_COMPILE=~/opt/gcc-4.7-linaro-rpi-gnueabihf/bin/arm-linux-gnueabihf- -sysroot /mnt/rasp-pi-rootfs -opensource -confirm-license -optimized-qmake -reduce-relocations -reduce-exports -release -make libs -prefix /usr/local/qt5pi -make tools -no-pch -nomake tests -nomake examples@
      But when running configure I was always getting

    @Alsa support ........... no@

    (I must hereby confide that I'm quite a noob in regards to qmake, make and all the compilation process, so I might just be doing something fundamentally wrong without knowing)

    Anyways to fix the alsa support I:

    • Tried changeing QT_SOURCE_HOME/qtbase/mkspecs/qconfig.pri adding alsa to the QT_CONFIG but it would just result in the same.

    @Alsa support ........... yes@

    • Then changed QT_SOURCE_HOME/qtbase/configure at line 869 from:

    @CFG_ALSA=auto@

    to

    @CFG_ALSA=yes@

    And this worked, producing something like:

    @Building on: linux-g++
    Building for: devices/linux-rasp-pi-g++
    Architecture: arm, features:
    Host architecture: unknown, features:
    Platform notes:

            - Also available for Linux: linux-kcc linux-icc linux-cxx
    

    Build .................. libs
    Configuration .......... cross_compile qpa largefile neon pcre minimal-config small-config medium-config large-config full-config evdev linuxfb c++11 accessibility egl eglfs opengl opengles2 shared qpa reduce_exports reduce_relocations clock-gettime clock-monotonic mremap getaddrinfo ipv6ifname getifaddrs inotify png freetype system-zlib nis iconv rpath alsa concurrent audio-backend v8 release
    Debug .................. no
    C++11 support .......... yes
    pkg-config ............. yes
    Qt D-Bus module ........ no
    Qt Concurrent code ..... yes
    Qt GUI module .......... yes
    Qt Widgets module ...... yes
    JavaScriptCore JIT ..... To be decided by JavaScriptCore
    QML debugging .......... yes
    PCH support ............ no
    iWMMXt support ......... no
    NEON support ........... yes
    IPv6 ifname support .... yes
    getaddrinfo support .... yes
    getifaddrs support ..... yes
    Accessibility .......... yes
    NIS support ............ yes
    CUPS support ........... no
    Iconv support .......... yes
    Glib support ........... no
    GStreamer support ...... no
    PulseAudio support ..... no
    Large File support ..... yes
    GIF support ............ plugin
    JPEG support ........... plugin (qt)
    PNG support ............ yes (qt)
    zlib support ........... system
    Session management ..... auto
    libudev support ........ no
    Use system proxies ..... no
    OpenGL support ......... yes (OpenGL ES 2.x)
    OpenVG support ......... no
    XShape support ......... auto
    XVideo support ......... auto
    XSync support .......... auto
    Xinerama support ....... runtime
    Xcursor support ........ runtime
    Xfixes support ......... runtime
    Xrandr support ......... runtime
    Xi support ............. runtime
    Xi2 support ............ auto
    MIT-SHM support ........ auto
    FontConfig support ..... no
    XKB Support ............ auto
    GTK theme support ...... no
    SQLite support ......... plugin (qt)
    OpenSSL support ........ no
    Alsa support ........... yes
    libICU support ......... no
    PCRE support ........... qt
    Xcb support ............ no
    Xrender support ........ no
    EGLFS support .......... yes
    DirectFB support ....... no
    LinuxFB support ........ yes
    KMS support ............ no@

    ...continued in the subsequent reply...



  • ... continuation

    I also made sure I had the libraries mentioned at the two blogposts in both in Ubuntu and on the Pi. Now having this I'm able to run a QTGuiApplication that uses QAudioOutput, but I can't produce any sound. This is the snippet of the code I'm using, note I'm using a RAW file as the source.

    @void AudioW::audioOut () {

    sourceFile.setFileName(":/test.raw");
    sourceFile.open(QIODevice::ReadOnly);
    
    QAudioFormat format;
    // Set up the format, eg.
    format.setSampleRate(44100);
    format.setChannelCount(1);
    format.setSampleSize(16);
    format.setCodec("audio/pcm");
    format.setByteOrder(QAudioFormat::LittleEndian);
    format.setSampleType(QAudioFormat::UnSignedInt);
    
    QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
    if (!info.isFormatSupported(format)) {
        qWarning() << "Default format not supported - trying to use nearest";
        format = info.nearestFormat(format);
    }
    foreach (const QAudioDeviceInfo &deviceInfo, QAudioDeviceInfo::availableDevices(QAudio::AudioOutput))
        qDebug() << "Device name: " << deviceInfo.deviceName();
    
    audio = new QAudioOutput(info, format, this);
    connect(audio, SIGNAL(notify()), SLOT(notified()));
    connect(audio, SIGNAL(stateChanged(QAudio::State)), this, SLOT(stateChanged(QAudio::State)));
    audio->start(&sourceFile);
    return;
    

    }@

    The foreach there was intended to figure out what devices are being picked up, because I get a

    @using null output device, none available@

    So looking into the source I've come to believe the factory is the root, "qaudiodevicefactory.cpp":http://qt.gitorious.org/qt/qt/blobs/fb50411e4c0c132631f8237933fbb0972fa4c9aa/src/multimedia/audio/qaudiodevicefactory.cpp

    and looking into defaultOutputDevice() method, I guess "defined(HAS_ALSA)" is false, but I have no clue where or how I would be able to make it true.

    Now I know for a fact that ALSA libs are there, as the following snippet does produce sound:

    @void AudioW::audioOut () {

    sourceFile.setFileName(":/test.raw");
    
    qWarning() << "Executing the process";
    QStringList arguments;
    arguments << "-c" << "1" << "-f" << "cd";
    QProcess *process = new QProcess(this);
    process->start("aplay", arguments);
    process->write(sourceFile.readAll());
    return;
    

    }@

    Note: lsmod does seem to be showing bcm2835

    I hope someone can provide some insight in what I might be doing wrong ;), perhaps it's all the way back to me compiling it wrong... Thanks in advance.

    Wolf



  • -Could it be QtMultimedia needs gstreamer or pulseaudio for audioplayback?-

    Scratch that... Alsa should work.

    qtmultimedia/src/multimedia/audio/audio.pri:
    @unix:!mac {
    config_pulseaudio {
    DEFINES += QT_NO_AUDIO_BACKEND
    CONFIG += link_pkgconfig
    PKGCONFIG += libpulse

        DEFINES += QT_MULTIMEDIA_PULSEAUDIO
        PRIVATE_HEADERS += audio/qsoundeffect_pulse_p.h
        SOURCES += audio/qsoundeffect_pulse_p.cpp
        !maemo*:DEFINES += QTM_PULSEAUDIO_DEFAULTBUFFER
    } else {
        DEFINES += QT_MULTIMEDIA_QAUDIO
        PRIVATE_HEADERS += audio/qsoundeffect_qaudio_p.h
        SOURCES += audio/qsoundeffect_qaudio_p.cpp
    
        config_alsa {
            DEFINES += HAS_ALSA
            PRIVATE_HEADERS += audio/qaudiooutput_alsa_p.h audio/qaudioinput_alsa_p.h audio/qaudiodeviceinfo_alsa_p.h
            SOURCES += audio/qaudiodeviceinfo_alsa_p.cpp \
                audio/qaudiooutput_alsa_p.cpp \
                audio/qaudioinput_alsa_p.cpp
            LIBS_PRIVATE += -lasound
        }
    }
    

    } else {
    DEFINES += QT_MULTIMEDIA_QAUDIO
    PRIVATE_HEADERS += audio/qsoundeffect_qaudio_p.h
    SOURCES += audio/qsoundeffect_qaudio_p.cpp
    }
    @



  • @Tomma:

    Hi Tomma, thanks for the reply, indeed it would seem that it should be working, however I wanted to point a couple things out.

    My rationale about HAS_ALSA is only from looking at the source code, I reckon I could be making some wrong assumptions, do you see anything I might be missing in that rationale?

    As for the change I made to the configure file, it kind of feels to me like I forced it (I'm not very familiar with the make process and the use configure). Now, I forced it because changing the *.pri file wasn't working, it would always yeild a 'no', do you think I might have introduced the problem when forcing the value to yes?

    Should I maybe force other values?

    Another thing I missed to mention is, I compiled this separately after finding the problems, do you think recompiling the whole thing again has a chance in fixing it?

    I might have run the compilation more than once, repeating the "make -j" and "make install" steps often more than once, perhaps when runnng it multiple times it can leave things dirty? Is there a way to 'clean' before rerunning these commands?

    I'm sorry for the newbie questions, I will be trying to get more familiar with these processes in the short term, but for now I haven;t been able to invest much more effort in it.

    @All: Has anyone out there been able to produce sound on the raspberry pi 3.5 audio output using QAudioOutput?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.