SpectrumVisualProcessor thread fixes, spectrum label optimize

This commit is contained in:
Charles J. Cliffe 2015-08-23 17:51:20 -04:00
parent 7a0f523eaf
commit 13140ec28c
3 changed files with 39 additions and 21 deletions

View File

@ -132,27 +132,31 @@ void SpectrumPanel::drawPanelContents() {
long long leftFreq = (double) freq - ((double) bandwidth / 2.0); long long leftFreq = (double) freq - ((double) bandwidth / 2.0);
long long rightFreq = leftFreq + (double) bandwidth; long long rightFreq = leftFreq + (double) bandwidth;
long long firstMhz = (leftFreq / 1000000) * 1000000; long long hzStep = 1000000;
long double mhzStart = ((long double) (firstMhz - leftFreq) / (long double) (rightFreq - leftFreq)) * 2.0;
long double mhzStep = (100000.0 / (long double) (rightFreq - leftFreq)) * 2.0; long double mhzStep = (100000.0 / (long double) (rightFreq - leftFreq)) * 2.0;
double mhzVisualStep = 0.1f; double mhzVisualStep = 0.1;
std::stringstream label;
label.precision(1);
if (mhzStep * 0.5 * viewWidth < 40) { if (mhzStep * 0.5 * viewWidth < 40) {
mhzStep = (250000.0 / (long double) (rightFreq - leftFreq)) * 2.0; mhzStep = (250000.0 / (long double) (rightFreq - leftFreq)) * 2.0;
mhzVisualStep = 0.25f; mhzVisualStep = 0.25;
label.precision(2);
} }
if (mhzStep * 0.5 * viewWidth > 400) { if (mhzStep * 0.5 * viewWidth > 350) {
mhzStep = (10000.0 / (long double) (rightFreq - leftFreq)) * 2.0; mhzStep = (10000.0 / (long double) (rightFreq - leftFreq)) * 2.0;
mhzVisualStep = 0.01f; mhzVisualStep = 0.01;
label.precision(2);
} }
long double currentMhz = trunc(floor(firstMhz / 1000000.0));
std::stringstream label; long long firstMhz = (leftFreq / hzStep) * hzStep;
label.precision(2); long double mhzStart = ((long double) (firstMhz - leftFreq) / (long double) (rightFreq - leftFreq)) * 2.0;
long double currentMhz = trunc(floor(firstMhz / (long double)1000000.0));
double hPos = 1.0 - (16.0 / viewHeight); double hPos = 1.0 - (16.0 / viewHeight);
double lMhzPos = 1.0 - (5.0 / viewHeight); double lMhzPos = 1.0 - (5.0 / viewHeight);

View File

@ -14,7 +14,7 @@ SpectrumVisualProcessor::SpectrumVisualProcessor() : lastInputBandwidth(0), last
fft_ceil_ma = fft_ceil_maa = 100.0; fft_ceil_ma = fft_ceil_maa = 100.0;
fft_floor_ma = fft_floor_maa = 0.0; fft_floor_ma = fft_floor_maa = 0.0;
desiredInputSize = 0; desiredInputSize.store(0);
fft_average_rate = 0.65; fft_average_rate = 0.65;
} }
@ -27,19 +27,25 @@ bool SpectrumVisualProcessor::isView() {
} }
void SpectrumVisualProcessor::setView(bool bView) { void SpectrumVisualProcessor::setView(bool bView) {
busy_run.lock();
is_view.store(bView); is_view.store(bView);
busy_run.unlock();
} }
void SpectrumVisualProcessor::setFFTAverageRate(float fftAverageRate) { void SpectrumVisualProcessor::setFFTAverageRate(float fftAverageRate) {
this->fft_average_rate = fftAverageRate; busy_run.lock();
this->fft_average_rate.store(fftAverageRate);
busy_run.unlock();
} }
float SpectrumVisualProcessor::getFFTAverageRate() { float SpectrumVisualProcessor::getFFTAverageRate() {
return this->fft_average_rate; return this->fft_average_rate.load();
} }
void SpectrumVisualProcessor::setCenterFrequency(long long centerFreq_in) { void SpectrumVisualProcessor::setCenterFrequency(long long centerFreq_in) {
busy_run.lock();
centerFreq.store(centerFreq_in); centerFreq.store(centerFreq_in);
busy_run.unlock();
} }
long long SpectrumVisualProcessor::getCenterFrequency() { long long SpectrumVisualProcessor::getCenterFrequency() {
@ -47,7 +53,9 @@ long long SpectrumVisualProcessor::getCenterFrequency() {
} }
void SpectrumVisualProcessor::setBandwidth(long bandwidth_in) { void SpectrumVisualProcessor::setBandwidth(long bandwidth_in) {
busy_run.lock();
bandwidth.store(bandwidth_in); bandwidth.store(bandwidth_in);
busy_run.unlock();
} }
long SpectrumVisualProcessor::getBandwidth() { long SpectrumVisualProcessor::getBandwidth() {
@ -55,12 +63,14 @@ long SpectrumVisualProcessor::getBandwidth() {
} }
int SpectrumVisualProcessor::getDesiredInputSize() { int SpectrumVisualProcessor::getDesiredInputSize() {
return desiredInputSize; return desiredInputSize.load();
} }
void SpectrumVisualProcessor::setup(int fftSize_in) { void SpectrumVisualProcessor::setup(int fftSize_in) {
busy_run.lock();
fftSize = fftSize_in; fftSize = fftSize_in;
desiredInputSize = fftSize; desiredInputSize.store(fftSize);
if (fftwInput) { if (fftwInput) {
free(fftwInput); free(fftwInput);
@ -82,7 +92,7 @@ void SpectrumVisualProcessor::setup(int fftSize_in) {
fftwf_destroy_plan(fftw_plan); fftwf_destroy_plan(fftw_plan);
} }
fftw_plan = fftwf_plan_dft_1d(fftSize, fftwInput, fftwOutput, FFTW_FORWARD, FFTW_ESTIMATE); fftw_plan = fftwf_plan_dft_1d(fftSize, fftwInput, fftwOutput, FFTW_FORWARD, FFTW_ESTIMATE);
busy_run.unlock();
} }
void SpectrumVisualProcessor::process() { void SpectrumVisualProcessor::process() {
@ -102,6 +112,7 @@ void SpectrumVisualProcessor::process() {
} }
iqData->busy_rw.lock(); iqData->busy_rw.lock();
busy_run.lock();
std::vector<liquid_float_complex> *data = &iqData->data; std::vector<liquid_float_complex> *data = &iqData->data;
@ -118,6 +129,7 @@ void SpectrumVisualProcessor::process() {
if (!iqData->frequency || !iqData->sampleRate) { if (!iqData->frequency || !iqData->sampleRate) {
iqData->decRefCount(); iqData->decRefCount();
iqData->busy_rw.unlock(); iqData->busy_rw.unlock();
busy_run.unlock();
return; return;
} }
@ -125,7 +137,7 @@ void SpectrumVisualProcessor::process() {
int desired_input_size = fftSize / resamplerRatio; int desired_input_size = fftSize / resamplerRatio;
this->desiredInputSize = desired_input_size; this->desiredInputSize.store(desired_input_size);
if (iqData->data.size() < desired_input_size) { if (iqData->data.size() < desired_input_size) {
// std::cout << "fft underflow, desired: " << desired_input_size << " actual:" << input->data.size() << std::endl; // std::cout << "fft underflow, desired: " << desired_input_size << " actual:" << input->data.size() << std::endl;
@ -304,5 +316,6 @@ void SpectrumVisualProcessor::process() {
iqData->decRefCount(); iqData->decRefCount();
iqData->busy_rw.unlock(); iqData->busy_rw.unlock();
busy_run.unlock();
} }

View File

@ -53,7 +53,7 @@ private:
double fft_ceil_ma, fft_ceil_maa; double fft_ceil_ma, fft_ceil_maa;
double fft_floor_ma, fft_floor_maa; double fft_floor_ma, fft_floor_maa;
float fft_average_rate; std::atomic<float> fft_average_rate;
std::vector<double> fft_result; std::vector<double> fft_result;
std::vector<double> fft_result_ma; std::vector<double> fft_result_ma;
@ -66,7 +66,8 @@ private:
std::vector<liquid_float_complex> shiftBuffer; std::vector<liquid_float_complex> shiftBuffer;
std::vector<liquid_float_complex> resampleBuffer; std::vector<liquid_float_complex> resampleBuffer;
int desiredInputSize; std::atomic_int desiredInputSize;
std::mutex busy_run;
}; };