annotate src/OSS/mixer.c @ 1891:9de655fcec38

Use GTK stock buttons.
author William Pitcock <nenolod@atheme.org>
date Wed, 26 Sep 2007 11:41:16 -0500
parents 11d45400f5ed
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1 /* BMP - Cross-platform multimedia player
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
2 * Copyright (C) 2003-2004 BMP development team.
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
3 *
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
4 * Based on XMMS:
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
5 * Copyright (C) 1998-2003 XMMS development team.
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
6 *
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
7 * This program is free software; you can redistribute it and/or modify
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
8 * it under the terms of the GNU General Public License as published by
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
10 * (at your option) any later version.
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
11 *
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
15 * GNU General Public License for more details.
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
16 *
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
18 * along with this program; if not, write to the Free Software
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
20 */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
21
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
22 #include <glib.h>
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
23 #include <stdio.h>
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
24 #include <string.h>
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
25
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
26 #include <unistd.h>
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
27 #include <fcntl.h>
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
28 #include <errno.h>
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
29 #include <sys/ioctl.h>
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
30
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
31 #include "OSS.h"
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
32
74
11d45400f5ed [svn] The mixer device isn't opened and closed for every action now, instead
js
parents: 12
diff changeset
33 static int fd = -1;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
34
74
11d45400f5ed [svn] The mixer device isn't opened and closed for every action now, instead
js
parents: 12
diff changeset
35 static int
11d45400f5ed [svn] The mixer device isn't opened and closed for every action now, instead
js
parents: 12
diff changeset
36 open_mixer_device()
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
37 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
38 char *name;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
39
74
11d45400f5ed [svn] The mixer device isn't opened and closed for every action now, instead
js
parents: 12
diff changeset
40 if (fd != -1)
11d45400f5ed [svn] The mixer device isn't opened and closed for every action now, instead
js
parents: 12
diff changeset
41 return 0;
11d45400f5ed [svn] The mixer device isn't opened and closed for every action now, instead
js
parents: 12
diff changeset
42
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
43 if (oss_cfg.use_alt_mixer_device && oss_cfg.alt_mixer_device)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
44 name = g_strdup(oss_cfg.alt_mixer_device);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
45 else if (oss_cfg.mixer_device > 0)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
46 name = g_strdup_printf("%s%d", DEV_MIXER, oss_cfg.mixer_device);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
47 else
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
48 name = g_strdup(DEV_MIXER);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
49
74
11d45400f5ed [svn] The mixer device isn't opened and closed for every action now, instead
js
parents: 12
diff changeset
50 if ((fd = open(name, O_RDWR)) == -1) {
11d45400f5ed [svn] The mixer device isn't opened and closed for every action now, instead
js
parents: 12
diff changeset
51 g_free(name);
11d45400f5ed [svn] The mixer device isn't opened and closed for every action now, instead
js
parents: 12
diff changeset
52 return 1;
11d45400f5ed [svn] The mixer device isn't opened and closed for every action now, instead
js
parents: 12
diff changeset
53 }
11d45400f5ed [svn] The mixer device isn't opened and closed for every action now, instead
js
parents: 12
diff changeset
54 g_free(name);
11d45400f5ed [svn] The mixer device isn't opened and closed for every action now, instead
js
parents: 12
diff changeset
55
11d45400f5ed [svn] The mixer device isn't opened and closed for every action now, instead
js
parents: 12
diff changeset
56 return 0;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
57 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
58
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
59 void
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
60 oss_get_volume(int *l, int *r)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
61 {
74
11d45400f5ed [svn] The mixer device isn't opened and closed for every action now, instead
js
parents: 12
diff changeset
62 int v, devs;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
63 long cmd;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
64
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
65 /*
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
66 * We dont show any errors if this fails, as this is called
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
67 * rather often
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
68 */
74
11d45400f5ed [svn] The mixer device isn't opened and closed for every action now, instead
js
parents: 12
diff changeset
69 if (!open_mixer_device()) {
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
70 ioctl(fd, SOUND_MIXER_READ_DEVMASK, &devs);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
71 if ((devs & SOUND_MASK_PCM) && (oss_cfg.use_master == 0))
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
72 cmd = SOUND_MIXER_READ_PCM;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
73 else if ((devs & SOUND_MASK_VOLUME) && (oss_cfg.use_master == 1))
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
74 cmd = SOUND_MIXER_READ_VOLUME;
74
11d45400f5ed [svn] The mixer device isn't opened and closed for every action now, instead
js
parents: 12
diff changeset
75 else
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
76 return;
74
11d45400f5ed [svn] The mixer device isn't opened and closed for every action now, instead
js
parents: 12
diff changeset
77
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
78 ioctl(fd, cmd, &v);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
79 *r = (v & 0xFF00) >> 8;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
80 *l = (v & 0x00FF);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
81 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
82 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
83
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
84 void
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
85 oss_set_volume(int l, int r)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
86 {
74
11d45400f5ed [svn] The mixer device isn't opened and closed for every action now, instead
js
parents: 12
diff changeset
87 int v, devs;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
88 long cmd;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
89
74
11d45400f5ed [svn] The mixer device isn't opened and closed for every action now, instead
js
parents: 12
diff changeset
90 if (!open_mixer_device()) {
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
91 ioctl(fd, SOUND_MIXER_READ_DEVMASK, &devs);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
92 if ((devs & SOUND_MASK_PCM) && (oss_cfg.use_master == 0))
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
93 cmd = SOUND_MIXER_WRITE_PCM;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
94 else if ((devs & SOUND_MASK_VOLUME) && (oss_cfg.use_master == 1))
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
95 cmd = SOUND_MIXER_WRITE_VOLUME;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
96 else {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
97 close(fd);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
98 return;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
99 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
100 v = (r << 8) | l;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
101 ioctl(fd, cmd, &v);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
102 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
103 else
74
11d45400f5ed [svn] The mixer device isn't opened and closed for every action now, instead
js
parents: 12
diff changeset
104 g_warning("Failed to open mixer device: %s", strerror(errno));
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
105 }
74
11d45400f5ed [svn] The mixer device isn't opened and closed for every action now, instead
js
parents: 12
diff changeset
106
11d45400f5ed [svn] The mixer device isn't opened and closed for every action now, instead
js
parents: 12
diff changeset
107 void
11d45400f5ed [svn] The mixer device isn't opened and closed for every action now, instead
js
parents: 12
diff changeset
108 close_mixer_device()
11d45400f5ed [svn] The mixer device isn't opened and closed for every action now, instead
js
parents: 12
diff changeset
109 {
11d45400f5ed [svn] The mixer device isn't opened and closed for every action now, instead
js
parents: 12
diff changeset
110 if (fd != -1) {
11d45400f5ed [svn] The mixer device isn't opened and closed for every action now, instead
js
parents: 12
diff changeset
111 close(fd);
11d45400f5ed [svn] The mixer device isn't opened and closed for every action now, instead
js
parents: 12
diff changeset
112 fd = -1;
11d45400f5ed [svn] The mixer device isn't opened and closed for every action now, instead
js
parents: 12
diff changeset
113 }
11d45400f5ed [svn] The mixer device isn't opened and closed for every action now, instead
js
parents: 12
diff changeset
114 }