mirror of
https://github.com/overte-org/overte.git
synced 2025-07-23 03:59:18 +02:00
Re-implement the continuous detection of device changes for all platforms, using a background thread. This prevents the glitches caused by calling checkDevices() on the audio processing thread.
This commit is contained in:
parent
3583bdecbb
commit
4b2778f02d
2 changed files with 34 additions and 10 deletions
|
@ -67,6 +67,33 @@ Setting::Handle<int> windowSecondsForDesiredReduction("windowSecondsForDesiredRe
|
||||||
DEFAULT_WINDOW_SECONDS_FOR_DESIRED_REDUCTION);
|
DEFAULT_WINDOW_SECONDS_FOR_DESIRED_REDUCTION);
|
||||||
Setting::Handle<bool> repetitionWithFade("repetitionWithFade", DEFAULT_REPETITION_WITH_FADE);
|
Setting::Handle<bool> repetitionWithFade("repetitionWithFade", DEFAULT_REPETITION_WITH_FADE);
|
||||||
|
|
||||||
|
// background thread that continuously polls for device changes
|
||||||
|
class CheckDevicesThread : public QThread {
|
||||||
|
public:
|
||||||
|
const unsigned long DEVICE_CHECK_INTERVAL_MSECS = 2 * 1000;
|
||||||
|
|
||||||
|
CheckDevicesThread(AudioClient* audioClient)
|
||||||
|
: _audioClient(audioClient) {
|
||||||
|
|
||||||
|
connect(qApp, &QCoreApplication::aboutToQuit, [this] {
|
||||||
|
_quit = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void run() override {
|
||||||
|
while (!_quit) {
|
||||||
|
|
||||||
|
//qDebug() << "Checking for audio device changes...";
|
||||||
|
_audioClient->checkDevices();
|
||||||
|
|
||||||
|
QThread::msleep(DEVICE_CHECK_INTERVAL_MSECS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AudioClient* _audioClient { nullptr };
|
||||||
|
bool _quit { false };
|
||||||
|
};
|
||||||
|
|
||||||
AudioClient::AudioClient() :
|
AudioClient::AudioClient() :
|
||||||
AbstractAudioInterface(),
|
AbstractAudioInterface(),
|
||||||
_audioInput(NULL),
|
_audioInput(NULL),
|
||||||
|
@ -121,14 +148,14 @@ AudioClient::AudioClient() :
|
||||||
|
|
||||||
connect(&_receivedAudioStream, &InboundAudioStream::mismatchedAudioCodec, this, &AudioClient::handleMismatchAudioFormat);
|
connect(&_receivedAudioStream, &InboundAudioStream::mismatchedAudioCodec, this, &AudioClient::handleMismatchAudioFormat);
|
||||||
|
|
||||||
|
|
||||||
_inputDevices = getDeviceNames(QAudio::AudioInput);
|
_inputDevices = getDeviceNames(QAudio::AudioInput);
|
||||||
_outputDevices = getDeviceNames(QAudio::AudioOutput);
|
_outputDevices = getDeviceNames(QAudio::AudioOutput);
|
||||||
|
|
||||||
const qint64 DEVICE_CHECK_INTERVAL_MSECS = 2 * 1000;
|
// start a thread to detect any device changes
|
||||||
QTimer* updateTimer = new QTimer(this);
|
QThread* checkDevicesThread = new CheckDevicesThread(this);
|
||||||
connect(updateTimer, &QTimer::timeout, this, &AudioClient::checkDevices);
|
checkDevicesThread->setObjectName("CheckDevices Thread");
|
||||||
updateTimer->start(DEVICE_CHECK_INTERVAL_MSECS);
|
checkDevicesThread->setPriority(QThread::LowPriority);
|
||||||
|
checkDevicesThread->start();
|
||||||
|
|
||||||
configureReverb();
|
configureReverb();
|
||||||
|
|
||||||
|
@ -1349,9 +1376,6 @@ qint64 AudioClient::AudioOutputIODevice::readData(char * data, qint64 maxSize) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioClient::checkDevices() {
|
void AudioClient::checkDevices() {
|
||||||
# if defined(Q_OS_LINUX) || defined (Q_OS_WIN)
|
|
||||||
// on Windows and Linux, this causes dropouts in the audio stream
|
|
||||||
# else
|
|
||||||
QVector<QString> inputDevices = getDeviceNames(QAudio::AudioInput);
|
QVector<QString> inputDevices = getDeviceNames(QAudio::AudioInput);
|
||||||
QVector<QString> outputDevices = getDeviceNames(QAudio::AudioOutput);
|
QVector<QString> outputDevices = getDeviceNames(QAudio::AudioOutput);
|
||||||
|
|
||||||
|
@ -1361,7 +1385,6 @@ void AudioClient::checkDevices() {
|
||||||
|
|
||||||
emit deviceChanged();
|
emit deviceChanged();
|
||||||
}
|
}
|
||||||
# endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioClient::loadSettings() {
|
void AudioClient::loadSettings() {
|
||||||
|
|
|
@ -139,6 +139,8 @@ public:
|
||||||
|
|
||||||
QVector<AudioInjector*>& getActiveLocalAudioInjectors() { return _activeLocalAudioInjectors; }
|
QVector<AudioInjector*>& getActiveLocalAudioInjectors() { return _activeLocalAudioInjectors; }
|
||||||
|
|
||||||
|
void checkDevices();
|
||||||
|
|
||||||
static const float CALLBACK_ACCELERATOR_RATIO;
|
static const float CALLBACK_ACCELERATOR_RATIO;
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
|
@ -312,7 +314,6 @@ private:
|
||||||
|
|
||||||
QVector<QString> _inputDevices;
|
QVector<QString> _inputDevices;
|
||||||
QVector<QString> _outputDevices;
|
QVector<QString> _outputDevices;
|
||||||
void checkDevices();
|
|
||||||
|
|
||||||
bool _hasReceivedFirstPacket = false;
|
bool _hasReceivedFirstPacket = false;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue