From 0fc47bc9161c2ca2c5845ae115ea88894c257332 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Fri, 26 Dec 2014 20:58:42 -0500 Subject: [PATCH 1/4] FM Stereo experiment, partly working --- src/demod/DemodDefs.h | 3 +- src/demod/DemodulatorInstance.cpp | 10 ++++++ src/demod/DemodulatorInstance.h | 4 +++ src/demod/DemodulatorPreThread.cpp | 1 + src/demod/DemodulatorThread.cpp | 54 ++++++++++++++++++++++++++++-- src/demod/DemodulatorThread.h | 4 +++ src/visual/WaterfallCanvas.cpp | 10 ++++++ 7 files changed, 82 insertions(+), 4 deletions(-) diff --git a/src/demod/DemodDefs.h b/src/demod/DemodDefs.h index c8ddf22..a1d2cdd 100644 --- a/src/demod/DemodDefs.h +++ b/src/demod/DemodDefs.h @@ -70,13 +70,14 @@ public: class DemodulatorThreadPostIQData: public ReferenceCounter { public: std::vector data; + int bandwidth; float audio_resample_ratio; msresamp_rrrf audio_resampler; float resample_ratio; msresamp_crcf resampler; DemodulatorThreadPostIQData() : - audio_resample_ratio(0), audio_resampler(NULL), resample_ratio(0), resampler(NULL) { + bandwidth(0), audio_resample_ratio(0), audio_resampler(NULL), resample_ratio(0), resampler(NULL) { } diff --git a/src/demod/DemodulatorInstance.cpp b/src/demod/DemodulatorInstance.cpp index ab26849..746468e 100644 --- a/src/demod/DemodulatorInstance.cpp +++ b/src/demod/DemodulatorInstance.cpp @@ -146,6 +146,16 @@ void DemodulatorInstance::setActive(bool state) { audioThread->setActive(state); } +bool DemodulatorInstance::isStereo() { + return stereo; +} + +void DemodulatorInstance::setStereo(bool state) { + stereo = state; + demodulatorThread->setStereo(state); +} + + void DemodulatorInstance::squelchAuto() { DemodulatorThreadControlCommand command; command.cmd = DemodulatorThreadControlCommand::DEMOD_THREAD_CMD_CTL_SQUELCH_AUTO; diff --git a/src/demod/DemodulatorInstance.h b/src/demod/DemodulatorInstance.h index 2853d6c..8d0ee39 100644 --- a/src/demod/DemodulatorInstance.h +++ b/src/demod/DemodulatorInstance.h @@ -49,6 +49,9 @@ public: bool isActive(); void setActive(bool state); + bool isStereo(); + void setStereo(bool state); + void squelchAuto();bool isSquelchEnabled(); void setSquelchEnabled(bool state); @@ -56,5 +59,6 @@ private: std::atomic label;bool terminated;bool demodTerminated;bool audioTerminated;bool preDemodTerminated; std::atomic active; std::atomic squelch; + std::atomic stereo; }; diff --git a/src/demod/DemodulatorPreThread.cpp b/src/demod/DemodulatorPreThread.cpp index 065141f..57bf7eb 100644 --- a/src/demod/DemodulatorPreThread.cpp +++ b/src/demod/DemodulatorPreThread.cpp @@ -219,6 +219,7 @@ void DemodulatorPreThread::threadMain() { resamp->audio_resampler = audio_resampler; resamp->resample_ratio = resample_ratio; resamp->resampler = resampler; + resamp->bandwidth = params.bandwidth; postInputQueue->push(resamp); } diff --git a/src/demod/DemodulatorThread.cpp b/src/demod/DemodulatorThread.cpp index 8b4f7ea..0222efb 100644 --- a/src/demod/DemodulatorThread.cpp +++ b/src/demod/DemodulatorThread.cpp @@ -8,7 +8,7 @@ DemodulatorThread::DemodulatorThread(DemodulatorThreadPostInputQueue* pQueue, DemodulatorThreadControlCommandQueue *threadQueueControl, DemodulatorThreadCommandQueue* threadQueueNotify) : - postInputQueue(pQueue), visOutQueue(NULL), audioInputQueue(NULL), agc(NULL), terminated(false), threadQueueNotify(threadQueueNotify), threadQueueControl( + postInputQueue(pQueue), visOutQueue(NULL), audioInputQueue(NULL), agc(NULL), stereo(false), terminated(false), threadQueueNotify(threadQueueNotify), threadQueueControl( threadQueueControl), squelch_level(0), squelch_tolerance(0), squelch_enabled(false) { float kf = 0.5; // modulation factor @@ -44,7 +44,11 @@ void DemodulatorThread::threadMain() { std::vector resampled_data; std::vector agc_data; std::vector demod_output; + std::vector demod_output_stereo; std::vector resampled_audio_output; + std::vector resampled_audio_output_stereo; + + double freq_index = 0; while (!terminated) { DemodulatorThreadPostIQData *inp; @@ -89,24 +93,49 @@ void DemodulatorThread::threadMain() { if (demod_output.size() != num_written) { if (demod_output.capacity() < num_written) { demod_output.reserve(num_written); + demod_output_stereo.reserve(num_written); } demod_output.resize(num_written); + demod_output_stereo.resize(num_written); } freqdem_demodulate_block(fdem, &agc_data[0], num_written, &demod_output[0]); + if (stereo) { + int shift_freq = 38000-inp->bandwidth; + double freq = (2.0 * M_PI) * (((double) abs(shift_freq)) / ((double) inp->bandwidth)); + + for (int i = 0; i < num_written; i++) { + freq_index+=freq; + + demod_output_stereo[i] = demod_output[i] * sin(freq_index) + demod_output[i] * cos(freq_index); + while (freq_index > (M_PI*2.0)) { + freq_index -= (M_PI*2.0); + } + while (freq_index < (M_PI*2.0)) { + freq_index += (M_PI*2.0); + } + } + } + int audio_out_size = ceil((float) (num_written) * audio_resample_ratio); if (audio_out_size != resampled_audio_output.size()) { if (resampled_audio_output.capacity() < audio_out_size) { resampled_audio_output.reserve(audio_out_size); + resampled_audio_output_stereo.reserve(audio_out_size); } resampled_audio_output.resize(audio_out_size); + resampled_audio_output_stereo.resize(audio_out_size); } unsigned int num_audio_written; msresamp_rrrf_execute(audio_resampler, &demod_output[0], num_written, &resampled_audio_output[0], &num_audio_written); + if (stereo) { + msresamp_rrrf_execute(audio_resampler, &demod_output_stereo[0], num_written, &resampled_audio_output_stereo[0], &num_audio_written); + } + if (audioInputQueue != NULL) { if (!squelch_enabled || ((agc_crcf_get_signal_level(agc)) >= 0.1)) { AudioThreadInput *ati = NULL; @@ -124,8 +153,18 @@ void DemodulatorThread::threadMain() { } ati->setRefCount(1); - ati->channels = 1; - ati->data.assign(resampled_audio_output.begin(), resampled_audio_output.begin() + num_audio_written); + + if (stereo) { + ati->channels = 2; + ati->data.resize(num_audio_written*2); + for (int i = 0; i < num_audio_written; i++) { + ati->data[i*2] = (resampled_audio_output[i]-(resampled_audio_output_stereo[i]*2.0))/2.0; + ati->data[i*2+1] = (resampled_audio_output[i]+(resampled_audio_output_stereo[i]*2.0))/2.0; + } + } else { + ati->channels = 1; + ati->data.assign(resampled_audio_output.begin(), resampled_audio_output.begin() + num_audio_written); + } audioInputQueue->push(ati); } @@ -204,3 +243,12 @@ void DemodulatorThread::terminate() { DemodulatorThreadPostIQData *inp = new DemodulatorThreadPostIQData; // push dummy to nudge queue postInputQueue->push(inp); } + + +void DemodulatorThread::setStereo(bool state) { + stereo = state; +} + +bool DemodulatorThread::isStereo() { + return stereo; +} diff --git a/src/demod/DemodulatorThread.h b/src/demod/DemodulatorThread.h index 3fb4bf6..a546e55 100644 --- a/src/demod/DemodulatorThread.h +++ b/src/demod/DemodulatorThread.h @@ -35,6 +35,9 @@ public: void terminate(); + void setStereo(bool state); + bool isStereo(); + #ifdef __APPLE__ static void *pthread_helper(void *context) { return ((DemodulatorThread *) context)->threadMain(); @@ -49,6 +52,7 @@ protected: freqdem fdem; agc_crcf agc; + std::atomic stereo; std::atomic terminated; DemodulatorThreadCommandQueue* threadQueueNotify; diff --git a/src/visual/WaterfallCanvas.cpp b/src/visual/WaterfallCanvas.cpp index 2d07282..6523da1 100644 --- a/src/visual/WaterfallCanvas.cpp +++ b/src/visual/WaterfallCanvas.cpp @@ -200,6 +200,16 @@ void WaterfallCanvas::OnKeyDown(wxKeyEvent& event) { activeDemod->squelchAuto(); } break; + case WXK_SPACE: + if (!activeDemod) { + break; + } + if (activeDemod->isStereo()) { + activeDemod->setStereo(false); + } else { + activeDemod->setStereo(true); + } + break; default: event.Skip(); return; From 44602303a77e7c594d7d8489a9024f5f0224d704 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Fri, 26 Dec 2014 21:55:13 -0500 Subject: [PATCH 2/4] Add stereo re-sampler --- src/audio/AudioThread.cpp | 2 +- src/demod/DemodDefs.h | 3 ++- src/demod/DemodulatorPreThread.cpp | 10 +++++++++- src/demod/DemodulatorPreThread.h | 1 + src/demod/DemodulatorThread.cpp | 11 +++++++++-- src/demod/DemodulatorWorkerThread.cpp | 1 + src/demod/DemodulatorWorkerThread.h | 5 +++-- 7 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/audio/AudioThread.cpp b/src/audio/AudioThread.cpp index de94c66..c1126e7 100644 --- a/src/audio/AudioThread.cpp +++ b/src/audio/AudioThread.cpp @@ -112,7 +112,7 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu srcmix->audio_queue_ptr++; } } else { - for (int i = 0, iMax = src->currentInput->channels * nBufferFrames; i < iMax; i++) { + for (int i = 0, iMax = srcmix->currentInput->channels * nBufferFrames; i < iMax; i++) { if (srcmix->audio_queue_ptr >= srcmix->currentInput->data.size()) { if (srcmix->currentInput) { srcmix->currentInput->decRefCount(); diff --git a/src/demod/DemodDefs.h b/src/demod/DemodDefs.h index a1d2cdd..93e6511 100644 --- a/src/demod/DemodDefs.h +++ b/src/demod/DemodDefs.h @@ -73,11 +73,12 @@ public: int bandwidth; float audio_resample_ratio; msresamp_rrrf audio_resampler; + msresamp_rrrf stereo_resampler; float resample_ratio; msresamp_crcf resampler; DemodulatorThreadPostIQData() : - bandwidth(0), audio_resample_ratio(0), audio_resampler(NULL), resample_ratio(0), resampler(NULL) { + bandwidth(0), audio_resample_ratio(0), audio_resampler(NULL), stereo_resampler(NULL), resample_ratio(0), resampler(NULL) { } diff --git a/src/demod/DemodulatorPreThread.cpp b/src/demod/DemodulatorPreThread.cpp index 57bf7eb..5a96e49 100644 --- a/src/demod/DemodulatorPreThread.cpp +++ b/src/demod/DemodulatorPreThread.cpp @@ -9,7 +9,7 @@ DemodulatorPreThread::DemodulatorPreThread(DemodulatorThreadInputQueue* pQueueIn, DemodulatorThreadPostInputQueue* pQueueOut, DemodulatorThreadControlCommandQueue *threadQueueControl, DemodulatorThreadCommandQueue* threadQueueNotify) : - inputQueue(pQueueIn), postInputQueue(pQueueOut), terminated(false), initialized(false), audio_resampler(NULL), resample_ratio(1), audio_resample_ratio( + inputQueue(pQueueIn), postInputQueue(pQueueOut), terminated(false), initialized(false), audio_resampler(NULL), stereo_resampler(NULL), resample_ratio(1), audio_resample_ratio( 1), resampler(NULL), commandQueue(NULL), fir_filter(NULL), audioInputQueue(NULL), threadQueueNotify(threadQueueNotify), threadQueueControl( threadQueueControl) { @@ -71,6 +71,12 @@ void DemodulatorPreThread::initialize() { audio_resampler = msresamp_rrrf_create(audio_resample_ratio, As); // msresamp_crcf_print(audio_resampler); + if (stereo_resampler) { + msresamp_rrrf_destroy(stereo_resampler); + } + stereo_resampler = msresamp_rrrf_create(audio_resample_ratio, As); + + initialized = true; // std::cout << "inputResampleRate " << params.bandwidth << std::endl; @@ -217,6 +223,7 @@ void DemodulatorPreThread::threadMain() { resamp->audio_resample_ratio = audio_resample_ratio; resamp->audio_resampler = audio_resampler; + resamp->stereo_resampler = stereo_resampler; resamp->resample_ratio = resample_ratio; resamp->resampler = resampler; resamp->bandwidth = params.bandwidth; @@ -240,6 +247,7 @@ void DemodulatorPreThread::threadMain() { fir_filter = result.fir_filter; resampler = result.resampler; audio_resampler = result.audio_resampler; + stereo_resampler = result.stereo_resampler; resample_ratio = result.resample_ratio; audio_resample_ratio = result.audio_resample_ratio; diff --git a/src/demod/DemodulatorPreThread.h b/src/demod/DemodulatorPreThread.h index 95304da..540f9a6 100644 --- a/src/demod/DemodulatorPreThread.h +++ b/src/demod/DemodulatorPreThread.h @@ -57,6 +57,7 @@ protected: float resample_ratio; msresamp_rrrf audio_resampler; + msresamp_rrrf stereo_resampler; float audio_resample_ratio; DemodulatorThreadParameters params; diff --git a/src/demod/DemodulatorThread.cpp b/src/demod/DemodulatorThread.cpp index 0222efb..0e392ce 100644 --- a/src/demod/DemodulatorThread.cpp +++ b/src/demod/DemodulatorThread.cpp @@ -31,6 +31,7 @@ void DemodulatorThread::threadMain() { #endif msresamp_rrrf audio_resampler = NULL; + msresamp_rrrf stereo_resampler = NULL; msresamp_crcf resampler = NULL; agc = agc_crcf_create(); @@ -65,11 +66,14 @@ void DemodulatorThread::threadMain() { if (resampler == NULL) { resampler = inp->resampler; audio_resampler = inp->audio_resampler; + stereo_resampler = inp->stereo_resampler; } else if (resampler != inp->resampler) { msresamp_crcf_destroy(resampler); msresamp_rrrf_destroy(audio_resampler); + msresamp_rrrf_destroy(stereo_resampler); resampler = inp->resampler; audio_resampler = inp->audio_resampler; + stereo_resampler = inp->stereo_resampler; } int out_size = ceil((float) (bufSize) * inp->resample_ratio); @@ -108,7 +112,7 @@ void DemodulatorThread::threadMain() { for (int i = 0; i < num_written; i++) { freq_index+=freq; - demod_output_stereo[i] = demod_output[i] * sin(freq_index) + demod_output[i] * cos(freq_index); + demod_output_stereo[i] = demod_output[i] * sin(freq_index);// + demod_output[i] * cos(freq_index); while (freq_index > (M_PI*2.0)) { freq_index -= (M_PI*2.0); } @@ -133,7 +137,7 @@ void DemodulatorThread::threadMain() { msresamp_rrrf_execute(audio_resampler, &demod_output[0], num_written, &resampled_audio_output[0], &num_audio_written); if (stereo) { - msresamp_rrrf_execute(audio_resampler, &demod_output_stereo[0], num_written, &resampled_audio_output_stereo[0], &num_audio_written); + msresamp_rrrf_execute(stereo_resampler, &demod_output_stereo[0], num_written, &resampled_audio_output_stereo[0], &num_audio_written); } if (audioInputQueue != NULL) { @@ -222,6 +226,9 @@ void DemodulatorThread::threadMain() { if (audio_resampler != NULL) { msresamp_rrrf_destroy(audio_resampler); } + if (stereo_resampler != NULL) { + msresamp_rrrf_destroy(stereo_resampler); + } agc_crcf_destroy(agc); diff --git a/src/demod/DemodulatorWorkerThread.cpp b/src/demod/DemodulatorWorkerThread.cpp index 8cadf90..206f2c5 100644 --- a/src/demod/DemodulatorWorkerThread.cpp +++ b/src/demod/DemodulatorWorkerThread.cpp @@ -59,6 +59,7 @@ void DemodulatorWorkerThread::threadMain() { result.fir_filter = firfilt_crcf_create(h, h_len); result.resampler = msresamp_crcf_create(result.resample_ratio, As); result.audio_resampler = msresamp_rrrf_create(result.audio_resample_ratio, As); + result.stereo_resampler = msresamp_rrrf_create(result.audio_resample_ratio, As); result.audioSampleRate = filterCommand.audioSampleRate; result.bandwidth = filterCommand.bandwidth; diff --git a/src/demod/DemodulatorWorkerThread.h b/src/demod/DemodulatorWorkerThread.h index 8db4c5a..94e9af7 100644 --- a/src/demod/DemodulatorWorkerThread.h +++ b/src/demod/DemodulatorWorkerThread.h @@ -22,13 +22,13 @@ public: }; DemodulatorWorkerThreadResult() : - cmd(DEMOD_WORKER_THREAD_RESULT_NULL), fir_filter(NULL), resampler(NULL), resample_ratio(0), audio_resampler(NULL), audio_resample_ratio( + cmd(DEMOD_WORKER_THREAD_RESULT_NULL), fir_filter(NULL), resampler(NULL), resample_ratio(0), audio_resampler(NULL), stereo_resampler(NULL), audio_resample_ratio( 0), inputRate(0), bandwidth(0), audioSampleRate(0) { } DemodulatorWorkerThreadResult(DemodulatorThreadResultEnum cmd) : - cmd(cmd), fir_filter(NULL), resampler(NULL), resample_ratio(0), audio_resampler(NULL), audio_resample_ratio(0), inputRate(0), bandwidth( + cmd(cmd), fir_filter(NULL), resampler(NULL), resample_ratio(0), audio_resampler(NULL), stereo_resampler(NULL), audio_resample_ratio(0), inputRate(0), bandwidth( 0), audioSampleRate(0) { } @@ -39,6 +39,7 @@ public: msresamp_crcf resampler; float resample_ratio; msresamp_rrrf audio_resampler; + msresamp_rrrf stereo_resampler; float audio_resample_ratio; unsigned int inputRate; From 591b03dc7df64e35871c1c2426ac3772d761cbc3 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Fri, 26 Dec 2014 22:07:49 -0500 Subject: [PATCH 3/4] Indicate stereo status in term --- src/demod/DemodulatorThread.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/demod/DemodulatorThread.cpp b/src/demod/DemodulatorThread.cpp index 0e392ce..e816a40 100644 --- a/src/demod/DemodulatorThread.cpp +++ b/src/demod/DemodulatorThread.cpp @@ -162,8 +162,8 @@ void DemodulatorThread::threadMain() { ati->channels = 2; ati->data.resize(num_audio_written*2); for (int i = 0; i < num_audio_written; i++) { - ati->data[i*2] = (resampled_audio_output[i]-(resampled_audio_output_stereo[i]*2.0))/2.0; - ati->data[i*2+1] = (resampled_audio_output[i]+(resampled_audio_output_stereo[i]*2.0))/2.0; + ati->data[i*2] = (resampled_audio_output[i]-(resampled_audio_output_stereo[i])); + ati->data[i*2+1] = (resampled_audio_output[i]+(resampled_audio_output_stereo[i])); } } else { ati->channels = 1; @@ -254,6 +254,7 @@ void DemodulatorThread::terminate() { void DemodulatorThread::setStereo(bool state) { stereo = state; + std::cout << "Stereo " << (state?"Enabled":"Disabled") << std::endl; } bool DemodulatorThread::isStereo() { From b69f90b17b7b5014b50674dc1bee62ee4b10f312 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Fri, 26 Dec 2014 22:20:50 -0500 Subject: [PATCH 4/4] Show stereo in vis output --- src/demod/DemodulatorThread.cpp | 62 ++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/src/demod/DemodulatorThread.cpp b/src/demod/DemodulatorThread.cpp index e816a40..1747587 100644 --- a/src/demod/DemodulatorThread.cpp +++ b/src/demod/DemodulatorThread.cpp @@ -8,8 +8,8 @@ DemodulatorThread::DemodulatorThread(DemodulatorThreadPostInputQueue* pQueue, DemodulatorThreadControlCommandQueue *threadQueueControl, DemodulatorThreadCommandQueue* threadQueueNotify) : - postInputQueue(pQueue), visOutQueue(NULL), audioInputQueue(NULL), agc(NULL), stereo(false), terminated(false), threadQueueNotify(threadQueueNotify), threadQueueControl( - threadQueueControl), squelch_level(0), squelch_tolerance(0), squelch_enabled(false) { + postInputQueue(pQueue), visOutQueue(NULL), audioInputQueue(NULL), agc(NULL), stereo(false), terminated(false), threadQueueNotify( + threadQueueNotify), threadQueueControl(threadQueueControl), squelch_level(0), squelch_tolerance(0), squelch_enabled(false) { float kf = 0.5; // modulation factor fdem = freqdem_create(kf); @@ -106,18 +106,18 @@ void DemodulatorThread::threadMain() { freqdem_demodulate_block(fdem, &agc_data[0], num_written, &demod_output[0]); if (stereo) { - int shift_freq = 38000-inp->bandwidth; - double freq = (2.0 * M_PI) * (((double) abs(shift_freq)) / ((double) inp->bandwidth)); + int shift_freq = 38000 - inp->bandwidth; + double freq = (2.0 * M_PI) * (((double) abs(shift_freq)) / ((double) inp->bandwidth)); for (int i = 0; i < num_written; i++) { - freq_index+=freq; + freq_index += freq; - demod_output_stereo[i] = demod_output[i] * sin(freq_index);// + demod_output[i] * cos(freq_index); - while (freq_index > (M_PI*2.0)) { - freq_index -= (M_PI*2.0); + demod_output_stereo[i] = demod_output[i] * sin(freq_index); // + demod_output[i] * cos(freq_index); + while (freq_index > (M_PI * 2.0)) { + freq_index -= (M_PI * 2.0); } - while (freq_index < (M_PI*2.0)) { - freq_index += (M_PI*2.0); + while (freq_index < (M_PI * 2.0)) { + freq_index += (M_PI * 2.0); } } } @@ -160,10 +160,10 @@ void DemodulatorThread::threadMain() { if (stereo) { ati->channels = 2; - ati->data.resize(num_audio_written*2); + ati->data.resize(num_audio_written * 2); for (int i = 0; i < num_audio_written; i++) { - ati->data[i*2] = (resampled_audio_output[i]-(resampled_audio_output_stereo[i])); - ati->data[i*2+1] = (resampled_audio_output[i]+(resampled_audio_output_stereo[i])); + ati->data[i * 2] = (resampled_audio_output[i] - (resampled_audio_output_stereo[i])); + ati->data[i * 2 + 1] = (resampled_audio_output[i] + (resampled_audio_output_stereo[i])); } } else { ati->channels = 1; @@ -179,22 +179,37 @@ void DemodulatorThread::threadMain() { ati_vis->channels = 1; int num_vis = DEMOD_VIS_SIZE; - if (num_audio_written > num_written) { - if (num_vis > num_audio_written) { - num_vis = num_audio_written; + if (stereo) { + + int stereoSize = resampled_audio_output.size(); + if (stereoSize > DEMOD_VIS_SIZE) { + stereoSize = DEMOD_VIS_SIZE; + } + ati_vis->data.resize(stereoSize); + + for (int i = 0; i < stereoSize / 2; i++) { + ati_vis->data[i] = (resampled_audio_output[i] - (resampled_audio_output_stereo[i])); + ati_vis->data[i + stereoSize / 2] = (resampled_audio_output[i] + (resampled_audio_output_stereo[i])); } - ati_vis->data.assign(resampled_audio_output.begin(), resampled_audio_output.begin() + num_vis); } else { - if (num_vis > num_written) { - num_vis = num_written; + if (num_audio_written > num_written) { + + if (num_vis > num_audio_written) { + num_vis = num_audio_written; + } + ati_vis->data.assign(resampled_audio_output.begin(), resampled_audio_output.begin() + num_vis); + } else { + if (num_vis > num_written) { + num_vis = num_written; + } + ati_vis->data.assign(demod_output.begin(), demod_output.begin() + num_vis); } - ati_vis->data.assign(demod_output.begin(), demod_output.begin() + num_vis); + +// std::cout << "Signal: " << agc_crcf_get_signal_level(agc) << " -- " << agc_crcf_get_rssi(agc) << "dB " << std::endl; } visOutQueue->push(ati_vis); -// std::cout << "Signal: " << agc_crcf_get_signal_level(agc) << " -- " << agc_crcf_get_rssi(agc) << "dB " << std::endl; } - if (!threadQueueControl->empty()) { while (!threadQueueControl->empty()) { DemodulatorThreadControlCommand command; @@ -251,10 +266,9 @@ void DemodulatorThread::terminate() { postInputQueue->push(inp); } - void DemodulatorThread::setStereo(bool state) { stereo = state; - std::cout << "Stereo " << (state?"Enabled":"Disabled") << std::endl; + std::cout << "Stereo " << (state ? "Enabled" : "Disabled") << std::endl; } bool DemodulatorThread::isStereo() {