From 72f2271a0a02b857e4654bd742dcedbfdd1a2d10 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 25 Oct 2022 01:33:03 +0200 Subject: Rename "system_alert_volume.c" to "SSVLSystemAlertVolume.c" Align with the new identifier naming. --- SSVLSystemAlertVolume.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 SSVLSystemAlertVolume.c (limited to 'SSVLSystemAlertVolume.c') diff --git a/SSVLSystemAlertVolume.c b/SSVLSystemAlertVolume.c new file mode 100644 index 0000000..a795568 --- /dev/null +++ b/SSVLSystemAlertVolume.c @@ -0,0 +1,62 @@ +#include + +const AudioServicesPropertyID SSVLAudioServicesPropertySystemAlertVolume = 'ssvl'; + +OSStatus SSVLGetSystemVolume(Float32 *volume) { + UInt32 volume_size = sizeof(*volume); + + OSStatus result = AudioServicesGetProperty( + kAudioServicesPropertySystemAlertVolume, + 0, + NULL, + &volume_size, + volume + ); + + // TODO: Sound PrefPane: If result != noErr, return 0.5? + + if (*volume != 0) { + *volume = log(*volume) + 1.0; + } + else { + *volume = 0; + } + + return result; +} + +OSStatus SSVLSetSystemVolume(Float32 volume) { + volume = exp(volume - 1.0); + + return AudioServicesSetProperty( + kAudioServicesPropertySystemAlertVolume, + 0, + NULL, + sizeof(volume), + &volume + ); +} + +int main() { + OSStatus result; + + Float32 volume; + + result = system_volume_get(&volume); + if (result != noErr) { + printf("Error getting system volume: %d\n", result); + return 1; + } + + printf("System volume: %f\n", volume); + + + Float32 new_volume = 0.5; + result = system_volume_set(new_volume); + if (result != noErr) { + printf("Error setting system volume: %d\n", result); + return 1; + } + + printf("Set volume to: %f\n", new_volume); +} -- cgit v1.2.3