Mercurial > hg > xemacs-beta
comparison src/hpplay.c @ 0:376386a54a3c r19-14
Import from CVS: tag r19-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:45:50 +0200 |
parents | |
children | ac2d302a0011 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:376386a54a3c |
---|---|
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 | |
109 speaker = (char *) (string_data (XSYMBOL (Vhp_play_speaker)->name)); | |
110 | |
111 /* | |
112 * setup the playback parameters | |
113 */ | |
114 | |
115 /* speaker selection */ | |
116 if ( strcmp(speaker,"external") == 0 ) { | |
117 gainEntry.u.o.out_dst = AODTMonoJack; | |
118 } else { | |
119 gainEntry.u.o.out_dst = AODTMonoIntSpeaker; | |
120 } | |
121 | |
122 gainEntry.u.o.out_ch = AOCTMono; | |
123 gainEntry.gain = AUnityGain; | |
124 playParams.gain_matrix.type = AGMTOutput; /* gain matrix */ | |
125 playParams.gain_matrix.num_entries = 1; | |
126 playParams.gain_matrix.gain_entries = &gainEntry; | |
127 playParams.play_volume = play_gain; /* play volume */ | |
128 playParams.pause_first = False; /* don't pause */ | |
129 playParams.start_offset.type = ATTSamples; /* start offset 0 */ | |
130 playParams.start_offset.u.samples = 0; | |
131 playParams.duration.type = ATTFullLength; /* play entire sample */ | |
132 playParams.loop_count = 1; /* play sample just once */ | |
133 playParams.previous_transaction = 0; /* no linked transaction */ | |
134 playParams.event_mask = 0; /* don't solicit any events */ | |
135 | |
136 /* | |
137 * play the sound bucket | |
138 */ | |
139 xid = APlaySBucket( audio, pSBucket, &playParams, NULL ); | |
140 | |
141 /* | |
142 * set close mode to prevent playback from stopping | |
143 * when we close audio connection | |
144 */ | |
145 ASetCloseDownMode( audio, AKeepTransactions, &status ); | |
146 | |
147 /* | |
148 * That's all, folks! | |
149 * Always destroy bucket and close connection. | |
150 */ | |
151 ADestroySBucket( audio, pSBucket, &status ); | |
152 ACloseAudio( audio, &status ); | |
153 } | |
154 | |
155 void | |
156 play_sound_file (sound_file, volume) | |
157 char * sound_file; | |
158 int volume; | |
159 { | |
160 SBucket *pSBucket; | |
161 Audio *audio; | |
162 long status; | |
163 AErrorHandler prevHandler; /* pointer to previous handler */ | |
164 char *server; | |
165 | |
166 if (STRINGP(Vhp_play_server)) | |
167 server = (char *) (string_data (XSTRING (Vhp_play_server))); | |
168 server = ""; | |
169 | |
170 /* | |
171 * open audio connection | |
172 */ | |
173 audio = AOpenAudio( server, &status ); | |
174 if( status ) { | |
175 player_error_internal( audio, "Open audio failed", status ); | |
176 } | |
177 | |
178 /* replace default error handler */ | |
179 prevHandler = ASetErrorHandler(myHandler); | |
180 | |
181 /* | |
182 * Load the audio file into a sound bucket | |
183 */ | |
184 | |
185 pSBucket = ALoadAFile( audio, sound_file, AFFUnknown, 0, NULL, NULL ); | |
186 | |
187 /* | |
188 * Play the bucket | |
189 */ | |
190 | |
191 play_bucket_internal(audio, pSBucket, volume); | |
192 | |
193 ASetErrorHandler(prevHandler); | |
194 } | |
195 | |
196 | |
197 void | |
198 play_sound_data (data, length, volume) | |
199 unsigned char * data; | |
200 int length; | |
201 int volume; | |
202 { | |
203 SBucket *pSBucket; | |
204 Audio *audio; | |
205 AErrorHandler prevHandler; | |
206 SunHeader *header; | |
207 long status; | |
208 char *server; | |
209 | |
210 if (STRINGP (Vhp_play_server)) | |
211 server = (char *) (string_data (XSTRING (Vhp_play_server))); | |
212 server = ""; | |
213 | |
214 /* open audio connection */ | |
215 audio = AOpenAudio( server, &status ); | |
216 if( status ) { | |
217 player_error_internal( audio, "Open audio failed", status ); | |
218 } | |
219 | |
220 /* replace default error handler */ | |
221 prevHandler = ASetErrorHandler (myHandler); | |
222 | |
223 /* Create sound bucket */ | |
224 header = (SunHeader *) data; | |
225 | |
226 pSBucket = ACreateSBucket(audio, NULL, NULL, &status); | |
227 if (status) | |
228 player_error_internal( audio, "Bucket creation failed", status ); | |
229 | |
230 APutSBucketData(audio, pSBucket, 0, (char *) (data + header->header_size), header->data_length, &status); | |
231 | |
232 if (status) | |
233 player_error_internal( audio, "Audio data copy failed", status ); | |
234 | |
235 /* Play sound */ | |
236 play_bucket_internal(audio, pSBucket, volume); | |
237 | |
238 ASetErrorHandler(prevHandler); | |
239 if (status) | |
240 player_error_internal( audio, "Audio data copy failed", status ); | |
241 } | |
242 | |
243 void | |
244 vars_of_hpplay (void) | |
245 { | |
246 DEFVAR_LISP ("hp-play-server", &Vhp_play_server /* | |
247 A string, determining which server to play sound at. | |
248 Note that this is specific to the HP sound implementation, and you should | |
249 not make your functions depend on it. | |
250 */ ); | |
251 | |
252 Vhp_play_server = Qnil; | |
253 | |
254 DEFVAR_LISP ("hp-play-speaker", &Vhp_play_speaker /* | |
255 If this variable is the symbol `external', sound is played externally. | |
256 If the environment variable SPEAKER is set, that value is used for | |
257 initializing this variable. | |
258 Note that this is specific to the HP sound implementation, and you should | |
259 not make your functions depend on it. | |
260 */ ); | |
261 | |
262 Vhp_play_speaker = intern ("internal"); | |
263 | |
264 DEFVAR_INT("hp-play-gain", &play_gain /* | |
265 Global gain value for playing sounds. | |
266 Default value is AUnityGain which means keep level. | |
267 Please refer to the HP documentation, for instance in | |
268 `Using the Audio Application Program Interface', for details on how to | |
269 interpret this variable. | |
270 Note that this is specific to the HP sound implementation, and you should | |
271 not make your functions depend on it. | |
272 */ ); | |
273 | |
274 play_gain = AUnityGain; | |
275 } | |
276 | |
277 void | |
278 init_hpplay (void) | |
279 { | |
280 if (getenv ("SPEAKER")) | |
281 Vhp_play_speaker = intern (getenv ("SPEAKER")); | |
282 } |