From 407ad633e0facf8143dd17722bfa0fc384853f92 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 11 Jan 2017 11:01:49 -0800 Subject: [PATCH] more cleanup use kens 1 byte audio gain --- libraries/avatars/src/AvatarData.cpp | 35 +++------------------------- libraries/avatars/src/AvatarData.h | 10 +++----- 2 files changed, 6 insertions(+), 39 deletions(-) diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index e70e73f8b5..5a781340a1 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include "AvatarLogging.h" @@ -314,14 +315,6 @@ QByteArray AvatarData::toByteArray(AvatarDataDetail dataDetail, quint64 lastSent if (hasAvatarOrientation) { auto localOrientation = getLocalOrientation(); - /* - auto data = reinterpret_cast(destinationBuffer); - glm::vec3 bodyEulerAngles = glm::degrees(safeEulerAngles(localOrientation)); - packFloatAngleToTwoByte((uint8_t*)(data->localOrientation + 0), bodyEulerAngles.y); - packFloatAngleToTwoByte((uint8_t*)(data->localOrientation + 1), bodyEulerAngles.x); - packFloatAngleToTwoByte((uint8_t*)(data->localOrientation + 2), bodyEulerAngles.z); - destinationBuffer += sizeof(AvatarDataPacket::AvatarOrientation); - */ destinationBuffer += packOrientationQuatToSixBytes(destinationBuffer, localOrientation); } @@ -343,8 +336,7 @@ QByteArray AvatarData::toByteArray(AvatarDataDetail dataDetail, quint64 lastSent if (hasAudioLoudness) { auto data = reinterpret_cast(destinationBuffer); - auto audioLoudness = glm::min(_headData->getAudioLoudness(), MAX_AUDIO_LOUDNESS); - packFloatScalarToSignedTwoByteFixed((uint8_t*)&data->audioLoudness, audioLoudness, AUDIO_LOUDNESS_RADIX); + data->audioLoudness = packFloatGainToByte(_headData->getAudioLoudness()); destinationBuffer += sizeof(AvatarDataPacket::AudioLoudness); } @@ -705,29 +697,9 @@ int AvatarData::parseDataFromBuffer(const QByteArray& buffer) { if (hasAvatarOrientation) { auto startSection = sourceBuffer; - PACKET_READ_CHECK(AvatarOrientation, sizeof(AvatarDataPacket::AvatarOrientation)); - - /* - auto data = reinterpret_cast(sourceBuffer); - float pitch, yaw, roll; - unpackFloatAngleFromTwoByte(data->localOrientation + 0, &yaw); - unpackFloatAngleFromTwoByte(data->localOrientation + 1, &pitch); - unpackFloatAngleFromTwoByte(data->localOrientation + 2, &roll); - if (isNaN(yaw) || isNaN(pitch) || isNaN(roll)) { - if (shouldLogError(now)) { - qCWarning(avatars) << "Discard AvatarData packet: localOriention is NaN, uuid " << getSessionUUID(); - } - return buffer.size(); - } - glm::vec3 newEulerAngles(pitch, yaw, roll); - glm::quat newOrientation = glm::quat(glm::radians(newEulerAngles)); - sourceBuffer += sizeof(AvatarDataPacket::AvatarOrientation); - */ - glm::quat newOrientation; sourceBuffer += unpackOrientationQuatFromSixBytes(sourceBuffer, newOrientation); - glm::quat currentOrientation = getLocalOrientation(); if (currentOrientation != newOrientation) { _hasNewJointRotations = true; @@ -779,8 +751,7 @@ int AvatarData::parseDataFromBuffer(const QByteArray& buffer) { PACKET_READ_CHECK(AudioLoudness, sizeof(AvatarDataPacket::AudioLoudness)); auto data = reinterpret_cast(sourceBuffer); - float audioLoudness; - unpackFloatScalarFromSignedTwoByteFixed((int16_t*)&data->audioLoudness, &audioLoudness, AUDIO_LOUDNESS_RADIX); + float audioLoudness = unpackFloatGainFromByte(data->audioLoudness); if (isNaN(audioLoudness)) { if (shouldLogError(now)) { diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index a31166920a..7e3a9f2923 100644 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -179,16 +179,12 @@ namespace AvatarDataPacket { using SixByteQuat = uint8_t[6]; PACKED_BEGIN struct AvatarOrientation { - //smallFloat localOrientation[3]; // avatar's local euler angles (degrees, compressed) relative to the - // thing it's attached to, or world relative if not attached - SixByteQuat avatarOrientation; // encodeded and compressed by packOrientationQuatToSixBytes() - } PACKED_END; const size_t AVATAR_ORIENTATION_SIZE = 6; PACKED_BEGIN struct AvatarScale { - smallFloat scale; // avatar's scale, (compressed) 'ratio' encoding uses sign bit as flag. + smallFloat scale; // avatar's scale, compressed by packFloatRatioToTwoByte() } PACKED_END; const size_t AVATAR_SCALE_SIZE = 2; @@ -204,9 +200,9 @@ namespace AvatarDataPacket { const size_t LOOK_AT_POSITION_SIZE = 12; PACKED_BEGIN struct AudioLoudness { - smallFloat audioLoudness; // current loudness of microphone, (compressed) + uint8_t audioLoudness; // current loudness of microphone, compressed by packFloatGainToByte() } PACKED_END; - const size_t AUDIO_LOUDNESS_SIZE = 2; + const size_t AUDIO_LOUDNESS_SIZE = 1; PACKED_BEGIN struct SensorToWorldMatrix { // FIXME - these 20 bytes are only used by viewers if my avatar has "attachments"