comparison src/sound.c @ 2179:64d8ef561763

[gaim-migrate @ 2189] Tom Dyas' patch for Arts ability in Gaim. committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Mon, 27 Aug 2001 22:39:17 +0000
parents 9b7cb09e2c06
children 94ee8eacb6f8
comparison
equal deleted inserted replaced
2178:a22f18ae43c1 2179:64d8ef561763
37 37
38 #ifdef ESD_SOUND 38 #ifdef ESD_SOUND
39 #include <esd.h> 39 #include <esd.h>
40 #endif 40 #endif
41 41
42 #ifdef ARTSC_SOUND
43 #include <artsc.h>
44 #endif
45
42 #ifdef NAS_SOUND 46 #ifdef NAS_SOUND
43 #include <audio/audiolib.h> 47 #include <audio/audiolib.h>
44 #endif 48 #endif
45 49
46 #include "gaim.h" 50 #include "gaim.h"
118 { 122 {
119 return check_dev("/dev/audio"); 123 return check_dev("/dev/audio");
120 } 124 }
121 125
122 126
123 #ifdef ESD_SOUND 127 #if defined(ESD_SOUND) || defined(ARTSC_SOUND)
128
124 /* 129 /*
125 ** This routine converts from ulaw to 16 bit linear. 130 ** This routine converts from ulaw to 16 bit linear.
126 ** 131 **
127 ** Craig Reese: IDA/Supercomputing Research Center 132 ** Craig Reese: IDA/Supercomputing Research Center
128 ** 29 September 1989 133 ** 29 September 1989
152 sample = -sample; 157 sample = -sample;
153 158
154 return (sample); 159 return (sample);
155 } 160 }
156 161
162 #endif
163
164 #ifdef ESD_SOUND
157 165
158 int esd_fd; 166 int esd_fd;
159 167
160 static int play_esd(unsigned char *data, int size) 168 static int play_esd(unsigned char *data, int size)
161 { 169 {
188 196
189 return 1; 197 return 1;
190 } 198 }
191 199
192 #endif 200 #endif
201
202 #ifdef ARTSC_SOUND
203
204 static int play_artsc(unsigned char *data, int size)
205 {
206 arts_stream_t stream;
207 guint16* lineardata;
208 int result = 1;
209 int error;
210 int i;
211
212 lineardata = g_malloc(size * 2);
213
214 for (i = 0; i < size; i++) {
215 lineardata[i] = _af_ulaw2linear(data[i]);
216 }
217
218 stream = arts_play_stream(8012, 16, 1, "gaim");
219
220 error = arts_write(stream, lineardata, size);
221 if (error < 0) {
222 result = 0;
223 }
224
225 arts_close_stream(stream);
226
227 g_free(lineardata);
228
229 arts_free();
230
231 return result;
232 }
233
234 static int can_play_artsc()
235 {
236 int error;
237
238 error = artsc_init();
239 if (error < 0)
240 return 0;
241
242 return 1;
243 }
244
245 static int play_artsc_file(char *file)
246 {
247 struct stat stat_buf;
248 unsigned char* buf = NULL;
249 int result = 0;
250 int fd = -1;
251
252 fd = open(file, O_RDONLY);
253 if (fd < 0)
254 goto out;
255
256 if (!can_play_artsc())
257 goto out;
258
259 if (fstat(fd, &stat_buf))
260 goto out;
261
262 if (!stat_buf.st_size)
263 goto out;
264
265 buf = g_malloc(stat_buf.st_size);
266 if (!buf)
267 goto out;
268
269 if (read(fd, buf, stat_buf.st_size) < 0)
270 goto out;
271
272 result = play_artsc(buf, stat_buf.st_size);
273
274 out:
275 if (buf) g_free(buf);
276 if (fd != -1) close(fd);
277 return result;
278 }
279
280 #endif /* ARTSC_SOUND */
193 281
194 #ifdef NAS_SOUND 282 #ifdef NAS_SOUND
195 283
196 char nas_server[] = "localhost"; 284 char nas_server[] = "localhost";
197 AuServer *nas_serv = NULL; 285 AuServer *nas_serv = NULL;
363 if (play_esd(data, size)) 451 if (play_esd(data, size))
364 _exit(0); 452 _exit(0);
365 } 453 }
366 #endif 454 #endif
367 455
456 #ifdef ARTSC_SOUND
457 /* ArtsC is the new second choice. */
458 if (can_play_artsc()) {
459 if (play_artsc(data, size))
460 _exit(0);
461 }
462 #endif
463
368 #ifdef NAS_SOUND 464 #ifdef NAS_SOUND
369 /* NAS is our second choice setup. */ 465 /* NAS is our second choice setup. */
370 if (can_play_nas()) { 466 if (can_play_nas()) {
371 if (play_nas(data, size)) 467 if (play_nas(data, size))
372 _exit(0); 468 _exit(0);