1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-09-28 15:56:33 -04:00

DATV demod: audio volume (1)

This commit is contained in:
f4exb 2019-03-22 08:05:01 +01:00
parent 5b300c1033
commit 9e668f5f22
8 changed files with 98 additions and 5 deletions

View File

@ -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) if (m_settings.isDifferent(settings) || force)
{ {
m_objSettingsMutex.lock(); m_objSettingsMutex.lock();

View File

@ -234,6 +234,9 @@ void DATVDemodGUI::displaySettings()
ui->rfBandwidth->setValue(m_settings.m_rfBandwidth); ui->rfBandwidth->setValue(m_settings.m_rfBandwidth);
ui->spiSymbolRate->setValue(m_settings.m_symbolRate); ui->spiSymbolRate->setValue(m_settings.m_symbolRate);
ui->spiExcursion->setValue(m_settings.m_excursion); 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); blockApplySettings(false);
m_objChannelMarker.blockSignals(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_rollOff = ((float)ui->spiRollOff->value()) / 100.0f;
m_settings.m_viterbi = ui->chkViterbi->isChecked(); m_settings.m_viterbi = ui->chkViterbi->isChecked();
m_settings.m_excursion = ui->spiExcursion->value(); 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); QString msg = tr("DATVDemodGUI::applySettings: force: %1").arg(force);
m_settings.debug(msg); m_settings.debug(msg);
@ -628,6 +633,18 @@ void DATVDemodGUI::on_chkFastlock_clicked()
applySettings(); 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) void DATVDemodGUI::on_StreamMetaDataChanged(DataTSMetaData2 *objMetaData)
{ {
QString strMetaData=""; QString strMetaData="";

View File

@ -92,6 +92,8 @@ private slots:
void on_spiExcursion_valueChanged(int arg1); void on_spiExcursion_valueChanged(int arg1);
void on_deltaFrequency_changed(qint64 value); void on_deltaFrequency_changed(qint64 value);
void on_rfBandwidth_changed(qint64 value); void on_rfBandwidth_changed(qint64 value);
void on_audioMute_toggled(bool checked);
void on_audioVolume_valueChanged(int value);
private: private:
Ui::DATVDemodGUI* ui; Ui::DATVDemodGUI* ui;

View File

@ -204,7 +204,7 @@
<enum>QTabWidget::West</enum> <enum>QTabWidget::West</enum>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>0</number> <number>1</number>
</property> </property>
<widget class="QWidget" name="datvTab"> <widget class="QWidget" name="datvTab">
<attribute name="title"> <attribute name="title">
@ -961,6 +961,9 @@
<property name="maximum"> <property name="maximum">
<number>32</number> <number>32</number>
</property> </property>
<property name="pageStep">
<number>1</number>
</property>
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
@ -980,6 +983,9 @@
<property name="text"> <property name="text">
<string>-32</string> <string>-32</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</widget> </widget>
</widget> </widget>

View File

@ -49,6 +49,7 @@ void DATVDemodSettings::resetToDefaults()
m_excursion = 10; m_excursion = 10;
m_audioMute = false; m_audioMute = false;
m_audioDeviceName = AudioDeviceManager::m_defaultDeviceName; m_audioDeviceName = AudioDeviceManager::m_defaultDeviceName;
m_audioVolume = 0;
} }
QByteArray DATVDemodSettings::serialize() const QByteArray DATVDemodSettings::serialize() const
@ -77,6 +78,7 @@ QByteArray DATVDemodSettings::serialize() const
s.writeBool(18, m_viterbi); s.writeBool(18, m_viterbi);
s.writeS32(19, m_excursion); s.writeS32(19, m_excursion);
s.writeString(20, m_audioDeviceName); s.writeString(20, m_audioDeviceName);
s.writeS32(21, m_audioVolume);
return s.final(); return s.final();
} }
@ -136,6 +138,7 @@ bool DATVDemodSettings::deserialize(const QByteArray& data)
d.readBool(18, &m_viterbi, false); d.readBool(18, &m_viterbi, false);
d.readS32(19, &m_excursion, 10); d.readS32(19, &m_excursion, 10);
d.readString(20, &m_audioDeviceName, AudioDeviceManager::m_defaultDeviceName); d.readString(20, &m_audioDeviceName, AudioDeviceManager::m_defaultDeviceName);
d.readS32(21, &m_audioVolume, 0);
return true; return true;
} }
@ -164,7 +167,8 @@ void DATVDemodSettings::debug(const QString& msg) const
<< " m_symbolRate: " << m_symbolRate << " m_symbolRate: " << m_symbolRate
<< " m_excursion: " << m_excursion << " m_excursion: " << m_excursion
<< " m_audioMute: " << m_audioMute << " m_audioMute: " << m_audioMute
<< " m_audioDeviceName: " << m_audioDeviceName; << " m_audioDeviceName: " << m_audioDeviceName
<< " m_audioVolume: " << m_audioVolume;
} }
bool DATVDemodSettings::isDifferent(const DATVDemodSettings& other) bool DATVDemodSettings::isDifferent(const DATVDemodSettings& other)

