Skip to content

Commit

Permalink
iq_formats: Implement recording/playback of different sample formats
Browse files Browse the repository at this point in the history
  • Loading branch information
vladisslav2011 committed Jul 28, 2023
1 parent a717247 commit 42583f0
Show file tree
Hide file tree
Showing 9 changed files with 880 additions and 109 deletions.
46 changes: 35 additions & 11 deletions src/applications/gqrx/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ MainWindow::MainWindow(const QString& cfgfile, bool edit_conf, QWidget *parent)
ui(new Ui::MainWindow),
d_lnb_lo(0),
d_hw_freq(0),
d_ignore_limits(false),
d_fftAvg(0.25),
d_fftNormalizeEnergy(false),
d_have_audio(true),
Expand Down Expand Up @@ -310,9 +311,9 @@ MainWindow::MainWindow(const QString& cfgfile, bool edit_conf, QWidget *parent)
connect(&DXCSpots::Get(), SIGNAL(dxcSpotsUpdated()), this, SLOT(updateClusterSpots()));

// I/Q playback
connect(iq_tool, SIGNAL(startRecording(QString)), this, SLOT(startIqRecording(QString)));
connect(iq_tool, SIGNAL(startRecording(QString, enum receiver::file_formats)), this, SLOT(startIqRecording(QString, enum receiver::file_formats)));
connect(iq_tool, SIGNAL(stopRecording()), this, SLOT(stopIqRecording()));
connect(iq_tool, SIGNAL(startPlayback(QString,float,qint64)), this, SLOT(startIqPlayback(QString,float,qint64)));
connect(iq_tool, SIGNAL(startPlayback(QString, float, qint64, enum receiver::file_formats)), this, SLOT(startIqPlayback(QString, float, qint64, enum receiver::file_formats)));
connect(iq_tool, SIGNAL(stopPlayback()), this, SLOT(stopIqPlayback()));
connect(iq_tool, SIGNAL(seek(qint64)), this,SLOT(seekIqFile(qint64)));

Expand Down Expand Up @@ -1646,25 +1647,50 @@ void MainWindow::stopAudioStreaming()
}

/** Start I/Q recording. */
void MainWindow::startIqRecording(const QString& recdir)
void MainWindow::startIqRecording(const QString& recdir, receiver::file_formats fmt)
{
qDebug() << __func__;
// generate file name using date, time, rf freq in kHz and BW in Hz
// gqrx_iq_yyyymmdd_hhmmss_freq_bw_fc.raw
auto freq = qRound64(rx->get_rf_freq());
auto sr = qRound64(rx->get_input_rate());
auto dec = (quint32)(rx->get_input_decim());
QString suffix = "fc";
switch(fmt)
{
case receiver::FILE_FORMAT_CS8:
suffix = "8";
break;
case receiver::FILE_FORMAT_CS16L:
suffix = "16";
break;
case receiver::FILE_FORMAT_CS32L:
suffix = "32";
break;
case receiver::FILE_FORMAT_CS8U:
suffix = "8u";
break;
case receiver::FILE_FORMAT_CS16LU:
suffix = "16u";
break;
case receiver::FILE_FORMAT_CS32LU:
suffix = "32u";
break;
default:
fmt = receiver::FILE_FORMAT_CF;
suffix = "fc";
}
auto lastRec = QDateTime::currentDateTimeUtc().
toString("%1/gqrx_yyyyMMdd_hhmmss_%2_%3_fc.'raw'")
.arg(recdir).arg(freq).arg(sr/dec);
toString("%1/gqrx_yyyyMMdd_hhmmss_%2_%3_%4.'raw'")
.arg(recdir).arg(freq).arg(sr/dec).arg(suffix);

ui->actionIoConfig->setDisabled(true);
ui->actionLoadSettings->setDisabled(true);
// start recorder; fails if recording already in progress
if (rx->start_iq_recording(lastRec.toStdString()))
if (rx->start_iq_recording(lastRec.toStdString(), fmt))
{
// reset action status
ui->statusBar->showMessage(tr("Error starting I/Q recoder"));
iq_tool->cancelRecording();

// show an error message to user
QMessageBox msg_box;
Expand Down Expand Up @@ -1694,7 +1720,7 @@ void MainWindow::stopIqRecording()
ui->actionLoadSettings->setDisabled(false);
}

void MainWindow::startIqPlayback(const QString& filename, float samprate, qint64 center_freq)
void MainWindow::startIqPlayback(const QString& filename, float samprate, qint64 center_freq, enum receiver::file_formats fmt)
{
if (ui->actionDSP->isChecked())
{
Expand All @@ -1715,6 +1741,7 @@ void MainWindow::startIqPlayback(const QString& filename, float samprate, qint64

rx->set_input_device(devstr.toStdString());
updateHWFrequencyRange(false);
rx->set_input_file(filename.toStdString(), samprate, fmt);

// sample rate
auto actual_rate = rx->set_input_rate((double)samprate);
Expand Down Expand Up @@ -1772,9 +1799,6 @@ void MainWindow::stopIqPlayback()
ui->plotter->setSampleRate(actual_rate);
ui->plotter->setSpanFreq((quint32)actual_rate);
remote->setBandwidth(sr);

// not needed as long as we are not recording in iq_tool
//iq_tool->setSampleRate(sr);
}

// restore frequency, gain, etc...
Expand Down
4 changes: 2 additions & 2 deletions src/applications/gqrx/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ private slots:
void stopAudioStreaming();

/* I/Q playback and recording*/
void startIqRecording(const QString& recdir);
void startIqRecording(const QString& recdir, enum receiver::file_formats fmt);
void stopIqRecording();
void startIqPlayback(const QString& filename, float samprate, qint64 center_freq);
void startIqPlayback(const QString& filename, float samprate, qint64 center_freq, enum receiver::file_formats fmt);
void stopIqPlayback();
void seekIqFile(qint64 seek_pos);

Expand Down
Loading

0 comments on commit 42583f0

Please sign in to comment.