From b4c064a5386ee37c7ff049b041c7b49a3b5c4b16 Mon Sep 17 00:00:00 2001 From: David Kelly Date: Fri, 7 Oct 2016 13:20:08 -0700 Subject: [PATCH] Hack in a 100hz timer sounds crappy, more to do, just push to not lose anything. --- assignment-client/src/Agent.cpp | 14 +++++++++----- assignment-client/src/Agent.h | 6 +++--- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/assignment-client/src/Agent.cpp b/assignment-client/src/Agent.cpp index 067cab41da..9b7e8b45c5 100644 --- a/assignment-client/src/Agent.cpp +++ b/assignment-client/src/Agent.cpp @@ -373,8 +373,13 @@ void Agent::executeScript() { DependencyManager::set(_entityViewer.getTree()); + _avatarAudioTimer = new QTimer(this); + _avatarAudioTimer->setTimerType(Qt::PreciseTimer); + connect(_avatarAudioTimer, SIGNAL(timeout()), this, SLOT(processAgentAvatarAndAudio())); + _avatarAudioTimer->start(10); + // wire up our additional agent related processing to the update signal - QObject::connect(_scriptEngine.get(), &ScriptEngine::update, this, &Agent::processAgentAvatarAndAudio); + //QObject::connect(_scriptEngine.get(), &ScriptEngine::update, this, &Agent::processAgentAvatarAndAudio); _scriptEngine->run(); @@ -420,10 +425,10 @@ void Agent::sendAvatarIdentityPacket() { } } -void Agent::processAgentAvatarAndAudio(float deltaTime) { +void Agent::processAgentAvatarAndAudio() { if (!_scriptEngine->isFinished() && _isAvatar) { auto scriptedAvatar = DependencyManager::get(); - const int SCRIPT_AUDIO_BUFFER_SAMPLES = AudioConstants::SAMPLE_RATE / SCRIPT_FPS + 0.5; + const int SCRIPT_AUDIO_BUFFER_SAMPLES = AudioConstants::SAMPLE_RATE / 100;//SCRIPT_FPS + 0.5; const int SCRIPT_AUDIO_BUFFER_BYTES = SCRIPT_AUDIO_BUFFER_SAMPLES * sizeof(int16_t); QByteArray avatarByteArray = scriptedAvatar->toByteArray(true, randFloat() < AVATAR_SEND_FULL_UPDATE_RATIO); @@ -513,10 +518,9 @@ void Agent::processAgentAvatarAndAudio(float deltaTime) { if (_encoder) { _encoder->encode(decodedBuffer, encodedBuffer); } else { - encodedBuffer = decodedBuffer; + audioPacket->write(decodedBuffer.data(), decodedBuffer.size()); } - // write the raw audio data audioPacket->write(encodedBuffer.data(), encodedBuffer.size()); } diff --git a/assignment-client/src/Agent.h b/assignment-client/src/Agent.h index e65d03a5b1..13ed8f7958 100644 --- a/assignment-client/src/Agent.h +++ b/assignment-client/src/Agent.h @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -70,7 +71,7 @@ private slots: void handleJurisdictionPacket(QSharedPointer message, SharedNodePointer senderNode); void handleSelectedAudioFormat(QSharedPointer message); - void processAgentAvatarAndAudio(float deltaTime); + void processAgentAvatarAndAudio(); void nodeActivated(SharedNodePointer activatedNode); private: @@ -101,8 +102,7 @@ private: CodecPluginPointer _codec; QString _selectedCodecName; Encoder* _encoder { nullptr }; - - + QTimer* _avatarAudioTimer; }; #endif // hifi_Agent_h