summaryrefslogtreecommitdiff
path: root/audio/cmp3/patches/patch-ac
blob: 5f5c0ae0b99e9cd019d86b9c67360c732975fcc4 (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
$NetBSD: patch-ac,v 1.1.1.1 2001/02/10 14:18:35 hubertf Exp $

--- cmp3volume.c.orig	Fri Feb  9 15:54:18 2001
+++ cmp3volume.c	Fri Feb  9 23:45:24 2001
@@ -3,7 +3,11 @@
 */    
 
 #include "cmp3funcs.h"
-#include<sys/soundcard.h>
+#if defined(__NetBSD__)
+#include <sys/audioio.h>
+#else
+#include <sys/soundcard.h>
+#endif
 
 static int mixernum,                    /* ID number for the mixer */
            vol;                         /* Current volume level */
@@ -12,6 +16,63 @@
  *  Initialize volume control
  *  Returns: nothing
  ****************************************************************************/
+#if defined(__NetBSD__)
+
+int device_id;
+mixer_ctrl_t *m, *values;
+
+extern void initvol()
+{
+    int i, ndev;
+    char *mixer_device;
+    mixer_devinfo_t dinfo, *infos;
+
+    mixer_device = getenv("MIXERDEVICE");
+    if (mixer_device == NULL)
+        mixer_device = "/dev/mixer0";
+
+    if ((mixernum=open(mixer_device, O_RDWR)) < 0) {
+        fprintf(stderr, "open mixer device: %s", strerror(errno));
+        enditall(SIGSEGV);
+    }
+
+    for (ndev = 0; ; ndev++) {
+        dinfo.index = ndev;
+        if (ioctl(mixernum, AUDIO_MIXER_DEVINFO, &dinfo) < 0)
+            break;
+    }
+    infos = calloc(ndev, sizeof *infos);
+    values = calloc(ndev, sizeof *values);
+
+    for (i = 0; i < ndev; i++) {
+        infos[i].index = i;
+        ioctl(mixernum, AUDIO_MIXER_DEVINFO, &infos[i]);
+    }
+
+    for (i = 0; i < ndev; i++) {
+        if (infos[i].type == AUDIO_MIXER_VALUE) {
+            values[i].dev = i;
+            values[i].type = infos[i].type;
+        }
+        if (strcmp(infos[i].label.name, AudioNdac) == 0) {
+            device_id = i;
+            break;
+        }
+    }
+
+    values[device_id].un.value.num_channels = 2;
+
+    m = &values[device_id];
+    ioctl(mixernum, AUDIO_MIXER_READ, m);
+    vol = m->un.value.level[0] * 100 / AUDIO_MAX_GAIN;
+    mvprintw(3,COLS/2-1,"-");
+    mvprintw(LINES-7,COLS/2-1,"-");
+    mvprintw((LINES-8)-(vol*(LINES-12)/100),COLS/2-1,"*");
+    return;
+}
+
+#else
+
 extern void initvol()
 {
     if ((mixernum=open("/dev/mixer", O_RDWR)) < 0) {
@@ -26,6 +87,8 @@
     return;
 }
 
+#endif
+
 extern void endvol()
 {
     close(mixernum);
@@ -57,6 +120,23 @@
  *  Although I hate users in general, we should probably do it.
  *  Returns: nothing
  ****************************************************************************/
+#if defined(__NetBSD__)
+
+extern void volup()
+{
+    mvprintw((LINES-8)-(vol*(LINES-12)/100),COLS/2-1," ");
+    vol += 3;
+    if (vol > 100)
+        vol = 100;
+    m = &values[device_id];
+    ioctl(mixernum, AUDIO_MIXER_WRITE, m);
+    m->un.value.level[0] = m->un.value.level[1] = vol * AUDIO_MAX_GAIN / 100;
+    mvprintw((LINES-8)-(vol*(LINES-12)/100), COLS/2-1, "*");
+    return;
+}
+
+#else
+
 extern void volup()
 {
     int i;
@@ -71,10 +151,29 @@
     return;
 }
 
+#endif
+
 /****************************************************************************
  *  It's too loud junior, turn it down!
  *  Returns: nothing
  ****************************************************************************/
+#if defined(__NetBSD__)
+
+extern void voldown()
+{
+    mvprintw((LINES-8)-(vol*(LINES-12)/100),COLS/2-1," ");
+    vol -= 3;
+    if (vol < 0)
+        vol = 0;
+    m = &values[device_id];
+    ioctl(mixernum, AUDIO_MIXER_WRITE, m);
+    m->un.value.level[0] = m->un.value.level[1] = vol * AUDIO_MAX_GAIN / 100;
+    mvprintw((LINES-8)-(vol*(LINES-12)/100), COLS/2-1, "*");
+    return;
+}
+
+#else
+
 extern void voldown()
 {
     int i;
@@ -89,4 +188,6 @@
     return;
 }
 
+#endif
+
 /* EOF */
\ No newline at end of file