Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iq tool center freq fix #1009

Merged
merged 2 commits into from
Dec 31, 2021
Merged

Conversation

vladisslav2011
Copy link
Contributor

  1. Parse the center frequency from IQ file name
  2. Save center frequency and offset before starting IQ file playback
  3. Restore center frequency and offset after finishing IQ file playback

This was referenced Dec 2, 2021
@argilo
Copy link
Member

argilo commented Dec 2, 2021

Thanks for splitting this off into its own pull request. It's much easier to review this way. I'll have a look at this tonight.

@@ -91,7 +91,8 @@ void CIqTool::on_listWidget_currentTextChanged(const QString &currentText)
QFileInfo info(*recdir, current_file);

// Get duration of selected recording and update label
sample_rate = sampleRateFromFileName(currentText);
//sample_rate = sampleRateFromFileName(currentText);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed.

@@ -91,7 +91,8 @@ void CIqTool::on_listWidget_currentTextChanged(const QString &currentText)
QFileInfo info(*recdir, current_file);

// Get duration of selected recording and update label
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment looks like it should be above line 96 instead.

@@ -126,7 +127,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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(float)sample_rate,center_freq);
(float)sample_rate, center_freq);

@@ -1658,6 +1663,7 @@ void MainWindow::stopIqPlayback()

// restore frequency, gain, etc...
uiDockInputCtl->readSettings(m_settings);
on_plotter_newDemodFreq(backupFreq,backupOffset);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
on_plotter_newDemodFreq(backupFreq,backupOffset);
on_plotter_newDemodFreq(backupFreq, backupOffset);


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

if (list.size() < 5)
return sample_rate;
return ;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return ;
return;


auto sri = (int)samprate;
auto devstr = QString("file='%1',rate=%2,throttle=true,repeat=false")
.arg(filename).arg(sri);
auto cf = (long long) center_freq;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
auto cf = (long long) center_freq;
auto cf = (long long) center_freq;

@argilo
Copy link
Member

argilo commented Dec 2, 2021

So far the code looks good, I just suggested a few formatting improvements.

I'll test this out tonight.

@vladisslav2011
Copy link
Contributor Author

Thank you for a review.
Sorry for sending a dirty PR. I forgot to check code formatting and remove unused code. Again...
Should I fix code formatting by editing commits followed by push --force, or by adding a new commit?

@argilo
Copy link
Member

argilo commented Dec 2, 2021

Should I fix code formatting by editing commits followed by push --force, or by adding a new commit?

I'd suggest to force-push a revised commit. That will keep the commit history clean once this is merged.

@vladisslav2011 vladisslav2011 force-pushed the iq_tool_center_freq_fix branch from 9dc5ecf to 796a5a8 Compare December 2, 2021 19:13
@vladisslav2011
Copy link
Contributor Author

Done.

@argilo
Copy link
Member

argilo commented Dec 3, 2021

I noticed a bug. When switching from receive (in this example, with an RTL-SDR) to I/Q playback, the plotter frequency axis updates, but the frequency controls do not. Here's what I see when I start playback of an I/Q file with a center frequency around 390 MHz:

gqrx-iq-bug-1

The frequency control still shows 929 MHz, and the indicated offset is 0 Hz. If I click to retune, then the correct frequencies are displayed.

@vladisslav2011
Copy link
Contributor Author

Thank you for reporting this bug.
Fixed in d7b7c94.

Comment on lines 1600 to 1601
backupFreq = ui->freqCtrl->getFrequency();
backupOffset = (qint64) rx->get_filter_offset();
Copy link
Member

@argilo argilo Dec 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to add these variables? I expect storeSession() already saves them in the input/frequency and receiver/offset settings, the same way that the sample rate is saved.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the "Device dialog" or the "Save settings" button may overwrite settings during IQ playback as both are calling storeSession(). But using any of these buttons breaks playback too...
OK. Ill switch to reading center/offset from stored settings and add disabling "Save settings" button during playback to #1011.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The suggestion to use storeSession() was just for consistency with the current design. I agree that the current design is not ideal, so maybe we should think about changing it (in a future PR, perhaps).

@argilo
Copy link
Member

argilo commented Dec 15, 2021

Another minor issue I noticed is that when the I/Q file's center frequency falls outside the hardware limits of the currently selected device, then the frequency is not set correctly. (It's constrained to be within the hardware device's limits.) It looks like this happens because the hardware frequency range is not updated. This change appears to fix the problem:

