annotate Plugins/Output/OSS/mixer.c @ 115:be5550234631 trunk

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