1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-26 01:39:05 -05:00

SDRPlay plugin: now working with open source libmirisdr

This commit is contained in:
f4exb 2016-11-16 02:38:21 +01:00
parent e4f3915282
commit 85807ffadb
10 changed files with 282 additions and 278 deletions

View File

@ -47,19 +47,19 @@ SDRPlayGui::SDRPlayGui(DeviceSourceAPI *deviceAPI, QWidget* parent) :
ui->ifFrequency->clear();
for (int i = 0; i < SDRPlayIF::getNbIFs(); i++)
{
ui->ifFrequency->addItem(QString::number(SDRPlayIF::getIF(i)));
ui->ifFrequency->addItem(QString::number(SDRPlayIF::getIF(i)/1000));
}
ui->samplerate->clear();
for (int i = 0; i < SDRPlaySampleRates::getNbRates(); i++)
{
ui->samplerate->addItem(QString::number(SDRPlaySampleRates::getRate(i)));
ui->samplerate->addItem(QString::number(SDRPlaySampleRates::getRate(i)/1000));
}
ui->bandwidth->clear();
for (int i = 0; i < SDRPlayBandwidths::getNbBandwidths(); i++)
{
ui->bandwidth->addItem(QString::number(SDRPlayBandwidths::getBandwidth(i)));
ui->bandwidth->addItem(QString::number(SDRPlayBandwidths::getBandwidth(i)/1000));
}
connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateHardware()));
@ -205,8 +205,8 @@ void SDRPlayGui::displaySettings()
{
ui->centerFrequency->setValue(m_settings.m_centerFrequency / 1000);
ui->ppm->setValue(m_settings.m_LOppmCorrection);
ui->ppmText->setText(QString("%1").arg(QString::number(m_settings.m_LOppmCorrection/10.0, 'f', 1)));
ui->ppm->setValue(m_settings.m_LOppmTenths);
ui->ppmText->setText(QString("%1").arg(QString::number(m_settings.m_LOppmTenths/10.0, 'f', 1)));
ui->samplerate->setCurrentIndex(m_settings.m_devSampleRateIndex);
@ -214,6 +214,7 @@ void SDRPlayGui::displaySettings()
ui->iqImbalance->setChecked(m_settings.m_iqCorrection);
ui->fBand->setCurrentIndex(m_settings.m_frequencyBandIndex);
ui->bandwidth->setCurrentIndex(m_settings.m_bandwidthIndex);
ui->ifFrequency->setCurrentIndex(m_settings.m_ifFrequencyIndex);
ui->samplerate->setCurrentIndex(m_settings.m_devSampleRateIndex);
@ -298,13 +299,14 @@ void SDRPlayGui::on_centerFrequency_changed(quint64 value)
void SDRPlayGui::on_ppm_valueChanged(int value)
{
m_settings.m_LOppmCorrection = value;
ui->ppmText->setText(QString("%1").arg(QString::number(m_settings.m_LOppmCorrection/10.0, 'f', 1)));
m_settings.m_LOppmTenths = value;
ui->ppmText->setText(QString("%1").arg(QString::number(m_settings.m_LOppmTenths/10.0, 'f', 1)));
sendSettings();
}
void SDRPlayGui::on_dcOffset_toggled(bool checked)
{
qDebug("SDRPlayGui::on_dcOffset_toggled: %s", checked ? "on" : "off");
m_settings.m_dcBlock = checked;
sendSettings();
}
@ -329,19 +331,6 @@ void SDRPlayGui::on_fBand_currentIndexChanged(int index)
sendSettings();
}
void SDRPlayGui::on_mirDCCorr_currentIndexChanged(int index)
{
m_settings.m_mirDcCorrIndex = index;
sendSettings();
}
void SDRPlayGui::on_mirDCCorrTrackTime_valueChanged(int value)
{
m_settings.m_mirDcCorrTrackTimeIndex = value;
ui->mirDCCorrTrackTimeText->setText(tr("%1us").arg(m_settings.m_mirDcCorrTrackTimeIndex * 3));
sendSettings();
}
void SDRPlayGui::on_bandwidth_currentIndexChanged(int index)
{
m_settings.m_bandwidthIndex = index;
@ -354,6 +343,12 @@ void SDRPlayGui::on_samplerate_currentIndexChanged(int index)
sendSettings();
}
void SDRPlayGui::on_ifFrequency_currentIndexChanged(int index)
{
m_settings.m_ifFrequencyIndex = index;
sendSettings();
}
void SDRPlayGui::on_decim_currentIndexChanged(int index)
{
m_settings.m_log2Decim = index;
@ -366,20 +361,24 @@ void SDRPlayGui::on_fcPos_currentIndexChanged(int index)
sendSettings();
}
void SDRPlayGui::on_gr_valueChanged(int value)
void SDRPlayGui::on_gain_valueChanged(int value)
{
m_settings.m_gainRedctionIndex = value;
if (value > (int)m_gains.size())
{
return;
}
char grStrChr[20];
int gain = m_gains[value];
ui->gainText->setText(tr("%1.%2").arg(gain / 10).arg(abs(gain % 10)));
m_settings.m_gain = gain;
sprintf(grStrChr, "%03d:%02d-%02d-%02d",
m_settings.m_gainRedctionIndex,
24 - m_lnaGr[m_settings.m_frequencyBandIndex][m_settings.m_gainRedctionIndex],
19 - m_mixerGr[m_settings.m_frequencyBandIndex][m_settings.m_gainRedctionIndex],
59 - m_bbGr[m_settings.m_frequencyBandIndex][m_settings.m_gainRedctionIndex]);
ui->grText->setText(QString(grStrChr));
sendSettings();
}
void SDRPlayGui::on_gainAuto_toggled(bool checked)
{
qDebug("SDRPlayGui::on_gainAuto_toggled: %s", checked ? "on" : "off");
m_settings.m_autoGain = checked;
sendSettings();
}

