mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 20:06:02 +02:00
open up ASI playSound method to ScriptEngine
This commit is contained in:
parent
443c94a88f
commit
f24eff33fe
9 changed files with 65 additions and 37 deletions
|
@ -127,11 +127,11 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f
|
||||||
// use the threadSound static method to inject the catch sound
|
// use the threadSound static method to inject the catch sound
|
||||||
// pass an AudioInjectorOptions struct to set position and disable loopback
|
// pass an AudioInjectorOptions struct to set position and disable loopback
|
||||||
AudioInjectorOptions injectorOptions;
|
AudioInjectorOptions injectorOptions;
|
||||||
injectorOptions.position = newPosition;
|
injectorOptions.setPosition(newPosition);
|
||||||
injectorOptions.shouldLoopback = false;
|
injectorOptions.setShouldLoopback(false);
|
||||||
injectorOptions.loopbackAudioInterface = app->getAudio();
|
injectorOptions.setLoopbackAudioInterface(app->getAudio());
|
||||||
|
|
||||||
AudioScriptingInterface::playSound(&_catchSound, injectorOptions);
|
AudioScriptingInterface::playSound(&_catchSound, &injectorOptions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,11 +216,11 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f
|
||||||
// use the threadSound static method to inject the throw sound
|
// use the threadSound static method to inject the throw sound
|
||||||
// pass an AudioInjectorOptions struct to set position and disable loopback
|
// pass an AudioInjectorOptions struct to set position and disable loopback
|
||||||
AudioInjectorOptions injectorOptions;
|
AudioInjectorOptions injectorOptions;
|
||||||
injectorOptions.position = ballPosition;
|
injectorOptions.setPosition(ballPosition);
|
||||||
injectorOptions.shouldLoopback = false;
|
injectorOptions.setShouldLoopback(false);
|
||||||
injectorOptions.loopbackAudioInterface = app->getAudio();
|
injectorOptions.setLoopbackAudioInterface(app->getAudio());
|
||||||
|
|
||||||
AudioScriptingInterface::playSound(&_throwSound, injectorOptions);
|
AudioScriptingInterface::playSound(&_throwSound, &injectorOptions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
int abstractAudioPointerMeta = qRegisterMetaType<AbstractAudioInterface*>("AbstractAudioInterface*");
|
int abstractAudioPointerMeta = qRegisterMetaType<AbstractAudioInterface*>("AbstractAudioInterface*");
|
||||||
|
|
||||||
AudioInjector::AudioInjector(Sound* sound, AudioInjectorOptions injectorOptions) :
|
AudioInjector::AudioInjector(Sound* sound, const AudioInjectorOptions& injectorOptions) :
|
||||||
_sound(sound),
|
_sound(sound),
|
||||||
_options(injectorOptions)
|
_options(injectorOptions)
|
||||||
{
|
{
|
||||||
|
@ -34,9 +34,9 @@ void AudioInjector::injectAudio() {
|
||||||
// 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 (_options.loopbackAudioInterface) {
|
if (_options.getLoopbackAudioInterface()) {
|
||||||
// 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(_options.loopbackAudioInterface, "handleAudioByteArray",
|
QMetaObject::invokeMethod(_options.getLoopbackAudioInterface(), "handleAudioByteArray",
|
||||||
Qt::AutoConnection,
|
Qt::AutoConnection,
|
||||||
Q_ARG(QByteArray, soundByteArray));
|
Q_ARG(QByteArray, soundByteArray));
|
||||||
|
|
||||||
|
@ -63,16 +63,17 @@ void AudioInjector::injectAudio() {
|
||||||
currentPacketPosition += rfcStreamUUID.size();
|
currentPacketPosition += rfcStreamUUID.size();
|
||||||
|
|
||||||
// pack the flag for loopback
|
// pack the flag for loopback
|
||||||
memcpy(currentPacketPosition, &_options.shouldLoopback, sizeof(_options.shouldLoopback));
|
bool loopbackFlag = _options.shouldLoopback();
|
||||||
currentPacketPosition += sizeof(_options.shouldLoopback);
|
memcpy(currentPacketPosition, &loopbackFlag, sizeof(loopbackFlag));
|
||||||
|
currentPacketPosition += sizeof(loopbackFlag);
|
||||||
|
|
||||||
// pack the position for injected audio
|
// pack the position for injected audio
|
||||||
memcpy(currentPacketPosition, &_options.position, sizeof(_options.position));
|
memcpy(currentPacketPosition, &_options.getPosition(), sizeof(_options.getPosition()));
|
||||||
currentPacketPosition += sizeof(_options.position);
|
currentPacketPosition += sizeof(_options.getPosition());
|
||||||
|
|
||||||
// pack our orientation for injected audio
|
// pack our orientation for injected audio
|
||||||
memcpy(currentPacketPosition, &_options.orientation, sizeof(_options.orientation));
|
memcpy(currentPacketPosition, &_options.getOrientation(), sizeof(_options.getOrientation()));
|
||||||
currentPacketPosition += sizeof(_options.orientation);
|
currentPacketPosition += sizeof(_options.getOrientation());
|
||||||
|
|
||||||
// pack zero for radius
|
// pack zero for radius
|
||||||
float radius = 0;
|
float radius = 0;
|
||||||
|
@ -80,7 +81,7 @@ void AudioInjector::injectAudio() {
|
||||||
currentPacketPosition += sizeof(radius);
|
currentPacketPosition += sizeof(radius);
|
||||||
|
|
||||||
// pack 255 for attenuation byte
|
// pack 255 for attenuation byte
|
||||||
uchar volume = MAX_INJECTOR_VOLUME * _options.volume;
|
uchar volume = MAX_INJECTOR_VOLUME * _options.getVolume();
|
||||||
memcpy(currentPacketPosition, &volume, sizeof(volume));
|
memcpy(currentPacketPosition, &volume, sizeof(volume));
|
||||||
currentPacketPosition += sizeof(volume);
|
currentPacketPosition += sizeof(volume);
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ class AudioInjector : public QObject {
|
||||||
public:
|
public:
|
||||||
friend AudioScriptingInterface;
|
friend AudioScriptingInterface;
|
||||||
private:
|
private:
|
||||||
AudioInjector(Sound* sound, AudioInjectorOptions injectorOptions);
|
AudioInjector(Sound* sound, const AudioInjectorOptions& injectorOptions);
|
||||||
|
|
||||||
Sound* _sound;
|
Sound* _sound;
|
||||||
AudioInjectorOptions _options;
|
AudioInjectorOptions _options;
|
||||||
|
|
|
@ -10,19 +10,19 @@
|
||||||
|
|
||||||
AudioInjectorOptions::AudioInjectorOptions(QObject* parent) :
|
AudioInjectorOptions::AudioInjectorOptions(QObject* parent) :
|
||||||
QObject(parent),
|
QObject(parent),
|
||||||
position(0.0f, 0.0f, 0.0f),
|
_position(0.0f, 0.0f, 0.0f),
|
||||||
volume(1.0f),
|
_volume(1.0f),
|
||||||
orientation(glm::vec3(0.0f, 0.0f, 0.0f)),
|
_orientation(glm::vec3(0.0f, 0.0f, 0.0f)),
|
||||||
shouldLoopback(true),
|
_shouldLoopback(true),
|
||||||
loopbackAudioInterface(NULL)
|
_loopbackAudioInterface(NULL)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioInjectorOptions::AudioInjectorOptions(const AudioInjectorOptions& other) {
|
AudioInjectorOptions::AudioInjectorOptions(const AudioInjectorOptions& other) {
|
||||||
position = other.position;
|
_position = other._position;
|
||||||
volume = other.volume;
|
_volume = other._volume;
|
||||||
orientation = other.orientation;
|
_orientation = other._orientation;
|
||||||
shouldLoopback = other.shouldLoopback;
|
_shouldLoopback = other._shouldLoopback;
|
||||||
loopbackAudioInterface = other.loopbackAudioInterface;
|
_loopbackAudioInterface = other._loopbackAudioInterface;
|
||||||
}
|
}
|
|
@ -14,19 +14,39 @@
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <glm/gtx/quaternion.hpp>
|
#include <glm/gtx/quaternion.hpp>
|
||||||
|
|
||||||
|
#include <RegisteredMetaTypes.h>
|
||||||
|
|
||||||
#include "AbstractAudioInterface.h"
|
#include "AbstractAudioInterface.h"
|
||||||
|
|
||||||
class AudioInjectorOptions : public QObject {
|
class AudioInjectorOptions : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
Q_PROPERTY(glm::vec3 position READ getPosition WRITE setPosition)
|
||||||
public:
|
public:
|
||||||
AudioInjectorOptions(QObject* parent = 0);
|
AudioInjectorOptions(QObject* parent = 0);
|
||||||
AudioInjectorOptions(const AudioInjectorOptions& other);
|
AudioInjectorOptions(const AudioInjectorOptions& other);
|
||||||
|
|
||||||
glm::vec3 position;
|
const glm::vec3& getPosition() const { return _position; }
|
||||||
float volume;
|
void setPosition(const glm::vec3& position) { _position = position; }
|
||||||
glm::quat orientation;
|
|
||||||
bool shouldLoopback;
|
float getVolume() const { return _volume; }
|
||||||
AbstractAudioInterface* loopbackAudioInterface;
|
void setVolume(float volume) { _volume = volume; }
|
||||||
|
|
||||||
|
const glm::quat& getOrientation() const { return _orientation; }
|
||||||
|
void setOrientation(const glm::quat& orientation) { _orientation = orientation; }
|
||||||
|
|
||||||
|
bool shouldLoopback() const { return _shouldLoopback; }
|
||||||
|
void setShouldLoopback(bool shouldLoopback) { _shouldLoopback = shouldLoopback; }
|
||||||
|
|
||||||
|
AbstractAudioInterface* getLoopbackAudioInterface() const { return _loopbackAudioInterface; }
|
||||||
|
void setLoopbackAudioInterface(AbstractAudioInterface* loopbackAudioInterface)
|
||||||
|
{ _loopbackAudioInterface = loopbackAudioInterface; }
|
||||||
|
private:
|
||||||
|
glm::vec3 _position;
|
||||||
|
float _volume;
|
||||||
|
glm::quat _orientation;
|
||||||
|
bool _shouldLoopback;
|
||||||
|
AbstractAudioInterface* _loopbackAudioInterface;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* defined(__hifi__AudioInjectorOptions__) */
|
#endif /* defined(__hifi__AudioInjectorOptions__) */
|
||||||
|
|
|
@ -10,9 +10,9 @@
|
||||||
|
|
||||||
#include "AudioScriptingInterface.h"
|
#include "AudioScriptingInterface.h"
|
||||||
|
|
||||||
void AudioScriptingInterface::playSound(Sound* sound, AudioInjectorOptions injectorOptions) {
|
void AudioScriptingInterface::playSound(Sound* sound, const AudioInjectorOptions* injectorOptions) {
|
||||||
|
|
||||||
AudioInjector* injector = new AudioInjector(sound, injectorOptions);
|
AudioInjector* injector = new AudioInjector(sound, *injectorOptions);
|
||||||
|
|
||||||
QThread* injectorThread = new QThread();
|
QThread* injectorThread = new QThread();
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ const AudioInjectorOptions DEFAULT_INJECTOR_OPTIONS;
|
||||||
class AudioScriptingInterface : public QObject {
|
class AudioScriptingInterface : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public slots:
|
public slots:
|
||||||
static void playSound(Sound* sound, AudioInjectorOptions injectorOptions = DEFAULT_INJECTOR_OPTIONS);
|
static void playSound(Sound* sound, const AudioInjectorOptions* injectorOptions = NULL);
|
||||||
|
|
||||||
};
|
};
|
||||||
#endif /* defined(__hifi__AudioScriptingInterface__) */
|
#endif /* defined(__hifi__AudioScriptingInterface__) */
|
||||||
|
|
|
@ -90,6 +90,8 @@ bool ScriptEngine::setScriptContents(const QString& scriptContents) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Q_SCRIPT_DECLARE_QMETAOBJECT(AudioInjectorOptions, QObject*)
|
||||||
|
|
||||||
void ScriptEngine::run() {
|
void ScriptEngine::run() {
|
||||||
_isRunning = true;
|
_isRunning = true;
|
||||||
QScriptEngine engine;
|
QScriptEngine engine;
|
||||||
|
@ -109,10 +111,14 @@ void ScriptEngine::run() {
|
||||||
QScriptValue particleScripterValue = engine.newQObject(&_particlesScriptingInterface);
|
QScriptValue particleScripterValue = engine.newQObject(&_particlesScriptingInterface);
|
||||||
engine.globalObject().setProperty("Particles", particleScripterValue);
|
engine.globalObject().setProperty("Particles", particleScripterValue);
|
||||||
|
|
||||||
|
|
||||||
QScriptValue soundConstructorValue = engine.newFunction(soundConstructor);
|
QScriptValue soundConstructorValue = engine.newFunction(soundConstructor);
|
||||||
QScriptValue soundMetaObject = engine.newQMetaObject(&Sound::staticMetaObject, soundConstructorValue);
|
QScriptValue soundMetaObject = engine.newQMetaObject(&Sound::staticMetaObject, soundConstructorValue);
|
||||||
engine.globalObject().setProperty("Sound", soundMetaObject);
|
engine.globalObject().setProperty("Sound", soundMetaObject);
|
||||||
|
|
||||||
|
QScriptValue injectionOptionValue = engine.scriptValueFromQMetaObject<AudioInjectorOptions>();
|
||||||
|
engine.globalObject().setProperty("AudioInjectionOptions", injectionOptionValue);
|
||||||
|
|
||||||
QScriptValue audioScriptingInterfaceValue = engine.newQObject(&_audioScriptingInterface);
|
QScriptValue audioScriptingInterfaceValue = engine.newQObject(&_audioScriptingInterface);
|
||||||
engine.globalObject().setProperty("Audio", audioScriptingInterfaceValue);
|
engine.globalObject().setProperty("Audio", audioScriptingInterfaceValue);
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#define hifi_RegisteredMetaTypes_h
|
#define hifi_RegisteredMetaTypes_h
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
#include <QtScript/QScriptEngine>
|
#include <QtScript/QScriptEngine>
|
||||||
|
|
||||||
#include "SharedUtil.h"
|
#include "SharedUtil.h"
|
||||||
|
|
Loading…
Reference in a new issue