removed _sourceID, using getNodeID() feature of Node class

This commit is contained in:
ZappoMan 2013-07-23 19:06:47 -07:00
parent 927b0b6708
commit 686bd6c5d1
3 changed files with 14 additions and 29 deletions

View file

@ -8,6 +8,7 @@
#include <cstring> #include <cstring>
#include <Node.h>
#include <PacketHeaders.h> #include <PacketHeaders.h>
#include "PositionalAudioRingBuffer.h" #include "PositionalAudioRingBuffer.h"
@ -17,7 +18,6 @@ PositionalAudioRingBuffer::PositionalAudioRingBuffer() :
_position(0.0f, 0.0f, 0.0f), _position(0.0f, 0.0f, 0.0f),
_orientation(0.0f, 0.0f, 0.0f, 0.0f), _orientation(0.0f, 0.0f, 0.0f, 0.0f),
_willBeAddedToMix(false), _willBeAddedToMix(false),
_sourceID(-1),
_listenMode(AudioRingBuffer::NORMAL), _listenMode(AudioRingBuffer::NORMAL),
_listenRadius(0.0f), _listenRadius(0.0f),
_listenSourceCount(0), _listenSourceCount(0),
@ -32,7 +32,7 @@ PositionalAudioRingBuffer::~PositionalAudioRingBuffer() {
} }
} }
bool PositionalAudioRingBuffer::isListeningToSource(PositionalAudioRingBuffer* other) { bool PositionalAudioRingBuffer::isListeningToNode(Node& other) const {
switch (_listenMode) { switch (_listenMode) {
default: default:
case AudioRingBuffer::NORMAL: case AudioRingBuffer::NORMAL:
@ -40,14 +40,15 @@ bool PositionalAudioRingBuffer::isListeningToSource(PositionalAudioRingBuffer* o
break; break;
case AudioRingBuffer::OMNI_DIRECTIONAL_POINT: { 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; return distance <= _listenRadius;
break; break;
} }
case AudioRingBuffer::SELECTED_SOURCES: case AudioRingBuffer::SELECTED_SOURCES:
if (_listenSources) { if (_listenSources) {
for (int i = 0; i < _listenSourceCount; i++) { for (int i = 0; i < _listenSourceCount; i++) {
if (other->_sourceID == _listenSources[i]) { if (other.getNodeID() == _listenSources[i]) {
return true; return true;
} }
} }
@ -60,7 +61,7 @@ bool PositionalAudioRingBuffer::isListeningToSource(PositionalAudioRingBuffer* o
int PositionalAudioRingBuffer::parseData(unsigned char* sourceBuffer, int numBytes) { int PositionalAudioRingBuffer::parseData(unsigned char* sourceBuffer, int numBytes) {
unsigned char* currentBuffer = sourceBuffer + numBytesForPacketHeader(sourceBuffer); 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 += parseListenModeData(currentBuffer, numBytes - (currentBuffer - sourceBuffer));
currentBuffer += parsePositionalData(currentBuffer, numBytes - (currentBuffer - sourceBuffer)); currentBuffer += parsePositionalData(currentBuffer, numBytes - (currentBuffer - sourceBuffer));
currentBuffer += parseAudioSamples(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; 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) { int PositionalAudioRingBuffer::parseListenModeData(unsigned char* sourceBuffer, int numBytes) {
unsigned char* currentBuffer = sourceBuffer; unsigned char* currentBuffer = sourceBuffer;
@ -134,6 +126,5 @@ bool PositionalAudioRingBuffer::shouldBeAddedToMix(int numJitterBufferSamples) {
return true; return true;
} }
} }
return false; return false;
} }

View file

@ -20,7 +20,6 @@ public:
int parseData(unsigned char* sourceBuffer, int numBytes); int parseData(unsigned char* sourceBuffer, int numBytes);
int parsePositionalData(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); int parseListenModeData(unsigned char* sourceBuffer, int numBytes);
bool shouldBeAddedToMix(int numJitterBufferSamples); bool shouldBeAddedToMix(int numJitterBufferSamples);
@ -31,8 +30,7 @@ public:
const glm::vec3& getPosition() const { return _position; } const glm::vec3& getPosition() const { return _position; }
const glm::quat& getOrientation() const { return _orientation; } const glm::quat& getOrientation() const { return _orientation; }
bool isListeningToSource(PositionalAudioRingBuffer* other); bool isListeningToNode(Node& other) const;
int getSourceID() const { return _sourceID; }
ListenMode getListeningMode() const { return _listenMode; } ListenMode getListeningMode() const { return _listenMode; }
protected: protected:
@ -44,7 +42,6 @@ protected:
glm::quat _orientation; glm::quat _orientation;
bool _willBeAddedToMix; bool _willBeAddedToMix;
int _sourceID;
ListenMode _listenMode; ListenMode _listenMode;
float _listenRadius; float _listenRadius;
int _listenSourceCount; int _listenSourceCount;

View file

@ -141,7 +141,6 @@ int main(int argc, const char* argv[]) {
for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) { for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {
PositionalAudioRingBuffer* positionalRingBuffer = (PositionalAudioRingBuffer*) node->getLinkedData(); PositionalAudioRingBuffer* positionalRingBuffer = (PositionalAudioRingBuffer*) node->getLinkedData();
if (positionalRingBuffer && positionalRingBuffer->shouldBeAddedToMix(JITTER_BUFFER_SAMPLES)) { if (positionalRingBuffer && positionalRingBuffer->shouldBeAddedToMix(JITTER_BUFFER_SAMPLES)) {
// this is a ring buffer that is ready to go // 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 // 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 // loop through all other nodes that have sufficient audio to mix
for (NodeList::iterator otherNode = nodeList->begin(); otherNode != nodeList->end(); otherNode++) { for (NodeList::iterator otherNode = nodeList->begin(); otherNode != nodeList->end(); otherNode++) {
if (((PositionalAudioRingBuffer*) otherNode->getLinkedData())->willBeAddedToMix() if (((PositionalAudioRingBuffer*) otherNode->getLinkedData())->willBeAddedToMix()
&& (otherNode != node || (otherNode == node && nodeRingBuffer->shouldLoopbackForNode()))) { && (otherNode != node || (otherNode == node && nodeRingBuffer->shouldLoopbackForNode()))) {
PositionalAudioRingBuffer* otherNodeBuffer = (PositionalAudioRingBuffer*) otherNode->getLinkedData(); PositionalAudioRingBuffer* otherNodeBuffer = (PositionalAudioRingBuffer*) otherNode->getLinkedData();
// based on our listen mode we will do this mixing... // based on our listen mode we will do this mixing...
if (nodeRingBuffer->isListeningToSource(otherNodeBuffer)) { if (nodeRingBuffer->isListeningToNode(*otherNode)) {
float bearingRelativeAngleToSource = 0.0f; float bearingRelativeAngleToSource = 0.0f;
float attenuationCoefficient = 1.0f; float attenuationCoefficient = 1.0f;
int numSamplesDelay = 0; int numSamplesDelay = 0;
@ -355,14 +351,15 @@ int main(int argc, const char* argv[]) {
packetVersionMatch(packetData)) { packetVersionMatch(packetData)) {
if (packetData[0] == PACKET_TYPE_MICROPHONE_AUDIO_NO_ECHO || if (packetData[0] == PACKET_TYPE_MICROPHONE_AUDIO_NO_ECHO ||
packetData[0] == PACKET_TYPE_MICROPHONE_AUDIO_WITH_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, Node* avatarNode = nodeList->addOrUpdateNode(nodeAddress,
nodeAddress, nodeAddress,
NODE_TYPE_AGENT, NODE_TYPE_AGENT,
nodeList->getLastNodeID()); sourceID);
if (avatarNode->getNodeID() == nodeList->getLastNodeID()) {
nodeList->increaseNodeID();
}
nodeList->updateNodeWithData(nodeAddress, packetData, receivedBytes); nodeList->updateNodeWithData(nodeAddress, packetData, receivedBytes);