Merge pull request #2443 from birarda/master

fix div by zero and output number of clients mixed in last frame
This commit is contained in:
Stephen Birarda 2014-03-21 18:18:06 -07:00
commit 6e83a939f9
2 changed files with 15 additions and 3 deletions

View file

@ -66,7 +66,8 @@ void attachNewBufferToNode(Node *newNode) {
AudioMixer::AudioMixer(const QByteArray& packet) : AudioMixer::AudioMixer(const QByteArray& packet) :
ThreadedAssignment(packet), ThreadedAssignment(packet),
_trailingSleepRatio(1.0f), _trailingSleepRatio(1.0f),
_minAudibilityThreshold(LOUDNESS_TO_DISTANCE_RATIO / 2.0f) _minAudibilityThreshold(LOUDNESS_TO_DISTANCE_RATIO / 2.0f),
_numClientsMixedInFrame(0)
{ {
} }
@ -80,15 +81,22 @@ void AudioMixer::addBufferToMixForListeningNodeWithBuffer(PositionalAudioRingBuf
if (bufferToAdd != listeningNodeBuffer) { if (bufferToAdd != listeningNodeBuffer) {
// if the two buffer pointers do not match then these are different buffers // if the two buffer pointers do not match then these are different buffers
glm::vec3 relativePosition = bufferToAdd->getPosition() - listeningNodeBuffer->getPosition(); glm::vec3 relativePosition = bufferToAdd->getPosition() - listeningNodeBuffer->getPosition();
if (bufferToAdd->getAverageLoudness() / glm::length(relativePosition) <= _minAudibilityThreshold) { float distanceBetween = glm::length(relativePosition);
if (distanceBetween < EPSILON) {
distanceBetween = EPSILON;
}
if (bufferToAdd->getAverageLoudness() / distanceBetween <= _minAudibilityThreshold) {
// according to mixer performance we have decided this does not get to be mixed in // according to mixer performance we have decided this does not get to be mixed in
// bail out // bail out
return; return;
} }
++_numClientsMixedInFrame;
glm::quat inverseOrientation = glm::inverse(listeningNodeBuffer->getOrientation()); glm::quat inverseOrientation = glm::inverse(listeningNodeBuffer->getOrientation());
float distanceSquareToSource = glm::dot(relativePosition, relativePosition); float distanceSquareToSource = glm::dot(relativePosition, relativePosition);
@ -441,6 +449,9 @@ void AudioMixer::run() {
nodeList->writeDatagram(clientMixBuffer, NETWORK_BUFFER_LENGTH_BYTES_STEREO + numBytesPacketHeader, node); nodeList->writeDatagram(clientMixBuffer, NETWORK_BUFFER_LENGTH_BYTES_STEREO + numBytesPacketHeader, node);
} }
} }
qDebug() << "There were" << _numClientsMixedInFrame << "clients mixed in the last frame";
_numClientsMixedInFrame = 0;
// push forward the next output pointers for any audio buffers we used // push forward the next output pointers for any audio buffers we used
foreach (const SharedNodePointer& node, nodeList->getNodeHash()) { foreach (const SharedNodePointer& node, nodeList->getNodeHash()) {

View file

@ -42,6 +42,7 @@ private:
float _trailingSleepRatio; float _trailingSleepRatio;
float _minAudibilityThreshold; float _minAudibilityThreshold;
int _numClientsMixedInFrame;
}; };
#endif /* defined(__hifi__AudioMixer__) */ #endif /* defined(__hifi__AudioMixer__) */