From 3d77c9af9bce72d52c19f7d1b1982fbc1bd6cd89 Mon Sep 17 00:00:00 2001 From: f4exb Date: Wed, 24 Jan 2018 08:49:18 +0100 Subject: [PATCH] SDRDaemon input: adaptation for 24 bit Rx DSP --- .../sdrdaemonsourceudphandler.cpp | 32 +++++++++++++++++-- .../sdrdaemonsourceudphandler.h | 2 ++ sdrbase/dsp/samplesinkfifo.cpp | 4 +-- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/plugins/samplesource/sdrdaemonsource/sdrdaemonsourceudphandler.cpp b/plugins/samplesource/sdrdaemonsource/sdrdaemonsourceudphandler.cpp index e9120f1e8..1330b077c 100644 --- a/plugins/samplesource/sdrdaemonsource/sdrdaemonsourceudphandler.cpp +++ b/plugins/samplesource/sdrdaemonsource/sdrdaemonsourceudphandler.cpp @@ -51,6 +51,8 @@ SDRdaemonSourceUDPHandler::SDRdaemonSourceUDPHandler(SampleSinkFifo *sampleFifo, m_throttlems(SDRDAEMONSOURCE_THROTTLE_MS), m_readLengthSamples(0), m_readLength(0), + m_converterBuffer(0), + m_converterBufferNbSamples(0), m_throttleToggle(false), m_rateDivider(1000/SDRDAEMONSOURCE_THROTTLE_MS), m_autoCorrBuffer(true) @@ -72,6 +74,7 @@ SDRdaemonSourceUDPHandler::~SDRdaemonSourceUDPHandler() { stop(); delete[] m_udpBuf; + if (m_converterBuffer) { delete[] m_converterBuffer; } #ifdef USE_INTERNAL_TIMER if (m_timer) { delete m_timer; @@ -263,9 +266,32 @@ void SDRdaemonSourceUDPHandler::tick() m_readLength = m_readLengthSamples * SDRdaemonSourceBuffer::m_iqSampleSize; - // read samples directly feeding the SampleFifo (no callback) - m_sampleFifo->write(reinterpret_cast(m_sdrDaemonBuffer.readData(m_readLength)), m_readLength); - m_samplesCount += m_readLengthSamples; + if (SDR_RX_SAMP_SZ == 16) + { + // read samples directly feeding the SampleFifo (no callback) + m_sampleFifo->write(reinterpret_cast(m_sdrDaemonBuffer.readData(m_readLength)), m_readLength); + m_samplesCount += m_readLengthSamples; + } + else if (SDR_RX_SAMP_SZ == 24) + { + if (m_readLengthSamples > m_converterBufferNbSamples) + { + if (m_converterBuffer) { delete[] m_converterBuffer; } + m_converterBuffer = new int32_t[m_readLengthSamples*2]; + } + + uint8_t *buf = m_sdrDaemonBuffer.readData(m_readLength); + + for (unsigned int is = 0; is < m_readLengthSamples; is++) + { + m_converterBuffer[2*is] = ((int16_t*)buf)[2*is]; + m_converterBuffer[2*is]<<=8; + m_converterBuffer[2*is+1] = ((int16_t*)buf)[2*is+1]; + m_converterBuffer[2*is+1]<<=8; + } + + m_sampleFifo->write(reinterpret_cast(m_converterBuffer), m_readLengthSamples*4*2); + } if (m_tickCount < m_rateDivider) { diff --git a/plugins/samplesource/sdrdaemonsource/sdrdaemonsourceudphandler.h b/plugins/samplesource/sdrdaemonsource/sdrdaemonsourceudphandler.h index 8a96e6978..0f686329a 100644 --- a/plugins/samplesource/sdrdaemonsource/sdrdaemonsourceudphandler.h +++ b/plugins/samplesource/sdrdaemonsource/sdrdaemonsourceudphandler.h @@ -77,6 +77,8 @@ private: int m_throttlems; uint32_t m_readLengthSamples; uint32_t m_readLength; + int32_t *m_converterBuffer; + uint32_t m_converterBufferNbSamples; bool m_throttleToggle; uint32_t m_rateDivider; bool m_autoCorrBuffer; diff --git a/sdrbase/dsp/samplesinkfifo.cpp b/sdrbase/dsp/samplesinkfifo.cpp index f76998d2e..e60cc2c8c 100644 --- a/sdrbase/dsp/samplesinkfifo.cpp +++ b/sdrbase/dsp/samplesinkfifo.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////////// -// Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany // + // Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany // // written by Christian Daniel // // // // This program is free software; you can redistribute it and/or modify // @@ -74,7 +74,7 @@ uint SampleSinkFifo::write(const quint8* data, uint count) uint remaining; uint len; const Sample* begin = (const Sample*)data; - count /= 4; + count /= sizeof(Sample); total = MIN(count, m_size - m_fill); if(total < count) {