428
|
1 /* Copyright (C) 1993 Free Software Foundation, Inc.
|
|
2
|
|
3 This file is part of XEmacs.
|
|
4
|
|
5 XEmacs is free software; you can redistribute it and/or modify it
|
|
6 under the terms of the GNU General Public License as published by the
|
|
7 Free Software Foundation; either version 2, or (at your option) any
|
|
8 later version.
|
|
9
|
|
10 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
13 for more details.
|
|
14
|
|
15 You should have received a copy of the GNU General Public License
|
|
16 along with XEmacs; see the file COPYING. If not, write to
|
|
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
18 Boston, MA 02111-1307, USA. */
|
|
19
|
|
20 /* Synched up with: Not in FSF. */
|
|
21
|
563
|
22 /* This file Mule-ized by Ben Wing, 5-15-01. */
|
|
23
|
428
|
24
|
|
25 /***
|
|
26 NAME
|
|
27 hpplay
|
|
28 PURPOSE
|
|
29 Play .au sound files on hp9000s700
|
|
30 BUGS
|
|
31 I have been unable to figure out how to use the volume feature, so no
|
444
|
32 attempt has been made to honor the volume arg of play_sound_*
|
428
|
33 This means that all sounds are played at 100%.
|
|
34 The gain parameter can be set by using the hp-play-gain variable.
|
|
35
|
|
36 NOTES
|
|
37 This file is mostly based on the player program found in the examples
|
|
38 directory of the audio software delivered on our machines. The path I
|
|
39 found it under was /usr/audio/examples/player.c
|
|
40 This file contained no credits and no copyrights. The original fileheader
|
|
41 is given below.
|
|
42 HISTORY
|
|
43 lynbech - Feb 10, 1993: Created.
|
|
44 ***/
|
|
45
|
|
46 /* ORIGINAL FILEHEADER:
|
|
47 * player - command-line audio file player
|
|
48 * Aug. 28 1991
|
|
49 * by three unknown, unsung audio programmers
|
|
50 * (well, only two are unsung)
|
|
51 */
|
|
52
|
|
53 #include <config.h>
|
|
54 #include "lisp.h"
|
|
55
|
563
|
56 #include "sound.h"
|
442
|
57
|
428
|
58 #ifdef HPUX10
|
|
59 #include <Alib.h>
|
|
60 #include <CUlib.h>
|
|
61 #else /* !HPUX 10 */
|
|
62 #include <audio/Alib.h>
|
|
63 #include <audio/CUlib.h>
|
|
64 #endif /* !HPUX 10 */
|
|
65
|
442
|
66
|
428
|
67 Lisp_Object Vhp_play_server;
|
|
68 Lisp_Object Vhp_play_speaker;
|
458
|
69 Fixnum hp_play_gain;
|
428
|
70
|
|
71 /* Functions */
|
|
72
|
|
73 /* error handling */
|
563
|
74 void
|
|
75 player_error_internal (Audio * audio, Char_ASCII * text, long errorCode)
|
428
|
76 {
|
563
|
77 Extbyte errorbuff[132];
|
665
|
78 Intbyte *interr;
|
428
|
79
|
563
|
80 AGetErrorText (audio, errorCode, errorbuff, 131);
|
|
81 EXTERNAL_TO_C_STRING (errorbuf, interr, Qnative);
|
|
82
|
|
83 signal_error (Qsound_error, text, build_string (interr));
|
428
|
84 }
|
|
85
|
563
|
86 long
|
|
87 myHandler( Audio * audio, AErrorEvent * err_event)
|
428
|
88 {
|
|
89 player_error_internal(audio, "Internal sound error", err_event->error_code);
|
|
90 return 1; /* Must return something, was orig. an exit */
|
|
91 }
|
|
92
|
|
93 /* Playing */
|
|
94 void
|
563
|
95 play_bucket_internal( Audio *audio, SBucket *pSBucket, long volume)
|
428
|
96 {
|
563
|
97 SBPlayParams playParams;
|
|
98 AGainEntry gainEntry;
|
|
99 ATransID xid;
|
|
100 long status;
|
|
101
|
|
102 playParams.priority = APriorityNormal; /* normal priority */
|
428
|
103
|
563
|
104 /*
|
|
105 * We can't signal an error, because all h*ll would break loose if
|
|
106 * we did.
|
|
107 */
|
|
108 if (EQ (Vhp_play_speaker, Qexternal))
|
|
109 gainEntry.u.o.out_dst = AODTMonoJack;
|
|
110 else
|
|
111 gainEntry.u.o.out_dst = AODTMonoIntSpeaker;
|
428
|
112
|
563
|
113 gainEntry.u.o.out_ch = AOCTMono;
|
|
114 gainEntry.gain = AUnityGain;
|
|
115 playParams.gain_matrix.type = AGMTOutput; /* gain matrix */
|
|
116 playParams.gain_matrix.num_entries = 1;
|
|
117 playParams.gain_matrix.gain_entries = &gainEntry;
|
|
118 playParams.play_volume = hp_play_gain; /* play volume */
|
|
119 playParams.pause_first = False; /* don't pause */
|
|
120 playParams.start_offset.type = ATTSamples; /* start offset 0 */
|
|
121 playParams.start_offset.u.samples = 0;
|
|
122 playParams.duration.type = ATTFullLength; /* play entire sample */
|
|
123 playParams.loop_count = 1; /* play sample just once */
|
|
124 playParams.previous_transaction = 0; /* no linked transaction */
|
|
125 playParams.event_mask = 0; /* don't solicit any events */
|
428
|
126
|
563
|
127 /*
|
|
128 * play the sound bucket
|
|
129 */
|
|
130 xid = APlaySBucket( audio, pSBucket, &playParams, NULL );
|
428
|
131
|
563
|
132 /*
|
|
133 * set close mode to prevent playback from stopping
|
|
134 * when we close audio connection
|
|
135 */
|
|
136 ASetCloseDownMode( audio, AKeepTransactions, &status );
|
428
|
137
|
563
|
138 /*
|
|
139 * That's all, folks!
|
|
140 * Always destroy bucket and close connection.
|
|
141 */
|
|
142 ADestroySBucket( audio, pSBucket, &status );
|
|
143 ACloseAudio( audio, &status );
|
428
|
144 }
|
|
145
|
|
146 void
|
563
|
147 play_sound_file (Extbyte * sound_file, int volume)
|
428
|
148 {
|
563
|
149 sbucket *pSBucket;
|
|
150 Audio *audio;
|
|
151 long status;
|
|
152 AErrorHandler prevHandler; /* pointer to previous handler */
|
|
153 Extbyte *server;
|
428
|
154
|
563
|
155 if (STRINGP (Vhp_play_server))
|
|
156 LISP_STRING_TO_EXTERNAL (Vhp_play_server, server, Qnative);
|
|
157 else
|
428
|
158 server = "";
|
|
159
|
563
|
160 /*
|
|
161 * open audio connection
|
|
162 */
|
|
163 audio = AOpenAudio( server, &status );
|
|
164 if( status )
|
|
165 {
|
|
166 player_error_internal( audio, "Open audio failed", status );
|
428
|
167 }
|
|
168
|
563
|
169 /* replace default error handler */
|
|
170 prevHandler = ASetErrorHandler(myHandler);
|
428
|
171
|
563
|
172 /*
|
|
173 * Load the audio file into a sound bucket
|
|
174 */
|
428
|
175
|
563
|
176 pSBucket = ALoadAFile( audio, sound_file, AFFUnknown, 0, NULL, NULL );
|
428
|
177
|
563
|
178 /*
|
|
179 * Play the bucket
|
|
180 */
|
428
|
181
|
563
|
182 play_bucket_internal(audio, pSBucket, volume);
|
428
|
183
|
563
|
184 ASetErrorHandler(prevHandler);
|
428
|
185 }
|
|
186
|
|
187
|
442
|
188 int
|
563
|
189 play_sound_data (UChar_Binary * data, int length, int volume)
|
428
|
190 {
|
563
|
191 SBucket *pSBucket;
|
|
192 Audio *audio;
|
|
193 AErrorHandler prevHandler;
|
|
194 SunHeader *header;
|
|
195 long status;
|
|
196 Extbyte *server;
|
|
197 int result;
|
428
|
198
|
563
|
199 /* #### Finish this to return an error code.
|
|
200 This function signal a lisp error. How consistent with the rest.
|
|
201 What if this function is needed in doing the beep for the error?
|
442
|
202
|
563
|
203 Apparently the author of this didn't read the comment in
|
|
204 Fplay_sound.
|
|
205 */
|
442
|
206
|
|
207
|
563
|
208 if (STRINGP (Vhp_play_server))
|
|
209 LISP_STRING_TO_EXTERNAL (Vhp_play_server, server, Qnative);
|
|
210 else
|
428
|
211 server = "";
|
|
212
|
563
|
213 /* open audio connection */
|
|
214 audio = AOpenAudio( server, &status );
|
|
215 if(status)
|
|
216 {
|
|
217 player_error_internal( audio, "Open audio failed", status );
|
428
|
218 }
|
|
219
|
563
|
220 /* replace default error handler */
|
|
221 prevHandler = ASetErrorHandler (myHandler);
|
428
|
222
|
563
|
223 /* Create sound bucket */
|
|
224 header = (SunHeader *) data;
|
428
|
225
|
563
|
226 pSBucket = ACreateSBucket(audio, NULL, NULL, &status);
|
|
227 if (status)
|
|
228 player_error_internal( audio, "Bucket creation failed", status );
|
428
|
229
|
563
|
230 APutSBucketData(audio, pSBucket, 0, (Char_Binary *) (data + header->header_size), header->data_length, &status);
|
428
|
231
|
563
|
232 if (status)
|
|
233 player_error_internal( audio, "Audio data copy failed", status );
|
428
|
234
|
563
|
235 /* Play sound */
|
|
236 play_bucket_internal(audio, pSBucket, volume);
|
428
|
237
|
563
|
238 ASetErrorHandler(prevHandler);
|
|
239 if (status)
|
|
240 player_error_internal( audio, "Audio data copy failed", status );
|
442
|
241
|
563
|
242 return 1;
|
428
|
243 }
|
|
244
|
|
245 void
|
|
246 vars_of_hpplay (void)
|
|
247 {
|
|
248 DEFVAR_LISP ("hp-play-server", &Vhp_play_server /*
|
|
249 A string, determining which server to play sound at.
|
|
250 Note that this is specific to the HP sound implementation, and you should
|
|
251 not make your functions depend on it.
|
|
252 */ );
|
|
253
|
|
254 Vhp_play_server = Qnil;
|
|
255
|
|
256 DEFVAR_LISP ("hp-play-speaker", &Vhp_play_speaker /*
|
|
257 If this variable is the symbol `external', sound is played externally.
|
|
258 If the environment variable SPEAKER is set, that value is used for
|
|
259 initializing this variable.
|
|
260 Note that this is specific to the HP sound implementation, and you should
|
|
261 not make your functions depend on it.
|
|
262 */ );
|
|
263
|
|
264 Vhp_play_speaker = intern ("internal");
|
|
265
|
563
|
266 DEFVAR_INT ("hp-play-gain", &hp_play_gain /*
|
428
|
267 Global gain value for playing sounds.
|
|
268 Default value is AUnityGain which means keep level.
|
|
269 Please refer to the HP documentation, for instance in
|
|
270 `Using the Audio Application Program Interface', for details on how to
|
|
271 interpret this variable.
|
|
272 Note that this is specific to the HP sound implementation, and you should
|
|
273 not make your functions depend on it.
|
|
274 */ );
|
|
275
|
|
276 hp_play_gain = AUnityGain;
|
|
277 }
|
|
278
|
|
279 void
|
|
280 init_hpplay (void)
|
|
281 {
|
771
|
282 if (egetenv ("SPEAKER"))
|
|
283 Vhp_play_speaker = intern (egetenv ("SPEAKER"));
|
428
|
284 }
|