mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2025-07-05 19:25:16 -04:00
Fix #677: SDRPostThread : Do not push twice the samples in single-channel mode, refactorings and simplifications.
This commit is contained in:
parent
5db28da361
commit
f03925d27f
@ -95,7 +95,6 @@ void SDRPostThread::updateActiveDemodulators() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add active demods to the current run:
|
// Add active demods to the current run:
|
||||||
|
|
||||||
runDemods.push_back(demod);
|
runDemods.push_back(demod);
|
||||||
demodChannel.push_back(-1);
|
demodChannel.push_back(-1);
|
||||||
}
|
}
|
||||||
@ -179,8 +178,6 @@ void SDRPostThread::run() {
|
|||||||
|
|
||||||
if (data_in && data_in->data.size()) {
|
if (data_in && data_in->data.size()) {
|
||||||
|
|
||||||
pushVisualData(data_in.get());
|
|
||||||
|
|
||||||
if(data_in->numChannels > 1) {
|
if(data_in->numChannels > 1) {
|
||||||
if (chanMode == 1) {
|
if (chanMode == 1) {
|
||||||
runPFBCH(data_in.get());
|
runPFBCH(data_in.get());
|
||||||
@ -224,27 +221,29 @@ void SDRPostThread::terminate() {
|
|||||||
iqActiveDemodVisualQueue->flush();
|
iqActiveDemodVisualQueue->flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Copy the full badwidth into a new DemodulatorThreadIQDataPtr.
|
||||||
|
DemodulatorThreadIQDataPtr SDRPostThread::getFullSampleRateIqData(SDRThreadIQData *data_in) {
|
||||||
|
|
||||||
|
DemodulatorThreadIQDataPtr iqDataOut = visualDataBuffers.getBuffer();
|
||||||
|
|
||||||
|
iqDataOut->frequency = data_in->frequency;
|
||||||
|
iqDataOut->sampleRate = data_in->sampleRate;
|
||||||
|
iqDataOut->data.assign(data_in->data.begin(), data_in->data.begin() + data_in->data.size());
|
||||||
|
|
||||||
|
return iqDataOut;
|
||||||
|
}
|
||||||
|
|
||||||
// Push visual data; i.e. Main Waterfall (all frames) and Spectrum (active frame)
|
// Push visual data; i.e. Main Waterfall (all frames) and Spectrum (active frame)
|
||||||
void SDRPostThread::pushVisualData(SDRThreadIQData *data_in) {
|
void SDRPostThread::pushVisualData(DemodulatorThreadIQDataPtr iqDataOut) {
|
||||||
if (iqDataOutQueue != nullptr && !iqDataOutQueue->full()) {
|
|
||||||
DemodulatorThreadIQDataPtr iqDataOut = visualDataBuffers.getBuffer();
|
|
||||||
|
|
||||||
bool doVis = false;
|
if (iqDataOutQueue != nullptr) {
|
||||||
|
|
||||||
if (iqVisualQueue != nullptr && !iqVisualQueue->full()) {
|
//non-blocking push here, we can afford to loose some samples for a ever-changing visual display.
|
||||||
doVis = true;
|
iqDataOutQueue->try_push(iqDataOut);
|
||||||
}
|
|
||||||
|
|
||||||
iqDataOut->frequency = data_in->frequency;
|
if (iqVisualQueue != nullptr) {
|
||||||
iqDataOut->sampleRate = data_in->sampleRate;
|
//non-blocking push here, we can afford to loose some samples for a ever-changing visual display.
|
||||||
iqDataOut->data.assign(data_in->data.begin(), data_in->data.begin() + data_in->data.size());
|
iqVisualQueue->try_push(iqDataOut);
|
||||||
|
|
||||||
//VSO: blocking push
|
|
||||||
iqDataOutQueue->push(iqDataOut);
|
|
||||||
|
|
||||||
if (doVis) {
|
|
||||||
//VSO: blocking push
|
|
||||||
iqVisualQueue->push(iqDataOut);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -285,32 +284,21 @@ void SDRPostThread::runSingleCH(SDRThreadIQData *data_in) {
|
|||||||
demodDataOut->data.resize(outSize);
|
demodDataOut->data.resize(outSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Only 1 channel, apply DC blocker.
|
||||||
iirfilt_crcf_execute_block(dcFilter, &data_in->data[0], data_in->data.size(), &demodDataOut->data[0]);
|
iirfilt_crcf_execute_block(dcFilter, &data_in->data[0], data_in->data.size(), &demodDataOut->data[0]);
|
||||||
|
|
||||||
if (runDemods.size() > 0 && iqActiveDemodVisualQueue != nullptr && !iqActiveDemodVisualQueue->full()) {
|
//push the DC-corrected data as Main Spactrum + Waterfall data.
|
||||||
//VSO: blocking push
|
pushVisualData(demodDataOut);
|
||||||
iqActiveDemodVisualQueue->push(demodDataOut);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (iqDataOutQueue != nullptr && !iqDataOutQueue->full()) {
|
if (runDemods.size() > 0 && iqActiveDemodVisualQueue != nullptr) {
|
||||||
//VSO: blocking push
|
//non-blocking push here, we can afford to loose some samples for a ever-changing visual display.
|
||||||
iqDataOutQueue->push(demodDataOut);
|
iqActiveDemodVisualQueue->try_push(demodDataOut);
|
||||||
}
|
|
||||||
|
|
||||||
if (iqVisualQueue != nullptr && !iqVisualQueue->full()) {
|
|
||||||
//VSO: blocking push
|
|
||||||
iqVisualQueue->push(demodDataOut);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < runDemods.size(); i++) {
|
for (size_t i = 0; i < runDemods.size(); i++) {
|
||||||
// try-push() : we do our best to only stimulate active demods, but some could happen to be dead, full, or indeed non-active.
|
// try-push() : we do our best to only stimulate active demods, but some could happen to be dead, full, or indeed non-active.
|
||||||
//so in short never block here no matter what.
|
//so in short never block here no matter what.
|
||||||
if (!runDemods[i]->getIQInputDataPipe()->try_push(demodDataOut)) {
|
runDemods[i]->getIQInputDataPipe()->try_push(demodDataOut);
|
||||||
|
|
||||||
// std::cout << "SDRPostThread::runSingleCH() attempt to push into demod '" << runDemods[i]->getLabel()
|
|
||||||
// << "' (" << runDemods[i]->getFrequency() << " Hz) failed, demod is either too busy, not-active, or dead..." << std::endl << std::flush;
|
|
||||||
std::this_thread::yield();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -347,7 +335,7 @@ void SDRPostThread::runDemodChannels(int channelBandwidth) {
|
|||||||
|
|
||||||
// Run channels
|
// Run channels
|
||||||
for (int i = 0; i < numChannels+1; i++) {
|
for (int i = 0; i < numChannels+1; i++) {
|
||||||
bool doDemodVis = (activeDemodChannel == i) && (iqActiveDemodVisualQueue != nullptr) && !iqActiveDemodVisualQueue->full();
|
bool doDemodVis = (activeDemodChannel == i) && (iqActiveDemodVisualQueue != nullptr);
|
||||||
|
|
||||||
if (!doDemodVis && demodChannelActive[i] == 0) {
|
if (!doDemodVis && demodChannelActive[i] == 0) {
|
||||||
// Nothing to do for this channel? continue.
|
// Nothing to do for this channel? continue.
|
||||||
@ -398,8 +386,8 @@ void SDRPostThread::runDemodChannels(int channelBandwidth) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (doDemodVis) {
|
if (doDemodVis) {
|
||||||
//VSO: blocking push
|
//non-blocking push here, we can afford to loose some samples for a ever-changing visual display.
|
||||||
iqActiveDemodVisualQueue->push(demodDataOut);
|
iqActiveDemodVisualQueue->try_push(demodDataOut);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t j = 0; j < runDemods.size(); j++) {
|
for (size_t j = 0; j < runDemods.size(); j++) {
|
||||||
@ -407,11 +395,7 @@ void SDRPostThread::runDemodChannels(int channelBandwidth) {
|
|||||||
|
|
||||||
// try-push() : we do our best to only stimulate active demods, but some could happen to be dead, full, or indeed non-active.
|
// try-push() : we do our best to only stimulate active demods, but some could happen to be dead, full, or indeed non-active.
|
||||||
//so in short never block here no matter what.
|
//so in short never block here no matter what.
|
||||||
if (!runDemods[j]->getIQInputDataPipe()->try_push(demodDataOut)) {
|
runDemods[j]->getIQInputDataPipe()->try_push(demodDataOut);
|
||||||
// std::cout << "SDRPostThread::runPFBCH() attempt to push into demod '" << runDemods[i]->getLabel()
|
|
||||||
// << "' (" << runDemods[i]->getFrequency() << " Hz) failed, demod is either too busy, not-active, or dead..." << std::endl << std::flush;
|
|
||||||
std::this_thread::yield();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} //end for
|
} //end for
|
||||||
}
|
}
|
||||||
@ -449,6 +433,10 @@ void SDRPostThread::runPFBCH(SDRThreadIQData *data_in) {
|
|||||||
updateChannels();
|
updateChannels();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//push the full data_in into (Main spectrum + waterfall) visual queue:
|
||||||
|
DemodulatorThreadIQDataPtr fullSampleRateIQ = getFullSampleRateIqData(data_in);
|
||||||
|
pushVisualData(fullSampleRateIQ);
|
||||||
|
|
||||||
size_t outSize = data_in->data.size();
|
size_t outSize = data_in->data.size();
|
||||||
|
|
||||||
if (outSize > dataOut.capacity()) {
|
if (outSize > dataOut.capacity()) {
|
||||||
@ -501,6 +489,10 @@ void SDRPostThread::runPFBCH2(SDRThreadIQData *data_in) {
|
|||||||
updateChannels();
|
updateChannels();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//push the full data_in into (Main spectrum + waterfall) visual queue:
|
||||||
|
DemodulatorThreadIQDataPtr fullSampleRateIQ = getFullSampleRateIqData(data_in);
|
||||||
|
pushVisualData(fullSampleRateIQ);
|
||||||
|
|
||||||
size_t outSize = data_in->data.size() * 2;
|
size_t outSize = data_in->data.size() * 2;
|
||||||
|
|
||||||
if (outSize > dataOut.capacity()) {
|
if (outSize > dataOut.capacity()) {
|
||||||
|
@ -34,8 +34,10 @@ protected:
|
|||||||
DemodulatorThreadInputQueuePtr iqActiveDemodVisualQueue;
|
DemodulatorThreadInputQueuePtr iqActiveDemodVisualQueue;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// Copy the full samplerate into a new DemodulatorThreadIQDataPtr.
|
||||||
|
DemodulatorThreadIQDataPtr getFullSampleRateIqData(SDRThreadIQData *data_in);
|
||||||
|
void pushVisualData(DemodulatorThreadIQDataPtr iqDataOut);
|
||||||
|
|
||||||
void pushVisualData(SDRThreadIQData *data_in);
|
|
||||||
void runSingleCH(SDRThreadIQData *data_in);
|
void runSingleCH(SDRThreadIQData *data_in);
|
||||||
|
|
||||||
void runDemodChannels(int channelBandwidth);
|
void runDemodChannels(int channelBandwidth);
|
||||||
|
@ -360,7 +360,6 @@ int SDRThread::readStream(SDRThreadIQDataQueuePtr iqDataOutQueue) {
|
|||||||
if (!iqDataOutQueue->try_push(dataOut)) {
|
if (!iqDataOutQueue->try_push(dataOut)) {
|
||||||
//The rest of the system saturates,
|
//The rest of the system saturates,
|
||||||
//finally the push didn't suceeded.
|
//finally the push didn't suceeded.
|
||||||
|
|
||||||
readStreamCode = -32;
|
readStreamCode = -32;
|
||||||
std::cout << "SDRThread::readStream(): 3.2 iqDataOutQueue output queue is full, discard processing of the batch..." << std::endl;
|
std::cout << "SDRThread::readStream(): 3.2 iqDataOutQueue output queue is full, discard processing of the batch..." << std::endl;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user