comparison playsound/playsound.c @ 176:69922f6a5c74

Added GNU disclaimers and a --credits option with our names.
author Ryan C. Gordon <icculus@icculus.org>
date Wed, 05 Dec 2001 10:05:09 +0000
parents 87b00f023710
children 47cc2de2ae36
comparison
equal deleted inserted replaced
175:865c17682d8f 176:69922f6a5c74
47 SOUND_VERSION(&compiled); 47 SOUND_VERSION(&compiled);
48 Sound_GetLinkedVersion(&linked); 48 Sound_GetLinkedVersion(&linked);
49 SDL_VERSION(&sdl_compiled); 49 SDL_VERSION(&sdl_compiled);
50 sdl_linked = SDL_Linked_Version(); 50 sdl_linked = SDL_Linked_Version();
51 51
52 printf("%s version %d.%d.%d.\n" 52 printf("%s version %d.%d.%d\n"
53 "Copyright 2001 Ryan C. Gordon\n"
54 "This program is free software, covered by the GNU Lesser General\n"
55 "Public License, and you are welcome to change it and/or\n"
56 "distribute copies of it under certain conditions. There is\n"
57 "absolutely NO WARRANTY for this program.\n"
58 "\n"
53 " Compiled against SDL_sound version %d.%d.%d,\n" 59 " Compiled against SDL_sound version %d.%d.%d,\n"
54 " and linked against %d.%d.%d.\n" 60 " and linked against %d.%d.%d.\n"
55 " Compiled against SDL version %d.%d.%d,\n" 61 " Compiled against SDL version %d.%d.%d,\n"
56 " and linked against %d.%d.%d.\n\n", 62 " and linked against %d.%d.%d.\n\n",
57 argv0, 63 argv0,
85 91
86 printf("\n"); 92 printf("\n");
87 } /* output_decoders */ 93 } /* output_decoders */
88 94
89 95
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
116
117 static Uint8 *decoded_ptr = NULL;
118 static Uint32 decoded_bytes = 0;
119
120 static void audio_callback(void *userdata, Uint8 *stream, int len)
121 {
122 Sound_Sample *sample = (Sound_Sample *) userdata;
123 int bw = 0; /* bytes written to stream this time through the callback */
124
125 while (bw < len)
126 {
127 int cpysize; /* bytes to copy on this iteration of the loop. */
128
129 if (!decoded_bytes) /* need more data decoded from sample? */
130 {
131 if (sample->flags & (SOUND_SAMPLEFLAG_ERROR|SOUND_SAMPLEFLAG_EOF))
132 {
133 /* ...but there isn't any more data to decode! */
134 memset(stream + bw, '\0', len - bw);
135 done_flag = 1;
136 return;
137 } /* if */
138
139 decoded_bytes = Sound_Decode(sample);
140 decoded_ptr = sample->buffer;
141 } /* if */
142
143 cpysize = len - bw;
144 if (cpysize > decoded_bytes)
145 cpysize = decoded_bytes;
146
147 if (cpysize > 0)
148 {
149 memcpy(stream + bw, decoded_ptr, cpysize);
150 bw += cpysize;
151 decoded_ptr += cpysize;
152 decoded_bytes -= cpysize;
153 } /* if */
154 } /* while */
155 } /* audio_callback */
156
157
158 static void output_usage(const char *argv0) 96 static void output_usage(const char *argv0)
159 { 97 {
160 fprintf(stderr, 98 fprintf(stderr,
161 "USAGE: %s [...options...] [soundFile1] ... [soundFileN]\n" 99 "USAGE: %s [...options...] [soundFile1] ... [soundFileN]\n"
162 "\n" 100 "\n"
165 " --format fmt Playback in fmt format (see below).\n" 103 " --format fmt Playback in fmt format (see below).\n"
166 " --channels n Playback on n channels (1 or 2).\n" 104 " --channels n Playback on n channels (1 or 2).\n"
167 " --version Display version information and exit.\n" 105 " --version Display version information and exit.\n"
168 " --decoders List supported sound formats and exit.\n" 106 " --decoders List supported sound formats and exit.\n"
169 " --predecode Decode entire sample before playback.\n" 107 " --predecode Decode entire sample before playback.\n"
108 " --credits Shameless promotion.\n"
170 " --help Display this information and exit.\n" 109 " --help Display this information and exit.\n"
171 "\n" 110 "\n"
172 " Valid arguments to the --format option are:\n" 111 " Valid arguments to the --format option are:\n"
173 " U8 Unsigned 8-bit.\n" 112 " U8 Unsigned 8-bit.\n"
174 " S8 Signed 8-bit.\n" 113 " S8 Signed 8-bit.\n"
177 " S16LSB Signed 16-bit (least significant byte first).\n" 116 " S16LSB Signed 16-bit (least significant byte first).\n"
178 " S16MSB Signed 16-bit (most significant byte first).\n" 117 " S16MSB Signed 16-bit (most significant byte first).\n"
179 "\n", 118 "\n",
180 argv0); 119 argv0);
181 } /* output_usage */ 120 } /* output_usage */
121
122
123 static void output_credits(void)
124 {
125 printf("playsound version %d.%d.%d\n"
126 "Copyright 2001 Ryan C. Gordon\n"
127 "playsound is free software, covered by the GNU Lesser General\n"
128 "Public License, and you are welcome to change it and/or\n"
129 "distribute copies of it under certain conditions. There is\n"
130 "absolutely NO WARRANTY for playsound.\n"
131 "\n"
132 " Written by Ryan C. Gordon, Torbjörn Andersson, Max Horn,\n"
133 " Tsuyoshi Iguchi, Tyler Montbriand, and a cast of thousands.\n"
134 "\n"
135 " Website and source code: http://icculus.org/SDL_sound/\n"
136 "\n",
137 PLAYSOUND_VER_MAJOR, PLAYSOUND_VER_MINOR, PLAYSOUND_VER_PATCH);
138 } /* output_credits */
139
140
141
142 static volatile int done_flag = 0;
143
144
145 void sigint_catcher(int signum)
146 {
147 static Uint32 last_sigint = 0;
148 Uint32 ticks = SDL_GetTicks();
149
150 assert(signum == SIGINT);
151
152 if ((last_sigint != 0) && (ticks - last_sigint < 500))
153 {
154 SDL_PauseAudio(1);
155 SDL_CloseAudio();
156 Sound_Quit();
157 SDL_Quit();
158 exit(1);
159 } /* if */
160
161 else
162 {
163 last_sigint = ticks;
164 done_flag = 1;
165 } /* else */
166 } /* sigint_catcher */
167
168
169 static Uint8 *decoded_ptr = NULL;
170 static Uint32 decoded_bytes = 0;
171
172 static void audio_callback(void *userdata, Uint8 *stream, int len)
173 {
174 Sound_Sample *sample = (Sound_Sample *) userdata;
175 int bw = 0; /* bytes written to stream this time through the callback */
176
177 while (bw < len)
178 {
179 int cpysize; /* bytes to copy on this iteration of the loop. */
180
181 if (!decoded_bytes) /* need more data decoded from sample? */
182 {
183 if (sample->flags & (SOUND_SAMPLEFLAG_ERROR|SOUND_SAMPLEFLAG_EOF))
184 {
185 /* ...but there isn't any more data to decode! */
186 memset(stream + bw, '\0', len - bw);
187 done_flag = 1;
188 return;
189 } /* if */
190
191 decoded_bytes = Sound_Decode(sample);
192 decoded_ptr = sample->buffer;
193 } /* if */
194
195 cpysize = len - bw;
196 if (cpysize > decoded_bytes)
197 cpysize = decoded_bytes;
198
199 if (cpysize > 0)
200 {
201 memcpy(stream + bw, decoded_ptr, cpysize);
202 bw += cpysize;
203 decoded_ptr += cpysize;
204 decoded_bytes -= cpysize;
205 } /* if */
206 } /* while */
207 } /* audio_callback */
182 208
183 209
184 static int str_to_fmt(char *str) 210 static int str_to_fmt(char *str)
185 { 211 {
186 if (strcmp(str, "U8") == 0) 212 if (strcmp(str, "U8") == 0)
230 { 256 {
231 output_versions(argv[0]); 257 output_versions(argv[0]);
232 return(42); 258 return(42);
233 } /* if */ 259 } /* if */
234 260
261 if (strcmp(argv[i], "--credits") == 0)
262 {
263 output_credits();
264 return(42);
265 } /* if */
266
235 else if (strcmp(argv[i], "--help") == 0) 267 else if (strcmp(argv[i], "--help") == 0)
236 { 268 {
237 output_usage(argv[0]); 269 output_usage(argv[0]);
238 return(42); 270 return(42);
239 } /* if */ 271 } /* if */