View File

@ -72,6 +72,7 @@ struct DATVDemodSettings
float m_rollOff; float m_rollOff;
bool m_viterbi; bool m_viterbi;
int m_excursion; int m_excursion;
int m_audioVolume;
DATVDemodSettings(); DATVDemodSettings();
void resetToDefaults(); void resetToDefaults();

View File

@ -45,6 +45,9 @@ DATVideoRender::DATVideoRender(QWidget *parent) : TVScreen(true, parent)
m_audioFifoBufferIndex = 0; m_audioFifoBufferIndex = 0;
m_videoStreamIndex = -1; m_videoStreamIndex = -1;
m_audioStreamIndex = -1; m_audioStreamIndex = -1;
m_audioMute = false;
m_audioVolume = 0;
m_updateAudioResampler = false;
m_currentRenderWidth = -1; m_currentRenderWidth = -1;
m_currentRenderHeight = -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) bool DATVideoRender::eventFilter(QObject *obj, QEvent *event)
{ {
if (event->type() == QEvent::MouseButtonRelease) if (event->type() == QEvent::MouseButtonRelease)
@ -572,6 +582,12 @@ bool DATVideoRender::RenderStream()
// Audio channel // Audio channel
else if ((packet.stream_index == m_audioStreamIndex) && (m_audioFifo) && (swr_is_initialized(m_audioSWR))) 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)); memset(m_frame, 0, sizeof(AVFrame));
av_frame_unref(m_frame); av_frame_unref(m_frame);
gotFrame = 0; gotFrame = 0;
@ -629,8 +645,18 @@ bool DATVideoRender::RenderStream()
return true; return true;
} }
void DATVideoRender::setAudioVolume(int audioVolume)
{
m_audioVolume = audioVolume < -32 ? -32 : audioVolume > 32 ? 32 : audioVolume;
m_updateAudioResampler = true;
}
void DATVideoRender::setResampler() void DATVideoRender::setResampler()
{ {
if (m_audioSWR) {
swr_free(&m_audioSWR);
}
m_audioSWR = swr_alloc(); m_audioSWR = swr_alloc();
av_opt_set_int(m_audioSWR, "in_channel_count", m_audioDecoderCtx->channels, 0); av_opt_set_int(m_audioSWR, "in_channel_count", m_audioDecoderCtx->channels, 0);
av_opt_set_int(m_audioSWR, "out_channel_count", 2, 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_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, "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_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); 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) bool DATVideoRender::CloseStream(QIODevice *device)

View File

@ -87,6 +87,8 @@ class DATVideoRender : public TVScreen
public: public:
explicit DATVideoRender(QWidget *parent); explicit DATVideoRender(QWidget *parent);
~DATVideoRender();
void SetFullScreen(bool blnFullScreen); void SetFullScreen(bool blnFullScreen);
bool OpenStream(DATVideostream *objDevice); bool OpenStream(DATVideostream *objDevice);
@ -97,6 +99,9 @@ class DATVideoRender : public TVScreen
int getVideoStreamIndex() const { return m_videoStreamIndex; } int getVideoStreamIndex() const { return m_videoStreamIndex; }
int getAudioStreamIndex() const { return m_audioStreamIndex; } int getAudioStreamIndex() const { return m_audioStreamIndex; }
void setAudioMute(bool audioMute) { m_audioMute = audioMute; }
void setAudioVolume(int audioVolume);
struct DataTSMetaData2 MetaData; struct DataTSMetaData2 MetaData;
private: private:
@ -119,6 +124,9 @@ class DATVideoRender : public TVScreen
static const int m_audioFifoBufferSize = 16000; static const int m_audioFifoBufferSize = 16000;
uint16_t m_audioFifoBuffer[m_audioFifoBufferSize*2]; // 2 channels uint16_t m_audioFifoBuffer[m_audioFifoBufferSize*2]; // 2 channels
int m_audioFifoBufferIndex; int m_audioFifoBufferIndex;
bool m_audioMute;
int m_audioVolume;
bool m_updateAudioResampler;
uint8_t *m_pbytDecodedData[4]; uint8_t *m_pbytDecodedData[4];
int m_pintDecodedLineSize[4]; int m_pintDecodedLineSize[4];
@ -135,13 +143,11 @@ class DATVideoRender : public TVScreen
void ResetMetaData(); void ResetMetaData();
int new_decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt); int new_decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt);
void setResampler();
protected: protected:
virtual bool eventFilter(QObject *obj, QEvent *event); virtual bool eventFilter(QObject *obj, QEvent *event);
private:
void setResampler();
signals: signals:
void onMetaDataChanged(DataTSMetaData2 *metaData); void onMetaDataChanged(DataTSMetaData2 *metaData);
}; };