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

Remote output: variable sample size in transmission. For now fixed to 16

This commit is contained in:
f4exb 2021-12-18 22:49:05 +01:00
parent 316e635466
commit 6cc1616cb8
2 changed files with 69 additions and 13 deletions

View File

@ -31,6 +31,8 @@ UDPSinkFEC::UDPSinkFEC() :
m_sampleRate(48000),
m_nbSamples(0),
m_nbBlocksFEC(0),
//m_nbTxBytes(SDR_RX_SAMP_SZ <= 16 ? 2 : 4),
m_nbTxBytes(2),
m_txDelayRatio(0.0),
m_dataFrame(nullptr),
m_txBlockIndex(0),
@ -108,8 +110,8 @@ void UDPSinkFEC::write(const SampleVector::iterator& begin, uint32_t sampleChunk
metaData.m_centerFrequency = 0; // frequency not set by stream
metaData.m_sampleRate = m_sampleRate;
metaData.m_sampleBytes = (SDR_RX_SAMP_SZ <= 16 ? 2 : 4);
metaData.m_sampleBits = SDR_RX_SAMP_SZ;
metaData.m_sampleBytes = m_nbTxBytes;;
metaData.m_sampleBits = getNbSampleBits();
metaData.m_nbOriginalBlocks = RemoteNbOrginalBlocks;
metaData.m_nbFECBlocks = m_nbBlocksFEC;
metaData.m_tv_sec = nowus / 1000000UL; // tv.tv_sec;
@ -126,8 +128,8 @@ void UDPSinkFEC::write(const SampleVector::iterator& begin, uint32_t sampleChunk
superBlock.init();
superBlock.m_header.m_frameIndex = m_frameCount;
superBlock.m_header.m_blockIndex = m_txBlockIndex;
superBlock.m_header.m_sampleBytes = (SDR_RX_SAMP_SZ <= 16 ? 2 : 4);
superBlock.m_header.m_sampleBits = SDR_RX_SAMP_SZ;
superBlock.m_header.m_sampleBytes = m_nbTxBytes;
superBlock.m_header.m_sampleBits = getNbSampleBits();
RemoteMetaDataFEC *destMeta = (RemoteMetaDataFEC *) &superBlock.m_protectedBlock;
*destMeta = metaData;
@ -151,27 +153,29 @@ void UDPSinkFEC::write(const SampleVector::iterator& begin, uint32_t sampleChunk
} // block zero
// handle different sample sizes...
int samplesPerBlock = RemoteNbBytesPerBlock / (SDR_RX_SAMP_SZ <= 16 ? 4 : 8); // two I or Q samples
int samplesPerBlock = RemoteNbBytesPerBlock / (m_nbTxBytes * 2); // two I or Q samples
if (m_sampleIndex + inRemainingSamples < samplesPerBlock) // there is still room in the current super block
{
memcpy((void *) &m_superBlock.m_protectedBlock.buf[m_sampleIndex*sizeof(Sample)],
(const void *) &(*(begin+inSamplesIndex)),
inRemainingSamples * sizeof(Sample));
convertSampleToData(begin + inSamplesIndex, inRemainingSamples);
// memcpy((void *) &m_superBlock.m_protectedBlock.buf[m_sampleIndex*sizeof(Sample)],
// (const void *) &(*(begin+inSamplesIndex)),
// inRemainingSamples * sizeof(Sample));
m_sampleIndex += inRemainingSamples;
it = end; // all input samples are consumed
}
else // complete super block and initiate the next if not end of frame
{
memcpy((void *) &m_superBlock.m_protectedBlock.buf[m_sampleIndex*sizeof(Sample)],
(const void *) &(*(begin+inSamplesIndex)),
(samplesPerBlock - m_sampleIndex) * sizeof(Sample));
convertSampleToData(begin + inSamplesIndex, samplesPerBlock - m_sampleIndex);
// memcpy((void *) &m_superBlock.m_protectedBlock.buf[m_sampleIndex*sizeof(Sample)],
// (const void *) &(*(begin+inSamplesIndex)),
// (samplesPerBlock - m_sampleIndex) * sizeof(Sample));
it += samplesPerBlock - m_sampleIndex;
m_sampleIndex = 0;
m_superBlock.m_header.m_frameIndex = m_frameCount;
m_superBlock.m_header.m_blockIndex = m_txBlockIndex;
m_superBlock.m_header.m_sampleBytes = (SDR_RX_SAMP_SZ <= 16 ? 2 : 4);
m_superBlock.m_header.m_sampleBits = SDR_RX_SAMP_SZ;
m_superBlock.m_header.m_sampleBytes = m_nbTxBytes;
m_superBlock.m_header.m_sampleBits = getNbSampleBits();
m_dataFrame->m_superBlocks[m_txBlockIndex] = m_superBlock;
if (m_txBlockIndex == RemoteNbOrginalBlocks - 1) // frame complete
@ -196,3 +200,15 @@ void UDPSinkFEC::write(const SampleVector::iterator& begin, uint32_t sampleChunk
}
}
uint32_t UDPSinkFEC::getNbSampleBits()
{
if (m_nbTxBytes == 1) {
return 8;
} else if (m_nbTxBytes == 2) {
return 16;
} else if (m_nbTxBytes == 4) {
return 24;
} else {
return 16;
}
}

View File

@ -85,6 +85,7 @@ private:
CRC64 m_crc64;
RemoteMetaDataFEC m_currentMetaFEC; //!< Meta data for current frame
uint32_t m_nbBlocksFEC; //!< Variable number of FEC blocks
uint32_t m_nbTxBytes;
float m_txDelayRatio; //!< Delay in ratio of nominal frame period
RemoteDataFrame *m_dataFrame;
RemoteSuperBlock m_superBlock; //!< current super block being built
@ -97,6 +98,45 @@ private:
QThread *m_senderThread;
QString m_remoteAddress;
uint16_t m_remotePort;
uint32_t getNbSampleBits();
inline void convertSampleToData(const SampleVector::iterator& begin, int nbSamples)
{
if (sizeof(Sample) == m_nbTxBytes * 2) // 16 -> 16 or 24 ->24: direct copy
{
memcpy((void *) &m_superBlock.m_protectedBlock.buf[m_sampleIndex*m_nbTxBytes*2],
(const void *) &(*(begin)),
nbSamples * sizeof(Sample));
}
else
{
if (m_nbTxBytes == 4) // 16 -> 24
{
for (int i = 0; i < nbSamples; i++)
{
m_superBlock.m_protectedBlock.buf[(m_sampleIndex+ i)*m_nbTxBytes*2] = (begin+i)->m_real << 8;
m_superBlock.m_protectedBlock.buf[(m_sampleIndex+ i)*m_nbTxBytes*2 + m_nbTxBytes] = (begin+i)->m_imag << 8;
}
}
else if (m_nbTxBytes == 2) // 24 -> 16
{
for (int i = 0; i < nbSamples; i++)
{
m_superBlock.m_protectedBlock.buf[(m_sampleIndex+ i)*m_nbTxBytes*2] = (begin+i)->m_real >> 8;
m_superBlock.m_protectedBlock.buf[(m_sampleIndex+ i)*m_nbTxBytes*2 + m_nbTxBytes] = (begin+i)->m_imag >> 8;
}
}
else if (m_nbTxBytes == 1) // 16 or 24 -> 8
{
for (int i = 0; i < nbSamples; i++)
{
m_superBlock.m_protectedBlock.buf[(m_sampleIndex+ i)*m_nbTxBytes*2] = (begin+i)->m_real >> sizeof(Sample)*2;
m_superBlock.m_protectedBlock.buf[(m_sampleIndex+ i)*m_nbTxBytes*2 + m_nbTxBytes] = (begin+i)->m_imag >> sizeof(Sample)*2;
}
}
}
}
};
#endif /* PLUGINS_SAMPLESINK_REMOTEOUTPUT_UDPSINKFEC_H_ */