SpectrumVisualProcessor fixes/tweaks

This commit is contained in:
Charles J. Cliffe 2015-12-11 22:58:58 -05:00
parent 8331b1e5b1
commit e22e696a7d
2 changed files with 24 additions and 5 deletions

View File

@ -134,6 +134,13 @@ void SpectrumVisualProcessor::process() {
unsigned int num_written; unsigned int num_written;
long resampleBw = iqData->sampleRate; long resampleBw = iqData->sampleRate;
if (bandwidth > resampleBw) {
iqData->decRefCount();
iqData->busy_rw.unlock();
busy_run.unlock();
return;
}
if (is_view.load()) { if (is_view.load()) {
if (!iqData->frequency || !iqData->sampleRate) { if (!iqData->frequency || !iqData->sampleRate) {
iqData->decRefCount(); iqData->decRefCount();
@ -189,6 +196,7 @@ void SpectrumVisualProcessor::process() {
if (resampler) { if (resampler) {
msresamp_crcf_destroy(resampler); msresamp_crcf_destroy(resampler);
} }
resampler = msresamp_crcf_create(resamplerRatio, As); resampler = msresamp_crcf_create(resamplerRatio, As);
lastBandwidth = resampleBw; lastBandwidth = resampleBw;
@ -323,11 +331,11 @@ void SpectrumVisualProcessor::process() {
// output->spectrum_points[i * 2 + 1] = v*sf; // output->spectrum_points[i * 2 + 1] = v*sf;
// } // }
double visualRatio = (double(bandwidth) / double(resampleBw)); double visualRatio = (double(bandwidth) / double(resampleBw));
int visualStart = fftSizeInternal/2 - floor((double(fftSizeInternal) * visualRatio) / 2.0); double visualStart = (double(fftSizeInternal) / 2.0) - (double(fftSizeInternal) * (visualRatio / 2.0));
double visualAccum = 0; double visualAccum = 0;
double acc = 0, accCount = 0; double acc = 0, accCount = 0, i = 0;
for (int x = 0, xMax = output->spectrum_points.size() / 2, i = 0; x < xMax; x++) { for (int x = 0, xMax = output->spectrum_points.size() / 2; x < xMax; x++) {
visualAccum += visualRatio * double(SPECTRUM_VZM); visualAccum += visualRatio * double(SPECTRUM_VZM);
// while (visualAccum >= 1.0) { // while (visualAccum >= 1.0) {
// visualAccum -= 1.0; // visualAccum -= 1.0;
@ -338,14 +346,21 @@ void SpectrumVisualProcessor::process() {
// output->spectrum_points[x * 2 + 1] = acc*sf; // output->spectrum_points[x * 2 + 1] = acc*sf;
while (visualAccum >= 1.0) { while (visualAccum >= 1.0) {
acc += (log10(fft_result_maa[visualStart+i]+0.25 - (fft_floor_maa-0.75)) / log10((fft_ceil_maa+0.25) - (fft_floor_maa-0.75))); int idx = round(visualStart+i);
if (idx < 0) {
idx = 0;
}
if (idx > fftSizeInternal) {
idx = fftSizeInternal;
}
acc += fft_result_maa[idx];
accCount += 1.0; accCount += 1.0;
visualAccum -= 1.0; visualAccum -= 1.0;
i++; i++;
} }
if (accCount) { if (accCount) {
output->spectrum_points[x * 2] = ((float) x / (float) xMax); output->spectrum_points[x * 2] = ((float) x / (float) xMax);
output->spectrum_points[x * 2 + 1] = (acc/accCount)*sf; output->spectrum_points[x * 2 + 1] = ((log10((acc/accCount)+0.25 - (fft_floor_maa-0.75)) / log10((fft_ceil_maa+0.25) - (fft_floor_maa-0.75))))*sf;
acc = 0.0; acc = 0.0;
accCount = 0.0; accCount = 0.0;
} }
@ -391,6 +406,8 @@ void SpectrumVisualProcessor::process() {
output->fft_floor = fft_floor_maa; output->fft_floor = fft_floor_maa;
} }
output->centerFreq = centerFreq;
output->bandwidth = bandwidth;
distribute(output); distribute(output);
} }

View File

@ -11,6 +11,8 @@ class SpectrumVisualData : public ReferenceCounter {
public: public:
std::vector<float> spectrum_points; std::vector<float> spectrum_points;
double fft_ceiling, fft_floor; double fft_ceiling, fft_floor;
long long centerFreq;
int bandwidth;
}; };
typedef ThreadQueue<SpectrumVisualData *> SpectrumVisualDataQueue; typedef ThreadQueue<SpectrumVisualData *> SpectrumVisualDataQueue;