diff --git a/src/audio/audio.cpp b/src/audio/audio.cpp index b33b0ba19..509dcd6d9 100644 --- a/src/audio/audio.cpp +++ b/src/audio/audio.cpp @@ -20,6 +20,7 @@ #include "audio.h" #include "src/audio/backend/openal.h" #include "src/audio/backend/openal2.h" +#include "src/persistence/settings.h" #include @@ -169,6 +170,19 @@ */ Audio& Audio::getInstance() { - static OpenAL2 instance; - return instance; + static bool initialized = false; + static bool Backend2 = false; + + if(!initialized) { + Backend2 = Settings::getInstance().getEnableBackend2(); + initialized = true; + } + + if(Backend2) { + static OpenAL2 instance; + return instance; + } else { + static OpenAL instance; + return instance; + } } diff --git a/src/audio/backend/openal2.cpp b/src/audio/backend/openal2.cpp index fa7bfecb9..873718104 100644 --- a/src/audio/backend/openal2.cpp +++ b/src/audio/backend/openal2.cpp @@ -288,29 +288,36 @@ bool OpenAL2::loadOpenALExtensions(ALCdevice* dev) // load OpenAL extension functions alcLoopbackOpenDeviceSOFT = reinterpret_cast (alcGetProcAddress(dev, "alcLoopbackOpenDeviceSOFT")); - checkAlcError(dev); if(!alcLoopbackOpenDeviceSOFT) { qDebug() << "Failed to load alcLoopbackOpenDeviceSOFT function!"; return false; } + alcIsRenderFormatSupportedSOFT = reinterpret_cast (alcGetProcAddress(dev, "alcIsRenderFormatSupportedSOFT")); - checkAlcError(dev); if(!alcIsRenderFormatSupportedSOFT) { qDebug() << "Failed to load alcIsRenderFormatSupportedSOFT function!"; return false; } + alGetSourcedvSOFT = reinterpret_cast (alcGetProcAddress(dev, "alGetSourcedvSOFT")); - checkAlcError(dev); if(!alGetSourcedvSOFT) { qDebug() << "Failed to load alGetSourcedvSOFT function!"; return false; } + alcRenderSamplesSOFT = reinterpret_cast + (alcGetProcAddress(alOutDev, "alcRenderSamplesSOFT")); + checkAlcError(dev); + if(!alcRenderSamplesSOFT) { + qDebug() << "Failed to load alcRenderSamplesSOFT function!"; + return false; + } + return true; } @@ -631,17 +638,14 @@ void OpenAL2::doOutput() } ALdouble latency[2] = {0}; - if(alGetSourcedvSOFT) { - alGetSourcedvSOFT(alProxySource, AL_SEC_OFFSET_LATENCY_SOFT, latency); - checkAlError(); - } + alGetSourcedvSOFT(alProxySource, AL_SEC_OFFSET_LATENCY_SOFT, latency); + checkAlError(); //qDebug() << "Playback latency: " << latency[1] << "offset: " << latency[0]; ALshort outBuf[AUDIO_FRAME_SAMPLE_COUNT] = {0}; alcMakeContextCurrent(alProxyContext); - LPALCRENDERSAMPLESSOFT alcRenderSamplesSOFT = - reinterpret_cast (alcGetProcAddress(alOutDev, "alcRenderSamplesSOFT")); alcRenderSamplesSOFT(alProxyDev, outBuf, AUDIO_FRAME_SAMPLE_COUNT); + checkAlcError(alProxyDev); alcMakeContextCurrent(alOutContext); alBufferData(bufids[0], AL_FORMAT_MONO16, outBuf, diff --git a/src/audio/backend/openal2.h b/src/audio/backend/openal2.h index d33c6e5f7..af8b45568 100644 --- a/src/audio/backend/openal2.h +++ b/src/audio/backend/openal2.h @@ -139,6 +139,7 @@ private: LPALCLOOPBACKOPENDEVICESOFT alcLoopbackOpenDeviceSOFT = nullptr; LPALCISRENDERFORMATSUPPORTEDSOFT alcIsRenderFormatSupportedSOFT = nullptr; LPALGETSOURCEDVSOFT alGetSourcedvSOFT = nullptr; + LPALCRENDERSAMPLESSOFT alcRenderSamplesSOFT = nullptr; }; #endif // OPENAL2_H diff --git a/src/persistence/settings.cpp b/src/persistence/settings.cpp index 01ad00d64..49743d6cb 100644 --- a/src/persistence/settings.cpp +++ b/src/persistence/settings.cpp @@ -265,6 +265,10 @@ void Settings::loadGlobal() audioOutDevEnabled = s.value("audioOutDevEnabled", true).toBool(); audioInGainDecibel = s.value("inGain", 0).toReal(); outVolume = s.value("outVolume", 100).toInt(); + enableBackend2 = false; + #ifdef USE_FILTERAUDIO + enableBackend2 = s.value("enableBackend2", false).toBool(); + #endif } s.endGroup(); @@ -561,6 +565,7 @@ void Settings::saveGlobal() s.setValue("audioOutDevEnabled", audioOutDevEnabled); s.setValue("inGain", audioInGainDecibel); s.setValue("outVolume", outVolume); + s.setValue("enableBackend2", enableBackend2); } s.endGroup(); @@ -1840,6 +1845,22 @@ void Settings::setOutVolume(int volume) } } +bool Settings::getEnableBackend2() const +{ + QMutexLocker locker{&bigLock}; + return enableBackend2; +} + +void Settings::setEnableBackend2(bool enabled) +{ + QMutexLocker locker{&bigLock}; + + if (enabled != enableBackend2) { + enableBackend2 = enabled; + emit enableBackend2Changed(enabled); + } +} + QRect Settings::getScreenRegion() const { QMutexLocker locker(&bigLock); diff --git a/src/persistence/settings.h b/src/persistence/settings.h index c12b05905..c0048ad0d 100644 --- a/src/persistence/settings.h +++ b/src/persistence/settings.h @@ -100,6 +100,7 @@ class Settings : public QObject Q_PROPERTY(bool audioOutDevEnabled READ getAudioOutDevEnabled WRITE setAudioOutDevEnabled NOTIFY audioOutDevEnabledChanged FINAL) Q_PROPERTY(int outVolume READ getOutVolume WRITE setOutVolume NOTIFY outVolumeChanged FINAL) + Q_PROPERTY(bool enableBackend2 READ getEnableBackend2 WRITE setEnableBackend2 NOTIFY enableBackend2Changed FINAL) // Video Q_PROPERTY(QString videoDev READ getVideoDev WRITE setVideoDev NOTIFY videoDevChanged FINAL) @@ -234,6 +235,7 @@ signals: void audioOutDevEnabledChanged(bool enabled); void outVolumeChanged(int volume); void enableTestSoundChanged(bool enabled); + void enableBackend2Changed(bool enabled); // Video void videoDevChanged(const QString& name); @@ -363,6 +365,9 @@ public: bool getEnableTestSound() const; void setEnableTestSound(bool newValue); + bool getEnableBackend2() const; + void setEnableBackend2(bool enabled); + QString getVideoDev() const; void setVideoDev(const QString& deviceSpecifier); @@ -617,6 +622,7 @@ private: bool audioOutDevEnabled; int outVolume; bool enableTestSound; + bool enableBackend2; // Video QString videoDev; diff --git a/src/widget/form/settings/avform.cpp b/src/widget/form/settings/avform.cpp index 1af8bc698..dbd8dd63f 100644 --- a/src/widget/form/settings/avform.cpp +++ b/src/widget/form/settings/avform.cpp @@ -60,6 +60,8 @@ AVForm::AVForm() cbEnableTestSound->setToolTip(tr("Play a test sound while changing the output volume.")); + cbEnableBackend2->setChecked(s.getEnableBackend2()); + connect(rescanButton, &QPushButton::clicked, this, &AVForm::rescanDevices); playbackSlider->setTracking(false); @@ -141,6 +143,11 @@ void AVForm::rescanDevices() getVideoDevices(); } +void AVForm::on_cbEnableBackend2_stateChanged() +{ + Settings::getInstance().setEnableBackend2(cbEnableBackend2->isChecked()); +} + void AVForm::on_videoModescomboBox_currentIndexChanged(int index) { assert(0 <= index && index < videoModes.size()); @@ -552,3 +559,5 @@ void AVForm::retranslateUi() { Ui::AVForm::retranslateUi(this); } + + diff --git a/src/widget/form/settings/avform.h b/src/widget/form/settings/avform.h index 2bdaf125f..21359813b 100644 --- a/src/widget/form/settings/avform.h +++ b/src/widget/form/settings/avform.h @@ -73,6 +73,8 @@ private slots: void rescanDevices(); + void on_cbEnableBackend2_stateChanged(); + protected: void updateVideoModes(int curIndex); diff --git a/src/widget/form/settings/avform.ui b/src/widget/form/settings/avform.ui index 8cef5c077..e0ed33f9b 100644 --- a/src/widget/form/settings/avform.ui +++ b/src/widget/form/settings/avform.ui @@ -30,8 +30,8 @@ 0 0 - 824 - 489 + 830 + 495 @@ -44,30 +44,20 @@ 6 - - - - - - - Qt::Horizontal + + + + Capture device - - + + - Gain + Test Sound - - - - - - - - - Playback device + + true @@ -84,12 +74,11 @@ - - - - Capture device - - + + + + + @@ -98,14 +87,38 @@ - - + + - Test Sound + Gain - + + + + + + Qt::Horizontal + + + + + + + Playback device + + + + + + true + + Enables the experimental audio backend with echo cancelling support, needs qTox restart to take effect. + + + Enable experimental audio backend +