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