1 /* Copyright (C) 1993 Free Software Foundation, Inc.
3 This file is part of XEmacs.
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
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
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. */
20 /* Synched up with: Not in FSF. */
27 Play .au sound files on hp9000s700
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 are played at 100%.
32 The gain parameter can be set by using the hp-play-gain variable.
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
41 lynbech - Feb 10, 1993: Created.
44 /* ORIGINAL FILEHEADER:
45 * player - command-line audio file player
47 * by three unknown, unsung audio programmers
48 * (well, only two are unsung)
60 #include <audio/Alib.h>
61 #include <audio/CUlib.h>
64 Lisp_Object Vhp_play_server;
65 Lisp_Object Vhp_play_speaker;
71 void player_error_internal(
77 char errorbuff[132],buf[256];
79 AGetErrorText(audio, errorCode, errorbuff, 131);
80 sprintf(buf,"%s: %s\n",text,errorbuff);
84 long myHandler(audio, err_event)
86 AErrorEvent * err_event;
88 player_error_internal(audio, "Internal sound error", err_event->error_code);
89 return 1; /* Must return something, was orig. an exit */
94 play_bucket_internal(audio, pSBucket, volume)
99 SBPlayParams playParams;
100 AGainEntry gainEntry;
105 playParams.priority = APriorityNormal; /* normal priority */
108 * We can't signal an error, because all h*ll would break loose if
111 if (SYMBOLP (Vhp_play_speaker))
113 speaker = (char *) (string_data (XSYMBOL (Vhp_play_speaker)->name));
116 * setup the playback parameters
119 /* speaker selection */
120 if ( strcmp(speaker,"external") == 0 ) {
121 gainEntry.u.o.out_dst = AODTMonoJack;
123 gainEntry.u.o.out_dst = AODTMonoIntSpeaker;
129 * Quietly revert to the internal speaker
131 gainEntry.u.o.out_dst = AODTMonoIntSpeaker;
134 gainEntry.u.o.out_ch = AOCTMono;
135 gainEntry.gain = AUnityGain;
136 playParams.gain_matrix.type = AGMTOutput; /* gain matrix */
137 playParams.gain_matrix.num_entries = 1;
138 playParams.gain_matrix.gain_entries = &gainEntry;
139 playParams.play_volume = hp_play_gain; /* play volume */
140 playParams.pause_first = False; /* don't pause */
141 playParams.start_offset.type = ATTSamples; /* start offset 0 */
142 playParams.start_offset.u.samples = 0;
143 playParams.duration.type = ATTFullLength; /* play entire sample */
144 playParams.loop_count = 1; /* play sample just once */
145 playParams.previous_transaction = 0; /* no linked transaction */
146 playParams.event_mask = 0; /* don't solicit any events */
149 * play the sound bucket
151 xid = APlaySBucket( audio, pSBucket, &playParams, NULL );
154 * set close mode to prevent playback from stopping
155 * when we close audio connection
157 ASetCloseDownMode( audio, AKeepTransactions, &status );
161 * Always destroy bucket and close connection.
163 ADestroySBucket( audio, pSBucket, &status );
164 ACloseAudio( audio, &status );
168 play_sound_file (sound_file, volume)
175 AErrorHandler prevHandler; /* pointer to previous handler */
178 if (STRINGP(Vhp_play_server))
179 server = (char *) XSTRING_DATA (Vhp_play_server);
183 * open audio connection
185 audio = AOpenAudio( server, &status );
187 player_error_internal( audio, "Open audio failed", status );
190 /* replace default error handler */
191 prevHandler = ASetErrorHandler(myHandler);
194 * Load the audio file into a sound bucket
197 pSBucket = ALoadAFile( audio, sound_file, AFFUnknown, 0, NULL, NULL );
203 play_bucket_internal(audio, pSBucket, volume);
205 ASetErrorHandler(prevHandler);
210 play_sound_data (data, length, volume)
211 unsigned char * data;
217 AErrorHandler prevHandler;
222 if (STRINGP (Vhp_play_server))
223 server = (char *) XSTRING_DATA (Vhp_play_server);
226 /* open audio connection */
227 audio = AOpenAudio( server, &status );
229 player_error_internal( audio, "Open audio failed", status );
232 /* replace default error handler */
233 prevHandler = ASetErrorHandler (myHandler);
235 /* Create sound bucket */
236 header = (SunHeader *) data;
238 pSBucket = ACreateSBucket(audio, NULL, NULL, &status);
240 player_error_internal( audio, "Bucket creation failed", status );
242 APutSBucketData(audio, pSBucket, 0, (char *) (data + header->header_size), header->data_length, &status);
245 player_error_internal( audio, "Audio data copy failed", status );
248 play_bucket_internal(audio, pSBucket, volume);
250 ASetErrorHandler(prevHandler);
252 player_error_internal( audio, "Audio data copy failed", status );
256 vars_of_hpplay (void)
258 DEFVAR_LISP ("hp-play-server", &Vhp_play_server /*
259 A string, determining which server to play sound at.
260 Note that this is specific to the HP sound implementation, and you should
261 not make your functions depend on it.
264 Vhp_play_server = Qnil;
266 DEFVAR_LISP ("hp-play-speaker", &Vhp_play_speaker /*
267 If this variable is the symbol `external', sound is played externally.
268 If the environment variable SPEAKER is set, that value is used for
269 initializing this variable.
270 Note that this is specific to the HP sound implementation, and you should
271 not make your functions depend on it.
274 Vhp_play_speaker = intern ("internal");
276 DEFVAR_INT("hp-play-gain", &hp_play_gain /*
277 Global gain value for playing sounds.
278 Default value is AUnityGain which means keep level.
279 Please refer to the HP documentation, for instance in
280 `Using the Audio Application Program Interface', for details on how to
281 interpret this variable.
282 Note that this is specific to the HP sound implementation, and you should
283 not make your functions depend on it.
286 hp_play_gain = AUnityGain;
292 if (getenv ("SPEAKER"))
293 Vhp_play_speaker = intern (getenv ("SPEAKER"));