Skip to content

Commit

Permalink
Volume matching
Browse files Browse the repository at this point in the history
  • Loading branch information
monkee52 committed Sep 5, 2016
1 parent d1ee5eb commit 5e35dd2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions vstaudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <Functiondiscoverykeys_devpkey.h>
#include <MsXml6.h>
#include <comdef.h>
#include <math.h>

#include "PolicyConfig.h"

Expand Down Expand Up @@ -670,6 +671,8 @@ void GetAudioEndpointVolume(LPWSTR deviceId, float * volume, BOOL * mute) {
}

void SetAudioEndpointVolume(LPWSTR deviceId, float volume, BOOL mute) {
volume = max(0.0, min(1.0, volume));

RwAudioEndpointVolume(deviceId, TRUE, &volume, &mute);
}

Expand Down Expand Up @@ -766,11 +769,17 @@ int wmain(int argc, wchar_t * argv[]) {
return EXIT_FAILURE;
}

float originalVolume;
BOOL originalMute;
float volume;
BOOL mute;

GetAudioEndpointVolume(defaultDeviceId, &originalVolume, &originalMute);
GetAudioEndpointVolume(defaultDeviceId, &volume, &mute);
SetAudioEndpointVolume(defaultDeviceId, (float)0.0, TRUE);

// Match volume
// TODO:
// * Custom functions
SetAudioEndpointVolume(targetDeviceId, (5.0 * log10(volume) + 10.0) / 13.0, mute);

SetDefaultAudioEndpoint(targetDeviceId);

// Sleep to prevent loud pop
Expand All @@ -794,7 +803,12 @@ int wmain(int argc, wchar_t * argv[]) {
// Restore
EnableMenuItem(hMenu, SC_CLOSE, MF_BYCOMMAND | MF_ENABLED);

SetAudioEndpointVolume(defaultDeviceId, originalVolume, originalMute);
// Match volume
// TODO:
// * Custom functions
GetAudioEndpointVolume(targetDeviceId, &volume, &mute);

SetAudioEndpointVolume(defaultDeviceId, pow(10.0, 13.0 * volume / 5.0 - 2.0), mute);
SetDefaultAudioEndpoint(defaultDeviceId);

CoUninitialize();
Expand Down
Binary file modified vstaudio.rc
Binary file not shown.

0 comments on commit 5e35dd2

Please sign in to comment.