Skip to content

Commit

Permalink
Fix gqrx-sdr#962 and restore the frequency after playback
Browse files Browse the repository at this point in the history
Try to parce center frequncy from a filename and apply it to waterfall.
Store current tuned frequency to a class member before switchng to IQ
file and restore it after playback ends.
My be fixes gqrx-sdr#977 too.
Restore offset freq after playback
Remove unused function
Update uiDockRxOpt widgets correctly
  • Loading branch information
vladisslav2011 committed Dec 18, 2021
1 parent c0f9b18 commit 08a99c3
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 21 deletions.
20 changes: 16 additions & 4 deletions src/applications/gqrx/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ MainWindow::MainWindow(const QString& cfgfile, bool edit_conf, QWidget *parent)
// I/Q playback
connect(iq_tool, SIGNAL(startRecording(QString)), this, SLOT(startIqRecording(QString)));
connect(iq_tool, SIGNAL(stopRecording()), this, SLOT(stopIqRecording()));
connect(iq_tool, SIGNAL(startPlayback(QString,float)), this, SLOT(startIqPlayback(QString,float)));
connect(iq_tool, SIGNAL(startPlayback(QString,float,double)), this, SLOT(startIqPlayback(QString,float,double)));
connect(iq_tool, SIGNAL(stopPlayback()), this, SLOT(stopIqPlayback()));
connect(iq_tool, SIGNAL(seek(qint64)), this,SLOT(seekIqFile(qint64)));

Expand Down Expand Up @@ -1588,7 +1588,7 @@ void MainWindow::stopIqRecording()
ui->statusBar->showMessage(tr("I/Q data recoding stopped"), 5000);
}

void MainWindow::startIqPlayback(const QString& filename, float samprate)
void MainWindow::startIqPlayback(const QString& filename, float samprate, double center_freq)
{
if (ui->actionDSP->isChecked())
{
Expand All @@ -1599,13 +1599,15 @@ void MainWindow::startIqPlayback(const QString& filename, float samprate)
storeSession();

auto sri = (int)samprate;
auto cf = (long long) center_freq;
QString escapedFilename = receiver::escape_filename(filename.toStdString()).c_str();
auto devstr = QString("file=%1,rate=%2,throttle=true,repeat=false")
.arg(escapedFilename).arg(sri);
auto devstr = QString("file=%1,rate=%2,freq=%3,throttle=true,repeat=false")
.arg(escapedFilename).arg(sri).arg(cf);

qDebug() << __func__ << ":" << devstr;

rx->set_input_device(devstr.toStdString());
updateHWFrequencyRange(false);

// sample rate
auto actual_rate = rx->set_input_rate(samprate);
Expand All @@ -1616,6 +1618,8 @@ void MainWindow::startIqPlayback(const QString& filename, float samprate)
uiDockRxOpt->setFilterOffsetRange((qint64)(actual_rate));
ui->plotter->setSampleRate(actual_rate);
ui->plotter->setSpanFreq((quint32)actual_rate);
on_plotter_newDemodFreq(center_freq + rx->get_filter_offset(), rx->get_filter_offset());

remote->setBandwidth(actual_rate);

// FIXME: would be nice with good/bad status
Expand Down Expand Up @@ -1659,6 +1663,14 @@ void MainWindow::stopIqPlayback()

// restore frequency, gain, etc...
uiDockInputCtl->readSettings(m_settings);
bool centerOK = false;
bool offsetOK = false;
qint64 oldCenter = m_settings->value("input/frequency", 0).toLongLong(&centerOK);
qint64 oldOffset = m_settings->value("receiver/offset", 0).toLongLong(&offsetOK);
if (centerOK && offsetOK)
{
on_plotter_newDemodFreq(oldCenter, oldOffset);
}

if (ui->actionDSP->isChecked())
{
Expand Down
2 changes: 1 addition & 1 deletion src/applications/gqrx/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private slots:
/* I/Q playback and recording*/
void startIqRecording(const QString& recdir);
void stopIqRecording();
void startIqPlayback(const QString& filename, float samprate);
void startIqPlayback(const QString& filename, float samprate, double center_freq);
void stopIqPlayback();
void seekIqFile(qint64 seek_pos);

Expand Down
41 changes: 29 additions & 12 deletions src/qtgui/iq_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ CIqTool::CIqTool(QWidget *parent) :
bytes_per_sample = 8;
sample_rate = 192000;
rec_len = 0;
center_freq = 1e8;

//ui->recDirEdit->setText(QDir::currentPath());
ui->sampleRateSpinBox->setValue(sample_rate);
ui->centerFreqSpinBox->setValue(center_freq);

recdir = new QDir(QDir::homePath(), "*.raw");

Expand Down Expand Up @@ -90,10 +93,10 @@ void CIqTool::on_listWidget_currentTextChanged(const QString &currentText)
current_file = currentText;
QFileInfo info(*recdir, current_file);

// Get duration of selected recording and update label
sample_rate = sampleRateFromFileName(currentText);
parseFileName(currentText);
rec_len = (int)(info.size() / (sample_rate * bytes_per_sample));

// Get duration of selected recording and update label
refreshTimeWidgets();

}
Expand Down Expand Up @@ -126,7 +129,7 @@ void CIqTool::on_playButton_clicked(bool checked)
ui->listWidget->setEnabled(false);
ui->recButton->setEnabled(false);
emit startPlayback(recdir->absoluteFilePath(current_file),
(float)sample_rate);
(float)sample_rate, center_freq);
}
}
else
Expand Down Expand Up @@ -275,7 +278,18 @@ void CIqTool::on_recDirButton_clicked()
if (!dir.isNull())
ui->recDirEdit->setText(dir);
}
#include <iostream>
void CIqTool::on_centerFreqSpinBox_valueChanged(double value)
{
center_freq = value * 1000.0;
std::cout<<"on_centerFreqSpinBox_valueChanged("<<value<<");"<<std::endl;
}

