code cleanup

This commit is contained in:
Charles J. Cliffe 2015-11-17 20:47:00 -05:00
parent 31bf65259d
commit 8ac4498db7
3 changed files with 35 additions and 209 deletions

View File

@ -24,50 +24,14 @@ DemodulatorPreThread::DemodulatorPreThread() : IOThread(), iqResampler(NULL), iq
}
void DemodulatorPreThread::initialize() {
initialized = false;
iqResampleRatio = (double) (params.bandwidth) / (double) params.sampleRate;
// audioResampleRatio = (double) (params.audioSampleRate) / (double) params.bandwidth;
float As = 60.0f; // stop-band attenuation [dB]
iqResampler = msresamp_crcf_create(iqResampleRatio, As);
// audioResampler = msresamp_rrrf_create(audioResampleRatio, As);
// stereoResampler = msresamp_rrrf_create(audioResampleRatio, As);
// Stereo filters / shifters
// double firStereoCutoff = ((double) 16000 / (double) params.audioSampleRate);
// float ft = ((double) 1000 / (double) params.audioSampleRate); // filter transition
// float mu = 0.0f; // fractional timing offset
//
// if (firStereoCutoff < 0) {
// firStereoCutoff = 0;
// }
//
// if (firStereoCutoff > 0.5) {
// firStereoCutoff = 0.5;
// }
initialized.store(true);
// unsigned int h_len = estimate_req_filter_len(ft, As);
// float *h = new float[h_len];
// liquid_firdes_kaiser(h_len, firStereoCutoff, As, mu, h);
//
// firStereoLeft = firfilt_rrrf_create(h, h_len);
// firStereoRight = firfilt_rrrf_create(h, h_len);
// stereo pilot filter
// float bw = params.bandwidth;
// if (bw < 100000.0) {
// bw = 100000.0;
// }
// unsigned int order = 5; // filter order
// float f0 = ((double) 19000 / bw);
// float fc = ((double) 19500 / bw);
// float Ap = 1.0f;
// As = 60.0f;
// iirStereoPilot = iirfilt_crcf_create_prototype(LIQUID_IIRDES_CHEBY2, LIQUID_IIRDES_BANDPASS, LIQUID_IIRDES_SOS, order, fc, f0, Ap, As);
initialized = true;
lastParams = params;
}
@ -99,8 +63,6 @@ void DemodulatorPreThread::run() {
std::vector<liquid_float_complex> in_buf_data;
std::vector<liquid_float_complex> out_buf_data;
// liquid_float_complex carrySample; // Keep the stream count even to simplify some demod operations
// bool carrySampleFlag = false;
while (!terminated) {
DemodulatorThreadIQData *inp;
@ -220,37 +182,6 @@ void DemodulatorPreThread::run() {
resamp->setRefCount(1);
resamp->data.assign(resampledData.begin(), resampledData.begin() + numWritten);
// bool uneven = (numWritten % 2 != 0);
// if (!carrySampleFlag && !uneven) {
// resamp->data.assign(resampledData.begin(), resampledData.begin() + numWritten);
// carrySampleFlag = false;
// } else if (!carrySampleFlag && uneven) {
// resamp->data.assign(resampledData.begin(), resampledData.begin() + (numWritten-1));
// carrySample = resampledData.back();
// carrySampleFlag = true;
// } else if (carrySampleFlag && uneven) {
// resamp->data.resize(numWritten+1);
// resamp->data[0] = carrySample;
// memcpy(&resamp->data[1],&resampledData[0],sizeof(liquid_float_complex)*numWritten);
// carrySampleFlag = false;
// } else if (carrySampleFlag && !uneven) {
// resamp->data.resize(numWritten);
// resamp->data[0] = carrySample;
// memcpy(&resamp->data[1],&resampledData[0],sizeof(liquid_float_complex)*(numWritten-1));
// carrySample = resampledData.back();
// carrySampleFlag = true;
// }
// resamp->audioResampleRatio = audioResampleRatio;
// resamp->audioResampler = audioResampler;
// resamp->audioSampleRate = params.audioSampleRate;
// resamp->stereoResampler = stereoResampler;
// resamp->firStereoLeft = firStereoLeft;
// resamp->firStereoRight = firStereoRight;
// resamp->iirStereoPilot = iirStereoPilot;
resamp->modem = cModem;
resamp->modemKit = cModemKit;
resamp->sampleRate = params.bandwidth;
@ -274,28 +205,6 @@ void DemodulatorPreThread::run() {
iqResampleRatio = result.iqResampleRatio;
}
// if (result.firStereoLeft) {
// firStereoLeft = result.firStereoLeft;
// }
//
// if (result.firStereoRight) {
// firStereoRight = result.firStereoRight;
// }
//
// if (result.iirStereoPilot) {
// iirStereoPilot = result.iirStereoPilot;
// }
//
// if (result.audioResampler) {
// audioResampler = result.audioResampler;
// audioResampleRatio = result.audioResamplerRatio;
// stereoResampler = result.stereoResampler;
// }
//
// if (result.audioSampleRate) {
// params.audioSampleRate = result.audioSampleRate;
// }
if (result.modem != nullptr) {
cModem = result.modem;
}
@ -327,6 +236,23 @@ void DemodulatorPreThread::run() {
std::cout << "Demodulator preprocessor thread done." << std::endl;
}
DemodulatorThreadParameters &DemodulatorPreThread::getParams() {
return params;
}
void DemodulatorPreThread::setParams(DemodulatorThreadParameters &params_in) {
params = params_in;
}
void DemodulatorPreThread::setDemodType(std::string demodType) {
this->demodType = demodType;
demodTypeChanged.store(true);
}
std::string DemodulatorPreThread::getDemodType() {
return demodType;
}
void DemodulatorPreThread::terminate() {
terminated = true;
DemodulatorThreadIQData *inp = new DemodulatorThreadIQData; // push dummy to nudge queue

View File

@ -15,13 +15,11 @@ public:
void run();
DemodulatorThreadParameters &getParams() {
return params;
}
DemodulatorThreadParameters &getParams();
void setParams(DemodulatorThreadParameters &params_in);
void setParams(DemodulatorThreadParameters &params_in) {
params = params_in;
}
void setDemodType(std::string demodType);
std::string getDemodType();
void initialize();
void terminate();
@ -40,14 +38,6 @@ protected:
Modem *cModem;
ModemKit *cModemKit;
// msresamp_rrrf audioResampler;
// msresamp_rrrf stereoResampler;
// double audioResampleRatio;
// firfilt_rrrf firStereoLeft;
// firfilt_rrrf firStereoRight;
// iirfilt_crcf iirStereoPilot;
DemodulatorThreadParameters params;
DemodulatorThreadParameters lastParams;
@ -55,6 +45,8 @@ protected:
int shiftFrequency;
std::atomic_bool initialized;
std::atomic_bool demodTypeChanged;
std::string demodType;
DemodulatorWorkerThread *workerThread;
std::thread *t_Worker;

View File

@ -170,47 +170,7 @@ void DemodulatorThread::run() {
continue;
}
// if (audioResampler == NULL) {
// audioResampler = inp->audioResampler;
// stereoResampler = inp->stereoResampler;
// firStereoLeft = inp->firStereoLeft;
// firStereoRight = inp->firStereoRight;
// iirStereoPilot = inp->iirStereoPilot;
// audioSampleRate = inp->audioSampleRate;
// } else if (audioResampler != inp->audioResampler) {
// msresamp_rrrf_destroy(audioResampler);
// msresamp_rrrf_destroy(stereoResampler);
// audioResampler = inp->audioResampler;
// stereoResampler = inp->stereoResampler;
// audioSampleRate = inp->audioSampleRate;
//
// if (demodAM) {
// ampmodem_reset(demodAM);
// }
// freqdem_reset(demodFM);
// nco_crcf_reset(stereoPilot);
// }
//
// if (firStereoLeft != inp->firStereoLeft) {
// if (firStereoLeft != NULL) {
// firfilt_rrrf_destroy(firStereoLeft);
// }
// firStereoLeft = inp->firStereoLeft;
// }
//
// if (firStereoRight != inp->firStereoRight) {
// if (firStereoRight != NULL) {
// firfilt_rrrf_destroy(firStereoRight);
// }
// firStereoRight = inp->firStereoRight;
// }
//
// if (iirStereoPilot != inp->iirStereoPilot) {
// if (iirStereoPilot != NULL) {
// iirfilt_crcf_destroy(iirStereoPilot);
// }
// iirStereoPilot = inp->iirStereoPilot;
// }
if (agcData.size() != bufSize) {
if (agcData.capacity() < bufSize) {
@ -618,58 +578,6 @@ void DemodulatorThread::run() {
} else {
msresamp_rrrf_execute(audioResampler, &demodOutputData[0], bufSize, &resampledOutputData[0], &numAudioWritten);
if (stereo && inp->sampleRate >= 100000) {
if (demodStereoData.size() != bufSize) {
if (demodStereoData.capacity() < bufSize) {
demodStereoData.reserve(bufSize);
}
demodStereoData.resize(bufSize);
}
float phase_error = 0;
for (int i = 0; i < bufSize; i++) {
// real -> complex
firhilbf_r2c_execute(firStereoR2C, demodOutputData[i], &x);
// 19khz pilot band-pass
iirfilt_crcf_execute(iirStereoPilot, x, &v);
nco_crcf_cexpf(stereoPilot, &w);
w.imag = -w.imag; // conjf(w)
// multiply u = v * conjf(w)
u.real = v.real * w.real - v.imag * w.imag;
u.imag = v.real * w.imag + v.imag * w.real;
// cargf(u)
phase_error = atan2f(u.imag,u.real);
// step pll
nco_crcf_pll_step(stereoPilot, phase_error);
nco_crcf_step(stereoPilot);
// 38khz down-mix
nco_crcf_mix_down(stereoPilot, x, &y);
nco_crcf_mix_down(stereoPilot, y, &x);
// complex -> real
firhilbf_c2r_execute(firStereoC2R, x, &demodStereoData[i]);
}
// std::cout << "[PLL] phase error: " << phase_error;
// std::cout << " freq:" << (((nco_crcf_get_frequency(stereoPilot) / (2.0 * M_PI)) * inp->sampleRate)) << std::endl;
if (audio_out_size != resampledStereoData.size()) {
if (resampledStereoData.capacity() < audio_out_size) {
resampledStereoData.reserve(audio_out_size);
}
resampledStereoData.resize(audio_out_size);
}
msresamp_rrrf_execute(stereoResampler, &demodStereoData[0], bufSize, &resampledStereoData[0], &numAudioWritten);
}
}*/
if (currentSignalLevel > signalLevel) {