mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 07:43:35 +02:00
removed _sourceID, using getNodeID() feature of Node class
This commit is contained in:
parent
927b0b6708
commit
686bd6c5d1
3 changed files with 14 additions and 29 deletions
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include <cstring>
|
||||
|
||||
#include <Node.h>
|
||||
#include <PacketHeaders.h>
|
||||
|
||||
#include "PositionalAudioRingBuffer.h"
|
||||
|
@ -17,7 +18,6 @@ PositionalAudioRingBuffer::PositionalAudioRingBuffer() :
|
|||
_position(0.0f, 0.0f, 0.0f),
|
||||
_orientation(0.0f, 0.0f, 0.0f, 0.0f),
|
||||
_willBeAddedToMix(false),
|
||||
_sourceID(-1),
|
||||
_listenMode(AudioRingBuffer::NORMAL),
|
||||
_listenRadius(0.0f),
|
||||
_listenSourceCount(0),
|
||||
|
@ -32,7 +32,7 @@ PositionalAudioRingBuffer::~PositionalAudioRingBuffer() {
|
|||
}
|
||||
}
|
||||
|
||||
bool PositionalAudioRingBuffer::isListeningToSource(PositionalAudioRingBuffer* other) {
|
||||
bool PositionalAudioRingBuffer::isListeningToNode(Node& other) const {
|
||||
switch (_listenMode) {
|
||||
default:
|
||||
case AudioRingBuffer::NORMAL:
|
||||
|
@ -40,14 +40,15 @@ bool PositionalAudioRingBuffer::isListeningToSource(PositionalAudioRingBuffer* o
|
|||
break;
|
||||
|
||||
case AudioRingBuffer::OMNI_DIRECTIONAL_POINT: {
|
||||
float distance = glm::distance(_position, other->_position);
|
||||
PositionalAudioRingBuffer* otherNodeBuffer = (PositionalAudioRingBuffer*) other.getLinkedData();
|
||||
float distance = glm::distance(_position, otherNodeBuffer->_position);
|
||||
return distance <= _listenRadius;
|
||||
break;
|
||||
}
|
||||
case AudioRingBuffer::SELECTED_SOURCES:
|
||||
if (_listenSources) {
|
||||
for (int i = 0; i < _listenSourceCount; i++) {
|
||||
if (other->_sourceID == _listenSources[i]) {
|
||||
if (other.getNodeID() == _listenSources[i]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +61,7 @@ bool PositionalAudioRingBuffer::isListeningToSource(PositionalAudioRingBuffer* o
|
|||
|
||||
int PositionalAudioRingBuffer::parseData(unsigned char* sourceBuffer, int numBytes) {
|
||||
unsigned char* currentBuffer = sourceBuffer + numBytesForPacketHeader(sourceBuffer);
|
||||
currentBuffer += parseSourceData(currentBuffer, numBytes - (currentBuffer - sourceBuffer));
|
||||
currentBuffer += sizeof(int); // the source ID
|
||||
currentBuffer += parseListenModeData(currentBuffer, numBytes - (currentBuffer - sourceBuffer));
|
||||
currentBuffer += parsePositionalData(currentBuffer, numBytes - (currentBuffer - sourceBuffer));
|
||||
currentBuffer += parseAudioSamples(currentBuffer, numBytes - (currentBuffer - sourceBuffer));
|
||||
|
@ -68,15 +69,6 @@ int PositionalAudioRingBuffer::parseData(unsigned char* sourceBuffer, int numByt
|
|||
return currentBuffer - sourceBuffer;
|
||||
}
|
||||
|
||||
int PositionalAudioRingBuffer::parseSourceData(unsigned char* sourceBuffer, int numBytes) {
|
||||
unsigned char* currentBuffer = sourceBuffer;
|
||||
|
||||
memcpy(&_sourceID, currentBuffer, sizeof(_sourceID));
|
||||
currentBuffer += sizeof(_sourceID);
|
||||
|
||||
return currentBuffer - sourceBuffer;
|
||||
}
|
||||
|
||||
int PositionalAudioRingBuffer::parseListenModeData(unsigned char* sourceBuffer, int numBytes) {
|
||||
unsigned char* currentBuffer = sourceBuffer;
|
||||
|
||||
|
@ -134,6 +126,5 @@ bool PositionalAudioRingBuffer::shouldBeAddedToMix(int numJitterBufferSamples) {
|
|||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ public:
|
|||
|
||||
int parseData(unsigned char* sourceBuffer, int numBytes);
|
||||
int parsePositionalData(unsigned char* sourceBuffer, int numBytes);
|
||||
int parseSourceData(unsigned char* sourceBuffer, int numBytes);
|
||||
int parseListenModeData(unsigned char* sourceBuffer, int numBytes);
|
||||
|
||||
bool shouldBeAddedToMix(int numJitterBufferSamples);
|
||||
|
@ -31,8 +30,7 @@ public:
|
|||
const glm::vec3& getPosition() const { return _position; }
|
||||
const glm::quat& getOrientation() const { return _orientation; }
|
||||
|
||||
bool isListeningToSource(PositionalAudioRingBuffer* other);
|
||||
int getSourceID() const { return _sourceID; }
|
||||
bool isListeningToNode(Node& other) const;
|
||||
ListenMode getListeningMode() const { return _listenMode; }
|
||||
|
||||
protected:
|
||||
|
@ -44,7 +42,6 @@ protected:
|
|||
glm::quat _orientation;
|
||||
bool _willBeAddedToMix;
|
||||
|
||||
int _sourceID;
|
||||
ListenMode _listenMode;
|
||||
float _listenRadius;
|
||||
int _listenSourceCount;
|
||||
|
|
|
@ -141,7 +141,6 @@ int main(int argc, const char* argv[]) {
|
|||
|
||||
for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {
|
||||
PositionalAudioRingBuffer* positionalRingBuffer = (PositionalAudioRingBuffer*) node->getLinkedData();
|
||||
|
||||
if (positionalRingBuffer && positionalRingBuffer->shouldBeAddedToMix(JITTER_BUFFER_SAMPLES)) {
|
||||
// this is a ring buffer that is ready to go
|
||||
// set its flag so we know to push its buffer when all is said and done
|
||||
|
@ -161,14 +160,11 @@ int main(int argc, const char* argv[]) {
|
|||
|
||||
// loop through all other nodes that have sufficient audio to mix
|
||||
for (NodeList::iterator otherNode = nodeList->begin(); otherNode != nodeList->end(); otherNode++) {
|
||||
|
||||
if (((PositionalAudioRingBuffer*) otherNode->getLinkedData())->willBeAddedToMix()
|
||||
&& (otherNode != node || (otherNode == node && nodeRingBuffer->shouldLoopbackForNode()))) {
|
||||
|
||||
PositionalAudioRingBuffer* otherNodeBuffer = (PositionalAudioRingBuffer*) otherNode->getLinkedData();
|
||||
|
||||
// based on our listen mode we will do this mixing...
|
||||
if (nodeRingBuffer->isListeningToSource(otherNodeBuffer)) {
|
||||
if (nodeRingBuffer->isListeningToNode(*otherNode)) {
|
||||
float bearingRelativeAngleToSource = 0.0f;
|
||||
float attenuationCoefficient = 1.0f;
|
||||
int numSamplesDelay = 0;
|
||||
|
@ -355,14 +351,15 @@ int main(int argc, const char* argv[]) {
|
|||
packetVersionMatch(packetData)) {
|
||||
if (packetData[0] == PACKET_TYPE_MICROPHONE_AUDIO_NO_ECHO ||
|
||||
packetData[0] == PACKET_TYPE_MICROPHONE_AUDIO_WITH_ECHO) {
|
||||
|
||||
unsigned char* currentBuffer = packetData + numBytesForPacketHeader(packetData);
|
||||
int sourceID;
|
||||
memcpy(&sourceID, currentBuffer, sizeof(sourceID));
|
||||
|
||||
Node* avatarNode = nodeList->addOrUpdateNode(nodeAddress,
|
||||
nodeAddress,
|
||||
NODE_TYPE_AGENT,
|
||||
nodeList->getLastNodeID());
|
||||
|
||||
if (avatarNode->getNodeID() == nodeList->getLastNodeID()) {
|
||||
nodeList->increaseNodeID();
|
||||
}
|
||||
sourceID);
|
||||
|
||||
nodeList->updateNodeWithData(nodeAddress, packetData, receivedBytes);
|
||||
|
||||
|
|
Loading…
Reference in a new issue