File: ossmixer.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 (71 lines) | stat: -rw-r--r-- 1,621 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
65
66
67
68
69
70
71
/*\
|*|  OSSMixer
|*|  Class for accessing the OSS mixer device (/dev/mixer)
\*/

#include <nmixer.h>

#ifdef __cplusplus
extern "C" {
#endif

#ifdef HAVE_SYS_SOUNDCARD_H
#include <sys/soundcard.h>
#elif HAVE_MACHINE_SOUNDCARD_H
#include <machine/soundcard.h>
#elif HAVE_SOUNDCARD_H
#include <soundcard.h>
#endif

#ifdef __cplusplus
}
#endif

OSSMixer::OSSMixer(baseMixer *next) : baseMixer(next)
{
	mixer = open(MIXER_DEVICE, O_RDWR);
	if (mixer < 0) return;
	unsigned int setting;
	ioctl(mixer, MIXER_READ(SOUND_MIXER_DEVMASK), &setting);
	for (int i = 0; i < SOUND_MIXER_NRDEVICES; i++)
		if (setting & (1 << i)) AddDevice(i);

#ifdef MOZART
	/* On my system, the mozart souncard I have (with OTI-601 chipset) 
	 * produces a lot of noise and fuss after initialisation. Setting 
	 * SOUND_MIXER_LINE2 to zero stops this (what actual setting does this
	 * change on the mozart card???)
	 */
	setting = 0;
	ioctl(mixer, MIXER_WRITE(SOUND_MIXER_LINE2), &setting);
#endif
}

OSSMixer::~OSSMixer()
{
	close(mixer);
}

bool OSSMixer::Set(int device, struct volume *vol)
{
	int setting = (vol->left & 0xFF) + ((vol->right & 0xFF) << 8);
	return (ioctl(mixer, MIXER_WRITE(device), &setting) >= 0);
}

bool OSSMixer::Get(int device, struct volume *vol)
{
	int setting;
	if (ioctl(mixer, MIXER_READ(device), &setting) < 0)
		return false;
	vol->left  = setting & 0x00FF;
	vol->right = (setting & 0xFF00) >> 8;
	return true;
}

const char *OSSMixer::Label(int device)
{
	static const char *sources[] = SOUND_DEVICE_LABELS;
	if ((device < 0) || (device >= SOUND_MIXER_NRDEVICES))
		return "<OSS:none>";
	return sources[device];
}