From 44602303a77e7c594d7d8489a9024f5f0224d704 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Fri, 26 Dec 2014 21:55:13 -0500 Subject: [PATCH] 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;