mirror of
https://github.com/f4exb/sdrangel.git
synced 2026-06-07 16:34:45 -04:00
IQ swap: initial implementation in non MIMO plugins
This commit is contained in:
@@ -51,7 +51,7 @@ BladeRF2Input::BladeRF2Input(DeviceAPI *deviceAPI) :
|
||||
m_settings(),
|
||||
m_deviceDescription("BladeRF2Input"),
|
||||
m_running(false),
|
||||
m_thread(0)
|
||||
m_thread(nullptr)
|
||||
{
|
||||
openDevice();
|
||||
|
||||
@@ -212,7 +212,7 @@ void BladeRF2Input::init()
|
||||
|
||||
BladeRF2InputThread *BladeRF2Input::findThread()
|
||||
{
|
||||
if (m_thread == 0) // this does not own the thread
|
||||
if (!m_thread) // this does not own the thread
|
||||
{
|
||||
BladeRF2InputThread *bladerf2InputThread = 0;
|
||||
|
||||
@@ -254,7 +254,7 @@ void BladeRF2Input::moveThreadToBuddy()
|
||||
if (buddySource)
|
||||
{
|
||||
buddySource->setThread(m_thread);
|
||||
m_thread = 0; // zero for others
|
||||
m_thread = nullptr; // zero for others
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -326,6 +326,7 @@ bool BladeRF2Input::start()
|
||||
delete bladerf2InputThread;
|
||||
bladerf2InputThread = new BladeRF2InputThread(m_deviceShared.m_dev->getDev(), requestedChannel+1);
|
||||
m_thread = bladerf2InputThread; // take ownership
|
||||
bladerf2InputThread->setIQOrder(m_settings.m_iqOrder);
|
||||
|
||||
for (int i = 0; i < nbOriginalChannels; i++) // restore original FIFO references
|
||||
{
|
||||
@@ -426,7 +427,7 @@ void BladeRF2Input::stop()
|
||||
qDebug("BladeRF2Input::stop: SI mode. Just stop and delete the thread");
|
||||
bladerf2InputThread->stopWork();
|
||||
delete bladerf2InputThread;
|
||||
m_thread = 0;
|
||||
m_thread = nullptr;
|
||||
|
||||
// remove old thread address from buddies (reset in all buddies)
|
||||
const std::vector<DeviceAPI*>& sourceBuddies = m_deviceAPI->getSourceBuddies();
|
||||
@@ -456,7 +457,7 @@ void BladeRF2Input::stop()
|
||||
}
|
||||
|
||||
delete bladerf2InputThread;
|
||||
m_thread = 0;
|
||||
m_thread = nullptr;
|
||||
|
||||
if (stillActiveFIFO)
|
||||
{
|
||||
@@ -861,7 +862,7 @@ bool BladeRF2Input::applySettings(const BladeRF2InputSettings& settings, bool fo
|
||||
reverseAPIKeys.append("fcPos");
|
||||
BladeRF2InputThread *inputThread = findThread();
|
||||
|
||||
if (inputThread != 0)
|
||||
if (inputThread)
|
||||
{
|
||||
inputThread->setFcPos(requestedChannel, (int) settings.m_fcPos);
|
||||
qDebug() << "BladeRF2Input::applySettings: set fc pos (enum) to " << (int) settings.m_fcPos;
|
||||
@@ -874,13 +875,23 @@ bool BladeRF2Input::applySettings(const BladeRF2InputSettings& settings, bool fo
|
||||
forwardChangeOwnDSP = true;
|
||||
BladeRF2InputThread *inputThread = findThread();
|
||||
|
||||
if (inputThread != 0)
|
||||
if (inputThread)
|
||||
{
|
||||
inputThread->setLog2Decimation(requestedChannel, settings.m_log2Decim);
|
||||
qDebug() << "BladeRF2Input::applySettings: set decimation to " << (1<<settings.m_log2Decim);
|
||||
}
|
||||
}
|
||||
|
||||
if ((m_settings.m_iqOrder != settings.m_iqOrder) || force)
|
||||
{
|
||||
reverseAPIKeys.append("iqOrder");
|
||||
BladeRF2InputThread *inputThread = findThread();
|
||||
|
||||
if (inputThread) {
|
||||
inputThread->setIQOrder(settings.m_iqOrder);
|
||||
}
|
||||
}
|
||||
|
||||
if ((m_settings.m_centerFrequency != settings.m_centerFrequency) || force) {
|
||||
reverseAPIKeys.append("centerFrequency");
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ void BladeRF2InputSettings::resetToDefaults()
|
||||
m_iqCorrection = false;
|
||||
m_transverterMode = false;
|
||||
m_transverterDeltaFrequency = 0;
|
||||
m_iqOrder = true;
|
||||
m_fileRecordName = "";
|
||||
m_useReverseAPI = false;
|
||||
m_reverseAPIAddress = "127.0.0.1";
|
||||
@@ -66,6 +67,7 @@ QByteArray BladeRF2InputSettings::serialize() const
|
||||
s.writeString(14, m_reverseAPIAddress);
|
||||
s.writeU32(15, m_reverseAPIPort);
|
||||
s.writeU32(16, m_reverseAPIDeviceIndex);
|
||||
s.writeBool(17, m_iqOrder);
|
||||
|
||||
return s.final();
|
||||
}
|
||||
@@ -110,6 +112,7 @@ bool BladeRF2InputSettings::deserialize(const QByteArray& data)
|
||||
|
||||
d.readU32(16, &uintval, 0);
|
||||
m_reverseAPIDeviceIndex = uintval > 99 ? 99 : uintval;
|
||||
d.readBool(17, &m_iqOrder, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ struct BladeRF2InputSettings {
|
||||
bool m_iqCorrection;
|
||||
bool m_transverterMode;
|
||||
qint64 m_transverterDeltaFrequency;
|
||||
bool m_iqOrder;
|
||||
QString m_fileRecordName;
|
||||
bool m_useReverseAPI;
|
||||
QString m_reverseAPIAddress;
|
||||
|
||||
@@ -23,7 +23,8 @@ BladeRF2InputThread::BladeRF2InputThread(struct bladerf* dev, unsigned int nbRxC
|
||||
QThread(parent),
|
||||
m_running(false),
|
||||
m_dev(dev),
|
||||
m_nbChannels(nbRxChannels)
|
||||
m_nbChannels(nbRxChannels),
|
||||
m_iqOrder(true)
|
||||
{
|
||||
qDebug("BladeRF2InputThread::BladeRF2InputThread");
|
||||
m_channels = new Channel[nbRxChannels];
|
||||
@@ -105,10 +106,17 @@ void BladeRF2InputThread::run()
|
||||
break;
|
||||
}
|
||||
|
||||
if (m_nbChannels > 1) {
|
||||
if (m_nbChannels > 1)
|
||||
{
|
||||
callbackMI(m_buf, DeviceBladeRF2::blockSize);
|
||||
} else {
|
||||
callbackSI(m_buf, 2*DeviceBladeRF2::blockSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_iqOrder) {
|
||||
callbackSIIQ(m_buf, 2*DeviceBladeRF2::blockSize);
|
||||
} else {
|
||||
callbackSIQI(m_buf, 2*DeviceBladeRF2::blockSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
qDebug("BladeRF2InputThread::run: stop running loop");
|
||||
@@ -198,19 +206,24 @@ void BladeRF2InputThread::callbackMI(const qint16* buf, qint32 samplesPerChannel
|
||||
|
||||
for (unsigned int channel = 0; channel < m_nbChannels; channel++)
|
||||
{
|
||||
if (m_channels[channel].m_sampleFifo) {
|
||||
callbackSI(&buf[2*samplesPerChannel*channel], 2*samplesPerChannel, channel);
|
||||
if (m_channels[channel].m_sampleFifo)
|
||||
{
|
||||
if (m_iqOrder) {
|
||||
callbackSIIQ(&buf[2*samplesPerChannel*channel], 2*samplesPerChannel, channel);
|
||||
} else {
|
||||
callbackSIQI(&buf[2*samplesPerChannel*channel], 2*samplesPerChannel, channel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BladeRF2InputThread::callbackSI(const qint16* buf, qint32 len, unsigned int channel)
|
||||
void BladeRF2InputThread::callbackSIIQ(const qint16* buf, qint32 len, unsigned int channel)
|
||||
{
|
||||
SampleVector::iterator it = m_channels[channel].m_convertBuffer.begin();
|
||||
|
||||
if (m_channels[channel].m_log2Decim == 0)
|
||||
{
|
||||
m_channels[channel].m_decimators.decimate1(&it, buf, len);
|
||||
m_channels[channel].m_decimatorsIQ.decimate1(&it, buf, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -219,22 +232,22 @@ void BladeRF2InputThread::callbackSI(const qint16* buf, qint32 len, unsigned int
|
||||
switch (m_channels[channel].m_log2Decim)
|
||||
{
|
||||
case 1:
|
||||
m_channels[channel].m_decimators.decimate2_inf(&it, buf, len);
|
||||
m_channels[channel].m_decimatorsIQ.decimate2_inf(&it, buf, len);
|
||||
break;
|
||||
case 2:
|
||||
m_channels[channel].m_decimators.decimate4_inf(&it, buf, len);
|
||||
m_channels[channel].m_decimatorsIQ.decimate4_inf(&it, buf, len);
|
||||
break;
|
||||
case 3:
|
||||
m_channels[channel].m_decimators.decimate8_inf(&it, buf, len);
|
||||
m_channels[channel].m_decimatorsIQ.decimate8_inf(&it, buf, len);
|
||||
break;
|
||||
case 4:
|
||||
m_channels[channel].m_decimators.decimate16_inf(&it, buf, len);
|
||||
m_channels[channel].m_decimatorsIQ.decimate16_inf(&it, buf, len);
|
||||
break;
|
||||
case 5:
|
||||
m_channels[channel].m_decimators.decimate32_inf(&it, buf, len);
|
||||
m_channels[channel].m_decimatorsIQ.decimate32_inf(&it, buf, len);
|
||||
break;
|
||||
case 6:
|
||||
m_channels[channel].m_decimators.decimate64_inf(&it, buf, len);
|
||||
m_channels[channel].m_decimatorsIQ.decimate64_inf(&it, buf, len);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -245,22 +258,22 @@ void BladeRF2InputThread::callbackSI(const qint16* buf, qint32 len, unsigned int
|
||||
switch (m_channels[channel].m_log2Decim)
|
||||
{
|
||||
case 1:
|
||||
m_channels[channel].m_decimators.decimate2_sup(&it, buf, len);
|
||||
m_channels[channel].m_decimatorsIQ.decimate2_sup(&it, buf, len);
|
||||
break;
|
||||
case 2:
|
||||
m_channels[channel].m_decimators.decimate4_sup(&it, buf, len);
|
||||
m_channels[channel].m_decimatorsIQ.decimate4_sup(&it, buf, len);
|
||||
break;
|
||||
case 3:
|
||||
m_channels[channel].m_decimators.decimate8_sup(&it, buf, len);
|
||||
m_channels[channel].m_decimatorsIQ.decimate8_sup(&it, buf, len);
|
||||
break;
|
||||
case 4:
|
||||
m_channels[channel].m_decimators.decimate16_sup(&it, buf, len);
|
||||
m_channels[channel].m_decimatorsIQ.decimate16_sup(&it, buf, len);
|
||||
break;
|
||||
case 5:
|
||||
m_channels[channel].m_decimators.decimate32_sup(&it, buf, len);
|
||||
m_channels[channel].m_decimatorsIQ.decimate32_sup(&it, buf, len);
|
||||
break;
|
||||
case 6:
|
||||
m_channels[channel].m_decimators.decimate64_sup(&it, buf, len);
|
||||
m_channels[channel].m_decimatorsIQ.decimate64_sup(&it, buf, len);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -271,22 +284,22 @@ void BladeRF2InputThread::callbackSI(const qint16* buf, qint32 len, unsigned int
|
||||
switch (m_channels[channel].m_log2Decim)
|
||||
{
|
||||
case 1:
|
||||
m_channels[channel].m_decimators.decimate2_cen(&it, buf, len);
|
||||
m_channels[channel].m_decimatorsIQ.decimate2_cen(&it, buf, len);
|
||||
break;
|
||||
case 2:
|
||||
m_channels[channel].m_decimators.decimate4_cen(&it, buf, len);
|
||||
m_channels[channel].m_decimatorsIQ.decimate4_cen(&it, buf, len);
|
||||
break;
|
||||
case 3:
|
||||
m_channels[channel].m_decimators.decimate8_cen(&it, buf, len);
|
||||
m_channels[channel].m_decimatorsIQ.decimate8_cen(&it, buf, len);
|
||||
break;
|
||||
case 4:
|
||||
m_channels[channel].m_decimators.decimate16_cen(&it, buf, len);
|
||||
m_channels[channel].m_decimatorsIQ.decimate16_cen(&it, buf, len);
|
||||
break;
|
||||
case 5:
|
||||
m_channels[channel].m_decimators.decimate32_cen(&it, buf, len);
|
||||
m_channels[channel].m_decimatorsIQ.decimate32_cen(&it, buf, len);
|
||||
break;
|
||||
case 6:
|
||||
m_channels[channel].m_decimators.decimate64_cen(&it, buf, len);
|
||||
m_channels[channel].m_decimatorsIQ.decimate64_cen(&it, buf, len);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -297,3 +310,95 @@ void BladeRF2InputThread::callbackSI(const qint16* buf, qint32 len, unsigned int
|
||||
m_channels[channel].m_sampleFifo->write(m_channels[channel].m_convertBuffer.begin(), it);
|
||||
}
|
||||
|
||||
void BladeRF2InputThread::callbackSIQI(const qint16* buf, qint32 len, unsigned int channel)
|
||||
{
|
||||
SampleVector::iterator it = m_channels[channel].m_convertBuffer.begin();
|
||||
|
||||
if (m_channels[channel].m_log2Decim == 0)
|
||||
{
|
||||
m_channels[channel].m_decimatorsQI.decimate1(&it, buf, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_channels[channel].m_fcPos == 0) // Infra
|
||||
{
|
||||
switch (m_channels[channel].m_log2Decim)
|
||||
{
|
||||
case 1:
|
||||
m_channels[channel].m_decimatorsQI.decimate2_inf(&it, buf, len);
|
||||
break;
|
||||
case 2:
|
||||
m_channels[channel].m_decimatorsQI.decimate4_inf(&it, buf, len);
|
||||
break;
|
||||
case 3:
|
||||
m_channels[channel].m_decimatorsQI.decimate8_inf(&it, buf, len);
|
||||
break;
|
||||
case 4:
|
||||
m_channels[channel].m_decimatorsQI.decimate16_inf(&it, buf, len);
|
||||
break;
|
||||
case 5:
|
||||
m_channels[channel].m_decimatorsQI.decimate32_inf(&it, buf, len);
|
||||
break;
|
||||
case 6:
|
||||
m_channels[channel].m_decimatorsQI.decimate64_inf(&it, buf, len);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (m_channels[channel].m_fcPos == 1) // Supra
|
||||
{
|
||||
switch (m_channels[channel].m_log2Decim)
|
||||
{
|
||||
case 1:
|
||||
m_channels[channel].m_decimatorsQI.decimate2_sup(&it, buf, len);
|
||||
break;
|
||||
case 2:
|
||||
m_channels[channel].m_decimatorsQI.decimate4_sup(&it, buf, len);
|
||||
break;
|
||||
case 3:
|
||||
m_channels[channel].m_decimatorsQI.decimate8_sup(&it, buf, len);
|
||||
break;
|
||||
case 4:
|
||||
m_channels[channel].m_decimatorsQI.decimate16_sup(&it, buf, len);
|
||||
break;
|
||||
case 5:
|
||||
m_channels[channel].m_decimatorsQI.decimate32_sup(&it, buf, len);
|
||||
break;
|
||||
case 6:
|
||||
m_channels[channel].m_decimatorsQI.decimate64_sup(&it, buf, len);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (m_channels[channel].m_fcPos == 2) // Center
|
||||
{
|
||||
switch (m_channels[channel].m_log2Decim)
|
||||
{
|
||||
case 1:
|
||||
m_channels[channel].m_decimatorsQI.decimate2_cen(&it, buf, len);
|
||||
break;
|
||||
case 2:
|
||||
m_channels[channel].m_decimatorsQI.decimate4_cen(&it, buf, len);
|
||||
break;
|
||||
case 3:
|
||||
m_channels[channel].m_decimatorsQI.decimate8_cen(&it, buf, len);
|
||||
break;
|
||||
case 4:
|
||||
m_channels[channel].m_decimatorsQI.decimate16_cen(&it, buf, len);
|
||||
break;
|
||||
case 5:
|
||||
m_channels[channel].m_decimatorsQI.decimate32_cen(&it, buf, len);
|
||||
break;
|
||||
case 6:
|
||||
m_channels[channel].m_decimatorsQI.decimate64_cen(&it, buf, len);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_channels[channel].m_sampleFifo->write(m_channels[channel].m_convertBuffer.begin(), it);
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ public:
|
||||
int getFcPos(unsigned int channel) const;
|
||||
void setFifo(unsigned int channel, SampleSinkFifo *sampleFifo);
|
||||
SampleSinkFifo *getFifo(unsigned int channel);
|
||||
void setIQOrder(bool iqOrder) { m_iqOrder = iqOrder; }
|
||||
|
||||
private:
|
||||
struct Channel
|
||||
@@ -59,7 +60,8 @@ private:
|
||||
SampleSinkFifo* m_sampleFifo;
|
||||
unsigned int m_log2Decim;
|
||||
int m_fcPos;
|
||||
Decimators<qint32, qint16, SDR_RX_SAMP_SZ, 12> m_decimators;
|
||||
Decimators<qint32, qint16, SDR_RX_SAMP_SZ, 12, true> m_decimatorsIQ;
|
||||
Decimators<qint32, qint16, SDR_RX_SAMP_SZ, 12, false> m_decimatorsQI;
|
||||
|
||||
Channel() :
|
||||
m_sampleFifo(0),
|
||||
@@ -79,10 +81,12 @@ private:
|
||||
Channel *m_channels; //!< Array of channels dynamically allocated for the given number of Rx channels
|
||||
qint16 *m_buf; //!< Full buffer for SISO or MIMO operation
|
||||
unsigned int m_nbChannels;
|
||||
bool m_iqOrder;
|
||||
|
||||
void run();
|
||||
unsigned int getNbFifos();
|
||||
void callbackSI(const qint16* buf, qint32 len, unsigned int channel = 0);
|
||||
void callbackSIIQ(const qint16* buf, qint32 len, unsigned int channel = 0);
|
||||
void callbackSIQI(const qint16* buf, qint32 len, unsigned int channel = 0);
|
||||
void callbackMI(const qint16* buf, qint32 samplesPerChannel);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user