Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSoundEffect with QAudioDeviceInfo not working

QSoundEffect with QAudioDeviceInfo not working

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 745 Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • JarggohJ Offline
    JarggohJ Offline
    Jarggoh
    wrote on last edited by Jarggoh
    #1

    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.html

    How 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..

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mchinand
      wrote on last edited by
      #2

      @Jarggoh said in QSoundEffect with QAudioDeviceInfo not working:

      if (deviceInfo.deviceName() == "hdmi:CARD=PCH,DEV=0")

      Is this if clause definitely satisfied for at least one device so that this->myDevice gets assigned?

      1 Reply Last reply
      0
      • JarggohJ Offline
        JarggohJ Offline
        Jarggoh
        wrote on last edited by
        #3

        Yes, I checked it with debugger and also checked the supported encoding and the wav matches, but still get pulseaudio error..

        1 Reply Last reply
        0
        • JarggohJ Offline
          JarggohJ Offline
          Jarggoh
          wrote on last edited by
          #4

          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 like

          void 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.

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            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.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved