summaryrefslogtreecommitdiff
path: root/audio/gqmpeg/patches/patch-ab
blob: 9e40a5e6803038d3efe3baab042f72357e40b19d (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
$NetBSD: patch-ab,v 1.9 1999/06/29 00:58:30 hubertf Exp $

--- mixer.c.orig	Wed Jun  2 05:50:45 1999
+++ mixer.c	Sun Jun 20 00:44:06 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,166 @@
 	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_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);
+
+      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");
+      }
+
+      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;
+    }
+  }
+
+  close(fd);
+
+  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 *mixer_device;
+  mixer_ctrl_t *m;
+
+  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);
+  }
+
+  close(fd);
+
+  if (m->un.value.num_channels == 2) {
+    /* input and output seem to only have one channel?? */
+    if (device->device_id == 13 || device->device_id == 14) {
+      m->un.value.level[0] = vol * AUDIO_MAX_GAIN / 100;
+    } else if (current_bal < 50) {
+      m->un.value.level[0] = vol * AUDIO_MAX_GAIN / 100;
+      m->un.value.level[1] = m->un.value.level[0] * current_bal / 50;
+    } else if (current_bal > 50) {
+      m->un.value.level[1] = vol * AUDIO_MAX_GAIN / 100;
+      m->un.value.level[0] = m->un.value.level[1] * (100 - current_bal) / 50;
+    } else {
+      m->un.value.level[0] = m->un.value.level[1] = vol * AUDIO_MAX_GAIN / 100;
+    }
+  } else {
+    m->un.value.level[0] = vol * AUDIO_MAX_GAIN / 100;
+  }
+  /* from AUDIO_MIN_GAIN (0) to AUDIO_MAX_GAIN (255) */
+
+  if (debug_mode) printf("volume set to %d (%d)\n", vol, current_bal);
+}
+
+static gint mixer_get_vol(DeviceData *device)
+{
+  int fd;
+  char *mixer_device;
+  mixer_ctrl_t *m;
+
+  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);
+
+  if (m->un.value.num_channels == 2) {
+    if (m->un.value.level[0] > m->un.value.level[1]) {
+      current_bal = m->un.value.level[1] * 50 / m->un.value.level[0];
+      return m->un.value.level[0] * 100 / AUDIO_MAX_GAIN;
+    } else if (m->un.value.level[0] < m->un.value.level[1]) {
+      current_bal = 100 - (m->un.value.level[0] * 50 / m->un.value.level[1]);
+      return m->un.value.level[1] * 100 / AUDIO_MAX_GAIN;
+    } else {
+      current_bal = 50;
+      return m->un.value.level[0] * 100 / AUDIO_MAX_GAIN;
+    }
+  } else {
+    current_bal = 50;
+    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 +595,7 @@
 
 #endif
 
-#if defined(sun) && defined(__svr4__)
+#if defined(sun) && defined(__svr4__) || defined(__NetBSD__)
 /* from 0 through 100% */
 void set_volume(gint vol)
 {