mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-05-29 05:22:25 -04:00
Make SDRDaemonSink -> DaemonSource work in all 16 / 24 bit samples combination
This commit is contained in:
parent
5e588ae09e
commit
e78ee1b946
@ -46,7 +46,6 @@ DaemonSource::DaemonSource(DeviceSinkAPI *deviceAPI) :
|
|||||||
m_deviceAPI(deviceAPI),
|
m_deviceAPI(deviceAPI),
|
||||||
m_sourceThread(0),
|
m_sourceThread(0),
|
||||||
m_running(false),
|
m_running(false),
|
||||||
m_dataReadQueue(SDR_TX_SAMP_SZ <= 16 ? 4 : 8),
|
|
||||||
m_nbCorrectableErrors(0),
|
m_nbCorrectableErrors(0),
|
||||||
m_nbUncorrectableErrors(0)
|
m_nbUncorrectableErrors(0)
|
||||||
{
|
{
|
||||||
@ -72,7 +71,7 @@ DaemonSource::~DaemonSource()
|
|||||||
|
|
||||||
void DaemonSource::pull(Sample& sample)
|
void DaemonSource::pull(Sample& sample)
|
||||||
{
|
{
|
||||||
m_dataReadQueue.readSample(sample);
|
m_dataReadQueue.readSample(sample, true); // true is scale for Tx
|
||||||
}
|
}
|
||||||
|
|
||||||
void DaemonSource::pullAudio(int nbSamples __attribute__((unused)))
|
void DaemonSource::pullAudio(int nbSamples __attribute__((unused)))
|
||||||
|
@ -25,12 +25,12 @@
|
|||||||
|
|
||||||
const uint32_t SDRDaemonDataReadQueue::MinimumMaxSize = 10;
|
const uint32_t SDRDaemonDataReadQueue::MinimumMaxSize = 10;
|
||||||
|
|
||||||
SDRDaemonDataReadQueue::SDRDaemonDataReadQueue(uint32_t sampleSize) :
|
SDRDaemonDataReadQueue::SDRDaemonDataReadQueue() :
|
||||||
m_sampleSize(sampleSize),
|
|
||||||
m_dataBlock(0),
|
m_dataBlock(0),
|
||||||
m_maxSize(MinimumMaxSize),
|
m_maxSize(MinimumMaxSize),
|
||||||
m_blockIndex(1),
|
m_blockIndex(1),
|
||||||
m_sampleIndex(0),
|
m_sampleIndex(0),
|
||||||
|
m_sampleCount(0),
|
||||||
m_full(false)
|
m_full(false)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ void SDRDaemonDataReadQueue::setSize(uint32_t size)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDRDaemonDataReadQueue::readSample(Sample& s)
|
void SDRDaemonDataReadQueue::readSample(Sample& s, bool scaleForTx)
|
||||||
{
|
{
|
||||||
// depletion/repletion state
|
// depletion/repletion state
|
||||||
if (m_dataBlock == 0)
|
if (m_dataBlock == 0)
|
||||||
@ -96,7 +96,7 @@ void SDRDaemonDataReadQueue::readSample(Sample& s)
|
|||||||
qDebug("SDRDaemonDataReadQueue::readSample: initial pop new block: queue size: %u", length());
|
qDebug("SDRDaemonDataReadQueue::readSample: initial pop new block: queue size: %u", length());
|
||||||
m_blockIndex = 1;
|
m_blockIndex = 1;
|
||||||
m_dataBlock = m_dataReadQueue.takeFirst();
|
m_dataBlock = m_dataReadQueue.takeFirst();
|
||||||
convertDataToSample(s, m_blockIndex, m_sampleIndex);
|
convertDataToSample(s, m_blockIndex, m_sampleIndex, scaleForTx);
|
||||||
m_sampleIndex++;
|
m_sampleIndex++;
|
||||||
m_sampleCount++;
|
m_sampleCount++;
|
||||||
}
|
}
|
||||||
@ -108,11 +108,12 @@ void SDRDaemonDataReadQueue::readSample(Sample& s)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t samplesPerBlock = SDRDaemonNbBytesPerBlock / m_sampleSize;
|
int sampleSize = m_dataBlock->m_superBlocks[m_blockIndex].m_header.m_sampleBytes * 2;
|
||||||
|
uint32_t samplesPerBlock = SDRDaemonNbBytesPerBlock / sampleSize;
|
||||||
|
|
||||||
if (m_sampleIndex < samplesPerBlock)
|
if (m_sampleIndex < samplesPerBlock)
|
||||||
{
|
{
|
||||||
convertDataToSample(s, m_blockIndex, m_sampleIndex);
|
convertDataToSample(s, m_blockIndex, m_sampleIndex, scaleForTx);
|
||||||
m_sampleIndex++;
|
m_sampleIndex++;
|
||||||
m_sampleCount++;
|
m_sampleCount++;
|
||||||
}
|
}
|
||||||
@ -123,7 +124,7 @@ void SDRDaemonDataReadQueue::readSample(Sample& s)
|
|||||||
|
|
||||||
if (m_blockIndex < SDRDaemonNbOrginalBlocks)
|
if (m_blockIndex < SDRDaemonNbOrginalBlocks)
|
||||||
{
|
{
|
||||||
convertDataToSample(s, m_blockIndex, m_sampleIndex);
|
convertDataToSample(s, m_blockIndex, m_sampleIndex, scaleForTx);
|
||||||
m_sampleIndex++;
|
m_sampleIndex++;
|
||||||
m_sampleCount++;
|
m_sampleCount++;
|
||||||
}
|
}
|
||||||
@ -144,7 +145,7 @@ void SDRDaemonDataReadQueue::readSample(Sample& s)
|
|||||||
//qDebug("SDRDaemonDataReadQueue::readSample: pop new block: queue size: %u", length());
|
//qDebug("SDRDaemonDataReadQueue::readSample: pop new block: queue size: %u", length());
|
||||||
m_blockIndex = 1;
|
m_blockIndex = 1;
|
||||||
m_dataBlock = m_dataReadQueue.takeFirst();
|
m_dataBlock = m_dataReadQueue.takeFirst();
|
||||||
convertDataToSample(s, m_blockIndex, m_sampleIndex);
|
convertDataToSample(s, m_blockIndex, m_sampleIndex, scaleForTx);
|
||||||
m_sampleIndex++;
|
m_sampleIndex++;
|
||||||
m_sampleCount++;
|
m_sampleCount++;
|
||||||
}
|
}
|
||||||
|
@ -31,12 +31,12 @@ class Sample;
|
|||||||
class SDRDaemonDataReadQueue
|
class SDRDaemonDataReadQueue
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SDRDaemonDataReadQueue(uint32_t sampleSize);
|
SDRDaemonDataReadQueue();
|
||||||
~SDRDaemonDataReadQueue();
|
~SDRDaemonDataReadQueue();
|
||||||
|
|
||||||
void push(SDRDaemonDataBlock* dataBlock); //!< push block on the queue
|
void push(SDRDaemonDataBlock* dataBlock); //!< push block on the queue
|
||||||
SDRDaemonDataBlock* pop(); //!< Pop block from the queue
|
SDRDaemonDataBlock* pop(); //!< Pop block from the queue
|
||||||
void readSample(Sample& s); //!< Read sample from queue
|
void readSample(Sample& s, bool scaleForTx = false); //!< Read sample from queue possibly scaling to Tx size
|
||||||
uint32_t length() const { return m_dataReadQueue.size(); } //!< Returns queue length
|
uint32_t length() const { return m_dataReadQueue.size(); } //!< Returns queue length
|
||||||
uint32_t size() const { return m_maxSize; } //!< Returns queue size (max length)
|
uint32_t size() const { return m_maxSize; } //!< Returns queue size (max length)
|
||||||
void setSize(uint32_t size); //!< Sets the queue size (max length)
|
void setSize(uint32_t size); //!< Sets the queue size (max length)
|
||||||
@ -45,7 +45,6 @@ public:
|
|||||||
static const uint32_t MinimumMaxSize;
|
static const uint32_t MinimumMaxSize;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint32_t m_sampleSize;
|
|
||||||
QQueue<SDRDaemonDataBlock*> m_dataReadQueue;
|
QQueue<SDRDaemonDataBlock*> m_dataReadQueue;
|
||||||
SDRDaemonDataBlock *m_dataBlock;
|
SDRDaemonDataBlock *m_dataBlock;
|
||||||
uint32_t m_maxSize;
|
uint32_t m_maxSize;
|
||||||
@ -54,25 +53,33 @@ private:
|
|||||||
uint32_t m_sampleCount; //!< use a counter capped below 2^31 as it is going to be converted to an int in the web interface
|
uint32_t m_sampleCount; //!< use a counter capped below 2^31 as it is going to be converted to an int in the web interface
|
||||||
bool m_full; //!< full condition was hit
|
bool m_full; //!< full condition was hit
|
||||||
|
|
||||||
inline void convertDataToSample(Sample& s, uint32_t blockIndex, uint32_t sampleIndex)
|
inline void convertDataToSample(Sample& s, uint32_t blockIndex, uint32_t sampleIndex, bool scaleForTx)
|
||||||
{
|
{
|
||||||
if (sizeof(Sample) == m_sampleSize)
|
int sampleSize = m_dataBlock->m_superBlocks[blockIndex].m_header.m_sampleBytes * 2; // I/Q sample size in data block
|
||||||
|
int samplebits = m_dataBlock->m_superBlocks[blockIndex].m_header.m_sampleBits; // I or Q sample size in bits
|
||||||
|
int32_t iconv, qconv;
|
||||||
|
|
||||||
|
if (sizeof(Sample) == sampleSize) // generally 16->16 or 24->24 bits
|
||||||
{
|
{
|
||||||
s = *((Sample*) &(m_dataBlock->m_superBlocks[blockIndex].m_protectedBlock.buf[sampleIndex*m_sampleSize]));
|
s = *((Sample*) &(m_dataBlock->m_superBlocks[blockIndex].m_protectedBlock.buf[sampleIndex*sampleSize]));
|
||||||
}
|
}
|
||||||
else if ((sizeof(Sample) == 4) && (m_sampleSize == 8))
|
else if ((sizeof(Sample) == 4) && (sampleSize == 8)) // generally 24->16 bits
|
||||||
{
|
{
|
||||||
int32_t rp = *( (int32_t*) &(m_dataBlock->m_superBlocks[blockIndex].m_protectedBlock.buf[sampleIndex*m_sampleSize]) );
|
iconv = ((int32_t*) &(m_dataBlock->m_superBlocks[blockIndex].m_protectedBlock.buf[sampleIndex*sampleSize]))[0];
|
||||||
int32_t ip = *( (int32_t*) &(m_dataBlock->m_superBlocks[blockIndex].m_protectedBlock.buf[sampleIndex*m_sampleSize+4]) );
|
qconv = ((int32_t*) &(m_dataBlock->m_superBlocks[blockIndex].m_protectedBlock.buf[sampleIndex*sampleSize+4]))[0];
|
||||||
s.setReal(rp>>8);
|
iconv >>= scaleForTx ? (SDR_TX_SAMP_SZ-SDR_RX_SAMP_SZ) : (samplebits-SDR_RX_SAMP_SZ);
|
||||||
s.setImag(ip>>8);
|
qconv >>= scaleForTx ? (SDR_TX_SAMP_SZ-SDR_RX_SAMP_SZ) : (samplebits-SDR_RX_SAMP_SZ);
|
||||||
|
s.setReal(iconv);
|
||||||
|
s.setImag(qconv);
|
||||||
}
|
}
|
||||||
else if ((sizeof(Sample) == 8) && (m_sampleSize == 4))
|
else if ((sizeof(Sample) == 8) && (sampleSize == 4)) // generally 16->24 bits
|
||||||
{
|
{
|
||||||
int32_t rp = *( (int16_t*) &(m_dataBlock->m_superBlocks[blockIndex].m_protectedBlock.buf[sampleIndex*m_sampleSize]) );
|
iconv = ((int16_t*) &(m_dataBlock->m_superBlocks[blockIndex].m_protectedBlock.buf[sampleIndex*sampleSize]))[0];
|
||||||
int32_t ip = *( (int16_t*) &(m_dataBlock->m_superBlocks[blockIndex].m_protectedBlock.buf[sampleIndex*m_sampleSize+2]) );
|
qconv = ((int16_t*) &(m_dataBlock->m_superBlocks[blockIndex].m_protectedBlock.buf[sampleIndex*sampleSize+2]))[0];
|
||||||
s.setReal(rp<<8);
|
iconv <<= scaleForTx ? (SDR_TX_SAMP_SZ-samplebits) : (SDR_RX_SAMP_SZ-samplebits);
|
||||||
s.setImag(ip<<8);
|
qconv <<= scaleForTx ? (SDR_TX_SAMP_SZ-samplebits) : (SDR_RX_SAMP_SZ-samplebits);
|
||||||
|
s.setReal(iconv);
|
||||||
|
s.setImag(qconv);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user