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. QMediaPlayer and volume control

QMediaPlayer and volume control

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 6.5k Views
  • 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.
  • J Offline
    J Offline
    jech
    wrote on last edited by
    #1

    Hello,

    I'm rewriting my music player from Qt4 to Qt5. I switched from Phonon to QtMultimedia. I now have a serious problem with volume control. To support ReplayGain, I read the tags from media files and then change the volume with every track to keep it equal.

    In phonon I use setVolumeDecibel because the volume differences stored in tags are in dB. But in QtMultiMedia I can not use it. The QMediaPlayer class only has a setVolume function. Is it planned to add the setVolumeDecibel function to this class? Is there any other possibility how I could control the volume in dB? What is the calculation for setVolume internally? Maybe I could reverse it to set the volume in dB.

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jech
      wrote on last edited by
      #2

      Nobody has an idea? At least I would like to know if it is possible at all or I should rather switch to another backend (libVLC, GStreamer).

      1 Reply Last reply
      0
      • JKSHJ Offline
        JKSHJ Offline
        JKSH
        Moderators
        wrote on last edited by
        #3

        Hi,

        There is currently no setVolumeDecible() function, but setVolume() scales your amplitudes linearly from 0 to 100: http://qt-project.org/doc/qt-5/qmediaplayer.html#volume-prop

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jech
          wrote on last edited by
          #4

          Hi JKSH, I know this but I need to change volume in dB.

          Do yo know what "replay gain":http://wiki.hydrogenaudio.org/index.php?title=ReplayGain_1.0_specification is? You have in your files stored tags which tell you if the file is louder or quieter then an average. The value is stored in dB. Thsi is why I need to control the volume in dB and a linear volume control is totally unusable for me.

          If at least I would know what is the calculation behind setVolume. Does it mean that if I call setVolume(50) it will set volume to -6 dB? I found some references but I really don't know how Qt is calculating it internally. I'll probably have to do some experimental tests...

          Here are some interesting references:
          "MSDN":http://social.msdn.microsoft.com/Forums/windowsdesktop
          /en-US/fd848086-0c73-4502-9fa9-a246f44e7dd7/converting-decibels-to-linear-0100-scale?forum=mediafoundationdevelopment
          "Audacity Forums":http://forum.audacityteam.org/viewtopic.php?f=21&t=26266

          1 Reply Last reply
          0
          • JKSHJ Offline
            JKSHJ Offline
            JKSH
            Moderators
            wrote on last edited by
            #5

            I know some very basic audio processing stuff. I wasn't familiar with replay gain before, but thank you for the link; I learnt something new today :)

            [quote author="jech" date="1393317490"]Does it mean that if I call setVolume(50) it will set volume to -6 dB?[/quote]Yes.

            • setVolume(100) gives you unattenuated playback (0 dB).
            • setVolume(0) mutes the audio.

            In other words,
            @
            finalAmplitude = sourceAmplitude * volume/100.0;
            @

            [quote]I found some references but I really don’t know how Qt is calculating it internally.[/quote]Qt simply passes the volume value to your system's audio backend. Here's an implementation where QMediaPlayer uses a GStreamer backend: http://code.woboq.org/qt5/qtmultimedia/src/plugins/gstreamer/mediaplayer/qgstreamerplayersession.cpp.html#_ZN23QGstreamerPlayerSession9setVolumeEi
            (It divides the volume value by 100 because GStreamer uses a linear scale of 0 to 1, while Qt uses a linear scale of 0 to 100)

            See:

            • http://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-base-libs/html/gst-plugins-base-libs-gststreamvolume.html#GstStreamVolume--volume
            • (Example usage) http://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-base-plugins/html/gst-plugins-base-plugins-volume.html

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            1 Reply Last reply
            0
            • J Offline
              J Offline
              jech
              wrote on last edited by
              #6

              Thanks a lot for the links it's now much more clear to me what is going on in the background.

              This means that it can behave differently based on the backend QtMultimedia uses. I studied some Internet sources and the basic conclusion is that multiplying or dividing the perceived volume by 2 is equal to a change of 6dB.

              I used these equations to solve the problem:
              dbVolume = 20*log10(volume/100);
              correctedVolume = pow(10, (dbVolume+replay_gain/2)/20)*100;

              For some reason I have to divide the replay_gain by 2. If I don't do it, the change would be too big. This seems to be working fine on Windows with DirectShow backend. I'll test it when I get home on a Linux machine.

              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