Example #1
0
// This method will get the specified channel volume.
// float fVolume: the range of the value from 0.0 to 1.0
AUDIO_DEVICE_API HRESULT GetCaptureListDeviceChannelVolume(DeviceInfo *pDeviceInfo, int index, float *pfVolume, UINT iChannel)
{
	InternalDeviceInfo *pInternalDeviceInfo = (InternalDeviceInfo *) pDeviceInfo;

    HRESULT hr;
	IMMDevice *pDevice = NULL;
	IAudioEndpointVolume *pAudioVolume = NULL;

    if (pInternalDeviceInfo->pCaptureCollection != NULL) {
        hr = pInternalDeviceInfo->pCaptureCollection->Item(index, &pDevice);
    }
	if (hr != S_OK) goto errors;

    hr = pDevice->Activate(__uuidof(IAudioEndpointVolume), CLSCTX_ALL, NULL, (void**)&pAudioVolume);
	if (hr != S_OK) goto errors;

    hr = pAudioVolume->GetChannelVolumeLevelScalar(iChannel, pfVolume);

errors:
    SAFE_RELEASE(pAudioVolume);
    SAFE_RELEASE(pDevice);
	return hr;
}