mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 20:06:02 +02:00
leverage new AudioInjector API for throw and catch sounds
This commit is contained in:
parent
3123b83d0b
commit
674c19a570
5 changed files with 50 additions and 43 deletions
|
@ -54,8 +54,8 @@ Hand::Hand(Avatar* owningAvatar) :
|
||||||
_grabDeltaVelocity(0, 0, 0),
|
_grabDeltaVelocity(0, 0, 0),
|
||||||
_grabStartRotation(0, 0, 0, 1),
|
_grabStartRotation(0, 0, 0, 1),
|
||||||
_grabCurrentRotation(0, 0, 0, 1),
|
_grabCurrentRotation(0, 0, 0, 1),
|
||||||
_throwInjector(QUrl("https://dl.dropboxusercontent.com/u/1864924/hifi-sounds/throw.raw")),
|
_throwSound(QUrl("https://dl.dropboxusercontent.com/u/1864924/hifi-sounds/throw.raw")),
|
||||||
_catchInjector(QUrl("https://dl.dropboxusercontent.com/u/1864924/hifi-sounds/catch.raw"))
|
_catchSound(QUrl("https://dl.dropboxusercontent.com/u/1864924/hifi-sounds/catch.raw"))
|
||||||
{
|
{
|
||||||
for (int i = 0; i < MAX_HANDS; i++) {
|
for (int i = 0; i < MAX_HANDS; i++) {
|
||||||
_toyBallInHand[i] = false;
|
_toyBallInHand[i] = false;
|
||||||
|
@ -63,10 +63,6 @@ Hand::Hand(Avatar* owningAvatar) :
|
||||||
_whichBallColor[i] = 0;
|
_whichBallColor[i] = 0;
|
||||||
}
|
}
|
||||||
_lastControllerButtons = 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() {
|
void Hand::init() {
|
||||||
|
@ -128,11 +124,8 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f
|
||||||
_ballParticleEditHandles[handID] = caughtParticle;
|
_ballParticleEditHandles[handID] = caughtParticle;
|
||||||
caughtParticle = NULL;
|
caughtParticle = NULL;
|
||||||
|
|
||||||
// set the position of the catch sound to the new position of the ball
|
// use the threadSound static method to inject the catch sound
|
||||||
_catchInjector.setPosition(targetPosition);
|
AudioInjector::threadSound(&_catchSound, targetPosition);
|
||||||
|
|
||||||
// inject the catch sound to the mixer and play it locally
|
|
||||||
_catchInjector.injectViaThread(app->getAudio());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,11 +207,8 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f
|
||||||
delete _ballParticleEditHandles[handID];
|
delete _ballParticleEditHandles[handID];
|
||||||
_ballParticleEditHandles[handID] = NULL;
|
_ballParticleEditHandles[handID] = NULL;
|
||||||
|
|
||||||
// move the throw injector to inject from the position of the ball
|
// use the threadSound static method to inject the throw sound
|
||||||
_throwInjector.setPosition(ballPosition);
|
AudioInjector::threadSound(&_throwSound, targetPosition);
|
||||||
|
|
||||||
// inject the throw sound and play it locally
|
|
||||||
_throwInjector.injectViaThread(app->getAudio());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -114,8 +114,8 @@ private:
|
||||||
glm::quat _grabStartRotation;
|
glm::quat _grabStartRotation;
|
||||||
glm::quat _grabCurrentRotation;
|
glm::quat _grabCurrentRotation;
|
||||||
|
|
||||||
AudioInjector _throwInjector;
|
Sound _throwSound;
|
||||||
AudioInjector _catchInjector;
|
Sound _catchSound;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -18,36 +18,46 @@
|
||||||
|
|
||||||
int abstractAudioPointerMeta = qRegisterMetaType<AbstractAudioInterface*>("AbstractAudioInterface*");
|
int abstractAudioPointerMeta = qRegisterMetaType<AbstractAudioInterface*>("AbstractAudioInterface*");
|
||||||
|
|
||||||
AudioInjector::AudioInjector(Sound* sound) :
|
AudioInjector::AudioInjector(Sound* sound, const glm::vec3 position, float volume,
|
||||||
|
const glm::quat orientation, bool shouldLoopback,
|
||||||
|
AbstractAudioInterface* loopbackAudioInterface) :
|
||||||
_sound(sound),
|
_sound(sound),
|
||||||
_volume(1.0f),
|
_volume(volume),
|
||||||
_shouldLoopback(true),
|
_shouldLoopback(shouldLoopback),
|
||||||
_position(0.0f, 0.0f, 0.0f),
|
_position(position),
|
||||||
_orientation()
|
_orientation(orientation),
|
||||||
|
_loopbackAudioInterface(loopbackAudioInterface)
|
||||||
{
|
{
|
||||||
// we want to live on our own thread
|
// we want to live on our own thread
|
||||||
moveToThread(&_thread);
|
moveToThread(&_thread);
|
||||||
connect(&_thread, SIGNAL(started()), this, SLOT(startDownload()));
|
|
||||||
_thread.start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioInjector::injectViaThread(AbstractAudioInterface* localAudioInterface) {
|
void AudioInjector::threadSound(Sound* sound, const glm::vec3 position, float volume,
|
||||||
// use Qt::AutoConnection so that this is called on our thread, if appropriate
|
const glm::quat orientation, bool shouldLoopback, AbstractAudioInterface* audioInterface) {
|
||||||
QMetaObject::invokeMethod(this, "injectAudio", Qt::AutoConnection, Q_ARG(AbstractAudioInterface*, localAudioInterface));
|
AudioInjector injector(sound, position, volume, orientation, shouldLoopback, audioInterface);
|
||||||
|
|
||||||
|
// start injecting when the injector thread starts
|
||||||
|
connect(&injector._thread, SIGNAL(started()), &injector, SLOT(injectAudio()));
|
||||||
|
|
||||||
|
// connect the right slots and signals so that the AudioInjector is killed once the injection is complete
|
||||||
|
connect(&injector, SIGNAL(finished()), &injector._thread, SLOT(quit()));
|
||||||
|
connect(&injector, SIGNAL(finished()), &injector, SLOT(deleteLater()));
|
||||||
|
|
||||||
|
injector._thread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
const uchar MAX_INJECTOR_VOLUME = 0xFF;
|
const uchar MAX_INJECTOR_VOLUME = 0xFF;
|
||||||
|
|
||||||
void AudioInjector::injectAudio(AbstractAudioInterface* localAudioInterface) {
|
void AudioInjector::injectAudio() {
|
||||||
|
|
||||||
QByteArray soundByteArray = _sound->getByteArray();
|
QByteArray soundByteArray = _sound->getByteArray();
|
||||||
|
|
||||||
// make sure we actually have samples downloaded to inject
|
// make sure we actually have samples downloaded to inject
|
||||||
if (soundByteArray.size()) {
|
if (soundByteArray.size()) {
|
||||||
// give our sample byte array to the local audio interface, if we have it, so it can be handled locally
|
// give our sample byte array to the local audio interface, if we have it, so it can be handled locally
|
||||||
if (localAudioInterface) {
|
if (_loopbackAudioInterface) {
|
||||||
// assume that localAudioInterface could be on a separate thread, use Qt::AutoConnection to handle properly
|
// assume that localAudioInterface could be on a separate thread, use Qt::AutoConnection to handle properly
|
||||||
QMetaObject::invokeMethod(localAudioInterface, "handleAudioByteArray",
|
QMetaObject::invokeMethod(_loopbackAudioInterface, "handleAudioByteArray",
|
||||||
Qt::AutoConnection,
|
Qt::AutoConnection,
|
||||||
Q_ARG(QByteArray, soundByteArray));
|
Q_ARG(QByteArray, soundByteArray));
|
||||||
|
|
||||||
|
@ -137,6 +147,7 @@ void AudioInjector::injectAudio(AbstractAudioInterface* localAudioInterface) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
emit finished();
|
||||||
}
|
}
|
|
@ -17,25 +17,31 @@
|
||||||
|
|
||||||
#include "Sound.h"
|
#include "Sound.h"
|
||||||
|
|
||||||
|
class AbstractAudioInterface;
|
||||||
|
|
||||||
class AudioInjector : public QObject {
|
class AudioInjector : public QObject {
|
||||||
public:
|
public:
|
||||||
AudioInjector(Sound* sound);
|
static void threadSound(Sound* sound,
|
||||||
|
const glm::vec3 position = glm::vec3(0.0f, 0.0f, 0.0f),
|
||||||
void setPosition(const glm::vec3& position) { _position = position; }
|
float volume = 1.0f,
|
||||||
void setOrientation(const glm::quat& orientation) { _orientation = orientation; }
|
const glm::quat orientation = glm::quat(),
|
||||||
void setVolume(float volume) { _volume = std::max(fabsf(volume), 1.0f); }
|
bool shouldLoopback = true,
|
||||||
void setShouldLoopback(bool shouldLoopback) { _shouldLoopback = shouldLoopback; }
|
AbstractAudioInterface* loopbackAudioInterface = NULL);
|
||||||
public slots:
|
|
||||||
void injectViaThread(AbstractAudioInterface* localAudioInterface = NULL);
|
|
||||||
private:
|
private:
|
||||||
|
AudioInjector(Sound* sound, const glm::vec3 position, float volume,
|
||||||
|
const glm::quat orientation, bool shouldLoopback, AbstractAudioInterface* loopbackAudioInterface);
|
||||||
|
|
||||||
QThread _thread;
|
QThread _thread;
|
||||||
Sound* _sound;
|
Sound* _sound;
|
||||||
float _volume;
|
float _volume;
|
||||||
uchar _shouldLoopback;
|
uchar _shouldLoopback;
|
||||||
glm::vec3 _position;
|
glm::vec3 _position;
|
||||||
glm::quat _orientation;
|
glm::quat _orientation;
|
||||||
|
AbstractAudioInterface* _loopbackAudioInterface;
|
||||||
private slots:
|
private slots:
|
||||||
void injectAudio(AbstractAudioInterface* localAudioInterface);
|
void injectAudio();
|
||||||
|
signals:
|
||||||
|
void finished();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* defined(__hifi__AudioInjector__) */
|
#endif /* defined(__hifi__AudioInjector__) */
|
||||||
|
|
|
@ -24,6 +24,6 @@ Sound::Sound(const QUrl& sampleURL) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sound::replyFinished(QNetworkReply* reply) {
|
void Sound::replyFinished(QNetworkReply* reply) {
|
||||||
// replace our samples array with the downloaded data
|
// replace our byte array with the downloaded data
|
||||||
_sampleByteArray = reply->readAll();
|
_byteArray = reply->readAll();
|
||||||
}
|
}
|
Loading…
Reference in a new issue