0
|
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
|
|
22
|
|
23 /***
|
|
24 NAME
|
|
25 hpplay
|
|
26 PURPOSE
|
|
27 Play .au sound files on hp9000s700
|
|
28 BUGS
|
|
29 I have been unable to figure out how to use the volume feature, so no
|
|
30 attempts has been made to honor the volume arg of play_sound_*
|
|
31 This means that all sounds is played at 100%.
|
|
32 The gain parameter can be set by using the play-gain variable.
|
|
33
|
|
34 NOTES
|
|
35 This file is mostly based on the player program found in the examples
|
|
36 directory of the audio software delivered on our machines. The path I
|
|
37 found it under was /usr/audio/examples/player.c
|
|
38 This file contained no credits and no copyrights. The original fileheader
|
|
39 is given below.
|
|
40 HISTORY
|
|
41 lynbech - Feb 10, 1993: Created.
|
|
42 ***/
|
|
43
|
|
44 /* ORIGINAL FILEHEADER:
|
|
45 * player - command-line audio file player
|
|
46 * Aug. 28 1991
|
|
47 * by three unknown, unsung audio programmers
|
|
48 * (well, only two are unsung)
|
|
49 */
|
|
50
|
|
51 #include <stdlib.h>
|
|
52 #include <stdio.h>
|
|
53 #include <config.h> /* to get system rev level. */
|
|
54 #ifdef HPUX10
|
|
55 #include <Alib.h>
|
|
56 #include <CUlib.h>
|
|
57 #else /* !HPUX 10 */
|
|
58 #include <audio/Alib.h>
|
|
59 #include <audio/CUlib.h>
|
|
60 #endif /* !HPUX 10 */
|
|
61
|
|
62 /* New Symbols */
|
|
63 #include <config.h>
|
|
64 #include "lisp.h"
|
|
65
|
|
66 Lisp_Object Vhp_play_server;
|
|
67 Lisp_Object Vhp_play_speaker;
|
|
68 int play_gain;
|
|
69
|
|
70 /* Functions */
|
|
71
|
|
72 /* error handling */
|
|
73 void player_error_internal(
|
|
74 Audio * audio,
|
|
75 char * text,
|
|
76 long errorCode
|
|
77 )
|
|
78 {
|
|
79 char errorbuff[132],buf[256];
|
|
80
|
|
81 AGetErrorText(audio, errorCode, errorbuff, 131);
|
|
82 sprintf(buf,"%s: %s\n",text,errorbuff);
|
|
83 error(buf);
|
|
84 }
|
|
85
|
|
86 long myHandler(audio, err_event)
|
|
87 Audio * audio;
|
|
88 AErrorEvent * err_event;
|
|
89 {
|
|
90 player_error_internal(audio, "Internal sound error", err_event->error_code);
|
|
91 return 1; /* Must return something, was orig. an exit */
|
|
92 }
|
|
93
|
|
94 /* Playing */
|
|
95 void
|
|
96 play_bucket_internal(audio, pSBucket, volume)
|
|
97 Audio *audio;
|
|
98 SBucket *pSBucket;
|
|
99 long volume;
|
|
100 {
|
|
101 SBPlayParams playParams;
|
|
102 AGainEntry gainEntry;
|
|
103 ATransID xid;
|
|
104 long status;
|
|
105 char * speaker;
|
|
106
|
|
107 playParams.priority = APriorityNormal; /* normal priority */
|
|
108
|
2
|
109 /*
|
|
110 * We can't signal an error, because all h*ll would break loose if
|
|
111 * we did.
|
|
112 */
|
|
113 if (SYMBOLP (Vhp_play_speaker))
|
|
114 {
|
|
115 speaker = (char *) (string_data (XSYMBOL (Vhp_play_speaker)->name));
|
0
|
116
|
2
|
117 /*
|
|
118 * setup the playback parameters
|
|
119 */
|
0
|
120
|
2
|
121 /* speaker selection */
|
|
122 if ( strcmp(speaker,"external") == 0 ) {
|
|
123 gainEntry.u.o.out_dst = AODTMonoJack;
|
|
124 } else {
|
|
125 gainEntry.u.o.out_dst = AODTMonoIntSpeaker;
|
|
126 }
|
|
127 }
|
|
128 else
|
|
129 {
|
|
130 /*
|
|
131 * Quietly revert to the internal speaker
|
|
132 */
|
|
133 gainEntry.u.o.out_dst = AODTMonoIntSpeaker;
|
0
|
134 }
|
|
135
|
|
136 gainEntry.u.o.out_ch = AOCTMono;
|
|
137 gainEntry.gain = AUnityGain;
|
|
138 playParams.gain_matrix.type = AGMTOutput; /* gain matrix */
|
|
139 playParams.gain_matrix.num_entries = 1;
|
|
140 playParams.gain_matrix.gain_entries = &gainEntry;
|
|
141 playParams.play_volume = play_gain; /* play volume */
|
|
142 playParams.pause_first = False; /* don't pause */
|
|
143 playParams.start_offset.type = ATTSamples; /* start offset 0 */
|
|
144 playParams.start_offset.u.samples = 0;
|
|
145 playParams.duration.type = ATTFullLength; /* play entire sample */
|
|
146 playParams.loop_count = 1; /* play sample just once */
|
|
147 playParams.previous_transaction = 0; /* no linked transaction */
|
|
148 playParams.event_mask = 0; /* don't solicit any events */
|
|
149
|
|
150 /*
|
|
151 * play the sound bucket
|
|
152 */
|
|
153 xid = APlaySBucket( audio, pSBucket, &playParams, NULL );
|
|
154
|
|
155 /*
|
|
156 * set close mode to prevent playback from stopping
|
|
157 * when we close audio connection
|
|
158 */
|
|
159 ASetCloseDownMode( audio, AKeepTransactions, &status );
|
|
160
|
|
161 /*
|
|
162 * That's all, folks!
|
|
163 * Always destroy bucket and close connection.
|
|
164 */
|
|
165 ADestroySBucket( audio, pSBucket, &status );
|
|
166 ACloseAudio( audio, &status );
|
|
167 }
|
|
168
|
|
169 void
|
|
170 play_sound_file (sound_file, volume)
|
|
171 char * sound_file;
|
|
172 int volume;
|
|
173 {
|
|
174 SBucket *pSBucket;
|
|
175 Audio *audio;
|
|
176 long status;
|
|
177 AErrorHandler prevHandler; /* pointer to previous handler */
|
|
178 char *server;
|
|
179
|
|
180 if (STRINGP(Vhp_play_server))
|
|
181 server = (char *) (string_data (XSTRING (Vhp_play_server)));
|
|
182 server = "";
|
|
183
|
|
184 /*
|
|
185 * open audio connection
|
|
186 */
|
|
187 audio = AOpenAudio( server, &status );
|
|
188 if( status ) {
|
|
189 player_error_internal( audio, "Open audio failed", status );
|
|
190 }
|
|
191
|
|
192 /* replace default error handler */
|
|
193 prevHandler = ASetErrorHandler(myHandler);
|
|
194
|
|
195 /*
|
|
196 * Load the audio file into a sound bucket
|
|
197 */
|
|
198
|
|
199 pSBucket = ALoadAFile( audio, sound_file, AFFUnknown, 0, NULL, NULL );
|
|
200
|
|
201 /*
|
|
202 * Play the bucket
|
|
203 */
|
|
204
|
|
205 play_bucket_internal(audio, pSBucket, volume);
|
|
206
|
|
207 ASetErrorHandler(prevHandler);
|
|
208 }
|
|
209
|
|
210
|
|
211 void
|
|
212 play_sound_data (data, length, volume)
|
|
213 unsigned char * data;
|
|
214 int length;
|
|
215 int volume;
|
|
216 {
|
|
217 SBucket *pSBucket;
|
|
218 Audio *audio;
|
|
219 AErrorHandler prevHandler;
|
|
220 SunHeader *header;
|
|
221 long status;
|
|
222 char *server;
|
|
223
|
|
224 if (STRINGP (Vhp_play_server))
|
|
225 server = (char *) (string_data (XSTRING (Vhp_play_server)));
|
|
226 server = "";
|
|
227
|
|
228 /* open audio connection */
|
|
229 audio = AOpenAudio( server, &status );
|
|
230 if( status ) {
|
|
231 player_error_internal( audio, "Open audio failed", status );
|
|
232 }
|
|
233
|
|
234 /* replace default error handler */
|
|
235 prevHandler = ASetErrorHandler (myHandler);
|
|
236
|
|
237 /* Create sound bucket */
|
|
238 header = (SunHeader *) data;
|
|
239
|
|
240 pSBucket = ACreateSBucket(audio, NULL, NULL, &status);
|
|
241 if (status)
|
|
242 player_error_internal( audio, "Bucket creation failed", status );
|
|
243
|
|
244 APutSBucketData(audio, pSBucket, 0, (char *) (data + header->header_size), header->data_length, &status);
|
|
245
|
|
246 if (status)
|
|
247 player_error_internal( audio, "Audio data copy failed", status );
|
|
248
|
|
249 /* Play sound */
|
|
250 play_bucket_internal(audio, pSBucket, volume);
|
|
251
|
|
252 ASetErrorHandler(prevHandler);
|
|
253 if (status)
|
|
254 player_error_internal( audio, "Audio data copy failed", status );
|
|
255 }
|
|
256
|
|
257 void
|
|
258 vars_of_hpplay (void)
|
|
259 {
|
|
260 DEFVAR_LISP ("hp-play-server", &Vhp_play_server /*
|
|
261 A string, determining which server to play sound at.
|
|
262 Note that this is specific to the HP sound implementation, and you should
|
|
263 not make your functions depend on it.
|
|
264 */ );
|
|
265
|
|
266 Vhp_play_server = Qnil;
|
|
267
|
|
268 DEFVAR_LISP ("hp-play-speaker", &Vhp_play_speaker /*
|
|
269 If this variable is the symbol `external', sound is played externally.
|
|
270 If the environment variable SPEAKER is set, that value is used for
|
|
271 initializing 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 Vhp_play_speaker = intern ("internal");
|
|
277
|
|
278 DEFVAR_INT("hp-play-gain", &play_gain /*
|
|
279 Global gain value for playing sounds.
|
|
280 Default value is AUnityGain which means keep level.
|
|
281 Please refer to the HP documentation, for instance in
|
|
282 `Using the Audio Application Program Interface', for details on how to
|
|
283 interpret this variable.
|
|
284 Note that this is specific to the HP sound implementation, and you should
|
|
285 not make your functions depend on it.
|
|
286 */ );
|
|
287
|
|
288 play_gain = AUnityGain;
|
|
289 }
|
|
290
|
|
291 void
|
|
292 init_hpplay (void)
|
|
293 {
|
|
294 if (getenv ("SPEAKER"))
|
|
295 Vhp_play_speaker = intern (getenv ("SPEAKER"));
|
|
296 }
|