mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 11:28:03 +02:00
no need to get the ScriptableAvatar from DependencyManager every time
This commit is contained in:
parent
e8b48eb3aa
commit
81451191c1
2 changed files with 8 additions and 9 deletions
|
@ -43,7 +43,6 @@
|
||||||
#include <WebSocketServerClass.h>
|
#include <WebSocketServerClass.h>
|
||||||
#include <EntityScriptingInterface.h> // TODO: consider moving to scriptengine.h
|
#include <EntityScriptingInterface.h> // TODO: consider moving to scriptengine.h
|
||||||
|
|
||||||
#include "avatars/ScriptableAvatar.h"
|
|
||||||
#include "entities/AssignmentParentFinder.h"
|
#include "entities/AssignmentParentFinder.h"
|
||||||
#include "RecordingScriptingInterface.h"
|
#include "RecordingScriptingInterface.h"
|
||||||
#include "AbstractAudioInterface.h"
|
#include "AbstractAudioInterface.h"
|
||||||
|
@ -380,7 +379,7 @@ void Agent::executeScript() {
|
||||||
audioTransform.setTranslation(scriptedAvatar->getPosition());
|
audioTransform.setTranslation(scriptedAvatar->getPosition());
|
||||||
audioTransform.setRotation(headOrientation);
|
audioTransform.setRotation(headOrientation);
|
||||||
|
|
||||||
computeLoudness(&audio);
|
computeLoudness(&audio, scriptedAvatar);
|
||||||
|
|
||||||
QByteArray encodedBuffer;
|
QByteArray encodedBuffer;
|
||||||
if (_encoder) {
|
if (_encoder) {
|
||||||
|
@ -573,9 +572,8 @@ void Agent::encodeFrameOfZeros(QByteArray& encodedZeros) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Agent::computeLoudness(const QByteArray* decodedBuffer) {
|
void Agent::computeLoudness(const QByteArray* decodedBuffer, QSharedPointer<ScriptableAvatar> scriptableAvatar) {
|
||||||
float loudness = 0.0f;
|
float loudness = 0.0f;
|
||||||
auto scriptedAvatar = DependencyManager::get<ScriptableAvatar>();
|
|
||||||
if (decodedBuffer) {
|
if (decodedBuffer) {
|
||||||
auto soundData = reinterpret_cast<const int16_t*>(decodedBuffer->constData());
|
auto soundData = reinterpret_cast<const int16_t*>(decodedBuffer->constData());
|
||||||
int numFrames = decodedBuffer->size() / sizeof(int16_t);
|
int numFrames = decodedBuffer->size() / sizeof(int16_t);
|
||||||
|
@ -587,7 +585,7 @@ void Agent::computeLoudness(const QByteArray* decodedBuffer) {
|
||||||
loudness /= numFrames;
|
loudness /= numFrames;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
scriptedAvatar->setAudioLoudness(loudness);
|
scriptableAvatar->setAudioLoudness(loudness);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Agent::processAgentAvatarAudio() {
|
void Agent::processAgentAvatarAudio() {
|
||||||
|
@ -640,7 +638,7 @@ void Agent::processAgentAvatarAudio() {
|
||||||
|
|
||||||
if (silentFrame) {
|
if (silentFrame) {
|
||||||
// no matter what, the loudness should be set to 0
|
// no matter what, the loudness should be set to 0
|
||||||
computeLoudness(nullptr);
|
computeLoudness(nullptr, scriptedAvatar);
|
||||||
|
|
||||||
if (!_isListeningToAudioStream) {
|
if (!_isListeningToAudioStream) {
|
||||||
// if we have a silent frame and we're not listening then just send nothing and break out of here
|
// if we have a silent frame and we're not listening then just send nothing and break out of here
|
||||||
|
@ -679,7 +677,7 @@ void Agent::processAgentAvatarAudio() {
|
||||||
if (_flushEncoder) {
|
if (_flushEncoder) {
|
||||||
encodeFrameOfZeros(encodedBuffer);
|
encodeFrameOfZeros(encodedBuffer);
|
||||||
// loudness is 0
|
// loudness is 0
|
||||||
computeLoudness(nullptr);
|
computeLoudness(nullptr, scriptedAvatar);
|
||||||
} else {
|
} else {
|
||||||
QByteArray decodedBuffer(reinterpret_cast<const char*>(nextSoundOutput), numAvailableSamples*sizeof(int16_t));
|
QByteArray decodedBuffer(reinterpret_cast<const char*>(nextSoundOutput), numAvailableSamples*sizeof(int16_t));
|
||||||
if (_encoder) {
|
if (_encoder) {
|
||||||
|
@ -688,7 +686,7 @@ void Agent::processAgentAvatarAudio() {
|
||||||
} else {
|
} else {
|
||||||
encodedBuffer = decodedBuffer;
|
encodedBuffer = decodedBuffer;
|
||||||
}
|
}
|
||||||
computeLoudness(&decodedBuffer);
|
computeLoudness(&decodedBuffer, scriptedAvatar);
|
||||||
}
|
}
|
||||||
audioPacket->write(encodedBuffer.constData(), encodedBuffer.size());
|
audioPacket->write(encodedBuffer.constData(), encodedBuffer.size());
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
#include <plugins/CodecPlugin.h>
|
#include <plugins/CodecPlugin.h>
|
||||||
|
|
||||||
#include "MixedAudioStream.h"
|
#include "MixedAudioStream.h"
|
||||||
|
#include "avatars/ScriptableAvatar.h"
|
||||||
|
|
||||||
class Agent : public ThreadedAssignment {
|
class Agent : public ThreadedAssignment {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -82,7 +83,7 @@ private:
|
||||||
void negotiateAudioFormat();
|
void negotiateAudioFormat();
|
||||||
void selectAudioFormat(const QString& selectedCodecName);
|
void selectAudioFormat(const QString& selectedCodecName);
|
||||||
void encodeFrameOfZeros(QByteArray& encodedZeros);
|
void encodeFrameOfZeros(QByteArray& encodedZeros);
|
||||||
void computeLoudness(const QByteArray* decodedBuffer);
|
void computeLoudness(const QByteArray* decodedBuffer, QSharedPointer<ScriptableAvatar>);
|
||||||
|
|
||||||
std::unique_ptr<ScriptEngine> _scriptEngine;
|
std::unique_ptr<ScriptEngine> _scriptEngine;
|
||||||
EntityEditPacketSender _entityEditSender;
|
EntityEditPacketSender _entityEditSender;
|
||||||
|
|
Loading…
Reference in a new issue