Skip to content

Commit

Permalink
[SDL][IOS] Audio fix - applies stream to sound data when resampling o…
Browse files Browse the repository at this point in the history
…r reformatting is required.
  • Loading branch information
slouken committed Aug 22, 2019
1 parent 5c15e81 commit b521df6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Empty file modified Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj 100644 → 100755
Empty file.
30 changes: 29 additions & 1 deletion src/audio/coreaudio/SDL_coreaudio.m
Expand Up @@ -417,7 +417,35 @@ static BOOL update_audio_session(_THIS, SDL_bool open)
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;

Expand Down

0 comments on commit b521df6

Please sign in to comment.