mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 20:48:56 +02:00
cleanup new API for sound injection
This commit is contained in:
parent
674c19a570
commit
3a45fb8533
4 changed files with 40 additions and 21 deletions
|
@ -125,7 +125,13 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f
|
||||||
caughtParticle = NULL;
|
caughtParticle = NULL;
|
||||||
|
|
||||||
// use the threadSound static method to inject the catch sound
|
// 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;
|
_ballParticleEditHandles[handID] = NULL;
|
||||||
|
|
||||||
// use the threadSound static method to inject the throw sound
|
// 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,23 +18,20 @@
|
||||||
|
|
||||||
int abstractAudioPointerMeta = qRegisterMetaType<AbstractAudioInterface*>("AbstractAudioInterface*");
|
int abstractAudioPointerMeta = qRegisterMetaType<AbstractAudioInterface*>("AbstractAudioInterface*");
|
||||||
|
|
||||||
AudioInjector::AudioInjector(Sound* sound, const glm::vec3 position, float volume,
|
AudioInjector::AudioInjector(Sound* sound, AudioInjectorOptions injectorOptions) :
|
||||||
const glm::quat orientation, bool shouldLoopback,
|
|
||||||
AbstractAudioInterface* loopbackAudioInterface) :
|
|
||||||
_sound(sound),
|
_sound(sound),
|
||||||
_volume(volume),
|
_volume(injectorOptions.volume),
|
||||||
_shouldLoopback(shouldLoopback),
|
_shouldLoopback(injectorOptions.shouldLoopback),
|
||||||
_position(position),
|
_position(injectorOptions.position),
|
||||||
_orientation(orientation),
|
_orientation(injectorOptions.orientation),
|
||||||
_loopbackAudioInterface(loopbackAudioInterface)
|
_loopbackAudioInterface(injectorOptions.loopbackAudioInterface)
|
||||||
{
|
{
|
||||||
// we want to live on our own thread
|
// we want to live on our own thread
|
||||||
moveToThread(&_thread);
|
moveToThread(&_thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioInjector::threadSound(Sound* sound, const glm::vec3 position, float volume,
|
void AudioInjector::threadSound(Sound* sound, AudioInjectorOptions injectorOptions) {
|
||||||
const glm::quat orientation, bool shouldLoopback, AbstractAudioInterface* audioInterface) {
|
AudioInjector injector(sound, injectorOptions);
|
||||||
AudioInjector injector(sound, position, volume, orientation, shouldLoopback, audioInterface);
|
|
||||||
|
|
||||||
// start injecting when the injector thread starts
|
// start injecting when the injector thread starts
|
||||||
connect(&injector._thread, SIGNAL(started()), &injector, SLOT(injectAudio()));
|
connect(&injector._thread, SIGNAL(started()), &injector, SLOT(injectAudio()));
|
||||||
|
|
|
@ -19,17 +19,26 @@
|
||||||
|
|
||||||
class AbstractAudioInterface;
|
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 {
|
class AudioInjector : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
static void threadSound(Sound* sound,
|
static void threadSound(Sound* sound, AudioInjectorOptions injectorOptions = AudioInjectorOptions());
|
||||||
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);
|
|
||||||
private:
|
private:
|
||||||
AudioInjector(Sound* sound, const glm::vec3 position, float volume,
|
AudioInjector(Sound* sound, AudioInjectorOptions injectorOptions);
|
||||||
const glm::quat orientation, bool shouldLoopback, AbstractAudioInterface* loopbackAudioInterface);
|
|
||||||
|
|
||||||
QThread _thread;
|
QThread _thread;
|
||||||
Sound* _sound;
|
Sound* _sound;
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
class QNetworkReply;
|
class QNetworkReply;
|
||||||
|
|
||||||
class Sound : public QObject {
|
class Sound : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
Sound(const QUrl& sampleURL);
|
Sound(const QUrl& sampleURL);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue