Mercurial > hg > xemacs-beta
comparison src/alsaplay.c @ 3335:f63530aa6c68
[xemacs-hg @ 2006-04-10 15:16:45 by james]
Support pre-1.0.10 versions of the ALSA library. See xemacs-patches message
<m3y7ydsbzl.fsf@jerrypc.cs.usu.edu>.
author | james |
---|---|
date | Mon, 10 Apr 2006 15:16:47 +0000 |
parents | 34cfe24248f6 |
children | 316f3f347b4f |
comparison
equal
deleted
inserted
replaced
3334:25b44ff1faa1 | 3335:f63530aa6c68 |
---|---|
39 #include <alsa/hwdep.h> | 39 #include <alsa/hwdep.h> |
40 #include <alsa/rawmidi.h> | 40 #include <alsa/rawmidi.h> |
41 #include <alsa/control.h> | 41 #include <alsa/control.h> |
42 #include <alsa/mixer.h> | 42 #include <alsa/mixer.h> |
43 | 43 |
44 #define ALSA_VERSION(major,minor,sub) (((major)<<16) | ((minor)<<8)| (sub)) | |
45 | |
44 struct mixer_state | 46 struct mixer_state |
45 { | 47 { |
46 snd_mixer_t *mixer; | 48 snd_mixer_t *mixer; |
47 snd_mixer_elem_t *vol_ctl; | 49 snd_mixer_elem_t *vol_ctl; |
48 | 50 |
49 /* Which channels need the old volume restored */ | 51 /* Which channels need the old volume restored */ |
50 int reset_front_left; | 52 int reset_front_left; |
51 int reset_front_center; | 53 int reset_front_center; |
52 int reset_front_right; | 54 int reset_front_right; |
53 int reset_rear_left; | 55 int reset_rear_left; |
56 int reset_rear_right; | |
57 int reset_woofer; | |
58 #if SND_LIB_VERSION >= ALSA_VERSION (1, 0, 10) | |
54 int reset_rear_center; | 59 int reset_rear_center; |
55 int reset_rear_right; | |
56 int reset_side_left; | 60 int reset_side_left; |
57 int reset_side_right; | 61 int reset_side_right; |
58 int reset_woofer; | 62 #endif |
59 | 63 |
60 /* Old volumes for the channels */ | 64 /* Old volumes for the channels */ |
61 long front_left_vol; | 65 long front_left_vol; |
62 long front_center_vol; | 66 long front_center_vol; |
63 long front_right_vol; | 67 long front_right_vol; |
64 long rear_left_vol; | 68 long rear_left_vol; |
69 long rear_right_vol; | |
70 long woofer_vol; | |
71 #if SND_LIB_VERSION >= ALSA_VERSION (1, 0, 10) | |
65 long rear_center_vol; | 72 long rear_center_vol; |
66 long rear_right_vol; | |
67 long side_left_vol; | 73 long side_left_vol; |
68 long side_right_vol; | 74 long side_right_vol; |
69 long woofer_vol; | 75 #endif |
70 }; | 76 }; |
71 | 77 |
72 /* Assemble a machine half-word in little-endian order */ | 78 /* Assemble a machine half-word in little-endian order */ |
73 #define HALF_LE(arr,start) (arr[start] + (arr[start + 1] << 8)) | 79 #define HALF_LE(arr,start) (arr[start] + (arr[start + 1] << 8)) |
74 | 80 |
225 == NULL) | 231 == NULL) |
226 return; | 232 return; |
227 } | 233 } |
228 | 234 |
229 /* Translate the Lisp volume range to the device volume range */ | 235 /* Translate the Lisp volume range to the device volume range */ |
236 #if SND_LIB_VERSION < ALSA_VERSION (1, 0, 10) | |
237 snd_mixer_selem_get_playback_volume_range (mix->vol_ctl, &min_vol, &max_vol); | |
238 #else | |
230 if (snd_mixer_selem_get_playback_volume_range (mix->vol_ctl, &min_vol, | 239 if (snd_mixer_selem_get_playback_volume_range (mix->vol_ctl, &min_vol, |
231 &max_vol) < 0) | 240 &max_vol) < 0) |
232 return; | 241 return; |
242 #endif | |
233 | 243 |
234 dev_vol = volume * (max_vol - min_vol) / 100 + min_vol; | 244 dev_vol = volume * (max_vol - min_vol) / 100 + min_vol; |
235 | 245 |
236 /* Record the old volumes */ | 246 /* Record the old volumes */ |
237 if (snd_mixer_selem_get_playback_volume | 247 if (snd_mixer_selem_get_playback_volume |
249 if (snd_mixer_selem_get_playback_volume | 259 if (snd_mixer_selem_get_playback_volume |
250 (mix->vol_ctl, SND_MIXER_SCHN_REAR_LEFT, &mix->rear_left_vol) >= 0) | 260 (mix->vol_ctl, SND_MIXER_SCHN_REAR_LEFT, &mix->rear_left_vol) >= 0) |
251 mix->reset_rear_left = 1; | 261 mix->reset_rear_left = 1; |
252 | 262 |
253 if (snd_mixer_selem_get_playback_volume | 263 if (snd_mixer_selem_get_playback_volume |
264 (mix->vol_ctl, SND_MIXER_SCHN_REAR_RIGHT, &mix->rear_right_vol) >= 0) | |
265 mix->reset_rear_right = 1; | |
266 | |
267 if (snd_mixer_selem_get_playback_volume | |
268 (mix->vol_ctl, SND_MIXER_SCHN_WOOFER, &mix->woofer_vol) >= 0) | |
269 mix->reset_woofer = 1; | |
270 | |
271 #if SND_LIB_VERSION >= ALSA_VERSION (1, 0, 10) | |
272 if (snd_mixer_selem_get_playback_volume | |
254 (mix->vol_ctl, SND_MIXER_SCHN_REAR_CENTER, &mix->rear_center_vol) >= 0) | 273 (mix->vol_ctl, SND_MIXER_SCHN_REAR_CENTER, &mix->rear_center_vol) >= 0) |
255 mix->reset_rear_center = 1; | 274 mix->reset_rear_center = 1; |
256 | 275 |
257 if (snd_mixer_selem_get_playback_volume | 276 if (snd_mixer_selem_get_playback_volume |
258 (mix->vol_ctl, SND_MIXER_SCHN_REAR_RIGHT, &mix->rear_right_vol) >= 0) | |
259 mix->reset_rear_right = 1; | |
260 | |
261 if (snd_mixer_selem_get_playback_volume | |
262 (mix->vol_ctl, SND_MIXER_SCHN_SIDE_LEFT, &mix->side_left_vol) >= 0) | 277 (mix->vol_ctl, SND_MIXER_SCHN_SIDE_LEFT, &mix->side_left_vol) >= 0) |
263 mix->reset_side_left = 1; | 278 mix->reset_side_left = 1; |
264 | 279 |
265 if (snd_mixer_selem_get_playback_volume | 280 if (snd_mixer_selem_get_playback_volume |
266 (mix->vol_ctl, SND_MIXER_SCHN_SIDE_RIGHT, &mix->side_right_vol) >= 0) | 281 (mix->vol_ctl, SND_MIXER_SCHN_SIDE_RIGHT, &mix->side_right_vol) >= 0) |
267 mix->reset_side_right = 1; | 282 mix->reset_side_right = 1; |
268 | 283 #endif |
269 if (snd_mixer_selem_get_playback_volume | |
270 (mix->vol_ctl, SND_MIXER_SCHN_WOOFER, &mix->woofer_vol) >= 0) | |
271 mix->reset_woofer = 1; | |
272 | 284 |
273 /* Set the volume */ | 285 /* Set the volume */ |
274 snd_mixer_selem_set_playback_volume_all (mix->vol_ctl, dev_vol); | 286 snd_mixer_selem_set_playback_volume_all (mix->vol_ctl, dev_vol); |
275 } | 287 } |
276 | 288 |
291 | 303 |
292 if (mix->reset_rear_left) | 304 if (mix->reset_rear_left) |
293 snd_mixer_selem_set_playback_volume | 305 snd_mixer_selem_set_playback_volume |
294 (mix->vol_ctl, SND_MIXER_SCHN_REAR_LEFT, mix->rear_left_vol); | 306 (mix->vol_ctl, SND_MIXER_SCHN_REAR_LEFT, mix->rear_left_vol); |
295 | 307 |
308 if (mix->reset_rear_right) | |
309 snd_mixer_selem_set_playback_volume | |
310 (mix->vol_ctl, SND_MIXER_SCHN_REAR_RIGHT, mix->rear_right_vol); | |
311 | |
312 if (mix->reset_woofer) | |
313 snd_mixer_selem_set_playback_volume | |
314 (mix->vol_ctl, SND_MIXER_SCHN_WOOFER, mix->woofer_vol); | |
315 | |
316 #if SND_LIB_VERSION >= ALSA_VERSION (1, 0, 10) | |
296 if (mix->reset_rear_center) | 317 if (mix->reset_rear_center) |
297 snd_mixer_selem_set_playback_volume | 318 snd_mixer_selem_set_playback_volume |
298 (mix->vol_ctl, SND_MIXER_SCHN_REAR_CENTER, mix->rear_center_vol); | 319 (mix->vol_ctl, SND_MIXER_SCHN_REAR_CENTER, mix->rear_center_vol); |
299 | 320 |
300 if (mix->reset_rear_right) | |
301 snd_mixer_selem_set_playback_volume | |
302 (mix->vol_ctl, SND_MIXER_SCHN_REAR_RIGHT, mix->rear_right_vol); | |
303 | |
304 if (mix->reset_side_left) | 321 if (mix->reset_side_left) |
305 snd_mixer_selem_set_playback_volume | 322 snd_mixer_selem_set_playback_volume |
306 (mix->vol_ctl, SND_MIXER_SCHN_SIDE_LEFT, mix->side_left_vol); | 323 (mix->vol_ctl, SND_MIXER_SCHN_SIDE_LEFT, mix->side_left_vol); |
307 | 324 |
308 if (mix->reset_side_right) | 325 if (mix->reset_side_right) |
309 snd_mixer_selem_set_playback_volume | 326 snd_mixer_selem_set_playback_volume |
310 (mix->vol_ctl, SND_MIXER_SCHN_SIDE_RIGHT, mix->side_right_vol); | 327 (mix->vol_ctl, SND_MIXER_SCHN_SIDE_RIGHT, mix->side_right_vol); |
311 | 328 #endif |
312 if (mix->reset_woofer) | |
313 snd_mixer_selem_set_playback_volume | |
314 (mix->vol_ctl, SND_MIXER_SCHN_WOOFER, mix->woofer_vol); | |
315 | 329 |
316 snd_mixer_close (mix->mixer); | 330 snd_mixer_close (mix->mixer); |
317 } | 331 } |
318 | 332 |
319 int | 333 int |