Skip to content

Commit

Permalink
Add audio gain setting
Browse files Browse the repository at this point in the history
  • Loading branch information
clementgallet committed Aug 9, 2024
1 parent d05112e commit b2ab662
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Add input events in movies
* Offer undo/redo in input editor
* Highlight undo/redo operations
* Audio gain setting

### Changed
### Fixed
Expand Down
5 changes: 4 additions & 1 deletion src/library/audio/AudioSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,10 @@ int AudioSource::mixWith( struct timespec ticks, uint8_t* outSamples, int outByt
*
* TODO: This is where we can support panning.
*/
float resultVolume = (volume * outVolume) > 1.0?1.0:(volume*outVolume);
float resultVolume = volume * outVolume * Global::shared_config.audio_gain;
if (resultVolume > 1.0f)
resultVolume = 1.0f;

int lvas = (int)(resultVolume * 65536.0f);
int rvas = (int)(resultVolume * 65536.0f);

Expand Down
41 changes: 38 additions & 3 deletions src/program/ui/settings/AudioPane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@
#include <QtWidgets/QLabel>
#include <QtWidgets/QGroupBox>
#include <QtWidgets/QFormLayout>
#include <QtWidgets/QHBoxLayout>
#include <QtWidgets/QVBoxLayout>
#include <QtWidgets/QComboBox>
#include <QtWidgets/QCheckBox>
#include <QtWidgets/QSpinBox>
#include <QtWidgets/QSlider>

AudioPane::AudioPane(Context* c) : context(c)
{
Expand Down Expand Up @@ -83,9 +86,29 @@ void AudioPane::initLayout()
controlLayout->addWidget(disableBox);
controlLayout->addWidget(preferOpenAlBox);

QVBoxLayout* const mainLayout = new QVBoxLayout;
mainLayout->addWidget(formatBox);
mainLayout->addWidget(controlBox);
QGroupBox* gainBox = new QGroupBox(tr("Audio Gain"));
QVBoxLayout* gainLayout = new QVBoxLayout;
gainBox->setLayout(gainLayout);

gainSlider = new QSlider(Qt::Vertical);
gainSlider->setRange(0, 100);
gainSlider->setSingleStep(1);
gainSlider->setPageStep(10);
gainSlider->setTracking(false);

gainValue = new QSpinBox();
gainValue->setRange(0, 100);

gainLayout->addWidget(gainSlider);
gainLayout->addWidget(gainValue);

QVBoxLayout* const sideLayout = new QVBoxLayout;
sideLayout->addWidget(formatBox);
sideLayout->addWidget(controlBox);

QHBoxLayout* const mainLayout = new QHBoxLayout;
mainLayout->addLayout(sideLayout, 1);
mainLayout->addWidget(gainBox);

setLayout(mainLayout);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
Expand All @@ -99,6 +122,10 @@ void AudioPane::initSignals()
connect(muteBox, &QAbstractButton::clicked, this, &AudioPane::saveConfig);
connect(disableBox, &QAbstractButton::clicked, this, &AudioPane::saveConfig);
connect(preferOpenAlBox, &QAbstractButton::clicked, this, &AudioPane::saveConfig);
connect(gainValue, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), gainSlider, &QSlider::setValue);
connect(gainValue, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &AudioPane::saveConfig);
connect(gainSlider, &QSlider::valueChanged, this, &AudioPane::saveConfig);
connect(gainSlider, &QSlider::valueChanged, gainValue, &QSpinBox::setValue);
}

void AudioPane::initToolTips()
Expand Down Expand Up @@ -142,6 +169,13 @@ void AudioPane::loadConfig()
muteBox->setChecked(context->config.sc.audio_mute);
disableBox->setChecked(context->config.sc.audio_disabled);
preferOpenAlBox->setChecked(context->config.sc.openal_soft);

gainValue->setValue(context->config.sc.audio_gain * 100.0f);

/* Disconnect to not trigger valueChanged() signal */
disconnect(gainSlider, &QSlider::valueChanged, this, &AudioPane::saveConfig);
gainSlider->setValue(context->config.sc.audio_gain * 100.0f);
connect(gainSlider, &QSlider::valueChanged, this, &AudioPane::saveConfig);
}

void AudioPane::saveConfig()
Expand All @@ -152,6 +186,7 @@ void AudioPane::saveConfig()
context->config.sc.audio_mute = muteBox->isChecked();
context->config.sc.audio_disabled = disableBox->isChecked();
context->config.sc.openal_soft = preferOpenAlBox->isChecked();
context->config.sc.audio_gain = ((float) gainValue->value()) / 100.0f;
context->config.sc_modified = true;
}

Expand Down
5 changes: 5 additions & 0 deletions src/program/ui/settings/AudioPane.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
class Context;
class QComboBox;
class QCheckBox;
class QSpinBox;
class QSlider;
class ToolTipCheckBox;

class AudioPane : public QWidget {
Expand All @@ -47,6 +49,9 @@ class AudioPane : public QWidget {
QComboBox* depthChoice;
QComboBox* channelChoice;

QSlider* gainSlider;
QSpinBox* gainValue;

ToolTipCheckBox* muteBox;
ToolTipCheckBox* disableBox;
ToolTipCheckBox* preferOpenAlBox;
Expand Down
3 changes: 3 additions & 0 deletions src/shared/SharedConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ struct __attribute__((packed, aligned(8))) SharedConfig {
/* Frequency of buffer in Hz */
int audio_frequency = 44100;

/* Audio gain from 0.0 to 1.0 */
float audio_gain = 1.0f;

/* Video codec */
enum VCodec {
VCODEC_X264,
Expand Down

0 comments on commit b2ab662

Please sign in to comment.