src/audio/SDL_audiocvt.c
changeset 2728 2768bd7281e0
parent 2716 f8f68f47285a
child 2738 79c1bd651f04
     1.1 --- a/src/audio/SDL_audiocvt.c	Tue Aug 26 07:34:23 2008 +0000
     1.2 +++ b/src/audio/SDL_audiocvt.c	Tue Aug 26 07:34:49 2008 +0000
     1.3 @@ -20,6 +20,8 @@
     1.4      slouken@libsdl.org
     1.5  */
     1.6  #include "SDL_config.h"
     1.7 +
     1.8 +#define _USE_MATH_DEFINES
     1.9  #include <math.h>
    1.10  
    1.11  /* Functions for audio drivers to perform runtime conversion of audio format */
    1.12 @@ -27,7 +29,7 @@
    1.13  #include "SDL_audio.h"
    1.14  #include "SDL_audio_c.h"
    1.15  
    1.16 -#define DEBUG_CONVERT
    1.17 +//#define DEBUG_CONVERT
    1.18  
    1.19  /* These are fractional multiplication routines. That is, their inputs
    1.20     are two numbers in the range [-1, 1) and the result falls in that
    1.21 @@ -1369,7 +1371,7 @@
    1.22  
    1.23      w0 = 2.0f * M_PI * fc;
    1.24      cosw0 = cosf(w0);
    1.25 -    alpha = sin(w0) / (2.0f * Q);
    1.26 +    alpha = sinf(w0) / (2.0f * Q);
    1.27  
    1.28      /* Compute coefficients, normalizing by a0 */
    1.29      scale = 1.0f / (1.0f + alpha);
    1.30 @@ -1438,7 +1440,7 @@
    1.31  #endif
    1.32  
    1.33      /* Initialize the state buffer to all zeroes, and set initial position */
    1.34 -    memset(cvt->state_buf, 0, 4 * SDL_AUDIO_BITSIZE(format) / 4);
    1.35 +    SDL_memset(cvt->state_buf, 0, 4 * SDL_AUDIO_BITSIZE(format) / 4);
    1.36      cvt->state_pos = 0;
    1.37  #undef convert_fixed
    1.38  }
    1.39 @@ -1636,7 +1638,7 @@
    1.40      cvt->len_sinc = m + 1;
    1.41  
    1.42      /* Allocate the floating point windowed sinc. */
    1.43 -    fSinc = (float *) malloc((m + 1) * sizeof(float));
    1.44 +    fSinc = SDL_stack_alloc(float, (m + 1));
    1.45      if (fSinc == NULL) {
    1.46          return -1;
    1.47      }
    1.48 @@ -1699,16 +1701,17 @@
    1.49      }
    1.50  
    1.51      /* Initialize the state buffer to all zeroes, and set initial position */
    1.52 -    memset(cvt->state_buf, 0, cvt->len_sinc * SDL_AUDIO_BITSIZE(format) / 4);
    1.53 +    SDL_memset(cvt->state_buf, 0,
    1.54 +               cvt->len_sinc * SDL_AUDIO_BITSIZE(format) / 4);
    1.55      cvt->state_pos = 0;
    1.56  
    1.57      /* Clean up */
    1.58  #undef convert_fixed
    1.59 -    free(fSinc);
    1.60 +    SDL_stack_free(fSinc);
    1.61  }
    1.62  
    1.63  /* This is used to reduce the resampling ratio */
    1.64 -inline int
    1.65 +static __inline__ int
    1.66  SDL_GCD(int a, int b)
    1.67  {
    1.68      int temp;