From b521df66c3384b1bf1dea92dc2489da27c8fc461 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 22 Aug 2019 16:09:42 -0700 Subject: [PATCH] [SDL][IOS] Audio fix - applies stream to sound data when resampling or reformatting is required. --- Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj | 0 src/audio/coreaudio/SDL_coreaudio.m | 30 ++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) mode change 100644 => 100755 Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj diff --git a/Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj b/Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj old mode 100644 new mode 100755 diff --git a/src/audio/coreaudio/SDL_coreaudio.m b/src/audio/coreaudio/SDL_coreaudio.m index e1f56ae93..b6c49abb1 100644 --- a/src/audio/coreaudio/SDL_coreaudio.m +++ b/src/audio/coreaudio/SDL_coreaudio.m @@ -417,7 +417,35 @@ outputCallback(void *inUserData, AudioQueueRef inAQ, AudioQueueBufferRef inBuffe if (!SDL_AtomicGet(&this->enabled) || SDL_AtomicGet(&this->paused)) { /* Supply silence if audio is not enabled or paused */ SDL_memset(inBuffer->mAudioData, this->spec.silence, inBuffer->mAudioDataBytesCapacity); - } else { + } else if (this->stream ) { + UInt32 remaining = inBuffer->mAudioDataBytesCapacity; + Uint8 *ptr = (Uint8 *) inBuffer->mAudioData; + + while (remaining > 0) { + if ( SDL_AudioStreamAvailable(this->stream) == 0 ) { + /* Generate the data */ + SDL_LockMutex(this->mixer_lock); + (*this->callbackspec.callback)(this->callbackspec.userdata, + this->hidden->buffer, this->hidden->bufferSize); + SDL_UnlockMutex(this->mixer_lock); + this->hidden->bufferOffset = 0; + SDL_AudioStreamPut(this->stream, this->hidden->buffer, this->hidden->bufferSize); + } + if ( SDL_AudioStreamAvailable(this->stream) > 0 ) { + int got; + UInt32 len = SDL_AudioStreamAvailable(this->stream); + if ( len > remaining ) + len = remaining; + got = SDL_AudioStreamGet(this->stream, ptr, len); + SDL_assert((got < 0) || (got == len)); + if (got != len) { + SDL_memset(ptr, this->spec.silence, len); + } + ptr = ptr + len; + remaining -= len; + } + } + } else { UInt32 remaining = inBuffer->mAudioDataBytesCapacity; Uint8 *ptr = (Uint8 *) inBuffer->mAudioData;