History

have agent optionally send silent stream flag

Stephen Birarda committed 12 years ago

Commit 7e0da711 parent d652cec1 file · +24 −3Browse files

Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 1 file). Show all

Unified · Split

libraries/script-engine/src/ScriptEngine.cpp+24−3
@@ -267,15 +267,36 @@ void ScriptEngine::run() { · 266 unmodified lines
267 267
268 if (_avatarAudioBuffer && _numAvatarAudioBufferSamples > 0) {268 if (_avatarAudioBuffer && _numAvatarAudioBufferSamples > 0) {
269 // if have an avatar audio stream then send it out to our audio-mixer269 // if have an avatar audio stream then send it out to our audio-mixer
270 QByteArray audioPacket = byteArrayWithPopulatedHeader(PacketTypeMicrophoneAudioNoEcho);270
271 bool silentFrame = true;
272
273 // check if the all of the _numAvatarAudioBufferSamples to be sent are silence
274 for (int i = 0; i < _numAvatarAudioBufferSamples; ++i) {
275 if (_avatarAudioBuffer[i] != 0) {
276 silentFrame = false;
277 break;
278 }
279 }
280
281 QByteArray audioPacket = byteArrayWithPopulatedHeader(silentFrame
282 ? PacketTypeSilentAudioFrame
283 : PacketTypeMicrophoneAudioNoEcho);
271 QDataStream packetStream(&audioPacket, QIODevice::Append);284 QDataStream packetStream(&audioPacket, QIODevice::Append);
272 285
273 // use the orientation and position of this avatar for the source of this audio286 // use the orientation and position of this avatar for the source of this audio
274 packetStream.writeRawData(reinterpret_cast<const char*>(&_avatarData->getPosition()), sizeof(glm::vec3));287 packetStream.writeRawData(reinterpret_cast<const char*>(&_avatarData->getPosition()), sizeof(glm::vec3));
275 glm::quat headOrientation = _avatarData->getHeadOrientation();288 glm::quat headOrientation = _avatarData->getHeadOrientation();
276 packetStream.writeRawData(reinterpret_cast<const char*>(&headOrientation), sizeof(glm::quat));289 packetStream.writeRawData(reinterpret_cast<const char*>(&headOrientation), sizeof(glm::quat));
277 packetStream.writeRawData(reinterpret_cast<const char*>(_avatarAudioBuffer),290
278 _numAvatarAudioBufferSamples * sizeof(int16_t));291 if (silentFrame) {
292 // write the number of silent samples so the audio-mixer can uphold timing
293 int16_t numSilentSamples = _numAvatarAudioBufferSamples;
294 packetStream.writeRawData(reinterpret_cast<const char*>(&numSilentSamples), sizeof(int16_t));
295 } else {
296 // write the raw audio data
297 packetStream.writeRawData(reinterpret_cast<const char*>(_avatarAudioBuffer),
298 _numAvatarAudioBufferSamples * sizeof(int16_t));
299 }
279 300
280 nodeList->broadcastToNodes(audioPacket, NodeSet() << NodeType::AudioMixer);301 nodeList->broadcastToNodes(audioPacket, NodeSet() << NodeType::AudioMixer);
281 }302 }