Simplify code and clean up Valgrind warning
authorSam Lantinga <slouken@libsdl.org>
Wed, 11 Feb 2004 07:26:29 +0000
changeset 8080defd90ef27c
parent 807 674df5617bba
child 809 dba98fb391e7
Simplify code and clean up Valgrind warning
src/audio/SDL_audio.c
     1.1 --- a/src/audio/SDL_audio.c	Wed Feb 11 07:09:11 2004 +0000
     1.2 +++ b/src/audio/SDL_audio.c	Wed Feb 11 07:26:29 2004 +0000
     1.3 @@ -461,35 +461,29 @@
     1.4  	}
     1.5  
     1.6  	/* See if we need to do any conversion */
     1.7 -	if ( memcmp(desired, &audio->spec, sizeof(audio->spec)) == 0 ) {
     1.8 -		/* Just copy over the desired audio specification */
     1.9 -		if ( obtained != NULL ) {
    1.10 -			memcpy(obtained, &audio->spec, sizeof(audio->spec));
    1.11 +	if ( obtained != NULL ) {
    1.12 +		memcpy(obtained, &audio->spec, sizeof(audio->spec));
    1.13 +	} else if ( desired->freq != audio->spec.freq ||
    1.14 +                    desired->format != audio->spec.format ||
    1.15 +	            desired->channels != audio->spec.channels ) {
    1.16 +		/* Build an audio conversion block */
    1.17 +		if ( SDL_BuildAudioCVT(&audio->convert,
    1.18 +			desired->format, desired->channels,
    1.19 +					desired->freq,
    1.20 +			audio->spec.format, audio->spec.channels,
    1.21 +					audio->spec.freq) < 0 ) {
    1.22 +			SDL_CloseAudio();
    1.23 +			return(-1);
    1.24  		}
    1.25 -	} else {
    1.26 -		/* Copy over the audio specification if possible */
    1.27 -		if ( obtained != NULL ) {
    1.28 -			memcpy(obtained, &audio->spec, sizeof(audio->spec));
    1.29 -		} else {
    1.30 -			/* Build an audio conversion block */
    1.31 -			if ( SDL_BuildAudioCVT(&audio->convert,
    1.32 -				desired->format, desired->channels,
    1.33 -						desired->freq,
    1.34 -				audio->spec.format, audio->spec.channels,
    1.35 -						audio->spec.freq) < 0 ) {
    1.36 +		if ( audio->convert.needed ) {
    1.37 +			audio->convert.len = desired->size;
    1.38 +			audio->convert.buf =(Uint8 *)SDL_AllocAudioMem(
    1.39 +			   audio->convert.len*audio->convert.len_mult);
    1.40 +			if ( audio->convert.buf == NULL ) {
    1.41  				SDL_CloseAudio();
    1.42 +				SDL_OutOfMemory();
    1.43  				return(-1);
    1.44  			}
    1.45 -			if ( audio->convert.needed ) {
    1.46 -				audio->convert.len = desired->size;
    1.47 -				audio->convert.buf =(Uint8 *)SDL_AllocAudioMem(
    1.48 -				   audio->convert.len*audio->convert.len_mult);
    1.49 -				if ( audio->convert.buf == NULL ) {
    1.50 -					SDL_CloseAudio();
    1.51 -					SDL_OutOfMemory();
    1.52 -					return(-1);
    1.53 -				}
    1.54 -			}
    1.55  		}
    1.56  	}
    1.57