make Audio class use DependencyManager

This commit is contained in:
Stephen Birarda 2014-12-16 12:31:01 -08:00
parent fba256692f
commit 6fd55e6f42
11 changed files with 75 additions and 74 deletions

View file

@ -177,7 +177,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
_touchAvgY(0.0f),
_isTouchPressed(false),
_mousePressed(false),
_audio(),
_enableProcessVoxelsThread(true),
_octreeProcessor(),
_voxelHideShowThread(&_voxels),
@ -249,9 +248,10 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
// put the audio processing on a separate thread
QThread* audioThread = new QThread(this);
_audio.moveToThread(audioThread);
connect(audioThread, SIGNAL(started()), &_audio, SLOT(start()));
Audio* audioIO = DependencyManager::get<Audio>();
audioIO->moveToThread(audioThread);
connect(audioThread, &QThread::started, audioIO, &Audio::start);
audioThread->start();
@ -423,7 +423,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
_trayIcon->show();
// set the local loopback interface for local sounds from audio scripts
AudioScriptingInterface::getInstance().setLocalAudioInterface(&_audio);
AudioScriptingInterface::getInstance().setLocalAudioInterface(audioIO);
#ifdef HAVE_RTMIDI
// setup the MIDIManager
@ -464,13 +464,15 @@ Application::~Application() {
// kill any audio injectors that are still around
AudioScriptingInterface::getInstance().stopAllInjectors();
Audio* audioIO = DependencyManager::get<Audio>();
// stop the audio process
QMetaObject::invokeMethod(&_audio, "stop");
QMetaObject::invokeMethod(audioIO, "stop");
// ask the audio thread to quit and wait until it is done
_audio.thread()->quit();
_audio.thread()->wait();
audioIO->thread()->quit();
audioIO->thread()->wait();
_octreeProcessor.terminate();
_voxelHideShowThread.terminate();
@ -1293,10 +1295,11 @@ void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) {
_mousePressed = true;
if (mouseOnScreen()) {
if (_audio.mousePressEvent(getMouseX(), getMouseY())) {
// stop propagation
return;
}
// TODO: MOVE THE AUDIO CONTROLS TO SEP OBJECT
// if (_audio.mousePressEvent(getMouseX(), getMouseY())) {
// // stop propagation
// return;
// }
if (_rearMirrorTools->mousePressEvent(getMouseX(), getMouseY())) {
// stop propagation
@ -1948,7 +1951,6 @@ void Application::init() {
_lastTimeUpdated.start();
Menu::getInstance()->loadSettings();
_audio.setReceivedAudioStreamSettings(Menu::getInstance()->getReceivedAudioStreamSettings());
// when --url in command line, teleport to location
const QString HIFI_URL_COMMAND_LINE_KEY = "--url";
@ -1991,7 +1993,7 @@ void Application::init() {
_entities.setViewFrustum(getViewFrustum());
EntityTree* entityTree = _entities.getTree();
_entityCollisionSystem.init(&_entityEditSender, entityTree, _voxels.getTree(), &_audio, &_avatarManager);
_entityCollisionSystem.init(&_entityEditSender, entityTree, _voxels.getTree(), &_avatarManager);
entityTree->setSimulation(&_entityCollisionSystem);
// connect the _entityCollisionSystem to our script engine's EntityScriptingInterface
@ -2018,7 +2020,8 @@ void Application::init() {
_metavoxels.init();
_audio.init(_glWidget);
// TODO: MOVE AUDIO CONTROLS TO SEP OBJECT
// _audio.init(_glWidget);
_rearMirrorTools = new RearMirrorTools(_glWidget, _mirrorViewRect, _settings);
@ -2027,9 +2030,6 @@ void Application::init() {
connect(_rearMirrorTools, SIGNAL(shrinkView()), SLOT(shrinkMirrorView()));
connect(_rearMirrorTools, SIGNAL(resetView()), SLOT(resetSensors()));
connect(getAudio(), &Audio::muteToggled, AudioDeviceScriptingInterface::getInstance(),
&AudioDeviceScriptingInterface::muteToggled, Qt::DirectConnection);
// save settings when avatar changes
connect(_myAvatar, &MyAvatar::transformChanged, this, &Application::bumpSettings);
@ -2416,7 +2416,7 @@ void Application::update(float deltaTime) {
if (sinceLastNack > TOO_LONG_SINCE_LAST_SEND_DOWNSTREAM_AUDIO_STATS) {
_lastSendDownstreamAudioStats = now;
QMetaObject::invokeMethod(&_audio, "sendDownstreamAudioStatsPacket", Qt::QueuedConnection);
QMetaObject::invokeMethod(DependencyManager::get<Audio>(), "sendDownstreamAudioStatsPacket", Qt::QueuedConnection);
}
}
}
@ -3566,7 +3566,7 @@ void Application::resetSensors() {
_myAvatar->reset();
QMetaObject::invokeMethod(&_audio, "reset", Qt::QueuedConnection);
QMetaObject::invokeMethod(DependencyManager::get<Audio>(), "reset", Qt::QueuedConnection);
}
static void setShortcutsEnabled(QWidget* widget, bool enabled) {
@ -3729,7 +3729,7 @@ void Application::nodeKilled(SharedNodePointer node) {
_entityEditSender.nodeKilled(node);
if (node->getType() == NodeType::AudioMixer) {
QMetaObject::invokeMethod(&_audio, "audioMixerKilled");
QMetaObject::invokeMethod(DependencyManager::get<Audio>(), "audioMixerKilled");
}
if (node->getType() == NodeType::VoxelServer) {

View file

@ -187,7 +187,6 @@ public:
GLCanvas* getGLWidget() { return _glWidget; }
bool isThrottleRendering() const { return _glWidget->isThrottleRendering(); }
MyAvatar* getAvatar() { return _myAvatar; }
Audio* getAudio() { return &_audio; }
Camera* getCamera() { return &_myCamera; }
ViewFrustum* getViewFrustum() { return &_viewFrustum; }
ViewFrustum* getDisplayViewFrustum() { return &_displayViewFrustum; }
@ -573,8 +572,6 @@ private:
GlowEffect _glowEffect;
AmbientOcclusionEffect _ambientOcclusionEffect;
Audio _audio;
bool _enableProcessVoxelsThread;
OctreePacketProcessor _octreeProcessor;
VoxelHideShowThread _voxelHideShowThread;

View file

@ -59,8 +59,8 @@ static const int MUTE_ICON_SIZE = 24;
static const int RECEIVED_AUDIO_STREAM_CAPACITY_FRAMES = 100;
Audio::Audio(QObject* parent) :
AbstractAudioInterface(parent),
Audio::Audio() :
AbstractAudioInterface(),
_audioInput(NULL),
_desiredInputFormat(),
_inputFormat(),

View file

@ -15,6 +15,21 @@
#include <fstream>
#include <vector>
#include <QAudio>
#include <QAudioInput>
#include <QElapsedTimer>
#include <QGLWidget>
#include <QtCore/QObject>
#include <QtCore/QVector>
#include <QtMultimedia/QAudioFormat>
#include <QVector>
#include <QByteArray>
#include <AbstractAudioInterface.h>
#include <AudioRingBuffer.h>
#include <DependencyManager.h>
#include <StDev.h>
#include "InterfaceConfig.h"
#include "AudioStreamStats.h"
#include "Recorder.h"
@ -27,23 +42,9 @@
#include "AudioSourceNoise.h"
#include "AudioGain.h"
#include <QAudio>
#include <QAudioInput>
#include <QElapsedTimer>
#include <QGLWidget>
#include <QtCore/QObject>
#include <QtCore/QVector>
#include <QtMultimedia/QAudioFormat>
#include <QVector>
#include <QByteArray>
#include <AbstractAudioInterface.h>
#include <StDev.h>
#include "MixedProcessedAudioStream.h"
#include "AudioEffectOptions.h"
#include <AudioRingBuffer.h>
#include <StDev.h>
#ifdef _WIN32
#pragma warning( push )
@ -66,7 +67,7 @@ class QAudioInput;
class QAudioOutput;
class QIODevice;
class Audio : public AbstractAudioInterface {
class Audio : public AbstractAudioInterface, public DependencyManager::Dependency {
Q_OBJECT
public:
@ -81,10 +82,8 @@ public:
private:
MixedProcessedAudioStream& _receivedAudioStream;
};
// setup for audio I/O
Audio(QObject* parent = 0);
const MixedProcessedAudioStream& getReceivedAudioStream() const { return _receivedAudioStream; }
float getLastInputLoudness() const { return glm::max(_lastInputLoudness - _noiseGateMeasuredFloor, 0.0f); }
float getTimeSinceLastClip() const { return _timeSinceLastClip; }
@ -118,6 +117,8 @@ public:
float getAudioOutputAverageMsecsUnplayed() const { return (float)_audioOutputMsecsUnplayedStats.getWindowAverage(); }
void setRecorder(RecorderPointer recorder) { _recorder = recorder; }
friend class DependencyManager;
public slots:
void start();
@ -166,6 +167,10 @@ signals:
void preProcessOriginalInboundAudio(unsigned int sampleTime, QByteArray& samples, const QAudioFormat& format);
void processInboundAudio(unsigned int sampleTime, const QByteArray& samples, const QAudioFormat& format);
void processLocalAudio(unsigned int sampleTime, const QByteArray& samples, const QAudioFormat& format);
protected:
// setup for audio I/O
Audio();
private:
void outputFormatChanged();

View file

@ -71,7 +71,6 @@ void AudioScope::reallocateScope(int frames) {
if (_framesPerScope != frames) {
_framesPerScope = frames;
_samplesPerScope = AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL * _framesPerScope;
QMutexLocker lock(&_guard);
freeScope();
allocateScope();
}
@ -114,7 +113,6 @@ void AudioScope::render(int width, int height) {
renderBackground(backgroundColor, x, y, w, h);
renderGrid(gridColor, x, y, w, h, gridRows, gridCols);
QMutexLocker lock(&_guard);
renderLineStrip(inputColor, x, y, _samplesPerScope, _scopeInputOffset, _scopeInput);
renderLineStrip(outputLeftColor, x, y, _samplesPerScope, _scopeOutputOffset, _scopeOutputLeft);
renderLineStrip(outputRightColor, x, y, _samplesPerScope, _scopeOutputOffset, _scopeOutputRight);
@ -222,7 +220,6 @@ int AudioScope::addBufferToScope(QByteArray* byteArray, int frameOffset, const i
// Temporary variable receives sample value
float sample;
QMutexLocker lock(&_guard);
// Short int pointer to mapped samples in byte array
int16_t* destination = (int16_t*) byteArray->data();
@ -235,8 +232,7 @@ int AudioScope::addBufferToScope(QByteArray* byteArray, int frameOffset, const i
}
int AudioScope::addSilenceToScope(QByteArray* byteArray, int frameOffset, int silentSamples) {
QMutexLocker lock(&_guard);
// Short int pointer to mapped samples in byte array
int16_t* destination = (int16_t*)byteArray->data();

View file

@ -62,7 +62,6 @@ private:
QByteArray* _scopeOutputLeft;
QByteArray* _scopeOutputRight;
QByteArray _scopeLastFrame;
QMutex _guard;
};
#endif // hifi_AudioScope_h

View file

@ -18,9 +18,15 @@ AudioDeviceScriptingInterface* AudioDeviceScriptingInterface::getInstance() {
return &sharedInstance;
}
AudioDeviceScriptingInterface::AudioDeviceScriptingInterface() {
connect(DependencyManager::get<Audio>(), &Audio::muteToggled,
AudioDeviceScriptingInterface::getInstance(),
&AudioDeviceScriptingInterface::muteToggled, Qt::DirectConnection);
}
bool AudioDeviceScriptingInterface::setInputDevice(const QString& deviceName) {
bool result;
QMetaObject::invokeMethod(Application::getInstance()->getAudio(), "switchInputToAudioDevice",
QMetaObject::invokeMethod(DependencyManager::get<Audio>(), "switchInputToAudioDevice",
Qt::BlockingQueuedConnection,
Q_RETURN_ARG(bool, result),
Q_ARG(const QString&, deviceName));
@ -30,7 +36,7 @@ bool AudioDeviceScriptingInterface::setInputDevice(const QString& deviceName) {
bool AudioDeviceScriptingInterface::setOutputDevice(const QString& deviceName) {
bool result;
QMetaObject::invokeMethod(Application::getInstance()->getAudio(), "switchOutputToAudioDevice",
QMetaObject::invokeMethod(DependencyManager::get<Audio>(), "switchOutputToAudioDevice",
Qt::BlockingQueuedConnection,
Q_RETURN_ARG(bool, result),
Q_ARG(const QString&, deviceName));
@ -39,50 +45,50 @@ bool AudioDeviceScriptingInterface::setOutputDevice(const QString& deviceName) {
}
QString AudioDeviceScriptingInterface::getInputDevice() {
return Application::getInstance()->getAudio()->getDeviceName(QAudio::AudioInput);
return DependencyManager::get<Audio>()->getDeviceName(QAudio::AudioInput);
}
QString AudioDeviceScriptingInterface::getOutputDevice() {
return Application::getInstance()->getAudio()->getDeviceName(QAudio::AudioOutput);
return DependencyManager::get<Audio>()->getDeviceName(QAudio::AudioOutput);
}
QString AudioDeviceScriptingInterface::getDefaultInputDevice() {
return Application::getInstance()->getAudio()->getDefaultDeviceName(QAudio::AudioInput);
return DependencyManager::get<Audio>()->getDefaultDeviceName(QAudio::AudioInput);
}
QString AudioDeviceScriptingInterface::getDefaultOutputDevice() {
return Application::getInstance()->getAudio()->getDefaultDeviceName(QAudio::AudioOutput);
return DependencyManager::get<Audio>()->getDefaultDeviceName(QAudio::AudioOutput);
}
QVector<QString> AudioDeviceScriptingInterface::getInputDevices() {
return Application::getInstance()->getAudio()->getDeviceNames(QAudio::AudioInput);
return DependencyManager::get<Audio>()->getDeviceNames(QAudio::AudioInput);
}
QVector<QString> AudioDeviceScriptingInterface::getOutputDevices() {
return Application::getInstance()->getAudio()->getDeviceNames(QAudio::AudioOutput);
return DependencyManager::get<Audio>()->getDeviceNames(QAudio::AudioOutput);
}
float AudioDeviceScriptingInterface::getInputVolume() {
return Application::getInstance()->getAudio()->getInputVolume();
return DependencyManager::get<Audio>()->getInputVolume();
}
void AudioDeviceScriptingInterface::setInputVolume(float volume) {
Application::getInstance()->getAudio()->setInputVolume(volume);
DependencyManager::get<Audio>()->setInputVolume(volume);
}
void AudioDeviceScriptingInterface::setReverb(bool reverb) {
Application::getInstance()->getAudio()->setReverb(reverb);
DependencyManager::get<Audio>()->setReverb(reverb);
}
void AudioDeviceScriptingInterface::setReverbOptions(const AudioEffectOptions* options) {
Application::getInstance()->getAudio()->setReverbOptions(options);
DependencyManager::get<Audio>()->setReverbOptions(options);
}
void AudioDeviceScriptingInterface::toggleMute() {
Application::getInstance()->getAudio()->toggleMute();
DependencyManager::get<Audio>()->toggleMute();
}
bool AudioDeviceScriptingInterface::getMuted() {
return Application::getInstance()->getAudio()->getMuted();
return DependencyManager::get<Audio>()->getMuted();
}

View file

@ -20,7 +20,6 @@
class AudioDeviceScriptingInterface : public QObject {
Q_OBJECT
AudioDeviceScriptingInterface() { };
public:
static AudioDeviceScriptingInterface* getInstance();
@ -44,6 +43,9 @@ public slots:
bool getMuted();
void toggleMute();
private:
AudioDeviceScriptingInterface();
signals:
void muteToggled();

View file

@ -245,7 +245,7 @@ void PreferencesDialog::savePreferences() {
streamSettings._repetitionWithFade = ui.repetitionWithFadeCheckBox->isChecked();
Menu::getInstance()->setReceivedAudioStreamSettings(streamSettings);
Application::getInstance()->getAudio()->setReceivedAudioStreamSettings(streamSettings);
DependencyManager::get<Audio>()->setReceivedAudioStreamSettings(streamSettings);
Application::getInstance()->resizeGL(Application::getInstance()->getGLWidget()->width(),
Application::getInstance()->getGLWidget()->height());

View file

@ -31,19 +31,16 @@ EntityCollisionSystem::EntityCollisionSystem()
: SimpleEntitySimulation(),
_packetSender(NULL),
_voxels(NULL),
_audio(NULL),
_avatars(NULL),
_collisions(MAX_COLLISIONS_PER_Entity) {
}
void EntityCollisionSystem::init(EntityEditPacketSender* packetSender,
EntityTree* entities, VoxelTree* voxels, AbstractAudioInterface* audio,
AvatarHashMap* avatars) {
EntityTree* entities, VoxelTree* voxels, AvatarHashMap* avatars) {
assert(entities);
setEntityTree(entities);
_packetSender = packetSender;
_voxels = voxels;
_audio = audio;
_avatars = avatars;
}

View file

@ -38,8 +38,7 @@ Q_OBJECT
public:
EntityCollisionSystem();
void init(EntityEditPacketSender* packetSender, EntityTree* entities, VoxelTree* voxels,
AbstractAudioInterface* audio = NULL, AvatarHashMap* _avatars = NULL);
void init(EntityEditPacketSender* packetSender, EntityTree* entities, VoxelTree* voxels, AvatarHashMap* _avatars = NULL);
~EntityCollisionSystem();