Mercurial > audlegacy-plugins
comparison src/sun/mixer.c @ 12:3da1b8942b8b trunk
[svn] - remove src/Input src/Output src/Effect src/General src/Visualization src/Container
author | nenolod |
---|---|
date | Mon, 18 Sep 2006 03:14:20 -0700 |
parents | src/Output/sun/mixer.c@13389e613d67 |
children |
comparison
equal
deleted
inserted
replaced
11:cff1d04026ae | 12:3da1b8942b8b |
---|---|
1 /* | |
2 * Copyright (C) 2001 CubeSoft Communications, Inc. | |
3 * <http://www.csoft.org> | |
4 * | |
5 * This program is free software; you can redistribute it and/or modify | |
6 * it under the terms of the GNU General Public License as published by | |
7 * the Free Software Foundation; either version 2 of the License, or | |
8 * (at your option) any later version. | |
9 * | |
10 * This program is distributed in the hope that it will be useful, | |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 * GNU General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU General Public License | |
16 * along with this program; if not, write to the Free Software | |
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
18 */ | |
19 | |
20 #include "sun.h" | |
21 #include "mixer.h" | |
22 | |
23 int sun_mixer_open(void) | |
24 { | |
25 if (pthread_mutex_lock(&audio.mixer_mutex) != 0) | |
26 return -1; | |
27 | |
28 if (!audio.mixer_keepopen || audio.mixerfd < 1) | |
29 { | |
30 audio.mixerfd = open(audio.devmixer, O_RDWR); | |
31 if (audio.mixerfd < 0) | |
32 perror(audio.devmixer); | |
33 } | |
34 return 0; | |
35 } | |
36 | |
37 void sun_mixer_close(void) | |
38 { | |
39 if (!audio.mixer_keepopen) | |
40 { | |
41 close(audio.mixerfd); | |
42 audio.mixerfd = 0; | |
43 } | |
44 pthread_mutex_unlock(&audio.mixer_mutex); | |
45 } | |
46 | |
47 int sun_mixer_get_dev(int fd, int *dev, char *id) | |
48 { | |
49 mixer_devinfo_t info; | |
50 | |
51 for (info.index = 0; ioctl(fd, AUDIO_MIXER_DEVINFO, &info) >= 0; | |
52 info.index++) | |
53 { | |
54 if (!strcmp(id, info.label.name)) | |
55 { | |
56 *dev = info.index; | |
57 return 0; | |
58 } | |
59 } | |
60 return -1; | |
61 } | |
62 | |
63 void sun_get_volume(int *l, int *r) | |
64 { | |
65 mixer_ctrl_t mixer; | |
66 | |
67 if (sun_mixer_open() < 0) | |
68 { | |
69 *l = 0; | |
70 *r = 0; | |
71 return; | |
72 } | |
73 | |
74 if ((sun_mixer_get_dev(audio.mixerfd, &mixer.dev, | |
75 audio.mixer_voldev) < 0)) | |
76 goto closemixer; | |
77 | |
78 mixer.type = AUDIO_MIXER_VALUE; | |
79 if (audio.output != NULL) | |
80 mixer.un.value.num_channels = audio.output->channels; | |
81 else | |
82 mixer.un.value.num_channels = 2; | |
83 | |
84 if (ioctl(audio.mixerfd, AUDIO_MIXER_READ, &mixer) < 0) | |
85 goto closemixer; | |
86 *l = (mixer.un.value.level[AUDIO_MIXER_LEVEL_LEFT] * 100) / 255; | |
87 if (mixer.un.value.num_channels > 1) | |
88 *r = (mixer.un.value.level[AUDIO_MIXER_LEVEL_RIGHT] * 100) / 255; | |
89 else | |
90 *r = *l; | |
91 | |
92 closemixer: | |
93 sun_mixer_close(); | |
94 } | |
95 | |
96 void sun_set_volume(int l, int r) | |
97 { | |
98 mixer_ctrl_t mixer; | |
99 | |
100 if (sun_mixer_open() < 0) | |
101 return; | |
102 | |
103 if ((sun_mixer_get_dev(audio.mixerfd, &mixer.dev, | |
104 audio.mixer_voldev) < 0)) | |
105 { | |
106 if (!audio.mixer_keepopen) | |
107 close(audio.mixerfd); | |
108 return; | |
109 } | |
110 mixer.type = AUDIO_MIXER_VALUE; | |
111 if (audio.output != NULL) | |
112 mixer.un.value.num_channels = audio.output->channels; | |
113 else | |
114 mixer.un.value.num_channels = 2; | |
115 mixer.un.value.level[AUDIO_MIXER_LEVEL_LEFT] = (l * 255) / 100; | |
116 if (mixer.un.value.num_channels > 1) | |
117 mixer.un.value.level[AUDIO_MIXER_LEVEL_RIGHT] = (r * 255) / 100; | |
118 | |
119 if (ioctl(audio.mixerfd, AUDIO_MIXER_WRITE, &mixer) < 0) | |
120 { | |
121 if (!audio.mixer_keepopen) | |
122 close(audio.mixerfd); | |
123 return; | |
124 } | |
125 sun_mixer_close(); | |
126 } |