Fixed audio being silent on older iOS devices

Tested on an iPod running iOS 6.1
This commit is contained in:
Sam Lantinga 2017-09-22 11:15:14 -07:00
parent 12efabcbf0
commit 407e1693ae

View File

@ -326,7 +326,7 @@ static BOOL update_audio_session(_THIS, SDL_bool open)
@autoreleasepool { @autoreleasepool {
AVAudioSession *session = [AVAudioSession sharedInstance]; AVAudioSession *session = [AVAudioSession sharedInstance];
NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
/* Set category to ambient by default so that other music continues playing. */ /* Set category to ambient by default so that other music continues playing. */
NSString *category = AVAudioSessionCategoryAmbient; NSString *category = AVAudioSessionCategoryAmbient;
NSError *err = nil; NSError *err = nil;
@ -674,11 +674,19 @@ prepare_audioqueue(_THIS)
return 0; return 0;
} }
/* Make sure we can feed the device at least 50 milliseconds at a time. */ /* Make sure we can feed the device a minimum amount of time */
double MINIMUM_AUDIO_BUFFER_TIME_MS;
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_7_1) {
/* Older hardware, use 40 ms as a minimum time */
MINIMUM_AUDIO_BUFFER_TIME_MS = 40.0;
} else {
/* Newer hardware, use 15 ms as a minimum time */
MINIMUM_AUDIO_BUFFER_TIME_MS = 15.0;
}
const double msecs = (this->spec.samples / ((double) this->spec.freq)) * 1000.0; const double msecs = (this->spec.samples / ((double) this->spec.freq)) * 1000.0;
int numAudioBuffers = 2; int numAudioBuffers = 2;
if (msecs < 10.0) { /* use more buffers if we have a VERY small sample set. */ if (msecs < MINIMUM_AUDIO_BUFFER_TIME_MS) { /* use more buffers if we have a VERY small sample set. */
numAudioBuffers = (int) (SDL_ceil(10.0 / msecs) * 2); numAudioBuffers = ((int)SDL_ceil(MINIMUM_AUDIO_BUFFER_TIME_MS / msecs) * 2);
} }
this->hidden->audioBuffer = SDL_calloc(1, sizeof (AudioQueueBufferRef) * numAudioBuffers); this->hidden->audioBuffer = SDL_calloc(1, sizeof (AudioQueueBufferRef) * numAudioBuffers);