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