void CIqTool::on_sampleRateSpinBox_valueChanged(double value)
{
sample_rate = value * 1000.0;
std::cout<<"on_sampleRateSpinBox_valueChanged("<<value<<");"<<std::endl;
}


void CIqTool::timeoutFunction(void)
Expand Down Expand Up @@ -355,22 +369,25 @@ void CIqTool::refreshTimeWidgets(void)
}


/*! \brief Extract sample rate from file name */
qint64 CIqTool::sampleRateFromFileName(const QString &filename)
/*! \brief Extract sample rate and offset frequency from file name */
void CIqTool::parseFileName(const QString &filename)
{
bool ok;
bool sr_ok;
qint64 sr;
bool ofs_ok;
double ofs;

QStringList list = filename.split('_');

if (list.size() < 5)
return sample_rate;
return;

// gqrx_yymmdd_hhmmss_freq_samprate_fc.raw
sr = list.at(4).toLongLong(&ok);
sr = list.at(4).toLongLong(&sr_ok);
ofs = list.at(3).toDouble(&ofs_ok);

if (ok)
return sr;
else
return sample_rate; // return current rate
if (sr_ok)
ui->sampleRateSpinBox->setValue(sr/1000.0);
if (ofs_ok)
ui->centerFreqSpinBox->setValue(ofs/1000.0);
}
8 changes: 5 additions & 3 deletions src/qtgui/iq_tool.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class CIqTool : public QDialog
signals:
void startRecording(const QString recdir);
void stopRecording();
void startPlayback(const QString filename, float samprate);
void startPlayback(const QString filename, float samprate, double center_freq);
void stopPlayback();
void seek(qint64 seek_pos);

Expand All @@ -79,13 +79,14 @@ private slots:
void on_playButton_clicked(bool checked);
void on_slider_valueChanged(int value);
void on_listWidget_currentTextChanged(const QString &currentText);
void on_centerFreqSpinBox_valueChanged(double value);
void on_sampleRateSpinBox_valueChanged(double value);
void timeoutFunction(void);

private:
void refreshDir(void);
void refreshTimeWidgets(void);
qint64 sampleRateFromFileName(const QString &filename);

void parseFileName(const QString &filename);

private:
Ui::CIqTool *ui;
Expand All @@ -100,6 +101,7 @@ private slots:
bool is_playing;
int bytes_per_sample; /*!< Bytes per sample (fc = 4) */
int sample_rate; /*!< Current sample rate. */
double center_freq; /*!< Center frequency. */
int rec_len; /*!< Length of a recording in seconds */
};

Expand Down
76 changes: 75 additions & 1 deletion src/qtgui/iq_tool.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>482</width>
<width>499</width>
<height>327</height>
</rect>
</property>
Expand Down Expand Up @@ -209,6 +209,80 @@
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="sampleRateLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Sample Rate, ksps</string>
</property>
<property name="scaledContents">
<bool>false</bool>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="sampleRateSpinBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="maximum">
<double>999999.989999999990687</double>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="Frequency">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Frequency, kHz</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="centerFreqSpinBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="maximum">
<double>99999999.989999994635582</double>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QFrame" name="frame">
<property name="minimumSize">
Expand Down

0 comments on commit 08a99c3

Please sign in to comment.