From 23020f92faca7ac1cd29ad4ebde03701eac0abfe Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Mon, 9 Jan 2017 16:31:57 -0500 Subject: [PATCH] audio: Don't ever use libsamplerate in the SDL_AudioCVT codepath. It causes audio pops if you're converting in chunks (and needs to allocate/initialize/free on each convert). We'll either adjust this interface when we break ABI for 2.1 to make this usable, or publish the SDL_AudioStream API for those that want a streaming solution. In the meantime, the "simple" resampler produces "good enough" audio without pops and doesn't have to be initialized, so that'll do for now on the SDL_AudioCVT interface. --- src/audio/SDL_audiocvt.c | 47 +++++----------------------------------- 1 file changed, 5 insertions(+), 42 deletions(-) diff --git a/src/audio/SDL_audiocvt.c b/src/audio/SDL_audiocvt.c index e690b1d17e41d..3c19a3215a0d1 100644 --- a/src/audio/SDL_audiocvt.c +++ b/src/audio/SDL_audiocvt.c @@ -377,53 +377,16 @@ SDL_ResampleCVT(SDL_AudioCVT *cvt, const int chans, const SDL_AudioFormat format const int srclen = cvt->len_cvt; float *dst = (float *) (cvt->buf + srclen); const int dstlen = (cvt->len * cvt->len_mult) - srclen; - SDL_bool do_simple = SDL_TRUE; + float state[8]; + int i; SDL_assert(format == AUDIO_F32SYS); -#ifdef HAVE_LIBSAMPLERATE_H - if (SRC_available) { - int result = 0; - SRC_STATE *state = SRC_src_new(SRC_SINC_FASTEST, chans, &result); - if (state) { - const int framelen = sizeof(float) * chans; - SRC_DATA data; - - data.data_in = (float *)src; /* Older versions of libsamplerate had a non-const pointer, but didn't write to it */ - data.input_frames = srclen / framelen; - data.input_frames_used = 0; - - data.data_out = dst; - data.output_frames = dstlen / framelen; - - data.end_of_input = 0; - data.src_ratio = cvt->rate_incr; - - result = SRC_src_process(state, &data); - SDL_assert(result == 0); /* what to do if this fails? Can it fail? */ - - /* What to do if this fails...? */ - SDL_assert(data.input_frames_used == data.input_frames); - - SRC_src_delete(state); - cvt->len_cvt = data.output_frames_gen * (sizeof(float) * chans); - do_simple = SDL_FALSE; - } - - /* failed to create state? Fall back to simple method. */ + for (i = 0; i < chans; i++) { + state[i] = src[i]; } -#endif - - if (do_simple) { - float state[8]; - int i; - for (i = 0; i < chans; i++) { - state[i] = src[i]; - } - - cvt->len_cvt = SDL_ResampleAudioSimple(chans, cvt->rate_incr, state, src, srclen, dst, dstlen); - } + cvt->len_cvt = SDL_ResampleAudioSimple(chans, cvt->rate_incr, state, src, srclen, dst, dstlen); SDL_memcpy(cvt->buf, dst, cvt->len_cvt); if (cvt->filters[++cvt->filter_index]) {