diff --git a/libraries/audio-client/src/AudioClient.cpp b/libraries/audio-client/src/AudioClient.cpp index fc54a04a5e..7a1d8edccd 100644 --- a/libraries/audio-client/src/AudioClient.cpp +++ b/libraries/audio-client/src/AudioClient.cpp @@ -224,13 +224,18 @@ AudioClient::AudioClient() : // start a thread to detect any device changes _checkDevicesTimer = new QTimer(this); connect(_checkDevicesTimer, &QTimer::timeout, [this] { - QtConcurrent::run(QThreadPool::globalInstance(), [this] { - checkDevices(); - }); + QtConcurrent::run(QThreadPool::globalInstance(), [this] { checkDevices(); }); }); const unsigned long DEVICE_CHECK_INTERVAL_MSECS = 2 * 1000; _checkDevicesTimer->start(DEVICE_CHECK_INTERVAL_MSECS); + // start a thread to detect peak value changes + _checkPeakValuesTimer = new QTimer(this); + connect(_checkPeakValuesTimer, &QTimer::timeout, [this] { + QtConcurrent::run(QThreadPool::globalInstance(), [this] { checkPeakValues(); }); + }); + const unsigned long PEAK_VALUES_CHECK_INTERVAL_SECS = 50; + configureReverb(); @@ -262,6 +267,7 @@ void AudioClient::cleanupBeforeQuit() { stop(); _checkDevicesTimer->stop(); + _checkPeakValuesTimer->stop(); } void AudioClient::handleMismatchAudioFormat(SharedNodePointer node, const QString& currentCodec, const QString& recievedCodec) { diff --git a/libraries/audio-client/src/AudioClient.h b/libraries/audio-client/src/AudioClient.h index 54ce3aa6c2..79e82526c6 100644 --- a/libraries/audio-client/src/AudioClient.h +++ b/libraries/audio-client/src/AudioClient.h @@ -148,6 +148,8 @@ public: QAudioDeviceInfo getActiveAudioDevice(QAudio::Mode mode) const; QList getAudioDevices(QAudio::Mode mode) const; + void enablePeakValues(bool enable) { _enablePeakValues = enable; } + static const float CALLBACK_ACCELERATOR_RATIO; bool getNamedAudioDeviceForModeExists(QAudio::Mode mode, const QString& deviceName); @@ -220,6 +222,7 @@ signals: void deviceChanged(QAudio::Mode mode, const QAudioDeviceInfo& device); void devicesChanged(QAudio::Mode mode, const QList& devices); + void peakValueListChanged(const QList peakValueList); void receivedFirstPacket(); void disconnected(); @@ -238,9 +241,12 @@ private: friend class CheckDevicesThread; friend class LocalInjectorsThread; + // background tasks + void checkDevices(); + void checkPeakValues(); + void outputFormatChanged(); void handleAudioInput(QByteArray& audioBuffer); - void checkDevices(); void prepareLocalAudioInjectors(std::unique_ptr localAudioLock = nullptr); bool mixLocalAudioInjectors(float* mixBuffer); float azimuthForSource(const glm::vec3& relativePosition); @@ -293,6 +299,7 @@ private: std::atomic _localInjectorsAvailable { false }; MixedProcessedAudioStream _receivedAudioStream; bool _isStereoInput; + std::atomic _enablePeakValues { false }; quint64 _outputStarveDetectionStartTimeMsec; int _outputStarveDetectionCount; @@ -391,6 +398,7 @@ private: RateCounter<> _audioInbound; QTimer* _checkDevicesTimer { nullptr }; + QTimer* _checkPeakValuesTimer { nullptr }; }; diff --git a/libraries/audio-client/src/AudioPeakValues.cpp b/libraries/audio-client/src/AudioPeakValues.cpp new file mode 100644 index 0000000000..021f23b907 --- /dev/null +++ b/libraries/audio-client/src/AudioPeakValues.cpp @@ -0,0 +1,16 @@ +// +// AudioPeakValues.cpp +// interface/src +// +// Created by Zach Pomerantz on 6/26/2017 +// Copyright 2013 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include "AudioClient.h" + +void AudioClient::checkPeakValues() { + // TODO +}