src/audio/SDL_audiocvt.c
changeset 2881 c8d203ef4335
parent 2880 3c2f56e433a8
child 2883 11626a53e7bc
     1.1 --- a/src/audio/SDL_audiocvt.c	Fri Dec 19 08:30:26 2008 +0000
     1.2 +++ b/src/audio/SDL_audiocvt.c	Fri Dec 19 09:15:59 2008 +0000
     1.3 @@ -1549,7 +1549,8 @@
     1.4  static void
     1.5  SDL_FilterFIR(SDL_AudioCVT * cvt, SDL_AudioFormat format)
     1.6  {
     1.7 -    int n = 8 * cvt->len_cvt / SDL_AUDIO_BITSIZE(format);
     1.8 +    /* !!! FIXME: (n) is incorrect, or my allocation of state_buf is wrong. */
     1.9 +    const int n = 8 * cvt->len_cvt / SDL_AUDIO_BITSIZE(format);
    1.10      int m = cvt->len_sinc;
    1.11      int i, j;
    1.12  
    1.13 @@ -1631,11 +1632,6 @@
    1.14      float norm_sum, norm_fact;
    1.15      unsigned int i;
    1.16  
    1.17 -    /* Check that the buffer is allocated */
    1.18 -    if (cvt->coeff == NULL) {
    1.19 -        return -1;
    1.20 -    }
    1.21 -
    1.22      /* Set the length */
    1.23      cvt->len_sinc = m + 1;
    1.24  
    1.25 @@ -1683,7 +1679,7 @@
    1.26      }
    1.27  
    1.28      /* !!! FIXME: this memory leaks. */
    1.29 -    cvt->coeff = (Uint8 *) SDL_malloc((SDL_AUDIO_BITSIZE(format) / 8) * m);
    1.30 +    cvt->coeff = (Uint8 *) SDL_malloc((SDL_AUDIO_BITSIZE(format) / 8) * (m+1));
    1.31      if (cvt->coeff == NULL) {
    1.32          return -1;
    1.33      }
    1.34 @@ -1709,6 +1705,11 @@
    1.35      }
    1.36  
    1.37      /* Initialize the state buffer to all zeroes, and set initial position */
    1.38 +    /* !!! FIXME: this memory leaks. */
    1.39 +    cvt->state_buf = (Uint8 *) SDL_malloc(cvt->len_sinc * SDL_AUDIO_BITSIZE(format) / 4);
    1.40 +    if (cvt->state_buf == NULL) {
    1.41 +        return -1;
    1.42 +    }
    1.43      SDL_memset(cvt->state_buf, 0,
    1.44                 cvt->len_sinc * SDL_AUDIO_BITSIZE(format) / 4);
    1.45      cvt->state_pos = 0;
    1.46 @@ -1744,9 +1745,9 @@
    1.47  #endif
    1.48  
    1.49  #define zerostuff_mono(type) { \
    1.50 -        const type *src = (const type *) (cvt->buf + cvt->len_cvt); \
    1.51 -        type *dst = (type *) (cvt->buf + (cvt->len_cvt * cvt->len_mult)); \
    1.52 -        for (i = cvt->len_cvt / sizeof (type); i; --i) { \
    1.53 +        const type *src = (const type *) (cvt->buf + cvt->len); \
    1.54 +        type *dst = (type *) (cvt->buf + (cvt->len * cvt->len_mult)); \
    1.55 +        for (i = cvt->len / sizeof (type); i; --i) { \
    1.56              src--; \
    1.57              dst[-1] = src[0]; \
    1.58              for( j = -cvt->len_mult; j < -1; ++j ) { \
    1.59 @@ -1914,6 +1915,7 @@
    1.60          cvt->len_div = src_rate / rate_gcd;
    1.61          cvt->len_ratio = (double) cvt->len_mult / (double) cvt->len_div;
    1.62          cvt->filters[cvt->filter_index++] = SDL_Resample;
    1.63 +        /* !!! FIXME: check return value. */
    1.64          SDL_BuildWindowedSinc(cvt, dst_fmt, 768);
    1.65      }
    1.66