QSoundEffect with QAudioDeviceInfo not working
-
Qt-5.15 QSoundEffect has a constructor (const QAudioDeviceInfo &audioDevice, QObject *parent = nullptr) so one can play from different pulseaudio outputs (e.g. "default", or "hdmi:CARD=PCH,DEV=0"). However, I can not seem to get this to work with any device selected. Sound only works without constructor parameters like
// private QSoundEffect* snd; this->snd = new QSoundEffect(); // This works always regardless of current pulseaudio out (Bluetooth/Speakers) // preselected QAudioDeviceInfo myDevice; this->snd = new QSoundEffect(myDevice); // This does not work with any output this->snd->setSource(QUrl("qrc:/sounds/beep.wav")); this->snd->setVolume(1.0f); this->snd->play();
With any preselected device I found from
for (auto& deviceInfo : QAudioDeviceInfo::availableDevices(QAudio::AudioOutput)) { if (deviceInfo.deviceName() == "hdmi:CARD=PCH,DEV=0") { this->myDevice = QAudioDeviceInfo(deviceInfo);
I can see and test my outputs with this example, which does not use QSoundEffect.
https://doc.qt.io/qt-5/qtmultimedia-multimedia-audiooutput-example.htmlHow can one use the QSoundEffect(myDevice)? Can I save the selected QAudioDeviceInfo into my class property and give it to QSoundEffect()? I have not found any uses of it like that..
-
Can not get QSoundEffect::QSoundEffect(const QAudioDeviceInfo &audioDevice, QObject *parent = nullptr) to work, so I went with QAudioOutput.
Class with QAudioOutput run forewer in a thread, with play() method, works pretty much like QSoundEffect. Just play the same file from beginning likevoid MyPlayer::play() { inputFile->reset(); m_audio->start(inputFile); }
QAudioOutput(const QAudioDeviceInfo &audioDevice, const QAudioFormat &format = QAudioFormat(), QObject *parent = nullptr)
Now, why does it say in docs that QSoundEffect can take QAudioDeviceInfo as a parameter, I dunno. What is the difference of QAudioOutput() input parameter and QSoundEffect() input parameter, since only QSoundEffect works and plays the sound from where ever you choose, and QSoundEffect does not!
Is there some undocumented thing u haveto do to QSoundEffect to somehow activate the the QAudioDeviceInfo you choose, or somthn... Pavucontrol does not even show the application using any sound, if QSoundEffect had a device parameter. -
Hi,
From a quick look at the backend code, it seems the difference is in the case you give a QAudioDeviceInfo, the sink name is passed to PulseAudio.
Something to dig into.