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