Generalized the audio resampling hint for other resampling methods in the future
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
diff --git a/include/SDL_hints.h b/include/SDL_hints.h
index ef68966..cbea8c5 100644
--- a/include/SDL_hints.h
+++ b/include/SDL_hints.h
@@ -780,36 +780,26 @@ extern "C" {
*
* If available, SDL can use libsamplerate ( http://www.mega-nerd.com/SRC/ )
* to handle audio resampling. There are different resampling modes available
- * that produce different levels of quality, possibly using more CPU.
+ * that produce different levels of quality, using more CPU.
*
* If this hint isn't specified to a valid setting, or libsamplerate isn't
- * available, SDL will act as if this hint was set to "fast".
+ * available, SDL will use the default, internal resampling algorithm.
*
* Note that this is currently only applicable to resampling audio that is
* being written to a device for playback or audio being read from a device
- * for capture. SDL_AudioCVT always uses the "fast" resampler (although this
+ * for capture. SDL_AudioCVT always uses the default resampler (although this
* might change for SDL 2.1).
*
- * Most things can probably live with the "fast" resampler, but if quality
- * is important or you can spare some CPU cycles, the other options are
- * worth exploring!
- *
- * libsamplerate's interpolators, that these hints map to, are explained here:
- * http://www.mega-nerd.com/SRC/api_misc.html#Converters
- *
- * This hint is only checked at audio subsystem init time and changes to it
- * at other times are ignored.
+ * This hint is currently only checked at audio subsystem initialization.
*
* This variable can be set to the following values:
*
- * "default" - Use SDL's internal, resampler. (Default when not set. low quality, fast.)
- * "linear" - Use libsamplerate's Linear interpolator (low quality, fast).
- * "zero_order_hold" - Use libsamplerate's Zero Order Hold interpolator (low quality, fast).
- * "sinc_fastest" - Use libsamplerate's fastest (lowest quality) sinc interpolator.
- * "sinc_medium" - Use libsamplerate's medium quality sinc interpolator.
- * "sinc_best" - Use libsamplerate's best quality sinc interpolator.
+ * "0" or "default" - Use SDL's internal resampling (Default when not set - low quality, fast)
+ * "1" or "fast" - Use fast, slightly higher quality resampling, if available
+ * "2" or "medium" - Use medium quality resampling, if available
+ * "3" or "best" - Use high quality resampling, if available
*/
-#define SDL_HINT_AUDIO_RESAMPLER_MODE "SDL_AUDIO_RESAMPLER_MODE"
+#define SDL_HINT_AUDIO_RESAMPLING_MODE "SDL_AUDIO_RESAMPLING_MODE"
/**
* \brief An enumeration of hint priorities
diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c
index ec4c981..a4fcd11 100644
--- a/src/audio/SDL_audio.c
+++ b/src/audio/SDL_audio.c
@@ -123,22 +123,18 @@ const char* (*SRC_src_strerror)(int error) = NULL;
static SDL_bool
LoadLibSampleRate(void)
{
- const char *hint = SDL_GetHint(SDL_HINT_AUDIO_RESAMPLER_MODE);
+ const char *hint = SDL_GetHint(SDL_HINT_AUDIO_RESAMPLING_MODE);
SRC_available = SDL_FALSE;
SRC_converter = 0;
- if (!hint || (SDL_strcasecmp(hint, "default") == 0)) {
+ if (!hint || *hint == '0' || SDL_strcasecmp(hint, "default") == 0) {
return SDL_FALSE; /* don't load anything. */
- } else if (SDL_strcasecmp(hint, "linear") == 0) {
- SRC_converter = SRC_LINEAR;
- } else if (SDL_strcasecmp(hint, "zero_order_hold") == 0) {
- SRC_converter = SRC_ZERO_ORDER_HOLD;
- } else if (SDL_strcasecmp(hint, "sinc_fastest") == 0) {
+ } else if (*hint == '1' || SDL_strcasecmp(hint, "fast") == 0) {
SRC_converter = SRC_SINC_FASTEST;
- } else if (SDL_strcasecmp(hint, "sinc_medium") == 0) {
+ } else if (*hint == '2' || SDL_strcasecmp(hint, "medium") == 0) {
SRC_converter = SRC_SINC_MEDIUM_QUALITY;
- } else if (SDL_strcasecmp(hint, "sinc_best") == 0) {
+ } else if (*hint == '3' || SDL_strcasecmp(hint, "best") == 0) {
SRC_converter = SRC_SINC_BEST_QUALITY;
} else {
return SDL_FALSE; /* treat it like "default", don't load anything. */