Mercurial > hg > xemacs-beta
comparison src/sgiplay.c @ 394:7d59cb494b73 r21-2-12
Import from CVS: tag r21-2-12
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:11:37 +0200 |
parents | cc15677e0335 |
children | 74fd4e045ea6 |
comparison
equal
deleted
inserted
replaced
393:2e030b8965b1 | 394:7d59cb494b73 |
---|---|
22 /* Synched up with: Not in FSF. */ | 22 /* Synched up with: Not in FSF. */ |
23 | 23 |
24 #include <config.h> | 24 #include <config.h> |
25 #include "lisp.h" | 25 #include "lisp.h" |
26 | 26 |
27 #include <audio.h> | 27 #include <string.h> |
28 #include <sys/file.h> | 28 #include <sys/file.h> |
29 #include <sys/types.h> | 29 #include <sys/types.h> |
30 #include <sys/stat.h> | 30 #include <sys/stat.h> |
31 #include <fcntl.h> | 31 #include <fcntl.h> |
32 #include <string.h> | 32 #include <unistd.h> |
33 #include <audio.h> | |
33 #include <netinet/in.h> /* for ntohl() etc. */ | 34 #include <netinet/in.h> /* for ntohl() etc. */ |
34 | 35 |
35 /* Configuration options */ | 36 /* Configuration options */ |
36 | 37 |
37 /* ability to parse Sun/NeXT (.au or .snd) audio file headers. The | 38 /* ability to parse Sun/NeXT (.au or .snd) audio file headers. The |
199 /* are we looking at an NeXT/Sun audio header? */ | 200 /* are we looking at an NeXT/Sun audio header? */ |
200 #define LOOKING_AT_SND_HEADER_P(address) \ | 201 #define LOOKING_AT_SND_HEADER_P(address) \ |
201 (!strncmp(".snd", (char *)(address), 4)) | 202 (!strncmp(".snd", (char *)(address), 4)) |
202 | 203 |
203 static Lisp_Object | 204 static Lisp_Object |
204 close_sound_file (closure) | 205 close_sound_file (Lisp_Object closure) |
205 Lisp_Object closure; | |
206 { | 206 { |
207 close (XINT (closure)); | 207 close (XINT (closure)); |
208 return Qnil; | 208 return Qnil; |
209 } | 209 } |
210 | 210 |
211 void | 211 void |
212 play_sound_file (sound_file, volume) | 212 play_sound_file (char *sound_file, int volume) |
213 char * sound_file; | |
214 int volume; | |
215 { | 213 { |
216 int count = specpdl_depth (); | 214 int count = specpdl_depth (); |
217 int input_fd; | 215 int input_fd; |
218 unsigned char buffer[CHUNKSIZE]; | 216 unsigned char buffer[CHUNKSIZE]; |
219 int bytes_read; | 217 int bytes_read; |
253 AL_LEFT_SPEAKER_GAIN, 0, | 251 AL_LEFT_SPEAKER_GAIN, 0, |
254 AL_RIGHT_SPEAKER_GAIN, 0, | 252 AL_RIGHT_SPEAKER_GAIN, 0, |
255 }; | 253 }; |
256 | 254 |
257 static Lisp_Object | 255 static Lisp_Object |
258 restore_audio_port (closure) | 256 restore_audio_port (Lisp_Object closure) |
259 Lisp_Object closure; | |
260 { | 257 { |
261 Lisp_Object * contents = XVECTOR_DATA (closure); | 258 Lisp_Object * contents = XVECTOR_DATA (closure); |
262 saved_device_state[1] = XINT (contents[0]); | 259 saved_device_state[1] = XINT (contents[0]); |
263 saved_device_state[3] = XINT (contents[1]); | 260 saved_device_state[3] = XINT (contents[1]); |
264 saved_device_state[5] = XINT (contents[2]); | 261 saved_device_state[5] = XINT (contents[2]); |
265 ALsetparams (AL_DEFAULT_DEVICE, saved_device_state, 6); | 262 ALsetparams (AL_DEFAULT_DEVICE, saved_device_state, 6); |
266 return Qnil; | 263 return Qnil; |
267 } | 264 } |
268 | 265 |
269 void | 266 void |
270 play_sound_data (data, length, volume) | 267 play_sound_data (unsigned char *data, int length, int volume) |
271 unsigned char * data; | |
272 int length; | |
273 int volume; | |
274 { | 268 { |
275 int count = specpdl_depth (); | 269 int count = specpdl_depth (); |
276 AudioContext ac; | 270 AudioContext ac; |
277 | 271 |
278 ac = audio_initialize (data, length, volume); | 272 ac = audio_initialize (data, length, volume); |
282 drain_audio_port (ac); | 276 drain_audio_port (ac); |
283 unbind_to (count, Qnil); | 277 unbind_to (count, Qnil); |
284 } | 278 } |
285 | 279 |
286 static AudioContext | 280 static AudioContext |
287 audio_initialize (data, length, volume) | 281 audio_initialize (unsigned char *data, int length, int volume) |
288 unsigned char * data; | |
289 int length; | |
290 int volume; | |
291 { | 282 { |
292 Lisp_Object audio_port_state[3]; | 283 Lisp_Object audio_port_state[3]; |
293 static AudioContextRec desc; | 284 static AudioContextRec desc; |
294 AudioContext ac; | 285 AudioContext ac; |
295 | 286 |
329 desc = * ac; | 320 desc = * ac; |
330 return ac; | 321 return ac; |
331 } | 322 } |
332 | 323 |
333 static void | 324 static void |
334 play_internal (data, length, ac) | 325 play_internal (unsigned char *data, int length, AudioContext ac) |
335 unsigned char * data; | |
336 int length; | |
337 AudioContext ac; | |
338 { | 326 { |
339 unsigned char * limit; | 327 unsigned char * limit; |
340 if (ac == (AudioContext) 0) | 328 if (ac == (AudioContext) 0) |
341 return; | 329 return; |
342 | 330 |
355 data = chunklimit; | 343 data = chunklimit; |
356 } | 344 } |
357 } | 345 } |
358 | 346 |
359 static void | 347 static void |
360 drain_audio_port (ac) | 348 drain_audio_port (AudioContext ac) |
361 AudioContext ac; | |
362 { | 349 { |
363 while (ALgetfilled (ac->ac_port) > 0) | 350 while (ALgetfilled (ac->ac_port) > 0) |
364 sginap(1); | 351 sginap(1); |
365 } | 352 } |
366 | 353 |
372 | 359 |
373 #if USE_MULAW_DECODE_TABLE | 360 #if USE_MULAW_DECODE_TABLE |
374 #include "libst.h" | 361 #include "libst.h" |
375 #else /* not USE_MULAW_DECODE_TABLE */ | 362 #else /* not USE_MULAW_DECODE_TABLE */ |
376 static int | 363 static int |
377 st_ulaw_to_linear (u) | 364 st_ulaw_to_linear (int u) |
378 int u; | |
379 { | 365 { |
380 static CONST short table[] = {0,132,396,924,1980,4092,8316,16764}; | 366 static CONST short table[] = {0,132,396,924,1980,4092,8316,16764}; |
381 int u1 = ~u; | 367 int u1 = ~u; |
382 short exponent = (u1 >> 4) & 0x07; | 368 short exponent = (u1 >> 4) & 0x07; |
383 int mantissa = u1 & 0x0f; | 369 int mantissa = u1 & 0x0f; |
385 return u1 & 0x80 ? -unsigned_result : unsigned_result; | 371 return u1 & 0x80 ? -unsigned_result : unsigned_result; |
386 } | 372 } |
387 #endif /* not USE_MULAW_DECODE_TABLE */ | 373 #endif /* not USE_MULAW_DECODE_TABLE */ |
388 | 374 |
389 static void | 375 static void |
390 write_mulaw_8_chunk (buffer, chunklimit, ac) | 376 write_mulaw_8_chunk (void *buffer, void *chunklimit, AudioContext ac) |
391 void * buffer; | |
392 void * chunklimit; | |
393 AudioContext ac; | |
394 { | 377 { |
395 unsigned char * data = (unsigned char *) buffer; | 378 unsigned char * data = (unsigned char *) buffer; |
396 unsigned char * limit = (unsigned char *) chunklimit; | 379 unsigned char * limit = (unsigned char *) chunklimit; |
397 short * obuf, * bufp; | 380 short * obuf, * bufp; |
398 long n_samples = limit - data; | 381 long n_samples = limit - data; |
406 } | 389 } |
407 #endif /* HAVE_MULAW_8 */ | 390 #endif /* HAVE_MULAW_8 */ |
408 | 391 |
409 #if HAVE_LINEAR | 392 #if HAVE_LINEAR |
410 static void | 393 static void |
411 write_linear_chunk (data, limit, ac) | 394 write_linear_chunk (void *data, void *limit, AudioContext ac) |
412 void * data; | |
413 void * limit; | |
414 AudioContext ac; | |
415 { | 395 { |
416 unsigned n_samples; | 396 unsigned n_samples; |
417 | 397 |
418 switch (ac->ac_format) | 398 switch (ac->ac_format) |
419 { | 399 { |
424 ALwritesamps (ac->ac_port, data, (long) n_samples); | 404 ALwritesamps (ac->ac_port, data, (long) n_samples); |
425 } | 405 } |
426 | 406 |
427 #if HAVE_LINEAR_32 | 407 #if HAVE_LINEAR_32 |
428 static void | 408 static void |
429 write_linear_32_chunk (buffer, chunklimit, ac) | 409 write_linear_32_chunk (void *buffer, void *chunklimit, AudioContext ac) |
430 void * buffer; | |
431 void * chunklimit; | |
432 AudioContext ac; | |
433 { | 410 { |
434 long * data = (long *) buffer; | 411 long * data = (long *) buffer; |
435 long * limit = (long *) chunklimit; | 412 long * limit = (long *) chunklimit; |
436 long * obuf, * bufp; | 413 long * obuf, * bufp; |
437 long n_samples = limit-data; | 414 long n_samples = limit-data; |
445 } | 422 } |
446 #endif /* HAVE_LINEAR_32 */ | 423 #endif /* HAVE_LINEAR_32 */ |
447 #endif /* HAVE_LINEAR */ | 424 #endif /* HAVE_LINEAR */ |
448 | 425 |
449 static AudioContext | 426 static AudioContext |
450 initialize_audio_port (desc) | 427 initialize_audio_port (AudioContext desc) |
451 AudioContext desc; | |
452 { | 428 { |
453 /* we can't use the same port for mono and stereo */ | 429 /* we can't use the same port for mono and stereo */ |
454 static AudioContextRec mono_port_state | 430 static AudioContextRec mono_port_state |
455 = { { 0, 0, 0, 0 }, | 431 = { { 0, 0, 0, 0 }, |
456 { (ALport) 0, AFunknown, 1, 0 }, | 432 { (ALport) 0, AFunknown, 1, 0 }, |
513 adjust_audio_volume (& desc->device); | 489 adjust_audio_volume (& desc->device); |
514 return return_ac; | 490 return return_ac; |
515 } | 491 } |
516 | 492 |
517 static int | 493 static int |
518 open_audio_port (return_ac, desc) | 494 open_audio_port (AudioContext return_ac, AudioContext desc) |
519 AudioContext return_ac; | |
520 AudioContext desc; | |
521 { | 495 { |
522 ALconfig config = ALnewconfig(); | 496 ALconfig config = ALnewconfig(); |
523 long params[2]; | 497 long params[2]; |
524 | 498 |
525 adjust_audio_volume (& desc->device); | 499 adjust_audio_volume (& desc->device); |
545 } | 519 } |
546 return 0; | 520 return 0; |
547 } | 521 } |
548 | 522 |
549 static int | 523 static int |
550 set_channels (config, nchan) | 524 set_channels (ALconfig config, unsigned int nchan) |
551 ALconfig config; | |
552 unsigned nchan; | |
553 { | 525 { |
554 switch (nchan) | 526 switch (nchan) |
555 { | 527 { |
556 case 1: ALsetchannels (config, AL_MONO); break; | 528 case 1: ALsetchannels (config, AL_MONO); break; |
557 #if HAVE_STEREO | 529 #if HAVE_STEREO |
564 } | 536 } |
565 return 0; | 537 return 0; |
566 } | 538 } |
567 | 539 |
568 static int | 540 static int |
569 set_output_format (config, format) | 541 set_output_format (ALconfig config, AudioFormat format) |
570 ALconfig config; | |
571 AudioFormat format; | |
572 { | 542 { |
573 long samplesize; | 543 long samplesize; |
574 long old_samplesize; | 544 long old_samplesize; |
575 | 545 |
576 switch (format) | 546 switch (format) |
607 ALsetwidth (config, samplesize); | 577 ALsetwidth (config, samplesize); |
608 return 1; | 578 return 1; |
609 } | 579 } |
610 | 580 |
611 static void | 581 static void |
612 adjust_audio_volume (device) | 582 adjust_audio_volume (AudioDevice device) |
613 AudioDevice device; | |
614 { | 583 { |
615 long params[4]; | 584 long params[4]; |
616 params[0] = AL_LEFT_SPEAKER_GAIN; | 585 params[0] = AL_LEFT_SPEAKER_GAIN; |
617 params[1] = device->left_speaker_gain; | 586 params[1] = device->left_speaker_gain; |
618 params[2] = AL_RIGHT_SPEAKER_GAIN; | 587 params[2] = AL_RIGHT_SPEAKER_GAIN; |
619 params[3] = device->right_speaker_gain; | 588 params[3] = device->right_speaker_gain; |
620 ALsetparams (device->device, params, 4); | 589 ALsetparams (device->device, params, 4); |
621 } | 590 } |
622 | 591 |
623 static void | 592 static void |
624 get_current_volumes (device) | 593 get_current_volumes (AudioDevice device) |
625 AudioDevice device; | |
626 { | 594 { |
627 long params[4]; | 595 long params[4]; |
628 params[0] = AL_LEFT_SPEAKER_GAIN; | 596 params[0] = AL_LEFT_SPEAKER_GAIN; |
629 params[2] = AL_RIGHT_SPEAKER_GAIN; | 597 params[2] = AL_RIGHT_SPEAKER_GAIN; |
630 ALgetparams (device->device, params, 4); | 598 ALgetparams (device->device, params, 4); |
676 SND_FORMAT_DSP_COMMANDS_SAMPLES | 644 SND_FORMAT_DSP_COMMANDS_SAMPLES |
677 } | 645 } |
678 SNDFormatCode; | 646 SNDFormatCode; |
679 | 647 |
680 static int | 648 static int |
681 parse_snd_header (header, length, desc) | 649 parse_snd_header (void *header, long length, AudioContext desc) |
682 void * header; | |
683 long length; | |
684 AudioContext desc; | |
685 { | 650 { |
686 #define hp ((SNDSoundStruct *) (header)) | 651 #define hp ((SNDSoundStruct *) (header)) |
687 long limit; | 652 long limit; |
688 | 653 |
689 #if HAVE_LINEAR | 654 #if HAVE_LINEAR |