mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 04:44:11 +02:00
groundwork for better locally looped audio
This commit is contained in:
parent
dbc1ba7925
commit
d083e75d2d
5 changed files with 7 additions and 31 deletions
|
@ -1334,22 +1334,10 @@ void Audio::startDrumSound(float volume, float frequency, float duration, float
|
|||
_drumSoundSample = 0;
|
||||
}
|
||||
|
||||
void Audio::handleAudioByteArray(const QByteArray& audioByteArray, const AudioInjectorOptions& injectorOptions) {
|
||||
if (audioByteArray.size() > 0) {
|
||||
QAudioFormat localFormat = _outputFormat;
|
||||
|
||||
if (!injectorOptions.isStereo()) {
|
||||
localFormat.setChannelCount(1);
|
||||
}
|
||||
|
||||
QAudioOutput* localSoundOutput = new QAudioOutput(getNamedAudioDeviceForMode(QAudio::AudioOutput, _outputAudioDeviceName), localFormat, this);
|
||||
|
||||
QIODevice* localIODevice = localSoundOutput->start();
|
||||
qDebug() << "Writing" << audioByteArray.size() << "to" << localIODevice;
|
||||
localIODevice->write(audioByteArray);
|
||||
} else {
|
||||
qDebug() << "Audio::handleAudioByteArray called with an empty byte array. Sound is likely still downloading.";
|
||||
}
|
||||
QAudioOutput* Audio::newLocalOutputInterface(bool isStereo) {
|
||||
QAudioFormat localFormat = _outputFormat;
|
||||
localFormat.setChannelCount(isStereo ? 2 : 1);
|
||||
return new QAudioOutput(getNamedAudioDeviceForMode(QAudio::AudioOutput, _outputAudioDeviceName), localFormat);
|
||||
}
|
||||
|
||||
void Audio::renderToolBox(int x, int y, bool boxed) {
|
||||
|
|
|
@ -155,7 +155,7 @@ public slots:
|
|||
void selectAudioFilterBassCut();
|
||||
void selectAudioFilterSmiley();
|
||||
|
||||
virtual void handleAudioByteArray(const QByteArray& audioByteArray, const AudioInjectorOptions& options);
|
||||
virtual QAudioOutput* newLocalOutputInterface(bool isStereo);
|
||||
|
||||
void sendDownstreamAudioStatsPacket();
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#define hifi_AbstractAudioInterface_h
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtMultimedia/qaudiooutput.h>
|
||||
|
||||
#include "AudioInjectorOptions.h"
|
||||
|
||||
|
@ -24,7 +25,7 @@ public:
|
|||
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;
|
||||
public slots:
|
||||
virtual void handleAudioByteArray(const QByteArray& audioByteArray, const AudioInjectorOptions& options) = 0;
|
||||
virtual QAudioOutput* newLocalOutputInterface(bool isStereo) = 0;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(AbstractAudioInterface*)
|
||||
|
|
|
@ -37,18 +37,6 @@ void AudioScriptingInterface::stopAllInjectors() {
|
|||
}
|
||||
}
|
||||
|
||||
void AudioScriptingInterface::playLocalSound(Sound* sound, const AudioInjectorOptions* injectorOptions) {
|
||||
if (sound->isStereo()) {
|
||||
const_cast<AudioInjectorOptions*>(injectorOptions)->setIsStereo(true);
|
||||
}
|
||||
|
||||
// assume that localAudioInterface could be on a separate thread, use Qt::AutoConnection to handle properly
|
||||
QMetaObject::invokeMethod(_localLoopbackInterface, "handleAudioByteArray",
|
||||
Qt::AutoConnection,
|
||||
Q_ARG(QByteArray, sound->getByteArray()),
|
||||
Q_ARG(const AudioInjectorOptions&, *injectorOptions));
|
||||
}
|
||||
|
||||
AudioInjector* AudioScriptingInterface::playSound(Sound* sound, const AudioInjectorOptions* injectorOptions) {
|
||||
|
||||
if (sound->isStereo()) {
|
||||
|
|
|
@ -32,7 +32,6 @@ public slots:
|
|||
|
||||
static float getLoudness(AudioInjector* injector);
|
||||
|
||||
void playLocalSound(Sound *sound, const AudioInjectorOptions* injectorOptions = NULL);
|
||||
AudioInjector* playSound(Sound* sound, const AudioInjectorOptions* injectorOptions = NULL);
|
||||
|
||||
void stopInjector(AudioInjector* injector);
|
||||
|
|
Loading…
Reference in a new issue