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.
This commit is contained in:
David Kelly 2016-10-24 15:18:29 -07:00
parent b5881146df
commit 86e01bbae6

View file

@ -529,14 +529,16 @@ void Agent::processAgentAvatarAudio() {
return; return;
} }
// write the codec
audioPacket->writeString(_selectedCodecName);
// write the number of silent samples so the audio-mixer can uphold timing // 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 // use the orientation and position of this avatar for the source of this audio
audioPacket->writePrimitive(scriptedAvatar->getPosition()); audioPacket->writePrimitive(scriptedAvatar->getPosition());
glm::quat headOrientation = scriptedAvatar->getHeadOrientation(); glm::quat headOrientation = scriptedAvatar->getHeadOrientation();
audioPacket->writePrimitive(headOrientation); audioPacket->writePrimitive(headOrientation);
} else if (nextSoundOutput) { } else if (nextSoundOutput) {
// write the codec // write the codec
@ -550,30 +552,28 @@ void Agent::processAgentAvatarAudio() {
glm::quat headOrientation = scriptedAvatar->getHeadOrientation(); glm::quat headOrientation = scriptedAvatar->getHeadOrientation();
audioPacket->writePrimitive(headOrientation); audioPacket->writePrimitive(headOrientation);
QByteArray decodedBuffer(reinterpret_cast<const char*>(nextSoundOutput), numAvailableSamples*sizeof(int16_t));
QByteArray encodedBuffer;
// encode it // encode it
if(_encoder) { if(_encoder) {
QByteArray decodedBuffer(reinterpret_cast<const char*>(nextSoundOutput), numAvailableSamples*sizeof(int16_t));
QByteArray encodedBuffer;
_encoder->encode(decodedBuffer, encodedBuffer); _encoder->encode(decodedBuffer, encodedBuffer);
audioPacket->write(encodedBuffer.data(), encodedBuffer.size()); } else {
} else { encodedBuffer = decodedBuffer;
audioPacket->write(reinterpret_cast<const char*>(nextSoundOutput), numAvailableSamples*sizeof(int16_t));
} }
audioPacket->write(encodedBuffer.constData(), encodedBuffer.size());
} }
// write audio packet to AudioMixer nodes // write audio packet to AudioMixer nodes
auto nodeList = DependencyManager::get<NodeList>(); auto nodeList = DependencyManager::get<NodeList>();
nodeList->eachNode([this, &nodeList, &audioPacket](const SharedNodePointer& node) { nodeList->eachNode([this, &nodeList, &audioPacket](const SharedNodePointer& node) {
// only send to nodes of type AudioMixer // only send to nodes of type AudioMixer
if (node->getType() == NodeType::AudioMixer) { if (node->getType() == NodeType::AudioMixer) {
// pack sequence number // pack sequence number
quint16 sequence = _outgoingScriptAudioSequenceNumbers[node->getUUID()]++; quint16 sequence = _outgoingScriptAudioSequenceNumbers[node->getUUID()]++;
audioPacket->seek(0); audioPacket->seek(0);
audioPacket->writePrimitive(sequence); audioPacket->writePrimitive(sequence);
// send audio packet
// send audio packet nodeList->sendUnreliablePacket(*audioPacket, *node);
nodeList->sendUnreliablePacket(*audioPacket, *node);
} }
}); });
} }