aboutsummaryrefslogtreecommitdiffstats
path: root/SSVLSystemAlertVolume.c
blob: d16204c99a614a6a1841a021fe55193691063f92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "SSVLSystemAlertVolume.h"

const AudioServicesPropertyID SSVLAudioServicesPropertySystemAlertVolume = 'ssvl';

OSStatus SSVLGetSystemVolume(Float32 *volume) {
	UInt32 volume_size = sizeof(*volume);

	OSStatus result = AudioServicesGetProperty(
		SSVLAudioServicesPropertySystemAlertVolume,
		0,
		NULL,
		&volume_size,
		volume
	);

	if (*volume != 0) {
		*volume = log(*volume) + 1.0;
	}
	else {
		*volume = 0;
	}

	return result;
}

OSStatus SSVLSetSystemVolume(Float32 volume) {
	volume = exp(volume - 1.0);

	return AudioServicesSetProperty(
		SSVLAudioServicesPropertySystemAlertVolume,
		0,
		NULL,
		sizeof(volume),
		&volume
	);
}