summaryrefslogtreecommitdiff
path: root/audio/gqmpeg/patches/patch-ab
blob: 2e8fc65dadf62f0b75a169f01bcc794aa7053541 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
$NetBSD: patch-ab,v 1.7 1999/06/16 03:06:36 hubertf Exp $

From rxg@ms25.url.com.tw Tue Jun 15 02:49:50 1999
Date: Mon, 14 Jun 1999 13:58:57 +0100
From: Rui-Xiang Guo <rxg@ms25.url.com.tw>
To: Hubert Feyrer <hubert.feyrer@rz.uni-regensburg.de>
Subject: Re: pkg/7768: new patches for 'gqmpeg'

I send you the patch for saving your time. :)
Should we need to remove some unnecesarry mixer control(eg. mic)?
This patch has a small bug. When you choose the mixer control 'master',
the balance control is unusable. The rest controls are OK.
We can fix this but I never use balance control except testing this
patch. :>
Can you tell me what you think? 
Thanks!
    [ Part 2: "Attached Text" ]

$NetBSD: patch-ab,v 1.7 1999/06/16 03:06:36 hubertf Exp $

--- mixer.c.orig	Wed Jun  2 05:50:45 1999
+++ mixer.c	Mon Jun 14 14:14:29 1999
@@ -24,7 +24,7 @@
 #include <linux/soundcard.h>
 #endif
 
-#if defined(sun) && defined(__svr4__)
+#if defined(sun) && defined(__svr4__) || defined(__NetBSD__)
 #include <sys/audioio.h>
 #endif
 
@@ -32,11 +32,6 @@
 #include <machine/soundcard.h>
 #endif
 
-#ifdef __NetBSD__
-#include <soundcard.h>
-#undef _POSIX_SOURCE
-#endif
-
 #ifdef __sgi
 #include <math.h>
 #include <audio.h>
@@ -65,7 +60,7 @@
 static GList *device_list = NULL;
 static DeviceData *current_device = NULL;
 
