From 680b795435a5a501a56610258dce5eda40a1725d Mon Sep 17 00:00:00 2001 From: Andy Hung Date: Wed, 12 Nov 2014 13:18:52 -0800 Subject: Fix AudioTrack loop mode to play audio from buffer start Bug: 18217633 Change-Id: Ica77acf0a32832d9b04eb657ef2f4f5329f8fbda --- media/libmedia/AudioTrackShared.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'media/libmedia/AudioTrackShared.cpp') diff --git a/media/libmedia/AudioTrackShared.cpp b/media/libmedia/AudioTrackShared.cpp index 62362da..4a783b3 100644 --- a/media/libmedia/AudioTrackShared.cpp +++ b/media/libmedia/AudioTrackShared.cpp @@ -503,7 +503,11 @@ void StaticAudioTrackClientProxy::setLoop(size_t loopStart, size_t loopEnd, int newState.mLoopStart = (uint32_t) loopStart; newState.mLoopEnd = (uint32_t) loopEnd; newState.mLoopCount = loopCount; - mBufferPosition = loopStart; + size_t bufferPosition; + if (loopCount == 0 || (bufferPosition = getBufferPosition()) >= loopEnd) { + bufferPosition = loopStart; + } + mBufferPosition = bufferPosition; // snapshot buffer position until loop is acknowledged. (void) mMutator.push(newState); } @@ -776,7 +780,9 @@ ssize_t StaticAudioTrackServerProxy::pollPosition() } else if (state.mLoopCount >= -1) { if (loopStart < loopEnd && loopEnd <= mFrameCount && loopEnd - loopStart >= MIN_LOOP) { - if (!(loopStart <= position && position < loopEnd)) { + // If the current position is greater than the end of the loop + // we "wrap" to the loop start. This might cause an audible pop. + if (position >= loopEnd) { mPosition = position = loopStart; } if (state.mLoopCount == -1) { -- cgit v1.1