mirror of
https://github.com/lubosz/overte.git
synced 2025-04-23 07:43:57 +02:00
add AudioScriptingInterface to expose playSound to JS
This commit is contained in:
parent
845176bbc6
commit
594bd58774
6 changed files with 52 additions and 25 deletions
|
@ -130,8 +130,8 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f
|
|||
injectorOptions.position = targetPosition;
|
||||
injectorOptions.shouldLoopback = false;
|
||||
injectorOptions.loopbackAudioInterface = app->getAudio();
|
||||
|
||||
AudioInjector::threadSound(&_catchSound, injectorOptions);
|
||||
|
||||
AudioScriptingInterface::playSound(&_catchSound, injectorOptions);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -220,7 +220,7 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f
|
|||
injectorOptions.shouldLoopback = false;
|
||||
injectorOptions.loopbackAudioInterface = app->getAudio();
|
||||
|
||||
AudioInjector::threadSound(&_throwSound, injectorOptions);
|
||||
AudioScriptingInterface::playSound(&_throwSound, injectorOptions);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include <SharedUtil.h>
|
||||
|
||||
#include <AvatarData.h>
|
||||
#include <AudioInjector.h>
|
||||
#include <AudioScriptingInterface.h>
|
||||
#include <HandData.h>
|
||||
#include <ParticleEditHandle.h>
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
int abstractAudioPointerMeta = qRegisterMetaType<AbstractAudioInterface*>("AbstractAudioInterface*");
|
||||
|
||||
AudioInjector::AudioInjector(Sound* sound, AudioInjectorOptions injectorOptions) :
|
||||
_thread(NULL),
|
||||
_sound(sound),
|
||||
_volume(injectorOptions.volume),
|
||||
_shouldLoopback(injectorOptions.shouldLoopback),
|
||||
|
@ -27,24 +26,7 @@ AudioInjector::AudioInjector(Sound* sound, AudioInjectorOptions injectorOptions)
|
|||
_orientation(injectorOptions.orientation),
|
||||
_loopbackAudioInterface(injectorOptions.loopbackAudioInterface)
|
||||
{
|
||||
_thread = new QThread();
|
||||
|
||||
// we want to live on our own thread
|
||||
moveToThread(_thread);
|
||||
}
|
||||
|
||||
void AudioInjector::threadSound(Sound* sound, AudioInjectorOptions injectorOptions) {
|
||||
AudioInjector* injector = new AudioInjector(sound, injectorOptions);
|
||||
|
||||
// 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, SLOT(deleteLater()));
|
||||
connect(injector, SIGNAL(finished()), injector->_thread, SLOT(quit()));
|
||||
connect(injector->_thread, SIGNAL(finished()), injector->_thread, SLOT(deleteLater()));
|
||||
|
||||
injector->_thread->start();
|
||||
}
|
||||
|
||||
const uchar MAX_INJECTOR_VOLUME = 0xFF;
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "Sound.h"
|
||||
|
||||
class AbstractAudioInterface;
|
||||
class AudioScriptingInterface;
|
||||
|
||||
struct AudioInjectorOptions {
|
||||
AudioInjectorOptions() : position(glm::vec3(0.0f, 0.0f, 0.0f)),
|
||||
|
@ -36,11 +37,10 @@ struct AudioInjectorOptions {
|
|||
class AudioInjector : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
static void threadSound(Sound* sound, AudioInjectorOptions injectorOptions = AudioInjectorOptions());
|
||||
friend AudioScriptingInterface;
|
||||
private:
|
||||
AudioInjector(Sound* sound, AudioInjectorOptions injectorOptions);
|
||||
|
||||
QThread* _thread;
|
||||
|
||||
Sound* _sound;
|
||||
float _volume;
|
||||
uchar _shouldLoopback;
|
||||
|
|
25
libraries/audio/src/AudioScriptingInterface.cpp
Normal file
25
libraries/audio/src/AudioScriptingInterface.cpp
Normal file
|
@ -0,0 +1,25 @@
|
|||
//
|
||||
// AudioScriptingInterface.cpp
|
||||
// hifi
|
||||
//
|
||||
// Created by Stephen Birarda on 1/2/2014.
|
||||
// Copyright (c) 2013 HighFidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#include "AudioScriptingInterface.h"
|
||||
|
||||
void AudioScriptingInterface::playSound(Sound* sound, AudioInjectorOptions injectorOptions) {
|
||||
AudioInjector* injector = new AudioInjector(sound, injectorOptions);
|
||||
|
||||
QThread* injectorThread = new QThread();
|
||||
|
||||
// start injecting when the injector thread starts
|
||||
connect(injectorThread, 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, SLOT(deleteLater()));
|
||||
connect(injector, SIGNAL(finished()), injectorThread, SLOT(quit()));
|
||||
connect(injectorThread, SIGNAL(finished()), injectorThread, SLOT(deleteLater()));
|
||||
|
||||
injectorThread->start();
|
||||
}
|
20
libraries/audio/src/AudioScriptingInterface.h
Normal file
20
libraries/audio/src/AudioScriptingInterface.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
//
|
||||
// AudioScriptingInterface.h
|
||||
// hifi
|
||||
//
|
||||
// Created by Stephen Birarda on 1/2/2014.
|
||||
// Copyright (c) 2013 HighFidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef __hifi__AudioScriptingInterface__
|
||||
#define __hifi__AudioScriptingInterface__
|
||||
|
||||
#include "AudioInjector.h"
|
||||
#include "Sound.h"
|
||||
|
||||
class AudioScriptingInterface : public QObject {
|
||||
public slots:
|
||||
static void playSound(Sound* sound, AudioInjectorOptions injectorOptions = AudioInjectorOptions());
|
||||
|
||||
};
|
||||
#endif /* defined(__hifi__AudioScriptingInterface__) */
|
Loading…
Reference in a new issue