1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-14 12:22:00 -05:00

Samplerate options.

This commit is contained in:
John Greb 2014-11-08 23:42:43 +00:00
parent 9c3b58d7a3
commit 812d0f4d15
7 changed files with 79 additions and 76 deletions

View File

@ -10,7 +10,7 @@ RTLSDRGui::RTLSDRGui(PluginAPI* pluginAPI, QWidget* parent) :
m_sampleSource(NULL) m_sampleSource(NULL)
{ {
ui->setupUi(this); ui->setupUi(this);
ui->centerFrequency->setValueRange(7, 20000U, 2200000U); ui->centerFrequency->setValueRange(7, 28900U, 1700000U);
connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateHardware())); connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateHardware()));
displaySettings(); displaySettings();
@ -95,7 +95,7 @@ bool RTLSDRGui::handleMessage(Message* message)
void RTLSDRGui::displaySettings() void RTLSDRGui::displaySettings()
{ {
ui->centerFrequency->setValue(m_generalSettings.m_centerFrequency / 1000); ui->centerFrequency->setValue(m_generalSettings.m_centerFrequency / 1000);
ui->decimation->setValue(m_settings.m_decimation); ui->samplerate->setValue(m_settings.m_samplerate);
if(m_gains.size() > 0) { if(m_gains.size() > 0) {
int dist = abs(m_settings.m_gain - m_gains[0]); int dist = abs(m_settings.m_gain - m_gains[0]);
@ -139,10 +139,12 @@ void RTLSDRGui::on_gain_valueChanged(int value)
sendSettings(); sendSettings();
} }
void RTLSDRGui::on_decimation_valueChanged(int value) void RTLSDRGui::on_samplerate_valueChanged(int value)
{ {
ui->decimationText->setText(tr("1:%1").arg(1 << value)); int Rates[] = {288, 1024, 1536, 0};
m_settings.m_decimation = value; int newrate = Rates[value];
ui->samplerateText->setText(tr("%1k").arg(newrate));
m_settings.m_samplerate = newrate * 1000;
sendSettings(); sendSettings();
} }
@ -159,19 +161,16 @@ void RTLSDRGui::on_checkBox_stateChanged(int state) {
ui->radioButton->setEnabled(true); ui->radioButton->setEnabled(true);
ui->radioButton_2->setEnabled(true); ui->radioButton_2->setEnabled(true);
ui->gain->setEnabled(false); ui->gain->setEnabled(false);
//ui->decimation->setMaximum(6); ui->centerFrequency->setValueRange(7, 1000U, 28700U);
ui->centerFrequency->setValue(27000);
ui->centerFrequency->setValueRange(5, 0U, 30000U);
ui->centerFrequency->setValue(0);
} }
else { else {
((RTLSDRInput*)m_sampleSource)->set_ds_mode(0); ((RTLSDRInput*)m_sampleSource)->set_ds_mode(0);
ui->radioButton->setEnabled(false); ui->radioButton->setEnabled(false);
ui->radioButton_2->setEnabled(false); ui->radioButton_2->setEnabled(false);
ui->gain->setEnabled(true); ui->gain->setEnabled(true);
//ui->decimation->setMaximum(4); ui->centerFrequency->setValueRange(7, 28900U, 1700000U);
ui->centerFrequency->setValue(29000);
ui->centerFrequency->setValueRange(7, 20000U, 2200000U);
} }
} }

View File

@ -45,7 +45,7 @@ private:
private slots: private slots:
void on_centerFrequency_changed(quint64 value); void on_centerFrequency_changed(quint64 value);
void on_gain_valueChanged(int value); void on_gain_valueChanged(int value);
void on_decimation_valueChanged(int value); void on_samplerate_valueChanged(int value);
void on_checkBox_stateChanged(int state); void on_checkBox_stateChanged(int state);
void on_radioButton_toggled(bool checked); void on_radioButton_toggled(bool checked);
void on_radioButton_2_toggled(bool checked); void on_radioButton_2_toggled(bool checked);

View File

@ -106,12 +106,12 @@
<number>3</number> <number>3</number>
</property> </property>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QSlider" name="decimation"> <widget class="QSlider" name="samplerate">
<property name="toolTip"> <property name="toolTip">
<string>Signal decimation factor</string> <string>Device Samplerate</string>
</property> </property>
<property name="maximum"> <property name="maximum">
<number>4</number> <number>2</number>
</property> </property>
<property name="pageStep"> <property name="pageStep">
<number>1</number> <number>1</number>
@ -130,12 +130,12 @@
</sizepolicy> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Zoom Out</string> <string>Rate</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="2"> <item row="0" column="2">
<widget class="QLabel" name="decimationText"> <widget class="QLabel" name="samplerateText">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>40</width> <width>40</width>
@ -143,7 +143,7 @@
</size> </size>
</property> </property>
<property name="text"> <property name="text">
<string>1:1</string> <string>288k</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@ -226,7 +226,7 @@
<item> <item>
<widget class="QCheckBox" name="checkBox"> <widget class="QCheckBox" name="checkBox">
<property name="text"> <property name="text">
<string>ds</string> <string>Direct Sampling: </string>
</property> </property>
</widget> </widget>
</item> </item>
@ -236,7 +236,7 @@
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="text"> <property name="text">
<string>i</string> <string>I</string>
</property> </property>
<property name="checkable"> <property name="checkable">
<bool>true</bool> <bool>true</bool>
@ -252,7 +252,7 @@
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="text"> <property name="text">
<string>q</string> <string>Q</string>
</property> </property>
</widget> </widget>
</item> </item>

