mirror of
https://github.com/lubosz/overte.git
synced 2025-04-23 16:33:56 +02:00
changes to allow AudioInjectorOptions to operate as a hash from js
This commit is contained in:
parent
d083e75d2d
commit
a8681cd5b6
7 changed files with 85 additions and 89 deletions
|
@ -75,7 +75,7 @@ void AudioInjector::injectAudio() {
|
|||
packetStream << QUuid::createUuid();
|
||||
|
||||
// pack the stereo/mono type of the stream
|
||||
packetStream << _options.isStereo();
|
||||
packetStream << _options.stereo;
|
||||
|
||||
// pack the flag for loopback
|
||||
uchar loopbackFlag = (uchar) true;
|
||||
|
@ -83,13 +83,13 @@ void AudioInjector::injectAudio() {
|
|||
|
||||
// pack the position for injected audio
|
||||
int positionOptionOffset = injectAudioPacket.size();
|
||||
packetStream.writeRawData(reinterpret_cast<const char*>(&_options.getPosition()),
|
||||
sizeof(_options.getPosition()));
|
||||
packetStream.writeRawData(reinterpret_cast<const char*>(&_options.position),
|
||||
sizeof(_options.position));
|
||||
|
||||
// pack our orientation for injected audio
|
||||
int orientationOptionOffset = injectAudioPacket.size();
|
||||
packetStream.writeRawData(reinterpret_cast<const char*>(&_options.getOrientation()),
|
||||
sizeof(_options.getOrientation()));
|
||||
packetStream.writeRawData(reinterpret_cast<const char*>(&_options.orientation),
|
||||
sizeof(_options.orientation));
|
||||
|
||||
// pack zero for radius
|
||||
float radius = 0;
|
||||
|
@ -97,23 +97,23 @@ void AudioInjector::injectAudio() {
|
|||
|
||||
// pack 255 for attenuation byte
|
||||
int volumeOptionOffset = injectAudioPacket.size();
|
||||
quint8 volume = MAX_INJECTOR_VOLUME * _options.getVolume();
|
||||
quint8 volume = MAX_INJECTOR_VOLUME * _options.volume;
|
||||
packetStream << volume;
|
||||
|
||||
packetStream << _options.ignorePenumbra();
|
||||
packetStream << _options.ignorePenumbra;
|
||||
|
||||
QElapsedTimer timer;
|
||||
timer.start();
|
||||
int nextFrame = 0;
|
||||
|
||||
int numPreAudioDataBytes = injectAudioPacket.size();
|
||||
bool shouldLoop = _options.getLoop();
|
||||
bool shouldLoop = _options.loop;
|
||||
|
||||
// loop to send off our audio in NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL byte chunks
|
||||
quint16 outgoingInjectedAudioSequenceNumber = 0;
|
||||
while (_currentSendPosition < soundByteArray.size() && !_shouldStop) {
|
||||
|
||||
int bytesToCopy = std::min(((_options.isStereo()) ? 2 : 1) * NETWORK_BUFFER_LENGTH_BYTES_PER_CHANNEL,
|
||||
int bytesToCopy = std::min(((_options.stereo) ? 2 : 1) * NETWORK_BUFFER_LENGTH_BYTES_PER_CHANNEL,
|
||||
soundByteArray.size() - _currentSendPosition);
|
||||
|
||||
// Measure the loudness of this frame
|
||||
|
@ -125,12 +125,12 @@ void AudioInjector::injectAudio() {
|
|||
_loudness /= (float)(bytesToCopy / sizeof(int16_t));
|
||||
|
||||
memcpy(injectAudioPacket.data() + positionOptionOffset,
|
||||
&_options.getPosition(),
|
||||
sizeof(_options.getPosition()));
|
||||
&_options.position,
|
||||
sizeof(_options.position));
|
||||
memcpy(injectAudioPacket.data() + orientationOptionOffset,
|
||||
&_options.getOrientation(),
|
||||
sizeof(_options.getOrientation()));
|
||||
volume = MAX_INJECTOR_VOLUME * _options.getVolume();
|
||||
&_options.orientation,
|
||||
sizeof(_options.orientation));
|
||||
volume = MAX_INJECTOR_VOLUME * _options.volume;
|
||||
memcpy(injectAudioPacket.data() + volumeOptionOffset, &volume, sizeof(volume));
|
||||
|
||||
// resize the QByteArray to the right size
|
||||
|
|
|
@ -9,33 +9,54 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include <RegisteredMetaTypes.h>
|
||||
|
||||
#include "AudioInjectorOptions.h"
|
||||
|
||||
AudioInjectorOptions::AudioInjectorOptions(QObject* parent) :
|
||||
QObject(parent),
|
||||
_position(0.0f, 0.0f, 0.0f),
|
||||
_volume(1.0f),
|
||||
_loop(false),
|
||||
_orientation(glm::vec3(0.0f, 0.0f, 0.0f)),
|
||||
_isStereo(false),
|
||||
_ignorePenumbra(false)
|
||||
AudioInjectorOptions::AudioInjectorOptions() :
|
||||
position(0.0f, 0.0f, 0.0f),
|
||||
volume(1.0f),
|
||||
loop(false),
|
||||
orientation(glm::vec3(0.0f, 0.0f, 0.0f)),
|
||||
stereo(false),
|
||||
ignorePenumbra(false)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
AudioInjectorOptions::AudioInjectorOptions(const AudioInjectorOptions& other) {
|
||||
_position = other._position;
|
||||
_volume = other._volume;
|
||||
_loop = other._loop;
|
||||
_orientation = other._orientation;
|
||||
_isStereo = other._isStereo;
|
||||
_ignorePenumbra = other._ignorePenumbra;
|
||||
QScriptValue injectorOptionsToScriptValue(QScriptEngine* engine, const AudioInjectorOptions& injectorOptions) {
|
||||
QScriptValue obj = engine->newObject();
|
||||
obj.setProperty("position", vec3toScriptValue(engine, injectorOptions.position));
|
||||
obj.setProperty("volume", injectorOptions.volume);
|
||||
obj.setProperty("loop", injectorOptions.loop);
|
||||
obj.setProperty("orientation", quatToScriptValue(engine, injectorOptions.orientation));
|
||||
obj.setProperty("stereo", injectorOptions.stereo);
|
||||
obj.setProperty("ignorePenumbra", injectorOptions.ignorePenumbra);
|
||||
return obj;
|
||||
}
|
||||
|
||||
void AudioInjectorOptions::operator=(const AudioInjectorOptions& other) {
|
||||
_position = other._position;
|
||||
_volume = other._volume;
|
||||
_loop = other._loop;
|
||||
_orientation = other._orientation;
|
||||
_isStereo = other._isStereo;
|
||||
_ignorePenumbra = other._ignorePenumbra;
|
||||
}
|
||||
void injectorOptionsFromScriptValue(const QScriptValue& object, AudioInjectorOptions& injectorOptions) {
|
||||
if (object.property("position").isValid()) {
|
||||
vec3FromScriptValue(object.property("position"), injectorOptions.position);
|
||||
}
|
||||
|
||||
if (object.property("volume").isValid()) {
|
||||
injectorOptions.volume = object.property("volume").toNumber();
|
||||
}
|
||||
|
||||
if (object.property("loop").isValid()) {
|
||||
injectorOptions.loop = object.property("loop").toBool();
|
||||
}
|
||||
|
||||
if (object.property("orientation").isValid()) {
|
||||
quatFromScriptValue(object.property("orientation"), injectorOptions.orientation);
|
||||
}
|
||||
|
||||
if (object.property("stereo").isValid()) {
|
||||
injectorOptions.stereo = object.property("stereo").toBool();
|
||||
}
|
||||
|
||||
if (object.property("ignorePenumbra").isValid()) {
|
||||
injectorOptions.ignorePenumbra = object.property("ignorePenumbra").toBool();
|
||||
}
|
||||
}
|
|
@ -12,54 +12,25 @@
|
|||
#ifndef hifi_AudioInjectorOptions_h
|
||||
#define hifi_AudioInjectorOptions_h
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtScript/qscriptengine.h>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
|
||||
#include <RegisteredMetaTypes.h>
|
||||
|
||||
class AudioInjectorOptions : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(glm::quat orientation READ getOrientation WRITE setOrientation)
|
||||
Q_PROPERTY(glm::vec3 position READ getPosition WRITE setPosition)
|
||||
Q_PROPERTY(float volume READ getVolume WRITE setVolume)
|
||||
Q_PROPERTY(bool loop READ getLoop WRITE setLoop)
|
||||
Q_PROPERTY(bool isStereo READ isStereo WRITE setIsStereo)
|
||||
Q_PROPERTY(bool ignorePenumbra READ ignorePenumbra WRITE setIgnorePenumbra)
|
||||
class AudioInjectorOptions {
|
||||
public:
|
||||
AudioInjectorOptions(QObject* parent = 0);
|
||||
AudioInjectorOptions(const AudioInjectorOptions& other);
|
||||
void operator=(const AudioInjectorOptions& other);
|
||||
|
||||
const glm::vec3& getPosition() const { return _position; }
|
||||
void setPosition(const glm::vec3& position) { _position = position; }
|
||||
|
||||
float getVolume() const { return _volume; }
|
||||
void setVolume(float volume) { _volume = volume; }
|
||||
|
||||
bool getLoop() const { return _loop; }
|
||||
void setLoop(bool loop) { _loop = loop; }
|
||||
|
||||
const glm::quat& getOrientation() const { return _orientation; }
|
||||
void setOrientation(const glm::quat& orientation) { _orientation = orientation; }
|
||||
|
||||
const bool isStereo() const { return _isStereo; }
|
||||
void setIsStereo(const bool isStereo) { _isStereo = isStereo; }
|
||||
|
||||
const bool ignorePenumbra() const {return _ignorePenumbra; }
|
||||
void setIgnorePenumbra(bool ignorePenumbra) { _ignorePenumbra = ignorePenumbra; }
|
||||
|
||||
private:
|
||||
glm::vec3 _position;
|
||||
float _volume;
|
||||
bool _loop;
|
||||
glm::quat _orientation;
|
||||
bool _isStereo;
|
||||
bool _ignorePenumbra;
|
||||
AudioInjectorOptions();
|
||||
glm::vec3 position;
|
||||
float volume;
|
||||
bool loop;
|
||||
glm::quat orientation;
|
||||
bool stereo;
|
||||
bool ignorePenumbra;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(AudioInjectorOptions)
|
||||
Q_DECLARE_METATYPE(AudioInjectorOptions);
|
||||
|
||||
QScriptValue injectorOptionsToScriptValue(QScriptEngine* engine, const AudioInjectorOptions& injectorOptions);
|
||||
void injectorOptionsFromScriptValue(const QScriptValue& object, AudioInjectorOptions& injectorOptions);
|
||||
|
||||
#endif // hifi_AudioInjectorOptions_h
|
||||
|
|
|
@ -11,6 +11,10 @@
|
|||
|
||||
#include "AudioScriptingInterface.h"
|
||||
|
||||
void registerAudioMetaTypes(QScriptEngine* engine) {
|
||||
qScriptRegisterMetaType(engine, injectorOptionsToScriptValue, injectorOptionsFromScriptValue);
|
||||
}
|
||||
|
||||
AudioScriptingInterface& AudioScriptingInterface::getInstance() {
|
||||
static AudioScriptingInterface staticInstance;
|
||||
return staticInstance;
|
||||
|
@ -40,7 +44,7 @@ void AudioScriptingInterface::stopAllInjectors() {
|
|||
AudioInjector* AudioScriptingInterface::playSound(Sound* sound, const AudioInjectorOptions* injectorOptions) {
|
||||
|
||||
if (sound->isStereo()) {
|
||||
const_cast<AudioInjectorOptions*>(injectorOptions)->setIsStereo(true);
|
||||
const_cast<AudioInjectorOptions*>(injectorOptions)->stereo = true;
|
||||
}
|
||||
AudioInjector* injector = new AudioInjector(sound, *injectorOptions);
|
||||
|
||||
|
|
|
@ -44,4 +44,7 @@ private:
|
|||
QList< QPointer<AudioInjector> > _activeInjectors;
|
||||
AbstractAudioInterface* _localLoopbackInterface;
|
||||
};
|
||||
|
||||
void registerAudioMetaTypes(QScriptEngine* engine);
|
||||
|
||||
#endif // hifi_AudioScriptingInterface_h
|
||||
|
|
|
@ -166,8 +166,8 @@ void Player::pausePlayer() {
|
|||
|
||||
void Player::setupAudioThread() {
|
||||
_audioThread = new QThread();
|
||||
_options.setPosition(_avatar->getPosition());
|
||||
_options.setOrientation(_avatar->getOrientation());
|
||||
_options.position = _avatar->getPosition();
|
||||
_options.orientation = _avatar->getOrientation();
|
||||
_injector.reset(new AudioInjector(_recording->getAudio(), _options), &QObject::deleteLater);
|
||||
_injector->moveToThread(_audioThread);
|
||||
_audioThread->start();
|
||||
|
@ -292,8 +292,8 @@ void Player::play() {
|
|||
qDebug() << "WARNING: Player couldn't find head data.";
|
||||
}
|
||||
|
||||
_options.setPosition(_avatar->getPosition());
|
||||
_options.setOrientation(_avatar->getOrientation());
|
||||
_options.position = _avatar->getPosition();
|
||||
_options.orientation = _avatar->getOrientation();
|
||||
_injector->setOptions(_options);
|
||||
}
|
||||
|
||||
|
@ -360,7 +360,7 @@ void Player::setCurrentTime(unsigned int currentTime) {
|
|||
}
|
||||
|
||||
void Player::setVolume(float volume) {
|
||||
_options.setVolume(volume);
|
||||
_options.volume = volume;
|
||||
if (_injector) {
|
||||
_injector->setOptions(_options);
|
||||
}
|
||||
|
|
|
@ -234,7 +234,6 @@ bool ScriptEngine::setScriptContents(const QString& scriptContents, const QStrin
|
|||
return true;
|
||||
}
|
||||
|
||||
Q_SCRIPT_DECLARE_QMETAOBJECT(AudioInjectorOptions, QObject*)
|
||||
Q_SCRIPT_DECLARE_QMETAOBJECT(LocalVoxels, QString)
|
||||
|
||||
void ScriptEngine::init() {
|
||||
|
@ -254,6 +253,7 @@ void ScriptEngine::init() {
|
|||
registerMenuItemProperties(this);
|
||||
registerAnimationTypes(this);
|
||||
registerAvatarTypes(this);
|
||||
registerAudioMetaTypes(this);
|
||||
Bitstream::registerTypes(this);
|
||||
|
||||
qScriptRegisterMetaType(this, EntityItemPropertiesToScriptValue, EntityItemPropertiesFromScriptValue);
|
||||
|
@ -275,9 +275,6 @@ void ScriptEngine::init() {
|
|||
QScriptValue soundMetaObject = newQMetaObject(&Sound::staticMetaObject, soundConstructorValue);
|
||||
globalObject().setProperty("Sound", soundMetaObject);
|
||||
|
||||
QScriptValue injectionOptionValue = scriptValueFromQMetaObject<AudioInjectorOptions>();
|
||||
globalObject().setProperty("AudioInjectionOptions", injectionOptionValue);
|
||||
|
||||
QScriptValue localVoxelsValue = scriptValueFromQMetaObject<LocalVoxels>();
|
||||
globalObject().setProperty("LocalVoxels", localVoxelsValue);
|
||||
|
||||
|
|
Loading…
Reference in a new issue