-#if defined (linux) || defined (__FreeBSD__) || defined (__NetBSD__)
+#if defined (linux) || defined (__FreeBSD__)
 void mixer_init(gint init_device_id)
 {
 	char *device_names[] = SOUND_DEVICE_NAMES;
@@ -100,11 +95,7 @@
 	/* get device listing */
 	for (i=0; i<SOUND_MIXER_NRDEVICES; i++)
 		{
-		if ((dev_mask & (1<<i)) /* skip unsupported */
-#ifndef __NetBSD__
-		   && !(rec_mask & (1<<i)) /* & record devs */
-#endif
-		   )
+		if ((dev_mask & (1<<i)) && !(rec_mask & (1<<i))) /* skip unsupported & record devs */
  			{
 			DeviceData *device = g_new0(DeviceData, 1);
 			device->device_id = i;
@@ -186,6 +177,199 @@
 	return vol;
 }
 
+#elif defined(__NetBSD__)
+mixer_devinfo_t *infos;
+mixer_ctrl_t *values;
+void mixer_init(gint init_device_id)
+{
+  int fd, i, ndev;
+  char *mixer_device;
+  audio_device_t adev;
+  mixer_devinfo_t dinfo;
+
+  mixer_device = getenv("MIXERDEVICE");
+  if (mixer_device == NULL)
+    mixer_device = "/dev/mixer0";
+
+  if ((fd = open(mixer_device, O_RDWR)) == -1) {
+    perror(mixer_device);
+    mixer_enabled = FALSE;
+  }
+
+  if (ioctl(fd, AUDIO_GETDEV, &adev) == -1) {
+    perror(mixer_device);
+    close(fd);
+    mixer_enabled = FALSE;
+  }
+
+  for (ndev = 0; ; ndev++) {
+    dinfo.index = ndev;
+    if (ioctl(fd, AUDIO_MIXER_DEVINFO, &dinfo) == -1)
+      break;
+  }
+  infos = calloc(ndev, sizeof *infos);
+  values = calloc(ndev, sizeof *values);
+
+  for (i = 0; i < ndev; i++) {
+    infos[i].index = i;
+    ioctl(fd, AUDIO_MIXER_DEVINFO, &infos[i]);
+  }
+
+  for (i = 0; i < ndev; i++) {
+    values[i].dev = i;
+    values[i].type = infos[i].type;
+    if (infos[i].type != AUDIO_MIXER_CLASS) {
+      values[i].un.value.num_channels = 2;
+      if (ioctl(fd, AUDIO_MIXER_READ, &values[i]) == -1) {
+        values[i].un.value.num_channels = 1;
+        if (ioctl(fd, AUDIO_MIXER_READ, &values[i]) == -1)
+          perror("AUDIO_MIXER_READ");
+      }
+    }
+  }
+  close(fd);
+
+  for (i = 0; i < ndev; i++) {
+    if (infos[i].type == AUDIO_MIXER_VALUE) {
+      DeviceData *device = g_new0(DeviceData, 1);
+      device->device_id = i;
+      device->device_name = infos[i].label.name;
+      device->stereo = 1;
+      device_list = g_list_append(device_list, device);
+
+      if (debug_mode) printf("Mixer device added to list: %d, %s, %d\n",
+                             device->device_id, device->device_name,
+                             device->stereo);
+      if (init_device_id == i) current_device = device;
+    }
+  }
+
+  if (device_list) {
+    mixer_enabled = TRUE;
+    if (!current_device)
+      current_device = device_list->data;
+    current_vol = mixer_get_vol(current_device);
+  } else {
+    mixer_enabled = FALSE;
+  }
+}
+
+static void mixer_set_vol(DeviceData *device, gint vol)
+{
+  int fd;
+  char *audioctl_device;
+  char *mixer_device;
+  audio_device_t adev;
+  audio_info_t ainfo;
+  mixer_ctrl_t *m;
+
+  audioctl_device = getenv("AUDIOCTLDEVICE");
+  if (audioctl_device == NULL)
+    audioctl_device = "/dev/audioctl0";
+
+  if ((fd = open(audioctl_device, O_RDONLY)) == -1) {
+    perror(audioctl_device);
+    mixer_enabled = FALSE;
+  }
+
+  if (ioctl(fd, AUDIO_GETDEV, &adev) == -1) {
+    perror(audioctl_device);
+    close(fd);
+    mixer_enabled = FALSE;
+  }
+
+  AUDIO_INITINFO(&ainfo);
+  /* from AUDIO_LEFT_BALANCE (0) to AUDIO_RIGHT_BALANCE (64) */
+  ainfo.play.balance = current_bal * AUDIO_RIGHT_BALANCE / 100;
+
+  if (ioctl(fd, AUDIO_SETINFO, &ainfo) == -1) {
+    perror("AUDIO_SETINFO");
+    close(fd);
+  }
+  close(fd);
+
+  mixer_device = getenv("MIXERDEVICE");
+  if (mixer_device == NULL)
+    mixer_device = "/dev/mixer0";
+
+  if ((fd = open(mixer_device, O_RDWR)) == -1) {
+    perror(mixer_device);
+    close(fd);
+  }
+
+  m = &values[device->device_id];
+  if (ioctl(fd, AUDIO_MIXER_WRITE, m) == -1) {
+    perror("AUDIO_MIXER_WRITE");
+    close(fd);
+  }
+  /* from AUDIO_MIN_GAIN (0) to AUDIO_MAX_GAIN (255) */
+  m->un.value.level[0] = m->un.value.level[1] = vol * AUDIO_MAX_GAIN / 100;
+
+  if (debug_mode) printf("volume set to %d (%d)\n", vol, current_bal);
+
+  close(fd);
+}
+
+static gint mixer_get_vol(DeviceData *device)
+{
+  int fd;
+  char *audioctl_device;
+  char *mixer_device;
+  audio_device_t adev;
+  audio_info_t ainfo;
+  mixer_ctrl_t *m;
+
+  audioctl_device = getenv("AUDIOCTLDEVICE");
+  if (audioctl_device == NULL)
+    audioctl_device = "/dev/audioctl0";
+
+  if ((fd = open(audioctl_device, O_RDONLY)) == -1) {
+    perror(audioctl_device);
+    mixer_enabled = FALSE;
+    return -1;
+  }
+
+  if (ioctl(fd, AUDIO_GETDEV, &adev) == -1) {
+    perror(audioctl_device);
+    close(fd);
+    mixer_enabled = FALSE;
+    return -1;
+  }
+
+  if (ioctl(fd, AUDIO_GETINFO, &ainfo) == -1) {
+    perror("AUDIO_GETINFO");
+    close(fd);
+    return -1;
+  }
+
+  if (ainfo.play.balance > AUDIO_RIGHT_BALANCE)
+    current_bal = 50;
+  else
+    current_bal = ainfo.play.balance * 100 / AUDIO_RIGHT_BALANCE;
+
+  close(fd);
+
+  mixer_device = getenv("MIXERDEVICE");
+  if (mixer_device == NULL)
+    mixer_device = "/dev/mixer0";
+
+  if ((fd = open(mixer_device, O_RDWR)) == -1) {
+    perror(mixer_device);
+    close(fd);
+    return -1;
+  }
+
+  m = &values[device->device_id];
+  if (ioctl(fd, AUDIO_MIXER_READ, m) == -1) {
+    perror("AUDIO_MIXER_READ");
+    close(fd);
+    return -1;
+  }
+  close(fd);
+
+  return m->un.value.level[0] * 100 / AUDIO_MAX_GAIN;
+}
+
 #elif defined(sun) && defined(__svr4__)
 static int device_ids[] = { AUDIO_SPEAKER,
 			    AUDIO_LINE_OUT,
@@ -444,7 +628,7 @@
 
 #endif
 
-#if defined(sun) && defined(__svr4__)
+#if defined(sun) && defined(__svr4__) || defined(__NetBSD__)
 /* from 0 through 100% */
 void set_volume(gint vol)
 {