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

UDPSink: fixed wrong sample sizes based on I/Q actual sample size that can now be 16 or 32 bits

This commit is contained in:
f4exb 2018-04-19 00:43:29 +02:00
parent 5c51297717
commit f8251ecb50
5 changed files with 49 additions and 27 deletions

View File

@ -175,7 +175,7 @@ void UDPSink::modulateSample()
}
else if (m_settings.m_sampleFormat == UDPSinkSettings::FormatNFM)
{
FixReal t;
qint16 t;
readMonoSample(t);
m_inMovingAverage.feed((t*t)/1073741824.0);
@ -198,7 +198,7 @@ void UDPSink::modulateSample()
}
else if (m_settings.m_sampleFormat == UDPSinkSettings::FormatAM)
{
FixReal t;
qint16 t;
readMonoSample(t);
m_inMovingAverage.feed((t*t)/(SDR_TX_SCALED*SDR_TX_SCALED));
m_inMagsq = m_inMovingAverage.average();
@ -219,7 +219,7 @@ void UDPSink::modulateSample()
}
else if ((m_settings.m_sampleFormat == UDPSinkSettings::FormatLSB) || (m_settings.m_sampleFormat == UDPSinkSettings::FormatUSB))
{
FixReal t;
qint16 t;
Complex c, ci;
fftfilt::cmplx *filtered;
int n_out = 0;

View File

@ -300,14 +300,14 @@ private:
}
}
inline void readMonoSample(FixReal& t)
inline void readMonoSample(qint16& t)
{
Sample s;
if (m_settings.m_stereoInput)
{
m_udpHandler.readSample(s);
t = ((s.m_real + s.m_imag) * m_settings.m_gainIn) / 2;
AudioSample a;
m_udpHandler.readSample(a);
t = ((a.l + a.r) * m_settings.m_gainIn) / 2;
}
else
{

View File

@ -33,7 +33,7 @@ UDPSinkUDPHandler::UDPSinkUDPHandler() :
m_udpDumpIndex(0),
m_nbUDPFrames(m_minNbUDPFrames),
m_nbAllocatedUDPFrames(m_minNbUDPFrames),
m_writeIndex(0),
m_writeFrameIndex(0),
m_readFrameIndex(m_minNbUDPFrames/2),
m_readIndex(0),
m_rwDelta(m_minNbUDPFrames/2),
@ -129,31 +129,45 @@ void UDPSinkUDPHandler::dataReadyRead()
void UDPSinkUDPHandler::moveData(char *blk)
{
memcpy(m_udpBuf[m_writeIndex], blk, m_udpBlockSize);
memcpy(m_udpBuf[m_writeFrameIndex], blk, m_udpBlockSize);
if (m_writeIndex < m_nbUDPFrames - 1) {
m_writeIndex++;
if (m_writeFrameIndex < m_nbUDPFrames - 1) {
m_writeFrameIndex++;
} else {
m_writeIndex = 0;
m_writeFrameIndex = 0;
}
}
void UDPSinkUDPHandler::readSample(FixReal &t)
void UDPSinkUDPHandler::readSample(qint16 &t)
{
if (m_readFrameIndex == m_writeIndex) // block until more writes
if (m_readFrameIndex == m_writeFrameIndex) // block until more writes
{
t = 0;
}
else
{
memcpy(&t, &m_udpBuf[m_readFrameIndex][m_readIndex], sizeof(FixReal));
advanceReadPointer((int) sizeof(FixReal));
memcpy(&t, &m_udpBuf[m_readFrameIndex][m_readIndex], sizeof(qint16));
advanceReadPointer((int) sizeof(qint16));
}
}
void UDPSinkUDPHandler::readSample(AudioSample &a)
{
if (m_readFrameIndex == m_writeFrameIndex) // block until more writes
{
a.l = 0;
a.r = 0;
}
else
{
memcpy(&a, &m_udpBuf[m_readFrameIndex][m_readIndex], sizeof(AudioSample));
advanceReadPointer((int) sizeof(AudioSample));
}
}
void UDPSinkUDPHandler::readSample(Sample &s)
{
if (m_readFrameIndex == m_writeIndex) // block until more writes
if (m_readFrameIndex == m_writeFrameIndex) // block until more writes
{
s.m_real = 0;
s.m_imag = 0;
@ -181,7 +195,7 @@ void UDPSinkUDPHandler::advanceReadPointer(int nbBytes)
}
else
{
m_rwDelta = m_writeIndex; // raw R/W delta estimate
m_rwDelta = m_writeFrameIndex; // raw R/W delta estimate
int nbUDPFrames2 = m_nbUDPFrames/2;
float d = (m_rwDelta - nbUDPFrames2)/(float) m_nbUDPFrames;
//qDebug("UDPSinkUDPHandler::advanceReadPointer: w: %02d d: %f", m_writeIndex, d);
@ -233,7 +247,7 @@ void UDPSinkUDPHandler::applyUDPLink(const QString& address, quint16 port)
void UDPSinkUDPHandler::resetReadIndex()
{
m_readFrameIndex = (m_writeIndex + (m_nbUDPFrames/2)) % m_nbUDPFrames;
m_readFrameIndex = (m_writeFrameIndex + (m_nbUDPFrames/2)) % m_nbUDPFrames;
m_rwDelta = m_nbUDPFrames/2;
m_readIndex = 0;
m_d = 0.0f;
@ -252,7 +266,7 @@ void UDPSinkUDPHandler::resizeBuffer(float sampleRate)
}
m_nbUDPFrames = 2*halfNbFrames;
m_writeIndex = 0;
m_writeFrameIndex = 0;
resetReadIndex();
}

View File

@ -40,8 +40,9 @@ public:
void resetReadIndex();
void resizeBuffer(float sampleRate);
void readSample(FixReal &t);
void readSample(Sample &s);
void readSample(qint16 &t); //!< audio mono
void readSample(AudioSample &a); //!< audio stereo
void readSample(Sample &s); //!< I/Q stream
void setAutoRWBalance(bool autoRWBalance) { m_autoRWBalance = autoRWBalance; }
void setFeedbackMessageQueue(MessageQueue *messageQueue) { m_feedbackMessageQueue = messageQueue; }
@ -104,7 +105,7 @@ private:
int m_udpDumpIndex;
int m_nbUDPFrames;
int m_nbAllocatedUDPFrames;
int m_writeIndex;
int m_writeFrameIndex;
int m_readFrameIndex;
int m_readIndex;
int m_rwDelta;

View File

@ -26,6 +26,7 @@ def getInputOptions():
parser.add_option("-f", "--channel-freq", dest="channel_freq", help="channel center frequency (Hz)", metavar="FREQ", type="int")
parser.add_option("-s", "--sample-rate", dest="sample_rate", help="host to device sample rate (S/s)", metavar="RATE", type="int")
parser.add_option("-l", "--log2-interp", dest="log2_interp", help="log2 of interpolation factor", metavar="RATE", type="int")
parser.add_option("-L", "--log2-interp-hard", dest="log2_interp_hard", help="log2 of hardware interpolation factor", metavar="RATE", type="int")
parser.add_option("-A", "--antenna-path", dest="antenna_path", help="antenna path number", metavar="NUMBER", type="int")
parser.add_option("-c", "--create", dest="create", help="create a new device set", metavar="CREATE", action="store_true", default=False)
parser.add_option("--ppm", dest="lo_ppm", help="LO correction in ppm", metavar="FILENAME", type="float", default=0)
@ -55,6 +56,9 @@ def getInputOptions():
if options.log2_interp == None:
options.log2_interp = 4
if options.log2_interp_hard == None:
options.log2_interp = 4
if options.antenna_path == None:
options.antenna_path = 1
@ -121,7 +125,7 @@ def setupDevice(options):
elif options.device_hwid == "LimeSDR":
settings["limeSdrOutputSettings"]["antennaPath"] = options.antenna_path
settings["limeSdrOutputSettings"]["devSampleRate"] = options.sample_rate
settings["limeSdrOutputSettings"]["log2HardInterp"] = 4
settings["limeSdrOutputSettings"]["log2HardInterp"] = options.log2_interp_hard
settings["limeSdrOutputSettings"]["log2SoftInterp"] = options.log2_interp
settings["limeSdrOutputSettings"]["centerFrequency"] = options.device_freq*1000 + 500000
settings["limeSdrOutputSettings"]["ncoEnable"] = 1
@ -129,6 +133,7 @@ def setupDevice(options):
settings["limeSdrOutputSettings"]["lpfBW"] = 4050000
settings["limeSdrOutputSettings"]["lpfFIRBW"] = 100000
settings["limeSdrOutputSettings"]["lpfFIREnable"] = 1
settings["limeSdrOutputSettings"]["gain"] = 17
elif options.device_hwid == "HackRF":
settings['hackRFOutputSettings']['LOppmTenths'] = round(options.lo_ppm*10)
settings['hackRFOutputSettings']['centerFrequency'] = options.device_freq*1000
@ -208,13 +213,15 @@ def setupChannel(options):
settings["UDPSinkSettings"]["title"] = "Test UDP Sink"
settings["UDPSinkSettings"]["inputFrequencyOffset"] = options.channel_freq
settings["UDPSinkSettings"]["rfBandwidth"] = 12500
settings["UDPSinkSettings"]["fmDeviation"] = 5000
settings["UDPSinkSettings"]["autoRWBalance"] = 0
settings["UDPSinkSettings"]["fmDeviation"] = 6000
settings["UDPSinkSettings"]["autoRWBalance"] = 1
settings["UDPSinkSettings"]["stereoInput"] = 0
settings["UDPSinkSettings"]["udpAddress"] = "127.0.0.1"
settings["UDPSinkSettings"]["udpPort"] = 9998
settings["UDPSinkSettings"]["inputSampleRate"] = 24000
settings["UDPSinkSettings"]["inputSampleRate"] = 48000
settings["UDPSinkSettings"]["sampleFormat"] = 1 # FormatNFM
settings["UDPSinkSettings"]["gainIn"] = 2.5
settings["UDPSinkSettings"]["gainOut"] = 2.8
elif options.channel_id == "WFMMod":
settings["WFMModSettings"]["title"] = "Test WFM"
settings["WFMModSettings"]["inputFrequencyOffset"] = options.channel_freq