diff --git a/src/applications/gqrx/mainwindow.cpp b/src/applications/gqrx/mainwindow.cpp
index 34a7d5eb6b..a78237d736 100644
--- a/src/applications/gqrx/mainwindow.cpp
+++ b/src/applications/gqrx/mainwindow.cpp
@@ -1609,6 +1609,7 @@ void MainWindow::startIqPlayback(const QString& filename, float samprate, double
     qDebug() << __func__ << ":" << devstr;
 
     rx->set_input_device(devstr.toStdString());
+    updateHWFrequencyRange(false);
 
     // sample rate
     auto actual_rate = rx->set_input_rate(samprate);

@argilo
Copy link
Member

argilo commented Dec 15, 2021

Thanks again for the pull request, and sorry for the long delay in reviewing this. I've suggested a couple further improvements. When you make those changes, could you also squash your commits into a single one? That will help keep the commit history clean.

@vladisslav2011 vladisslav2011 force-pushed the iq_tool_center_freq_fix branch from c57412c to 489af53 Compare December 15, 2021 20:53
@vladisslav2011
Copy link
Contributor Author

This change appears to fix the problem

Thanks. Fix confirmed. Included into 489af53.

When you make those changes, could you also squash your commits into a single one?

No problem. Done.
I'll rebase subsequent PRs on top of this and squash commits into one too.

@argilo
Copy link
Member

argilo commented Dec 17, 2021

Another bug:

If CIqTool::parseFileName fails to parse the filename for any reason (for instance, if the filename is foo.raw), it leaves center_freq uninitialized, which leads to undefined behaviour. Its value needs to be set, perhaps similarly to how sample_rate is set:

sample_rate = 192000;

iq_tool->setSampleRate((qint64)actual_rate);

@vladisslav2011 vladisslav2011 force-pushed the iq_tool_center_freq_fix branch from 489af53 to 08a99c3 Compare December 18, 2021 20:01
@vladisslav2011
Copy link
Contributor Author

Thanks for more testing.
Hmmm. If we want to support arbitrary-named files in the IQ Player, then it's up to user to supply correct sample rate, center frequency (and sample format). So, we have to provide some GUI elements.
Another issue was spotted while testing this PR: Incorrect frequency calculation. on_plotter_newDemodFreq wants current tuned frequency and offset, not center frequency and offset.
I've fixed both and force pushed a new version.

@vladisslav2011 vladisslav2011 force-pushed the iq_tool_center_freq_fix branch from 08a99c3 to 2d24568 Compare December 18, 2021 20:04
@vladisslav2011
Copy link
Contributor Author

I forgot to remove debug prints.
Pushed a clean version.

@argilo
Copy link
Member

argilo commented Dec 18, 2021

If we want to support arbitrary-named files in the IQ Player, then it's up to user to supply correct sample rate, center frequency (and sample format). So, we have to provide some GUI elements.

That might be a useful feature, but for now I think it's fine to default to the current sample rate and center frequency, and assume complex floating point samples.

@vladisslav2011
Copy link
Contributor Author

OK. I'll split this feature into separate PR. Wait some minutes.

@vladisslav2011 vladisslav2011 marked this pull request as draft December 18, 2021 20:18
@vladisslav2011 vladisslav2011 force-pushed the iq_tool_center_freq_fix branch from 2d24568 to 510c45a Compare December 18, 2021 20:39
@vladisslav2011 vladisslav2011 force-pushed the iq_tool_center_freq_fix branch from 510c45a to 4059516 Compare December 18, 2021 20:57
@vladisslav2011 vladisslav2011 marked this pull request as ready for review December 18, 2021 21:05
@vladisslav2011
Copy link
Contributor Author

vladisslav2011 commented Dec 18, 2021

New GUI controls are moved to #1026

@argilo
Copy link
Member

argilo commented Dec 23, 2021

Another bug:

  1. Open the I/Q tool
  2. Click on a file, but don't play it yet
  3. Close the I/Q tool
  4. Open the I/Q tool again
  5. Press the Play button

In this case, the center frequency will not be adjusted.

@argilo
Copy link
Member

argilo commented Dec 23, 2021

Also, in that same case the wrong file duration will be displayed if the sample rate of the file differs from the sample rate of the currently selected device. I guess both bugs are triggered by the additional code that was added to MainWindow::on_actionIqTool_triggered.

@vladisslav2011
Copy link
Contributor Author

In this case, the center frequency will not be adjusted.

Confirmed. It looks, like getting default sample rate/center frequency from current selected device does not work as expected.

  • I have found another bug. Wrong center frequency is set when the current offset does not fit into bandwidth of selected IQ file:
  1. Set sampling rate to ~2 Msps and record IQ file.
  2. Select wideband device (LimeSDR/HackRF), set sampling rate to some large value. 16 Msps for example.
  3. Set offset to +7 MHz for example
  4. Select IQ file, recorded at step 1 and hit play.

I'll fix both bugs and reopen this PR.
I think, we should not declare support of playing back arbitrary named IQ files until #1026 gets merged.

@vladisslav2011 vladisslav2011 marked this pull request as draft December 23, 2021 13:16
@vladisslav2011 vladisslav2011 force-pushed the iq_tool_center_freq_fix branch from 4059516 to 7877be3 Compare December 23, 2021 13:21
@vladisslav2011 vladisslav2011 marked this pull request as ready for review December 23, 2021 13:31
@vladisslav2011 vladisslav2011 force-pushed the iq_tool_center_freq_fix branch from 7877be3 to ee3f480 Compare December 31, 2021 00:02
vladisslav2011 and others added 2 commits December 30, 2021 22:34
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 gqrx-sdr#977 too.
Remove unused function
Update uiDockRxOpt widgets correctly
@argilo argilo force-pushed the iq_tool_center_freq_fix branch from ee3f480 to bae1256 Compare December 31, 2021 04:01
@argilo
Copy link
Member

argilo commented Dec 31, 2021

The code looks good now, and the change appears to be working well. I'll merge once CI passes.

@argilo argilo merged commit 4eaeb16 into gqrx-sdr:master Dec 31, 2021
@vladisslav2011 vladisslav2011 deleted the iq_tool_center_freq_fix branch December 31, 2021 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants