Skip to content

Commit

Permalink
Fixed audio being silent on older iOS devices
Browse files Browse the repository at this point in the history
Tested on an iPod running iOS 6.1
  • Loading branch information
slouken committed Sep 22, 2017
1 parent 12efabc commit 407e169
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/audio/coreaudio/SDL_coreaudio.m
Expand Up @@ -326,7 +326,7 @@ static BOOL update_audio_session(_THIS, SDL_bool open)
@autoreleasepool {
AVAudioSession *session = [AVAudioSession sharedInstance];
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;
NSError *err = nil;

Expand Down Expand Up @@ -674,11 +674,19 @@ static BOOL update_audio_session(_THIS, SDL_bool open)
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;
int numAudioBuffers = 2;
if (msecs < 10.0) { /* use more buffers if we have a VERY small sample set. */
numAudioBuffers = (int) (SDL_ceil(10.0 / msecs) * 2);
if (msecs < MINIMUM_AUDIO_BUFFER_TIME_MS) { /* use more buffers if we have a VERY small sample set. */
numAudioBuffers = ((int)SDL_ceil(MINIMUM_AUDIO_BUFFER_TIME_MS / msecs) * 2);
}

this->hidden->audioBuffer = SDL_calloc(1, sizeof (AudioQueueBufferRef) * numAudioBuffers);
Expand Down

0 comments on commit 407e169

Please sign in to comment.