cleanup new API for sound injection

This commit is contained in:
Stephen Birarda 2014-01-02 12:31:01 -08:00
parent 674c19a570
commit 3a45fb8533
4 changed files with 40 additions and 21 deletions

View file

@ -125,7 +125,13 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f
caughtParticle = NULL;
// use the threadSound static method to inject the catch sound
AudioInjector::threadSound(&_catchSound, targetPosition);
// pass an AudioInjectorOptions struct to set position and disable loopback
AudioInjectorOptions injectorOptions;
injectorOptions.position = targetPosition;
injectorOptions.shouldLoopback = false;
injectorOptions.loopbackAudioInterface = app->getAudio();
AudioInjector::threadSound(&_catchSound, injectorOptions);
}
}
@ -208,7 +214,13 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f
_ballParticleEditHandles[handID] = NULL;
// use the threadSound static method to inject the throw sound
AudioInjector::threadSound(&_throwSound, targetPosition);
// pass an AudioInjectorOptions struct to set position and disable loopback
AudioInjectorOptions injectorOptions;
injectorOptions.position = targetPosition;
injectorOptions.shouldLoopback = false;
injectorOptions.loopbackAudioInterface = app->getAudio();
AudioInjector::threadSound(&_throwSound, injectorOptions);
}
}

View file

@ -18,23 +18,20 @@
int abstractAudioPointerMeta = qRegisterMetaType<AbstractAudioInterface*>("AbstractAudioInterface*");
AudioInjector::AudioInjector(Sound* sound, const glm::vec3 position, float volume,
const glm::quat orientation, bool shouldLoopback,
AbstractAudioInterface* loopbackAudioInterface) :
AudioInjector::AudioInjector(Sound* sound, AudioInjectorOptions injectorOptions) :
_sound(sound),
_volume(volume),
_shouldLoopback(shouldLoopback),
_position(position),
_orientation(orientation),
_loopbackAudioInterface(loopbackAudioInterface)
_volume(injectorOptions.volume),
_shouldLoopback(injectorOptions.shouldLoopback),
_position(injectorOptions.position),
_orientation(injectorOptions.orientation),
_loopbackAudioInterface(injectorOptions.loopbackAudioInterface)
{
// we want to live on our own thread
moveToThread(&_thread);
}
void AudioInjector::threadSound(Sound* sound, const glm::vec3 position, float volume,
const glm::quat orientation, bool shouldLoopback, AbstractAudioInterface* audioInterface) {
AudioInjector injector(sound, position, volume, orientation, shouldLoopback, audioInterface);
void AudioInjector::threadSound(Sound* sound, AudioInjectorOptions injectorOptions) {
AudioInjector injector(sound, injectorOptions);
// start injecting when the injector thread starts
connect(&injector._thread, SIGNAL(started()), &injector, SLOT(injectAudio()));

View file

@ -19,17 +19,26 @@
class AbstractAudioInterface;
struct AudioInjectorOptions {
AudioInjectorOptions() : position(glm::vec3(0.0f, 0.0f, 0.0f)),
volume(1.0f),
orientation(glm::quat()),
shouldLoopback(true),
loopbackAudioInterface(NULL) {};
glm::vec3 position;
float volume;
const glm::quat orientation;
bool shouldLoopback;
AbstractAudioInterface* loopbackAudioInterface;
};
class AudioInjector : public QObject {
Q_OBJECT
public:
static void threadSound(Sound* sound,
const glm::vec3 position = glm::vec3(0.0f, 0.0f, 0.0f),
float volume = 1.0f,
const glm::quat orientation = glm::quat(),
bool shouldLoopback = true,
AbstractAudioInterface* loopbackAudioInterface = NULL);
static void threadSound(Sound* sound, AudioInjectorOptions injectorOptions = AudioInjectorOptions());
private:
AudioInjector(Sound* sound, const glm::vec3 position, float volume,
const glm::quat orientation, bool shouldLoopback, AbstractAudioInterface* loopbackAudioInterface);
AudioInjector(Sound* sound, AudioInjectorOptions injectorOptions);
QThread _thread;
Sound* _sound;

View file

@ -14,6 +14,7 @@
class QNetworkReply;
class Sound : public QObject {
Q_OBJECT
public:
Sound(const QUrl& sampleURL);