1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-21 15:51:47 -05:00

Remote: more fixes in conversion routines

This commit is contained in:
f4exb 2021-12-20 22:30:43 +01:00
parent ab9f316737
commit 7c8cb7a85a
8 changed files with 74 additions and 71 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

View File

@ -56,17 +56,6 @@ When the return key is hit within the address (1) or port (2) the changes are ef
This sets the number of FEC blocks per frame. A frame consists of 128 data blocks (1 meta data block followed by 127 I/Q data blocks) and a variable number of FEC blocks used to protect the UDP transmission with a Cauchy MDS block erasure correction. The two numbers next are the total number of blocks and the number of FEC blocks separated by a slash (/).
<h3>10: Delay between UDP blocks transmission</h3>
<h3>10: Transmission sample size</h3>
This sets the minimum delay between transmission of an UDP block (send datagram) and the next. This allows throttling of the UDP transmission that is otherwise uncontrolled and causes network congestion.
The value is a percentage of the nominal time it takes to process a block of samples corresponding to one UDP block (512 bytes). This is calculated as follows:
- Sample rate on the network: _SR_
- Delay percentage: _d_
- Number of FEC blocks: _F_
- There are 127 blocks of I/Q data per frame (1 meta block for 128 blocks) and each I/Q data block of 512 bytes (128 samples) has a 8 bytes header (2 samples) thus there are 126 samples remaining effectively. This gives the constant 127*126 = 16002 samples per frame in the formula
Formula: ((127 &#x2715; 126 &#x2715; _d_) / _SR_) / (128 + _F_)
The percentage appears first at the right of the dial button and then the actual delay value in microseconds.
Number of bytes per I or Q sample in transmission.

View File

@ -144,7 +144,7 @@ void RemoteSinkSink::feed(const SampleVector::const_iterator& begin, const Sampl
} // block zero
// handle different sample sizes...
int samplesPerBlock = RemoteNbBytesPerBlock / (SDR_RX_SAMP_SZ <= 16 ? 4 : 8); // two I or Q samples
int samplesPerBlock = RemoteNbBytesPerBlock / (2 * m_nbTxBytes); // two I or Q samples
if (m_sampleIndex + inRemainingSamples < samplesPerBlock) // there is still room in the current super block
{
convertSampleToData(begin + inSamplesIndex, inRemainingSamples, false);

View File

@ -96,12 +96,12 @@ private:
*((int16_t*) &m_superBlock.m_protectedBlock.buf[(m_sampleIndex+ i)*m_nbTxBytes*2 + m_nbTxBytes]) = (begin+i)->m_imag;
}
}
else if (m_nbTxBytes == 1) // 16 -> 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] = (uint8_t) ((begin+i)->m_real / 256);
m_superBlock.m_protectedBlock.buf[(m_sampleIndex+ i)*m_nbTxBytes*2 + m_nbTxBytes] = (uint8_t) ((begin+i)->m_imag / 256);
*((int8_t*) &m_superBlock.m_protectedBlock.buf[(m_sampleIndex+ i)*m_nbTxBytes*2]) = (int8_t) ((begin+i)->m_real / (1<<8));
*((int8_t*) &m_superBlock.m_protectedBlock.buf[(m_sampleIndex+ i)*m_nbTxBytes*2 + m_nbTxBytes]) = (int8_t) ((begin+i)->m_imag / (1<<8));
}
}
}
@ -111,26 +111,32 @@ private:
{
for (int i = 0; i < nbSamples; i++)
{
*((int32_t*) &m_superBlock.m_protectedBlock.buf[(m_sampleIndex+ i)*m_nbTxBytes*2]) = (begin+i)->m_real << 8;
*((int32_t*) &m_superBlock.m_protectedBlock.buf[(m_sampleIndex+ i)*m_nbTxBytes*2 + m_nbTxBytes]) = (begin+i)->m_imag << 8;
*((int32_t*) &m_superBlock.m_protectedBlock.buf[(m_sampleIndex+ i)*m_nbTxBytes*2]) = (begin+i)->m_real * (1<<8);
*((int32_t*) &m_superBlock.m_protectedBlock.buf[(m_sampleIndex+ i)*m_nbTxBytes*2 + m_nbTxBytes]) = (begin+i)->m_imag * (1<<8);
}
}
else if (m_nbTxBytes == 2) // 24 -> 16
{
for (int i = 0; i < nbSamples; i++)
{
*((int16_t*) &m_superBlock.m_protectedBlock.buf[(m_sampleIndex+ i)*m_nbTxBytes*2]) = (begin+i)->m_real >> 8;
*((int16_t*) &m_superBlock.m_protectedBlock.buf[(m_sampleIndex+ i)*m_nbTxBytes*2 + m_nbTxBytes]) = (begin+i)->m_imag >> 8;
*((int16_t*) &m_superBlock.m_protectedBlock.buf[(m_sampleIndex+ i)*m_nbTxBytes*2]) = (begin+i)->m_real / (1<<8);
*((int16_t*) &m_superBlock.m_protectedBlock.buf[(m_sampleIndex+ i)*m_nbTxBytes*2 + m_nbTxBytes]) = (begin+i)->m_imag / (1<<8);
}
}
else if (m_nbTxBytes == 1) // 16 or 24 -> 8
else if ((m_nbTxBytes == 1) && (sizeof(Sample) == 4)) // 16 -> 8
{
for (int i = 0; i < nbSamples; i++)
{
m_superBlock.m_protectedBlock.buf[(m_sampleIndex+ i)*m_nbTxBytes*2] =
(uint8_t) (((begin+i)->m_real / (1<<sizeof(Sample)*2)) & 0xFF);
m_superBlock.m_protectedBlock.buf[(m_sampleIndex+ i)*m_nbTxBytes*2 + m_nbTxBytes] =
(uint8_t) (((begin+i)->m_imag / (1<<sizeof(Sample)*2)) & 0xFF);
*((int8_t*) &m_superBlock.m_protectedBlock.buf[(m_sampleIndex+ i)*m_nbTxBytes*2]) = (int8_t) ((begin+i)->m_real / (1<<8));
*((int8_t*) &m_superBlock.m_protectedBlock.buf[(m_sampleIndex+ i)*m_nbTxBytes*2 + m_nbTxBytes]) = (int8_t) ((begin+i)->m_imag / (1<<8));
}
}
else if ((m_nbTxBytes == 1) && (sizeof(Sample) == 8)) // 24 -> 8
{
for (int i = 0; i < nbSamples; i++)
{
*((int8_t*) &m_superBlock.m_protectedBlock.buf[(m_sampleIndex+ i)*m_nbTxBytes*2]) = (int8_t) ((begin+i)->m_real / (1<<16));
*((int8_t*) &m_superBlock.m_protectedBlock.buf[(m_sampleIndex+ i)*m_nbTxBytes*2 + m_nbTxBytes]) = (int8_t) ((begin+i)->m_imag / (1<<16));
}
}
}

