Browse Source

feat(audio): add setting to switch between new and old audio backend

pull/4367/head
sudden6 8 years ago
parent
commit
9d0498e0cf
No known key found for this signature in database
GPG Key ID: 279509B499E032B9
  1. 18
      src/audio/audio.cpp
  2. 22
      src/audio/backend/openal2.cpp
  3. 1
      src/audio/backend/openal2.h
  4. 21
      src/persistence/settings.cpp
  5. 6
      src/persistence/settings.h
  6. 9
      src/widget/form/settings/avform.cpp
  7. 2
      src/widget/form/settings/avform.h
  8. 75
      src/widget/form/settings/avform.ui

18
src/audio/audio.cpp

@ -20,6 +20,7 @@ @@ -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 <QDebug>
@ -169,6 +170,19 @@ @@ -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;
}
}

22
src/audio/backend/openal2.cpp

@ -288,29 +288,36 @@ bool OpenAL2::loadOpenALExtensions(ALCdevice* dev) @@ -288,29 +288,36 @@ bool OpenAL2::loadOpenALExtensions(ALCdevice* dev)
// load OpenAL extension functions
alcLoopbackOpenDeviceSOFT = reinterpret_cast<LPALCLOOPBACKOPENDEVICESOFT>
(alcGetProcAddress(dev, "alcLoopbackOpenDeviceSOFT"));
checkAlcError(dev);
if(!alcLoopbackOpenDeviceSOFT) {
qDebug() << "Failed to load alcLoopbackOpenDeviceSOFT function!";
return false;
}
alcIsRenderFormatSupportedSOFT = reinterpret_cast<LPALCISRENDERFORMATSUPPORTEDSOFT>
(alcGetProcAddress(dev, "alcIsRenderFormatSupportedSOFT"));
checkAlcError(dev);
if(!alcIsRenderFormatSupportedSOFT) {
qDebug() << "Failed to load alcIsRenderFormatSupportedSOFT function!";
return false;
}
alGetSourcedvSOFT = reinterpret_cast<LPALGETSOURCEDVSOFT>
(alcGetProcAddress(dev, "alGetSourcedvSOFT"));
checkAlcError(dev);
if(!alGetSourcedvSOFT) {
qDebug() << "Failed to load alGetSourcedvSOFT function!";
return false;
}
alcRenderSamplesSOFT = reinterpret_cast<LPALCRENDERSAMPLESSOFT>
(alcGetProcAddress(alOutDev, "alcRenderSamplesSOFT"));
checkAlcError(dev);
if(!alcRenderSamplesSOFT) {
qDebug() << "Failed to load alcRenderSamplesSOFT function!";
return false;
}
return true;
}
@ -631,17 +638,14 @@ void OpenAL2::doOutput() @@ -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<LPALCRENDERSAMPLESSOFT> (alcGetProcAddress(alOutDev, "alcRenderSamplesSOFT"));
alcRenderSamplesSOFT(alProxyDev, outBuf, AUDIO_FRAME_SAMPLE_COUNT);
checkAlcError(alProxyDev);
alcMakeContextCurrent(alOutContext);
alBufferData(bufids[0], AL_FORMAT_MONO16, outBuf,

1
src/audio/backend/openal2.h

@ -139,6 +139,7 @@ private: @@ -139,6 +139,7 @@ private:
LPALCLOOPBACKOPENDEVICESOFT alcLoopbackOpenDeviceSOFT = nullptr;
LPALCISRENDERFORMATSUPPORTEDSOFT alcIsRenderFormatSupportedSOFT = nullptr;
LPALGETSOURCEDVSOFT alGetSourcedvSOFT = nullptr;
LPALCRENDERSAMPLESSOFT alcRenderSamplesSOFT = nullptr;
};
#endif // OPENAL2_H

21
src/persistence/settings.cpp

@ -265,6 +265,10 @@ void Settings::loadGlobal() @@ -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() @@ -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) @@ -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);

6
src/persistence/settings.h

@ -100,6 +100,7 @@ class Settings : public QObject @@ -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: @@ -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: @@ -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: @@ -617,6 +622,7 @@ private:
bool audioOutDevEnabled;
int outVolume;
bool enableTestSound;
bool enableBackend2;
// Video
QString videoDev;

9
src/widget/form/settings/avform.cpp

@ -60,6 +60,8 @@ AVForm::AVForm() @@ -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() @@ -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() @@ -552,3 +559,5 @@ void AVForm::retranslateUi()
{
Ui::AVForm::retranslateUi(this);
}

2
src/widget/form/settings/avform.h

@ -73,6 +73,8 @@ private slots: @@ -73,6 +73,8 @@ private slots:
void rescanDevices();
void on_cbEnableBackend2_stateChanged();
protected:
void updateVideoModes(int curIndex);

75
src/widget/form/settings/avform.ui

@ -30,8 +30,8 @@ @@ -30,8 +30,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>824</width>
<height>489</height>
<width>830</width>
<height>495</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
@ -44,30 +44,20 @@ @@ -44,30 +44,20 @@
<property name="bottomMargin">
<number>6</number>
</property>
<item row="0" column="1" colspan="2">
<widget class="QComboBox" name="outDevCombobox"/>
</item>
<item row="3" column="1" colspan="2">
<widget class="QSlider" name="microphoneSlider">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="microphoneLabel">
<item row="2" column="0">
<widget class="QLabel" name="inDevLabel">
<property name="text">
<string>Gain</string>
<string>Capture device</string>
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<widget class="QComboBox" name="inDevCombobox"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="outDevLabel">
<item row="1" column="2">
<widget class="QCheckBox" name="cbEnableTestSound">
<property name="text">
<string>Playback device</string>
<string>Test Sound</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
@ -84,12 +74,11 @@ @@ -84,12 +74,11 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="inDevLabel">
<property name="text">
<string>Capture device</string>
</property>
</widget>
<item row="2" column="1" colspan="2">
<widget class="QComboBox" name="inDevCombobox"/>
</item>
<item row="0" column="1" colspan="2">
<widget class="QComboBox" name="outDevCombobox"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="playbackLabel">
@ -98,14 +87,38 @@ @@ -98,14 +87,38 @@
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QCheckBox" name="cbEnableTestSound">
<item row="3" column="0">
<widget class="QLabel" name="microphoneLabel">
<property name="text">
<string>Test Sound</string>
<string>Gain</string>
</property>
<property name="checked">
</widget>
</item>
<item row="3" column="1" colspan="2">
<widget class="QSlider" name="microphoneSlider">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="outDevLabel">
<property name="text">
<string>Playback device</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="3">
<widget class="QCheckBox" name="cbEnableBackend2">
<property name="enabled">
<bool>true</bool>
</property>
<property name="toolTip">
<string>Enables the experimental audio backend with echo cancelling support, needs qTox restart to take effect.</string>
</property>
<property name="text">
<string>Enable experimental audio backend</string>
</property>
</widget>
</item>
</layout>

Loading…
Cancel
Save