File: nasmixer.cc

package info (click to toggle)
mp3blaster 2-0b16-1.1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 1,012 kB
  • ctags: 1,241
  • sloc: cpp: 12,228; ansic: 1,557; sh: 362; makefile: 107
file content (64 lines) | stat: -rw-r--r-- 1,522 bytes parent folder | download
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*\
|*| Network Audio System specific mixer routines
\*/
#ifdef HAVE_NASPLAYER
#include <nmixer.h>
#include <audio/audiolib.h>
#include <audio/audio.h>

static AuDeviceAttributes *
au_list_devices(AuServer *aud, int *ndev)
{
	AuDeviceAttributes *d;
	int i;
	i = *ndev = AuServerNumDevices(aud);
	if (i < 1) return NULL;
	d = (AuDeviceAttributes *)malloc(i * sizeof(AuDeviceAttributes));
	while (--i >= 0) {
		AuDeviceAttributes *t = AuServerDevice(aud, i);
		memcpy(d + i, t, sizeof(AuDeviceAttributes));
	}
	return d;
}

NASMixer::NASMixer(baseMixer *next) : baseMixer(next)
{
	aud = AuOpenServer(0, 0, 0, 0, 0, 0);
	if (!aud) return;
	ada = au_list_devices(aud, &num_ada);
	for (int i = 0; i < num_ada; i++) AddDevice(i);
}

NASMixer::~NASMixer()
{
	if (!aud) return;
	AuFreeDeviceAttributes(aud, num_ada, ada);
	AuCloseServer(aud);
}

bool NASMixer::Set(int device, struct volume *vol)
{
	if (!aud) return false;
	AuDeviceAttributes *da = &ada[device];
	AuDeviceGain(da) = AuFixedPointFromSum((vol->left + vol->right) / 2, 0);
	AuSetDeviceAttributes(aud, AuDeviceIdentifier(da),
			AuCompDeviceGainMask, da, NULL);
	AuFlush(aud);
	return true;
}

bool NASMixer::Get(int device, struct volume *vol)
{
	if (!aud) return false;
	AuDeviceAttributes *da = &ada[device];
	vol->left = vol->right = AuFixedPointIntegralAddend(AuDeviceGain(da));
	return true;
}

const char *NASMixer::Label(int device)
{
	if ((device < 0) || (device >= num_ada))
		return "<NAS:none>";
	return AuDeviceDescription(&ada[device])->data;
}
#endif