Qt5.3看到默认的Raspberry Pi all_output.0.analog-mono设备(3.5毫米耳机插孔)和5.3的QAudioOutput成功地将音频写入该设备,我可以用耳机听到音频。这一切都适用于默认的Raspbian,来自apt-get的PulseAudio 2.0,没有额外的配置。 PulseAudio作为会话进程运行,而不是在系统守护程序模式下运行。 Qt 5.4没有看到具有完全相同源代码和Raspbian的设备(除了使用Qt 5.4.0交叉编译而不是Qt 5.3.2),也无法向其写入数据。
它给了我这个错误(请注意我手动分配了两个sys默认值:CARD = ALSA和'默认'但它们都返回相同的' snd_pcm_hw_params'错误):
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看到了:
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
我试图在底部修改/etc/pulse/default.pa以强制输出设备:
load-module module-alsa-sink sink_name=alsa_output.0.analog-mono device=hw:0
set-default-sink alsa_output.0.analog-mono
以下是我的设置代码,它给出了错误:
// 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();
世界上发生了什么?为什么相同的配置适用于5.3.2而不是5.4.1。分配默认音频设备不起作用......我在这里可以做什么以及如何使其工作?谢谢!
答案 0 :(得分:1)
答案是在会话模式下运行(不是系统范围的PulseAudio守护程序)并编辑default.pa,如下所示:
## 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