comparison src/nas.c @ 432:3a7e78e1142d r21-2-24

Import from CVS: tag r21-2-24
author cvs
date Mon, 13 Aug 2007 11:29:58 +0200
parents 3ecd8885ac67
children 8de8e3f6228a
comparison
equal deleted inserted replaced
431:a97165e56215 432:3a7e78e1142d
144 #ifdef XTOOLKIT 144 #ifdef XTOOLKIT
145 Display *display 145 Display *display
146 #else 146 #else
147 char *server 147 char *server
148 #endif 148 #endif
149 );
150 char *
151 init_play (
152 #ifdef XTOOLKIT
153 Display *display
154 #else
155 char *server
156 #endif
149 ) 157 )
150 { 158 {
151 char *err_message; 159 char *err_message;
152 SIGTYPE (*old_sigpipe) (); 160 SIGTYPE (*old_sigpipe) (int);
153 161
154 #ifdef XTOOLKIT 162 #ifdef XTOOLKIT
155 char * server = DisplayString (display); 163 char * server = DisplayString (display);
156 XtAppContext app_context = XtDisplayToApplicationContext (display); 164 XtAppContext app_context = XtDisplayToApplicationContext (display);
157 165
221 sounds_in_play = 0; 229 sounds_in_play = 0;
222 230
223 return NULL; 231 return NULL;
224 } 232 }
225 233
226 void 234 static void
227 close_down_play (void) 235 close_down_play (void)
228 236
229 { 237 {
230 AuCloseServer (aud); 238 AuCloseServer (aud);
231 warn ("disconnected from audio server"); 239 warn ("disconnected from audio server");
236 * Callback which is run when the sound finishes playing. * 244 * Callback which is run when the sound finishes playing. *
237 * * 245 * *
238 \********************************************************************/ 246 \********************************************************************/
239 247
240 static void 248 static void
241 doneCB (AuServer *aud, 249 doneCB (AuServer *auserver,
242 AuEventHandlerRec *handler, 250 AuEventHandlerRec *handler,
243 AuEvent *ev, 251 AuEvent *ev,
244 AuPointer data) 252 AuPointer data)
245 { 253 {
246 int *in_play_p = (int *) data; 254 int *in_play_p = (int *) data;
272 280
273 list = AuListBuckets (aud, AuCompCommonDescriptionMask, &b, &n, NULL); 281 list = AuListBuckets (aud, AuCompCommonDescriptionMask, &b, &n, NULL);
274 282
275 if (list == NULL) 283 if (list == NULL)
276 { 284 {
277 unsigned char *my_buf; 285 AuPointer my_buf;
278 286
279 if (buf==NULL) 287 if (buf==NULL)
280 { 288 {
281 if ((my_buf=malloc (SoundNumBytes (s)))==NULL) 289 if ((my_buf= (AuPointer) malloc (SoundNumBytes (s)))==NULL)
282 { 290 {
283 return; 291 return;
284 } 292 }
285 293
286 if (SoundReadFile (my_buf, SoundNumBytes (s), s) != SoundNumBytes (s)) 294 if (SoundReadFile ((char *) my_buf, SoundNumBytes (s), s) != SoundNumBytes (s))
287 { 295 {
288 free (my_buf); 296 free (my_buf);
289 return; 297 return;
290 } 298 }
291 } 299 }
292 else 300 else
293 my_buf=buf; 301 my_buf = (AuPointer) buf;
294 302
295 id = AuSoundCreateBucketFromData (aud, 303 id = AuSoundCreateBucketFromData (aud,
296 s, 304 s,
297 my_buf, 305 my_buf,
298 AuAccessAllMasks, 306 AuAccessAllMasks,
320 328
321 } 329 }
322 #endif /* CACHE_SOUNDS */ 330 #endif /* CACHE_SOUNDS */
323 331
324 332
333 void wait_for_sounds (void);
325 void 334 void
326 wait_for_sounds (void) 335 wait_for_sounds (void)
327 336
328 { 337 {
329 AuEvent ev; 338 AuEvent ev;
333 AuNextEvent (aud, AuTrue, &ev); 342 AuNextEvent (aud, AuTrue, &ev);
334 AuDispatchEvent (aud, &ev); 343 AuDispatchEvent (aud, &ev);
335 } 344 }
336 } 345 }
337 346
347 int play_sound_file (char *sound_file, int volume);
338 int 348 int
339 play_sound_file (char *sound_file, 349 play_sound_file (char *sound_file,
340 int volume) 350 int volume)
341 { 351 {
342 SIGTYPE (*old_sigpipe) (); 352 SIGTYPE (*old_sigpipe) (int);
343 353
344 #ifdef ROBUST_PLAY 354 #ifdef ROBUST_PLAY
345 old_sigpipe=signal (SIGPIPE, sigpipe_handle); 355 old_sigpipe=signal (SIGPIPE, sigpipe_handle);
346 if (setjmp (AuXtErrorJump)) 356 if (setjmp (AuXtErrorJump))
347 { 357 {
425 #endif 435 #endif
426 436
427 return 1; 437 return 1;
428 } 438 }
429 439
440 int play_sound_data (unsigned char *data, int length, int volume);
430 int 441 int
431 play_sound_data (unsigned char *data, 442 play_sound_data (unsigned char *data,
432 int length, 443 int length,
433 int volume) 444 int volume)
434 { 445 {
435 Sound s; 446 Sound s;
436 int offset; 447 int offset;
437 SIGTYPE (*old_sigpipe) (); 448 SIGTYPE (*old_sigpipe) (int);
438 449
439 #if !defined (XTEVENTS) 450 #if !defined (XTEVENTS)
440 AuEvent ev; 451 AuEvent ev;
441 #endif 452 #endif
442 453
611 \********************************************************************/ 622 \********************************************************************/
612 623
613 /* Create a name from the sound. */ 624 /* Create a name from the sound. */
614 625
615 static char * 626 static char *
616 NameFromData (CONST unsigned char *buf, 627 NameFromData (CONST char *buf,
617 int len) 628 int len)
618 629
619 { 630 {
620 unsigned char name[9]; 631 char name[9];
621 int i; 632 int i;
622 char *s; 633 char *s;
623 634
624 buf+=len/2; 635 buf+=len/2;
625 len -= len/2; 636 len -= len/2;
640 651
641 name[i]='\0'; 652 name[i]='\0';
642 653
643 if (i==8) 654 if (i==8)
644 { 655 {
645 strcpy (s=malloc (10), name); 656 strcpy (s = (char *) malloc (10), name);
646 } 657 }
647 else 658 else
648 { 659 {
649 strcpy (s=malloc (15), "short sound"); 660 strcpy (s = (char *) malloc (15), "short sound");
650 } 661 }
651 662
652 return s; 663 return s;
653 } 664 }
654 665
727 #define PAD2(_x) (((_x) + 1) & ~1) 738 #define PAD2(_x) (((_x) + 1) & ~1)
728 739
729 /* These functions here are for faking file I/O from buffer. */ 740 /* These functions here are for faking file I/O from buffer. */
730 741
731 /* The "file" position */ 742 /* The "file" position */
732 static int file_posn; 743 static size_t file_posn;
733 /* The length of the "file" */ 744 /* The length of the "file" */
734 static int file_len; 745 static size_t file_len;
735 /* The actual "file" data. */ 746 /* The actual "file" data. */
736 CONST static char* file_data; 747 static CONST void* file_data;
737 748
738 /* Like fopen, but for a buffer in memory */ 749 /* Like fopen, but for a buffer in memory */
739 static void 750 static void
740 dopen(CONST char* data, int length) 751 dopen (CONST void* data, size_t length)
741 { 752 {
742 file_data = data; 753 file_data = data;
743 file_len = length; 754 file_len = length;
744 file_posn = 0; 755 file_posn = 0;
745 } 756 }
746 757
747 /* Like fread, but for a buffer in memory */ 758 /* Like fread, but for a buffer in memory */
748 static int 759 static int
749 dread(char* buf, int size, int nitems) 760 dread (void* buf, size_t size, size_t nitems)
750 { 761 {
751 int nread; 762 size_t nread = size * nitems;
752
753 nread = size * nitems;
754 763
755 if (file_posn + nread <= file_len) 764 if (file_posn + nread <= file_len)
756 { 765 {
757 memcpy(buf, file_data + file_posn, size * nitems); 766 memcpy(buf, (char *) file_data + file_posn, size * nitems);
758 file_posn += nread; 767 file_posn += nread;
759 return nitems; 768 return nitems;
760 } 769 }
761 else 770 else
762 { 771 {
764 } 773 }
765 } 774 }
766 775
767 /* Like fgetc, but for a buffer in memory */ 776 /* Like fgetc, but for a buffer in memory */
768 static int 777 static int
769 dgetc() 778 dgetc (void)
770 { 779 {
771 int ch;
772
773 if (file_posn < file_len) 780 if (file_posn < file_len)
774 return file_data[file_posn++]; 781 return ((char *)file_data)[file_posn++];
775 else 782 else
776 return -1; 783 return -1;
777 } 784 }
778 785
779 /* Like fseek, but for a buffer in memory */ 786 /* Like fseek, but for a buffer in memory */
780 static int 787 static int
781 dseek(long offset, int from) 788 dseek (long offset, int from)
782 { 789 {
783 if (from == 0) 790 if (from == 0)
784 file_posn = offset; 791 file_posn = offset;
785 else if (from == 1) 792 else if (from == 1)
786 file_posn += offset; 793 file_posn += offset;
789 796
790 return 0; 797 return 0;
791 } 798 }
792 799
793 /* Like ftell, but for a buffer in memory */ 800 /* Like ftell, but for a buffer in memory */
794 static int 801 static long
795 dtell() 802 dtell()
796 { 803 {
797 return file_posn; 804 return file_posn;
798 } 805 }
799 806
979 Sound s; 986 Sound s;
980 987
981 if (!(s = (Sound) malloc (sizeof (SoundRec)))) 988 if (!(s = (Sound) malloc (sizeof (SoundRec))))
982 return NULL; 989 return NULL;
983 990
984 if ((s->formatInfo = SndOpenDataForReading (data, length)) != NULL) 991 if ((s->formatInfo = SndOpenDataForReading ((char *) data, length)) != NULL)
985 { 992 {
986 if (!(SoundFileInfo[SoundFileFormatSnd].toSound) (s)) 993 if (!((int(*)(Sound))(SoundFileInfo[SoundFileFormatSnd].toSound)) (s))
987 { 994 {
988 SndCloseFile (s->formatInfo); 995 SndCloseFile ((SndInfo *) (s->formatInfo));
989 free (s); 996 free (s);
990 return NULL; 997 return NULL;
991 } 998 }
992 } 999 }
993 else if ((s->formatInfo = WaveOpenDataForReading (data, length)) != NULL) 1000 else if ((s->formatInfo = WaveOpenDataForReading ((char *) data, length)) != NULL)
994 { 1001 {
995 if (!(SoundFileInfo[SoundFileFormatWave].toSound) (s)) 1002 if (!((int(*)(Sound))(SoundFileInfo[SoundFileFormatWave].toSound)) (s))
996 { 1003 {
997 WaveCloseFile (s->formatInfo); 1004 WaveCloseFile ((WaveInfo *) (s->formatInfo));
998 free (s); 1005 free (s);
999 return NULL; 1006 return NULL;
1000 } 1007 }
1001 } 1008 }
1002 1009
1003 return s; 1010 return s;
1004 } 1011 }
1005