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. QAudioOutput Unable to setVolume
Forum Updated to NodeBB v4.3 + New Features

QAudioOutput Unable to setVolume

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 1.9k Views 2 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.
  • Banshee10000B Offline
    Banshee10000B Offline
    Banshee10000
    wrote on last edited by Banshee10000
    #1

    Currently I'm struggling to set the volume for a QAudioOutput object...
    In the documentation its noted that ::setVolume takes a qreal

    I have a horizontal slider with value 0 to 100.
    Then I convert the incoming horizontal Slider value like this:

    output is a QAudioOutput

    void SoundSystem::SetVolume(int volume)
    {
        if(output->state() ==  QAudio::ActiveState)
        {
            //qreal linearVolume = QAudio::convertVolume(volume / qreal(100.0),
                                                            //QAudio::LogarithmicVolumeScale,
                                                            //QAudio::LinearVolumeScale);
            //output->setVolume(qRound(linearVolume * 100));
    
            qreal newVol =  (qreal)volume / 100;
            qDebug() << "Volume  Value: "  << newVol;
            output->setVolume(newVol);
            qDebug() << "Check Value: "  << output->volume();
        }
    }
    

    The debugging output:

    Exec::playSound
    handleAudioStateChanged ActiveState
    Volume Value: 0.99
    Check Value: 0.99
    Volume Value: 0.98
    Check Value: 0.98
    Volume Value: 0.97
    Check Value: 0.97
    Volume Value: 0.96
    Check Value: 0.96
    Volume Value: 0.95
    Check Value: 0.95
    Volume Value: 0.7
    Check Value: 0.7
    handleAudioStateChanged StoppedState
    sound stopped

    It seems like the value is set currently and even when I query the objects current volume using ::volume() member I get the correct values. However the volume doesn't change. Only when it get to max or min does the stream either mute or play at full volume.

    So basically when I move the slider it goes from 0 (Min value from the Slider) to 100 (MAX value from the slider.)
    converting that to a range between 0 and 1. All which works when I move the slider the audio either plays or if the slider is low the audio is muted, everything in between doesn't do anything to the volume of the QAudioOutput output.
    I have also tried to do it like its stated in the Qt Documentation on how to set the volume and that too didn't work.

    My setup:
    Windows 10 Pro x64
    Qt 5.9.3
    MinGW32 Compiler.

    Any idea's?

    RatzzR 1 Reply Last reply
    0
    • Banshee10000B Banshee10000

      Currently I'm struggling to set the volume for a QAudioOutput object...
      In the documentation its noted that ::setVolume takes a qreal

      I have a horizontal slider with value 0 to 100.
      Then I convert the incoming horizontal Slider value like this:

      output is a QAudioOutput

      void SoundSystem::SetVolume(int volume)
      {
          if(output->state() ==  QAudio::ActiveState)
          {
              //qreal linearVolume = QAudio::convertVolume(volume / qreal(100.0),
                                                              //QAudio::LogarithmicVolumeScale,
                                                              //QAudio::LinearVolumeScale);
              //output->setVolume(qRound(linearVolume * 100));
      
              qreal newVol =  (qreal)volume / 100;
              qDebug() << "Volume  Value: "  << newVol;
              output->setVolume(newVol);
              qDebug() << "Check Value: "  << output->volume();
          }
      }
      

      The debugging output:

      Exec::playSound
      handleAudioStateChanged ActiveState
      Volume Value: 0.99
      Check Value: 0.99
      Volume Value: 0.98
      Check Value: 0.98
      Volume Value: 0.97
      Check Value: 0.97
      Volume Value: 0.96
      Check Value: 0.96
      Volume Value: 0.95
      Check Value: 0.95
      Volume Value: 0.7
      Check Value: 0.7
      handleAudioStateChanged StoppedState
      sound stopped

      It seems like the value is set currently and even when I query the objects current volume using ::volume() member I get the correct values. However the volume doesn't change. Only when it get to max or min does the stream either mute or play at full volume.

      So basically when I move the slider it goes from 0 (Min value from the Slider) to 100 (MAX value from the slider.)
      converting that to a range between 0 and 1. All which works when I move the slider the audio either plays or if the slider is low the audio is muted, everything in between doesn't do anything to the volume of the QAudioOutput output.
      I have also tried to do it like its stated in the Qt Documentation on how to set the volume and that too didn't work.

      My setup:
      Windows 10 Pro x64
      Qt 5.9.3
      MinGW32 Compiler.

      Any idea's?

      RatzzR Offline
      RatzzR Offline
      Ratzz
      wrote on last edited by
      #2

      @Banshee10000

      Can you setVolume directly with qreal values which you get from QAudio::convertVolume ?
      https://doc.qt.io/qt-5/qtmultimedia-multimedia-audiooutput-audiooutput-cpp.html

      --Alles ist gut.

      1 Reply Last reply
      0
      • Banshee10000B Offline
        Banshee10000B Offline
        Banshee10000
        wrote on last edited by Banshee10000
        #3

        Hello @Ratzz I have tried to set the value directly, with qreal values as suggested but same results. Volume doesn't change unless slider is at 0 then the audio mutes otherwise its playing at max. so either 0 or 1. even though I feed it a range between 0 and 1 its ignored
        Debug from qreal values set directly using QAudio::convertVolume

        Exec::playSound
        handleAudioStateChanged ActiveState
        Check Value: 1
        Check Value: 0.849485
        Check Value: 0.761439
        Check Value: 0.69897
        Check Value: 0.650515
        Check Value: 0.610924
        Check Value: 0.577451
        Check Value: 0.548455
        Check Value: 0.522879
        Check Value: 0.5
        Check Value: 0
        handleAudioStateChanged StoppedState
        sound stopped

        I have also tried to use doubles and floats instead of qreal and I have downloaded the latest version of Qt 5.11.1 to see if that address the issue but the same issue remains. No idea however why though.

        1 Reply Last reply
        0
        • Pradeep P NP Offline
          Pradeep P NP Offline
          Pradeep P N
          wrote on last edited by Pradeep P N
          #4

          Hi @Banshee10000

          Did you check the example code available in Qt ?
          the link suggested by @Ratzz

          https://doc.qt.io/qt-5/qtmultimedia-multimedia-audiooutput-example.html
          Can you run this example and check the volume ?

          Pradeep Nimbalkar.
          Upvote the answer(s) that helped you to solve the issue...
          Keep code clean.

          1 Reply Last reply
          2
          • Banshee10000B Offline
            Banshee10000B Offline
            Banshee10000
            wrote on last edited by Banshee10000
            #5

            I was just testing with the example on my system which works. The volume can be set correctly and behaves as expected in the example. Could it maybe be PCM data that I'm sending to QAudioOutput that is preventing correct volume change ?

            I'm also using QAudioOutput in a thread. the slider is on the mainWindow UI sending the int value to the thread via signals and slots. I know that the value from the slider is received and converted in the thread correctly as per debug output. As well as when I move the slider it does mute the audio when its at its lowest point but moving it instantly goes from mute to max vol.

            1 Reply Last reply
            0
            • Banshee10000B Offline
              Banshee10000B Offline
              Banshee10000
              wrote on last edited by
              #6

              After a lot of trial and error I managed to solve this. It was indeed the way I create the PCM data.
              I used a unSignedInt as the sampleType and it should be SignedInt. Then setVolume works.

              1 Reply Last reply
              1

              • Login

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