View File

@ -80,9 +80,11 @@ private slots:
void on_fBand_currentIndexChanged(int index);
void on_bandwidth_currentIndexChanged(int index);
void on_samplerate_currentIndexChanged(int index);
void on_ifFrequency_currentIndexChanged(int index);
void on_decim_currentIndexChanged(int index);
void on_fcPos_currentIndexChanged(int index);
void on_gain_valueChanged(int value);
void on_gainAuto_toggled(bool checked);
void on_startStop_toggled(bool checked);
void on_record_toggled(bool checked);
};

View File

@ -35,16 +35,7 @@
<property name="spacing">
<number>3</number>
</property>
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<property name="margin">
<number>2</number>
</property>
<item>
@ -526,7 +517,7 @@
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_vga1">
<layout class="QGridLayout" name="gridLayout_gain">
<property name="spacing">
<number>3</number>
</property>
@ -561,10 +552,10 @@
</size>
</property>
<property name="toolTip">
<string>Tuner gain in dB</string>
<string> </string>
</property>
<property name="text">
<string>---</string>
<string>000</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@ -578,6 +569,13 @@
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="ButtonSwitch" name="gainAuto">
<property name="text">
<string>A</string>
</property>
</widget>
</item>
</layout>
</item>
<item>

View File

@ -50,7 +50,7 @@ bool SDRPlayInput::init(const Message& cmd)
return false;
}
bool SDRPlayInput::start(uint32_t device)
bool SDRPlayInput::start(int device)
{
QMutexLocker mutexLocker(&m_mutex);
@ -81,7 +81,7 @@ bool SDRPlayInput::start(uint32_t device)
product[0] = '\0';
serial[0] = '\0';
if ((res = mirisdr_get_device_usb_strings(m_dev, vendor, product, serial)) < 0)
if ((res = mirisdr_get_device_usb_strings(device, vendor, product, serial)) < 0)
{
qCritical("SDRPlayInput::start: error accessing USB device");
stop();
@ -105,28 +105,32 @@ bool SDRPlayInput::start(uint32_t device)
return false;
}
if ((res = mirisdr_set_sample_format(m_dev, "336_S16"))) // sample format S12
char s12FormatString[] = "336_S16";
if ((res = mirisdr_set_sample_format(m_dev, s12FormatString))) // sample format S12
{
qCritical("SDRPlayInput::start: could not set sample format: rc: %d", res);
stop();
return false;
}
if ((res = mirisdr_set_transfer(m_dev, "BULK")) < 0)
char bulkFormatString[] = "BULK";
if ((res = mirisdr_set_transfer(m_dev, bulkFormatString)) < 0)
{
qCritical("SDRPlayInput::start: could not set USB Bulk mode: rc: %d", res);
stop();
return false;
}
if ((res = mirisdr_set_if_freq(m_dev, SDRPlayIF::m_if[m_settings.m_ifFrequencyIndex])) < 0)
if ((res = mirisdr_set_if_freq(m_dev, SDRPlayIF::getIF(m_settings.m_ifFrequencyIndex))) < 0)
{
qCritical("SDRPlayInput::start: could not set IF frequency at index %d: rc: %d", m_settings.m_ifFrequencyIndex, res);
stop();
return false;
}
if ((res = mirisdr_set_bandwidth(m_dev, SDRPlayBandwidths::m_bw[m_settings.m_bandwidthIndex])) < 0)
if ((res = mirisdr_set_bandwidth(m_dev, SDRPlayBandwidths::getBandwidth(m_settings.m_bandwidthIndex))) < 0)
{
qCritical("SDRPlayInput::start: could not set bandwidth at index %d: rc: %d", m_settings.m_bandwidthIndex, res);
stop();
@ -175,7 +179,7 @@ bool SDRPlayInput::start(uint32_t device)
return false;
}
if((m_sdrPlayThread = new SDRPlayThread(&m_sampleFifo)) == 0)
if((m_sdrPlayThread = new SDRPlayThread(m_dev, &m_sampleFifo)) == 0)
{
qFatal("SDRPlayInput::start: failed to create thread");
return false;
@ -186,28 +190,28 @@ bool SDRPlayInput::start(uint32_t device)
mutexLocker.unlock();
applySettings(m_settings, true);
return true;
}
void SDRPlayInput::stop()
{
mir_sdr_ErrT r;
QMutexLocker mutexLocker(&m_mutex);
r = mir_sdr_StreamUninit();
if (r != mir_sdr_Success)
{
qCritical("SDRPlayInput::stop: stream uninit failed with code %d", (int) r);
}
m_mirStreamRunning = false;
if(m_sdrPlayThread != 0)
{
m_sdrPlayThread->stopWork();
delete m_sdrPlayThread;
m_sdrPlayThread = 0;
}
if (m_dev != 0)
{
mirisdr_close(m_dev);
m_dev = 0;
}
m_deviceDescription.clear();
}
const QString& SDRPlayInput::getDeviceDescription() const
@ -218,7 +222,7 @@ const QString& SDRPlayInput::getDeviceDescription() const
int SDRPlayInput::getSampleRate() const
{
int rate = SDRPlaySampleRates::getRate(m_settings.m_devSampleRateIndex);
return (rate * 1000) / (1<<m_settings.m_log2Decim);
return rate / (1<<m_settings.m_log2Decim);
}
quint64 SDRPlayInput::getCenterFrequency() const
@ -233,9 +237,7 @@ bool SDRPlayInput::handleMessage(const Message& message)
MsgConfigureSDRPlay& conf = (MsgConfigureSDRPlay&) message;
qDebug() << "SDRPlayInput::handleMessage: MsgConfigureSDRPlay";
bool success = applySettings(conf.getSettings(), false);
if (!success)
if (!applySettings(conf.getSettings(), false))
{
qDebug("SDRPlayInput::handleMessage: config error");
}
@ -251,20 +253,81 @@ bool SDRPlayInput::handleMessage(const Message& message)
bool SDRPlayInput::applySettings(const SDRPlaySettings& settings, bool force)
{
bool forwardChange = false;
bool forceManualGain = false;
QMutexLocker mutexLocker(&m_mutex);
if (m_settings.m_dcBlock != settings.m_dcBlock)
if ((m_settings.m_dcBlock != settings.m_dcBlock) || force)
{
m_settings.m_dcBlock = settings.m_dcBlock;
m_deviceAPI->configureCorrections(m_settings.m_dcBlock, m_settings.m_iqCorrection);
}
if (m_settings.m_iqCorrection != settings.m_iqCorrection)
if ((m_settings.m_iqCorrection != settings.m_iqCorrection) || force)
{
m_settings.m_iqCorrection = settings.m_iqCorrection;
m_deviceAPI->configureCorrections(m_settings.m_dcBlock, m_settings.m_iqCorrection);
}
if ((m_settings.m_autoGain != settings.m_autoGain) || force)
{
m_settings.m_autoGain = settings.m_autoGain;
if(m_dev != 0)
{
int r = mirisdr_set_tuner_gain_mode(m_dev, m_settings.m_autoGain ? 0 : 1);
if (r < 0)
{
qDebug("SDRPlayInput::applySettings: could not set auto gain %s: rc: %d", m_settings.m_autoGain ? "on" : "off", r);
}
else
{
qDebug("SDRPlayInput::applySettings: auto gain set to %s", m_settings.m_autoGain ? "on" : "off");
forceManualGain = !m_settings.m_autoGain;
}
}
}
if (!m_settings.m_autoGain)
{
if ((m_settings.m_gain != settings.m_gain) || force || forceManualGain)
{
m_settings.m_gain = settings.m_gain;
if(m_dev != 0)
{
int r = mirisdr_set_tuner_gain(m_dev, m_settings.m_gain);
if (r < 0)
{
qDebug("SDRPlayInput::applySettings: could not set tuner gain()");
}
}
}
}
if ((m_settings.m_devSampleRateIndex != settings.m_devSampleRateIndex) || force)
{
forwardChange = true;
if(m_dev != 0)
{
int sampleRate = SDRPlaySampleRates::getRate(m_settings.m_devSampleRateIndex);
int r = mirisdr_set_sample_rate(m_dev, sampleRate);
if(r < 0)
{
qCritical("SDRPlayInput::applySettings: could not set sample rate: %d rc: %d", sampleRate, r);
}
else
{
qDebug("SDRPlayInput::applySettings: sample rate set to %d", sampleRate);
m_settings.m_devSampleRateIndex = settings.m_devSampleRateIndex;
m_sdrPlayThread->setSamplerate(sampleRate);
}
}
}
if ((m_settings.m_log2Decim != settings.m_log2Decim) || force)
{
m_settings.m_log2Decim = settings.m_log2Decim;
@ -273,7 +336,55 @@ bool SDRPlayInput::applySettings(const SDRPlaySettings& settings, bool force)
if (m_sdrPlayThread != 0)
{
m_sdrPlayThread->setLog2Decimation(m_settings.m_log2Decim);
qDebug() << "SDRPlayInput: set decimation to " << (1<<m_settings.m_log2Decim);
qDebug() << "SDRPlayInput::applySettings: set decimation to " << (1<<m_settings.m_log2Decim);
}
}
if (m_settings.m_centerFrequency != settings.m_centerFrequency)
{
forwardChange = true;
}
qint64 deviceCenterFrequency = m_settings.m_centerFrequency;
qint64 f_img = deviceCenterFrequency;
quint32 devSampleRate = SDRPlaySampleRates::getRate(m_settings.m_devSampleRateIndex);
if (force || (m_settings.m_centerFrequency != settings.m_centerFrequency)
|| (m_settings.m_LOppmTenths != settings.m_LOppmTenths)
|| (m_settings.m_fcPos != settings.m_fcPos))
{
m_settings.m_centerFrequency = settings.m_centerFrequency;
m_settings.m_LOppmTenths = settings.m_LOppmTenths;
if ((m_settings.m_log2Decim == 0) || (settings.m_fcPos == SDRPlaySettings::FC_POS_CENTER))
{
deviceCenterFrequency = m_settings.m_centerFrequency;
f_img = deviceCenterFrequency;
}
else
{
if (settings.m_fcPos == SDRPlaySettings::FC_POS_INFRA)
{
deviceCenterFrequency = m_settings.m_centerFrequency + (devSampleRate / 4);
f_img = deviceCenterFrequency + devSampleRate/2;
}
else if (settings.m_fcPos == SDRPlaySettings::FC_POS_SUPRA)
{
deviceCenterFrequency = m_settings.m_centerFrequency - (devSampleRate / 4);
f_img = deviceCenterFrequency - devSampleRate/2;
}
}
if(m_dev != 0)
{
if (setCenterFrequency(deviceCenterFrequency))
{
qDebug() << "SDRPlayInput::applySettings: center freq: " << m_settings.m_centerFrequency << " Hz"
<< " device center freq: " << deviceCenterFrequency << " Hz"
<< " device sample rate: " << devSampleRate << "Hz"
<< " Actual sample rate: " << devSampleRate/(1<<m_settings.m_log2Decim) << "Hz"
<< " img: " << f_img << "Hz";
}
}
}
@ -288,28 +399,6 @@ bool SDRPlayInput::applySettings(const SDRPlaySettings& settings, bool force)
}
}
if ((m_settings.m_devSampleRateIndex != settings.m_devSampleRateIndex) || force)
{
m_settings.m_devSampleRateIndex = settings.m_devSampleRateIndex;
forwardChange = true;
if (m_mirStreamRunning)
{
reinitMirSDR(mir_sdr_CHANGE_FS_FREQ);
}
}
if ((m_settings.m_centerFrequency != settings.m_centerFrequency) || force)
{
m_settings.m_centerFrequency = settings.m_centerFrequency;
forwardChange = true;
if (m_mirStreamRunning)
{
reinitMirSDR(mir_sdr_CHANGE_RF_FREQ);
}
}
if ((m_settings.m_frequencyBandIndex != settings.m_frequencyBandIndex) || force)
{
m_settings.m_frequencyBandIndex = settings.m_frequencyBandIndex;
@ -318,93 +407,33 @@ bool SDRPlayInput::applySettings(const SDRPlaySettings& settings, bool force)
if ((m_settings.m_bandwidthIndex != settings.m_bandwidthIndex) || force)
{
m_settings.m_bandwidthIndex = settings.m_bandwidthIndex;
int bandwidth = SDRPlayBandwidths::getBandwidth(settings.m_bandwidthIndex);
int r = mirisdr_set_bandwidth(m_dev, bandwidth);
if (m_mirStreamRunning)
if (r < 0)
{
reinitMirSDR(mir_sdr_CHANGE_BW_TYPE);
}
}
// TODO: change IF mode
// TODO: change LO mode
if ((m_settings.m_gainRedctionIndex != settings.m_gainRedctionIndex) || force)
{
if (m_settings.m_bandwidthIndex < 4)
{
m_settings.m_gainRedctionIndex = settings.m_gainRedctionIndex;
if (m_mirStreamRunning)
{
reinitMirSDR(mir_sdr_CHANGE_GR);
}
qCritical("SDRPlayInput::applySettings: set bandwidth %d failed: rc: %d", bandwidth, r);
}
else
{
if (settings.m_gainRedctionIndex > 85)
{
if (m_settings.m_gainRedctionIndex < 85)
{
m_settings.m_gainRedctionIndex = 85;
if (m_mirStreamRunning)
{
reinitMirSDR(mir_sdr_CHANGE_GR);
}
}
}
else
{
m_settings.m_gainRedctionIndex = settings.m_gainRedctionIndex;
if (m_mirStreamRunning)
{
reinitMirSDR(mir_sdr_CHANGE_GR);
}
}
qDebug("SDRPlayInput::applySettings: bandwidth set to %d", bandwidth);
m_settings.m_bandwidthIndex = settings.m_bandwidthIndex;
}
}
if ((m_settings.m_LOppmCorrection != settings.m_LOppmCorrection) || force)
if (m_settings.m_ifFrequencyIndex != settings.m_ifFrequencyIndex)
{
m_settings.m_LOppmCorrection = settings.m_LOppmCorrection;
int iFFrequency = SDRPlayIF::getIF(settings.m_ifFrequencyIndex);
int r = mirisdr_set_if_freq(m_dev, iFFrequency);
mir_sdr_ErrT r = mir_sdr_SetPpm(m_settings.m_LOppmCorrection / 10.0);
if (r != mir_sdr_Success)
if (r < 0)
{
qDebug("SDRPlayInput::applySettings: mir_sdr_SetPpm failed with code %d", (int) r);
qCritical("SDRPlayInput::applySettings: set IF frequency to %d failed: rc: %d", iFFrequency, r);
}
}
if ((m_settings.m_mirDcCorrIndex != settings.m_mirDcCorrIndex) || force)
{
m_settings.m_mirDcCorrIndex = settings.m_mirDcCorrIndex;
if (m_mirStreamRunning)
else
{
mir_sdr_ErrT r = mir_sdr_SetDcMode(m_settings.m_mirDcCorrIndex, 0);
if (r != mir_sdr_Success)
{
qDebug("SDRPlayInput::applySettings: mir_sdr_SetDcMode failed with code %d", (int) r);
}
}
}
if ((m_settings.m_mirDcCorrTrackTimeIndex != settings.m_mirDcCorrTrackTimeIndex) || force)
{
m_settings.m_mirDcCorrTrackTimeIndex = settings.m_mirDcCorrTrackTimeIndex;
if (m_mirStreamRunning)
{
mir_sdr_ErrT r = mir_sdr_SetDcTrackTime(m_settings.m_mirDcCorrTrackTimeIndex);
if (r != mir_sdr_Success)
{
qDebug("SDRPlayInput::applySettings: mir_sdr_SetDcTrackTime failed with code %d", (int) r);
}
qDebug("SDRPlayInput::applySettings: IF frequency set to %d", iFFrequency);
m_settings.m_ifFrequencyIndex = settings.m_ifFrequencyIndex;
}
}
@ -418,37 +447,23 @@ bool SDRPlayInput::applySettings(const SDRPlaySettings& settings, bool force)
return true;
}
void SDRPlayInput::reinitMirSDR(mir_sdr_ReasonForReinitT reasonForReinit)
bool SDRPlayInput::setCenterFrequency(quint64 freq_hz)
{
int grdB = -m_settings.m_gainRedctionIndex;
int rate = SDRPlaySampleRates::getRate(m_settings.m_devSampleRateIndex);
int gRdBsystem;
qint64 df = ((qint64)freq_hz * m_settings.m_LOppmTenths) / 10000000LL;
freq_hz += df;
mir_sdr_ErrT r = mir_sdr_Reinit(
&grdB,
rate / 1e3,
m_settings.m_centerFrequency / 1e6,
(mir_sdr_Bw_MHzT) m_settings.m_bandwidthIndex,
mir_sdr_IF_Zero,
mir_sdr_LO_Auto,
1, // LNA
&gRdBsystem,
0, // use mir_sdr_SetGr() to set initial gain reduction
&m_samplesPerPacket,
reasonForReinit);
int r = mirisdr_set_center_freq(m_dev, static_cast<uint32_t>(freq_hz));
if (r != mir_sdr_Success)
if (r != 0)
{
qCritical("SDRPlayInput::reinitMirSDR (%d): MirSDR stream reinit failed with code %d", (int) reasonForReinit, (int) r);
m_mirStreamRunning = false;
qWarning("SDRPlayInput::setCenterFrequency: could not frequency to %llu Hz", freq_hz);
return false;
}
else
{
qDebug("SDRPlayInput::reinitMirSDR (%d): MirSDR stream restarted: samplesPerPacket: %d", (int) reasonForReinit, m_samplesPerPacket);
qWarning("SDRPlayInput::setCenterFrequency: frequency set to %llu Hz", freq_hz);
return true;
}
}
void SDRPlayInput::callbackGC(unsigned int gRdB, unsigned int lnaGRdB, void *cbContext)
{
return;
}

