mirror of
https://github.com/overte-org/overte.git
synced 2025-07-10 15:58:31 +02:00
merge branch qt5 with upstream/master
This commit is contained in:
commit
08b94d731f
12 changed files with 367 additions and 160 deletions
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
#include <Node.h>
|
||||||
#include <PacketHeaders.h>
|
#include <PacketHeaders.h>
|
||||||
|
|
||||||
#include "PositionalAudioRingBuffer.h"
|
#include "PositionalAudioRingBuffer.h"
|
||||||
|
@ -16,25 +17,81 @@ PositionalAudioRingBuffer::PositionalAudioRingBuffer() :
|
||||||
AudioRingBuffer(false),
|
AudioRingBuffer(false),
|
||||||
_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),
|
||||||
|
_listenMode(AudioRingBuffer::NORMAL),
|
||||||
|
_listenRadius(0.0f)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PositionalAudioRingBuffer::~PositionalAudioRingBuffer() {
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PositionalAudioRingBuffer::isListeningToNode(Node& other) const {
|
||||||
|
switch (_listenMode) {
|
||||||
|
default:
|
||||||
|
case AudioRingBuffer::NORMAL:
|
||||||
|
return true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AudioRingBuffer::OMNI_DIRECTIONAL_POINT: {
|
||||||
|
PositionalAudioRingBuffer* otherNodeBuffer = (PositionalAudioRingBuffer*) other.getLinkedData();
|
||||||
|
float distance = glm::distance(_position, otherNodeBuffer->_position);
|
||||||
|
return distance <= _listenRadius;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case AudioRingBuffer::SELECTED_SOURCES:
|
||||||
|
for (int i = 0; i < _listenSources.size(); i++) {
|
||||||
|
if (other.getNodeID() == _listenSources[i]) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
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 += sizeof(uint16_t); // the source ID
|
||||||
|
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));
|
||||||
|
|
||||||
return currentBuffer - sourceBuffer;
|
return currentBuffer - sourceBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int PositionalAudioRingBuffer::parseListenModeData(unsigned char* sourceBuffer, int numBytes) {
|
||||||
|
unsigned char* currentBuffer = sourceBuffer;
|
||||||
|
|
||||||
|
memcpy(&_listenMode, currentBuffer, sizeof(_listenMode));
|
||||||
|
currentBuffer += sizeof(_listenMode);
|
||||||
|
|
||||||
|
if (_listenMode == AudioRingBuffer::OMNI_DIRECTIONAL_POINT) {
|
||||||
|
memcpy(&_listenRadius, currentBuffer, sizeof(_listenRadius));
|
||||||
|
currentBuffer += sizeof(_listenRadius);
|
||||||
|
} else if (_listenMode == AudioRingBuffer::SELECTED_SOURCES) {
|
||||||
|
int listenSourcesCount;
|
||||||
|
memcpy(&listenSourcesCount, currentBuffer, sizeof(listenSourcesCount));
|
||||||
|
currentBuffer += sizeof(listenSourcesCount);
|
||||||
|
for (int i = 0; i < listenSourcesCount; i++) {
|
||||||
|
int sourceID;
|
||||||
|
memcpy(&sourceID, currentBuffer, sizeof(sourceID));
|
||||||
|
currentBuffer += sizeof(sourceID);
|
||||||
|
_listenSources.push_back(sourceID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return currentBuffer - sourceBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
int PositionalAudioRingBuffer::parsePositionalData(unsigned char* sourceBuffer, int numBytes) {
|
int PositionalAudioRingBuffer::parsePositionalData(unsigned char* sourceBuffer, int numBytes) {
|
||||||
unsigned char* currentBuffer = sourceBuffer;
|
unsigned char* currentBuffer = sourceBuffer;
|
||||||
|
|
||||||
memcpy(&_position, currentBuffer, sizeof(_position));
|
memcpy(&_position, currentBuffer, sizeof(_position));
|
||||||
currentBuffer += sizeof(_position);
|
currentBuffer += sizeof(_position);
|
||||||
|
|
||||||
memcpy(&_orientation, currentBuffer, sizeof(_orientation));
|
memcpy(&_orientation, currentBuffer, sizeof(_orientation));
|
||||||
currentBuffer += sizeof(_orientation);
|
currentBuffer += sizeof(_orientation);
|
||||||
|
|
||||||
|
@ -63,6 +120,6 @@ bool PositionalAudioRingBuffer::shouldBeAddedToMix(int numJitterBufferSamples) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
printf("packet mismatch...\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#ifndef __hifi__PositionalAudioRingBuffer__
|
#ifndef __hifi__PositionalAudioRingBuffer__
|
||||||
#define __hifi__PositionalAudioRingBuffer__
|
#define __hifi__PositionalAudioRingBuffer__
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
#include <glm/gtx/quaternion.hpp>
|
#include <glm/gtx/quaternion.hpp>
|
||||||
|
|
||||||
#include <AudioRingBuffer.h>
|
#include <AudioRingBuffer.h>
|
||||||
|
@ -16,9 +17,11 @@
|
||||||
class PositionalAudioRingBuffer : public AudioRingBuffer {
|
class PositionalAudioRingBuffer : public AudioRingBuffer {
|
||||||
public:
|
public:
|
||||||
PositionalAudioRingBuffer();
|
PositionalAudioRingBuffer();
|
||||||
|
~PositionalAudioRingBuffer();
|
||||||
|
|
||||||
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 parseListenModeData(unsigned char* sourceBuffer, int numBytes);
|
||||||
|
|
||||||
bool shouldBeAddedToMix(int numJitterBufferSamples);
|
bool shouldBeAddedToMix(int numJitterBufferSamples);
|
||||||
|
|
||||||
|
@ -27,6 +30,9 @@ 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 isListeningToNode(Node& other) const;
|
||||||
|
ListenMode getListeningMode() const { return _listenMode; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// disallow copying of PositionalAudioRingBuffer objects
|
// disallow copying of PositionalAudioRingBuffer objects
|
||||||
|
@ -36,6 +42,10 @@ protected:
|
||||||
glm::vec3 _position;
|
glm::vec3 _position;
|
||||||
glm::quat _orientation;
|
glm::quat _orientation;
|
||||||
bool _willBeAddedToMix;
|
bool _willBeAddedToMix;
|
||||||
|
|
||||||
|
ListenMode _listenMode;
|
||||||
|
float _listenRadius;
|
||||||
|
std::vector<int> _listenSources;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* defined(__hifi__PositionalAudioRingBuffer__) */
|
#endif /* defined(__hifi__PositionalAudioRingBuffer__) */
|
||||||
|
|
|
@ -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
|
||||||
|
@ -159,168 +158,171 @@ int main(int argc, const char* argv[]) {
|
||||||
// zero out the client mix for this node
|
// zero out the client mix for this node
|
||||||
memset(clientSamples, 0, sizeof(clientSamples));
|
memset(clientSamples, 0, sizeof(clientSamples));
|
||||||
|
|
||||||
|
// 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...
|
||||||
|
if (nodeRingBuffer->isListeningToNode(*otherNode)) {
|
||||||
|
float bearingRelativeAngleToSource = 0.0f;
|
||||||
|
float attenuationCoefficient = 1.0f;
|
||||||
|
int numSamplesDelay = 0;
|
||||||
|
float weakChannelAmplitudeRatio = 1.0f;
|
||||||
|
|
||||||
float bearingRelativeAngleToSource = 0.0f;
|
stk::TwoPole* otherNodeTwoPole = NULL;
|
||||||
float attenuationCoefficient = 1.0f;
|
|
||||||
int numSamplesDelay = 0;
|
|
||||||
float weakChannelAmplitudeRatio = 1.0f;
|
|
||||||
|
|
||||||
stk::TwoPole* otherNodeTwoPole = NULL;
|
// only do axis/distance attenuation when in normal mode
|
||||||
|
if (otherNode != node && nodeRingBuffer->getListeningMode() == AudioRingBuffer::NORMAL) {
|
||||||
if (otherNode != node) {
|
|
||||||
|
|
||||||
glm::vec3 listenerPosition = nodeRingBuffer->getPosition();
|
glm::vec3 listenerPosition = nodeRingBuffer->getPosition();
|
||||||
glm::vec3 relativePosition = otherNodeBuffer->getPosition() - nodeRingBuffer->getPosition();
|
glm::vec3 relativePosition = otherNodeBuffer->getPosition() - nodeRingBuffer->getPosition();
|
||||||
glm::quat inverseOrientation = glm::inverse(nodeRingBuffer->getOrientation());
|
glm::quat inverseOrientation = glm::inverse(nodeRingBuffer->getOrientation());
|
||||||
|
|
||||||
float distanceSquareToSource = glm::dot(relativePosition, relativePosition);
|
float distanceSquareToSource = glm::dot(relativePosition, relativePosition);
|
||||||
float radius = 0.0f;
|
float radius = 0.0f;
|
||||||
|
|
||||||
if (otherNode->getType() == NODE_TYPE_AUDIO_INJECTOR) {
|
if (otherNode->getType() == NODE_TYPE_AUDIO_INJECTOR) {
|
||||||
InjectedAudioRingBuffer* injectedBuffer = (InjectedAudioRingBuffer*) otherNodeBuffer;
|
InjectedAudioRingBuffer* injectedBuffer = (InjectedAudioRingBuffer*) otherNodeBuffer;
|
||||||
radius = injectedBuffer->getRadius();
|
radius = injectedBuffer->getRadius();
|
||||||
attenuationCoefficient *= injectedBuffer->getAttenuationRatio();
|
attenuationCoefficient *= injectedBuffer->getAttenuationRatio();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (radius == 0 || (distanceSquareToSource > radius * radius)) {
|
if (radius == 0 || (distanceSquareToSource > radius * radius)) {
|
||||||
// this is either not a spherical source, or the listener is outside the sphere
|
// this is either not a spherical source, or the listener is outside the sphere
|
||||||
|
|
||||||
if (radius > 0) {
|
if (radius > 0) {
|
||||||
// this is a spherical source - the distance used for the coefficient
|
// this is a spherical source - the distance used for the coefficient
|
||||||
// needs to be the closest point on the boundary to the source
|
// needs to be the closest point on the boundary to the source
|
||||||
|
|
||||||
// ovveride the distance to the node with the distance to the point on the
|
// ovveride the distance to the node with the distance to the point on the
|
||||||
// boundary of the sphere
|
// boundary of the sphere
|
||||||
distanceSquareToSource -= (radius * radius);
|
distanceSquareToSource -= (radius * radius);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// calculate the angle delivery for off-axis attenuation
|
// calculate the angle delivery for off-axis attenuation
|
||||||
glm::vec3 rotatedListenerPosition = glm::inverse(otherNodeBuffer->getOrientation())
|
glm::vec3 rotatedListenerPosition = glm::inverse(otherNodeBuffer->getOrientation())
|
||||||
* relativePosition;
|
* relativePosition;
|
||||||
|
|
||||||
float angleOfDelivery = glm::angle(glm::vec3(0.0f, 0.0f, -1.0f),
|
float angleOfDelivery = glm::angle(glm::vec3(0.0f, 0.0f, -1.0f),
|
||||||
glm::normalize(rotatedListenerPosition));
|
glm::normalize(rotatedListenerPosition));
|
||||||
|
|
||||||
const float MAX_OFF_AXIS_ATTENUATION = 0.2f;
|
const float MAX_OFF_AXIS_ATTENUATION = 0.2f;
|
||||||
const float OFF_AXIS_ATTENUATION_FORMULA_STEP = (1 - MAX_OFF_AXIS_ATTENUATION) / 2.0f;
|
const float OFF_AXIS_ATTENUATION_FORMULA_STEP = (1 - MAX_OFF_AXIS_ATTENUATION) / 2.0f;
|
||||||
|
|
||||||
float offAxisCoefficient = MAX_OFF_AXIS_ATTENUATION +
|
float offAxisCoefficient = MAX_OFF_AXIS_ATTENUATION +
|
||||||
(OFF_AXIS_ATTENUATION_FORMULA_STEP * (angleOfDelivery / 90.0f));
|
(OFF_AXIS_ATTENUATION_FORMULA_STEP * (angleOfDelivery / 90.0f));
|
||||||
|
|
||||||
// multiply the current attenuation coefficient by the calculated off axis coefficient
|
// multiply the current attenuation coefficient by the calculated off axis coefficient
|
||||||
attenuationCoefficient *= offAxisCoefficient;
|
attenuationCoefficient *= offAxisCoefficient;
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::vec3 rotatedSourcePosition = inverseOrientation * relativePosition;
|
||||||
|
|
||||||
|
const float DISTANCE_SCALE = 2.5f;
|
||||||
|
const float GEOMETRIC_AMPLITUDE_SCALAR = 0.3f;
|
||||||
|
const float DISTANCE_LOG_BASE = 2.5f;
|
||||||
|
const float DISTANCE_SCALE_LOG = logf(DISTANCE_SCALE) / logf(DISTANCE_LOG_BASE);
|
||||||
|
|
||||||
|
// calculate the distance coefficient using the distance to this node
|
||||||
|
float distanceCoefficient = powf(GEOMETRIC_AMPLITUDE_SCALAR,
|
||||||
|
DISTANCE_SCALE_LOG +
|
||||||
|
(0.5f * logf(distanceSquareToSource) / logf(DISTANCE_LOG_BASE)) - 1);
|
||||||
|
distanceCoefficient = std::min(1.0f, distanceCoefficient);
|
||||||
|
|
||||||
|
// multiply the current attenuation coefficient by the distance coefficient
|
||||||
|
attenuationCoefficient *= distanceCoefficient;
|
||||||
|
|
||||||
|
// project the rotated source position vector onto the XZ plane
|
||||||
|
rotatedSourcePosition.y = 0.0f;
|
||||||
|
|
||||||
|
// produce an oriented angle about the y-axis
|
||||||
|
bearingRelativeAngleToSource = glm::orientedAngle(glm::vec3(0.0f, 0.0f, -1.0f),
|
||||||
|
glm::normalize(rotatedSourcePosition),
|
||||||
|
glm::vec3(0.0f, 1.0f, 0.0f));
|
||||||
|
|
||||||
|
const float PHASE_AMPLITUDE_RATIO_AT_90 = 0.5;
|
||||||
|
|
||||||
|
// figure out the number of samples of delay and the ratio of the amplitude
|
||||||
|
// in the weak channel for audio spatialization
|
||||||
|
float sinRatio = fabsf(sinf(glm::radians(bearingRelativeAngleToSource)));
|
||||||
|
numSamplesDelay = PHASE_DELAY_AT_90 * sinRatio;
|
||||||
|
weakChannelAmplitudeRatio = 1 - (PHASE_AMPLITUDE_RATIO_AT_90 * sinRatio);
|
||||||
|
|
||||||
|
// grab the TwoPole object for this source, add it if it doesn't exist
|
||||||
|
TwoPoleNodeMap& nodeTwoPoles = nodeRingBuffer->getTwoPoles();
|
||||||
|
TwoPoleNodeMap::iterator twoPoleIterator = nodeTwoPoles.find(otherNode->getNodeID());
|
||||||
|
|
||||||
|
if (twoPoleIterator == nodeTwoPoles.end()) {
|
||||||
|
// setup the freeVerb effect for this source for this client
|
||||||
|
otherNodeTwoPole = nodeTwoPoles[otherNode->getNodeID()] = new stk::TwoPole;
|
||||||
|
} else {
|
||||||
|
otherNodeTwoPole = twoPoleIterator->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
// calculate the reasonance for this TwoPole based on angle to source
|
||||||
|
float TWO_POLE_CUT_OFF_FREQUENCY = 800.0f;
|
||||||
|
float TWO_POLE_MAX_FILTER_STRENGTH = 0.4f;
|
||||||
|
|
||||||
|
otherNodeTwoPole->setResonance(TWO_POLE_CUT_OFF_FREQUENCY,
|
||||||
|
TWO_POLE_MAX_FILTER_STRENGTH
|
||||||
|
* fabsf(bearingRelativeAngleToSource) / 180.0f,
|
||||||
|
true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t* sourceBuffer = otherNodeBuffer->getNextOutput();
|
||||||
|
|
||||||
|
int16_t* goodChannel = (bearingRelativeAngleToSource > 0.0f)
|
||||||
|
? clientSamples
|
||||||
|
: clientSamples + BUFFER_LENGTH_SAMPLES_PER_CHANNEL;
|
||||||
|
int16_t* delayedChannel = (bearingRelativeAngleToSource > 0.0f)
|
||||||
|
? clientSamples + BUFFER_LENGTH_SAMPLES_PER_CHANNEL
|
||||||
|
: clientSamples;
|
||||||
|
|
||||||
|
int16_t* delaySamplePointer = otherNodeBuffer->getNextOutput() == otherNodeBuffer->getBuffer()
|
||||||
|
? otherNodeBuffer->getBuffer() + RING_BUFFER_LENGTH_SAMPLES - numSamplesDelay
|
||||||
|
: otherNodeBuffer->getNextOutput() - numSamplesDelay;
|
||||||
|
|
||||||
|
for (int s = 0; s < BUFFER_LENGTH_SAMPLES_PER_CHANNEL; s++) {
|
||||||
|
// load up the stkFrameBuffer with this source's samples
|
||||||
|
stkFrameBuffer[s] = (stk::StkFloat) sourceBuffer[s];
|
||||||
|
}
|
||||||
|
|
||||||
|
// perform the TwoPole effect on the stkFrameBuffer
|
||||||
|
if (otherNodeTwoPole) {
|
||||||
|
otherNodeTwoPole->tick(stkFrameBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int s = 0; s < BUFFER_LENGTH_SAMPLES_PER_CHANNEL; s++) {
|
||||||
|
if (s < numSamplesDelay) {
|
||||||
|
// pull the earlier sample for the delayed channel
|
||||||
|
int earlierSample = delaySamplePointer[s] * attenuationCoefficient * weakChannelAmplitudeRatio;
|
||||||
|
|
||||||
glm::vec3 rotatedSourcePosition = inverseOrientation * relativePosition;
|
delayedChannel[s] = glm::clamp(delayedChannel[s] + earlierSample,
|
||||||
|
MIN_SAMPLE_VALUE,
|
||||||
const float DISTANCE_SCALE = 2.5f;
|
MAX_SAMPLE_VALUE);
|
||||||
const float GEOMETRIC_AMPLITUDE_SCALAR = 0.3f;
|
|
||||||
const float DISTANCE_LOG_BASE = 2.5f;
|
|
||||||
const float DISTANCE_SCALE_LOG = logf(DISTANCE_SCALE) / logf(DISTANCE_LOG_BASE);
|
|
||||||
|
|
||||||
// calculate the distance coefficient using the distance to this node
|
|
||||||
float distanceCoefficient = powf(GEOMETRIC_AMPLITUDE_SCALAR,
|
|
||||||
DISTANCE_SCALE_LOG +
|
|
||||||
(0.5f * logf(distanceSquareToSource) / logf(DISTANCE_LOG_BASE)) - 1);
|
|
||||||
distanceCoefficient = std::min(1.0f, distanceCoefficient);
|
|
||||||
|
|
||||||
// multiply the current attenuation coefficient by the distance coefficient
|
|
||||||
attenuationCoefficient *= distanceCoefficient;
|
|
||||||
|
|
||||||
// project the rotated source position vector onto the XZ plane
|
|
||||||
rotatedSourcePosition.y = 0.0f;
|
|
||||||
|
|
||||||
// produce an oriented angle about the y-axis
|
|
||||||
bearingRelativeAngleToSource = glm::orientedAngle(glm::vec3(0.0f, 0.0f, -1.0f),
|
|
||||||
glm::normalize(rotatedSourcePosition),
|
|
||||||
glm::vec3(0.0f, 1.0f, 0.0f));
|
|
||||||
|
|
||||||
const float PHASE_AMPLITUDE_RATIO_AT_90 = 0.5;
|
|
||||||
|
|
||||||
// figure out the number of samples of delay and the ratio of the amplitude
|
|
||||||
// in the weak channel for audio spatialization
|
|
||||||
float sinRatio = fabsf(sinf(glm::radians(bearingRelativeAngleToSource)));
|
|
||||||
numSamplesDelay = PHASE_DELAY_AT_90 * sinRatio;
|
|
||||||
weakChannelAmplitudeRatio = 1 - (PHASE_AMPLITUDE_RATIO_AT_90 * sinRatio);
|
|
||||||
|
|
||||||
// grab the TwoPole object for this source, add it if it doesn't exist
|
|
||||||
TwoPoleNodeMap& nodeTwoPoles = nodeRingBuffer->getTwoPoles();
|
|
||||||
TwoPoleNodeMap::iterator twoPoleIterator = nodeTwoPoles.find(otherNode->getNodeID());
|
|
||||||
|
|
||||||
if (twoPoleIterator == nodeTwoPoles.end()) {
|
|
||||||
// setup the freeVerb effect for this source for this client
|
|
||||||
otherNodeTwoPole = nodeTwoPoles[otherNode->getNodeID()] = new stk::TwoPole;
|
|
||||||
} else {
|
|
||||||
otherNodeTwoPole = twoPoleIterator->second;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// calculate the reasonance for this TwoPole based on angle to source
|
|
||||||
float TWO_POLE_CUT_OFF_FREQUENCY = 800.0f;
|
|
||||||
float TWO_POLE_MAX_FILTER_STRENGTH = 0.4f;
|
|
||||||
|
|
||||||
otherNodeTwoPole->setResonance(TWO_POLE_CUT_OFF_FREQUENCY,
|
|
||||||
TWO_POLE_MAX_FILTER_STRENGTH
|
|
||||||
* fabsf(bearingRelativeAngleToSource) / 180.0f,
|
|
||||||
true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int16_t* sourceBuffer = otherNodeBuffer->getNextOutput();
|
|
||||||
|
|
||||||
int16_t* goodChannel = (bearingRelativeAngleToSource > 0.0f)
|
|
||||||
? clientSamples
|
|
||||||
: clientSamples + BUFFER_LENGTH_SAMPLES_PER_CHANNEL;
|
|
||||||
int16_t* delayedChannel = (bearingRelativeAngleToSource > 0.0f)
|
|
||||||
? clientSamples + BUFFER_LENGTH_SAMPLES_PER_CHANNEL
|
|
||||||
: clientSamples;
|
|
||||||
|
|
||||||
int16_t* delaySamplePointer = otherNodeBuffer->getNextOutput() == otherNodeBuffer->getBuffer()
|
|
||||||
? otherNodeBuffer->getBuffer() + RING_BUFFER_LENGTH_SAMPLES - numSamplesDelay
|
|
||||||
: otherNodeBuffer->getNextOutput() - numSamplesDelay;
|
|
||||||
|
|
||||||
for (int s = 0; s < BUFFER_LENGTH_SAMPLES_PER_CHANNEL; s++) {
|
|
||||||
// load up the stkFrameBuffer with this source's samples
|
|
||||||
stkFrameBuffer[s] = (stk::StkFloat) sourceBuffer[s];
|
|
||||||
}
|
|
||||||
|
|
||||||
// perform the TwoPole effect on the stkFrameBuffer
|
|
||||||
if (otherNodeTwoPole) {
|
|
||||||
otherNodeTwoPole->tick(stkFrameBuffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int s = 0; s < BUFFER_LENGTH_SAMPLES_PER_CHANNEL; s++) {
|
|
||||||
if (s < numSamplesDelay) {
|
|
||||||
// pull the earlier sample for the delayed channel
|
|
||||||
int earlierSample = delaySamplePointer[s] * attenuationCoefficient * weakChannelAmplitudeRatio;
|
|
||||||
|
|
||||||
delayedChannel[s] = glm::clamp(delayedChannel[s] + earlierSample,
|
|
||||||
MIN_SAMPLE_VALUE,
|
|
||||||
MAX_SAMPLE_VALUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
int16_t currentSample = stkFrameBuffer[s] * attenuationCoefficient;
|
int16_t currentSample = stkFrameBuffer[s] * attenuationCoefficient;
|
||||||
|
|
||||||
goodChannel[s] = glm::clamp(goodChannel[s] + currentSample,
|
goodChannel[s] = glm::clamp(goodChannel[s] + currentSample,
|
||||||
MIN_SAMPLE_VALUE,
|
MIN_SAMPLE_VALUE,
|
||||||
MAX_SAMPLE_VALUE);
|
MAX_SAMPLE_VALUE);
|
||||||
|
|
||||||
if (s + numSamplesDelay < BUFFER_LENGTH_SAMPLES_PER_CHANNEL) {
|
if (s + numSamplesDelay < BUFFER_LENGTH_SAMPLES_PER_CHANNEL) {
|
||||||
int sumSample = delayedChannel[s + numSamplesDelay]
|
int sumSample = delayedChannel[s + numSamplesDelay]
|
||||||
+ (currentSample * weakChannelAmplitudeRatio);
|
+ (currentSample * weakChannelAmplitudeRatio);
|
||||||
delayedChannel[s + numSamplesDelay] = glm::clamp(sumSample,
|
delayedChannel[s + numSamplesDelay] = glm::clamp(sumSample,
|
||||||
MIN_SAMPLE_VALUE,
|
MIN_SAMPLE_VALUE,
|
||||||
MAX_SAMPLE_VALUE);
|
MAX_SAMPLE_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s >= BUFFER_LENGTH_SAMPLES_PER_CHANNEL - PHASE_DELAY_AT_90) {
|
if (s >= BUFFER_LENGTH_SAMPLES_PER_CHANNEL - PHASE_DELAY_AT_90) {
|
||||||
// this could be a delayed sample on the next pass
|
// this could be a delayed sample on the next pass
|
||||||
// so store the affected back in the ARB
|
// so store the affected back in the ARB
|
||||||
otherNodeBuffer->getNextOutput()[s] = (int16_t) stkFrameBuffer[s];
|
otherNodeBuffer->getNextOutput()[s] = (int16_t) stkFrameBuffer[s];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -340,7 +342,6 @@ int main(int argc, const char* argv[]) {
|
||||||
if (nodeBuffer->getNextOutput() >= nodeBuffer->getBuffer() + RING_BUFFER_LENGTH_SAMPLES) {
|
if (nodeBuffer->getNextOutput() >= nodeBuffer->getBuffer() + RING_BUFFER_LENGTH_SAMPLES) {
|
||||||
nodeBuffer->setNextOutput(nodeBuffer->getBuffer());
|
nodeBuffer->setNextOutput(nodeBuffer->getBuffer());
|
||||||
}
|
}
|
||||||
|
|
||||||
nodeBuffer->setWillBeAddedToMix(false);
|
nodeBuffer->setWillBeAddedToMix(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -350,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);
|
||||||
|
uint16_t 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);
|
||||||
|
|
||||||
|
|
|
@ -40,11 +40,13 @@ bool hasInjectedAudioOnce = false;
|
||||||
float sleepIntervalMin = 1.00;
|
float sleepIntervalMin = 1.00;
|
||||||
float sleepIntervalMax = 2.00;
|
float sleepIntervalMax = 2.00;
|
||||||
char *sourceAudioFile = NULL;
|
char *sourceAudioFile = NULL;
|
||||||
const char *allowedParameters = ":sc::a::f::t::r:";
|
const char *allowedParameters = ":sc::a::f::t::r:l";
|
||||||
float floatArguments[4] = {0.0f, 0.0f, 0.0f, 0.0f};
|
float floatArguments[4] = {0.0f, 0.0f, 0.0f, 0.0f};
|
||||||
unsigned char volume = DEFAULT_INJECTOR_VOLUME;
|
unsigned char volume = DEFAULT_INJECTOR_VOLUME;
|
||||||
float triggerDistance = 0.0f;
|
float triggerDistance = 0.0f;
|
||||||
float radius = 0.0f;
|
float radius = 0.0f;
|
||||||
|
bool wantsLocalDomain = false;
|
||||||
|
|
||||||
|
|
||||||
void usage(void) {
|
void usage(void) {
|
||||||
std::cout << "High Fidelity - Interface audio injector" << std::endl;
|
std::cout << "High Fidelity - Interface audio injector" << std::endl;
|
||||||
|
@ -54,6 +56,7 @@ void usage(void) {
|
||||||
std::cout << " -f FILENAME Name of audio source file. Required - RAW format, 22050hz 16bit signed mono" << std::endl;
|
std::cout << " -f FILENAME Name of audio source file. Required - RAW format, 22050hz 16bit signed mono" << std::endl;
|
||||||
std::cout << " -t FLOAT Trigger distance for injection. If not specified will loop constantly" << std::endl;
|
std::cout << " -t FLOAT Trigger distance for injection. If not specified will loop constantly" << std::endl;
|
||||||
std::cout << " -r FLOAT Radius for spherical source. If not specified injected audio is point source" << std::endl;
|
std::cout << " -r FLOAT Radius for spherical source. If not specified injected audio is point source" << std::endl;
|
||||||
|
std::cout << " -l Local domain mode." << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool processParameters(int parameterCount, char* parameterData[]) {
|
bool processParameters(int parameterCount, char* parameterData[]) {
|
||||||
|
@ -96,6 +99,9 @@ bool processParameters(int parameterCount, char* parameterData[]) {
|
||||||
::radius = atof(optarg);
|
::radius = atof(optarg);
|
||||||
std::cout << "[DEBUG] Injector radius: " << optarg << std::endl;
|
std::cout << "[DEBUG] Injector radius: " << optarg << std::endl;
|
||||||
break;
|
break;
|
||||||
|
case 'l':
|
||||||
|
::wantsLocalDomain = true;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
return false;
|
return false;
|
||||||
|
@ -111,6 +117,7 @@ void createAvatarDataForNode(Node* node) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
|
|
||||||
// new seed for random audio sleep times
|
// new seed for random audio sleep times
|
||||||
srand(time(0));
|
srand(time(0));
|
||||||
|
|
||||||
|
@ -126,6 +133,11 @@ int main(int argc, char* argv[]) {
|
||||||
// create an NodeList instance to handle communication with other nodes
|
// create an NodeList instance to handle communication with other nodes
|
||||||
NodeList* nodeList = NodeList::createInstance(NODE_TYPE_AUDIO_INJECTOR, AUDIO_UDP_SEND_PORT);
|
NodeList* nodeList = NodeList::createInstance(NODE_TYPE_AUDIO_INJECTOR, AUDIO_UDP_SEND_PORT);
|
||||||
|
|
||||||
|
if (::wantsLocalDomain) {
|
||||||
|
printf("Local Domain MODE!\n");
|
||||||
|
nodeList->setDomainIPToLocalhost();
|
||||||
|
}
|
||||||
|
|
||||||
// start the node list thread that will kill off nodes when they stop talking
|
// start the node list thread that will kill off nodes when they stop talking
|
||||||
nodeList->startSilentNodeRemovalThread();
|
nodeList->startSilentNodeRemovalThread();
|
||||||
|
|
||||||
|
|
|
@ -203,6 +203,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) :
|
||||||
_mouseVoxelScale(1.0f / 1024.0f),
|
_mouseVoxelScale(1.0f / 1024.0f),
|
||||||
_justEditedVoxel(false),
|
_justEditedVoxel(false),
|
||||||
_isLookingAtOtherAvatar(false),
|
_isLookingAtOtherAvatar(false),
|
||||||
|
_lookatIndicatorScale(1.0f),
|
||||||
_paintOn(false),
|
_paintOn(false),
|
||||||
_dominantColor(0),
|
_dominantColor(0),
|
||||||
_perfStatsOn(false),
|
_perfStatsOn(false),
|
||||||
|
@ -1854,6 +1855,11 @@ void Application::initMenu() {
|
||||||
(_simulateLeapHand = debugMenu->addAction("Simulate Leap Hand"))->setCheckable(true);
|
(_simulateLeapHand = debugMenu->addAction("Simulate Leap Hand"))->setCheckable(true);
|
||||||
(_testRaveGlove = debugMenu->addAction("Test RaveGlove"))->setCheckable(true);
|
(_testRaveGlove = debugMenu->addAction("Test RaveGlove"))->setCheckable(true);
|
||||||
|
|
||||||
|
QMenu* audioDebugMenu = debugMenu->addMenu("Audio Debugging Tools");
|
||||||
|
audioDebugMenu->addAction("Listen Mode Normal", this, SLOT(setListenModeNormal()), Qt::CTRL | Qt::Key_1);
|
||||||
|
audioDebugMenu->addAction("Listen Mode Point/Radius", this, SLOT(setListenModePoint()), Qt::CTRL | Qt::Key_2);
|
||||||
|
audioDebugMenu->addAction("Listen Mode Single Source", this, SLOT(setListenModeSingleSource()), Qt::CTRL | Qt::Key_3);
|
||||||
|
|
||||||
QMenu* settingsMenu = menuBar->addMenu("Settings");
|
QMenu* settingsMenu = menuBar->addMenu("Settings");
|
||||||
(_settingsAutosave = settingsMenu->addAction("Autosave"))->setCheckable(true);
|
(_settingsAutosave = settingsMenu->addAction("Autosave"))->setCheckable(true);
|
||||||
_settingsAutosave->setChecked(true);
|
_settingsAutosave->setChecked(true);
|
||||||
|
@ -1865,6 +1871,30 @@ void Application::initMenu() {
|
||||||
_networkAccessManager = new QNetworkAccessManager(this);
|
_networkAccessManager = new QNetworkAccessManager(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Application::setListenModeNormal() {
|
||||||
|
_audio.setListenMode(AudioRingBuffer::NORMAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Application::setListenModePoint() {
|
||||||
|
_audio.setListenMode(AudioRingBuffer::OMNI_DIRECTIONAL_POINT);
|
||||||
|
_audio.setListenRadius(1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Application::setListenModeSingleSource() {
|
||||||
|
_audio.setListenMode(AudioRingBuffer::SELECTED_SOURCES);
|
||||||
|
_audio.clearListenSources();
|
||||||
|
|
||||||
|
glm::vec3 mouseRayOrigin = _myAvatar.getMouseRayOrigin();
|
||||||
|
glm::vec3 mouseRayDirection = _myAvatar.getMouseRayDirection();
|
||||||
|
glm::vec3 eyePositionIgnored;
|
||||||
|
uint16_t nodeID;
|
||||||
|
|
||||||
|
if (isLookingAtOtherAvatar(mouseRayOrigin, mouseRayDirection, eyePositionIgnored, nodeID)) {
|
||||||
|
_audio.addListenSource(nodeID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Application::updateFrustumRenderModeAction() {
|
void Application::updateFrustumRenderModeAction() {
|
||||||
switch (_frustumDrawingMode) {
|
switch (_frustumDrawingMode) {
|
||||||
default:
|
default:
|
||||||
|
@ -1953,7 +1983,13 @@ const float MAX_AVATAR_EDIT_VELOCITY = 1.0f;
|
||||||
const float MAX_VOXEL_EDIT_DISTANCE = 20.0f;
|
const float MAX_VOXEL_EDIT_DISTANCE = 20.0f;
|
||||||
const float HEAD_SPHERE_RADIUS = 0.07;
|
const float HEAD_SPHERE_RADIUS = 0.07;
|
||||||
|
|
||||||
bool Application::isLookingAtOtherAvatar(glm::vec3& mouseRayOrigin, glm::vec3& mouseRayDirection, glm::vec3& eyePosition) {
|
|
||||||
|
static uint16_t DEFAULT_NODE_ID_REF = 1;
|
||||||
|
|
||||||
|
|
||||||
|
bool Application::isLookingAtOtherAvatar(glm::vec3& mouseRayOrigin, glm::vec3& mouseRayDirection,
|
||||||
|
glm::vec3& eyePosition, uint16_t& nodeID = DEFAULT_NODE_ID_REF) {
|
||||||
|
|
||||||
NodeList* nodeList = NodeList::getInstance();
|
NodeList* nodeList = NodeList::getInstance();
|
||||||
for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {
|
for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {
|
||||||
if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) {
|
if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) {
|
||||||
|
@ -1961,7 +1997,9 @@ bool Application::isLookingAtOtherAvatar(glm::vec3& mouseRayOrigin, glm::vec3& m
|
||||||
glm::vec3 headPosition = avatar->getHead().getPosition();
|
glm::vec3 headPosition = avatar->getHead().getPosition();
|
||||||
if (rayIntersectsSphere(mouseRayOrigin, mouseRayDirection, headPosition, HEAD_SPHERE_RADIUS)) {
|
if (rayIntersectsSphere(mouseRayOrigin, mouseRayDirection, headPosition, HEAD_SPHERE_RADIUS)) {
|
||||||
eyePosition = avatar->getHead().getEyeLevelPosition();
|
eyePosition = avatar->getHead().getEyeLevelPosition();
|
||||||
|
_lookatIndicatorScale = avatar->getScale();
|
||||||
_lookatOtherPosition = headPosition;
|
_lookatOtherPosition = headPosition;
|
||||||
|
nodeID = avatar->getOwningNode()->getNodeID();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1971,11 +2009,13 @@ bool Application::isLookingAtOtherAvatar(glm::vec3& mouseRayOrigin, glm::vec3& m
|
||||||
|
|
||||||
void Application::renderLookatIndicator(glm::vec3 pointOfInterest, Camera& whichCamera) {
|
void Application::renderLookatIndicator(glm::vec3 pointOfInterest, Camera& whichCamera) {
|
||||||
|
|
||||||
const float DISTANCE_FROM_HEAD_SPHERE = 0.1f;
|
const float DISTANCE_FROM_HEAD_SPHERE = 0.1f * _lookatIndicatorScale;
|
||||||
|
const float INDICATOR_RADIUS = 0.1f * _lookatIndicatorScale;
|
||||||
const float YELLOW[] = { 1.0f, 1.0f, 0.0f };
|
const float YELLOW[] = { 1.0f, 1.0f, 0.0f };
|
||||||
|
const int NUM_SEGMENTS = 30;
|
||||||
glm::vec3 haloOrigin(pointOfInterest.x, pointOfInterest.y + DISTANCE_FROM_HEAD_SPHERE, pointOfInterest.z);
|
glm::vec3 haloOrigin(pointOfInterest.x, pointOfInterest.y + DISTANCE_FROM_HEAD_SPHERE, pointOfInterest.z);
|
||||||
glColor3f(YELLOW[0], YELLOW[1], YELLOW[2]);
|
glColor3f(YELLOW[0], YELLOW[1], YELLOW[2]);
|
||||||
renderCircle(haloOrigin, 0.1f, glm::vec3(0.0f, 1.0f, 0.0f), 30);
|
renderCircle(haloOrigin, INDICATOR_RADIUS, IDENTITY_UP, NUM_SEGMENTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::update(float deltaTime) {
|
void Application::update(float deltaTime) {
|
||||||
|
@ -2005,7 +2045,9 @@ void Application::update(float deltaTime) {
|
||||||
|
|
||||||
// Set where I am looking based on my mouse ray (so that other people can see)
|
// Set where I am looking based on my mouse ray (so that other people can see)
|
||||||
glm::vec3 eyePosition;
|
glm::vec3 eyePosition;
|
||||||
if ((_isLookingAtOtherAvatar = isLookingAtOtherAvatar(mouseRayOrigin, mouseRayDirection, eyePosition))) {
|
|
||||||
|
_isLookingAtOtherAvatar = isLookingAtOtherAvatar(mouseRayOrigin, mouseRayDirection, eyePosition);
|
||||||
|
if (_isLookingAtOtherAvatar) {
|
||||||
// If the mouse is over another avatar's head...
|
// If the mouse is over another avatar's head...
|
||||||
glm::vec3 myLookAtFromMouse(eyePosition);
|
glm::vec3 myLookAtFromMouse(eyePosition);
|
||||||
_myAvatar.getHead().setLookAtPosition(myLookAtFromMouse);
|
_myAvatar.getHead().setLookAtPosition(myLookAtFromMouse);
|
||||||
|
@ -2022,7 +2064,7 @@ void Application::update(float deltaTime) {
|
||||||
glm::vec3 front = orientation * IDENTITY_FRONT;
|
glm::vec3 front = orientation * IDENTITY_FRONT;
|
||||||
glm::vec3 up = orientation * IDENTITY_UP;
|
glm::vec3 up = orientation * IDENTITY_UP;
|
||||||
glm::vec3 towardVoxel = getMouseVoxelWorldCoordinates(_mouseVoxelDragging)
|
glm::vec3 towardVoxel = getMouseVoxelWorldCoordinates(_mouseVoxelDragging)
|
||||||
- _myAvatar.getCameraPosition(); // is this an error? getCameraPosition dne
|
- _myAvatar.getCameraPosition();
|
||||||
towardVoxel = front * glm::length(towardVoxel);
|
towardVoxel = front * glm::length(towardVoxel);
|
||||||
glm::vec3 lateralToVoxel = glm::cross(up, glm::normalize(towardVoxel)) * glm::length(towardVoxel);
|
glm::vec3 lateralToVoxel = glm::cross(up, glm::normalize(towardVoxel)) * glm::length(towardVoxel);
|
||||||
_voxelThrust = glm::vec3(0, 0, 0);
|
_voxelThrust = glm::vec3(0, 0, 0);
|
||||||
|
@ -2270,7 +2312,9 @@ void Application::updateAvatar(float deltaTime) {
|
||||||
_viewFrustum.computePickRay(MIDPOINT_OF_SCREEN, MIDPOINT_OF_SCREEN, screenCenterRayOrigin, screenCenterRayDirection);
|
_viewFrustum.computePickRay(MIDPOINT_OF_SCREEN, MIDPOINT_OF_SCREEN, screenCenterRayOrigin, screenCenterRayDirection);
|
||||||
|
|
||||||
glm::vec3 eyePosition;
|
glm::vec3 eyePosition;
|
||||||
if ((_isLookingAtOtherAvatar = isLookingAtOtherAvatar(screenCenterRayOrigin, screenCenterRayDirection, eyePosition))) {
|
|
||||||
|
_isLookingAtOtherAvatar = isLookingAtOtherAvatar(screenCenterRayOrigin, screenCenterRayDirection, eyePosition);
|
||||||
|
if (_isLookingAtOtherAvatar) {
|
||||||
glm::vec3 myLookAtFromMouse(eyePosition);
|
glm::vec3 myLookAtFromMouse(eyePosition);
|
||||||
_myAvatar.getHead().setLookAtPosition(myLookAtFromMouse);
|
_myAvatar.getHead().setLookAtPosition(myLookAtFromMouse);
|
||||||
}
|
}
|
||||||
|
@ -2298,7 +2342,7 @@ void Application::updateAvatar(float deltaTime) {
|
||||||
// actually need to calculate the view frustum planes to send these details
|
// actually need to calculate the view frustum planes to send these details
|
||||||
// to the server.
|
// to the server.
|
||||||
loadViewFrustum(_myCamera, _viewFrustum);
|
loadViewFrustum(_myCamera, _viewFrustum);
|
||||||
_myAvatar.setCameraPosition(_viewFrustum.getPosition()); // setCameraPosition() dne
|
_myAvatar.setCameraPosition(_viewFrustum.getPosition());
|
||||||
_myAvatar.setCameraOrientation(_viewFrustum.getOrientation());
|
_myAvatar.setCameraOrientation(_viewFrustum.getOrientation());
|
||||||
_myAvatar.setCameraFov(_viewFrustum.getFieldOfView());
|
_myAvatar.setCameraFov(_viewFrustum.getFieldOfView());
|
||||||
_myAvatar.setCameraAspectRatio(_viewFrustum.getAspectRatio());
|
_myAvatar.setCameraAspectRatio(_viewFrustum.getAspectRatio());
|
||||||
|
|
|
@ -174,6 +174,10 @@ private slots:
|
||||||
void copyVoxels();
|
void copyVoxels();
|
||||||
void pasteVoxels();
|
void pasteVoxels();
|
||||||
void runTests();
|
void runTests();
|
||||||
|
void setListenModeNormal();
|
||||||
|
void setListenModePoint();
|
||||||
|
void setListenModeSingleSource();
|
||||||
|
|
||||||
|
|
||||||
void renderCoverageMap();
|
void renderCoverageMap();
|
||||||
void renderCoverageMapsRecursively(CoverageMap* map);
|
void renderCoverageMapsRecursively(CoverageMap* map);
|
||||||
|
@ -203,7 +207,9 @@ private:
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
void update(float deltaTime);
|
void update(float deltaTime);
|
||||||
bool isLookingAtOtherAvatar(glm::vec3& mouseRayOrigin, glm::vec3& mouseRayDirection, glm::vec3& eyePosition);
|
bool isLookingAtOtherAvatar(glm::vec3& mouseRayOrigin, glm::vec3& mouseRayDirection,
|
||||||
|
glm::vec3& eyePosition, uint16_t& nodeID);
|
||||||
|
|
||||||
void renderLookatIndicator(glm::vec3 pointOfInterest, Camera& whichCamera);
|
void renderLookatIndicator(glm::vec3 pointOfInterest, Camera& whichCamera);
|
||||||
void updateAvatar(float deltaTime);
|
void updateAvatar(float deltaTime);
|
||||||
void loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum);
|
void loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum);
|
||||||
|
@ -378,6 +384,7 @@ private:
|
||||||
|
|
||||||
bool _isLookingAtOtherAvatar;
|
bool _isLookingAtOtherAvatar;
|
||||||
glm::vec3 _lookatOtherPosition;
|
glm::vec3 _lookatOtherPosition;
|
||||||
|
float _lookatIndicatorScale;
|
||||||
|
|
||||||
bool _paintOn; // Whether to paint voxels as you fly around
|
bool _paintOn; // Whether to paint voxels as you fly around
|
||||||
unsigned char _dominantColor; // The dominant color of the voxel we're painting
|
unsigned char _dominantColor; // The dominant color of the voxel we're painting
|
||||||
|
|
|
@ -112,7 +112,7 @@ inline void Audio::performIO(int16_t* inputLeft, int16_t* outputLeft, int16_t* o
|
||||||
|
|
||||||
// we need the amount of bytes in the buffer + 1 for type
|
// we need the amount of bytes in the buffer + 1 for type
|
||||||
// + 12 for 3 floats for position + float for bearing + 1 attenuation byte
|
// + 12 for 3 floats for position + float for bearing + 1 attenuation byte
|
||||||
unsigned char dataPacket[BUFFER_LENGTH_BYTES_PER_CHANNEL + leadingBytes];
|
unsigned char dataPacket[MAX_PACKET_SIZE];
|
||||||
|
|
||||||
PACKET_TYPE packetType = (Application::getInstance()->shouldEchoAudio())
|
PACKET_TYPE packetType = (Application::getInstance()->shouldEchoAudio())
|
||||||
? PACKET_TYPE_MICROPHONE_AUDIO_WITH_ECHO
|
? PACKET_TYPE_MICROPHONE_AUDIO_WITH_ECHO
|
||||||
|
@ -120,6 +120,33 @@ inline void Audio::performIO(int16_t* inputLeft, int16_t* outputLeft, int16_t* o
|
||||||
|
|
||||||
unsigned char* currentPacketPtr = dataPacket + populateTypeAndVersion(dataPacket, packetType);
|
unsigned char* currentPacketPtr = dataPacket + populateTypeAndVersion(dataPacket, packetType);
|
||||||
|
|
||||||
|
// pack Source Data
|
||||||
|
uint16_t ownerID = NodeList::getInstance()->getOwnerID();
|
||||||
|
memcpy(currentPacketPtr, &ownerID, sizeof(ownerID));
|
||||||
|
currentPacketPtr += (sizeof(ownerID));
|
||||||
|
leadingBytes += (sizeof(ownerID));
|
||||||
|
|
||||||
|
// pack Listen Mode Data
|
||||||
|
memcpy(currentPacketPtr, &_listenMode, sizeof(_listenMode));
|
||||||
|
currentPacketPtr += (sizeof(_listenMode));
|
||||||
|
leadingBytes += (sizeof(_listenMode));
|
||||||
|
|
||||||
|
if (_listenMode == AudioRingBuffer::OMNI_DIRECTIONAL_POINT) {
|
||||||
|
memcpy(currentPacketPtr, &_listenRadius, sizeof(_listenRadius));
|
||||||
|
currentPacketPtr += (sizeof(_listenRadius));
|
||||||
|
leadingBytes += (sizeof(_listenRadius));
|
||||||
|
} else if (_listenMode == AudioRingBuffer::SELECTED_SOURCES) {
|
||||||
|
int listenSourceCount = _listenSources.size();
|
||||||
|
memcpy(currentPacketPtr, &listenSourceCount, sizeof(listenSourceCount));
|
||||||
|
currentPacketPtr += (sizeof(listenSourceCount));
|
||||||
|
leadingBytes += (sizeof(listenSourceCount));
|
||||||
|
for (int i = 0; i < listenSourceCount; i++) {
|
||||||
|
memcpy(currentPacketPtr, &_listenSources[i], sizeof(_listenSources[i]));
|
||||||
|
currentPacketPtr += sizeof(_listenSources[i]);
|
||||||
|
leadingBytes += sizeof(_listenSources[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// memcpy the three float positions
|
// memcpy the three float positions
|
||||||
memcpy(currentPacketPtr, &headPosition, sizeof(headPosition));
|
memcpy(currentPacketPtr, &headPosition, sizeof(headPosition));
|
||||||
currentPacketPtr += (sizeof(headPosition));
|
currentPacketPtr += (sizeof(headPosition));
|
||||||
|
@ -309,6 +336,24 @@ void Audio::reset() {
|
||||||
_ringBuffer.reset();
|
_ringBuffer.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Audio::addListenSource(int sourceID) {
|
||||||
|
_listenSources.push_back(sourceID);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Audio::clearListenSources() {
|
||||||
|
_listenSources.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Audio::removeListenSource(int sourceID) {
|
||||||
|
for (int i = 0; i < _listenSources.size(); i++) {
|
||||||
|
if (_listenSources[i] == sourceID) {
|
||||||
|
_listenSources.erase(_listenSources.begin() + i);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Audio::Audio(Oscilloscope* scope, int16_t initialJitterBufferSamples) :
|
Audio::Audio(Oscilloscope* scope, int16_t initialJitterBufferSamples) :
|
||||||
_stream(NULL),
|
_stream(NULL),
|
||||||
_ringBuffer(true),
|
_ringBuffer(true),
|
||||||
|
@ -338,7 +383,9 @@ Audio::Audio(Oscilloscope* scope, int16_t initialJitterBufferSamples) :
|
||||||
_collisionSoundNoise(0.0f),
|
_collisionSoundNoise(0.0f),
|
||||||
_collisionSoundDuration(0.0f),
|
_collisionSoundDuration(0.0f),
|
||||||
_proceduralEffectSample(0),
|
_proceduralEffectSample(0),
|
||||||
_heartbeatMagnitude(0.0f)
|
_heartbeatMagnitude(0.0f),
|
||||||
|
_listenMode(AudioRingBuffer::NORMAL),
|
||||||
|
_listenRadius(0.0f)
|
||||||
{
|
{
|
||||||
outputPortAudioError(Pa_Initialize());
|
outputPortAudioError(Pa_Initialize());
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#ifndef __interface__Audio__
|
#ifndef __interface__Audio__
|
||||||
#define __interface__Audio__
|
#define __interface__Audio__
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
#include <portaudio.h>
|
#include <portaudio.h>
|
||||||
#include <AudioRingBuffer.h>
|
#include <AudioRingBuffer.h>
|
||||||
#include <StdDev.h>
|
#include <StdDev.h>
|
||||||
|
@ -54,6 +55,11 @@ public:
|
||||||
// The results of the analysis are written to the log.
|
// The results of the analysis are written to the log.
|
||||||
bool eventuallyAnalyzePing();
|
bool eventuallyAnalyzePing();
|
||||||
|
|
||||||
|
void setListenMode(AudioRingBuffer::ListenMode mode) { _listenMode = mode; };
|
||||||
|
void setListenRadius(float radius) { _listenRadius = radius; };
|
||||||
|
void addListenSource(int sourceID);
|
||||||
|
void removeListenSource(int sourceID);
|
||||||
|
void clearListenSources();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PaStream* _stream;
|
PaStream* _stream;
|
||||||
|
@ -90,6 +96,10 @@ private:
|
||||||
float _collisionSoundDuration;
|
float _collisionSoundDuration;
|
||||||
int _proceduralEffectSample;
|
int _proceduralEffectSample;
|
||||||
float _heartbeatMagnitude;
|
float _heartbeatMagnitude;
|
||||||
|
|
||||||
|
AudioRingBuffer::ListenMode _listenMode;
|
||||||
|
float _listenRadius;
|
||||||
|
std::vector<int> _listenSources;
|
||||||
|
|
||||||
// Audio callback in class context.
|
// Audio callback in class context.
|
||||||
inline void performIO(int16_t* inputLeft, int16_t* outputLeft, int16_t* outputRight);
|
inline void performIO(int16_t* inputLeft, int16_t* outputLeft, int16_t* outputRight);
|
||||||
|
|
|
@ -164,6 +164,10 @@ public:
|
||||||
glm::quat getOrientation () const;
|
glm::quat getOrientation () const;
|
||||||
glm::quat getWorldAlignedOrientation() const;
|
glm::quat getWorldAlignedOrientation() const;
|
||||||
|
|
||||||
|
const glm::vec3& getMouseRayOrigin() const { return _mouseRayOrigin; }
|
||||||
|
const glm::vec3& getMouseRayDirection() const { return _mouseRayDirection; }
|
||||||
|
|
||||||
|
|
||||||
glm::vec3 getGravity () const { return _gravity; }
|
glm::vec3 getGravity () const { return _gravity; }
|
||||||
|
|
||||||
glm::vec3 getUprightHeadPosition() const;
|
glm::vec3 getUprightHeadPosition() const;
|
||||||
|
|
|
@ -272,7 +272,7 @@ void Head::calculateGeometry() {
|
||||||
+ up * _scale * BODY_BALL_RADIUS_HEAD_BASE * EYE_UP_OFFSET
|
+ up * _scale * BODY_BALL_RADIUS_HEAD_BASE * EYE_UP_OFFSET
|
||||||
+ front * _scale * BODY_BALL_RADIUS_HEAD_BASE * EYE_FRONT_OFFSET;
|
+ front * _scale * BODY_BALL_RADIUS_HEAD_BASE * EYE_FRONT_OFFSET;
|
||||||
|
|
||||||
_eyeLevelPosition = _position + up * _scale * BODY_BALL_RADIUS_HEAD_BASE * EYE_UP_OFFSET;
|
_eyeLevelPosition = _rightEyePosition - right * _scale * BODY_BALL_RADIUS_HEAD_BASE * EYE_RIGHT_OFFSET;
|
||||||
|
|
||||||
//calculate the eyebrow positions
|
//calculate the eyebrow positions
|
||||||
_leftEyeBrowPosition = _leftEyePosition;
|
_leftEyeBrowPosition = _leftEyePosition;
|
||||||
|
|
|
@ -27,6 +27,14 @@ const short RING_BUFFER_LENGTH_SAMPLES = RING_BUFFER_LENGTH_FRAMES * BUFFER_LENG
|
||||||
|
|
||||||
class AudioRingBuffer : public NodeData {
|
class AudioRingBuffer : public NodeData {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
static int const DEFAULT_LISTEN_LIST_SIZE = 100;
|
||||||
|
typedef enum {
|
||||||
|
NORMAL,
|
||||||
|
OMNI_DIRECTIONAL_POINT,
|
||||||
|
SELECTED_SOURCES
|
||||||
|
} ListenMode;
|
||||||
|
|
||||||
AudioRingBuffer(bool isStereo);
|
AudioRingBuffer(bool isStereo);
|
||||||
~AudioRingBuffer();
|
~AudioRingBuffer();
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,12 @@
|
||||||
|
|
||||||
PACKET_VERSION versionForPacketType(PACKET_TYPE type) {
|
PACKET_VERSION versionForPacketType(PACKET_TYPE type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
|
||||||
|
case PACKET_TYPE_MICROPHONE_AUDIO_NO_ECHO:
|
||||||
|
case PACKET_TYPE_MICROPHONE_AUDIO_WITH_ECHO:
|
||||||
|
return 1;
|
||||||
|
break;
|
||||||
|
|
||||||
case PACKET_TYPE_HEAD_DATA:
|
case PACKET_TYPE_HEAD_DATA:
|
||||||
return 2;
|
return 2;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue