Mercurial > hg > xemacs-beta
comparison src/nas.c @ 412:697ef44129c6 r21-2-14
Import from CVS: tag r21-2-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:20:41 +0200 |
parents | 74fd4e045ea6 |
children |
comparison
equal
deleted
inserted
replaced
411:12e008d41344 | 412:697ef44129c6 |
---|---|
106 # define init_play nas_init_play | 106 # define init_play nas_init_play |
107 # define close_down_play nas_close_down_play | 107 # define close_down_play nas_close_down_play |
108 | 108 |
109 #else /* !emacs */ | 109 #else /* !emacs */ |
110 # define warn(str) fprintf (stderr, "%s\n", (str)) | 110 # define warn(str) fprintf (stderr, "%s\n", (str)) |
111 # define CONST const | |
111 #endif /* emacs */ | 112 #endif /* emacs */ |
112 | 113 |
113 #ifdef XTOOLKIT | 114 #ifdef XTOOLKIT |
114 # include <X11/Intrinsic.h> | 115 # include <X11/Intrinsic.h> |
115 # include <audio/Xtutil.h> | 116 # include <audio/Xtutil.h> |
143 #ifdef XTOOLKIT | 144 #ifdef XTOOLKIT |
144 Display *display | 145 Display *display |
145 #else | 146 #else |
146 char *server | 147 char *server |
147 #endif | 148 #endif |
148 ); | |
149 char * | |
150 init_play ( | |
151 #ifdef XTOOLKIT | |
152 Display *display | |
153 #else | |
154 char *server | |
155 #endif | |
156 ) | 149 ) |
157 { | 150 { |
158 char *err_message; | 151 char *err_message; |
159 SIGTYPE (*old_sigpipe) (int); | 152 SIGTYPE (*old_sigpipe) (); |
160 | 153 |
161 #ifdef XTOOLKIT | 154 #ifdef XTOOLKIT |
162 char * server = DisplayString (display); | 155 char * server = DisplayString (display); |
163 XtAppContext app_context = XtDisplayToApplicationContext (display); | 156 XtAppContext app_context = XtDisplayToApplicationContext (display); |
164 | 157 |
228 sounds_in_play = 0; | 221 sounds_in_play = 0; |
229 | 222 |
230 return NULL; | 223 return NULL; |
231 } | 224 } |
232 | 225 |
233 static void | 226 void |
234 close_down_play (void) | 227 close_down_play (void) |
235 | 228 |
236 { | 229 { |
237 AuCloseServer (aud); | 230 AuCloseServer (aud); |
238 warn ("disconnected from audio server"); | 231 warn ("disconnected from audio server"); |
243 * Callback which is run when the sound finishes playing. * | 236 * Callback which is run when the sound finishes playing. * |
244 * * | 237 * * |
245 \********************************************************************/ | 238 \********************************************************************/ |
246 | 239 |
247 static void | 240 static void |
248 doneCB (AuServer *auserver, | 241 doneCB (AuServer *aud, |
249 AuEventHandlerRec *handler, | 242 AuEventHandlerRec *handler, |
250 AuEvent *ev, | 243 AuEvent *ev, |
251 AuPointer data) | 244 AuPointer data) |
252 { | 245 { |
253 int *in_play_p = (int *) data; | 246 int *in_play_p = (int *) data; |
279 | 272 |
280 list = AuListBuckets (aud, AuCompCommonDescriptionMask, &b, &n, NULL); | 273 list = AuListBuckets (aud, AuCompCommonDescriptionMask, &b, &n, NULL); |
281 | 274 |
282 if (list == NULL) | 275 if (list == NULL) |
283 { | 276 { |
284 AuPointer my_buf; | 277 unsigned char *my_buf; |
285 | 278 |
286 if (buf==NULL) | 279 if (buf==NULL) |
287 { | 280 { |
288 if ((my_buf= (AuPointer) malloc (SoundNumBytes (s)))==NULL) | 281 if ((my_buf=malloc (SoundNumBytes (s)))==NULL) |
289 { | 282 { |
290 return; | 283 return; |
291 } | 284 } |
292 | 285 |
293 if (SoundReadFile ((char *) my_buf, SoundNumBytes (s), s) != SoundNumBytes (s)) | 286 if (SoundReadFile (my_buf, SoundNumBytes (s), s) != SoundNumBytes (s)) |
294 { | 287 { |
295 free (my_buf); | 288 free (my_buf); |
296 return; | 289 return; |
297 } | 290 } |
298 } | 291 } |
299 else | 292 else |
300 my_buf = (AuPointer) buf; | 293 my_buf=buf; |
301 | 294 |
302 id = AuSoundCreateBucketFromData (aud, | 295 id = AuSoundCreateBucketFromData (aud, |
303 s, | 296 s, |
304 my_buf, | 297 my_buf, |
305 AuAccessAllMasks, | 298 AuAccessAllMasks, |
327 | 320 |
328 } | 321 } |
329 #endif /* CACHE_SOUNDS */ | 322 #endif /* CACHE_SOUNDS */ |
330 | 323 |
331 | 324 |
332 void wait_for_sounds (void); | |
333 void | 325 void |
334 wait_for_sounds (void) | 326 wait_for_sounds (void) |
335 | 327 |
336 { | 328 { |
337 AuEvent ev; | 329 AuEvent ev; |
341 AuNextEvent (aud, AuTrue, &ev); | 333 AuNextEvent (aud, AuTrue, &ev); |
342 AuDispatchEvent (aud, &ev); | 334 AuDispatchEvent (aud, &ev); |
343 } | 335 } |
344 } | 336 } |
345 | 337 |
346 int play_sound_file (char *sound_file, int volume); | |
347 int | 338 int |
348 play_sound_file (char *sound_file, | 339 play_sound_file (char *sound_file, |
349 int volume) | 340 int volume) |
350 { | 341 { |
351 SIGTYPE (*old_sigpipe) (int); | 342 SIGTYPE (*old_sigpipe) (); |
352 | 343 |
353 #ifdef ROBUST_PLAY | 344 #ifdef ROBUST_PLAY |
354 old_sigpipe=signal (SIGPIPE, sigpipe_handle); | 345 old_sigpipe=signal (SIGPIPE, sigpipe_handle); |
355 if (setjmp (AuXtErrorJump)) | 346 if (setjmp (AuXtErrorJump)) |
356 { | 347 { |
434 #endif | 425 #endif |
435 | 426 |
436 return 1; | 427 return 1; |
437 } | 428 } |
438 | 429 |
439 int play_sound_data (unsigned char *data, int length, int volume); | |
440 int | 430 int |
441 play_sound_data (unsigned char *data, | 431 play_sound_data (unsigned char *data, |
442 int length, | 432 int length, |
443 int volume) | 433 int volume) |
444 { | 434 { |
445 Sound s; | 435 Sound s; |
446 int offset; | 436 int offset; |
447 SIGTYPE (*old_sigpipe) (int); | 437 SIGTYPE (*old_sigpipe) (); |
448 | 438 |
449 #if !defined (XTEVENTS) | 439 #if !defined (XTEVENTS) |
450 AuEvent ev; | 440 AuEvent ev; |
451 #endif | 441 #endif |
452 | 442 |
621 \********************************************************************/ | 611 \********************************************************************/ |
622 | 612 |
623 /* Create a name from the sound. */ | 613 /* Create a name from the sound. */ |
624 | 614 |
625 static char * | 615 static char * |
626 NameFromData (const char *buf, | 616 NameFromData (CONST unsigned char *buf, |
627 int len) | 617 int len) |
628 | 618 |
629 { | 619 { |
630 char name[9]; | 620 unsigned char name[9]; |
631 int i; | 621 int i; |
632 char *s; | 622 char *s; |
633 | 623 |
634 buf+=len/2; | 624 buf+=len/2; |
635 len -= len/2; | 625 len -= len/2; |
650 | 640 |
651 name[i]='\0'; | 641 name[i]='\0'; |
652 | 642 |
653 if (i==8) | 643 if (i==8) |
654 { | 644 { |
655 strcpy (s = (char *) malloc (10), name); | 645 strcpy (s=malloc (10), name); |
656 } | 646 } |
657 else | 647 else |
658 { | 648 { |
659 strcpy (s = (char *) malloc (15), "short sound"); | 649 strcpy (s=malloc (15), "short sound"); |
660 } | 650 } |
661 | 651 |
662 return s; | 652 return s; |
663 } | 653 } |
664 | 654 |
665 /* Code to do a pseudo-open on a data buffer. Only for snd files at the | 655 /* Code to do a pseudo-open on a data buffer. Only for snd files at the |
666 moment. | 656 moment. |
667 */ | 657 */ |
668 | 658 |
669 static SndInfo * | 659 static SndInfo * |
670 SndOpenDataForReading (const char *data, | 660 SndOpenDataForReading (CONST char *data, |
671 int length) | 661 int length) |
672 | 662 |
673 { | 663 { |
674 SndInfo *si; | 664 SndInfo *si; |
675 int size; | 665 int size; |
737 #define PAD2(_x) (((_x) + 1) & ~1) | 727 #define PAD2(_x) (((_x) + 1) & ~1) |
738 | 728 |
739 /* These functions here are for faking file I/O from buffer. */ | 729 /* These functions here are for faking file I/O from buffer. */ |
740 | 730 |
741 /* The "file" position */ | 731 /* The "file" position */ |
742 static size_t file_posn; | 732 static int file_posn; |
743 /* The length of the "file" */ | 733 /* The length of the "file" */ |
744 static size_t file_len; | 734 static int file_len; |
745 /* The actual "file" data. */ | 735 /* The actual "file" data. */ |
746 static const void* file_data; | 736 CONST static char* file_data; |
747 | 737 |
748 /* Like fopen, but for a buffer in memory */ | 738 /* Like fopen, but for a buffer in memory */ |
749 static void | 739 static void |
750 dopen (const void* data, size_t length) | 740 dopen(CONST char* data, int length) |
751 { | 741 { |
752 file_data = data; | 742 file_data = data; |
753 file_len = length; | 743 file_len = length; |
754 file_posn = 0; | 744 file_posn = 0; |
755 } | 745 } |
756 | 746 |
757 /* Like fread, but for a buffer in memory */ | 747 /* Like fread, but for a buffer in memory */ |
758 static int | 748 static int |
759 dread (void* buf, size_t size, size_t nitems) | 749 dread(char* buf, int size, int nitems) |
760 { | 750 { |
761 size_t nread = size * nitems; | 751 int nread; |
752 | |
753 nread = size * nitems; | |
762 | 754 |
763 if (file_posn + nread <= file_len) | 755 if (file_posn + nread <= file_len) |
764 { | 756 { |
765 memcpy(buf, (char *) file_data + file_posn, size * nitems); | 757 memcpy(buf, file_data + file_posn, size * nitems); |
766 file_posn += nread; | 758 file_posn += nread; |
767 return nitems; | 759 return nitems; |
768 } | 760 } |
769 else | 761 else |
770 { | 762 { |
772 } | 764 } |
773 } | 765 } |
774 | 766 |
775 /* Like fgetc, but for a buffer in memory */ | 767 /* Like fgetc, but for a buffer in memory */ |
776 static int | 768 static int |
777 dgetc (void) | 769 dgetc() |
778 { | 770 { |
771 int ch; | |
772 | |
779 if (file_posn < file_len) | 773 if (file_posn < file_len) |
780 return ((char *)file_data)[file_posn++]; | 774 return file_data[file_posn++]; |
781 else | 775 else |
782 return -1; | 776 return -1; |
783 } | 777 } |
784 | 778 |
785 /* Like fseek, but for a buffer in memory */ | 779 /* Like fseek, but for a buffer in memory */ |
786 static int | 780 static int |
787 dseek (long offset, int from) | 781 dseek(long offset, int from) |
788 { | 782 { |
789 if (from == 0) | 783 if (from == 0) |
790 file_posn = offset; | 784 file_posn = offset; |
791 else if (from == 1) | 785 else if (from == 1) |
792 file_posn += offset; | 786 file_posn += offset; |
795 | 789 |
796 return 0; | 790 return 0; |
797 } | 791 } |
798 | 792 |
799 /* Like ftell, but for a buffer in memory */ | 793 /* Like ftell, but for a buffer in memory */ |
800 static long | 794 static int |
801 dtell (void) | 795 dtell() |
802 { | 796 { |
803 return file_posn; | 797 return file_posn; |
804 } | 798 } |
805 | 799 |
806 /* Data buffer analogs for FileReadS and FileReadL in NAS. */ | 800 /* Data buffer analogs for FileReadS and FileReadL in NAS. */ |
807 | 801 |
808 static unsigned short | 802 static unsigned short |
809 DataReadS (int swapit) | 803 DataReadS(int swapit) |
810 { | 804 { |
811 unsigned short us; | 805 unsigned short us; |
812 | 806 |
813 dread(&us, 2, 1); | 807 dread(&us, 2, 1); |
814 if (swapit) | 808 if (swapit) |
815 us = FileSwapS(us); | 809 us = FileSwapS(us); |
816 return us; | 810 return us; |
817 } | 811 } |
818 | 812 |
819 static AuUint32 | 813 static AuUint32 |
820 DataReadL (int swapit) | 814 DataReadL(int swapit) |
821 { | 815 { |
822 AuUint32 ul; | 816 AuUint32 ul; |
823 | 817 |
824 dread(&ul, 4, 1); | 818 dread(&ul, 4, 1); |
825 if (swapit) | 819 if (swapit) |
826 ul = FileSwapL(ul); | 820 ul = FileSwapL(ul); |
827 return ul; | 821 return ul; |
828 } | 822 } |
829 | 823 |
830 static int | 824 static int |
831 readChunk (RiffChunk *c) | 825 readChunk(RiffChunk *c) |
832 { | 826 { |
833 int status; | 827 int status; |
834 char n; | 828 char n; |
835 | 829 |
836 if ((status = dread(c, sizeof(RiffChunk), 1))) | 830 if ((status = dread(c, sizeof(RiffChunk), 1))) |
842 | 836 |
843 /* A very straight-forward translation of WaveOpenFileForReading to | 837 /* A very straight-forward translation of WaveOpenFileForReading to |
844 read the wave data from a buffer in memory. */ | 838 read the wave data from a buffer in memory. */ |
845 | 839 |
846 static WaveInfo * | 840 static WaveInfo * |
847 WaveOpenDataForReading (const char *data, | 841 WaveOpenDataForReading(CONST char *data, |
848 int length) | 842 int length) |
849 { | 843 { |
850 RiffChunk ck; | 844 RiffChunk ck; |
851 RIFF_FOURCC fourcc; | 845 RIFF_FOURCC fourcc; |
852 AuInt32 fileSize; | 846 AuInt32 fileSize; |
853 WaveInfo *wi; | 847 WaveInfo *wi; |
985 Sound s; | 979 Sound s; |
986 | 980 |
987 if (!(s = (Sound) malloc (sizeof (SoundRec)))) | 981 if (!(s = (Sound) malloc (sizeof (SoundRec)))) |
988 return NULL; | 982 return NULL; |
989 | 983 |
990 if ((s->formatInfo = SndOpenDataForReading ((char *) data, length)) != NULL) | 984 if ((s->formatInfo = SndOpenDataForReading (data, length)) != NULL) |
991 { | 985 { |
992 if (!((int(*)(Sound))(SoundFileInfo[SoundFileFormatSnd].toSound)) (s)) | 986 if (!(SoundFileInfo[SoundFileFormatSnd].toSound) (s)) |
993 { | 987 { |
994 SndCloseFile ((SndInfo *) (s->formatInfo)); | 988 SndCloseFile (s->formatInfo); |
995 free (s); | 989 free (s); |
996 return NULL; | 990 return NULL; |
997 } | 991 } |
998 } | 992 } |
999 else if ((s->formatInfo = WaveOpenDataForReading ((char *) data, length)) != NULL) | 993 else if ((s->formatInfo = WaveOpenDataForReading (data, length)) != NULL) |
1000 { | 994 { |
1001 if (!((int(*)(Sound))(SoundFileInfo[SoundFileFormatWave].toSound)) (s)) | 995 if (!(SoundFileInfo[SoundFileFormatWave].toSound) (s)) |
1002 { | 996 { |
1003 WaveCloseFile ((WaveInfo *) (s->formatInfo)); | 997 WaveCloseFile (s->formatInfo); |
1004 free (s); | 998 free (s); |
1005 return NULL; | 999 return NULL; |
1006 } | 1000 } |
1007 } | 1001 } |
1008 | 1002 |
1009 return s; | 1003 return s; |
1010 } | 1004 } |
1005 |