diff --git a/plugins/channelrx/demoddatv/datvdemod.cpp b/plugins/channelrx/demoddatv/datvdemod.cpp
index 9401487d7..45ba214e7 100644
--- a/plugins/channelrx/demoddatv/datvdemod.cpp
+++ b/plugins/channelrx/demoddatv/datvdemod.cpp
@@ -947,6 +947,20 @@ void DATVDemod::applySettings(const DATVDemodSettings& settings, bool force)
// }
}
+ if ((settings.m_audioVolume) != (m_settings.m_audioVolume) || force)
+ {
+ if (m_objRegisteredVideoRender) {
+ m_objRegisteredVideoRender->setAudioVolume(settings.m_audioVolume);
+ }
+ }
+
+ if ((settings.m_audioMute) != (m_settings.m_audioMute) || force)
+ {
+ if (m_objRegisteredVideoRender) {
+ m_objRegisteredVideoRender->setAudioMute(settings.m_audioMute);
+ }
+ }
+
if (m_settings.isDifferent(settings) || force)
{
m_objSettingsMutex.lock();
diff --git a/plugins/channelrx/demoddatv/datvdemodgui.cpp b/plugins/channelrx/demoddatv/datvdemodgui.cpp
index 1a0cd6a3f..01b61ffec 100644
--- a/plugins/channelrx/demoddatv/datvdemodgui.cpp
+++ b/plugins/channelrx/demoddatv/datvdemodgui.cpp
@@ -234,6 +234,9 @@ void DATVDemodGUI::displaySettings()
ui->rfBandwidth->setValue(m_settings.m_rfBandwidth);
ui->spiSymbolRate->setValue(m_settings.m_symbolRate);
ui->spiExcursion->setValue(m_settings.m_excursion);
+ ui->audioMute->setChecked(m_settings.m_audioMute);
+ ui->audioVolume->setValue(m_settings.m_audioVolume);
+ ui->audioVolumeText->setText(tr("%1").arg(m_settings.m_audioVolume));
blockApplySettings(false);
m_objChannelMarker.blockSignals(false);
@@ -347,6 +350,8 @@ void DATVDemodGUI::applySettings(bool force)
m_settings.m_rollOff = ((float)ui->spiRollOff->value()) / 100.0f;
m_settings.m_viterbi = ui->chkViterbi->isChecked();
m_settings.m_excursion = ui->spiExcursion->value();
+ m_settings.m_audioMute = ui->audioMute->isChecked();
+ m_settings.m_audioVolume = ui->audioVolume->value();
QString msg = tr("DATVDemodGUI::applySettings: force: %1").arg(force);
m_settings.debug(msg);
@@ -628,6 +633,18 @@ void DATVDemodGUI::on_chkFastlock_clicked()
applySettings();
}
+void DATVDemodGUI::on_audioMute_toggled(bool checked)
+{
+ (void) checked;
+ applySettings();
+}
+
+void DATVDemodGUI::on_audioVolume_valueChanged(int value)
+{
+ ui->audioVolumeText->setText(tr("%1").arg(value));
+ applySettings();
+}
+
void DATVDemodGUI::on_StreamMetaDataChanged(DataTSMetaData2 *objMetaData)
{
QString strMetaData="";
diff --git a/plugins/channelrx/demoddatv/datvdemodgui.h b/plugins/channelrx/demoddatv/datvdemodgui.h
index bc1d09cf2..8dfb66c5f 100644
--- a/plugins/channelrx/demoddatv/datvdemodgui.h
+++ b/plugins/channelrx/demoddatv/datvdemodgui.h
@@ -92,6 +92,8 @@ private slots:
void on_spiExcursion_valueChanged(int arg1);
void on_deltaFrequency_changed(qint64 value);
void on_rfBandwidth_changed(qint64 value);
+ void on_audioMute_toggled(bool checked);
+ void on_audioVolume_valueChanged(int value);
private:
Ui::DATVDemodGUI* ui;
diff --git a/plugins/channelrx/demoddatv/datvdemodgui.ui b/plugins/channelrx/demoddatv/datvdemodgui.ui
index ab170f766..586c8c7a1 100644
--- a/plugins/channelrx/demoddatv/datvdemodgui.ui
+++ b/plugins/channelrx/demoddatv/datvdemodgui.ui
@@ -204,7 +204,7 @@
QTabWidget::West
- 0
+ 1
@@ -961,6 +961,9 @@
32
+
+ 1
+
Qt::Horizontal
@@ -980,6 +983,9 @@
-32
+
+ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
+
diff --git a/plugins/channelrx/demoddatv/datvdemodsettings.cpp b/plugins/channelrx/demoddatv/datvdemodsettings.cpp
index 0f0d39c56..704d3bf43 100644
--- a/plugins/channelrx/demoddatv/datvdemodsettings.cpp
+++ b/plugins/channelrx/demoddatv/datvdemodsettings.cpp
@@ -49,6 +49,7 @@ void DATVDemodSettings::resetToDefaults()
m_excursion = 10;
m_audioMute = false;
m_audioDeviceName = AudioDeviceManager::m_defaultDeviceName;
+ m_audioVolume = 0;
}
QByteArray DATVDemodSettings::serialize() const
@@ -77,6 +78,7 @@ QByteArray DATVDemodSettings::serialize() const
s.writeBool(18, m_viterbi);
s.writeS32(19, m_excursion);
s.writeString(20, m_audioDeviceName);
+ s.writeS32(21, m_audioVolume);
return s.final();
}
@@ -136,6 +138,7 @@ bool DATVDemodSettings::deserialize(const QByteArray& data)
d.readBool(18, &m_viterbi, false);
d.readS32(19, &m_excursion, 10);
d.readString(20, &m_audioDeviceName, AudioDeviceManager::m_defaultDeviceName);
+ d.readS32(21, &m_audioVolume, 0);
return true;
}
@@ -164,7 +167,8 @@ void DATVDemodSettings::debug(const QString& msg) const
<< " m_symbolRate: " << m_symbolRate
<< " m_excursion: " << m_excursion
<< " m_audioMute: " << m_audioMute
- << " m_audioDeviceName: " << m_audioDeviceName;
+ << " m_audioDeviceName: " << m_audioDeviceName
+ << " m_audioVolume: " << m_audioVolume;
}
bool DATVDemodSettings::isDifferent(const DATVDemodSettings& other)
diff --git a/plugins/channelrx/demoddatv/datvdemodsettings.h b/plugins/channelrx/demoddatv/datvdemodsettings.h
index 2b58d202e..1c031a451 100644
--- a/plugins/channelrx/demoddatv/datvdemodsettings.h
+++ b/plugins/channelrx/demoddatv/datvdemodsettings.h
@@ -72,6 +72,7 @@ struct DATVDemodSettings
float m_rollOff;
bool m_viterbi;
int m_excursion;
+ int m_audioVolume;
DATVDemodSettings();
void resetToDefaults();
diff --git a/plugins/channelrx/demoddatv/datvideorender.cpp b/plugins/channelrx/demoddatv/datvideorender.cpp
index b48588348..5d490ef85 100644
--- a/plugins/channelrx/demoddatv/datvideorender.cpp
+++ b/plugins/channelrx/demoddatv/datvideorender.cpp
@@ -45,6 +45,9 @@ DATVideoRender::DATVideoRender(QWidget *parent) : TVScreen(true, parent)
m_audioFifoBufferIndex = 0;
m_videoStreamIndex = -1;
m_audioStreamIndex = -1;
+ m_audioMute = false;
+ m_audioVolume = 0;
+ m_updateAudioResampler = false;
m_currentRenderWidth = -1;
m_currentRenderHeight = -1;
@@ -59,6 +62,13 @@ DATVideoRender::DATVideoRender(QWidget *parent) : TVScreen(true, parent)
// }
}
+DATVideoRender::~DATVideoRender()
+{
+ if (m_audioSWR) {
+ swr_free(&m_audioSWR);
+ }
+}
+
bool DATVideoRender::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::MouseButtonRelease)
@@ -572,6 +582,12 @@ bool DATVideoRender::RenderStream()
// Audio channel
else if ((packet.stream_index == m_audioStreamIndex) && (m_audioFifo) && (swr_is_initialized(m_audioSWR)))
{
+ if (m_updateAudioResampler)
+ {
+ setResampler();
+ m_updateAudioResampler = false;
+ }
+
memset(m_frame, 0, sizeof(AVFrame));
av_frame_unref(m_frame);
gotFrame = 0;
@@ -629,8 +645,18 @@ bool DATVideoRender::RenderStream()
return true;
}
+void DATVideoRender::setAudioVolume(int audioVolume)
+{
+ m_audioVolume = audioVolume < -32 ? -32 : audioVolume > 32 ? 32 : audioVolume;
+ m_updateAudioResampler = true;
+}
+
void DATVideoRender::setResampler()
{
+ if (m_audioSWR) {
+ swr_free(&m_audioSWR);
+ }
+
m_audioSWR = swr_alloc();
av_opt_set_int(m_audioSWR, "in_channel_count", m_audioDecoderCtx->channels, 0);
av_opt_set_int(m_audioSWR, "out_channel_count", 2, 0);
@@ -640,7 +666,24 @@ void DATVideoRender::setResampler()
av_opt_set_int(m_audioSWR, "out_sample_rate", m_audioSampleRate, 0);
av_opt_set_sample_fmt(m_audioSWR, "in_sample_fmt", m_audioDecoderCtx->sample_fmt, 0);
av_opt_set_sample_fmt(m_audioSWR, "out_sample_fmt", AV_SAMPLE_FMT_S16, 0);
+ av_opt_set_int(m_audioSWR, "center_mix_level", m_audioVolume, 0);
+ av_opt_set_int(m_audioSWR, "surround_mix_level", m_audioVolume, 0);
+ av_opt_set_int(m_audioSWR, "lfe_mix_level", m_audioVolume, 0);
+
swr_init(m_audioSWR);
+
+ qDebug() << "DATVideoRender::setResampler: "
+ << " in_channel_count: " << m_audioDecoderCtx->channels
+ << " out_channel_count: " << 2
+ << " in_channel_layout: " << m_audioDecoderCtx->channel_layout
+ << " out_channel_layout: " << AV_CH_LAYOUT_STEREO
+ << " in_sample_rate: " << m_audioDecoderCtx->sample_rate
+ << " out_sample_rate: " << m_audioSampleRate
+ << " in_sample_fmt: " << m_audioDecoderCtx->sample_fmt
+ << " out_sample_fmt: " << AV_SAMPLE_FMT_S16
+ << " center_mix_level: " << m_audioVolume
+ << " surround_mix_level: " << m_audioVolume
+ << " lfe_mix_level: " << m_audioVolume;
}
bool DATVideoRender::CloseStream(QIODevice *device)
diff --git a/plugins/channelrx/demoddatv/datvideorender.h b/plugins/channelrx/demoddatv/datvideorender.h
index 76fd64c07..bb23623b7 100644
--- a/plugins/channelrx/demoddatv/datvideorender.h
+++ b/plugins/channelrx/demoddatv/datvideorender.h
@@ -87,6 +87,8 @@ class DATVideoRender : public TVScreen
public:
explicit DATVideoRender(QWidget *parent);
+ ~DATVideoRender();
+
void SetFullScreen(bool blnFullScreen);
bool OpenStream(DATVideostream *objDevice);
@@ -97,6 +99,9 @@ class DATVideoRender : public TVScreen
int getVideoStreamIndex() const { return m_videoStreamIndex; }
int getAudioStreamIndex() const { return m_audioStreamIndex; }
+ void setAudioMute(bool audioMute) { m_audioMute = audioMute; }
+ void setAudioVolume(int audioVolume);
+
struct DataTSMetaData2 MetaData;
private:
@@ -119,6 +124,9 @@ class DATVideoRender : public TVScreen
static const int m_audioFifoBufferSize = 16000;
uint16_t m_audioFifoBuffer[m_audioFifoBufferSize*2]; // 2 channels
int m_audioFifoBufferIndex;
+ bool m_audioMute;
+ int m_audioVolume;
+ bool m_updateAudioResampler;
uint8_t *m_pbytDecodedData[4];
int m_pintDecodedLineSize[4];
@@ -135,13 +143,11 @@ class DATVideoRender : public TVScreen
void ResetMetaData();
int new_decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt);
+ void setResampler();
protected:
virtual bool eventFilter(QObject *obj, QEvent *event);
- private:
- void setResampler();
-
signals:
void onMetaDataChanged(DataTSMetaData2 *metaData);
};