View File

@ -73,7 +73,7 @@ public:
virtual ~SDRPlayInput();
virtual bool init(const Message& message);
virtual bool start(uint32_t device);
virtual bool start(int device);
virtual void stop();
virtual const QString& getDeviceDescription() const;
@ -84,6 +84,7 @@ public:
private:
bool applySettings(const SDRPlaySettings& settings, bool force);
bool setCenterFrequency(quint64 freq);
DeviceSourceAPI *m_deviceAPI;
QMutex m_mutex;

View File

@ -28,33 +28,33 @@ void SDRPlaySettings::resetToDefaults()
{
m_centerFrequency = 7040*1000;
m_gain = 0;
m_LOppmCorrection = 0;
m_LOppmTenths = 0;
m_frequencyBandIndex = 0;
m_ifFrequencyIndex = 0;
m_bandwidthIndex = 0;
m_devSampleRateIndex = 0;
m_gainRedctionIndex = 35;
m_log2Decim = 0;
m_fcPos = FC_POS_CENTER;
m_dcBlock = false;
m_iqCorrection = false;
m_autoGain = false;
}
QByteArray SDRPlaySettings::serialize() const
{
SimpleSerializer s(1);
s.writeS32(1, m_LOppmCorrection);
s.writeS32(1, m_LOppmTenths);
s.writeU32(2, m_frequencyBandIndex);
s.writeU32(3, m_ifFrequencyIndex);
s.writeS32(4, m_gain);
s.writeU32(5, m_bandwidthIndex);
s.writeU32(6, m_devSampleRateIndex);
s.writeU32(7, m_gainRedctionIndex);
s.writeU32(8, m_log2Decim);
s.writeS32(9, (int) m_fcPos);
s.writeBool(10, m_dcBlock);
s.writeBool(11, m_iqCorrection);
s.writeU32(7, m_log2Decim);
s.writeS32(8, (int) m_fcPos);
s.writeBool(9, m_dcBlock);
s.writeBool(10, m_iqCorrection);
s.writeBool(11, m_autoGain);
return s.final();
}
@ -73,18 +73,18 @@ bool SDRPlaySettings::deserialize(const QByteArray& data)
{
int intval;
d.readS32(1, &m_LOppmCorrection, 0);
d.readS32(1, &m_LOppmTenths, 0);
d.readU32(2, &m_frequencyBandIndex, 0);
d.readU32(3, &m_ifFrequencyIndex, 0);
d.readS32(4, &m_gain, 0);
d.readU32(5, &m_bandwidthIndex, 0);
d.readU32(6, &m_devSampleRateIndex, 0);
d.readU32(7, &m_gainRedctionIndex, 35);
d.readU32(8, &m_log2Decim, 0);
d.readS32(9, &intval, 0);
d.readU32(7, &m_log2Decim, 0);
d.readS32(8, &intval, 0);
m_fcPos = (fcPos_t) intval;
d.readBool(10, &m_dcBlock, false);
d.readBool(11, &m_iqCorrection, false);
d.readBool(9, &m_dcBlock, false);
d.readBool(10, &m_iqCorrection, false);
d.readBool(11, &m_autoGain, false);
return true;
}

