Generalized the audio resampling hint for other resampling methods in the future
authorSam Lantinga <slouken@libsdl.org>
Tue, 24 Jan 2017 19:38:01 -0800
changeset 10852494d0f56ae7a
parent 10851 9209506bac56
child 10853 f4a771647ecd
Generalized the audio resampling hint for other resampling methods in the future
include/SDL_hints.h
src/audio/SDL_audio.c
     1.1 --- a/include/SDL_hints.h	Tue Jan 24 20:30:48 2017 -0500
     1.2 +++ b/include/SDL_hints.h	Tue Jan 24 19:38:01 2017 -0800
     1.3 @@ -780,36 +780,26 @@
     1.4   *
     1.5   *  If available, SDL can use libsamplerate ( http://www.mega-nerd.com/SRC/ )
     1.6   *  to handle audio resampling. There are different resampling modes available
     1.7 - *  that produce different levels of quality, possibly using more CPU.
     1.8 + *  that produce different levels of quality, using more CPU.
     1.9   *
    1.10   *  If this hint isn't specified to a valid setting, or libsamplerate isn't
    1.11 - *  available, SDL will act as if this hint was set to "fast".
    1.12 + *  available, SDL will use the default, internal resampling algorithm.
    1.13   *
    1.14   *  Note that this is currently only applicable to resampling audio that is
    1.15   *  being written to a device for playback or audio being read from a device
    1.16 - *  for capture. SDL_AudioCVT always uses the "fast" resampler (although this
    1.17 + *  for capture. SDL_AudioCVT always uses the default resampler (although this
    1.18   *  might change for SDL 2.1).
    1.19   *
    1.20 - *  Most things can probably live with the "fast" resampler, but if quality
    1.21 - *  is important or you can spare some CPU cycles, the other options are
    1.22 - *  worth exploring!
    1.23 - *
    1.24 - *  libsamplerate's interpolators, that these hints map to, are explained here:
    1.25 - *     http://www.mega-nerd.com/SRC/api_misc.html#Converters
    1.26 - *
    1.27 - *  This hint is only checked at audio subsystem init time and changes to it
    1.28 - *  at other times are ignored.
    1.29 + *  This hint is currently only checked at audio subsystem initialization.
    1.30   *
    1.31   *  This variable can be set to the following values:
    1.32   *
    1.33 - *    "default"  - Use SDL's internal, resampler. (Default when not set. low quality, fast.)
    1.34 - *    "linear" - Use libsamplerate's Linear interpolator (low quality, fast).
    1.35 - *    "zero_order_hold" - Use libsamplerate's Zero Order Hold interpolator (low quality, fast).
    1.36 - *    "sinc_fastest" - Use libsamplerate's fastest (lowest quality) sinc interpolator.
    1.37 - *    "sinc_medium" - Use libsamplerate's medium quality sinc interpolator.
    1.38 - *    "sinc_best" - Use libsamplerate's best quality sinc interpolator.
    1.39 + *    "0" or "default" - Use SDL's internal resampling (Default when not set - low quality, fast)
    1.40 + *    "1" or "fast"    - Use fast, slightly higher quality resampling, if available
    1.41 + *    "2" or "medium"  - Use medium quality resampling, if available
    1.42 + *    "3" or "best"    - Use high quality resampling, if available
    1.43   */
    1.44 -#define SDL_HINT_AUDIO_RESAMPLER_MODE   "SDL_AUDIO_RESAMPLER_MODE"
    1.45 +#define SDL_HINT_AUDIO_RESAMPLING_MODE   "SDL_AUDIO_RESAMPLING_MODE"
    1.46  
    1.47  /**
    1.48   *  \brief  An enumeration of hint priorities
     2.1 --- a/src/audio/SDL_audio.c	Tue Jan 24 20:30:48 2017 -0500
     2.2 +++ b/src/audio/SDL_audio.c	Tue Jan 24 19:38:01 2017 -0800
     2.3 @@ -123,22 +123,18 @@
     2.4  static SDL_bool
     2.5  LoadLibSampleRate(void)
     2.6  {
     2.7 -    const char *hint = SDL_GetHint(SDL_HINT_AUDIO_RESAMPLER_MODE);
     2.8 +    const char *hint = SDL_GetHint(SDL_HINT_AUDIO_RESAMPLING_MODE);
     2.9  
    2.10      SRC_available = SDL_FALSE;
    2.11      SRC_converter = 0;
    2.12  
    2.13 -    if (!hint || (SDL_strcasecmp(hint, "default") == 0)) {
    2.14 +    if (!hint || *hint == '0' || SDL_strcasecmp(hint, "default") == 0) {
    2.15          return SDL_FALSE;  /* don't load anything. */
    2.16 -    } else if (SDL_strcasecmp(hint, "linear") == 0) {
    2.17 -        SRC_converter = SRC_LINEAR;
    2.18 -    } else if (SDL_strcasecmp(hint, "zero_order_hold") == 0) {
    2.19 -        SRC_converter = SRC_ZERO_ORDER_HOLD;
    2.20 -    } else if (SDL_strcasecmp(hint, "sinc_fastest") == 0) {
    2.21 +    } else if (*hint == '1' || SDL_strcasecmp(hint, "fast") == 0) {
    2.22          SRC_converter = SRC_SINC_FASTEST;
    2.23 -    } else if (SDL_strcasecmp(hint, "sinc_medium") == 0) {
    2.24 +    } else if (*hint == '2' || SDL_strcasecmp(hint, "medium") == 0) {
    2.25          SRC_converter = SRC_SINC_MEDIUM_QUALITY;
    2.26 -    } else if (SDL_strcasecmp(hint, "sinc_best") == 0) {
    2.27 +    } else if (*hint == '3' || SDL_strcasecmp(hint, "best") == 0) {
    2.28          SRC_converter = SRC_SINC_BEST_QUALITY;
    2.29      } else {
    2.30          return SDL_FALSE;  /* treat it like "default", don't load anything. */