diff --git a/app/audio/audiomanager.cpp b/app/audio/audiomanager.cpp index aee368c84..e14a9d3ad 100644 --- a/app/audio/audiomanager.cpp +++ b/app/audio/audiomanager.cpp @@ -135,11 +135,12 @@ void AudioManager::SetOutputDevice(const QAudioDeviceInfo &info) abort(); } - output_manager_.SetOutputDevice(info, format); + if (info.isFormatSupported(format)) { + output_manager_.SetOutputDevice(info, format); + } else { + qWarning() << "Output format not supported by device"; + } } - - // Un-comment this to get debug information about what the audio output is doing - //connect(output_.get(), &QAudioOutput::stateChanged, this, &AudioManager::OutputStateChanged); } void AudioManager::SetOutputParams(const AudioRenderingParams ¶ms) @@ -195,10 +196,7 @@ AudioManager::AudioManager() : { RefreshDevices(); - connect(&output_manager_, &AudioOutputManager::SentSamples, this, &AudioManager::SentSamples); connect(&output_manager_, &AudioOutputManager::OutputNotified, this, &AudioManager::OutputNotified); - - output_manager_.SetEnableSendingSamples(true); } AudioManager::~AudioManager() @@ -258,11 +256,6 @@ void AudioManager::RefreshThreadDone() emit DeviceListReady(); } -void AudioManager::OutputStateChanged(QAudio::State state) -{ - qDebug() << state; -} - AudioRefreshDevicesObject::AudioRefreshDevicesObject() { } diff --git a/app/audio/audiomanager.h b/app/audio/audiomanager.h index 79faef13e..116b62c2f 100644 --- a/app/audio/audiomanager.h +++ b/app/audio/audiomanager.h @@ -103,8 +103,6 @@ public: signals: void DeviceListReady(); - void SentSamples(QVector averages); - void OutputNotified(); private: @@ -132,8 +130,6 @@ private: private slots: void RefreshThreadDone(); - void OutputStateChanged(QAudio::State state); - }; OLIVE_NAMESPACE_EXIT diff --git a/app/audio/outputdeviceproxy.cpp b/app/audio/outputdeviceproxy.cpp index 2da841122..713888b05 100644 --- a/app/audio/outputdeviceproxy.cpp +++ b/app/audio/outputdeviceproxy.cpp @@ -26,8 +26,7 @@ OLIVE_NAMESPACE_ENTER AudioOutputDeviceProxy::AudioOutputDeviceProxy() : - device_(nullptr), - send_averages_(false) + device_(nullptr) { } @@ -41,7 +40,9 @@ void AudioOutputDeviceProxy::SetDevice(QIODevice *device, int playback_speed) device_ = device; if (!device_->isOpen()) { - device_->open(QIODevice::ReadOnly); + if (!device_->open(QIODevice::ReadOnly)) { + qWarning() << "Failed to open sub-device"; + } } playback_speed_ = playback_speed; @@ -51,11 +52,6 @@ void AudioOutputDeviceProxy::SetDevice(QIODevice *device, int playback_speed) } } -void AudioOutputDeviceProxy::SetSendAverages(bool send) -{ - send_averages_ = send; -} - void AudioOutputDeviceProxy::close() { QIODevice::close(); @@ -73,8 +69,6 @@ qint64 AudioOutputDeviceProxy::readData(char *data, qint64 maxlen) qint64 read_count; - - if (tempo_processor_.IsOpen()) { while ((read_count = tempo_processor_.Pull(data, static_cast(maxlen))) == 0) { @@ -92,11 +86,6 @@ qint64 AudioOutputDeviceProxy::readData(char *data, qint64 maxlen) read_count = ReverseAwareRead(data, maxlen); } - // If we read any - if (read_count > 0 && send_averages_) { - emit ProcessedAverages(AudioBufferAverage::ProcessAverages(data, static_cast(read_count), params_.channel_count())); - } - return read_count; } @@ -108,7 +97,7 @@ qint64 AudioOutputDeviceProxy::writeData(const char *data, qint64 maxSize) Q_UNUSED(data) Q_UNUSED(maxSize) - return -1; + return 0; } qint64 AudioOutputDeviceProxy::ReverseAwareRead(char *data, qint64 maxlen) diff --git a/app/audio/outputdeviceproxy.h b/app/audio/outputdeviceproxy.h index 515f27a2e..bf639c7fc 100644 --- a/app/audio/outputdeviceproxy.h +++ b/app/audio/outputdeviceproxy.h @@ -38,13 +38,8 @@ public: void SetDevice(QIODevice* device, int playback_speed); - void SetSendAverages(bool send); - virtual void close() override; -signals: - void ProcessedAverages(QVector averages); - protected: virtual qint64 readData(char *data, qint64 maxlen) override; @@ -57,8 +52,6 @@ private: TempoProcessor tempo_processor_; - bool send_averages_; - AudioRenderingParams params_; int playback_speed_; diff --git a/app/audio/outputmanager.cpp b/app/audio/outputmanager.cpp index d289badb0..aa1a97911 100644 --- a/app/audio/outputmanager.cpp +++ b/app/audio/outputmanager.cpp @@ -23,6 +23,8 @@ #include #include +#include + #include "bufferaverage.h" OLIVE_NAMESPACE_ENTER @@ -30,15 +32,18 @@ OLIVE_NAMESPACE_ENTER AudioOutputManager::AudioOutputManager(QObject *parent) : QObject(parent), output_(nullptr), - push_device_(nullptr), - enable_sending_samples_(false) + push_device_(nullptr) { - connect(&device_proxy_, &AudioOutputDeviceProxy::ProcessedAverages, this, &AudioOutputManager::SentSamples); +} + +AudioOutputManager::~AudioOutputManager() +{ + delete output_; } bool AudioOutputManager::OutputIsSet() { - return (output_.get()); + return output_; } void AudioOutputManager::Push(const QByteArray& samples) @@ -107,9 +112,6 @@ void AudioOutputManager::PushMoreSamples() qint64 write_count = push_device_->write(read_ptr, pushed_samples_.size() - pushed_sample_index_); - // Emit the samples we just sent - ProcessAverages(read_ptr, static_cast(write_count)); - // Increment sample buffer index (faster than shift the bytes up) pushed_sample_index_ += static_cast(write_count); @@ -119,13 +121,6 @@ void AudioOutputManager::PushMoreSamples() } } -void AudioOutputManager::SetEnableSendingSamples(bool e) -{ - enable_sending_samples_ = e; - - device_proxy_.SetSendAverages(e); -} - void AudioOutputManager::SetOutputDevice(QAudioDeviceInfo info, QAudioFormat format) { // Whatever the output is doing right now, stop it @@ -135,23 +130,24 @@ void AudioOutputManager::SetOutputDevice(QAudioDeviceInfo info, QAudioFormat for if (device_proxy_.isOpen()) { device_proxy_.close(); } + + delete output_; } // Create a new output device and start it in push mode - output_ = std::unique_ptr(new QAudioOutput(info, format, this)); + output_ = new QAudioOutput(info, format, this); output_->setNotifyInterval(1); push_device_ = output_->start(); - connect(output_.get(), &QAudioOutput::notify, this, &AudioOutputManager::PushMoreSamples); - connect(output_.get(), &QAudioOutput::notify, this, &AudioOutputManager::OutputNotified); + connect(output_, &QAudioOutput::notify, this, &AudioOutputManager::PushMoreSamples); + connect(output_, &QAudioOutput::notify, this, &AudioOutputManager::OutputNotified); + + // Un-comment this to get debug information about what the audio output is doing + //connect(output_, &QAudioOutput::stateChanged, this, &AudioOutputManager::OutputStateChanged); } -void AudioOutputManager::ProcessAverages(const char *data, int length) +void AudioOutputManager::OutputStateChanged(QAudio::State state) { - if (!enable_sending_samples_ || length == 0) { - return; - } - - emit SentSamples(AudioBufferAverage::ProcessAverages(data, length, output_.get()->format().channelCount())); + qDebug() << state << output_->error(); } OLIVE_NAMESPACE_EXIT diff --git a/app/audio/outputmanager.h b/app/audio/outputmanager.h index c10af3bc1..cf06f0641 100644 --- a/app/audio/outputmanager.h +++ b/app/audio/outputmanager.h @@ -26,6 +26,7 @@ #include #include #include +#include #include "outputdeviceproxy.h" @@ -37,12 +38,9 @@ class AudioOutputManager : public QObject public: AudioOutputManager(QObject* parent = nullptr); - bool OutputIsSet(); + virtual ~AudioOutputManager() override; - /** - * @brief If enabled, this will emit the SentSamples() signal whenever samples are sent to the output device - */ - void SetEnableSendingSamples(bool e); + bool OutputIsSet(); void SetOutputDevice(QAudioDeviceInfo info, QAudioFormat format); @@ -60,34 +58,26 @@ public: void SetParameters(const AudioRenderingParams& params); -signals: - /** - * @brief Signal emitted when samples are sent to the output device - * - * This sends an array of values corresponding to the channel count. Each value is an average of all the samples just - * sent to that channel. Useful for connecting to AudioMonitor. - * - * Can be disabled with SetEnableSendingSamples() to save CPU usage. - */ - void SentSamples(QVector averages); +public slots: + +signals: void OutputNotified(); private: - void ProcessAverages(const char* data, int length); - - std::unique_ptr output_; + QAudioOutput* output_; QIODevice* push_device_; QByteArray pushed_samples_; int pushed_sample_index_; - bool enable_sending_samples_; - AudioOutputDeviceProxy device_proxy_; private slots: void PushMoreSamples(); + + void OutputStateChanged(QAudio::State state); + }; OLIVE_NAMESPACE_EXIT diff --git a/app/widget/audiomonitor/audiomonitor.cpp b/app/widget/audiomonitor/audiomonitor.cpp index 48063120b..7542965a9 100644 --- a/app/widget/audiomonitor/audiomonitor.cpp +++ b/app/widget/audiomonitor/audiomonitor.cpp @@ -39,7 +39,6 @@ AudioMonitor::AudioMonitor(QWidget *parent) : clear_timer_.setInterval(kClearTimerInterval); clear_timer_.setSingleShot(true); - connect(AudioManager::instance(), &AudioManager::SentSamples, this, &AudioMonitor::SetValues); connect(&clear_timer_, &QTimer::timeout, this, &AudioMonitor::Clear); } diff --git a/app/window/mainwindow/mainwindow.cpp b/app/window/mainwindow/mainwindow.cpp index 9bef78fb9..1a83578e5 100644 --- a/app/window/mainwindow/mainwindow.cpp +++ b/app/window/mainwindow/mainwindow.cpp @@ -321,8 +321,6 @@ void MainWindow::ProjectOpen(Project *p) } panel->set_project(p); - - // FIXME Use settings data to create panels and restore state if they exist } void MainWindow::ProjectClose(Project *p)