Question

On Windows Vista and later it is posible to get master sound volume with MMDevice Api:

CoInitialize(NULL);
IMMDeviceEnumerator *pEnum = NULL;
IMMDevice *pDevice = NULL;
IAudioMeterInformation *pMeter = NULL;
float peak;

HRESULT hr;
hr = CoCreateInstance(__uuidof(MMDeviceEnumerator),     
                      NULL,
                      CLSCTX_INPROC_SERVER,
                      __uuidof(IMMDeviceEnumerator),
                      (void**)&pEnum);

hr = pEnum -> GetDefaultAudioEndpoint(eRender, eConsole, &pDevice);

pDevice -> Activate(__uuidof(IAudioMeterInformation), 
                    CLSCTX_ALL,
                    NULL,
                    (void**)&pMeter);

pMeter -> GetPeakValue(&peak); // I need this value

But how to get this info on Windows XP?

Was it helpful?

Solution

From MSDN, Peak Meters:

If the audio endpoint device implements the peak meter in hardware, the IAudioMeterInformation interface uses the hardware peak meter. Otherwise, the interface implements the peak meter in software.

Before Vista, there was no hardware peak metering on devices or KMixer (predecessor to WASAPI for internal audio mixing). There was no software fallback implementation to provide metering data too. So you just don't have the data, you cannot obtain it.

If you have the data you send to playback, you might want to implement software metering over this data feed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top