View File

@ -27,21 +27,21 @@ MESSAGE_CLASS_DEFINITION(RTLSDRInput::MsgReportRTLSDR, Message)
RTLSDRInput::Settings::Settings() : RTLSDRInput::Settings::Settings() :
m_gain(0), m_gain(0),
m_decimation(0) m_samplerate(288000)
{ {
} }
void RTLSDRInput::Settings::resetToDefaults() void RTLSDRInput::Settings::resetToDefaults()
{ {
m_gain = 0; m_gain = 0;
m_decimation = 0; m_samplerate = 288000;
} }
QByteArray RTLSDRInput::Settings::serialize() const QByteArray RTLSDRInput::Settings::serialize() const
{ {
SimpleSerializer s(1); SimpleSerializer s(1);
s.writeS32(1, m_gain); s.writeS32(1, m_gain);
s.writeS32(2, m_decimation); s.writeS32(2, m_samplerate);
return s.final(); return s.final();
} }
@ -56,7 +56,7 @@ bool RTLSDRInput::Settings::deserialize(const QByteArray& data)
if(d.getVersion() == 1) { if(d.getVersion() == 1) {
d.readS32(1, &m_gain, 0); d.readS32(1, &m_gain, 0);
d.readS32(2, &m_decimation, 0); d.readS32(2, &m_samplerate, 0);
return true; return true;
} else { } else {
resetToDefaults(); resetToDefaults();
@ -91,7 +91,7 @@ bool RTLSDRInput::startInput(int device)
int res; int res;
int numberOfGains; int numberOfGains;
if(!m_sampleFifo.setSize(524288)) { if(!m_sampleFifo.setSize(96000 * 4)) {
qCritical("Could not allocate SampleFifo"); qCritical("Could not allocate SampleFifo");
return false; return false;
} }
@ -111,8 +111,8 @@ bool RTLSDRInput::startInput(int device)
qWarning("RTLSDRInput open: %s %s, SN: %s", vendor, product, serial); qWarning("RTLSDRInput open: %s %s, SN: %s", vendor, product, serial);
m_deviceDescription = QString("%1 (SN %2)").arg(product).arg(serial); m_deviceDescription = QString("%1 (SN %2)").arg(product).arg(serial);
if((res = rtlsdr_set_sample_rate(m_dev, 1536000)) < 0) { if((res = rtlsdr_set_sample_rate(m_dev, 288000)) < 0) {
qCritical("could not set sample rate: %s", strerror(errno)); qCritical("could not set sample rate: 288k S/s");
goto failed; goto failed;
} }
@ -182,7 +182,10 @@ const QString& RTLSDRInput::getDeviceDescription() const
int RTLSDRInput::getSampleRate() const int RTLSDRInput::getSampleRate() const
{ {
return 96000 * (1 << m_settings.m_decimation); int rate = m_settings.m_samplerate / 4;
if (rate < 200000)
return rate;
return (rate / 4);
} }
quint64 RTLSDRInput::getCenterFrequency() const quint64 RTLSDRInput::getCenterFrequency() const
@ -207,14 +210,6 @@ bool RTLSDRInput::applySettings(const GeneralSettings& generalSettings, const Se
{ {
QMutexLocker mutexLocker(&m_mutex); QMutexLocker mutexLocker(&m_mutex);
if((m_generalSettings.m_centerFrequency != generalSettings.m_centerFrequency) || force) {
m_generalSettings.m_centerFrequency = generalSettings.m_centerFrequency;
if(m_dev != NULL) {
if(rtlsdr_set_center_freq(m_dev, m_generalSettings.m_centerFrequency
+ 384000) != 0)
qDebug("osmosdr_set_center_freq(%lld) failed", m_generalSettings.m_centerFrequency);
}
}
if((m_settings.m_gain != settings.m_gain) || force) { if((m_settings.m_gain != settings.m_gain) || force) {
m_settings.m_gain = settings.m_gain; m_settings.m_gain = settings.m_gain;
if(m_dev != NULL) { if(m_dev != NULL) {
@ -222,15 +217,30 @@ bool RTLSDRInput::applySettings(const GeneralSettings& generalSettings, const Se
qDebug("rtlsdr_set_tuner_gain() failed"); qDebug("rtlsdr_set_tuner_gain() failed");
} }
} }
if((m_settings.m_decimation != settings.m_decimation) || force) {
m_settings.m_decimation = settings.m_decimation; if((m_settings.m_samplerate != settings.m_samplerate) || force) {
if(m_dev != NULL) if(m_dev != NULL) {
m_rtlSDRThread->setDecimation(m_settings.m_decimation); if( rtlsdr_set_sample_rate(m_dev, settings.m_samplerate) < 0)
qCritical("could not set sample rate: %d", settings.m_samplerate);
else {
m_settings.m_samplerate = settings.m_samplerate;
m_rtlSDRThread->setSamplerate(settings.m_samplerate);
}
}
} }
m_generalSettings.m_centerFrequency = generalSettings.m_centerFrequency;
if(m_dev != NULL) {
if(rtlsdr_set_center_freq( m_dev, m_generalSettings.m_centerFrequency
+ (m_settings.m_samplerate / 4) ) != 0)
qDebug("osmosdr_set_center_freq(%lld) failed", m_generalSettings.m_centerFrequency);
}
return true; return true;
} }
void RTLSDRInput::set_ds_mode(int on)
void RTLSDRInput::set_ds_mode(int on){ {
rtlsdr_set_direct_sampling(m_dev, on); rtlsdr_set_direct_sampling(m_dev, on);
} }

View File

@ -28,7 +28,7 @@ class RTLSDRInput : public SampleSource {
public: public:
struct Settings { struct Settings {
qint32 m_gain; qint32 m_gain;
qint32 m_decimation; qint32 m_samplerate;
Settings(); Settings();
void resetToDefaults(); void resetToDefaults();

View File

@ -28,9 +28,8 @@ RTLSDRThread::RTLSDRThread(rtlsdr_dev_t* dev, SampleFifo* sampleFifo, QObject* p
m_dev(dev), m_dev(dev),
m_convertBuffer(BLOCKSIZE), m_convertBuffer(BLOCKSIZE),
m_sampleFifo(sampleFifo), m_sampleFifo(sampleFifo),
m_decimation(2) m_samplerate(288000)
{ {
m_localdecimation = 0;
} }
RTLSDRThread::~RTLSDRThread() RTLSDRThread::~RTLSDRThread()
@ -53,9 +52,9 @@ void RTLSDRThread::stopWork()
wait(); wait();
} }
void RTLSDRThread::setDecimation(int decimation) void RTLSDRThread::setSamplerate(int samplerate)
{ {
m_decimation = decimation; m_samplerate = samplerate;
} }
void RTLSDRThread::run() void RTLSDRThread::run()
@ -136,43 +135,39 @@ void RTLSDRThread::decimate16(SampleVector::iterator* it, const quint8* buf, qin
} }
} }
/*
Decimate everything by 16x, except 288kHz
TODO : no offset tuning for direct sampling
*/
void RTLSDRThread::callback(const quint8* buf, qint32 len) void RTLSDRThread::callback(const quint8* buf, qint32 len)
{ {
qint16 xreal, yimag, phase; qint16 xreal, yimag, phase;
SampleVector::iterator it = m_convertBuffer.begin(); SampleVector::iterator it = m_convertBuffer.begin();
int decimationFactor[] = {1, 1, 1, 2, 4, 0};
if (++m_localdecimation < decimationFactor[m_decimation]) return; int mode = 0;
m_localdecimation = 0; if (m_samplerate < 800000)
mode = 2;
// if (directsampling) mode++;
switch(4 - m_decimation) { switch(mode) {
case 0: // 1:1 = no decimation case 0:
// just rotation decimate16(&it, buf, len);
phase = -(1<<2);
for (int pos = 0; pos < len + 3; pos += 4) {
phase *= -1;
xreal = phase * (2 * buf[pos+0] - 255);
yimag = phase * (2 * buf[pos+1] - 255);
*it++ = Sample(xreal, yimag);
xreal = phase * (255 - 2 * buf[pos+3]);
yimag = phase * (2 * buf[pos+2] - 255);
*it++ = Sample(xreal, yimag);
}
break; break;
case 1: // 1:2 case 1:
decimate2(&it, buf, len); // no_rotate16(&it, buf, len);
break; break;
case 2: // 1:4 case 2:
decimate4(&it, buf, len); decimate4(&it, buf, len);
break; break;
case 3: // 1:8 case 3:
decimate8(&it, buf, len); // norotate4(&it, buf, len);
break; break;
default: default:
case 4: // 1:16
decimate16(&it, buf, len); decimate16(&it, buf, len);
break; break;
} }

View File

@ -35,7 +35,7 @@ public:
void startWork(); void startWork();
void stopWork(); void stopWork();
void setDecimation(int decimation); void setSamplerate(int sanplerate);
private: private:
QMutex m_startWaitMutex; QMutex m_startWaitMutex;
@ -46,8 +46,7 @@ private:
SampleVector m_convertBuffer; SampleVector m_convertBuffer;
SampleFifo* m_sampleFifo; SampleFifo* m_sampleFifo;
int m_decimation; int m_samplerate;
int m_localdecimation;
void run(); void run();