Last active
July 12, 2022 18:48
-
-
Save rdp/8363580 to your computer and use it in GitHub Desktop.
Revisions
-
rdp revised this gist
Jun 24, 2015 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -70,6 +70,7 @@ int main(int argc, char** argv) { else { printf("wrong v of windows, req. vista+ ! \n"); } fflush(stdout); // just in case Exit: SAFE_RELEASE(pEnumerator) -
rdp revised this gist
Jan 13, 2014 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,6 +2,8 @@ // g++ this_filename.c -lole32 // outputs current system volume (out of 0-100) to stdout, ex: output "23" // mostly gleaned from examples here: http://msdn.microsoft.com/en-us/library/windows/desktop/dd370839(v=vs.85).aspx // download a compiled version here: // https://sourceforge.net/projects/mplayer-edl/files/adjust_get_current_system_volume_vista_plus.exe.exe (updated, can set it too now!) #include <windows.h> #include <commctrl.h> #include <mmdeviceapi.h> -
rdp renamed this gist
Jan 13, 2014 . 1 changed file with 11 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,8 +2,6 @@ // g++ this_filename.c -lole32 // outputs current system volume (out of 0-100) to stdout, ex: output "23" // mostly gleaned from examples here: http://msdn.microsoft.com/en-us/library/windows/desktop/dd370839(v=vs.85).aspx #include <windows.h> #include <commctrl.h> #include <mmdeviceapi.h> @@ -12,14 +10,14 @@ #include <math.h> /* log */ #define EXIT_ON_ERROR(hr) \ if (FAILED(hr)) { printf("error %d occurred\n", -hr); goto Exit; } #define SAFE_RELEASE(punk) \ if ((punk) != NULL) \ { (punk)->Release(); (punk) = NULL; } int main(int argc, char** argv) { IAudioEndpointVolume *g_pEndptVol = NULL; bool WindowsLH; HRESULT hr = S_OK; @@ -54,6 +52,15 @@ int main(int argc, char** args) { CLSCTX_ALL, NULL, (void**)&g_pEndptVol); EXIT_ON_ERROR(hr) float currentVal; if(argc == 2) { if(strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "/?")==0 || strcmp(argv[1], "--help")==0 ) { printf("sets/gest current master volume level [vista+]\nSyntax: either no args to display current value, or a number to set it, 0-100. It prints out the new or current value."); goto Exit; } float got = (float) atof(argv[1])/100.0; // needs to be within 1.0 to 0.0 hr = g_pEndptVol->SetMasterVolumeLevelScalar(got, NULL); EXIT_ON_ERROR(hr) } hr = g_pEndptVol->GetMasterVolumeLevelScalar(¤tVal); EXIT_ON_ERROR(hr) printf("%d", (int) round(100 * currentVal)); // 0.839999 to 84 :) -
rdp revised this gist
Jan 10, 2014 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,6 +2,8 @@ // g++ this_filename.c -lole32 // outputs current system volume (out of 0-100) to stdout, ex: output "23" // mostly gleaned from examples here: http://msdn.microsoft.com/en-us/library/windows/desktop/dd370839(v=vs.85).aspx // download a compiled version here: // https://sourceforge.net/projects/mplayer-edl/files/current_system_volume_vista_plus.exe #include <windows.h> #include <commctrl.h> #include <mmdeviceapi.h> -
rdp revised this gist
Jan 10, 2014 . 1 changed file with 5 additions and 22 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ // to compile (using mingw-w64) // g++ this_filename.c -lole32 // outputs current system volume (out of 0-100) to stdout, ex: output "23" // mostly gleaned from examples here: http://msdn.microsoft.com/en-us/library/windows/desktop/dd370839(v=vs.85).aspx #include <windows.h> #include <commctrl.h> #include <mmdeviceapi.h> @@ -51,30 +51,13 @@ int main(int argc, char** args) { hr = pDevice->Activate(__uuidof(IAudioEndpointVolume), CLSCTX_ALL, NULL, (void**)&g_pEndptVol); EXIT_ON_ERROR(hr) float currentVal; hr = g_pEndptVol->GetMasterVolumeLevelScalar(¤tVal); EXIT_ON_ERROR(hr) printf("%d", (int) round(100 * currentVal)); // 0.839999 to 84 :) } else { printf("wrong v of windows, req. vista+ ! \n"); } Exit: -
rdp revised this gist
Jan 10, 2014 . 1 changed file with 18 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,11 +1,13 @@ // to compile (using mingw-w64) // g++ this_filename.c -lole32 // outputs current system volume (out of 0-100) to stdout // mostly gleaned via "copy and paste" from http://msdn.microsoft.com/en-us/library/windows/desktop/dd370839(v=vs.85).aspx #include <windows.h> #include <commctrl.h> #include <mmdeviceapi.h> #include <endpointvolume.h> #include <stdio.h> #include <math.h> /* log */ #define EXIT_ON_ERROR(hr) \ if (FAILED(hr)) { goto Exit; } @@ -57,7 +59,19 @@ int main(int argc, char** args) { float currentVal; hr = g_pEndptVol->GetMasterVolumeLevel(¤tVal); EXIT_ON_ERROR(hr) printf("current master volume is %f (min %f max %f inc %f)\n", currentVal, pfLevelMinDB, pfLevelMaxDB, pfVolumeIncrementDB); // 50% is like current master volume is -10.419663 (min -74.000000 max 0.000000 inc 0.031250) // so range is 74 // log(74) == 4.3 // current value is log(10.4) = 2.3 // so divide those 2 values [?]... 2.3/4.3 float totalRange = pfLevelMaxDB - pfLevelMinDB; // not sure why this doesn't quite add up to the right value though... if(currentVal == 0.0) { printf("100"); // avoid log(0) below which is INF } else { printf("%f", 100-round(100*log(-currentVal-pfLevelMaxDB)/log(totalRange))); } } else { printf("wrong v of windows, req. vista+\n"); -
rdp revised this gist
Jan 10, 2014 . 1 changed file with 13 additions and 17 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,11 +1,11 @@ // compile (mingw-w64) // g++ this_filename.c -luuid -loleaut32 -lole32 #include <windows.h> #include <commctrl.h> #include <mmdeviceapi.h> #include <endpointvolume.h> #include <stdio.h> // mostly gleaned via "copy and paste" from http://msdn.microsoft.com/en-us/library/windows/desktop/dd370839(v=vs.85).aspx #define EXIT_ON_ERROR(hr) \ if (FAILED(hr)) { goto Exit; } @@ -16,6 +16,8 @@ bool WindowsLH; { (punk)->Release(); (punk) = NULL; } int main(int argc, char** args) { IAudioEndpointVolume *g_pEndptVol = NULL; bool WindowsLH; HRESULT hr = S_OK; IMMDeviceEnumerator *pEnumerator = NULL; IMMDevice *pDevice = NULL; @@ -25,7 +27,7 @@ int main(int argc, char** args) { VersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); GetVersionEx(&VersionInfo); if (VersionInfo.dwMajorVersion > 5) WindowsLH = true; // vista+ else WindowsLH = false; @@ -50,24 +52,18 @@ int main(int argc, char** args) { float pfLevelMinDB; float pfLevelMaxDB; float pfVolumeIncrementDB; hr = g_pEndptVol->GetVolumeRange(&pfLevelMinDB, &pfLevelMaxDB, &pfVolumeIncrementDB); EXIT_ON_ERROR(hr) float currentVal; hr = g_pEndptVol->GetMasterVolumeLevel(¤tVal); EXIT_ON_ERROR(hr) printf("current master volume is %f (min %f max %f inc %f)", currentVal, pfLevelMinDB, pfLevelMaxDB, pfVolumeIncrementDB); } else { printf("wrong v of windows, req. vista+\n"); } Exit: SAFE_RELEASE(pEnumerator) SAFE_RELEASE(pDevice) SAFE_RELEASE(g_pEndptVol) -
rdp created this gist
Jan 10, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,76 @@ #include <windows.h> #include <commctrl.h> #include <mmdeviceapi.h> #include <endpointvolume.h> #include <stdio.h> static IAudioEndpointVolume *g_pEndptVol = NULL; bool WindowsLH; #define EXIT_ON_ERROR(hr) \ if (FAILED(hr)) { goto Exit; } #define SAFE_RELEASE(punk) \ if ((punk) != NULL) \ { (punk)->Release(); (punk) = NULL; } int main(int argc, char** args) { HRESULT hr = S_OK; IMMDeviceEnumerator *pEnumerator = NULL; IMMDevice *pDevice = NULL; OSVERSIONINFO VersionInfo; ZeroMemory(&VersionInfo, sizeof(OSVERSIONINFO)); VersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); GetVersionEx(&VersionInfo); if (VersionInfo.dwMajorVersion > 5) WindowsLH = true; else WindowsLH = false; if (WindowsLH) { CoInitialize(NULL); // Get enumerator for audio endpoint devices. hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_INPROC_SERVER, __uuidof(IMMDeviceEnumerator), (void**)&pEnumerator); EXIT_ON_ERROR(hr) // Get default audio-rendering device. hr = pEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &pDevice); EXIT_ON_ERROR(hr) hr = pDevice->Activate(__uuidof(IAudioEndpointVolume), CLSCTX_ALL, NULL, (void**)&g_pEndptVol); EXIT_ON_ERROR(hr) float pfLevelMinDB; float pfLevelMaxDB; float pfVolumeIncrementDB; g_pEndptVol->GetVolumeRange(&pfLevelMinDB, &pfLevelMaxDB, &pfVolumeIncrementDB); float currentVal; g_pEndptVol->GetMasterVolumeLevel(¤tVal); printf("current master volume is %f (min %f max %f inc %f)", currentVal, pfLevelMinDB, pfLevelMaxDB, pfVolumeIncrementDB); } else { printf("wrong v of windows, req. vista+\n"); } Exit: if (FAILED(hr)) { MessageBox(NULL, TEXT("This program requires Windows Vista."), TEXT("Error termination"), MB_OK); } if (pEnumerator != NULL) { } SAFE_RELEASE(pEnumerator) SAFE_RELEASE(pDevice) SAFE_RELEASE(g_pEndptVol) CoUninitialize(); return 0; }