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.
1.1 --- a/src/audio/SDL_audiocvt.c Mon Jan 09 15:56:11 2017 -0500
1.2 +++ b/src/audio/SDL_audiocvt.c Mon Jan 09 16:31:57 2017 -0500
1.3 @@ -377,53 +377,16 @@
1.4 const int srclen = cvt->len_cvt;
1.5 float *dst = (float *) (cvt->buf + srclen);
1.6 const int dstlen = (cvt->len * cvt->len_mult) - srclen;
1.7 - SDL_bool do_simple = SDL_TRUE;
1.8 + float state[8];
1.9 + int i;
1.10
1.11 SDL_assert(format == AUDIO_F32SYS);
1.12
1.13 -#ifdef HAVE_LIBSAMPLERATE_H
1.14 - if (SRC_available) {
1.15 - int result = 0;
1.16 - SRC_STATE *state = SRC_src_new(SRC_SINC_FASTEST, chans, &result);
1.17 - if (state) {
1.18 - const int framelen = sizeof(float) * chans;
1.19 - SRC_DATA data;
1.20 -
1.21 - data.data_in = (float *)src; /* Older versions of libsamplerate had a non-const pointer, but didn't write to it */
1.22 - data.input_frames = srclen / framelen;
1.23 - data.input_frames_used = 0;
1.24 -
1.25 - data.data_out = dst;
1.26 - data.output_frames = dstlen / framelen;
1.27 -
1.28 - data.end_of_input = 0;
1.29 - data.src_ratio = cvt->rate_incr;
1.30 -
1.31 - result = SRC_src_process(state, &data);
1.32 - SDL_assert(result == 0); /* what to do if this fails? Can it fail? */
1.33 + for (i = 0; i < chans; i++) {
1.34 + state[i] = src[i];
1.35 + }
1.36
1.37 - /* What to do if this fails...? */
1.38 - SDL_assert(data.input_frames_used == data.input_frames);
1.39 -
1.40 - SRC_src_delete(state);
1.41 - cvt->len_cvt = data.output_frames_gen * (sizeof(float) * chans);
1.42 - do_simple = SDL_FALSE;
1.43 - }
1.44 -
1.45 - /* failed to create state? Fall back to simple method. */
1.46 - }
1.47 -#endif
1.48 -
1.49 - if (do_simple) {
1.50 - float state[8];
1.51 - int i;
1.52 -
1.53 - for (i = 0; i < chans; i++) {
1.54 - state[i] = src[i];
1.55 - }
1.56 -
1.57 - cvt->len_cvt = SDL_ResampleAudioSimple(chans, cvt->rate_incr, state, src, srclen, dst, dstlen);
1.58 - }
1.59 + cvt->len_cvt = SDL_ResampleAudioSimple(chans, cvt->rate_incr, state, src, srclen, dst, dstlen);
1.60
1.61 SDL_memcpy(cvt->buf, dst, cvt->len_cvt);
1.62 if (cvt->filters[++cvt->filter_index]) {