commit c6b28f46b8116552ec2b38d1d3c8535df28ba7a1 Author: Anthony Pesch Date: Fri May 4 20:21:21 2018 -0400 Added SDL_AUDIO_ALLOW_SAMPLES_CHANGE flag enabling users of SDL_OpenAudioDevice to get the sample size of the actual hardware buffer vs having a stream created to handle the delta diff --git a/include/SDL_audio.h b/include/SDL_audio.h index d6ea68954..d3e1bface 100644 --- a/include/SDL_audio.h +++ b/include/SDL_audio.h @@ -140,7 +140,8 @@ typedef Uint16 SDL_AudioFormat; #define SDL_AUDIO_ALLOW_FREQUENCY_CHANGE 0x00000001 #define SDL_AUDIO_ALLOW_FORMAT_CHANGE 0x00000002 #define SDL_AUDIO_ALLOW_CHANNELS_CHANGE 0x00000004 -#define SDL_AUDIO_ALLOW_ANY_CHANGE (SDL_AUDIO_ALLOW_FREQUENCY_CHANGE|SDL_AUDIO_ALLOW_FORMAT_CHANGE|SDL_AUDIO_ALLOW_CHANNELS_CHANGE) +#define SDL_AUDIO_ALLOW_SAMPLES_CHANGE 0x00000008 +#define SDL_AUDIO_ALLOW_ANY_CHANGE (SDL_AUDIO_ALLOW_FREQUENCY_CHANGE|SDL_AUDIO_ALLOW_FORMAT_CHANGE|SDL_AUDIO_ALLOW_CHANNELS_CHANGE|SDL_AUDIO_ALLOW_SAMPLES_CHANGE) /* @} */ /* @} *//* Audio flags */ diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c index 364e25e3c..3e744d4af 100644 --- a/src/audio/SDL_audio.c +++ b/src/audio/SDL_audio.c @@ -1314,15 +1314,12 @@ open_audio_device(const char *devname, int iscapture, build_stream = SDL_TRUE; } } - - /* !!! FIXME in 2.1: add SDL_AUDIO_ALLOW_SAMPLES_CHANGE flag? - As of 2.0.6, we will build a stream to buffer the difference between - what the app wants to feed and the device wants to eat, so everyone - gets their way. In prior releases, SDL would force the callback to - feed at the rate the device requested, adjusted for resampling. - */ if (device->spec.samples != obtained->samples) { - build_stream = SDL_TRUE; + if (allowed_changes & SDL_AUDIO_ALLOW_SAMPLES_CHANGE) { + obtained->samples = device->spec.samples; + } else { + build_stream = SDL_TRUE; + } } SDL_CalculateAudioSpec(obtained); /* recalc after possible changes. */