View File

@ -29,16 +29,16 @@ struct SDRPlaySettings {
uint64_t m_centerFrequency;
qint32 m_gain;
int32_t m_LOppmCorrection;
int32_t m_LOppmTenths;
uint32_t m_frequencyBandIndex;
uint32_t m_ifFrequencyIndex;
uint32_t m_bandwidthIndex;
uint32_t m_devSampleRateIndex;
uint32_t m_gainRedctionIndex;
uint32_t m_log2Decim;
fcPos_t m_fcPos;
bool m_dcBlock;
bool m_iqCorrection;
bool m_autoGain;
SDRPlaySettings();
void resetToDefaults();

View File

@ -19,23 +19,21 @@
#include "sdrplaythread.h"
#include "dsp/samplesinkfifo.h"
SDRPlayThread *SDRPlayThread::m_this = 0;
SDRPlayThread::SDRPlayThread(SampleSinkFifo* sampleFifo, QObject* parent) :
SDRPlayThread::SDRPlayThread(mirisdr_dev_t* dev, SampleSinkFifo* sampleFifo, QObject* parent) :
QThread(parent),
m_running(false),
m_dev(dev),
m_convertBuffer(SDRPLAY_INIT_NBSAMPLES),
m_sampleFifo(sampleFifo),
m_samplerate(288000),
m_log2Decim(0),
m_fcPos(0)
{
m_this = this;
}
SDRPlayThread::~SDRPlayThread()
{
stopWork();
m_this = 0;
}
void SDRPlayThread::startWork()
@ -53,6 +51,11 @@ void SDRPlayThread::stopWork()
wait();
}
void SDRPlayThread::setSamplerate(int samplerate)
{
m_samplerate = samplerate;
}
void SDRPlayThread::setLog2Decimation(unsigned int log2_decim)
{
m_log2Decim = log2_decim;
@ -63,110 +66,114 @@ void SDRPlayThread::setFcPos(int fcPos)
m_fcPos = fcPos;
}
void SDRPlayThread::streamCallback(
short *xi,
short *xq,
unsigned int firstSampleNum,
int grChanged,
int rfChanged,
int fsChanged,
unsigned int numSamples,
unsigned int reset,
void *cbContext)
void SDRPlayThread::run()
{
qDebug("SDRPlayThread::streamCallback");
m_this->callback(xi, xq, numSamples);
}
int res;
void SDRPlayThread::callback(short *xi, short *xq, unsigned int numSamples)
{
qDebug("SDRPlayThread::callback");
if (m_convertBuffer.size() < numSamples)
m_running = true;
m_startWaiter.wakeAll();
while (m_running)
{
m_convertBuffer.resize(numSamples);
if ((res = mirisdr_read_async(m_dev, &SDRPlayThread::callbackHelper, this, 32, SDRPLAY_INIT_NBSAMPLES)) < 0)
{
qCritical("SDRPlayThread::run: async read error: rc %d: %s", res, strerror(errno));
break;
}
}
m_running = false;
}
void SDRPlayThread::callbackHelper(unsigned char* buf, uint32_t len, void* ctx)
{
SDRPlayThread* thread = (SDRPlayThread*) ctx;
thread->callback((const qint16*) buf, len/2);
}
void SDRPlayThread::callback(const qint16* buf, qint32 len)
{
SampleVector::iterator it = m_convertBuffer.begin();
if (m_log2Decim == 0)
{
m_decimators.decimate1(&it, xi, xq, numSamples);
m_decimators.decimate1(&it, buf, len);
}
else
{
if (m_fcPos == 0) // Infra
if (m_fcPos == 0) // Infradyne
{
switch (m_log2Decim)
{
case 1:
m_decimators.decimate2_inf(&it, xi, xq, numSamples);
m_decimators.decimate2_inf(&it, buf, len);
break;
case 2:
m_decimators.decimate4_inf(&it, xi, xq, numSamples);
m_decimators.decimate4_inf(&it, buf, len);
break;
case 3:
m_decimators.decimate8_inf(&it, xi, xq, numSamples);
m_decimators.decimate8_inf(&it, buf, len);
break;
case 4:
m_decimators.decimate16_inf(&it, xi, xq, numSamples);
m_decimators.decimate16_inf(&it, buf, len);
break;
case 5:
m_decimators.decimate32_inf(&it, xi, xq, numSamples);
m_decimators.decimate32_inf(&it, buf, len);
break;
case 6:
m_decimators.decimate64_inf(&it, xi, xq, numSamples);
m_decimators.decimate64_inf(&it, buf, len);
break;
default:
break;
}
}
else if (m_fcPos == 1) // Supra
else if (m_fcPos == 1) // Supradyne
{
switch (m_log2Decim)
{
case 1:
m_decimators.decimate2_sup(&it, xi, xq, numSamples);
m_decimators.decimate2_sup(&it, buf, len);
break;
case 2:
m_decimators.decimate4_sup(&it, xi, xq, numSamples);
m_decimators.decimate4_sup(&it, buf, len);
break;
case 3:
m_decimators.decimate8_sup(&it, xi, xq, numSamples);
m_decimators.decimate8_sup(&it, buf, len);
break;
case 4:
m_decimators.decimate16_sup(&it, xi, xq, numSamples);
m_decimators.decimate16_sup(&it, buf, len);
break;
case 5:
m_decimators.decimate32_sup(&it, xi, xq, numSamples);
m_decimators.decimate32_sup(&it, buf, len);
break;
case 6:
m_decimators.decimate64_sup(&it, xi, xq, numSamples);
m_decimators.decimate64_sup(&it, buf, len);
break;
default:
break;
}
}
else if (m_fcPos == 2) // Center
else // Centered
{
switch (m_log2Decim)
{
case 1:
m_decimators.decimate2_cen(&it, xi, xq, numSamples);
m_decimators.decimate2_cen(&it, buf, len);
break;
case 2:
m_decimators.decimate4_cen(&it, xi, xq, numSamples);
m_decimators.decimate4_cen(&it, buf, len);
break;
case 3:
m_decimators.decimate8_cen(&it, xi, xq, numSamples);
m_decimators.decimate8_cen(&it, buf, len);
break;
case 4:
m_decimators.decimate16_cen(&it, xi, xq, numSamples);
m_decimators.decimate16_cen(&it, buf, len);
break;
case 5:
m_decimators.decimate32_cen(&it, xi, xq, numSamples);
m_decimators.decimate32_cen(&it, buf, len);
break;
case 6:
m_decimators.decimate64_cen(&it, xi, xq, numSamples);
m_decimators.decimate64_cen(&it, buf, len);
break;
default:
break;
@ -175,21 +182,10 @@ void SDRPlayThread::callback(short *xi, short *xq, unsigned int numSamples)
}
m_sampleFifo->write(m_convertBuffer.begin(), it);
}
void SDRPlayThread::run()
{
int res;
m_running = true;
m_startWaiter.wakeAll();
while(m_running)
if(!m_running)
{
sleep(1);
mirisdr_cancel_async(m_dev);
}
m_running = false;
}

View File

@ -20,7 +20,7 @@
#include <QThread>
#include <QMutex>
#include <QWaitCondition>
#include <mirsdrapi-rsp.h>
#include <mirisdr.h>
#include "dsp/samplesinkfifo.h"
#include "dsp/decimators.h"
@ -30,41 +30,34 @@ class SDRPlayThread : public QThread {
Q_OBJECT
public:
SDRPlayThread(SampleSinkFifo* sampleFifo, QObject* parent = NULL);
SDRPlayThread(mirisdr_dev_t* dev, SampleSinkFifo* sampleFifo, QObject* parent = NULL);
~SDRPlayThread();
void startWork();
void stopWork();
void setSamplerate(int samplerate);
void setLog2Decimation(unsigned int log2_decim);
void setFcPos(int fcPos);
static void streamCallback (
short *xi,
short *xq,
unsigned int firstSampleNum,
int grChanged,
int rfChanged,
int fsChanged,
unsigned int numSamples,
unsigned int reset,
void *cbContext);
private:
QMutex m_startWaitMutex;
QWaitCondition m_startWaiter;
bool m_running;
mirisdr_dev_t *m_dev;
SampleVector m_convertBuffer;
SampleSinkFifo* m_sampleFifo;
int m_samplerate;
unsigned int m_log2Decim;
int m_fcPos;
static SDRPlayThread *m_this;
Decimators<qint16, SDR_SAMP_SZ, 12> m_decimators;
void run();
void callback(short *xi, short *xq, unsigned int numSamples);
void callback(const qint16* buf, qint32 len);
static void callbackHelper(unsigned char* buf, uint32_t len, void* ctx);
};
#endif /* PLUGINS_SAMPLESOURCE_SDRPLAY_SDRPLAYTHREAD_H_ */

View File

@ -473,7 +473,7 @@ DSPDeviceSourceEngine::State DSPDeviceSourceEngine::gotoRunning()
DSPDeviceSourceEngine::State DSPDeviceSourceEngine::gotoError(const QString& errorMessage)
{
qDebug() << "DSPDeviceSourceEngine::gotoError";
qDebug() << "DSPDeviceSourceEngine::gotoError: " << errorMessage;
m_errorMessage = errorMessage;
m_deviceDescription.clear();