Skip to content

Commit

Permalink
Fix #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.
If parcing the file fails, default to last sample rate/center frequency.
Store current tuned frequency to a class member before switchng to IQ
file and restore it after playback ends.
My be fixes #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 510c45a
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 22 deletions.
22 changes: 18 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 Expand Up @@ -1971,6 +1983,8 @@ void MainWindow::on_actionSaveWaterfall_triggered()
/** Show I/Q player. */
void MainWindow::on_actionIqTool_triggered()
{
iq_tool->setSampleRate(rx->get_input_rate());
iq_tool->setCenterFreq(rx->get_rf_freq());
iq_tool->show();
}

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
37 changes: 23 additions & 14 deletions src/qtgui/iq_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ CIqTool::CIqTool(QWidget *parent) :
bytes_per_sample = 8;
sample_rate = 192000;
rec_len = 0;
center_freq = 1e8;

//ui->recDirEdit->setText(QDir::currentPath());

Expand Down Expand Up @@ -83,17 +84,24 @@ void CIqTool::setSampleRate(qint64 sr)
}
}

/*! \brief Set new center frequency. */
void CIqTool::setCenterFreq(double freq)
{
center_freq = freq;
}


/*! \brief Slot activated when the user selects a file. */
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 +134,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 @@ -276,8 +284,6 @@ void CIqTool::on_recDirButton_clicked()
ui->recDirEdit->setText(dir);
}



void CIqTool::timeoutFunction(void)
{
refreshDir();
Expand Down Expand Up @@ -355,22 +361,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 center_ok;
double center;

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);
center = list.at(3).toDouble(&center_ok);

if (ok)
return sr;
else
return sample_rate; // return current rate
if (sr_ok)
sample_rate = sr;
if (center_ok)
center_freq = center;
}
7 changes: 4 additions & 3 deletions src/qtgui/iq_tool.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class CIqTool : public QDialog
~CIqTool();

void setSampleRate(qint64 sr);
void setCenterFreq(double freq);

void closeEvent(QCloseEvent *event);
void showEvent(QShowEvent * event);
Expand All @@ -64,7 +65,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 @@ -84,8 +85,7 @@ private slots:
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 +100,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

0 comments on commit 510c45a

Please sign in to comment.