comparison playsound/playsound.c @ 148:d51546293fd1

Support for multiple file extensions in the decoders, and a SIGINT catcher.
author Ryan C. Gordon <icculus@icculus.org>
date Thu, 01 Nov 2001 19:12:36 +0000
parents 023c3e7f028b
children 033afe96afbc
comparison
equal deleted inserted replaced
147:9d122da5f5a9 148:d51546293fd1
26 */ 26 */
27 27
28 #include <stdio.h> 28 #include <stdio.h>
29 #include <string.h> 29 #include <string.h>
30 #include <assert.h> 30 #include <assert.h>
31 #include <signal.h>
31 #include "SDL.h" 32 #include "SDL.h"
32 #include "SDL_sound.h" 33 #include "SDL_sound.h"
33 34
34 #define PLAYSOUND_VER_MAJOR 0 35 #define PLAYSOUND_VER_MAJOR 0
35 #define PLAYSOUND_VER_MINOR 1 36 #define PLAYSOUND_VER_MINOR 1
46 SOUND_VERSION(&compiled); 47 SOUND_VERSION(&compiled);
47 Sound_GetLinkedVersion(&linked); 48 Sound_GetLinkedVersion(&linked);
48 SDL_VERSION(&sdl_compiled); 49 SDL_VERSION(&sdl_compiled);
49 sdl_linked = SDL_Linked_Version(); 50 sdl_linked = SDL_Linked_Version();
50 51
51 fprintf(stderr, 52 printf("%s version %d.%d.%d.\n"
52 "%s version %d.%d.%d.\n" 53 " Compiled against SDL_sound version %d.%d.%d,\n"
53 " Compiled against SDL_sound version %d.%d.%d,\n" 54 " and linked against %d.%d.%d.\n"
54 " and linked against %d.%d.%d.\n" 55 " Compiled against SDL version %d.%d.%d,\n"
55 " Compiled against SDL version %d.%d.%d,\n" 56 " and linked against %d.%d.%d.\n\n",
56 " and linked against %d.%d.%d.\n\n",
57 argv0, 57 argv0,
58 PLAYSOUND_VER_MAJOR, PLAYSOUND_VER_MINOR, PLAYSOUND_VER_PATCH, 58 PLAYSOUND_VER_MAJOR, PLAYSOUND_VER_MINOR, PLAYSOUND_VER_PATCH,
59 compiled.major, compiled.minor, compiled.patch, 59 compiled.major, compiled.minor, compiled.patch,
60 linked.major, linked.minor, linked.patch, 60 linked.major, linked.minor, linked.patch,
61 sdl_compiled.major, sdl_compiled.minor, sdl_compiled.patch, 61 sdl_compiled.major, sdl_compiled.minor, sdl_compiled.patch,
65 65
66 static void output_decoders(void) 66 static void output_decoders(void)
67 { 67 {
68 const Sound_DecoderInfo **rc = Sound_AvailableDecoders(); 68 const Sound_DecoderInfo **rc = Sound_AvailableDecoders();
69 const Sound_DecoderInfo **i; 69 const Sound_DecoderInfo **i;
70 70 const char **ext;
71 fprintf(stderr, "Supported sound formats:\n"); 71
72 printf("Supported sound formats:\n");
72 if (rc == NULL) 73 if (rc == NULL)
73 fprintf(stderr, " * Apparently, NONE!\n"); 74 printf(" * Apparently, NONE!\n");
74 else 75 else
75 { 76 {
76 for (i = rc; *i != NULL; i++) 77 for (i = rc; *i != NULL; i++)
77 { 78 {
78 fprintf(stderr, " * %s: %s\n Written by %s.\n %s\n", 79 printf(" * %s\n", (*i)->description);
79 (*i)->extension, (*i)->description, 80 for (ext = (*i)->extensions; *ext != NULL; ext++)
80 (*i)->author, (*i)->url); 81 printf(" Extension \"%s\"\n", *ext);
82 printf(" Written by %s.\n %s\n\n", (*i)->author, (*i)->url);
81 } /* for */ 83 } /* for */
82 } /* else */ 84 } /* else */
83 85
84 fprintf(stderr, "\n"); 86 printf("\n");
85 } /* output_decoders */ 87 } /* output_decoders */
86 88
87 89
88 static volatile int done_flag = 0; 90 static volatile int done_flag = 0;
91
92
93 void sigint_catcher(int signum)
94 {
95 static Uint32 last_sigint = 0;
96 Uint32 ticks = SDL_GetTicks();
97
98 assert(signum == SIGINT);
99
100 if ((last_sigint != 0) && (ticks - last_sigint < 500))
101 {
102 SDL_PauseAudio(1);
103 SDL_CloseAudio();
104 Sound_Quit();
105 SDL_Quit();
106 exit(1);
107 } /* if */
108
109 else
110 {
111 last_sigint = ticks;
112 done_flag = 1;
113 } /* else */
114 } /* sigint_catcher */
115
89 116
90 static Uint8 *decoded_ptr = NULL; 117 static Uint8 *decoded_ptr = NULL;
91 static Uint32 decoded_bytes = 0; 118 static Uint32 decoded_bytes = 0;
92 119
93 static void audio_callback(void *userdata, Uint8 *stream, int len) 120 static void audio_callback(void *userdata, Uint8 *stream, int len)
286 " reason: [%s].\n", Sound_GetError()); 313 " reason: [%s].\n", Sound_GetError());
287 SDL_Quit(); 314 SDL_Quit();
288 return(42); 315 return(42);
289 } /* if */ 316 } /* if */
290 317
318 signal(SIGINT, sigint_catcher);
319
291 for (i = 1; i < argc; i++) 320 for (i = 1; i < argc; i++)
292 { 321 {
293 /* !!! FIXME: This is ugly! */ 322 /* !!! FIXME: This is ugly! */
294 if ( (strcmp(argv[i], "--rate") == 0) || 323 if ( (strcmp(argv[i], "--rate") == 0) ||
295 (strcmp(argv[i], "--format") == 0) || 324 (strcmp(argv[i], "--format") == 0) ||