View File

@ -128,12 +128,12 @@ private:
*((int16_t*) &m_superBlock.m_protectedBlock.buf[(m_sampleIndex+ i)*m_nbTxBytes*2 + m_nbTxBytes]) = (begin+i)->m_imag;
}
}
else if (m_nbTxBytes == 1) // 16 -> 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] = (uint8_t) ((begin+i)->m_real / 256);
m_superBlock.m_protectedBlock.buf[(m_sampleIndex+ i)*m_nbTxBytes*2 + m_nbTxBytes] = (uint8_t) ((begin+i)->m_imag / 256);
*((int8_t*) &m_superBlock.m_protectedBlock.buf[(m_sampleIndex+ i)*m_nbTxBytes*2]) = (int8_t) ((begin+i)->m_real / (1<<8));
*((int8_t*) &m_superBlock.m_protectedBlock.buf[(m_sampleIndex+ i)*m_nbTxBytes*2 + m_nbTxBytes]) = (int8_t) ((begin+i)->m_imag / (1<<8));
}
}
}
@ -143,26 +143,32 @@ private:
{
for (int i = 0; i < nbSamples; i++)
{
*((int32_t*) &m_superBlock.m_protectedBlock.buf[(m_sampleIndex+ i)*m_nbTxBytes*2]) = (begin+i)->m_real << 8;
*((int32_t*) &m_superBlock.m_protectedBlock.buf[(m_sampleIndex+ i)*m_nbTxBytes*2 + m_nbTxBytes]) = (begin+i)->m_imag << 8;
*((int32_t*) &m_superBlock.m_protectedBlock.buf[(m_sampleIndex+ i)*m_nbTxBytes*2]) = (begin+i)->m_real * (1<<8);
*((int32_t*) &m_superBlock.m_protectedBlock.buf[(m_sampleIndex+ i)*m_nbTxBytes*2 + m_nbTxBytes]) = (begin+i)->m_imag * (1<<8);
}
}
else if (m_nbTxBytes == 2) // 24 -> 16
{
for (int i = 0; i < nbSamples; i++)
{
*((int16_t*) &m_superBlock.m_protectedBlock.buf[(m_sampleIndex+ i)*m_nbTxBytes*2]) = (begin+i)->m_real >> 8;
*((int16_t*) &m_superBlock.m_protectedBlock.buf[(m_sampleIndex+ i)*m_nbTxBytes*2 + m_nbTxBytes]) = (begin+i)->m_imag >> 8;
*((int16_t*) &m_superBlock.m_protectedBlock.buf[(m_sampleIndex+ i)*m_nbTxBytes*2]) = (begin+i)->m_real / (1<<8);
*((int16_t*) &m_superBlock.m_protectedBlock.buf[(m_sampleIndex+ i)*m_nbTxBytes*2 + m_nbTxBytes]) = (begin+i)->m_imag / (1<<8);
}
}
else if (m_nbTxBytes == 1) // 16 or 24 -> 8
else if ((m_nbTxBytes == 1) && (sizeof(Sample) == 4)) // 16 -> 8
{
for (int i = 0; i < nbSamples; i++)
{
m_superBlock.m_protectedBlock.buf[(m_sampleIndex+ i)*m_nbTxBytes*2] =
(uint8_t) (((begin+i)->m_real / (1<<sizeof(Sample)*2)) & 0xFF);
m_superBlock.m_protectedBlock.buf[(m_sampleIndex+ i)*m_nbTxBytes*2 + m_nbTxBytes] =
(uint8_t) (((begin+i)->m_imag / (1<<sizeof(Sample)*2)) & 0xFF);
*((int8_t*) &m_superBlock.m_protectedBlock.buf[(m_sampleIndex+ i)*m_nbTxBytes*2]) = (int8_t) ((begin+i)->m_real / (1<<8));
*((int8_t*) &m_superBlock.m_protectedBlock.buf[(m_sampleIndex+ i)*m_nbTxBytes*2 + m_nbTxBytes]) = (int8_t) ((begin+i)->m_imag / (1<<8));
}
}
else if ((m_nbTxBytes == 1) && (sizeof(Sample) == 4)) // 24 -> 8
{
for (int i = 0; i < nbSamples; i++)
{
*((int8_t*) &m_superBlock.m_protectedBlock.buf[(m_sampleIndex+ i)*m_nbTxBytes*2]) = (int8_t) ((begin+i)->m_real / (1<<16));
*((int8_t*) &m_superBlock.m_protectedBlock.buf[(m_sampleIndex+ i)*m_nbTxBytes*2 + m_nbTxBytes]) = (int8_t) ((begin+i)->m_imag / (1<<16));
}
}
}

View File

@ -340,13 +340,13 @@ void RemoteInputUDPHandler::tick()
m_converterBuffer = new int32_t[m_readLengthSamples];
}
uint8_t *buf = m_remoteInputBuffer.readData(m_readLength);
int8_t *buf = (int8_t*) m_remoteInputBuffer.readData(m_readLength);
for (int is = 0; is < m_readLengthSamples; is++)
{
m_converterBuffer[is] = buf[2*is+1] << 8; // Q -> MSB
m_converterBuffer[is] = buf[2*is+1] * (1<<8); // Q -> MSB
m_converterBuffer[is] <<= 16;
m_converterBuffer[is] += buf[2*is] << 8; // I -> LSB
m_converterBuffer[is] += buf[2*is] * (1<<8); // I -> LSB
}
}
else if ((metaData.m_sampleBits == 8) && (SDR_RX_SAMP_SZ == 24)) // 8 -> 24
@ -357,14 +357,12 @@ void RemoteInputUDPHandler::tick()
m_converterBuffer = new int32_t[m_readLengthSamples*2];
}
uint8_t *buf = m_remoteInputBuffer.readData(m_readLength);
int8_t *buf = (int8_t*) m_remoteInputBuffer.readData(m_readLength);
for (int is = 0; is < m_readLengthSamples; is++)
{
m_converterBuffer[2*is] = buf[2*is]; // I
m_converterBuffer[2*is] <<= 16;
m_converterBuffer[2*is+1] = buf[2*is+1]; // Q
m_converterBuffer[2*is+1] <<= 16;
m_converterBuffer[2*is] = buf[2*is] * (1<<16); // I
m_converterBuffer[2*is+1] = buf[2*is+1] * (1<<16); // Q
}
m_sampleFifo->write(reinterpret_cast<quint8*>(m_converterBuffer), m_readLengthSamples*sizeof(Sample));
@ -377,14 +375,12 @@ void RemoteInputUDPHandler::tick()
m_converterBuffer = new int32_t[m_readLengthSamples*2];
}
uint8_t *buf = m_remoteInputBuffer.readData(m_readLength);
int16_t *buf = (int16_t*) m_remoteInputBuffer.readData(m_readLength);
for (int is = 0; is < m_readLengthSamples; is++)
{
m_converterBuffer[2*is] = ((int16_t*)buf)[2*is]; // I
m_converterBuffer[2*is] <<= 8;
m_converterBuffer[2*is+1] = ((int16_t*)buf)[2*is+1]; // Q
m_converterBuffer[2*is+1] <<= 8;
m_converterBuffer[2*is] = buf[2*is] * (1<<8); // I
m_converterBuffer[2*is+1] = buf[2*is+1] * (1<<8); // Q
}
m_sampleFifo->write(reinterpret_cast<quint8*>(m_converterBuffer), m_readLengthSamples*sizeof(Sample));
@ -397,13 +393,13 @@ void RemoteInputUDPHandler::tick()
m_converterBuffer = new int32_t[m_readLengthSamples];
}
uint8_t *buf = m_remoteInputBuffer.readData(m_readLength);
int32_t *buf = (int32_t*) m_remoteInputBuffer.readData(m_readLength);
for (int is = 0; is < m_readLengthSamples; is++)
{
m_converterBuffer[is] = ((int32_t *)buf)[2*is+1]>>8; // Q -> MSB
m_converterBuffer[is] = buf[2*is+1] / (1<<8); // Q -> MSB
m_converterBuffer[is] <<= 16;
m_converterBuffer[is] += ((int32_t *)buf)[2*is]>>8; // I -> LSB
m_converterBuffer[is] += buf[2*is] / (1<<8); // I -> LSB
}
m_sampleFifo->write(reinterpret_cast<quint8*>(m_converterBuffer), m_readLengthSamples*sizeof(Sample));

