diff --git a/plugins/channeltx/remotesource/remotesourcesource.cpp b/plugins/channeltx/remotesource/remotesourcesource.cpp index 2bd610d07..414f6ecaf 100644 --- a/plugins/channeltx/remotesource/remotesourcesource.cpp +++ b/plugins/channeltx/remotesource/remotesourcesource.cpp @@ -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() diff --git a/sdrbase/channel/remotedatareadqueue.cpp b/sdrbase/channel/remotedatareadqueue.cpp index 1b9fceeb7..c8019f19f 100644 --- a/sdrbase/channel/remotedatareadqueue.cpp +++ b/sdrbase/channel/remotedatareadqueue.cpp @@ -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++; } diff --git a/sdrbase/channel/remotedatareadqueue.h b/sdrbase/channel/remotedatareadqueue.h index 1f62ad48f..51cacfe25 100644 --- a/sdrbase/channel/remotedatareadqueue.h +++ b/sdrbase/channel/remotedatareadqueue.h @@ -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}; + } } } };