Skip to content

Commit

Permalink
audio: Replaced the resampler. Again.
Browse files Browse the repository at this point in the history
This time it's using real math from a real whitepaper instead of my previous
amateur, fast-but-low-quality attempt. The new resampler does "bandlimited
interpolation," as described here: https://ccrma.stanford.edu/~jos/resample/

The output appears to sound cleaner, especially at high frequencies, and of
course works with non-power-of-two rate conversions.

There are some obvious optimizations to be done to this still, and there is
other fallout: this doesn't resample a buffer in-place, the 2-channels-Sint16
fast path is gone because this resampler does a _lot_ of floating point math.
There is a nasty hack to make it work with SDL_AudioCVT.

It's possible these issues are solvable, but they aren't solved as of yet.
Still, I hope this effort is slouching in the right direction.
  • Loading branch information
icculus committed Sep 21, 2017
1 parent 3c45e66 commit 1a3b95a
Show file tree
Hide file tree
Showing 4 changed files with 400 additions and 264 deletions.
2 changes: 2 additions & 0 deletions src/audio/SDL_audio.c
Expand Up @@ -1543,6 +1543,8 @@ SDL_AudioQuit(void)
#ifdef HAVE_LIBSAMPLERATE_H
UnloadLibSampleRate();
#endif

SDL_FreeResampleFilter();
}

#define NUM_FORMATS 10
Expand Down
5 changes: 5 additions & 0 deletions src/audio/SDL_audio_c.h
Expand Up @@ -69,6 +69,11 @@ extern SDL_AudioFilter SDL_Convert_F32_to_S16;
extern SDL_AudioFilter SDL_Convert_F32_to_U16;
extern SDL_AudioFilter SDL_Convert_F32_to_S32;

/* You need to call SDL_PrepareResampleFilter() before using the internal resampler.
SDL_AudioQuit() calls SDL_FreeResamplerFilter(), you should never call it yourself. */
int SDL_PrepareResampleFilter(void);
void SDL_FreeResampleFilter(void);


/* SDL_AudioStream is a new audio conversion interface. It
might eventually become a public API.
Expand Down

0 comments on commit 1a3b95a

Please sign in to comment.