View File

@ -70,24 +70,23 @@ private:
{
if (sampleSize == 2) // 8 -> 16 bits
{
int8_t iu = m_dataFrame->m_superBlocks[blockIndex].m_protectedBlock.buf[sampleIndex*sampleSize];
int8_t qu = m_dataFrame->m_superBlocks[blockIndex].m_protectedBlock.buf[sampleIndex*sampleSize+1];
iconv = iu * (1 << 8);
qconv = qu * (1 << 8);
int8_t *buf = (int8_t*) m_dataFrame->m_superBlocks[blockIndex].m_protectedBlock.buf;
iconv = buf[sampleIndex*sampleSize] * (1<<8);
qconv = buf[sampleIndex*sampleSize+1] * (1<<8);
s.setReal(iconv);
s.setImag(qconv);
}
else if (sampleSize == 4) // just convert types (always 16 bits wide)
{
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 = *((int16_t*) &(m_dataFrame->m_superBlocks[blockIndex].m_protectedBlock.buf[sampleIndex*sampleSize]));
qconv = *((int16_t*) &(m_dataFrame->m_superBlocks[blockIndex].m_protectedBlock.buf[sampleIndex*sampleSize+2]));
s.setReal(iconv);
s.setImag(qconv);
}
else if (sampleSize == 8) // just convert types (always 16 bits wide)
{
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 = *((int32_t*) &(m_dataFrame->m_superBlocks[blockIndex].m_protectedBlock.buf[sampleIndex*sampleSize]));
qconv = *((int32_t*) &(m_dataFrame->m_superBlocks[blockIndex].m_protectedBlock.buf[sampleIndex*sampleSize+4]));
s.setReal(iconv);
s.setImag(qconv);
}
@ -98,26 +97,33 @@ private:
}
else
{
if (sampleSize == 2) // 8 -> 16 or 24 bits
if ((sampleSize == 2) && (sizeof(Sample) == 2)) // 8 -> 16 bits
{
int8_t iu = m_dataFrame->m_superBlocks[blockIndex].m_protectedBlock.buf[sampleIndex*sampleSize];
int8_t qu = m_dataFrame->m_superBlocks[blockIndex].m_protectedBlock.buf[sampleIndex*sampleSize+1];
iconv = iu * (1 << sizeof(Sample)*2);
qconv = qu * (1 << sizeof(Sample)*2);
int8_t *buf = (int8_t*) m_dataFrame->m_superBlocks[blockIndex].m_protectedBlock.buf;
iconv = buf[sampleIndex*sampleSize] * (1<<8);
qconv = buf[sampleIndex*sampleSize+1] * (1<<8);
s.setReal(iconv);
s.setImag(qconv);
}
else if ((sampleSize == 2) && (sizeof(Sample) == 4)) // 8 -> 24 bits
{
int8_t *buf = (int8_t*) m_dataFrame->m_superBlocks[blockIndex].m_protectedBlock.buf;
iconv = buf[sampleIndex*sampleSize] * (1<<16);
qconv = buf[sampleIndex*sampleSize+1] * (1<<16);
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;
iconv = *((int16_t*) &(m_dataFrame->m_superBlocks[blockIndex].m_protectedBlock.buf[sampleIndex*sampleSize])) * (1<<8);
qconv = *((int16_t*) &(m_dataFrame->m_superBlocks[blockIndex].m_protectedBlock.buf[sampleIndex*sampleSize+2])) * (1<<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;
iconv = *((int32_t*) &(m_dataFrame->m_superBlocks[blockIndex].m_protectedBlock.buf[sampleIndex*sampleSize])) / (1<<8);
qconv = *((int32_t*) &(m_dataFrame->m_superBlocks[blockIndex].m_protectedBlock.buf[sampleIndex*sampleSize+4])) / (1<<8);
s.setReal(iconv);
s.setImag(qconv);
}