From 86e01bbae6f4e6179510d5d4d09186b1049ae98f Mon Sep 17 00:00:00 2001 From: David Kelly Date: Mon, 24 Oct 2016 15:18:29 -0700 Subject: [PATCH] First cut Started with the horrible screaming when avatar goes away, seems due to not putting a codec string in the packets. This was an existing issue, not due to recent changes. Also, some weird indenting was fixed, etc... Still hear an artifact when audio starts, but only when a codec was negotiated. Hoping to fix that too. --- assignment-client/src/Agent.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/assignment-client/src/Agent.cpp b/assignment-client/src/Agent.cpp index eebd2a81e7..5c97385ea4 100644 --- a/assignment-client/src/Agent.cpp +++ b/assignment-client/src/Agent.cpp @@ -529,14 +529,16 @@ void Agent::processAgentAvatarAudio() { return; } + // write the codec + audioPacket->writeString(_selectedCodecName); + // write the number of silent samples so the audio-mixer can uphold timing - audioPacket->writePrimitive(AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL); + audioPacket->writePrimitive(numAvailableSamples); // use the orientation and position of this avatar for the source of this audio audioPacket->writePrimitive(scriptedAvatar->getPosition()); glm::quat headOrientation = scriptedAvatar->getHeadOrientation(); audioPacket->writePrimitive(headOrientation); - } else if (nextSoundOutput) { // write the codec @@ -550,30 +552,28 @@ void Agent::processAgentAvatarAudio() { glm::quat headOrientation = scriptedAvatar->getHeadOrientation(); audioPacket->writePrimitive(headOrientation); + QByteArray decodedBuffer(reinterpret_cast(nextSoundOutput), numAvailableSamples*sizeof(int16_t)); + QByteArray encodedBuffer; // encode it if(_encoder) { - QByteArray decodedBuffer(reinterpret_cast(nextSoundOutput), numAvailableSamples*sizeof(int16_t)); - QByteArray encodedBuffer; _encoder->encode(decodedBuffer, encodedBuffer); - audioPacket->write(encodedBuffer.data(), encodedBuffer.size()); - } else { - audioPacket->write(reinterpret_cast(nextSoundOutput), numAvailableSamples*sizeof(int16_t)); + } else { + encodedBuffer = decodedBuffer; } - + audioPacket->write(encodedBuffer.constData(), encodedBuffer.size()); } - // write audio packet to AudioMixer nodes + // write audio packet to AudioMixer nodes auto nodeList = DependencyManager::get(); nodeList->eachNode([this, &nodeList, &audioPacket](const SharedNodePointer& node) { // only send to nodes of type AudioMixer if (node->getType() == NodeType::AudioMixer) { - // pack sequence number - quint16 sequence = _outgoingScriptAudioSequenceNumbers[node->getUUID()]++; - audioPacket->seek(0); - audioPacket->writePrimitive(sequence); - - // send audio packet - nodeList->sendUnreliablePacket(*audioPacket, *node); + // pack sequence number + quint16 sequence = _outgoingScriptAudioSequenceNumbers[node->getUUID()]++; + audioPacket->seek(0); + audioPacket->writePrimitive(sequence); + // send audio packet + nodeList->sendUnreliablePacket(*audioPacket, *node); } }); }