Release 980809
[wine] / multimedia / mmaux.c
1 /*
2  * Sample AUXILARY Wine Driver
3  *
4  * Copyright 1994 Martin Ayotte
5  */
6
7 #define EMULATE_SB16
8
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <fcntl.h>
12 #include <sys/ioctl.h>
13 #include "windows.h"
14 #include "user.h"
15 #include "driver.h"
16 #include "mmsystem.h"
17 #include "debug.h"
18
19 #ifdef HAVE_SYS_SOUNDCARD_H
20 # include <sys/soundcard.h>
21 #endif
22 #ifdef HAVE_MACHINE_SOUNDCARD_H
23 # include <machine/soundcard.h>
24 #endif
25
26 #define MIXER_DEV "/dev/mixer"
27
28 #ifdef SOUND_VERSION
29 #define IOCTL(a,b,c)            ioctl(a,b,&c)
30 #else
31 #define IOCTL(a,b,c)            (c = ioctl(a,b,c) )
32 #endif
33
34
35 static int      NumDev = 6;
36
37 /*-----------------------------------------------------------------------*/
38
39
40 /**************************************************************************
41  *                              AUX_GetDevCaps                  [internal]
42  */
43 static DWORD AUX_GetDevCaps(WORD wDevID, LPAUXCAPS16 lpCaps, DWORD dwSize)
44 {
45 #ifdef HAVE_OSS
46         int     mixer,volume;
47
48         TRACE(mmaux,"(%04X, %p, %lu);\n", wDevID, lpCaps, dwSize);
49         if (lpCaps == NULL) return MMSYSERR_NOTENABLED;
50         if ((mixer = open(MIXER_DEV, O_RDWR)) < 0) {
51                 WARN(mmaux, "mixer device not available !\n");
52                 return MMSYSERR_NOTENABLED;
53         }
54         if (ioctl(mixer, SOUND_MIXER_READ_LINE, &volume) == -1) {
55                 close(mixer);
56                 WARN(mmaux, "unable read mixer !\n");
57                 return MMSYSERR_NOTENABLED;
58         }
59         close(mixer);
60 #ifdef EMULATE_SB16
61         lpCaps->wMid = 0x0002;
62         lpCaps->vDriverVersion = 0x0200;
63         lpCaps->dwSupport = AUXCAPS_VOLUME | AUXCAPS_LRVOLUME;
64         switch (wDevID) {
65                 case 0:
66                         lpCaps->wPid = 0x0196;
67                         strcpy(lpCaps->szPname, "SB16 Aux: Wave");
68                         lpCaps->wTechnology = AUXCAPS_AUXIN;
69                         break;
70                 case 1:
71                         lpCaps->wPid = 0x0197;
72                         strcpy(lpCaps->szPname, "SB16 Aux: Midi Synth");
73                         lpCaps->wTechnology = AUXCAPS_AUXIN;
74                         break;
75                 case 2:
76                         lpCaps->wPid = 0x0191;
77                         strcpy(lpCaps->szPname, "SB16 Aux: CD");
78                         lpCaps->wTechnology = AUXCAPS_CDAUDIO;
79                         break;
80                 case 3:
81                         lpCaps->wPid = 0x0192;
82                         strcpy(lpCaps->szPname, "SB16 Aux: Line-In");
83                         lpCaps->wTechnology = AUXCAPS_AUXIN;
84                         break;
85                 case 4:
86                         lpCaps->wPid = 0x0193;
87                         strcpy(lpCaps->szPname, "SB16 Aux: Mic");
88                         lpCaps->wTechnology = AUXCAPS_AUXIN;
89                         break;
90                 case 5:
91                         lpCaps->wPid = 0x0194;
92                         strcpy(lpCaps->szPname, "SB16 Aux: Master");
93                         lpCaps->wTechnology = AUXCAPS_AUXIN;
94                         break;
95                 }
96 #else
97         lpCaps->wMid = 0xAA;
98         lpCaps->wPid = 0x55;
99         lpCaps->vDriverVersion = 0x0100;
100         strcpy(lpCaps->szPname, "Generic Linux Auxiliary Driver");
101         lpCaps->wTechnology = AUXCAPS_CDAUDIO;
102         lpCaps->dwSupport = AUXCAPS_VOLUME | AUXCAPS_LRVOLUME;
103 #endif
104         return MMSYSERR_NOERROR;
105 #else
106         return MMSYSERR_NOTENABLED;
107 #endif
108 }
109
110
111 /**************************************************************************
112  *                              AUX_GetVolume                   [internal]
113  */
114 static DWORD AUX_GetVolume(WORD wDevID, LPDWORD lpdwVol)
115 {
116 #ifdef HAVE_OSS
117         int     mixer,volume,left,right,cmd;
118
119         TRACE(mmaux,"(%04X, %p);\n", wDevID, lpdwVol);
120         if (lpdwVol == NULL) return MMSYSERR_NOTENABLED;
121         if ((mixer = open(MIXER_DEV, O_RDWR)) < 0) {
122                 WARN(mmaux, "mixer device not available !\n");
123                 return MMSYSERR_NOTENABLED;
124         }
125         switch(wDevID) {
126                 case 0:
127                         TRACE(mmaux,"SOUND_MIXER_READ_PCM !\n");
128                         cmd = SOUND_MIXER_READ_PCM;
129                         break;
130                 case 1:
131                         TRACE(mmaux,"SOUND_MIXER_READ_SYNTH !\n");
132                         cmd = SOUND_MIXER_READ_SYNTH;
133                         break;
134                 case 2:
135                         TRACE(mmaux,"SOUND_MIXER_READ_CD !\n");
136                         cmd = SOUND_MIXER_READ_CD;
137                         break;
138                 case 3:
139                         TRACE(mmaux,"SOUND_MIXER_READ_LINE !\n");
140                         cmd = SOUND_MIXER_READ_LINE;
141                         break;
142                 case 4:
143                         TRACE(mmaux,"SOUND_MIXER_READ_MIC !\n");
144                         cmd = SOUND_MIXER_READ_MIC;
145                         break;
146                 case 5:
147                         TRACE(mmaux,"SOUND_MIXER_READ_VOLUME !\n");
148                         cmd = SOUND_MIXER_READ_VOLUME;
149                         break;
150                 default:
151                         WARN(mmaux, "invalid device id=%04X !\n", wDevID);
152                         return MMSYSERR_NOTENABLED;
153                 }
154         if (ioctl(mixer, cmd, &volume) == -1) {
155                 WARN(mmaux, "unable read mixer !\n");
156                 return MMSYSERR_NOTENABLED;
157         }
158         close(mixer);
159         left = volume & 0x7F;
160         right = (volume >> 8) & 0x7F;
161         TRACE(mmaux,"left=%d right=%d !\n", left, right);
162         *lpdwVol = MAKELONG(left << 9, right << 9);
163         return MMSYSERR_NOERROR;
164 #else
165         return MMSYSERR_NOTENABLED;
166 #endif
167 }
168
169 /**************************************************************************
170  *                              AUX_SetVolume                   [internal]
171  */
172 static DWORD AUX_SetVolume(WORD wDevID, DWORD dwParam)
173 {
174 #ifdef HAVE_OSS
175         int     mixer;
176         int             volume;
177         int             cmd;
178         TRACE(mmaux,"(%04X, %08lX);\n", wDevID, dwParam);
179         volume = (LOWORD(dwParam) >> 9 & 0x7F) + 
180                 ((HIWORD(dwParam) >> 9  & 0x7F) << 8);
181         if ((mixer = open(MIXER_DEV, O_RDWR)) < 0) {
182                 WARN(mmaux, "mixer device not available !\n");
183                 return MMSYSERR_NOTENABLED;
184                 }
185         switch(wDevID) {
186                 case 0:
187                         TRACE(mmaux,"SOUND_MIXER_WRITE_PCM !\n");
188                         cmd = SOUND_MIXER_WRITE_PCM;
189                         break;
190                 case 1:
191                         TRACE(mmaux,"SOUND_MIXER_WRITE_SYNTH !\n");
192                         cmd = SOUND_MIXER_WRITE_SYNTH;
193                         break;
194                 case 2:
195                         TRACE(mmaux,"SOUND_MIXER_WRITE_CD !\n");
196                         cmd = SOUND_MIXER_WRITE_CD;
197                         break;
198                 case 3:
199                         TRACE(mmaux,"SOUND_MIXER_WRITE_LINE !\n");
200                         cmd = SOUND_MIXER_WRITE_LINE;
201                         break;
202                 case 4:
203                         TRACE(mmaux,"SOUND_MIXER_WRITE_MIC !\n");
204                         cmd = SOUND_MIXER_WRITE_MIC;
205                         break;
206                 case 5:
207                         TRACE(mmaux,"SOUND_MIXER_WRITE_VOLUME !\n");
208                         cmd = SOUND_MIXER_WRITE_VOLUME;
209                         break;
210                 default:
211                         WARN(mmaux,"invalid device id=%04X !\n", wDevID);
212                         return MMSYSERR_NOTENABLED;
213                 }
214     if (ioctl(mixer, cmd, &volume) == -1) {
215                 WARN(mmaux, "unable set mixer !\n");
216                 return MMSYSERR_NOTENABLED;
217                 }
218         close(mixer);
219         return MMSYSERR_NOERROR;
220 #else
221         return MMSYSERR_NOTENABLED;
222 #endif
223 }
224
225
226 /**************************************************************************
227  *                              auxMessage                      [sample driver]
228  */
229 DWORD WINAPI auxMessage(WORD wDevID, WORD wMsg, DWORD dwUser, 
230                                         DWORD dwParam1, DWORD dwParam2)
231 {
232         TRACE(mmaux,"(%04X, %04X, %08lX, %08lX, %08lX);\n", 
233                         wDevID, wMsg, dwUser, dwParam1, dwParam2);
234         switch(wMsg) {
235         case AUXDM_GETDEVCAPS:
236                 return AUX_GetDevCaps(wDevID,(LPAUXCAPS16)dwParam1,dwParam2);
237         case AUXDM_GETNUMDEVS:
238                 TRACE(mmaux,"return %d;\n", NumDev);
239                 return NumDev;
240         case AUXDM_GETVOLUME:
241                 return AUX_GetVolume(wDevID,(LPDWORD)dwParam1);
242         case AUXDM_SETVOLUME:
243                 return AUX_SetVolume(wDevID,dwParam1);
244         default:
245                 WARN(mmaux, "unknown message !\n");
246         }
247         return MMSYSERR_NOTSUPPORTED;
248 }