Skip to content

Commit

Permalink
Restore FM de-emphasis between sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
csete committed Jan 5, 2017
1 parent 86147c5 commit 52dd3da
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 11 deletions.
47 changes: 37 additions & 10 deletions src/qtgui/demod_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,32 @@
#include "ui_demod_options.h"


/* convert between deemphasis time constant and combo-index */
const double tau_tbl[] = {
0.0, 25.0e-6, 50.0e-6, 75.0e-6, 100.0e-6, 250.0e-6, 530.0e-6, 1.0e-3
};
const int tau_tbl_maxidx = 7;

double tau_from_index(int index)
{
if (index < 0 or index > tau_tbl_maxidx)

This comment has been minimized.

Copy link
@guruofquality

guruofquality Jan 18, 2017

Contributor

@csete could this be changed to if (index < 0 || index > tau_tbl_maxidx) or get a #include <ciso646>? Sorry just windows problems. Or I can make a PR. Thanks!

This comment has been minimized.

Copy link
@csete

csete Jan 18, 2017

Author Collaborator

Ok, this was totally unintentional. I wasn't even aware of that this worked. Thanks for pointing this out - fixed now.

This comment has been minimized.

Copy link
@guruofquality

guruofquality Jan 18, 2017

Contributor

I'm personally a fan of the or/and/not keywords. It makes my C++ look more like python :-)
You need the ciso646 or iso646.h header to use them, but on gcc, it seems to be implicit.
Thanks for the fix!

return 0.0;

return tau_tbl[index];
}

int tau_to_index(double tau)
{
int i;
for (i = 0; i < tau_tbl_maxidx; i++)
{
if (tau < (tau_tbl[i] + 0.5 * (tau_tbl[i+1] - tau_tbl[i])))
return i;
}
return 0;
}

/* convert betweenFM max dev and combo index */
float maxdev_from_index(int index)
{
switch(index)
Expand Down Expand Up @@ -120,23 +146,24 @@ float CDemodOptions::getMaxDev(void) const
return maxdev_from_index(ui->maxdevSelector->currentIndex());
}

void CDemodOptions::setEmph(double tau)
{
ui->emphSelector->setCurrentIndex((tau_to_index(tau)));
}

double CDemodOptions::getEmph(void) const
{
return tau_from_index(ui->emphSelector->currentIndex());
}

void CDemodOptions::on_maxdevSelector_activated(int index)
{
emit fmMaxdevSelected(maxdev_from_index(index));
}

void CDemodOptions::on_emphSelector_activated(int index)
{
double tau_tbl[] = {0.0, 25.0, 50.0, 75.0, 100.0, 250.0, 530.0, 1000.0};
double tau;

if ((index < 0) || (index > 7)) {
qDebug() << "Invalid tau selection index: " << index;
return;
}

tau = tau_tbl[index] * 1.0e-6;
emit fmEmphSelected(tau);
emit fmEmphSelected(tau_from_index(index));
}

void CDemodOptions::on_dcrCheckBox_toggled(bool checked)
Expand Down
3 changes: 3 additions & 0 deletions src/qtgui/demod_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ class CDemodOptions : public QDialog
void setMaxDev(float max_dev);
float getMaxDev(void) const;

void setEmph(double tau);
double getEmph(void) const;

signals:
/*! \brief Signal emitted when new FM deviation is selected. */
void fmMaxdevSelected(float max_dev);
Expand Down
16 changes: 16 additions & 0 deletions src/qtgui/dockrxopt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,11 @@ float DockRxOpt::currentMaxdev() const
return demodOpt->getMaxDev();
}

double DockRxOpt::currentEmph() const
{
return demodOpt->getEmph();
}

/**
* @brief Set squelch level.
* @param level Squelch level in dBFS
Expand Down Expand Up @@ -326,6 +331,10 @@ void DockRxOpt::readSettings(QSettings *settings)
if (conv_ok)
demodOpt->setMaxDev(int_val);

dbl_val = settings->value("receiver/fm_deemph", 75).toDouble(&conv_ok);
if (conv_ok && dbl_val >= 0)
demodOpt->setEmph(1.0e-6 * dbl_val); // was stored as usec

qint64 offs = settings->value("receiver/offset", 0).toInt(&conv_ok);
if (offs)
{
Expand Down Expand Up @@ -397,6 +406,13 @@ void DockRxOpt::saveSettings(QSettings *settings)
else
settings->setValue("receiver/fm_maxdev", int_val);

// save as usec
int_val = (int)(1.0e6 * demodOpt->getEmph());
if (int_val == 75)
settings->remove("receiver/fm_deemph");
else
settings->setValue("receiver/fm_deemph", int_val);

qint64 offs = ui->filterFreq->getFrequency();
if (offs)
settings->setValue("receiver/offset", offs);
Expand Down
2 changes: 1 addition & 1 deletion src/qtgui/dockrxopt.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class DockRxOpt : public QDockWidget
QString currentDemodAsString();

float currentMaxdev() const;

double currentEmph() const;
double currentSquelchLevel() const;

void getFilterPreset(int mode, int preset, int * lo, int * hi) const;
Expand Down

0 comments on commit 52dd3da

Please sign in to comment.