annotate src/alsaplay.c @ 3347:316f3f347b4f

[xemacs-hg @ 2006-04-18 17:28:30 by james] Fix ALSA library version detection for older versions of the library. See xemacs-patches message <m3y7y2ssjq.fsf@jerrypc.cs.usu.edu>.
author james
date Tue, 18 Apr 2006 17:28:32 +0000
parents f63530aa6c68
children 16112448d484
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3308
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
1 /* Play sound with the ALSA library
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
2 Copyright (C) 2006 Jerry James.
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
3
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
4 This file is part of XEmacs.
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
5
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
6 XEmacs is free software; you can redistribute it and/or modify it
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
7 under the terms of the GNU General Public License as published by the
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
8 Free Software Foundation; either version 2, or (at your option) any
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
9 later version.
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
10
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
14 for more details.
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
15
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
17 along with XEmacs; see the file COPYING. If not, write to
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
19 Boston, MA 02111-1307, USA. */
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
20
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
21 /* Synched up with: Not in FSF. */
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
22
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
23 /* TODO: Support asynchronous sound playing; see the NAS support in sound.c */
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
24
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
25 #include <config.h>
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
26 #include "lisp.h"
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
27 #include "sound.h"
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
28 #include "sysfile.h"
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
29
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
30 /* We can't just include <alsa/asoundlib.h> because it tries to redefine
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
31 * several symbols defined by the previous header files.
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
32 */
3347
316f3f347b4f [xemacs-hg @ 2006-04-18 17:28:30 by james]
james
parents: 3335
diff changeset
33 #include <alsa/version.h>
3308
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
34 #include <alsa/input.h>
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
35 #include <alsa/output.h>
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
36 #include <alsa/conf.h>
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
37 #include <alsa/global.h>
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
38 #include <alsa/pcm.h>
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
39 #include <alsa/error.h>
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
40 #include <alsa/hwdep.h>
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
41 #include <alsa/rawmidi.h>
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
42 #include <alsa/control.h>
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
43 #include <alsa/mixer.h>
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
44
3335
f63530aa6c68 [xemacs-hg @ 2006-04-10 15:16:45 by james]
james
parents: 3308
diff changeset
45 #define ALSA_VERSION(major,minor,sub) (((major)<<16) | ((minor)<<8)| (sub))
f63530aa6c68 [xemacs-hg @ 2006-04-10 15:16:45 by james]
james
parents: 3308
diff changeset
46
3308
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
47 struct mixer_state
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
48 {
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
49 snd_mixer_t *mixer;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
50 snd_mixer_elem_t *vol_ctl;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
51
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
52 /* Which channels need the old volume restored */
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
53 int reset_front_left;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
54 int reset_front_center;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
55 int reset_front_right;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
56 int reset_rear_left;
3335
f63530aa6c68 [xemacs-hg @ 2006-04-10 15:16:45 by james]
james
parents: 3308
diff changeset
57 int reset_rear_right;
f63530aa6c68 [xemacs-hg @ 2006-04-10 15:16:45 by james]
james
parents: 3308
diff changeset
58 int reset_woofer;
f63530aa6c68 [xemacs-hg @ 2006-04-10 15:16:45 by james]
james
parents: 3308
diff changeset
59 #if SND_LIB_VERSION >= ALSA_VERSION (1, 0, 10)
3308
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
60 int reset_rear_center;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
61 int reset_side_left;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
62 int reset_side_right;
3335
f63530aa6c68 [xemacs-hg @ 2006-04-10 15:16:45 by james]
james
parents: 3308
diff changeset
63 #endif
3308
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
64
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
65 /* Old volumes for the channels */
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
66 long front_left_vol;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
67 long front_center_vol;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
68 long front_right_vol;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
69 long rear_left_vol;
3335
f63530aa6c68 [xemacs-hg @ 2006-04-10 15:16:45 by james]
james
parents: 3308
diff changeset
70 long rear_right_vol;
f63530aa6c68 [xemacs-hg @ 2006-04-10 15:16:45 by james]
james
parents: 3308
diff changeset
71 long woofer_vol;
f63530aa6c68 [xemacs-hg @ 2006-04-10 15:16:45 by james]
james
parents: 3308
diff changeset
72 #if SND_LIB_VERSION >= ALSA_VERSION (1, 0, 10)
3308
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
73 long rear_center_vol;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
74 long side_left_vol;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
75 long side_right_vol;
3335
f63530aa6c68 [xemacs-hg @ 2006-04-10 15:16:45 by james]
james
parents: 3308
diff changeset
76 #endif
3308
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
77 };
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
78
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
79 /* Assemble a machine half-word in little-endian order */
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
80 #define HALF_LE(arr,start) (arr[start] + (arr[start + 1] << 8))
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
81
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
82 /* Assemble a machine word in little-endian order */
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
83 #define WORD_LE(arr,start) (arr[start] + (arr[start + 1] << 8) + \
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
84 (arr[start + 2] << 16) + (arr[start + 3] << 24))
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
85
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
86 /* Assemble a machine word in big-endian order */
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
87 #define WORD_BE(arr,start) ((arr[start] << 24) + (arr[start + 1] << 16) + \
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
88 (arr[start + 2] << 8) + arr[start + 3])
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
89
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
90 /* This function was inspired by miscplay.c.
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
91 * Examine sound data to determine its format.
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
92 *
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
93 * TODO: Detect other formats that ALSA can play, such as GSM and MPEG.
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
94 */
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
95 static snd_pcm_format_t
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
96 analyze_format (const Binbyte *format, int *speed, int *tracks)
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
97 {
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
98 if (!memcmp (format, "Creative Voice File\x1A\x1A\x00", 22) &&
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
99 HALF_LE (format, 22) == ((0x1233 - HALF_LE (format, 24)) & 0xFFFF))
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
100 {
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
101 /* VOC */
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
102 *speed = 8000;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
103 *tracks = 2;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
104 return SND_PCM_FORMAT_U8;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
105 }
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
106 else if (!memcmp (format, "RIFF", 4) && !memcmp (format + 8, "WAVEfmt ", 8))
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
107 {
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
108 /* WAVE */
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
109 *speed = WORD_LE (format, 24);
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
110 *tracks = format[22];
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
111 return format[32] / format[22] == 1
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
112 ? SND_PCM_FORMAT_U8
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
113 : SND_PCM_FORMAT_S16_LE;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
114 }
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
115 else if (!memcmp (format, ".snd", 4))
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
116 {
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
117 /* Sun/NeXT Audio (big endian) */
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
118 if (WORD_BE (format, 4) < 24)
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
119 {
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
120 *speed = 8000;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
121 *tracks = 1;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
122 return SND_PCM_FORMAT_MU_LAW;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
123 }
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
124 *speed = WORD_BE (format, 16);
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
125 *tracks = format[23];
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
126 if (!memcmp (format + 12, "\000\000\000", 3))
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
127 {
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
128 switch (format[15])
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
129 {
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
130 case 1:
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
131 case 17:
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
132 case 29:
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
133 return SND_PCM_FORMAT_MU_LAW;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
134 case 2:
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
135 return SND_PCM_FORMAT_S8;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
136 case 3:
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
137 return SND_PCM_FORMAT_S16_BE;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
138 case 4:
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
139 return SND_PCM_FORMAT_S24_BE;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
140 case 5:
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
141 return SND_PCM_FORMAT_S32_BE;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
142 case 23:
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
143 case 24:
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
144 case 25:
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
145 case 26:
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
146 return SND_PCM_FORMAT_IMA_ADPCM;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
147 case 27:
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
148 return SND_PCM_FORMAT_A_LAW;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
149 default:
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
150 break;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
151 }
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
152 }
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
153 return SND_PCM_FORMAT_UNKNOWN;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
154 }
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
155 else if (!memcmp (format, ".sd", 4))
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
156 {
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
157 /* DEC Audio (little endian) */
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
158 if (WORD_LE (format, 4) < 24)
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
159 {
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
160 *speed = 8000;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
161 *tracks = 1;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
162 return SND_PCM_FORMAT_MU_LAW;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
163 }
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
164 *speed = WORD_LE (format, 16);
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
165 *tracks = format[20];
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
166 if (!memcmp (format + 13, "\000\000\000", 3))
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
167 {
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
168 switch (format[12])
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
169 {
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
170 case 1:
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
171 case 17:
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
172 case 29:
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
173 return SND_PCM_FORMAT_MU_LAW;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
174 case 2:
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
175 return SND_PCM_FORMAT_S8;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
176 case 3:
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
177 return SND_PCM_FORMAT_S16_LE;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
178 case 4:
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
179 return SND_PCM_FORMAT_S24_LE;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
180 case 5:
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
181 return SND_PCM_FORMAT_S32_LE;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
182 case 23:
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
183 case 24:
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
184 case 25:
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
185 case 26:
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
186 return SND_PCM_FORMAT_IMA_ADPCM;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
187 case 27:
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
188 return SND_PCM_FORMAT_A_LAW;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
189 default:
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
190 break;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
191 }
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
192 }
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
193 return SND_PCM_FORMAT_UNKNOWN;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
194 }
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
195 else
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
196 {
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
197 /* We don't know what it is. Guess that it is mono audio in unsigned
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
198 * byte format. Maybe we should error if we reach this point.
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
199 */
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
200 *speed = 8000;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
201 *tracks = 1;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
202 return SND_PCM_FORMAT_U8;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
203 }
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
204 }
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
205
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
206 /* Set the volume: if any errors occur, we accept the existing volume */
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
207 static void
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
208 set_volume (struct mixer_state *mix, int volume)
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
209 {
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
210 snd_mixer_selem_id_t *volume_id;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
211 long min_vol, max_vol, dev_vol;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
212
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
213 if (snd_mixer_open (&mix->mixer, 0) < 0)
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
214 return;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
215
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
216 if (snd_mixer_attach (mix->mixer, "default") < 0)
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
217 return;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
218
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
219 if (snd_mixer_selem_register (mix->mixer, NULL, NULL) < 0)
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
220 return;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
221
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
222 if (snd_mixer_load (mix->mixer) < 0)
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
223 return;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
224
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
225 snd_mixer_selem_id_alloca (&volume_id);
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
226 snd_mixer_selem_id_set_name (volume_id, "PCM");
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
227
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
228 if ((mix->vol_ctl = snd_mixer_find_selem (mix->mixer, volume_id)) == NULL)
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
229 {
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
230 snd_mixer_selem_id_set_name (volume_id, "Master");
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
231 if ((mix->vol_ctl = snd_mixer_find_selem (mix->mixer, volume_id))
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
232 == NULL)
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
233 return;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
234 }
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
235
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
236 /* Translate the Lisp volume range to the device volume range */
3335
f63530aa6c68 [xemacs-hg @ 2006-04-10 15:16:45 by james]
james
parents: 3308
diff changeset
237 #if SND_LIB_VERSION < ALSA_VERSION (1, 0, 10)
f63530aa6c68 [xemacs-hg @ 2006-04-10 15:16:45 by james]
james
parents: 3308
diff changeset
238 snd_mixer_selem_get_playback_volume_range (mix->vol_ctl, &min_vol, &max_vol);
f63530aa6c68 [xemacs-hg @ 2006-04-10 15:16:45 by james]
james
parents: 3308
diff changeset
239 #else
3308
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
240 if (snd_mixer_selem_get_playback_volume_range (mix->vol_ctl, &min_vol,
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
241 &max_vol) < 0)
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
242 return;
3335
f63530aa6c68 [xemacs-hg @ 2006-04-10 15:16:45 by james]
james
parents: 3308
diff changeset
243 #endif
3308
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
244
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
245 dev_vol = volume * (max_vol - min_vol) / 100 + min_vol;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
246
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
247 /* Record the old volumes */
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
248 if (snd_mixer_selem_get_playback_volume
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
249 (mix->vol_ctl, SND_MIXER_SCHN_FRONT_LEFT, &mix->front_left_vol) >= 0)
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
250 mix->reset_front_left = 1;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
251
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
252 if (snd_mixer_selem_get_playback_volume
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
253 (mix->vol_ctl, SND_MIXER_SCHN_FRONT_CENTER, &mix->front_center_vol) >= 0)
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
254 mix->reset_front_center = 1;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
255
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
256 if (snd_mixer_selem_get_playback_volume
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
257 (mix->vol_ctl, SND_MIXER_SCHN_FRONT_RIGHT, &mix->front_right_vol) >= 0)
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
258 mix->reset_front_right = 1;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
259
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
260 if (snd_mixer_selem_get_playback_volume
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
261 (mix->vol_ctl, SND_MIXER_SCHN_REAR_LEFT, &mix->rear_left_vol) >= 0)
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
262 mix->reset_rear_left = 1;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
263
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
264 if (snd_mixer_selem_get_playback_volume
3335
f63530aa6c68 [xemacs-hg @ 2006-04-10 15:16:45 by james]
james
parents: 3308
diff changeset
265 (mix->vol_ctl, SND_MIXER_SCHN_REAR_RIGHT, &mix->rear_right_vol) >= 0)
f63530aa6c68 [xemacs-hg @ 2006-04-10 15:16:45 by james]
james
parents: 3308
diff changeset
266 mix->reset_rear_right = 1;
f63530aa6c68 [xemacs-hg @ 2006-04-10 15:16:45 by james]
james
parents: 3308
diff changeset
267
f63530aa6c68 [xemacs-hg @ 2006-04-10 15:16:45 by james]
james
parents: 3308
diff changeset
268 if (snd_mixer_selem_get_playback_volume
f63530aa6c68 [xemacs-hg @ 2006-04-10 15:16:45 by james]
james
parents: 3308
diff changeset
269 (mix->vol_ctl, SND_MIXER_SCHN_WOOFER, &mix->woofer_vol) >= 0)
f63530aa6c68 [xemacs-hg @ 2006-04-10 15:16:45 by james]
james
parents: 3308
diff changeset
270 mix->reset_woofer = 1;
f63530aa6c68 [xemacs-hg @ 2006-04-10 15:16:45 by james]
james
parents: 3308
diff changeset
271
f63530aa6c68 [xemacs-hg @ 2006-04-10 15:16:45 by james]
james
parents: 3308
diff changeset
272 #if SND_LIB_VERSION >= ALSA_VERSION (1, 0, 10)
f63530aa6c68 [xemacs-hg @ 2006-04-10 15:16:45 by james]
james
parents: 3308
diff changeset
273 if (snd_mixer_selem_get_playback_volume
3308
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
274 (mix->vol_ctl, SND_MIXER_SCHN_REAR_CENTER, &mix->rear_center_vol) >= 0)
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
275 mix->reset_rear_center = 1;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
276
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
277 if (snd_mixer_selem_get_playback_volume
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
278 (mix->vol_ctl, SND_MIXER_SCHN_SIDE_LEFT, &mix->side_left_vol) >= 0)
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
279 mix->reset_side_left = 1;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
280
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
281 if (snd_mixer_selem_get_playback_volume
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
282 (mix->vol_ctl, SND_MIXER_SCHN_SIDE_RIGHT, &mix->side_right_vol) >= 0)
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
283 mix->reset_side_right = 1;
3335
f63530aa6c68 [xemacs-hg @ 2006-04-10 15:16:45 by james]
james
parents: 3308
diff changeset
284 #endif
3308
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
285
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
286 /* Set the volume */
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
287 snd_mixer_selem_set_playback_volume_all (mix->vol_ctl, dev_vol);
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
288 }
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
289
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
290 static void
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
291 reset_volume (const struct mixer_state *mix)
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
292 {
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
293 if (mix->reset_front_left)
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
294 snd_mixer_selem_set_playback_volume
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
295 (mix->vol_ctl, SND_MIXER_SCHN_FRONT_LEFT, mix->front_left_vol);
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
296
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
297 if (mix->reset_front_center)
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
298 snd_mixer_selem_set_playback_volume
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
299 (mix->vol_ctl, SND_MIXER_SCHN_FRONT_CENTER, mix->front_center_vol);
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
300
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
301 if (mix->reset_front_right)
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
302 snd_mixer_selem_set_playback_volume
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
303 (mix->vol_ctl, SND_MIXER_SCHN_FRONT_RIGHT, mix->front_right_vol);
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
304
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
305 if (mix->reset_rear_left)
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
306 snd_mixer_selem_set_playback_volume
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
307 (mix->vol_ctl, SND_MIXER_SCHN_REAR_LEFT, mix->rear_left_vol);
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
308
3335
f63530aa6c68 [xemacs-hg @ 2006-04-10 15:16:45 by james]
james
parents: 3308
diff changeset
309 if (mix->reset_rear_right)
f63530aa6c68 [xemacs-hg @ 2006-04-10 15:16:45 by james]
james
parents: 3308
diff changeset
310 snd_mixer_selem_set_playback_volume
f63530aa6c68 [xemacs-hg @ 2006-04-10 15:16:45 by james]
james
parents: 3308
diff changeset
311 (mix->vol_ctl, SND_MIXER_SCHN_REAR_RIGHT, mix->rear_right_vol);
f63530aa6c68 [xemacs-hg @ 2006-04-10 15:16:45 by james]
james
parents: 3308
diff changeset
312
f63530aa6c68 [xemacs-hg @ 2006-04-10 15:16:45 by james]
james
parents: 3308
diff changeset
313 if (mix->reset_woofer)
f63530aa6c68 [xemacs-hg @ 2006-04-10 15:16:45 by james]
james
parents: 3308
diff changeset
314 snd_mixer_selem_set_playback_volume
f63530aa6c68 [xemacs-hg @ 2006-04-10 15:16:45 by james]
james
parents: 3308
diff changeset
315 (mix->vol_ctl, SND_MIXER_SCHN_WOOFER, mix->woofer_vol);
f63530aa6c68 [xemacs-hg @ 2006-04-10 15:16:45 by james]
james
parents: 3308
diff changeset
316
f63530aa6c68 [xemacs-hg @ 2006-04-10 15:16:45 by james]
james
parents: 3308
diff changeset
317 #if SND_LIB_VERSION >= ALSA_VERSION (1, 0, 10)
3308
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
318 if (mix->reset_rear_center)
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
319 snd_mixer_selem_set_playback_volume
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
320 (mix->vol_ctl, SND_MIXER_SCHN_REAR_CENTER, mix->rear_center_vol);
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
321
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
322 if (mix->reset_side_left)
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
323 snd_mixer_selem_set_playback_volume
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
324 (mix->vol_ctl, SND_MIXER_SCHN_SIDE_LEFT, mix->side_left_vol);
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
325
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
326 if (mix->reset_side_right)
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
327 snd_mixer_selem_set_playback_volume
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
328 (mix->vol_ctl, SND_MIXER_SCHN_SIDE_RIGHT, mix->side_right_vol);
3335
f63530aa6c68 [xemacs-hg @ 2006-04-10 15:16:45 by james]
james
parents: 3308
diff changeset
329 #endif
3308
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
330
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
331 snd_mixer_close (mix->mixer);
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
332 }
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
333
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
334 int
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
335 alsa_play_sound_data (const Binbyte *data, int length, int volume)
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
336 {
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
337 snd_pcm_t *pcm_handle;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
338 snd_pcm_hw_params_t *hwparams;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
339 snd_pcm_format_t format;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
340 struct mixer_state mix;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
341 int speed, tracks, err;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
342
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
343 /* Set the PCM parameters */
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
344 if ((err = snd_pcm_open (&pcm_handle, "default", SND_PCM_STREAM_PLAYBACK,
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
345 0)) < 0)
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
346 goto error_pcm_open;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
347
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
348 snd_pcm_hw_params_alloca (&hwparams);
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
349
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
350 if ((err = snd_pcm_hw_params_any (pcm_handle, hwparams)) < 0)
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
351 goto error_pcm;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
352
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
353 format = analyze_format (data, &speed, &tracks);
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
354
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
355 if ((err = snd_pcm_hw_params_set_access (pcm_handle, hwparams,
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
356 SND_PCM_ACCESS_RW_INTERLEAVED)) < 0)
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
357 goto error_pcm;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
358
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
359 if ((err = snd_pcm_hw_params_set_format (pcm_handle, hwparams, format)) < 0)
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
360 goto error_pcm;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
361
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
362 if ((err = snd_pcm_hw_params_set_rate (pcm_handle, hwparams, speed, 0)) < 0)
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
363 goto error_pcm;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
364
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
365 if ((err = snd_pcm_hw_params_set_channels (pcm_handle, hwparams, tracks))
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
366 < 0)
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
367 goto error_pcm;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
368
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
369 if ((err = snd_pcm_hw_params (pcm_handle, hwparams)) < 0)
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
370 goto error_pcm;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
371
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
372 /* Set the volume */
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
373 memset (&mix, 0, sizeof (mix));
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
374 set_volume (&mix, volume);
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
375
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
376 /* Play the sound */
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
377 if ((err = snd_pcm_writei (pcm_handle, data, length)) < 0)
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
378 goto error_mixer;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
379
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
380 /* Put the volume back the way it used to be */
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
381 reset_volume (&mix);
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
382
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
383 /* Release resources */
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
384 snd_pcm_close (pcm_handle);
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
385 return 1;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
386
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
387 error_mixer:
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
388 reset_volume (&mix);
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
389 error_pcm:
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
390 snd_pcm_close (pcm_handle);
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
391 error_pcm_open:
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
392 sound_perror (snd_strerror (err));
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
393 return 0;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
394 }
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
395
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
396 /* Read the sound file into an internal buffer, then call
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
397 * alsa_play_sound_data.
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
398 */
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
399 int
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
400 alsa_play_sound_file (const Extbyte *sound_file, int volume)
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
401 {
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
402 Binbyte *data;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
403 int fd, retval;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
404 struct stat st;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
405
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
406 fd = retry_open (sound_file, O_RDONLY, 0);
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
407 if (fd < 0) {
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
408 sound_perror (sound_file);
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
409 return 0;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
410 }
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
411
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
412 qxe_fstat (fd, &st);
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
413 data = xnew_array (Binbyte, st.st_size);
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
414 retry_read (fd, data, st.st_size);
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
415 retry_close (fd);
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
416 retval = alsa_play_sound_data (data, st.st_size, volume);
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
417 xfree (data, Binbyte);
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
418 return retval;
34cfe24248f6 [xemacs-hg @ 2006-03-27 17:40:45 by james]
james
parents:
diff changeset
419 }