Mercurial > hg > xemacs-beta
comparison src/nas.c @ 2108:8de911beca70
[xemacs-hg @ 2004-06-02 09:16:14 by didierv]
C++ related fixes
author | didierv |
---|---|
date | Wed, 02 Jun 2004 09:16:21 +0000 |
parents | 18d2b8dabcf7 |
children | f18c80177dfe |
comparison
equal
deleted
inserted
replaced
2107:91e93aba4aae | 2108:8de911beca70 |
---|---|
8 * Permission to use, copy, modify, distribute, and sell this software and | 8 * Permission to use, copy, modify, distribute, and sell this software and |
9 * its documentation for any purpose is hereby granted without fee, provided | 9 * its documentation for any purpose is hereby granted without fee, provided |
10 * that the above copyright notice appear in all copies and that both that | 10 * that the above copyright notice appear in all copies and that both that |
11 * copyright notice and this permission notice appear in supporting | 11 * copyright notice and this permission notice appear in supporting |
12 * documentation, and that the name Network Computing Devices, Inc. not be | 12 * documentation, and that the name Network Computing Devices, Inc. not be |
13 * used in advertising or publicity pertaining to distribution of this | 13 * used in advertising or publicity pertaining to distribution of this |
14 * software without specific, written prior permission. | 14 * software without specific, written prior permission. |
15 * | 15 * |
16 * THIS SOFTWARE IS PROVIDED 'AS-IS'. NETWORK COMPUTING DEVICES, INC., | 16 * THIS SOFTWARE IS PROVIDED 'AS-IS'. NETWORK COMPUTING DEVICES, INC., |
17 * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT | 17 * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT |
18 * LIMITATION ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | 18 * LIMITATION ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A |
19 * PARTICULAR PURPOSE, OR NONINFRINGEMENT. IN NO EVENT SHALL NETWORK | 19 * PARTICULAR PURPOSE, OR NONINFRINGEMENT. IN NO EVENT SHALL NETWORK |
20 * COMPUTING DEVICES, INC., BE LIABLE FOR ANY DAMAGES WHATSOEVER, INCLUDING | 20 * COMPUTING DEVICES, INC., BE LIABLE FOR ANY DAMAGES WHATSOEVER, INCLUDING |
29 /* This file Mule-ized by Ben Wing, 5-15-01. */ | 29 /* This file Mule-ized by Ben Wing, 5-15-01. */ |
30 | 30 |
31 /* There are four compile-time options. | 31 /* There are four compile-time options. |
32 * | 32 * |
33 * XTOOLKIT This will be part of an Xt program. | 33 * XTOOLKIT This will be part of an Xt program. |
34 * | 34 * |
35 * XTEVENTS The playing will be supervised asynchronously by the Xt event | 35 * XTEVENTS The playing will be supervised asynchronously by the Xt event |
36 * loop. If not set, playing will be completed within the call | 36 * loop. If not set, playing will be completed within the call |
37 * to play_file etc. | 37 * to play_file etc. |
38 * | 38 * |
39 * ROBUST_PLAY Causes errors in nas to be caught. This means that the | 39 * ROBUST_PLAY Causes errors in nas to be caught. This means that the |
40 * program will attempt not to die if the nas server does. | 40 * program will attempt not to die if the nas server does. |
41 * | 41 * |
42 * CACHE_SOUNDS Causes the sounds to be played in buckets in the NAS | 42 * CACHE_SOUNDS Causes the sounds to be played in buckets in the NAS |
78 seems unnecessarily complex. | 78 seems unnecessarily complex. |
79 */ | 79 */ |
80 #undef LITTLE_ENDIAN | 80 #undef LITTLE_ENDIAN |
81 #undef BIG_ENDIAN | 81 #undef BIG_ENDIAN |
82 | 82 |
83 EXTERN_C | |
84 { | |
83 #include <audio/audiolib.h> | 85 #include <audio/audiolib.h> |
84 #include <audio/soundlib.h> | 86 #include <audio/soundlib.h> |
85 #include <audio/snd.h> | 87 #include <audio/snd.h> |
86 #include <audio/wave.h> | 88 #include <audio/wave.h> |
87 #include <audio/fileutil.h> | 89 #include <audio/fileutil.h> |
90 } | |
88 | 91 |
89 /* NAS <= 1.2p5 <audio/fileutil.h> doesn't define the NAS_ versions */ | 92 /* NAS <= 1.2p5 <audio/fileutil.h> doesn't define the NAS_ versions */ |
90 #ifndef NAS_LITTLE_ENDIAN | 93 #ifndef NAS_LITTLE_ENDIAN |
91 # define NAS_LITTLE_ENDIAN LITTLE_ENDIAN | 94 # define NAS_LITTLE_ENDIAN LITTLE_ENDIAN |
92 # define NAS_BIG_ENDIAN BIG_ENDIAN | 95 # define NAS_BIG_ENDIAN BIG_ENDIAN |
216 AuDefaultErrorHandler = NULL; | 219 AuDefaultErrorHandler = NULL; |
217 # endif | 220 # endif |
218 #endif | 221 #endif |
219 | 222 |
220 #ifdef XTEVENTS | 223 #ifdef XTEVENTS |
221 input_id = AuXtAppAddAudioHandler (app_context, aud); | 224 input_id = AuXtAppAddAudioHandler (app_context, aud); |
222 #endif | 225 #endif |
223 | 226 |
224 #ifdef CACHE_SOUNDS | 227 #ifdef CACHE_SOUNDS |
225 AuSetCloseDownMode (aud, AuCloseDownRetainPermanent, NULL); | 228 AuSetCloseDownMode (aud, AuCloseDownRetainPermanent, NULL); |
226 #endif | 229 #endif |
301 } | 304 } |
302 } | 305 } |
303 else | 306 else |
304 my_buf = (AuPointer) buf; | 307 my_buf = (AuPointer) buf; |
305 | 308 |
306 id = AuSoundCreateBucketFromData (aud, | 309 id = AuSoundCreateBucketFromData (aud, |
307 s, | 310 s, |
308 my_buf, | 311 my_buf, |
309 AuAccessAllMasks, | 312 AuAccessAllMasks, |
310 NULL, | 313 NULL, |
311 NULL); | 314 NULL); |
312 if (buf == NULL) | 315 if (buf == NULL) |
313 free (my_buf); | 316 free (my_buf); |
314 } | 317 } |
318 AuFreeBucketAttributes (aud, n, list); | 321 AuFreeBucketAttributes (aud, n, list); |
319 } | 322 } |
320 | 323 |
321 sounds_in_play++; | 324 sounds_in_play++; |
322 | 325 |
323 AuSoundPlayFromBucket (aud, | 326 AuSoundPlayFromBucket (aud, |
324 id, | 327 id, |
325 AuNone, | 328 AuNone, |
326 AuFixedPointFromFraction (volume, 100), | 329 AuFixedPointFromFraction (volume, 100), |
327 doneCB, (AuPointer) &sounds_in_play, | 330 doneCB, (AuPointer) &sounds_in_play, |
328 1, | 331 1, |
329 NULL, NULL, | 332 NULL, NULL, |
330 NULL, NULL); | 333 NULL, NULL); |
331 | 334 |
332 } | 335 } |
333 #endif /* CACHE_SOUNDS */ | 336 #endif /* CACHE_SOUNDS */ |
334 | 337 |
335 | 338 |
336 void nas_wait_for_sounds (void); | 339 void nas_wait_for_sounds (void); |
337 void | 340 void |
338 nas_wait_for_sounds (void) | 341 nas_wait_for_sounds (void) |
339 | 342 |
340 { | 343 { |
341 AuEvent ev; | 344 AuEvent ev; |
342 | 345 |
369 { | 372 { |
370 Extbyte *m; | 373 Extbyte *m; |
371 /* attempt to reconect */ | 374 /* attempt to reconect */ |
372 if ((m = nas_init_play (aud_server)) != NULL) | 375 if ((m = nas_init_play (aud_server)) != NULL) |
373 { | 376 { |
374 | 377 |
375 #ifdef ROBUST_PLAY | 378 #ifdef ROBUST_PLAY |
376 EMACS_SIGNAL (SIGPIPE, old_sigpipe); | 379 EMACS_SIGNAL (SIGPIPE, old_sigpipe); |
377 #endif | 380 #endif |
378 return 0; | 381 return 0; |
379 } | 382 } |
536 #else | 539 #else |
537 if (!NILP (Vsynchronous_sounds)) | 540 if (!NILP (Vsynchronous_sounds)) |
538 nas_wait_for_sounds (); | 541 nas_wait_for_sounds (); |
539 #endif | 542 #endif |
540 | 543 |
541 SoundCloseFile (s); | 544 SoundCloseFile (s); |
542 | 545 |
543 #ifdef ROBUST_PLAY | 546 #ifdef ROBUST_PLAY |
544 EMACS_SIGNAL (SIGPIPE, old_sigpipe); | 547 EMACS_SIGNAL (SIGPIPE, old_sigpipe); |
545 #endif | 548 #endif |
546 | 549 |
559 | 562 |
560 static AuBool | 563 static AuBool |
561 CatchIoErrorAndJump (AuServer *old_aud) | 564 CatchIoErrorAndJump (AuServer *old_aud) |
562 { | 565 { |
563 if (old_aud) | 566 if (old_aud) |
564 sound_warn ("Audio Server connection broken"); | 567 sound_warn ("Audio Server connection broken"); |
565 else | 568 else |
566 sound_warn ("Audio Server connection broken because of signal"); | 569 sound_warn ("Audio Server connection broken because of signal"); |
567 | 570 |
568 #ifdef XTEVENTS | 571 #ifdef XTEVENTS |
569 #ifdef XTOOLKIT | 572 #ifdef XTOOLKIT |
570 AuXtAppRemoveAudioHandler (aud, input_id); | 573 AuXtAppRemoveAudioHandler (aud, input_id); |
571 #endif | 574 #endif |
572 | 575 |
573 if (aud) | 576 if (aud) |
574 AuCloseServer (aud); | 577 AuCloseServer (aud); |
575 aud = NULL; | 578 aud = NULL; |
582 if (aud) | 585 if (aud) |
583 AuCloseServer (aud); | 586 AuCloseServer (aud); |
584 aud = NULL; | 587 aud = NULL; |
585 sounds_in_play = 0; | 588 sounds_in_play = 0; |
586 longjmp (AuXtErrorJump, 1); | 589 longjmp (AuXtErrorJump, 1); |
587 | 590 |
588 #endif /* XTEVENTS */ | 591 #endif /* XTEVENTS */ |
589 return 0; | 592 return 0; |
590 } | 593 } |
591 | 594 |
592 SIGTYPE | 595 SIGTYPE |
647 | 650 |
648 if (i==8) | 651 if (i==8) |
649 { | 652 { |
650 strcpy (s = (Extbyte *) malloc (10), name); | 653 strcpy (s = (Extbyte *) malloc (10), name); |
651 } | 654 } |
652 else | 655 else |
653 { | 656 { |
654 strcpy (s = (Extbyte *) malloc (15), "short sound"); | 657 strcpy (s = (Extbyte *) malloc (15), "short sound"); |
655 } | 658 } |
656 | 659 |
657 return s; | 660 return s; |
658 } | 661 } |
659 | 662 |
660 /* Code to do a pseudo-open on a data buffer. Only for snd files at the | 663 /* Code to do a pseudo-open on a data buffer. Only for snd files at the |
661 moment. | 664 moment. |
662 */ | 665 */ |
663 | 666 |
664 static SndInfo * | 667 static SndInfo * |
665 SndOpenDataForReading (const Char_Binary *data, | 668 SndOpenDataForReading (const Char_Binary *data, |
666 int length) | 669 int length) |
678 memcpy (&si->h, data, sizeof (SndHeader)); | 681 memcpy (&si->h, data, sizeof (SndHeader)); |
679 | 682 |
680 if (NAS_LITTLE_ENDIAN) | 683 if (NAS_LITTLE_ENDIAN) |
681 { | 684 { |
682 Char_Binary n; | 685 Char_Binary n; |
683 | 686 |
684 swapl (&si->h.magic, n); | 687 swapl (&si->h.magic, n); |
685 swapl (&si->h.dataOffset, n); | 688 swapl (&si->h.dataOffset, n); |
686 swapl (&si->h.dataSize, n); | 689 swapl (&si->h.dataSize, n); |
687 swapl (&si->h.format, n); | 690 swapl (&si->h.format, n); |
688 swapl (&si->h.sampleRate, n); | 691 swapl (&si->h.sampleRate, n); |
752 /* Like fread, but for a buffer in memory */ | 755 /* Like fread, but for a buffer in memory */ |
753 static int | 756 static int |
754 dread (void* buf, size_t size, size_t nitems) | 757 dread (void* buf, size_t size, size_t nitems) |
755 { | 758 { |
756 size_t nread = size * nitems; | 759 size_t nread = size * nitems; |
757 | 760 |
758 if (file_posn + nread <= file_len) | 761 if (file_posn + nread <= file_len) |
759 { | 762 { |
760 memcpy(buf, (Char_Binary *) file_data + file_posn, size * nitems); | 763 memcpy(buf, (Char_Binary *) file_data + file_posn, size * nitems); |
761 file_posn += nread; | 764 file_posn += nread; |
762 return nitems; | 765 return nitems; |
845 RiffChunk ck; | 848 RiffChunk ck; |
846 RIFF_FOURCC fourcc; | 849 RIFF_FOURCC fourcc; |
847 AuInt32 fileSize; | 850 AuInt32 fileSize; |
848 WaveInfo *wi; | 851 WaveInfo *wi; |
849 | 852 |
850 | 853 |
851 if (!(wi = (WaveInfo *) malloc(sizeof(WaveInfo)))) | 854 if (!(wi = (WaveInfo *) malloc(sizeof(WaveInfo)))) |
852 return NULL; | 855 return NULL; |
853 | 856 |
854 wi->comment = NULL; | 857 wi->comment = NULL; |
855 wi->dataOffset = wi->format = wi->writing = 0; | 858 wi->dataOffset = wi->format = wi->writing = 0; |
856 | 859 |
857 dopen(data, length); | 860 dopen(data, length); |
858 | 861 |
859 if (!readChunk(&ck) || | 862 if (!readChunk(&ck) || |
860 cmpID(&ck.ckID, RIFF_RiffID) || | 863 cmpID(&ck.ckID, RIFF_RiffID) || |
861 !readFourcc(&fourcc) || | 864 !readFourcc(&fourcc) || |
862 cmpID(&fourcc, RIFF_WaveID)) | 865 cmpID(&fourcc, RIFF_WaveID)) |
863 Err(); | 866 Err(); |
965 if (!wi->comment) | 968 if (!wi->comment) |
966 wi->comment = NameFromData (data + wi->dataOffset, | 969 wi->comment = NameFromData (data + wi->dataOffset, |
967 length - wi->dataOffset); | 970 length - wi->dataOffset); |
968 | 971 |
969 wi->fp = NULL; | 972 wi->fp = NULL; |
970 | 973 |
971 return wi; | 974 return wi; |
972 } | 975 } |
973 | 976 |
974 | 977 |
975 static Sound | 978 static Sound |
986 return NULL; | 989 return NULL; |
987 | 990 |
988 if ((s->formatInfo = SndOpenDataForReading ((Char_Binary *) data, length)) != NULL) | 991 if ((s->formatInfo = SndOpenDataForReading ((Char_Binary *) data, length)) != NULL) |
989 { | 992 { |
990 #if (AudioLibraryVersionMajor >= 2 ) && (AudioLibraryVersionMinor >= 3) | 993 #if (AudioLibraryVersionMajor >= 2 ) && (AudioLibraryVersionMinor >= 3) |
991 if ((toProc = SoundFileGetProc(SoundFileFormatSnd, | 994 if ((toProc = SoundFileGetProc(SoundFileFormatSnd, |
992 SoundFileInfoProcTo)) == NULL) | 995 SoundFileInfoProcTo)) == NULL) |
993 { | 996 { |
994 SndCloseFile ((SndInfo *) (s->formatInfo)); | 997 SndCloseFile ((SndInfo *) (s->formatInfo)); |
995 free (s); | 998 free (s); |
996 | 999 |
1007 } | 1010 } |
1008 } | 1011 } |
1009 else if ((s->formatInfo = WaveOpenDataForReading ((Char_Binary *) data, length)) != NULL) | 1012 else if ((s->formatInfo = WaveOpenDataForReading ((Char_Binary *) data, length)) != NULL) |
1010 { | 1013 { |
1011 #if (AudioLibraryVersionMajor >= 2 ) && (AudioLibraryVersionMinor >= 3) | 1014 #if (AudioLibraryVersionMajor >= 2 ) && (AudioLibraryVersionMinor >= 3) |
1012 if ((toProc = SoundFileGetProc(SoundFileFormatWave, | 1015 if ((toProc = SoundFileGetProc(SoundFileFormatWave, |
1013 SoundFileInfoProcTo)) == NULL) | 1016 SoundFileInfoProcTo)) == NULL) |
1014 { | 1017 { |
1015 WaveCloseFile ((WaveInfo *) (s->formatInfo)); | 1018 WaveCloseFile ((WaveInfo *) (s->formatInfo)); |
1016 free (s); | 1019 free (s); |
1017 | 1020 |