Mercurial > sdl-ios-xcode
comparison src/audio/SDL_audiocvt.c @ 2728:2768bd7281e0
Fixed Visual Studio compilation problems
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 26 Aug 2008 07:34:49 +0000 |
parents | f8f68f47285a |
children | 79c1bd651f04 |
comparison
equal
deleted
inserted
replaced
2727:76c2fc9696ea | 2728:2768bd7281e0 |
---|---|
18 | 18 |
19 Sam Lantinga | 19 Sam Lantinga |
20 slouken@libsdl.org | 20 slouken@libsdl.org |
21 */ | 21 */ |
22 #include "SDL_config.h" | 22 #include "SDL_config.h" |
23 | |
24 #define _USE_MATH_DEFINES | |
23 #include <math.h> | 25 #include <math.h> |
24 | 26 |
25 /* Functions for audio drivers to perform runtime conversion of audio format */ | 27 /* Functions for audio drivers to perform runtime conversion of audio format */ |
26 | 28 |
27 #include "SDL_audio.h" | 29 #include "SDL_audio.h" |
28 #include "SDL_audio_c.h" | 30 #include "SDL_audio_c.h" |
29 | 31 |
30 #define DEBUG_CONVERT | 32 //#define DEBUG_CONVERT |
31 | 33 |
32 /* These are fractional multiplication routines. That is, their inputs | 34 /* These are fractional multiplication routines. That is, their inputs |
33 are two numbers in the range [-1, 1) and the result falls in that | 35 are two numbers in the range [-1, 1) and the result falls in that |
34 same range. The output is the same size as the inputs, i.e. | 36 same range. The output is the same size as the inputs, i.e. |
35 32-bit x 32-bit = 32-bit. | 37 32-bit x 32-bit = 32-bit. |
1367 cvt->len_div) ? CUTOFF / (float) cvt->len_mult : CUTOFF / | 1369 cvt->len_div) ? CUTOFF / (float) cvt->len_mult : CUTOFF / |
1368 (float) cvt->len_div; | 1370 (float) cvt->len_div; |
1369 | 1371 |
1370 w0 = 2.0f * M_PI * fc; | 1372 w0 = 2.0f * M_PI * fc; |
1371 cosw0 = cosf(w0); | 1373 cosw0 = cosf(w0); |
1372 alpha = sin(w0) / (2.0f * Q); | 1374 alpha = sinf(w0) / (2.0f * Q); |
1373 | 1375 |
1374 /* Compute coefficients, normalizing by a0 */ | 1376 /* Compute coefficients, normalizing by a0 */ |
1375 scale = 1.0f / (1.0f + alpha); | 1377 scale = 1.0f / (1.0f + alpha); |
1376 | 1378 |
1377 coeff[0] = (1.0f - cosw0) / 2.0f * scale; | 1379 coeff[0] = (1.0f - cosw0) / 2.0f * scale; |
1436 } | 1438 } |
1437 #undef debug_iir | 1439 #undef debug_iir |
1438 #endif | 1440 #endif |
1439 | 1441 |
1440 /* Initialize the state buffer to all zeroes, and set initial position */ | 1442 /* Initialize the state buffer to all zeroes, and set initial position */ |
1441 memset(cvt->state_buf, 0, 4 * SDL_AUDIO_BITSIZE(format) / 4); | 1443 SDL_memset(cvt->state_buf, 0, 4 * SDL_AUDIO_BITSIZE(format) / 4); |
1442 cvt->state_pos = 0; | 1444 cvt->state_pos = 0; |
1443 #undef convert_fixed | 1445 #undef convert_fixed |
1444 } | 1446 } |
1445 | 1447 |
1446 /* Apply the lowpass IIR filter to the given SDL_AudioCVT struct */ | 1448 /* Apply the lowpass IIR filter to the given SDL_AudioCVT struct */ |
1634 | 1636 |
1635 /* Set the length */ | 1637 /* Set the length */ |
1636 cvt->len_sinc = m + 1; | 1638 cvt->len_sinc = m + 1; |
1637 | 1639 |
1638 /* Allocate the floating point windowed sinc. */ | 1640 /* Allocate the floating point windowed sinc. */ |
1639 fSinc = (float *) malloc((m + 1) * sizeof(float)); | 1641 fSinc = SDL_stack_alloc(float, (m + 1)); |
1640 if (fSinc == NULL) { | 1642 if (fSinc == NULL) { |
1641 return -1; | 1643 return -1; |
1642 } | 1644 } |
1643 | 1645 |
1644 /* Set up the filter parameters */ | 1646 /* Set up the filter parameters */ |
1697 break; | 1699 break; |
1698 } | 1700 } |
1699 } | 1701 } |
1700 | 1702 |
1701 /* Initialize the state buffer to all zeroes, and set initial position */ | 1703 /* Initialize the state buffer to all zeroes, and set initial position */ |
1702 memset(cvt->state_buf, 0, cvt->len_sinc * SDL_AUDIO_BITSIZE(format) / 4); | 1704 SDL_memset(cvt->state_buf, 0, |
1705 cvt->len_sinc * SDL_AUDIO_BITSIZE(format) / 4); | |
1703 cvt->state_pos = 0; | 1706 cvt->state_pos = 0; |
1704 | 1707 |
1705 /* Clean up */ | 1708 /* Clean up */ |
1706 #undef convert_fixed | 1709 #undef convert_fixed |
1707 free(fSinc); | 1710 SDL_stack_free(fSinc); |
1708 } | 1711 } |
1709 | 1712 |
1710 /* This is used to reduce the resampling ratio */ | 1713 /* This is used to reduce the resampling ratio */ |
1711 inline int | 1714 static __inline__ int |
1712 SDL_GCD(int a, int b) | 1715 SDL_GCD(int a, int b) |
1713 { | 1716 { |
1714 int temp; | 1717 int temp; |
1715 while (b != 0) { | 1718 while (b != 0) { |
1716 temp = a % b; | 1719 temp = a % b; |