comparison src/sgiplay.c @ 563:183866b06e0b

[xemacs-hg @ 2001-05-24 07:50:48 by ben] Makefile.in.in, abbrev.c, alloc.c, buffer.c, bytecode.c, callint.c, callproc.c, casetab.c, chartab.c, cmdloop.c, cmds.c, console-msw.c, console-msw.h, console-stream.c, console-tty.c, console-x.c, console.c, data.c, database.c, debug.c, device-gtk.c, device-msw.c, device-tty.c, device-x.c, device.c, dialog-gtk.c, dialog-msw.c, dialog-x.c, dialog.c, dired-msw.c, dired.c, doc.c, doprnt.c, dragdrop.c, editfns.c, eldap.c, eldap.h, elhash.c, emacs-widget-accessors.c, emacs.c, emodules.c, esd.c, eval.c, event-Xt.c, event-gtk.c, event-msw.c, event-stream.c, events.c, extents.c, faces.c, file-coding.c, fileio.c, filelock.c, floatfns.c, fns.c, font-lock.c, frame-gtk.c, frame-x.c, frame.c, general-slots.h, glade.c, glyphs-gtk.c, glyphs-msw.c, glyphs-widget.c, glyphs-x.c, glyphs.c, glyphs.h, gpmevent.c, gui-gtk.c, gui-x.c, gui.c, gutter.c, hpplay.c, indent.c, input-method-xlib.c, insdel.c, intl.c, keymap.c, libsst.c, libsst.h, linuxplay.c, lisp.h, lread.c, lstream.c, lstream.h, macros.c, marker.c, md5.c, menubar-gtk.c, menubar-msw.c, menubar-x.c, menubar.c, minibuf.c, miscplay.c, miscplay.h, mule-ccl.c, mule-charset.c, mule-wnnfns.c, mule.c, nas.c, ntplay.c, ntproc.c, objects-gtk.c, objects-msw.c, objects-x.c, objects.c, postgresql.c, print.c, process-nt.c, process-unix.c, process.c, ralloc.c, rangetab.c, redisplay.c, scrollbar.c, search.c, select-gtk.c, select-x.c, select.c, sgiplay.c, sheap.c, sound.c, specifier.c, sunplay.c, symbols.c, symeval.h, symsinit.h, syntax.c, sysdep.c, toolbar-msw.c, toolbar.c, tooltalk.c, ui-byhand.c, ui-gtk.c, undo.c, unexaix.c, unexapollo.c, unexconvex.c, unexec.c, widget.c, win32.c, window.c: -- defsymbol -> DEFSYMBOL. -- add an error type to all errors. -- eliminate the error functions in eval.c that let you just use Qerror as the type. -- redo the error API to be more consistent, sensibly named, and easier to use. -- redo the error hierarchy somewhat. create new errors: structure-formation-error, gui-error, invalid-constant, stack-overflow, out-of-memory, process-error, network-error, sound-error, printing-unreadable-object, base64-conversion- error; coding-system-error renamed to text-conversion error; some others. -- fix Mule problems in error strings in emodules.c, tooltalk.c. -- fix error handling in mswin open-network-stream. -- Mule-ize all sound files and clean up the headers. -- nativesound.h -> sound.h and used for all sound files. -- move some shared stuff into glyphs-shared.c: first attempt at eliminating some of the massive GTK code duplication. xemacs.mak: add glyphs-shared.c. xemacs-faq.texi: document how to debug X errors subr.el: fix doc string to reflect reality
author ben
date Thu, 24 May 2001 07:51:33 +0000
parents 576fb035e263
children 13e3d7ae7155
comparison
equal deleted inserted replaced
562:c775bd016b32 563:183866b06e0b
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */ 20 Boston, MA 02111-1307, USA. */
21 21
22 /* Synched up with: Not in FSF. */ 22 /* Synched up with: Not in FSF. */
23 23
24 /* This file Mule-ized by Ben Wing, 5-15-01. */
25
24 #include <config.h> 26 #include <config.h>
25 #include "lisp.h" 27 #include "lisp.h"
26 28
27 #include <string.h> 29 #include "sound.h"
28 #include <sys/file.h> 30
29 #include <sys/types.h> 31 #include "sysfile.h"
30 #include <sys/stat.h> 32 #include "sysproc.h" /* netinet/in.h for ntohl() etc. */
31 #include <fcntl.h>
32 #include <unistd.h>
33 #include <audio.h>
34 #include <netinet/in.h> /* for ntohl() etc. */
35 33
36 /* Configuration options */ 34 /* Configuration options */
37 35
38 /* ability to parse Sun/NeXT (.au or .snd) audio file headers. The 36 /* ability to parse Sun/NeXT (.au or .snd) audio file headers. The
39 .snd format supports all sampling rates and sample widths that are 37 .snd format supports all sampling rates and sample widths that are
89 assumes ".au" format (8000 samples/sec mono 8-bit mulaw). */ 87 assumes ".au" format (8000 samples/sec mono 8-bit mulaw). */
90 #define DEFAULT_SAMPLING_RATE 8000 88 #define DEFAULT_SAMPLING_RATE 8000
91 #define DEFAULT_CHANNEL_COUNT 1 89 #define DEFAULT_CHANNEL_COUNT 1
92 #define DEFAULT_FORMAT AFmulaw8 90 #define DEFAULT_FORMAT AFmulaw8
93 91
94 /* Exports */
95
96 /* all compilers on machines that have the SGI audio library
97 understand prototypes, right? */
98
99 extern void play_sound_file (char *, int);
100 extern void play_sound_data (unsigned char *, int, int);
101
102 /* Data structures */ 92 /* Data structures */
103 93
104 /* an AudioContext describes everything we want to know about how a 94 /* an AudioContext describes everything we want to know about how a
105 particular sound snippet should be played. It is split into three 95 particular sound snippet should be played. It is split into three
106 parts (device, port and buffer) for implementation reasons. The 96 parts (device, port and buffer) for implementation reasons. The
180 #define ac_write_chunk_function buffer.write_chunk_function 170 #define ac_write_chunk_function buffer.write_chunk_function
181 171
182 /* Forward declarations */ 172 /* Forward declarations */
183 173
184 static Lisp_Object close_sound_file (Lisp_Object); 174 static Lisp_Object close_sound_file (Lisp_Object);
185 static AudioContext audio_initialize (unsigned char *, int, int); 175 static AudioContext audio_initialize (UChar_Binary *, int, int);
186 static void play_internal (unsigned char *, int, AudioContext); 176 static void play_internal (UChar_Binary *, int, AudioContext);
187 static void drain_audio_port (AudioContext); 177 static void drain_audio_port (AudioContext);
188 static void write_mulaw_8_chunk (void *, void *, AudioContext); 178 static void write_mulaw_8_chunk (void *, void *, AudioContext);
189 static void write_linear_chunk (void *, void *, AudioContext); 179 static void write_linear_chunk (void *, void *, AudioContext);
190 static void write_linear_32_chunk (void *, void *, AudioContext); 180 static void write_linear_32_chunk (void *, void *, AudioContext);
191 static Lisp_Object restore_audio_port (Lisp_Object); 181 static Lisp_Object restore_audio_port (Lisp_Object);
207 close (XINT (closure)); 197 close (XINT (closure));
208 return Qnil; 198 return Qnil;
209 } 199 }
210 200
211 void 201 void
212 play_sound_file (char *sound_file, int volume) 202 play_sound_file (Extbyte *sound_file, int volume)
213 { 203 {
214 int count = specpdl_depth (); 204 int count = specpdl_depth ();
215 int input_fd; 205 int input_fd;
216 unsigned char buffer[CHUNKSIZE]; 206 UChar_Binary buffer[CHUNKSIZE];
217 int bytes_read; 207 int bytes_read;
218 AudioContext ac = (AudioContext) 0; 208 AudioContext ac = (AudioContext) 0;
219 209
220 input_fd = open (sound_file, O_RDONLY); 210 input_fd = open (sound_file, O_RDONLY);
221 if (input_fd == -1) 211 if (input_fd == -1)
262 ALsetparams (AL_DEFAULT_DEVICE, saved_device_state, 6); 252 ALsetparams (AL_DEFAULT_DEVICE, saved_device_state, 6);
263 return Qnil; 253 return Qnil;
264 } 254 }
265 255
266 void 256 void
267 play_sound_data (unsigned char *data, int length, int volume) 257 play_sound_data (UChar_Binary *data, int length, int volume)
268 { 258 {
269 int count = specpdl_depth (); 259 int count = specpdl_depth ();
270 AudioContext ac; 260 AudioContext ac;
271 261
272 ac = audio_initialize (data, length, volume); 262 ac = audio_initialize (data, length, volume);
276 drain_audio_port (ac); 266 drain_audio_port (ac);
277 unbind_to (count, Qnil); 267 unbind_to (count, Qnil);
278 } 268 }
279 269
280 static AudioContext 270 static AudioContext
281 audio_initialize (unsigned char *data, int length, int volume) 271 audio_initialize (UChar_Binary *data, int length, int volume)
282 { 272 {
283 Lisp_Object audio_port_state[3]; 273 Lisp_Object audio_port_state[3];
284 static AudioContextRec desc; 274 static AudioContextRec desc;
285 AudioContext ac; 275 AudioContext ac;
286 276
291 281
292 #if HAVE_SND_FILES 282 #if HAVE_SND_FILES
293 if (LOOKING_AT_SND_HEADER_P (data)) 283 if (LOOKING_AT_SND_HEADER_P (data))
294 { 284 {
295 if (parse_snd_header (data, length, & desc)==-1) 285 if (parse_snd_header (data, length, & desc)==-1)
296 report_file_error ("decoding .snd header", Qnil); 286 report_sound_error ("decoding .snd header", Qunbound);
297 } 287 }
298 else 288 else
299 #endif 289 #endif
300 { 290 {
301 desc.ac_data = data; 291 desc.ac_data = data;
320 desc = * ac; 310 desc = * ac;
321 return ac; 311 return ac;
322 } 312 }
323 313
324 static void 314 static void
325 play_internal (unsigned char *data, int length, AudioContext ac) 315 play_internal (UChar_Binary *data, int length, AudioContext ac)
326 { 316 {
327 unsigned char * limit; 317 UChar_Binary * limit;
328 if (ac == (AudioContext) 0) 318 if (ac == (AudioContext) 0)
329 return; 319 return;
330 320
331 data = (unsigned char *) ac->ac_data; 321 data = (UChar_Binary *) ac->ac_data;
332 limit = data + ac->ac_size; 322 limit = data + ac->ac_size;
333 while (data < limit) 323 while (data < limit)
334 { 324 {
335 unsigned char * chunklimit = data + CHUNKSIZE; 325 UChar_Binary * chunklimit = data + CHUNKSIZE;
336 326
337 if (chunklimit > limit) 327 if (chunklimit > limit)
338 chunklimit = limit; 328 chunklimit = limit;
339 329
340 QUIT; 330 QUIT;
373 #endif /* not USE_MULAW_DECODE_TABLE */ 363 #endif /* not USE_MULAW_DECODE_TABLE */
374 364
375 static void 365 static void
376 write_mulaw_8_chunk (void *buffer, void *chunklimit, AudioContext ac) 366 write_mulaw_8_chunk (void *buffer, void *chunklimit, AudioContext ac)
377 { 367 {
378 unsigned char * data = (unsigned char *) buffer; 368 UChar_Binary * data = (UChar_Binary *) buffer;
379 unsigned char * limit = (unsigned char *) chunklimit; 369 UChar_Binary * limit = (UChar_Binary *) chunklimit;
380 short * obuf, * bufp; 370 short * obuf, * bufp;
381 long n_samples = limit - data; 371 long n_samples = limit - data;
382 372
383 obuf = alloca_array (short, n_samples); 373 obuf = alloca_array (short, n_samples);
384 bufp = &obuf[0]; 374 bufp = &obuf[0];
396 unsigned n_samples; 386 unsigned n_samples;
397 387
398 switch (ac->ac_format) 388 switch (ac->ac_format)
399 { 389 {
400 case AFlinear16: n_samples = (short *) limit - (short *) data; break; 390 case AFlinear16: n_samples = (short *) limit - (short *) data; break;
401 case AFlinear8: n_samples = (char *) limit - (char *) data; break; 391 case AFlinear8: n_samples = (Char_Binary *) limit - (Char_Binary *) data; break;
402 default: n_samples = (long *) limit - (long *) data; break; 392 default: n_samples = (long *) limit - (long *) data; break;
403 } 393 }
404 ALwritesamps (ac->ac_port, data, (long) n_samples); 394 ALwritesamps (ac->ac_port, data, (long) n_samples);
405 } 395 }
406 396
455 445
456 if (return_ac->ac_port==(ALport) 0) 446 if (return_ac->ac_port==(ALport) 0)
457 { 447 {
458 if ((open_audio_port (return_ac, desc))==-1) 448 if ((open_audio_port (return_ac, desc))==-1)
459 { 449 {
460 report_file_error ("Open audio port", Qnil); 450 report_sound_error ("Open audio port", Qunbound);
461 return (AudioContext) 0; 451 return (AudioContext) 0;
462 } 452 }
463 } 453 }
464 else 454 else
465 { 455 {
512 ALsetqueuesize (config, (long) CHUNKSIZE); 502 ALsetqueuesize (config, (long) CHUNKSIZE);
513 return_ac->ac_port = ALopenport("XEmacs audio output", "w", config); 503 return_ac->ac_port = ALopenport("XEmacs audio output", "w", config);
514 ALfreeconfig (config); 504 ALfreeconfig (config);
515 if (return_ac->ac_port==0) 505 if (return_ac->ac_port==0)
516 { 506 {
517 report_file_error ("Opening audio output port", Qnil); 507 report_sound_error ("Opening audio output port", Qunbound);
518 return -1; 508 return -1;
519 } 509 }
520 return 0; 510 return 0;
521 } 511 }
522 512
528 case 1: ALsetchannels (config, AL_MONO); break; 518 case 1: ALsetchannels (config, AL_MONO); break;
529 #if HAVE_STEREO 519 #if HAVE_STEREO
530 case 2: ALsetchannels (config, AL_STEREO); break; 520 case 2: ALsetchannels (config, AL_STEREO); break;
531 #endif /* HAVE_STEREO */ 521 #endif /* HAVE_STEREO */
532 default: 522 default:
533 report_file_error ("Unsupported channel count", 523 report_sound_error ("Unsupported channel count",
534 Fcons (make_int (nchan), Qnil)); 524 make_int (nchan));
535 return -1; 525 return -1;
536 } 526 }
537 return 0; 527 return 0;
538 } 528 }
539 529
565 samplesize = AL_SAMPLE_24; 555 samplesize = AL_SAMPLE_24;
566 break; 556 break;
567 #endif 557 #endif
568 #endif 558 #endif
569 default: 559 default:
570 report_file_error ("Unsupported audio format", 560 report_sound_error ("Unsupported audio format", make_int (format));
571 Fcons (make_int (format), Qnil));
572 return -1; 561 return -1;
573 } 562 }
574 old_samplesize = ALgetwidth (config); 563 old_samplesize = ALgetwidth (config);
575 if (old_samplesize==samplesize) 564 if (old_samplesize==samplesize)
576 return 0; 565 return 0;
610 int dataLocation; 599 int dataLocation;
611 int dataSize; 600 int dataSize;
612 int dataFormat; 601 int dataFormat;
613 int samplingRate; 602 int samplingRate;
614 int channelCount; 603 int channelCount;
615 char info[4]; 604 Char_Binary info[4];
616 } 605 }
617 SNDSoundStruct; 606 SNDSoundStruct;
618 #define SOUND_TO_HOST_INT(x) ntohl(x) 607 #define SOUND_TO_HOST_INT(x) ntohl(x)
619 608
620 typedef enum 609 typedef enum
682 default: 671 default:
683 desc->ac_format = AFunknown; 672 desc->ac_format = AFunknown;
684 } 673 }
685 desc->ac_output_rate = SOUND_TO_HOST_INT (hp->samplingRate); 674 desc->ac_output_rate = SOUND_TO_HOST_INT (hp->samplingRate);
686 desc->ac_nchan = SOUND_TO_HOST_INT (hp->channelCount); 675 desc->ac_nchan = SOUND_TO_HOST_INT (hp->channelCount);
687 desc->ac_data = (char *) header + SOUND_TO_HOST_INT (hp->dataLocation); 676 desc->ac_data = (Char_Binary *) header + SOUND_TO_HOST_INT (hp->dataLocation);
688 limit = (char *) header + length - (char *) desc->ac_data; 677 limit = (Char_Binary *) header + length - (Char_Binary *) desc->ac_data;
689 desc->ac_size = SOUND_TO_HOST_INT (hp->dataSize); 678 desc->ac_size = SOUND_TO_HOST_INT (hp->dataSize);
690 if (desc->ac_size > limit) desc->ac_size = limit; 679 if (desc->ac_size > limit) desc->ac_size = limit;
691 return 0; 680 return 0;
692 #undef hp 681 #undef hp
693 } 682 }