From b251876126e07891122abde462114d867d957204 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 1 Oct 2018 09:47:10 -0700 Subject: [PATCH] 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 --- include/SDL_audio.h | 3 ++- src/audio/SDL_audio.c | 13 +++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/include/SDL_audio.h b/include/SDL_audio.h index d6ea689543c05..d3e1bface4d40 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 23daf002a0790..2f0854dde94ae 100644 --- a/src/audio/SDL_audio.c +++ b/src/audio/SDL_audio.c @@ -1324,15 +1324,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. */