mirror of
https://github.com/lubosz/overte.git
synced 2025-04-24 12:43:19 +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 <EntityScriptingInterface.h> // TODO: consider moving to scriptengine.h
|
||||
|
||||
#include "avatars/ScriptableAvatar.h"
|
||||
#include "entities/AssignmentParentFinder.h"
|
||||
#include "RecordingScriptingInterface.h"
|
||||
#include "AbstractAudioInterface.h"
|
||||
|
@ -380,7 +379,7 @@ void Agent::executeScript() {
|
|||
audioTransform.setTranslation(scriptedAvatar->getPosition());
|
||||
audioTransform.setRotation(headOrientation);
|
||||
|
||||
computeLoudness(&audio);
|
||||
computeLoudness(&audio, scriptedAvatar);
|
||||
|
||||
QByteArray encodedBuffer;
|
||||
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;
|
||||
auto scriptedAvatar = DependencyManager::get<ScriptableAvatar>();
|
||||
if (decodedBuffer) {
|
||||
auto soundData = reinterpret_cast<const int16_t*>(decodedBuffer->constData());
|
||||
int numFrames = decodedBuffer->size() / sizeof(int16_t);
|
||||
|
@ -587,7 +585,7 @@ void Agent::computeLoudness(const QByteArray* decodedBuffer) {
|
|||
loudness /= numFrames;
|
||||
}
|
||||
}
|
||||
scriptedAvatar->setAudioLoudness(loudness);
|
||||
scriptableAvatar->setAudioLoudness(loudness);
|
||||
}
|
||||
|
||||
void Agent::processAgentAvatarAudio() {
|
||||
|
@ -640,7 +638,7 @@ void Agent::processAgentAvatarAudio() {
|
|||
|
||||
if (silentFrame) {
|
||||
// no matter what, the loudness should be set to 0
|
||||
computeLoudness(nullptr);
|
||||
computeLoudness(nullptr, scriptedAvatar);
|
||||
|
||||
if (!_isListeningToAudioStream) {
|
||||
// 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) {
|
||||
encodeFrameOfZeros(encodedBuffer);
|
||||
// loudness is 0
|
||||
computeLoudness(nullptr);
|
||||
computeLoudness(nullptr, scriptedAvatar);
|
||||
} else {
|
||||
QByteArray decodedBuffer(reinterpret_cast<const char*>(nextSoundOutput), numAvailableSamples*sizeof(int16_t));
|
||||
if (_encoder) {
|
||||
|
@ -688,7 +686,7 @@ void Agent::processAgentAvatarAudio() {
|
|||
} else {
|
||||
encodedBuffer = decodedBuffer;
|
||||
}
|
||||
computeLoudness(&decodedBuffer);
|
||||
computeLoudness(&decodedBuffer, scriptedAvatar);
|
||||
}
|
||||
audioPacket->write(encodedBuffer.constData(), encodedBuffer.size());
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include <plugins/CodecPlugin.h>
|
||||
|
||||
#include "MixedAudioStream.h"
|
||||
#include "avatars/ScriptableAvatar.h"
|
||||
|
||||
class Agent : public ThreadedAssignment {
|
||||
Q_OBJECT
|
||||
|
@ -82,7 +83,7 @@ private:
|
|||
void negotiateAudioFormat();
|
||||
void selectAudioFormat(const QString& selectedCodecName);
|
||||
void encodeFrameOfZeros(QByteArray& encodedZeros);
|
||||
void computeLoudness(const QByteArray* decodedBuffer);
|
||||
void computeLoudness(const QByteArray* decodedBuffer, QSharedPointer<ScriptableAvatar>);
|
||||
|
||||
std::unique_ptr<ScriptEngine> _scriptEngine;
|
||||
EntityEditPacketSender _entityEditSender;
|
||||
|
|
Loading…
Reference in a new issue