comparison src/audio/SDL_audiocvt.c @ 3012:7e30c2dc7783

Fixed Visual C++ release build for Visual C++ 2005 * Some math functions become intrinsic in release mode, so we need to convert all the math functions into SDL math functions, like we did with the stdlib functions. * Constant initializers of 8-bit values become calls to memset() in release mode, but memset() itself is an intrinsic when explicitly called. So we'll just explicitly call memset() in those cases.
author Sam Lantinga <slouken@libsdl.org>
date Sat, 10 Jan 2009 18:32:24 +0000
parents 11626a53e7bc
children f3dcf04412cf
comparison
equal deleted inserted replaced
3011:8f4ed5ec2b06 3012:7e30c2dc7783
23 23
24 /* Functions for audio drivers to perform runtime conversion of audio format */ 24 /* Functions for audio drivers to perform runtime conversion of audio format */
25 25
26 #include "SDL_audio.h" 26 #include "SDL_audio.h"
27 #include "SDL_audio_c.h" 27 #include "SDL_audio_c.h"
28
29 #include "../libm/math.h"
30 28
31 //#define DEBUG_CONVERT 29 //#define DEBUG_CONVERT
32 30
33 /* These are fractional multiplication routines. That is, their inputs 31 /* These are fractional multiplication routines. That is, their inputs
34 are two numbers in the range [-1, 1) and the result falls in that 32 are two numbers in the range [-1, 1) and the result falls in that
1656 1654
1657 for (i = 0; i <= m; ++i) { 1655 for (i = 0; i <= m; ++i) {
1658 if (i == m / 2) { 1656 if (i == m / 2) {
1659 fSinc[i] = two_pi_fc; 1657 fSinc[i] = two_pi_fc;
1660 } else { 1658 } else {
1661 fSinc[i] = 1659 fSinc[i] = SDL_sinf(two_pi_fc * ((float) i - m_over_two)) / ((float) i - m_over_two);
1662 sinf(two_pi_fc * ((float) i - m_over_two)) / ((float) i -
1663 m_over_two);
1664 /* Apply blackman window */ 1660 /* Apply blackman window */
1665 fSinc[i] *= 1661 fSinc[i] *= 0.42f - 0.5f * SDL_cosf(two_pi_over_m * (float) i) + 0.08f * SDL_cosf(four_pi_over_m * (float) i);
1666 0.42f - 0.5f * cosf(two_pi_over_m * (float) i) +
1667 0.08f * cosf(four_pi_over_m * (float) i);
1668 } 1662 }
1669 norm_sum += fSinc[i] < 0 ? -fSinc[i] : fSinc[i]; /* fabs(fSinc[i]); */ 1663 norm_sum += fSinc[i] < 0 ? -fSinc[i] : fSinc[i]; /* fabs(fSinc[i]); */
1670 } 1664 }
1671 1665
1672 norm_fact = 1.0f / norm_sum; 1666 norm_fact = 1.0f / norm_sum;
1738 1732
1739 /* Perform proper resampling. This is pretty slow but it's the best-sounding method. */ 1733 /* Perform proper resampling. This is pretty slow but it's the best-sounding method. */
1740 static void SDLCALL 1734 static void SDLCALL
1741 SDL_Resample(SDL_AudioCVT * cvt, SDL_AudioFormat format) 1735 SDL_Resample(SDL_AudioCVT * cvt, SDL_AudioFormat format)
1742 { 1736 {
1743 int i, j; 1737 int i;
1744 1738
1745 #ifdef DEBUG_CONVERT 1739 #ifdef DEBUG_CONVERT
1746 printf("Converting audio rate via proper resampling (mono)\n"); 1740 printf("Converting audio rate via proper resampling (mono)\n");
1747 #endif 1741 #endif
1748 1742
1750 const type *src = (const type *) (cvt->buf + cvt->len); \ 1744 const type *src = (const type *) (cvt->buf + cvt->len); \
1751 type *dst = (type *) (cvt->buf + (cvt->len * cvt->len_mult)); \ 1745 type *dst = (type *) (cvt->buf + (cvt->len * cvt->len_mult)); \
1752 for (i = cvt->len / sizeof (type); i; --i) { \ 1746 for (i = cvt->len / sizeof (type); i; --i) { \
1753 src--; \ 1747 src--; \
1754 dst[-1] = src[0]; \ 1748 dst[-1] = src[0]; \
1755 for( j = -cvt->len_mult; j < -1; ++j ) { \ 1749 if (cvt->len_mult > 1) { \
1756 dst[j] = 0; \ 1750 SDL_memset(dst-cvt->len_mult, 0, cvt->len_mult-1); \
1757 } \ 1751 } \
1758 dst -= cvt->len_mult; \ 1752 dst -= cvt->len_mult; \
1759 } \ 1753 } \
1760 } 1754 }
1761 1755