comparison playsound/playsound.c @ 377:cbb15ecf423a

WinCE (PocketPC) patches from Tyler.
author Ryan C. Gordon <icculus@icculus.org>
date Tue, 02 Jul 2002 03:58:24 +0000
parents 03f47480200f
children 818f9af97a19
comparison
equal deleted inserted replaced
376:51883cd1193e 377:cbb15ecf423a
23 * Please see the file COPYING in the source's root directory. 23 * Please see the file COPYING in the source's root directory.
24 * 24 *
25 * This file written by Ryan C. Gordon. (icculus@clutteredmind.org) 25 * This file written by Ryan C. Gordon. (icculus@clutteredmind.org)
26 */ 26 */
27 27
28 #if HAVE_CONFIG_H
29 # include <config.h>
30 #endif
31
28 #include <stdio.h> 32 #include <stdio.h>
29 #include <stdlib.h> 33 #include <stdlib.h>
30 #include <string.h> 34 #include <string.h>
31 #include <assert.h> 35
32 #include <signal.h> 36 #if HAVE_ASSERT_H
37 # include <assert.h>
38 #elif (!defined assert)
39 # define assert(x)
40 #endif
41
42 #if HAVE_SIGNAL_H
43 # include <signal.h>
44 #endif
45
33 #include "SDL.h" 46 #include "SDL.h"
34 #include "SDL_sound.h" 47 #include "SDL_sound.h"
35 48
36 #if SUPPORT_PHYSFS 49 #if SUPPORT_PHYSFS
37 #include "physfs.h" 50 #include "physfs.h"
55 SOUND_VERSION(&compiled); 68 SOUND_VERSION(&compiled);
56 Sound_GetLinkedVersion(&linked); 69 Sound_GetLinkedVersion(&linked);
57 SDL_VERSION(&sdl_compiled); 70 SDL_VERSION(&sdl_compiled);
58 sdl_linked = SDL_Linked_Version(); 71 sdl_linked = SDL_Linked_Version();
59 72
60 printf("%s version %d.%d.%d\n" 73 fprintf(stdout,
74 "%s version %d.%d.%d\n"
61 "Copyright 2001 Ryan C. Gordon\n" 75 "Copyright 2001 Ryan C. Gordon\n"
62 "This program is free software, covered by the GNU Lesser General\n" 76 "This program is free software, covered by the GNU Lesser General\n"
63 "Public License, and you are welcome to change it and/or\n" 77 "Public License, and you are welcome to change it and/or\n"
64 "distribute copies of it under certain conditions. There is\n" 78 "distribute copies of it under certain conditions. There is\n"
65 "absolutely NO WARRANTY for this program.\n" 79 "absolutely NO WARRANTY for this program.\n"
81 { 95 {
82 const Sound_DecoderInfo **rc = Sound_AvailableDecoders(); 96 const Sound_DecoderInfo **rc = Sound_AvailableDecoders();
83 const Sound_DecoderInfo **i; 97 const Sound_DecoderInfo **i;
84 const char **ext; 98 const char **ext;
85 99
86 printf("Supported sound formats:\n"); 100 fprintf(stdout, "Supported sound formats:\n");
87 if (rc == NULL) 101 if (rc == NULL)
88 printf(" * Apparently, NONE!\n"); 102 fprintf(stdout, " * Apparently, NONE!\n");
89 else 103 else
90 { 104 {
91 for (i = rc; *i != NULL; i++) 105 for (i = rc; *i != NULL; i++)
92 { 106 {
93 printf(" * %s\n", (*i)->description); 107 fprintf(stdout, " * %s\n", (*i)->description);
108
94 for (ext = (*i)->extensions; *ext != NULL; ext++) 109 for (ext = (*i)->extensions; *ext != NULL; ext++)
95 printf(" File extension \"%s\"\n", *ext); 110 fprintf(stdout, " File extension \"%s\"\n", *ext);
96 printf(" Written by %s.\n %s\n\n", (*i)->author, (*i)->url); 111
112 fprintf(stdout, " Written by %s.\n %s\n\n",
113 (*i)->author, (*i)->url);
97 } /* for */ 114 } /* for */
98 } /* else */ 115 } /* else */
99 116
100 printf("\n"); 117 fprintf(stdout, "\n");
101 } /* output_decoders */ 118 } /* output_decoders */
102 119
103 120
104 static void output_usage(const char *argv0) 121 static void output_usage(const char *argv0)
105 { 122 {
145 } /* output_usage */ 162 } /* output_usage */
146 163
147 164
148 static void output_credits(void) 165 static void output_credits(void)
149 { 166 {
150 printf("playsound version %d.%d.%d\n" 167 fprintf(stdout,
168 "playsound version %d.%d.%d\n"
151 "Copyright 2001 Ryan C. Gordon\n" 169 "Copyright 2001 Ryan C. Gordon\n"
152 "playsound is free software, covered by the GNU Lesser General\n" 170 "playsound is free software, covered by the GNU Lesser General\n"
153 "Public License, and you are welcome to change it and/or\n" 171 "Public License, and you are welcome to change it and/or\n"
154 "distribute copies of it under certain conditions. There is\n" 172 "distribute copies of it under certain conditions. There is\n"
155 "absolutely NO WARRANTY for playsound.\n" 173 "absolutely NO WARRANTY for playsound.\n"
267 285
268 286
269 287
270 static volatile int done_flag = 0; 288 static volatile int done_flag = 0;
271 289
272 290 #if HAVE_SIGNAL_H
273 void sigint_catcher(int signum) 291 void sigint_catcher(int signum)
274 { 292 {
275 static Uint32 last_sigint = 0; 293 static Uint32 last_sigint = 0;
276 Uint32 ticks = SDL_GetTicks(); 294 Uint32 ticks = SDL_GetTicks();
277 295
291 { 309 {
292 last_sigint = ticks; 310 last_sigint = ticks;
293 done_flag = 1; 311 done_flag = 1;
294 } /* else */ 312 } /* else */
295 } /* sigint_catcher */ 313 } /* sigint_catcher */
314 #endif
296 315
297 316
298 /* global decoding state. */ 317 /* global decoding state. */
299 /* !!! FIXME: Put this in a struct and pass a pointer to it as the 318 /* !!! FIXME: Put this in a struct and pass a pointer to it as the
300 * !!! FIXME: audio callback's argument. This will clean up the 319 * !!! FIXME: audio callback's argument. This will clean up the
322 } /* cvtMsToBytePos */ 341 } /* cvtMsToBytePos */
323 342
324 343
325 static void do_seek(Sound_Sample *sample) 344 static void do_seek(Sound_Sample *sample)
326 { 345 {
327 printf("Seeking to %.2d:%.2d:%.4d...\n", 346 fprintf(stdout, "Seeking to %.2d:%.2d:%.4d...\n",
328 (int) ((seek_list[seek_index] / 1000) / 60), 347 (int) ((seek_list[seek_index] / 1000) / 60),
329 (int) ((seek_list[seek_index] / 1000) % 60), 348 (int) ((seek_list[seek_index] / 1000) % 60),
330 (int) ((seek_list[seek_index] % 1000))); 349 (int) ((seek_list[seek_index] % 1000)));
331 350
332 if (predecode) 351 if (predecode)
650 int use_specific_audiofmt = 0; 669 int use_specific_audiofmt = 0;
651 int i; 670 int i;
652 int delay; 671 int delay;
653 int new_sample = 1; 672 int new_sample = 1;
654 673
655 setbuf(stdout, NULL); 674 #ifdef HAVE_SETBUF
656 setbuf(stderr, NULL); 675 setbuf(stdout, NULL);
676 setbuf(stderr, NULL);
677 #endif
657 678
658 if (argc < 2) 679 if (argc < 2)
659 { 680 {
660 output_usage(argv[0]); 681 output_usage(argv[0]);
661 return(42); 682 return(42);
726 " reason: [%s].\n", Sound_GetError()); 747 " reason: [%s].\n", Sound_GetError());
727 SDL_Quit(); 748 SDL_Quit();
728 return(42); 749 return(42);
729 } /* if */ 750 } /* if */
730 751
731 signal(SIGINT, sigint_catcher); 752 #if HAVE_SIGNAL_H
753 signal(SIGINT, sigint_catcher);
754 #endif
732 755
733 for (i = 1; i < argc; i++) 756 for (i = 1; i < argc; i++)
734 { 757 {
735 char *filename = NULL; 758 char *filename = NULL;
736 759
917 Sound_Quit(); 940 Sound_Quit();
918 SDL_Quit(); 941 SDL_Quit();
919 return(42); 942 return(42);
920 } /* if */ 943 } /* if */
921 944
922 printf("Now playing [%s]...\n", filename); 945 fprintf(stdout, "Now playing [%s]...\n", filename);
923 946
924 if (predecode) 947 if (predecode)
925 { 948 {
926 printf(" predecoding..."); 949 fprintf(stdout, " predecoding...");
927 decoded_bytes = Sound_DecodeAll(sample); 950 decoded_bytes = Sound_DecodeAll(sample);
928 decoded_ptr = sample->buffer; 951 decoded_ptr = sample->buffer;
929 if (sample->flags & SOUND_SAMPLEFLAG_ERROR) 952 if (sample->flags & SOUND_SAMPLEFLAG_ERROR)
930 { 953 {
931 fprintf(stderr, 954 fprintf(stderr,
934 " (playing first %lu bytes of decoded data...)\n", 957 " (playing first %lu bytes of decoded data...)\n",
935 filename, Sound_GetError(), decoded_bytes); 958 filename, Sound_GetError(), decoded_bytes);
936 } /* if */ 959 } /* if */
937 else 960 else
938 { 961 {
939 printf("done.\n"); 962 fprintf(stdout, "done.\n");
940 } /* else */ 963 } /* else */
941 } /* if */ 964 } /* if */
942 965
943 SDL_PauseAudio(0); 966 SDL_PauseAudio(0);
944 #if ENABLE_EVENTS 967 #if ENABLE_EVENTS