1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-23 01:55:48 -05:00

Remote data queue: fixed sample conversion

This commit is contained in:
f4exb 2021-12-18 22:48:20 +01:00
parent 78be244dc6
commit 316e635466
3 changed files with 35 additions and 30 deletions

View File

@ -53,7 +53,7 @@ void RemoteSourceSource::pull(SampleVector::iterator begin, unsigned int nbSampl
void RemoteSourceSource::pullOne(Sample& sample)
{
m_dataReadQueue.readSample(sample, true); // true is scale for Tx
m_dataReadQueue.readSample(sample);
}
void RemoteSourceSource::start()

View File

@ -77,7 +77,7 @@ void RemoteDataReadQueue::setSize(uint32_t size)
}
}
void RemoteDataReadQueue::readSample(Sample& s, bool scaleForTx)
void RemoteDataReadQueue::readSample(Sample& s)
{
// depletion/repletion state
if (m_dataFrame == nullptr)
@ -89,7 +89,7 @@ void RemoteDataReadQueue::readSample(Sample& s, bool scaleForTx)
qDebug("RemoteDataReadQueue::readSample: initial pop new frame: queue size: %u", length());
m_blockIndex = 1;
m_sampleIndex = 0;
convertDataToSample(s, m_blockIndex, m_sampleIndex, scaleForTx);
convertDataToSample(s, m_blockIndex, m_sampleIndex);
m_sampleIndex++;
}
else
@ -107,7 +107,7 @@ void RemoteDataReadQueue::readSample(Sample& s, bool scaleForTx)
if (m_sampleIndex < samplesPerBlock)
{
convertDataToSample(s, m_blockIndex, m_sampleIndex, scaleForTx);
convertDataToSample(s, m_blockIndex, m_sampleIndex);
m_sampleIndex++;
m_sampleCount++;
}
@ -118,7 +118,7 @@ void RemoteDataReadQueue::readSample(Sample& s, bool scaleForTx)
if (m_blockIndex < RemoteNbOrginalBlocks)
{
convertDataToSample(s, m_blockIndex, m_sampleIndex, scaleForTx);
convertDataToSample(s, m_blockIndex, m_sampleIndex);
m_sampleIndex++;
m_sampleCount++;
}
@ -133,7 +133,7 @@ void RemoteDataReadQueue::readSample(Sample& s, bool scaleForTx)
{
m_blockIndex = 1;
m_sampleIndex = 0;
convertDataToSample(s, m_blockIndex, m_sampleIndex, scaleForTx);
convertDataToSample(s, m_blockIndex, m_sampleIndex);
m_sampleIndex++;
m_sampleCount++;
}

View File

@ -39,7 +39,7 @@ public:
~RemoteDataReadQueue();
void push(RemoteDataFrame* dataFrame); //!< push frame on the queue
void readSample(Sample& s, bool scaleForTx = false); //!< Read sample from queue possibly scaling to Tx size
void readSample(Sample& s); //!< Read sample from queue
uint32_t length() const { return m_dataReadQueue.size(); } //!< Returns queue length
uint32_t size() const { return m_maxSize; } //!< Returns queue size (max length)
void setSize(uint32_t size); //!< Sets the queue size (max length)
@ -57,37 +57,42 @@ private:
RemoteDataFrame* pop(); //!< Pop frame from the queue
inline void convertDataToSample(Sample& s, uint32_t blockIndex, uint32_t sampleIndex, bool scaleForTx)
inline void convertDataToSample(Sample& s, uint32_t blockIndex, uint32_t sampleIndex)
{
int sampleSize = m_dataFrame->m_superBlocks[blockIndex].m_header.m_sampleBytes * 2; // I/Q sample size in data block
int samplebits = m_dataFrame->m_superBlocks[blockIndex].m_header.m_sampleBits; // I or Q sample size in bits
int32_t iconv, qconv;
if ((sizeof(Sample) == 4) && (sampleSize == 8)) // generally 24->16 bits
{
iconv = ((int32_t*) &(m_dataFrame->m_superBlocks[blockIndex].m_protectedBlock.buf[sampleIndex*sampleSize]))[0];
qconv = ((int32_t*) &(m_dataFrame->m_superBlocks[blockIndex].m_protectedBlock.buf[sampleIndex*sampleSize+4]))[0];
iconv >>= scaleForTx ? (SDR_TX_SAMP_SZ-SDR_RX_SAMP_SZ) : (samplebits-SDR_RX_SAMP_SZ);
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) && (sampleSize == 4)) // generally 16->24 bits
{
iconv = ((int16_t*) &(m_dataFrame->m_superBlocks[blockIndex].m_protectedBlock.buf[sampleIndex*sampleSize]))[0];
qconv = ((int16_t*) &(m_dataFrame->m_superBlocks[blockIndex].m_protectedBlock.buf[sampleIndex*sampleSize+2]))[0];
iconv <<= scaleForTx ? (SDR_TX_SAMP_SZ-samplebits) : (SDR_RX_SAMP_SZ-samplebits);
qconv <<= scaleForTx ? (SDR_TX_SAMP_SZ-samplebits) : (SDR_RX_SAMP_SZ-samplebits);
s.setReal(iconv);
s.setImag(qconv);
}
else if ((sampleSize == 4) || (sampleSize == 8)) // generally 16->16 or 24->24 bits
if (sizeof(Sample) == sampleSize) // no conversion
{
s = *((Sample*) &(m_dataFrame->m_superBlocks[blockIndex].m_protectedBlock.buf[sampleIndex*sampleSize]));
}
else // invalid size
else
{
s = Sample{0, 0};
if (sampleSize == 2) // 8 -> 16 or 24 bits
{
iconv = ((int32_t*) &(m_dataFrame->m_superBlocks[blockIndex].m_protectedBlock.buf[sampleIndex*sampleSize]))[0] << sizeof(Sample)*2;
qconv = ((int32_t*) &(m_dataFrame->m_superBlocks[blockIndex].m_protectedBlock.buf[sampleIndex*sampleSize+sampleSize]))[0] << sizeof(Sample)*2;
s.setReal(iconv);
s.setImag(qconv);
}
else if (sampleSize == 4) // 16 -> 24 bits
{
iconv = ((int16_t*) &(m_dataFrame->m_superBlocks[blockIndex].m_protectedBlock.buf[sampleIndex*sampleSize]))[0] << 8;
qconv = ((int16_t*) &(m_dataFrame->m_superBlocks[blockIndex].m_protectedBlock.buf[sampleIndex*sampleSize+2]))[0] << 8;
s.setReal(iconv);
s.setImag(qconv);
}
else if (sampleSize == 8) // 24 -> 16 bits
{
iconv = ((int32_t*) &(m_dataFrame->m_superBlocks[blockIndex].m_protectedBlock.buf[sampleIndex*sampleSize]))[0] >> 8;
qconv = ((int32_t*) &(m_dataFrame->m_superBlocks[blockIndex].m_protectedBlock.buf[sampleIndex*sampleSize+4]))[0] >> 8;
s.setReal(iconv);
s.setImag(qconv);
}
else // invalid
{
s = Sample{0, 0};
}
}
}
};