mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 11:48:52 +02:00
handle local audio output via AudioInjector directly for control
This commit is contained in:
parent
d0e8c294da
commit
cd3877b584
8 changed files with 53 additions and 8 deletions
|
@ -37,7 +37,8 @@ var panelsCenterShift = Vec3.subtract(panelsCenter, orbCenter);
|
||||||
|
|
||||||
var ORB_SHIFT = { x: 0, y: -1.4, z: -0.8};
|
var ORB_SHIFT = { x: 0, y: -1.4, z: -0.8};
|
||||||
|
|
||||||
var HELMET_ATTACHMENT_URL = "https://hifi-public.s3.amazonaws.com/models/attachments/IronManMaskOnly.fbx"
|
var HELMET_ATTACHMENT_URL = HIFI_PUBLIC_BUCKET + "models/attachments/IronManMaskOnly.fbx"
|
||||||
|
var droneSound = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Lobby/drone.raw")
|
||||||
|
|
||||||
function reticlePosition() {
|
function reticlePosition() {
|
||||||
var RETICLE_DISTANCE = 1;
|
var RETICLE_DISTANCE = 1;
|
||||||
|
@ -87,6 +88,9 @@ function drawLobby() {
|
||||||
|
|
||||||
// add an attachment on this avatar so other people see them in the lobby
|
// add an attachment on this avatar so other people see them in the lobby
|
||||||
MyAvatar.attach(HELMET_ATTACHMENT_URL, "Neck", {x: 0, y: 0, z: 0}, Quat.fromPitchYawRollDegrees(0, 0, 0), 1.15);
|
MyAvatar.attach(HELMET_ATTACHMENT_URL, "Neck", {x: 0, y: 0, z: 0}, Quat.fromPitchYawRollDegrees(0, 0, 0), 1.15);
|
||||||
|
|
||||||
|
// start the drone sound
|
||||||
|
Audio.playSound(droneSound, { stereo: true, localOnly: true });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1334,10 +1334,13 @@ void Audio::startDrumSound(float volume, float frequency, float duration, float
|
||||||
_drumSoundSample = 0;
|
_drumSoundSample = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
QAudioOutput* Audio::newLocalOutputInterface(bool isStereo) {
|
QIODevice* Audio::newLocalOutputDevice(bool isStereo) {
|
||||||
QAudioFormat localFormat = _outputFormat;
|
QAudioFormat localFormat = _desiredOutputFormat;
|
||||||
localFormat.setChannelCount(isStereo ? 2 : 1);
|
localFormat.setChannelCount(isStereo ? 2 : 1);
|
||||||
return new QAudioOutput(getNamedAudioDeviceForMode(QAudio::AudioOutput, _outputAudioDeviceName), localFormat);
|
QAudioOutput* localOutput = new QAudioOutput(getNamedAudioDeviceForMode(QAudio::AudioOutput, _outputAudioDeviceName),
|
||||||
|
localFormat);
|
||||||
|
|
||||||
|
return localOutput->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Audio::renderToolBox(int x, int y, bool boxed) {
|
void Audio::renderToolBox(int x, int y, bool boxed) {
|
||||||
|
|
|
@ -155,7 +155,7 @@ public slots:
|
||||||
void selectAudioFilterBassCut();
|
void selectAudioFilterBassCut();
|
||||||
void selectAudioFilterSmiley();
|
void selectAudioFilterSmiley();
|
||||||
|
|
||||||
virtual QAudioOutput* newLocalOutputInterface(bool isStereo);
|
virtual QIODevice* newLocalOutputDevice(bool isStereo);
|
||||||
|
|
||||||
void sendDownstreamAudioStatsPacket();
|
void sendDownstreamAudioStatsPacket();
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ public:
|
||||||
virtual void startCollisionSound(float magnitude, float frequency, float noise, float duration, bool flashScreen) = 0;
|
virtual void startCollisionSound(float magnitude, float frequency, float noise, float duration, bool flashScreen) = 0;
|
||||||
virtual void startDrumSound(float volume, float frequency, float duration, float decay) = 0;
|
virtual void startDrumSound(float volume, float frequency, float duration, float decay) = 0;
|
||||||
public slots:
|
public slots:
|
||||||
virtual QAudioOutput* newLocalOutputInterface(bool isStereo) = 0;
|
virtual QIODevice* newLocalOutputDevice(bool isStereo) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(AbstractAudioInterface*)
|
Q_DECLARE_METATYPE(AbstractAudioInterface*)
|
||||||
|
|
|
@ -58,9 +58,37 @@ float AudioInjector::getLoudness() {
|
||||||
return _loudness;
|
return _loudness;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AudioInjector::injectAudio() {
|
||||||
|
if (_options.localOnly) {
|
||||||
|
injectLocally();
|
||||||
|
} else {
|
||||||
|
injectToMixer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AudioInjector::injectLocally() {
|
||||||
|
if (_localAudioInterface) {
|
||||||
|
|
||||||
|
QIODevice* localBuffer = NULL;
|
||||||
|
|
||||||
|
QMetaObject::invokeMethod(_localAudioInterface, "newLocalOutputDevice", Qt::BlockingQueuedConnection,
|
||||||
|
Q_RETURN_ARG(QIODevice*, localBuffer),
|
||||||
|
Q_ARG(bool, _options.stereo));
|
||||||
|
|
||||||
|
if (localBuffer) {
|
||||||
|
// immediately write the byte array to the local device
|
||||||
|
localBuffer->write(_sound->getByteArray());
|
||||||
|
} else {
|
||||||
|
qDebug() << "AudioInject::injectLocally did not get a valid QIODevice from _localAudioInterface";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
qDebug() << "AudioInject::injectLocally cannot inject locally with no local audio interface present.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const uchar MAX_INJECTOR_VOLUME = 0xFF;
|
const uchar MAX_INJECTOR_VOLUME = 0xFF;
|
||||||
|
|
||||||
void AudioInjector::injectAudio() {
|
void AudioInjector::injectToMixer() {
|
||||||
QByteArray soundByteArray = _sound->getByteArray();
|
QByteArray soundByteArray = _sound->getByteArray();
|
||||||
|
|
||||||
if (_currentSendPosition < 0 ||
|
if (_currentSendPosition < 0 ||
|
||||||
|
|
|
@ -43,6 +43,9 @@ public slots:
|
||||||
signals:
|
signals:
|
||||||
void finished();
|
void finished();
|
||||||
private:
|
private:
|
||||||
|
void injectToMixer();
|
||||||
|
void injectLocally();
|
||||||
|
|
||||||
Sound* _sound;
|
Sound* _sound;
|
||||||
AudioInjectorOptions _options;
|
AudioInjectorOptions _options;
|
||||||
bool _shouldStop;
|
bool _shouldStop;
|
||||||
|
|
|
@ -19,7 +19,8 @@ AudioInjectorOptions::AudioInjectorOptions() :
|
||||||
loop(false),
|
loop(false),
|
||||||
orientation(glm::vec3(0.0f, 0.0f, 0.0f)),
|
orientation(glm::vec3(0.0f, 0.0f, 0.0f)),
|
||||||
stereo(false),
|
stereo(false),
|
||||||
ignorePenumbra(false)
|
ignorePenumbra(false),
|
||||||
|
localOnly(false)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -32,6 +33,7 @@ QScriptValue injectorOptionsToScriptValue(QScriptEngine* engine, const AudioInje
|
||||||
obj.setProperty("orientation", quatToScriptValue(engine, injectorOptions.orientation));
|
obj.setProperty("orientation", quatToScriptValue(engine, injectorOptions.orientation));
|
||||||
obj.setProperty("stereo", injectorOptions.stereo);
|
obj.setProperty("stereo", injectorOptions.stereo);
|
||||||
obj.setProperty("ignorePenumbra", injectorOptions.ignorePenumbra);
|
obj.setProperty("ignorePenumbra", injectorOptions.ignorePenumbra);
|
||||||
|
obj.setProperty("localOnly", injectorOptions.localOnly);
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,4 +61,8 @@ void injectorOptionsFromScriptValue(const QScriptValue& object, AudioInjectorOpt
|
||||||
if (object.property("ignorePenumbra").isValid()) {
|
if (object.property("ignorePenumbra").isValid()) {
|
||||||
injectorOptions.ignorePenumbra = object.property("ignorePenumbra").toBool();
|
injectorOptions.ignorePenumbra = object.property("ignorePenumbra").toBool();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (object.property("localOnly").isValid()) {
|
||||||
|
injectorOptions.localOnly = object.property("localOnly").toBool();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -26,6 +26,7 @@ public:
|
||||||
glm::quat orientation;
|
glm::quat orientation;
|
||||||
bool stereo;
|
bool stereo;
|
||||||
bool ignorePenumbra;
|
bool ignorePenumbra;
|
||||||
|
bool localOnly;
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(AudioInjectorOptions);
|
Q_DECLARE_METATYPE(AudioInjectorOptions);
|
||||||
|
|
Loading…
Reference in a new issue