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