Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 14 files). Show all
Unified · Split
| @@ -459,32 +459,55 @@ void ScriptEngine::run() { · 458 unmodified lines | |||
| 459 | } | 459 | } |
| 460 | } | 460 | } |
| 461 | 461 | ||
| 462 | QByteArray audioPacket = byteArrayWithPopulatedHeader(silentFrame | 462 | char audioPacket[MAX_PACKET_SIZE]; |
| 463 | ? PacketTypeSilentAudioFrame | ||
| 464 | : PacketTypeMicrophoneAudioNoEcho); | ||
| 465 | 463 | ||
| 466 | QDataStream packetStream(&audioPacket, QIODevice::Append); | 464 | // pack header |
| 465 | int numBytesPacketHeader = populatePacketHeader(audioPacket, silentFrame | ||
| 466 | ? PacketTypeSilentAudioFrame | ||
| 467 | : PacketTypeMicrophoneAudioNoEcho); | ||
| 468 | char* dataAt = audioPacket + numBytesPacketHeader; | ||
| 469 | |||
| 470 | // skip over sequence number for now; will be packed when destination node is known | ||
| 471 | char* sequenceAt = dataAt; | ||
| 472 | dataAt += sizeof(quint16); | ||
| 467 | 473 | ||
| 468 | // use the orientation and position of this avatar for the source of this audio | 474 | // use the orientation and position of this avatar for the source of this audio |
| 469 | packetStream.writeRawData(reinterpret_cast<const char*>(&_avatarData->getPosition()), sizeof(glm::vec3)); | 475 | memcpy(dataAt, &_avatarData->getPosition(), sizeof(glm::vec3)); |
| 476 | dataAt += sizeof(glm::vec3); | ||
| 477 | |||
| 470 | glm::quat headOrientation = _avatarData->getHeadOrientation(); | 478 | glm::quat headOrientation = _avatarData->getHeadOrientation(); |
| 471 | packetStream.writeRawData(reinterpret_cast<const char*>(&headOrientation), sizeof(glm::quat)); | 479 | memcpy(dataAt, &headOrientation, sizeof(glm::quat)); |
| 480 | dataAt += sizeof(glm::quat); | ||
| 472 | 481 | ||
| 473 | if (silentFrame) { | 482 | if (silentFrame) { |
| 474 | if (!_isListeningToAudioStream) { | 483 | if (!_isListeningToAudioStream) { |
| 475 | // if we have a silent frame and we're not listening then just send nothing and break out of here | 484 | // if we have a silent frame and we're not listening then just send nothing and break out of here |
| 476 | break; | 485 | break; |
| 477 | } | 486 | } |
| 478 | |||
| 479 | // write the number of silent samples so the audio-mixer can uphold timing | 487 | // write the number of silent samples so the audio-mixer can uphold timing |
| 480 | packetStream.writeRawData(reinterpret_cast<const char*>(&SCRIPT_AUDIO_BUFFER_SAMPLES), sizeof(int16_t)); | 488 | memcpy(dataAt, &SCRIPT_AUDIO_BUFFER_SAMPLES, sizeof(int16_t)); |
| 489 | dataAt += sizeof(int16_t); | ||
| 481 | } else if (nextSoundOutput) { | 490 | } else if (nextSoundOutput) { |
| 482 | // write the raw audio data | 491 | // write the raw audio data |
| 483 | packetStream.writeRawData(reinterpret_cast<const char*>(nextSoundOutput), | 492 | int numAvailableBytes = numAvailableSamples * sizeof(int16_t); |
| 484 | numAvailableSamples * sizeof(int16_t)); | 493 | memcpy(dataAt, nextSoundOutput, numAvailableBytes); |
| 494 | dataAt += numAvailableBytes; | ||
| 485 | } | 495 | } |
| 486 | 496 | ||
| 487 | nodeList->broadcastToNodes(audioPacket, NodeSet() << NodeType::AudioMixer); | 497 | // write audio packet to AudioMixer nodes |
| 498 | int audioPacketSize = dataAt - audioPacket; | ||
| 499 | NodeList* nodeList = NodeList::getInstance(); | ||
| 500 | foreach(const SharedNodePointer& node, nodeList->getNodeHash()) { | ||
| 501 | // only send to nodes of type AudioMixer | ||
| 502 | if (node->getType() == NodeType::AudioMixer) { | ||
| 503 | // pack sequence number | ||
| 504 | quint16 sequence = _outgoingSequenceNumbers[node->getUUID()]++; | ||
| 505 | memcpy(sequenceAt, &sequence, sizeof(quint16)); | ||
| 506 | |||
| 507 | // send audio packet | ||
| 508 | nodeList->writeDatagram(audioPacket, audioPacketSize, node); | ||
| 509 | } | ||
| 510 | } | ||
| 488 | } | 511 | } |
| 489 | } | 512 | } |
| 490 | 513 | ||
| @@ -658,3 +681,7 @@ void ScriptEngine::include(const QString& includeFile) { · 167 unmodified lines | |||
| 658 | emit errorMessage("Uncaught exception at (" + includeFile + ") line" + QString::number(line) + ":" + result.toString()); | 681 | emit errorMessage("Uncaught exception at (" + includeFile + ") line" + QString::number(line) + ":" + result.toString()); |
| 659 | } | 682 | } |
| 660 | } | 683 | } |
| 684 | |||
| 685 | void ScriptEngine::nodeKilled(SharedNodePointer node) { | ||
| 686 | _outgoingSequenceNumbers.remove(node->getUUID()); | ||
| 687 | } | ||