comparison src/audio/SDL_audio.c @ 808:0defd90ef27c

Simplify code and clean up Valgrind warning
author Sam Lantinga <slouken@libsdl.org>
date Wed, 11 Feb 2004 07:26:29 +0000
parents b8d311d90021
children f8d5ddc7aef1
comparison
equal deleted inserted replaced
807:674df5617bba 808:0defd90ef27c
459 SDL_OutOfMemory(); 459 SDL_OutOfMemory();
460 return(-1); 460 return(-1);
461 } 461 }
462 462
463 /* See if we need to do any conversion */ 463 /* See if we need to do any conversion */
464 if ( memcmp(desired, &audio->spec, sizeof(audio->spec)) == 0 ) { 464 if ( obtained != NULL ) {
465 /* Just copy over the desired audio specification */ 465 memcpy(obtained, &audio->spec, sizeof(audio->spec));
466 if ( obtained != NULL ) { 466 } else if ( desired->freq != audio->spec.freq ||
467 memcpy(obtained, &audio->spec, sizeof(audio->spec)); 467 desired->format != audio->spec.format ||
468 } 468 desired->channels != audio->spec.channels ) {
469 } else { 469 /* Build an audio conversion block */
470 /* Copy over the audio specification if possible */ 470 if ( SDL_BuildAudioCVT(&audio->convert,
471 if ( obtained != NULL ) { 471 desired->format, desired->channels,
472 memcpy(obtained, &audio->spec, sizeof(audio->spec)); 472 desired->freq,
473 } else { 473 audio->spec.format, audio->spec.channels,
474 /* Build an audio conversion block */ 474 audio->spec.freq) < 0 ) {
475 if ( SDL_BuildAudioCVT(&audio->convert, 475 SDL_CloseAudio();
476 desired->format, desired->channels, 476 return(-1);
477 desired->freq, 477 }
478 audio->spec.format, audio->spec.channels, 478 if ( audio->convert.needed ) {
479 audio->spec.freq) < 0 ) { 479 audio->convert.len = desired->size;
480 audio->convert.buf =(Uint8 *)SDL_AllocAudioMem(
481 audio->convert.len*audio->convert.len_mult);
482 if ( audio->convert.buf == NULL ) {
480 SDL_CloseAudio(); 483 SDL_CloseAudio();
484 SDL_OutOfMemory();
481 return(-1); 485 return(-1);
482 }
483 if ( audio->convert.needed ) {
484 audio->convert.len = desired->size;
485 audio->convert.buf =(Uint8 *)SDL_AllocAudioMem(
486 audio->convert.len*audio->convert.len_mult);
487 if ( audio->convert.buf == NULL ) {
488 SDL_CloseAudio();
489 SDL_OutOfMemory();
490 return(-1);
491 }
492 } 486 }
493 } 487 }
494 } 488 }
495 489
496 #ifndef ENABLE_AHI 490 #ifndef ENABLE_AHI