From 240917e8ae05cb6d835fd6e18387cbd3e4a38b2c Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Mon, 17 Dec 2018 15:46:08 -0800 Subject: [PATCH 1/3] Fix MS20089: Enable interrupting of avatar recordings with sounds --- assignment-client/src/Agent.cpp | 10 ++++++++++ assignment-client/src/Agent.h | 2 ++ 2 files changed, 12 insertions(+) diff --git a/assignment-client/src/Agent.cpp b/assignment-client/src/Agent.cpp index bd368ef7c2..cd2723e896 100644 --- a/assignment-client/src/Agent.cpp +++ b/assignment-client/src/Agent.cpp @@ -756,6 +756,11 @@ void Agent::processAgentAvatarAudio() { const int16_t* nextSoundOutput = NULL; if (_avatarSound) { + if (isPlayingRecording) { + recordingInterface->stopPlaying(); + _recordingInterrupted = true; + } + auto audioData = _avatarSound->getAudioData(); nextSoundOutput = reinterpret_cast(audioData->rawData() + _numAvatarSoundSentBytes); @@ -781,6 +786,11 @@ void Agent::processAgentAvatarAudio() { _avatarSound.clear(); _numAvatarSoundSentBytes = 0; _flushEncoder = true; + + if (_recordingInterrupted) { + _recordingInterrupted = false; + recordingInterface->startPlaying(); + } } } diff --git a/assignment-client/src/Agent.h b/assignment-client/src/Agent.h index 7d47c8e713..19e9a06336 100644 --- a/assignment-client/src/Agent.h +++ b/assignment-client/src/Agent.h @@ -122,6 +122,8 @@ private: Encoder* _encoder { nullptr }; QTimer _avatarAudioTimer; bool _flushEncoder { false }; + + bool _recordingInterrupted { false }; }; #endif // hifi_Agent_h From 2964a05bd3e452c401cc0e5e7349f3ca385028c1 Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Tue, 18 Dec 2018 10:30:20 -0800 Subject: [PATCH 2/3] Keep playing the recording visually --- assignment-client/src/Agent.cpp | 14 ++++++++------ assignment-client/src/Agent.h | 3 +-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/assignment-client/src/Agent.cpp b/assignment-client/src/Agent.cpp index cd2723e896..07d1533101 100644 --- a/assignment-client/src/Agent.cpp +++ b/assignment-client/src/Agent.cpp @@ -428,6 +428,10 @@ void Agent::executeScript() { using namespace recording; static const FrameType AUDIO_FRAME_TYPE = Frame::registerFrameType(AudioConstants::getAudioFrameName()); Frame::registerFrameHandler(AUDIO_FRAME_TYPE, [this, &scriptedAvatar](Frame::ConstPointer frame) { + if (_shouldMuteRecordingAudio) { + return; + } + static quint16 audioSequenceNumber{ 0 }; QByteArray audio(frame->data); @@ -756,9 +760,8 @@ void Agent::processAgentAvatarAudio() { const int16_t* nextSoundOutput = NULL; if (_avatarSound) { - if (isPlayingRecording) { - recordingInterface->stopPlaying(); - _recordingInterrupted = true; + if (isPlayingRecording && !_shouldMuteRecordingAudio) { + _shouldMuteRecordingAudio = true; } auto audioData = _avatarSound->getAudioData(); @@ -787,9 +790,8 @@ void Agent::processAgentAvatarAudio() { _numAvatarSoundSentBytes = 0; _flushEncoder = true; - if (_recordingInterrupted) { - _recordingInterrupted = false; - recordingInterface->startPlaying(); + if (_shouldMuteRecordingAudio) { + _shouldMuteRecordingAudio = false; } } } diff --git a/assignment-client/src/Agent.h b/assignment-client/src/Agent.h index 19e9a06336..8951fffb8c 100644 --- a/assignment-client/src/Agent.h +++ b/assignment-client/src/Agent.h @@ -107,6 +107,7 @@ private: ResourceRequest* _pendingScriptRequest { nullptr }; bool _isListeningToAudioStream = false; SharedSoundPointer _avatarSound; + bool _shouldMuteRecordingAudio{ false }; int _numAvatarSoundSentBytes = 0; bool _isAvatar = false; QTimer* _avatarIdentityTimer = nullptr; @@ -122,8 +123,6 @@ private: Encoder* _encoder { nullptr }; QTimer _avatarAudioTimer; bool _flushEncoder { false }; - - bool _recordingInterrupted { false }; }; #endif // hifi_Agent_h From f31d685323c276e798a1b8850cda2edb3c324202 Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Tue, 18 Dec 2018 14:33:41 -0800 Subject: [PATCH 3/3] Fix spacing --- assignment-client/src/Agent.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assignment-client/src/Agent.h b/assignment-client/src/Agent.h index 8951fffb8c..244f72e624 100644 --- a/assignment-client/src/Agent.h +++ b/assignment-client/src/Agent.h @@ -107,7 +107,7 @@ private: ResourceRequest* _pendingScriptRequest { nullptr }; bool _isListeningToAudioStream = false; SharedSoundPointer _avatarSound; - bool _shouldMuteRecordingAudio{ false }; + bool _shouldMuteRecordingAudio { false }; int _numAvatarSoundSentBytes = 0; bool _isAvatar = false; QTimer* _avatarIdentityTimer = nullptr;