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.
Restore current tuned frequency and offset after playback ends.
My be fixes #977 too.
Remove unused function
Update uiDockRxOpt widgets correctly
  • Loading branch information
vladisslav2011 committed Dec 31, 2021
1 parent d9a989d commit ee3f480
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 22 deletions.
24 changes: 20 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,qint64)), this, SLOT(startIqPlayback(QString,float,qint64)));
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, qint64 center_freq)
{
if (ui->actionDSP->isChecked())
{
Expand All @@ -1599,13 +1599,16 @@ void MainWindow::startIqPlayback(const QString& filename, float samprate)
storeSession();

auto sri = (int)samprate;
auto cf = center_freq;
double current_offset = rx->get_filter_offset();
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 +1619,11 @@ void MainWindow::startIqPlayback(const QString& filename, float samprate)
uiDockRxOpt->setFilterOffsetRange((qint64)(actual_rate));
ui->plotter->setSampleRate(actual_rate);
ui->plotter->setSpanFreq((quint32)actual_rate);
if (std::abs(current_offset) > actual_rate / 2)
on_plotter_newDemodFreq(center_freq, 0);
else
on_plotter_newDemodFreq(center_freq + current_offset, current_offset);

remote->setBandwidth(actual_rate);

// FIXME: would be nice with good/bad status
Expand Down Expand Up @@ -1659,6 +1667,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, qint64 center_freq);
void stopIqPlayback();
void seekIqFile(qint64 seek_pos);

Expand Down
31 changes: 17 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,18 @@ void CIqTool::setSampleRate(qint64 sr)
}
}


/*! \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 +128,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 +278,6 @@ void CIqTool::on_recDirButton_clicked()
ui->recDirEdit->setText(dir);
}



void CIqTool::timeoutFunction(void)
{
refreshDir();
Expand Down Expand Up @@ -355,22 +355,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;
qint64 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).toLongLong(&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;
}
6 changes: 3 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, qint64 center_freq);
void stopPlayback();
void seek(qint64 seek_pos);

Expand All @@ -84,8 +84,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 +99,7 @@ private slots:
bool is_playing;
int bytes_per_sample; /*!< Bytes per sample (fc = 4) */
int sample_rate; /*!< Current sample rate. */
qint64 center_freq; /*!< Center frequency. */
int rec_len; /*!< Length of a recording in seconds */
};

Expand Down

0 comments on commit ee3f480

Please sign in to comment.