61
|
1 /* BMP - Cross-platform multimedia player
|
|
2 * Copyright (C) 2003-2004 BMP development team.
|
|
3 *
|
|
4 * Based on XMMS:
|
|
5 * Copyright (C) 1998-2003 XMMS development team.
|
|
6 *
|
|
7 * This program is free software; you can redistribute it and/or modify
|
|
8 * it under the terms of the GNU General Public License as published by
|
|
9 * the Free Software Foundation; either version 2 of the License, or
|
|
10 * (at your option) any later version.
|
|
11 *
|
|
12 * This program is distributed in the hope that it will be useful,
|
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15 * GNU General Public License for more details.
|
|
16 *
|
|
17 * You should have received a copy of the GNU General Public License
|
|
18 * along with this program; if not, write to the Free Software
|
|
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
20 */
|
|
21
|
|
22
|
|
23 #include <glib.h>
|
|
24 #include <stdio.h>
|
|
25 #include <string.h>
|
|
26
|
|
27 #include <unistd.h>
|
|
28 #include <fcntl.h>
|
|
29 #include <errno.h>
|
|
30 #include <sys/ioctl.h>
|
|
31
|
|
32 #include "OSS.h"
|
|
33
|
|
34
|
|
35 static char *
|
|
36 get_mixer_device(void)
|
|
37 {
|
|
38 char *name;
|
|
39
|
|
40 if (oss_cfg.use_alt_mixer_device && oss_cfg.alt_mixer_device)
|
|
41 name = g_strdup(oss_cfg.alt_mixer_device);
|
|
42 else if (oss_cfg.mixer_device > 0)
|
|
43 name = g_strdup_printf("%s%d", DEV_MIXER, oss_cfg.mixer_device);
|
|
44 else
|
|
45 name = g_strdup(DEV_MIXER);
|
|
46
|
|
47 return name;
|
|
48 }
|
|
49
|
|
50 void
|
|
51 oss_get_volume(int *l, int *r)
|
|
52 {
|
|
53 int fd, v, devs;
|
|
54 long cmd;
|
|
55 gchar *devname;
|
|
56
|
|
57 devname = get_mixer_device();
|
|
58 fd = open(devname, O_RDONLY);
|
|
59 g_free(devname);
|
|
60
|
|
61 /*
|
|
62 * We dont show any errors if this fails, as this is called
|
|
63 * rather often
|
|
64 */
|
|
65 if (fd != -1) {
|
|
66 ioctl(fd, SOUND_MIXER_READ_DEVMASK, &devs);
|
|
67 if ((devs & SOUND_MASK_PCM) && (oss_cfg.use_master == 0))
|
|
68 cmd = SOUND_MIXER_READ_PCM;
|
|
69 else if ((devs & SOUND_MASK_VOLUME) && (oss_cfg.use_master == 1))
|
|
70 cmd = SOUND_MIXER_READ_VOLUME;
|
|
71 else {
|
|
72 close(fd);
|
|
73 return;
|
|
74 }
|
|
75 ioctl(fd, cmd, &v);
|
|
76 *r = (v & 0xFF00) >> 8;
|
|
77 *l = (v & 0x00FF);
|
|
78 close(fd);
|
|
79 }
|
|
80 }
|
|
81
|
|
82 void
|
|
83 oss_set_volume(int l, int r)
|
|
84 {
|
|
85 int fd, v, devs;
|
|
86 long cmd;
|
|
87 gchar *devname;
|
|
88
|
|
89 devname = get_mixer_device();
|
|
90 fd = open(devname, O_RDONLY);
|
|
91
|
|
92 if (fd != -1) {
|
|
93 ioctl(fd, SOUND_MIXER_READ_DEVMASK, &devs);
|
|
94 if ((devs & SOUND_MASK_PCM) && (oss_cfg.use_master == 0))
|
|
95 cmd = SOUND_MIXER_WRITE_PCM;
|
|
96 else if ((devs & SOUND_MASK_VOLUME) && (oss_cfg.use_master == 1))
|
|
97 cmd = SOUND_MIXER_WRITE_VOLUME;
|
|
98 else {
|
|
99 close(fd);
|
|
100 return;
|
|
101 }
|
|
102 v = (r << 8) | l;
|
|
103 ioctl(fd, cmd, &v);
|
|
104 close(fd);
|
|
105 }
|
|
106 else
|
|
107 g_warning("oss_set_volume(): Failed to open mixer device (%s): %s",
|
|
108 devname, strerror(errno));
|
|
109 g_free(devname);
|
|
110 }
|