title: How to get system volume level as a scalar from 0 to 100?
body: <p>I'm currently working on a "Volume mixer" to control the volume of each program on my PC (Windows 10).</p>
  
  <p>How do I get the volume level of each program/audio session as a scalar from 0 to 100?</p>
  
  <p>As you can see, in the code below, I found the <code>GetPeakValue</code> function, but it returns values like 0.0812654 or 0.021352.</p>
  
  <p>I'm sure that these values are the volume of each audio session in a scalar from 1.0 to 0.0. But what I want is the volume limitation, which you can set in the windows audio mixer for example, and not the current level. So if I set the program volume level to 50%, I want a value like 0.5.</p>
  
  <p>In the second function (<code>getVolume</code>), you'll see that I already got the master volume in a 0-100 scalar, but there the endpoint device has a function for the scalar level already. So I'll need the same function at least, or a calculation, to get such a scalar for every audio session as well.</p>
  
  <pre><code>void getSessions() {
      CoInitialize(NULL);
  
      IMMDeviceEnumerator *pDeviceEnumerator = NULL;
      IMMDevice *pDevice = NULL;
      IAudioSessionManager2 *pAudioSessionManager2 = NULL;
      IAudioSessionEnumerator *pAudioSessionEnumerator = NULL;
  
      CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_INPROC_SERVER, __uuidof(IMMDeviceEnumerator), (LPVOID *)&amp;pDeviceEnumerator);
      pDeviceEnumerator-&gt;GetDefaultAudioEndpoint(eRender, eConsole, &amp;pDevice);
  
      pDevice-&gt;Activate(__uuidof(IAudioSessionManager2), CLSCTX_ALL, NULL, (void **) &amp;pAudioSessionManager2);
      pAudioSessionManager2-&gt;GetSessionEnumerator(&amp;pAudioSessionEnumerator);
  
      int nSessionCount;
      pAudioSessionEnumerator-&gt;GetCount(&amp;nSessionCount);
  
      std::cout &lt;&lt; "Session Count: " &lt;&lt; nSessionCount &lt;&lt; std::endl;
  
      while (true) {
          for (int nSessionIndex = 0; nSessionIndex &lt; nSessionCount; nSessionIndex++) {
              IAudioSessionControl *pSessionControl = NULL;
              if (FAILED(pAudioSessionEnumerator-&gt;GetSession(nSessionIndex, &amp;pSessionControl)))
                  continue;
  
              IAudioMeterInformation *pAudioMeterInformation = NULL;
              pSessionControl-&gt;QueryInterface(&amp;pAudioMeterInformation);
  
              float fPeak = NULL;
              pAudioMeterInformation-&gt;GetPeakValue(&amp;fPeak);
  
              std::cout &lt;&lt; "fPeak Value: " &lt;&lt; fPeak &lt;&lt; std::endl;
          }
  
          std::cout &lt;&lt; "\n\n";
          Sleep(1000);
      }
  
      CoUninitialize();
  }
  
  double getVolume() {
      float currentVolume = 0;
  
      CoInitialize(NULL);
      IMMDeviceEnumerator *deviceEnumerator = NULL;
      CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_INPROC_SERVER, __uuidof(IMMDeviceEnumerator), (LPVOID *)&amp;deviceEnumerator);
      IMMDevice *defaultDevice = NULL;
      deviceEnumerator-&gt;GetDefaultAudioEndpoint(eRender, eConsole, &amp;defaultDevice);
      deviceEnumerator-&gt;Release();
      deviceEnumerator = NULL;
  
      IAudioEndpointVolume *endpointVolume = NULL;
      defaultDevice-&gt;Activate(__uuidof(IAudioEndpointVolume), CLSCTX_INPROC_SERVER, NULL, (LPVOID *)&amp;endpointVolume);
      defaultDevice-&gt;Release();
      defaultDevice = NULL;
  
      float fLevel;
      endpointVolume-&gt;GetMasterVolumeLevel(&amp;fLevel);
      qDebug() &lt;&lt; "FLevel: ";
      qDebug() &lt;&lt; fLevel;
  
      endpointVolume-&gt;GetMasterVolumeLevelScalar(&amp;currentVolume);
      endpointVolume-&gt;Release();
  
      CoUninitialize();
  
      return (double)(currentVolume * 100);
  }
  </code></pre>