1
votes

Qt5.3 sees the default Raspberry Pi also_output.0.analog-mono device ( 3.5 mm headphone jack ) and QAudioOutput from 5.3 successfully writes audio to that device and I can hear the audio with my headphones. This all works with default Raspbian, with PulseAudio 2.0 from apt-get, and no extra configuration. PulseAudio is run as session process and not in the System Daemon mode. Qt 5.4 does not see the device with the exact same source code and Raspbian ( except cross-compiled with Qt 5.4.0 and not Qt 5.3.2 ) and also cannot write data to it.

It gives me this error ( Please note that I've manually assigned both sys default:CARD=ALSA and 'default' but they both return the same 'snd_pcm_hw_params' error ):

Output Device name:  "sysdefault:CARD=ALSA"
Output Device name:  "default"
Default device is "default"
Output device is:  "default"
"QAudioOutput: snd_pcm_hw_params: err = -12"

Pactl sees it:

pactl list sinks
Sink #0
    State: SUSPENDED
    Name: alsa_output.0.analog-mono
    Description: bcm2835 ALSA Analog Mono
    Driver: module-alsa-card.c
    Sample Specification: u8 1ch 8000Hz

I've tried to modify /etc/pulse/default.pa with this at the bottom to force the output device:

load-module module-alsa-sink sink_name=alsa_output.0.analog-mono device=hw:0
set-default-sink alsa_output.0.analog-mono

Here is my setup code that gives the error:

        // Coordinator receives Audio data
        m_Format.setSampleRate(8000);
        m_Format.setChannelCount(1);
        m_Format.setSampleSize(8);
        m_Format.setCodec("audio/pcm");
        m_Format.setByteOrder(QAudioFormat::BigEndian);
        m_Format.setSampleType(QAudioFormat::UnSignedInt);

        QAudioDeviceInfo infoOut(QAudioDeviceInfo::defaultOutputDevice());

        foreach (const QAudioDeviceInfo &deviceInfo,  QAudioDeviceInfo::availableDevices(QAudio::AudioOutput)) {
            qDebug() << "Output Device name: " << deviceInfo.deviceName();
        }

        qDebug() << "Default device is" << infoOut.deviceName();

        if (!infoOut.isFormatSupported(m_Format))
        {
            qDebug()<< "Default format not supported - trying to use nearest";
            m_Format = infoOut.nearestFormat(m_Format);
        }

        qDebug() << "Output device is: " << infoOut.deviceName();
        m_AudioOutput = new QAudioOutput(infoOut, m_Format, this);

        // This data accumulates and dumps data to output
        m_DataForOutput.clear();

        // Now Start playing
        // m_Output gets written to to send data to speakers
        m_Output = m_AudioOutput->start();

What in the world is going on? How come the same configuration works with 5.3.2 and not 5.4.1. Assigning the default audio device doesn't work... What can I do here and how can I make it work? Thanks!

1

1 Answers

1
votes

The answer was to run in session mode ( not a system-wide PulseAudio daemon ) and edit default.pa to look like this:

## Create the default output device
#load-module module-udev-detect tsched=0

load-module module-alsa-card device_id=0

#load-module module-alsa-card device_id=0 tsched=0 fragments=10 fragment_size=640 tsched_buffer_size=4194384 tsched_buffer_watermark=262144

#load-module module-alsa-card device_id=0 tsched=0 fragments=6 fragment_size=16 tsched_buffer_size=4194384 tsched_buffer_watermark=262144

load-module module-suspend-on-idle timeout=86400

### Load several protocols
load-module module-native-protocol-unix

### Make sure we always have a sink around, even if it is a null sink.
#load-module module-always-sink