1 /* Copyright (C) 1993 Free Software Foundation, Inc.
3 This file is part of SXEmacs
5 SXEmacs is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 SXEmacs is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 /* Synched up with: Not in FSF. */
25 Play .au sound files on hp9000s700
27 I have been unable to figure out how to use the volume feature, so no
28 attempt has been made to honor the volume arg of play_sound_*
29 This means that all sounds are played at 100%.
30 The gain parameter can be set by using the hp-play-gain variable.
33 This file is mostly based on the player program found in the examples
34 directory of the audio software delivered on our machines. The path I
35 found it under was /usr/audio/examples/player.c
36 This file contained no credits and no copyrights. The original fileheader
39 lynbech - Feb 10, 1993: Created.
42 /* ORIGINAL FILEHEADER:
43 * player - command-line audio file player
45 * by three unknown, unsung audio programmers
46 * (well, only two are unsung)
52 #include "nativesound.h"
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(Audio * audio, char *text, long errorCode)
73 char errorbuff[132], buf[256];
76 AGetErrorText(audio, errorCode, errorbuff, 131);
77 sz = sprintf(buf, sizeof(buf), "%s: %s\n", text, errorbuff);
78 assert(sz>=0 && sz<sizeof(buf));
82 long myHandler(audio, err_event)
84 AErrorEvent *err_event;
86 player_error_internal(audio, "Internal sound error",
87 err_event->error_code);
88 return 1; /* Must return something, was orig. an exit */
92 void play_bucket_internal(audio, pSBucket, volume)
97 SBPlayParams playParams;
103 playParams.priority = APriorityNormal; /* normal priority */
106 * We can't signal an error, because all h*ll would break loose if
109 if (SYMBOLP(Vhp_play_speaker)) {
111 (char *)(string_data(XSYMBOL(Vhp_play_speaker)->name));
114 * setup the playback parameters
117 /* speaker selection */
118 if (strcmp(speaker, "external") == 0) {
119 gainEntry.u.o.out_dst = AODTMonoJack;
121 gainEntry.u.o.out_dst = AODTMonoIntSpeaker;
125 * Quietly revert to the internal speaker
127 gainEntry.u.o.out_dst = AODTMonoIntSpeaker;
130 gainEntry.u.o.out_ch = AOCTMono;
131 gainEntry.gain = AUnityGain;
132 playParams.gain_matrix.type = AGMTOutput; /* gain matrix */
133 playParams.gain_matrix.num_entries = 1;
134 playParams.gain_matrix.gain_entries = &gainEntry;
135 playParams.play_volume = hp_play_gain; /* play volume */
136 playParams.pause_first = False; /* don't pause */
137 playParams.start_offset.type = ATTSamples; /* start offset 0 */
138 playParams.start_offset.u.samples = 0;
139 playParams.duration.type = ATTFullLength; /* play entire sample */
140 playParams.loop_count = 1; /* play sample just once */
141 playParams.previous_transaction = 0; /* no linked transaction */
142 playParams.event_mask = 0; /* don't solicit any events */
145 * play the sound bucket
147 xid = APlaySBucket(audio, pSBucket, &playParams, NULL);
150 * set close mode to prevent playback from stopping
151 * when we close audio connection
153 ASetCloseDownMode(audio, AKeepTransactions, &status);
157 * Always destroy bucket and close connection.
159 ADestroySBucket(audio, pSBucket, &status);
160 ACloseAudio(audio, &status);
163 void play_sound_file(sound_file, volume)
170 AErrorHandler prevHandler; /* pointer to previous handler */
173 if (STRINGP(Vhp_play_server))
174 server = (char *)XSTRING_DATA(Vhp_play_server);
178 * open audio connection
180 audio = AOpenAudio(server, &status);
182 player_error_internal(audio, "Open audio failed", status);
185 /* replace default error handler */
186 prevHandler = ASetErrorHandler(myHandler);
189 * Load the audio file into a sound bucket
192 pSBucket = ALoadAFile(audio, sound_file, AFFUnknown, 0, NULL, NULL);
198 play_bucket_internal(audio, pSBucket, volume);
200 ASetErrorHandler(prevHandler);
203 int play_sound_data(data, length, volume)
210 AErrorHandler prevHandler;
216 /* #### Finish this to return an error code.
217 This function signal a lisp error. How consistent with the rest.
218 What if this function is needed in doing the beep for the error?
220 Apparently the author of this didn't read the comment in
224 if (STRINGP(Vhp_play_server))
225 server = (char *)XSTRING_DATA(Vhp_play_server);
228 /* open audio connection */
229 audio = AOpenAudio(server, &status);
231 player_error_internal(audio, "Open audio failed", status);
234 /* replace default error handler */
235 prevHandler = ASetErrorHandler(myHandler);
237 /* Create sound bucket */
238 header = (SunHeader *) data;
240 pSBucket = ACreateSBucket(audio, NULL, NULL, &status);
242 player_error_internal(audio, "Bucket creation failed", status);
244 APutSBucketData(audio, pSBucket, 0,
245 (char *)(data + header->header_size),
246 header->data_length, &status);
249 player_error_internal(audio, "Audio data copy failed", status);
252 play_bucket_internal(audio, pSBucket, volume);
254 ASetErrorHandler(prevHandler);
256 player_error_internal(audio, "Audio data copy failed", status);
261 void vars_of_hpplay(void)
263 DEFVAR_LISP("hp-play-server", &Vhp_play_server /*
264 A string, determining which server to play sound at.
265 Note that this is specific to the HP sound implementation, and you should
266 not make your functions depend on it.
269 Vhp_play_server = Qnil;
271 DEFVAR_LISP("hp-play-speaker", &Vhp_play_speaker /*
272 If this variable is the symbol `external', sound is played externally.
273 If the environment variable SPEAKER is set, that value is used for
274 initializing this variable.
275 Note that this is specific to the HP sound implementation, and you should
276 not make your functions depend on it.
279 Vhp_play_speaker = intern("internal");
281 DEFVAR_INT("hp-play-gain", &hp_play_gain /*
282 Global gain value for playing sounds.
283 Default value is AUnityGain which means keep level.
284 Please refer to the HP documentation, for instance in
285 `Using the Audio Application Program Interface', for details on how to
286 interpret this variable.
287 Note that this is specific to the HP sound implementation, and you should
288 not make your functions depend on it.
291 hp_play_gain = AUnityGain;
294 void init_hpplay(void)
296 if (getenv("SPEAKER"))
297 Vhp_play_speaker = intern(getenv("SPEAKER"));