Mercurial > sdl-ios-xcode
diff src/audio/SDL_audiocvt.c @ 2660:a55543cef395 gsoc2008_audio_resampling
Cleaned up some bugs, but the FIR filter is still distorting.
author | Aaron Wishnick <schnarf@gmail.com> |
---|---|
date | Wed, 02 Jul 2008 07:25:02 +0000 |
parents | 8da698bc1205 |
children | d38309be5178 |
line wrap: on
line diff
--- a/src/audio/SDL_audiocvt.c Sun Jun 22 00:36:35 2008 +0000 +++ b/src/audio/SDL_audiocvt.c Wed Jul 02 07:25:02 2008 +0000 @@ -1550,7 +1550,7 @@ } \ } - /* If it's floating point, we don't need to do any shifting */ + /* If it's floating point, do it normally, otherwise used fixed-point code */ if(SDL_AUDIO_ISFLOAT(format) && SDL_AUDIO_BITSIZE(format) == 32) { float *sinc = (float *)cvt->coeff; float *state = (float *)cvt->state_buf; @@ -1561,7 +1561,7 @@ if(cvt->state_pos == m) cvt->state_pos = 0; buf[i] = 0.0f; for(j = 0; j < m; ++j) { - buf[i] += state[j] * sinc[j]; + buf[i] += state[(cvt->state_pos - j) % m] * sinc[j]; } } } else { @@ -1628,20 +1628,17 @@ /* Apply blackman window */ fSinc[i] *= 0.42f - 0.5f * cosf(two_pi_over_m * (float)i) + 0.08f * cosf(four_pi_over_m * (float)i); } - norm_sum += abs(fSinc[i]); + fSinc[i] = 0.0f; + norm_sum += fabs(fSinc[i]); printf("%f\n", fSinc[i]); } - - /* Now normalize and convert to fixed point. We scale everything to half the precision - of whatever datatype we're using, for example, 16 bit data means we use 8 bits */ - + #define convert_fixed(type, fix) { \ - norm_fact = 0.9f / norm_sum; \ - norm_fact = 0.15f; \ + norm_fact = 0.8f / norm_sum; \ type *dst = (type *)cvt->coeff; \ for( i = 0; i <= m; ++i ) { \ dst[i] = fix(fSinc[i] * norm_fact); \ - printf("%f = 0x%x\n", fSinc[i], dst[i]); \ + printf("%f = 0x%x\n", fSinc[i] * norm_fact, dst[i]); \ } \ } @@ -1720,7 +1717,7 @@ } // Step 1: Zero stuff the conversion buffer -#ifdef DEBUG_CONVERT +/*#ifdef DEBUG_CONVERT printf("Zero-stuffing by a factor of %u\n", cvt->len_mult); #endif switch (SDL_AUDIO_BITSIZE(format)) { @@ -1735,13 +1732,13 @@ break; } - cvt->len_cvt *= cvt->len_mult; + cvt->len_cvt *= cvt->len_mult;*/ // Step 2: Use either a windowed sinc FIR filter or IIR lowpass filter to remove all alias frequencies SDL_FilterFIR( cvt, format ); // Step 3: Discard unnecessary samples -#ifdef DEBUG_CONVERT +/*#ifdef DEBUG_CONVERT printf("Discarding samples by a factor of %u\n", cvt->len_div); #endif switch (SDL_AUDIO_BITSIZE(format)) { @@ -1759,7 +1756,7 @@ #undef zerostuff_mono #undef discard_mono - cvt->len_cvt /= cvt->len_div; + cvt->len_cvt /= cvt->len_div;*/ if (cvt->filters[++cvt->filter_index]) { cvt->filters[cvt->filter_index] (cvt, format);