Cleaned up some bugs, but the FIR filter is still distorting. gsoc2008_audio_resampling
authorAaron Wishnick <schnarf@gmail.com>
Wed, 02 Jul 2008 07:25:02 +0000
branchgsoc2008_audio_resampling
changeset 2660a55543cef395
parent 2659 8da698bc1205
child 2661 d38309be5178
Cleaned up some bugs, but the FIR filter is still distorting.
src/audio/SDL_audiocvt.c
     1.1 --- a/src/audio/SDL_audiocvt.c	Sun Jun 22 00:36:35 2008 +0000
     1.2 +++ b/src/audio/SDL_audiocvt.c	Wed Jul 02 07:25:02 2008 +0000
     1.3 @@ -1550,7 +1550,7 @@
     1.4  			} \
     1.5  		}
     1.6  	
     1.7 -	/* If it's floating point, we don't need to do any shifting */
     1.8 +	/* If it's floating point, do it normally, otherwise used fixed-point code */
     1.9  	if(SDL_AUDIO_ISFLOAT(format) && SDL_AUDIO_BITSIZE(format) == 32) {
    1.10  		float *sinc = (float *)cvt->coeff;
    1.11  		float *state = (float *)cvt->state_buf;
    1.12 @@ -1561,7 +1561,7 @@
    1.13  			if(cvt->state_pos == m) cvt->state_pos = 0;
    1.14  			buf[i] = 0.0f;
    1.15  			for(j = 0; j < m; ++j) {
    1.16 -				buf[i] += state[j] * sinc[j];
    1.17 +				buf[i] += state[(cvt->state_pos - j) % m] * sinc[j];
    1.18  			}
    1.19  		}
    1.20  	} else {
    1.21 @@ -1628,20 +1628,17 @@
    1.22  			/* Apply blackman window */
    1.23  			fSinc[i] *= 0.42f - 0.5f * cosf(two_pi_over_m * (float)i) + 0.08f * cosf(four_pi_over_m * (float)i);
    1.24  		}
    1.25 -		norm_sum += abs(fSinc[i]);
    1.26 +		fSinc[i] = 0.0f;
    1.27 +		norm_sum += fabs(fSinc[i]);
    1.28  		printf("%f\n", fSinc[i]);
    1.29  	}
    1.30 -
    1.31 -	/* Now normalize and convert to fixed point. We scale everything to half the precision
    1.32 -	   of whatever datatype we're using, for example, 16 bit data means we use 8 bits */
    1.33 -	
    1.34 +		
    1.35  #define convert_fixed(type, fix) { \
    1.36 -		norm_fact = 0.9f / norm_sum; \
    1.37 -		norm_fact = 0.15f; \
    1.38 +		norm_fact = 0.8f / norm_sum; \
    1.39  		type *dst = (type *)cvt->coeff; \
    1.40  		for( i = 0; i <= m; ++i ) { \
    1.41  			dst[i] = fix(fSinc[i] * norm_fact); \
    1.42 -			printf("%f = 0x%x\n", fSinc[i], dst[i]); \
    1.43 +			printf("%f = 0x%x\n", fSinc[i] * norm_fact, dst[i]); \
    1.44  		} \
    1.45  	}
    1.46  	
    1.47 @@ -1720,7 +1717,7 @@
    1.48      }
    1.49  
    1.50  	// Step 1: Zero stuff the conversion buffer
    1.51 -#ifdef DEBUG_CONVERT
    1.52 +/*#ifdef DEBUG_CONVERT
    1.53  	printf("Zero-stuffing by a factor of %u\n", cvt->len_mult);
    1.54  #endif
    1.55      switch (SDL_AUDIO_BITSIZE(format)) {
    1.56 @@ -1735,13 +1732,13 @@
    1.57          break;
    1.58      }
    1.59  	
    1.60 -	cvt->len_cvt *= cvt->len_mult;
    1.61 +	cvt->len_cvt *= cvt->len_mult;*/
    1.62  
    1.63  	// Step 2: Use either a windowed sinc FIR filter or IIR lowpass filter to remove all alias frequencies
    1.64  	SDL_FilterFIR( cvt, format );
    1.65  	
    1.66  	// Step 3: Discard unnecessary samples
    1.67 -#ifdef DEBUG_CONVERT
    1.68 +/*#ifdef DEBUG_CONVERT
    1.69  	printf("Discarding samples by a factor of %u\n", cvt->len_div);
    1.70  #endif
    1.71      switch (SDL_AUDIO_BITSIZE(format)) {
    1.72 @@ -1759,7 +1756,7 @@
    1.73  #undef zerostuff_mono
    1.74  #undef discard_mono
    1.75  
    1.76 -    cvt->len_cvt /= cvt->len_div;
    1.77 +    cvt->len_cvt /= cvt->len_div;*/
    1.78  	
    1.79      if (cvt->filters[++cvt->filter_index]) {
    1.80          cvt->filters[cvt->filter_index] (cvt, format);