From d3028606c5ae844ac8388ecc1f92ec716a476abe Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 29 Jan 2016 14:47:27 -0800 Subject: [PATCH 1/2] retart the nextFrame and frameTimer on injector restart --- libraries/audio/src/AudioInjector.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libraries/audio/src/AudioInjector.cpp b/libraries/audio/src/AudioInjector.cpp index ea63df7f17..3bd46833d4 100644 --- a/libraries/audio/src/AudioInjector.cpp +++ b/libraries/audio/src/AudioInjector.cpp @@ -102,6 +102,10 @@ void AudioInjector::restart() { // reset the current send offset to zero _currentSendOffset = 0; + // reset the nextFrame and elapsed timer + _nextFrame = 0; + _frameTimer->invalidate(); + // check our state to decide if we need extra handling for the restart request if (_state == State::Finished) { // we finished playing, need to reset state so we can get going again @@ -246,6 +250,11 @@ int64_t AudioInjector::injectNextFrame() { } } + if (!_frameTimer->isValid()) { + // in the case where we have been restarted, the frame timer will be invalid and we need to start it back over here + _frameTimer->restart(); + } + int totalBytesLeftToCopy = (_options.stereo ? 2 : 1) * AudioConstants::NETWORK_FRAME_BYTES_PER_CHANNEL; if (!_options.loop) { // If we aren't looping, let's make sure we don't read past the end From d7990bf88af976a3c9fbe7afe3080988ee5cf5bd Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 29 Jan 2016 14:55:08 -0800 Subject: [PATCH 2/2] reset hasSentFirstFrame to false for double frame on first send --- libraries/audio/src/AudioInjector.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/audio/src/AudioInjector.cpp b/libraries/audio/src/AudioInjector.cpp index 3bd46833d4..157e973f5b 100644 --- a/libraries/audio/src/AudioInjector.cpp +++ b/libraries/audio/src/AudioInjector.cpp @@ -102,9 +102,10 @@ void AudioInjector::restart() { // reset the current send offset to zero _currentSendOffset = 0; - // reset the nextFrame and elapsed timer + // reset state to start sending from beginning again _nextFrame = 0; _frameTimer->invalidate(); + _hasSentFirstFrame = false; // check our state to decide if we need extra handling for the restart request if (_state == State::Finished) {