diff --git a/assignment-client/src/audio/AudioMixerClientData.cpp b/assignment-client/src/audio/AudioMixerClientData.cpp index 4827fbc918..fa171f252d 100644 --- a/assignment-client/src/audio/AudioMixerClientData.cpp +++ b/assignment-client/src/audio/AudioMixerClientData.cpp @@ -94,11 +94,10 @@ void AudioMixerClientData::pushBuffersAfterFrameSend() { audioBuffer->shiftReadPosition(NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL); audioBuffer->setWillBeAddedToMix(false); - } else if (audioBuffer->isStarved()) { - // this was previously the kill for injected audio from a client - // fix when that is added back - // delete audioBuffer; - // _ringBuffers.erase(_ringBuffers.begin() + i); + } else if (audioBuffer->hasStarted() && audioBuffer->isStarved()) { + // this is an empty audio buffer that has starved, safe to delete + delete audioBuffer; + _ringBuffers.erase(_ringBuffers.begin() + i); } } } diff --git a/interface/src/avatar/Hand.cpp b/interface/src/avatar/Hand.cpp index a25fa086de..3dfcc88807 100755 --- a/interface/src/avatar/Hand.cpp +++ b/interface/src/avatar/Hand.cpp @@ -53,7 +53,9 @@ Hand::Hand(Avatar* owningAvatar) : _collisionDuration(0), _pitchUpdate(0), _grabDelta(0, 0, 0), - _grabDeltaVelocity(0, 0, 0) + _grabDeltaVelocity(0, 0, 0), + _throwInjector(QUrl("https://dl.dropboxusercontent.com/u/1864924/hifi-sounds/throw.raw")), + _catchInjector(QUrl("https://dl.dropboxusercontent.com/u/1864924/hifi-sounds/catch.raw")) { for (int i = 0; i < MAX_HANDS; i++) { _toyBallInHand[i] = false; @@ -61,6 +63,10 @@ Hand::Hand(Avatar* owningAvatar) : _whichBallColor[i] = 0; } _lastControllerButtons = 0; + + // the throw and catch sounds should not loopback, we'll play them locally + _throwInjector.setShouldLoopback(false); + _catchInjector.setShouldLoopback(false); } void Hand::init() { @@ -119,7 +125,10 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f _ballParticleEditHandles[handID] = caughtParticle; caughtParticle = NULL; // Play a catch sound! - app->getAudio()->startDrumSound(1.0, 300, 0.5, 0.05); + _catchInjector.setPosition(targetPosition); + + // inject the catch sound to the mixer and play it locally + _catchInjector.injectViaThread(app->getAudio()); } } @@ -222,8 +231,11 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f delete _ballParticleEditHandles[handID]; _ballParticleEditHandles[handID] = NULL; - // Play a throw sound - app->getAudio()->startDrumSound(1.0, 3000, 0.5, 0.02); + // move the throw injector to inject from the position of the ball + _throwInjector.setPosition(ballPosition); + + // inject the throw sound and play it locally + _throwInjector.injectViaThread(app->getAudio()); } } diff --git a/interface/src/avatar/Hand.h b/interface/src/avatar/Hand.h index d7acba6a3e..884d710381 100755 --- a/interface/src/avatar/Hand.h +++ b/interface/src/avatar/Hand.h @@ -17,6 +17,7 @@ #include #include +#include #include #include @@ -110,7 +111,9 @@ private: glm::vec3 _grabDelta; glm::vec3 _grabDeltaVelocity; - + + AudioInjector _throwInjector; + AudioInjector _catchInjector; }; #endif diff --git a/libraries/audio/src/AudioRingBuffer.h b/libraries/audio/src/AudioRingBuffer.h index 4860b47af2..0bcd127a2e 100644 --- a/libraries/audio/src/AudioRingBuffer.h +++ b/libraries/audio/src/AudioRingBuffer.h @@ -62,6 +62,8 @@ public: bool isStarved() const { return _isStarved; } void setIsStarved(bool isStarved) { _isStarved = isStarved; } + + bool hasStarted() const { return _hasStarted; } protected: // disallow copying of AudioRingBuffer objects AudioRingBuffer(const AudioRingBuffer&);