Commit b18cb001 authored by Ryan C. Gordon's avatar Ryan C. Gordon

More resampling fixes.

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403343
parent 83de1885
...@@ -1549,7 +1549,8 @@ SDL_FilterIIR(SDL_AudioCVT * cvt, SDL_AudioFormat format) ...@@ -1549,7 +1549,8 @@ SDL_FilterIIR(SDL_AudioCVT * cvt, SDL_AudioFormat format)
static void static void
SDL_FilterFIR(SDL_AudioCVT * cvt, SDL_AudioFormat format) SDL_FilterFIR(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{ {
int n = 8 * cvt->len_cvt / SDL_AUDIO_BITSIZE(format); /* !!! FIXME: (n) is incorrect, or my allocation of state_buf is wrong. */
const int n = 8 * cvt->len_cvt / SDL_AUDIO_BITSIZE(format);
int m = cvt->len_sinc; int m = cvt->len_sinc;
int i, j; int i, j;
...@@ -1631,11 +1632,6 @@ SDL_BuildWindowedSinc(SDL_AudioCVT * cvt, SDL_AudioFormat format, ...@@ -1631,11 +1632,6 @@ SDL_BuildWindowedSinc(SDL_AudioCVT * cvt, SDL_AudioFormat format,
float norm_sum, norm_fact; float norm_sum, norm_fact;
unsigned int i; unsigned int i;
/* Check that the buffer is allocated */
if (cvt->coeff == NULL) {
return -1;
}
/* Set the length */ /* Set the length */
cvt->len_sinc = m + 1; cvt->len_sinc = m + 1;
...@@ -1683,7 +1679,7 @@ SDL_BuildWindowedSinc(SDL_AudioCVT * cvt, SDL_AudioFormat format, ...@@ -1683,7 +1679,7 @@ SDL_BuildWindowedSinc(SDL_AudioCVT * cvt, SDL_AudioFormat format,
} }
/* !!! FIXME: this memory leaks. */ /* !!! FIXME: this memory leaks. */
cvt->coeff = (Uint8 *) SDL_malloc((SDL_AUDIO_BITSIZE(format) / 8) * m); cvt->coeff = (Uint8 *) SDL_malloc((SDL_AUDIO_BITSIZE(format) / 8) * (m+1));
if (cvt->coeff == NULL) { if (cvt->coeff == NULL) {
return -1; return -1;
} }
...@@ -1709,6 +1705,11 @@ SDL_BuildWindowedSinc(SDL_AudioCVT * cvt, SDL_AudioFormat format, ...@@ -1709,6 +1705,11 @@ SDL_BuildWindowedSinc(SDL_AudioCVT * cvt, SDL_AudioFormat format,
} }
/* Initialize the state buffer to all zeroes, and set initial position */ /* Initialize the state buffer to all zeroes, and set initial position */
/* !!! FIXME: this memory leaks. */
cvt->state_buf = (Uint8 *) SDL_malloc(cvt->len_sinc * SDL_AUDIO_BITSIZE(format) / 4);
if (cvt->state_buf == NULL) {
return -1;
}
SDL_memset(cvt->state_buf, 0, SDL_memset(cvt->state_buf, 0,
cvt->len_sinc * SDL_AUDIO_BITSIZE(format) / 4); cvt->len_sinc * SDL_AUDIO_BITSIZE(format) / 4);
cvt->state_pos = 0; cvt->state_pos = 0;
...@@ -1744,9 +1745,9 @@ SDL_Resample(SDL_AudioCVT * cvt, SDL_AudioFormat format) ...@@ -1744,9 +1745,9 @@ SDL_Resample(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif #endif
#define zerostuff_mono(type) { \ #define zerostuff_mono(type) { \
const type *src = (const type *) (cvt->buf + cvt->len_cvt); \ const type *src = (const type *) (cvt->buf + cvt->len); \
type *dst = (type *) (cvt->buf + (cvt->len_cvt * cvt->len_mult)); \ type *dst = (type *) (cvt->buf + (cvt->len * cvt->len_mult)); \
for (i = cvt->len_cvt / sizeof (type); i; --i) { \ for (i = cvt->len / sizeof (type); i; --i) { \
src--; \ src--; \
dst[-1] = src[0]; \ dst[-1] = src[0]; \
for( j = -cvt->len_mult; j < -1; ++j ) { \ for( j = -cvt->len_mult; j < -1; ++j ) { \
...@@ -1914,6 +1915,7 @@ SDL_BuildAudioCVT(SDL_AudioCVT * cvt, ...@@ -1914,6 +1915,7 @@ SDL_BuildAudioCVT(SDL_AudioCVT * cvt,
cvt->len_div = src_rate / rate_gcd; cvt->len_div = src_rate / rate_gcd;
cvt->len_ratio = (double) cvt->len_mult / (double) cvt->len_div; cvt->len_ratio = (double) cvt->len_mult / (double) cvt->len_div;
cvt->filters[cvt->filter_index++] = SDL_Resample; cvt->filters[cvt->filter_index++] = SDL_Resample;
/* !!! FIXME: check return value. */
SDL_BuildWindowedSinc(cvt, dst_fmt, 768); SDL_BuildWindowedSinc(cvt, dst_fmt, 768);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment