comparison SDL_sound.c @ 118:fd942c1433f8

Fixed for win32 compile.
author Ryan C. Gordon <icculus@icculus.org>
date Sat, 06 Oct 2001 22:09:57 +0000
parents 5e5adbe0f215
children 3e60862fbd76
comparison
equal deleted inserted replaced
117:9778eba22813 118:fd942c1433f8
126 #endif 126 #endif
127 127
128 #if (defined SOUND_SUPPORTS_MIDI) 128 #if (defined SOUND_SUPPORTS_MIDI)
129 { 0, &__Sound_DecoderFunctions_MIDI }, 129 { 0, &__Sound_DecoderFunctions_MIDI },
130 #endif 130 #endif
131
132 { 0, NULL }
131 }; 133 };
132 134
133 135
134 136
135 /* General SDL_sound state ... */ 137 /* General SDL_sound state ... */
161 samplesList = NULL; 163 samplesList = NULL;
162 164
163 SDL_Init(SDL_INIT_AUDIO); 165 SDL_Init(SDL_INIT_AUDIO);
164 166
165 available_decoders = (const Sound_DecoderInfo **) 167 available_decoders = (const Sound_DecoderInfo **)
166 malloc((total + 1) * sizeof (Sound_DecoderInfo *)); 168 malloc((total) * sizeof (Sound_DecoderInfo *));
167 BAIL_IF_MACRO(available_decoders == NULL, ERR_OUT_OF_MEMORY, 0); 169 BAIL_IF_MACRO(available_decoders == NULL, ERR_OUT_OF_MEMORY, 0);
168 170
169 for (i = 0; i < total; i++) 171 for (i = 0; decoders[i].funcs != NULL; i++)
170 { 172 {
171 decoders[i].available = decoders[i].funcs->init(); 173 decoders[i].available = decoders[i].funcs->init();
172 if (decoders[i].available) 174 if (decoders[i].available)
173 { 175 {
174 available_decoders[pos] = &(decoders[i].funcs->info); 176 available_decoders[pos] = &(decoders[i].funcs->info);
183 } /* Sound_Init */ 185 } /* Sound_Init */
184 186
185 187
186 int Sound_Quit(void) 188 int Sound_Quit(void)
187 { 189 {
188 size_t total = sizeof (decoders) / sizeof (decoders[0]);
189 size_t i; 190 size_t i;
190 191
191 BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0); 192 BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0);
192 193
193 while (((volatile Sound_Sample *) samplesList) != NULL) 194 while (((volatile Sound_Sample *) samplesList) != NULL)
194 Sound_FreeSample(samplesList); 195 Sound_FreeSample(samplesList);
195 196
196 for (i = 0; i < total; i++) 197 for (i = 0; decoders[i].funcs != NULL; i++)
197 { 198 {
198 if (decoders[i].available) 199 if (decoders[i].available)
199 { 200 {
200 decoders[i].funcs->quit(); 201 decoders[i].funcs->quit();
201 decoders[i].available = 0; 202 decoders[i].available = 0;
441 442
442 443
443 Sound_Sample *Sound_NewSample(SDL_RWops *rw, const char *ext, 444 Sound_Sample *Sound_NewSample(SDL_RWops *rw, const char *ext,
444 Sound_AudioInfo *desired, Uint32 bSize) 445 Sound_AudioInfo *desired, Uint32 bSize)
445 { 446 {
446 size_t total = sizeof (decoders) / sizeof (decoders[0]);
447 size_t i; 447 size_t i;
448 Sound_Sample *retval; 448 Sound_Sample *retval;
449 449
450 /* sanity checks. */ 450 /* sanity checks. */
451 BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, NULL); 451 BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, NULL);
455 if (!retval) 455 if (!retval)
456 return(NULL); /* alloc_sample() sets error message... */ 456 return(NULL); /* alloc_sample() sets error message... */
457 457
458 if (ext != NULL) 458 if (ext != NULL)
459 { 459 {
460 for (i = 0; i < total; i++) 460 for (i = 0; decoders[i].funcs != NULL; i++)
461 { 461 {
462 if (decoders[i].available) 462 if (decoders[i].available)
463 { 463 {
464 const char *decoderExt = decoders[i].funcs->info.extension; 464 const char *decoderExt = decoders[i].funcs->info.extension;
465 if (__Sound_strcasecmp(decoderExt, ext) == 0) 465 if (__Sound_strcasecmp(decoderExt, ext) == 0)
470 } /* if */ 470 } /* if */
471 } /* for */ 471 } /* for */
472 } /* if */ 472 } /* if */
473 473
474 /* no direct extension match? Try everything we've got... */ 474 /* no direct extension match? Try everything we've got... */
475 for (i = 0; i < total; i++) 475 for (i = 0; decoders[i].funcs != NULL; i++)
476 { 476 {
477 if (decoders[i].available) 477 if (decoders[i].available)
478 { 478 {
479 if (init_sample(decoders[i].funcs, retval, ext, desired)) 479 if (init_sample(decoders[i].funcs, retval, ext, desired))
480 return(retval); 480 return(retval);