From e89331f58f4c0130acd72b0ddd760d65b91e98b1 Mon Sep 17 00:00:00 2001 From: f4exb Date: Tue, 8 Nov 2022 22:55:40 +0100 Subject: [PATCH] Audio output device recording: GUI and settings --- sdrbase/audio/audiodevicemanager.h | 10 ++- sdrgui/gui/audiodialog.cpp | 47 ++++++++++++ sdrgui/gui/audiodialog.h | 3 + sdrgui/gui/audiodialog.ui | 113 +++++++++++++++++++++++++++++ 4 files changed, 172 insertions(+), 1 deletion(-) diff --git a/sdrbase/audio/audiodevicemanager.h b/sdrbase/audio/audiodevicemanager.h index 1df909208..2966d6f41 100644 --- a/sdrbase/audio/audiodevicemanager.h +++ b/sdrbase/audio/audiodevicemanager.h @@ -62,7 +62,9 @@ public: udpUseRTP(false), udpChannelMode(AudioOutputDevice::UDPChannelLeft), udpChannelCodec(AudioOutputDevice::UDPCodecL16), - udpDecimationFactor(1) + udpDecimationFactor(1), + recordToFile(false), + recordSilenceTime(0) {} void resetToDefaults() { sampleRate = m_defaultAudioSampleRate; @@ -73,6 +75,9 @@ public: udpChannelMode = AudioOutputDevice::UDPChannelLeft; udpChannelCodec = AudioOutputDevice::UDPCodecL16; udpDecimationFactor = 1; + fileRecordName.clear(); + recordToFile = false; + recordSilenceTime = 0; } int sampleRate; QString udpAddress; @@ -82,6 +87,9 @@ public: AudioOutputDevice::UDPChannelMode udpChannelMode; AudioOutputDevice::UDPChannelCodec udpChannelCodec; uint32_t udpDecimationFactor; + QString fileRecordName; + bool recordToFile; + int recordSilenceTime; //!< 100's ms friend QDataStream& operator<<(QDataStream& ds, const OutputDeviceInfo& info); friend QDataStream& operator>>(QDataStream& ds, OutputDeviceInfo& info); }; diff --git a/sdrgui/gui/audiodialog.cpp b/sdrgui/gui/audiodialog.cpp index fdc098049..7b8cadd4e 100644 --- a/sdrgui/gui/audiodialog.cpp +++ b/sdrgui/gui/audiodialog.cpp @@ -20,6 +20,7 @@ #include #include +#include #include "audio/audiodevicemanager.h" #include "audiodialog.h" @@ -259,6 +260,44 @@ void AudioDialogX::on_outputUDPChannelMode_currentIndexChanged(int index) check(); } +void AudioDialogX::on_record_toggled(bool checked) +{ + ui->showFileDialog->setEnabled(!checked); + m_outputDeviceInfo.recordToFile = checked; +} + +void AudioDialogX::on_showFileDialog_clicked(bool checked) +{ + (void) checked; + QFileDialog fileDialog( + this, + tr("Save record file"), + m_outputDeviceInfo.fileRecordName, + tr("WAV Files (*.wav)") + ); + + fileDialog.setOptions(QFileDialog::DontUseNativeDialog); + fileDialog.setFileMode(QFileDialog::AnyFile); + QStringList fileNames; + + if (fileDialog.exec()) + { + fileNames = fileDialog.selectedFiles(); + + if (fileNames.size() > 0) + { + m_outputDeviceInfo.fileRecordName = fileNames.at(0); + ui->fileNameText->setText(m_outputDeviceInfo.fileRecordName); + } + } +} + +void AudioDialogX::on_recordSilenceTime_valueChanged(int value) +{ + m_outputDeviceInfo.recordSilenceTime = value; + ui->recordSilenceText->setText(tr("%1").arg(value / 10.0, 0, 'f', 1)); +} + void AudioDialogX::updateOutputDisplay() { ui->outputSampleRate->blockSignals(true); @@ -274,6 +313,11 @@ void AudioDialogX::updateOutputDisplay() ui->outputUDPChannelMode->setCurrentIndex((int) m_outputDeviceInfo.udpChannelMode); ui->outputUDPChannelCodec->setCurrentIndex((int) m_outputDeviceInfo.udpChannelCodec); ui->decimationFactor->setCurrentIndex(m_outputDeviceInfo.udpDecimationFactor == 0 ? 0 : m_outputDeviceInfo.udpDecimationFactor - 1); + ui->record->setChecked(m_outputDeviceInfo.recordToFile); + ui->fileNameText->setText(m_outputDeviceInfo.fileRecordName); + ui->showFileDialog->setEnabled(!m_outputDeviceInfo.recordToFile); + ui->recordSilenceTime->setValue(m_outputDeviceInfo.recordSilenceTime); + ui->recordSilenceText->setText(tr("%1").arg(m_outputDeviceInfo.recordSilenceTime / 10.0, 0, 'f', 1)); updateOutputSDPString(); @@ -293,6 +337,9 @@ void AudioDialogX::updateOutputDeviceInfo() m_outputDeviceInfo.udpChannelMode = (AudioOutputDevice::UDPChannelMode) ui->outputUDPChannelMode->currentIndex(); m_outputDeviceInfo.udpChannelCodec = (AudioOutputDevice::UDPChannelCodec) ui->outputUDPChannelCodec->currentIndex(); m_outputDeviceInfo.udpDecimationFactor = ui->decimationFactor->currentIndex() + 1; + m_outputDeviceInfo.recordToFile = ui->record->isChecked(); + m_outputDeviceInfo.fileRecordName = ui->fileNameText->text(); + m_outputDeviceInfo.recordSilenceTime = ui->recordSilenceTime->value(); } void AudioDialogX::updateOutputSDPString() diff --git a/sdrgui/gui/audiodialog.h b/sdrgui/gui/audiodialog.h index 4c237fbce..3384726ae 100644 --- a/sdrgui/gui/audiodialog.h +++ b/sdrgui/gui/audiodialog.h @@ -52,6 +52,9 @@ private slots: void on_decimationFactor_currentIndexChanged(int index); void on_outputUDPChannelCodec_currentIndexChanged(int index); void on_outputUDPChannelMode_currentIndexChanged(int index); + void on_record_toggled(bool checked); + void on_showFileDialog_clicked(bool checked); + void on_recordSilenceTime_valueChanged(int value); }; #endif // INCLUDE_AUDIODIALOG_H diff --git a/sdrgui/gui/audiodialog.ui b/sdrgui/gui/audiodialog.ui index b48550b03..667dd3e72 100644 --- a/sdrgui/gui/audiodialog.ui +++ b/sdrgui/gui/audiodialog.ui @@ -390,6 +390,119 @@ + + + + + + + 24 + 16777215 + + + + Start/stop recording + + + + + + + :/record_off.png:/record_off.png + + + + + + + + 24 + 24 + + + + + 24 + 24 + + + + Open file + + + + + + + :/preset-load.png:/preset-load.png + + + + + + + true + + + Current recording file + + + ... + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + 24 + 24 + + + + Silence time (s) before recording is stopoed. 0 for continuous recording. + + + 0 + + + 100 + + + 1 + + + 1 + + + 0 + + + + + + + + 30 + 16777215 + + + + Silence time (s) before recording is stopoed + + + 10.0 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + +