Mercurial > sdl-ios-xcode
comparison src/audio/SDL_audiocvt.c @ 2760:02aa80d7905f
Updated Visual C++ build
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 15 Sep 2008 07:34:36 +0000 |
parents | 79c1bd651f04 |
children | f55c87ae336b |
comparison
equal
deleted
inserted
replaced
2759:95fccd9bf262 | 2760:02aa80d7905f |
---|---|
26 | 26 |
27 /* Functions for audio drivers to perform runtime conversion of audio format */ | 27 /* Functions for audio drivers to perform runtime conversion of audio format */ |
28 | 28 |
29 #include "SDL_audio.h" | 29 #include "SDL_audio.h" |
30 #include "SDL_audio_c.h" | 30 #include "SDL_audio_c.h" |
31 | |
32 #include "../libm/math.h" | |
31 | 33 |
32 //#define DEBUG_CONVERT | 34 //#define DEBUG_CONVERT |
33 | 35 |
34 /* These are fractional multiplication routines. That is, their inputs | 36 /* These are fractional multiplication routines. That is, their inputs |
35 are two numbers in the range [-1, 1) and the result falls in that | 37 are two numbers in the range [-1, 1) and the result falls in that |
1350 type of dst_format. Also assume the buffer is allocated. | 1352 type of dst_format. Also assume the buffer is allocated. |
1351 Note the buffer needs to be 6 units long. | 1353 Note the buffer needs to be 6 units long. |
1352 For now, use RBJ's cookbook coefficients. It might be more | 1354 For now, use RBJ's cookbook coefficients. It might be more |
1353 optimal to create a Butterworth filter, but this is more difficult. | 1355 optimal to create a Butterworth filter, but this is more difficult. |
1354 */ | 1356 */ |
1357 #if 0 | |
1355 int | 1358 int |
1356 SDL_BuildIIRLowpass(SDL_AudioCVT * cvt, SDL_AudioFormat format) | 1359 SDL_BuildIIRLowpass(SDL_AudioCVT * cvt, SDL_AudioFormat format) |
1357 { | 1360 { |
1358 float fc; /* cutoff frequency */ | 1361 float fc; /* cutoff frequency */ |
1359 float coeff[6]; /* floating point iir coefficients b0, b1, b2, a0, a1, a2 */ | 1362 float coeff[6]; /* floating point iir coefficients b0, b1, b2, a0, a1, a2 */ |
1441 | 1444 |
1442 /* Initialize the state buffer to all zeroes, and set initial position */ | 1445 /* Initialize the state buffer to all zeroes, and set initial position */ |
1443 SDL_memset(cvt->state_buf, 0, 4 * SDL_AUDIO_BITSIZE(format) / 4); | 1446 SDL_memset(cvt->state_buf, 0, 4 * SDL_AUDIO_BITSIZE(format) / 4); |
1444 cvt->state_pos = 0; | 1447 cvt->state_pos = 0; |
1445 #undef convert_fixed | 1448 #undef convert_fixed |
1446 } | 1449 |
1450 return 0; | |
1451 } | |
1452 #endif | |
1447 | 1453 |
1448 /* Apply the lowpass IIR filter to the given SDL_AudioCVT struct */ | 1454 /* Apply the lowpass IIR filter to the given SDL_AudioCVT struct */ |
1449 /* This was implemented because it would be much faster than the fir filter, | 1455 /* This was implemented because it would be much faster than the fir filter, |
1450 but it doesn't seem to have a steep enough cutoff so we'd need several | 1456 but it doesn't seem to have a steep enough cutoff so we'd need several |
1451 cascaded biquads, which probably isn't a great idea. Therefore, this | 1457 cascaded biquads, which probably isn't a great idea. Therefore, this |
1665 /* Apply blackman window */ | 1671 /* Apply blackman window */ |
1666 fSinc[i] *= | 1672 fSinc[i] *= |
1667 0.42f - 0.5f * cosf(two_pi_over_m * (float) i) + | 1673 0.42f - 0.5f * cosf(two_pi_over_m * (float) i) + |
1668 0.08f * cosf(four_pi_over_m * (float) i); | 1674 0.08f * cosf(four_pi_over_m * (float) i); |
1669 } | 1675 } |
1670 norm_sum += fabs(fSinc[i]); | 1676 norm_sum += fSinc[i] < 0 ? -fSinc[i] : fSinc[i]; /* fabs(fSinc[i]); */ |
1671 } | 1677 } |
1672 | 1678 |
1673 norm_fact = 1.0f / norm_sum; | 1679 norm_fact = 1.0f / norm_sum; |
1674 | 1680 |
1675 #define convert_fixed(type, fix) { \ | 1681 #define convert_fixed(type, fix) { \ |