Skip to content

Commit

Permalink
Fixed data race condition in spectrum vis when the FFT size is changed
Browse files Browse the repository at this point in the history
  • Loading branch information
f4exb committed Oct 22, 2015
1 parent 91cab6c commit 6a59ac7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions include/dsp/spectrumvis.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef INCLUDE_SPECTRUMVIS_H
#define INCLUDE_SPECTRUMVIS_H

#include <QMutex>
#include "dsp/samplesink.h"
#include "dsp/fftengine.h"
#include "fftwindow.h"
Expand Down Expand Up @@ -61,6 +62,8 @@ class SDRANGEL_API SpectrumVis : public SampleSink {

GLSpectrum* m_glSpectrum;

QMutex m_mutex;

void handleConfigure(int fftSize, int overlapPercent, FFTWindow::Function window);
};

Expand Down
7 changes: 6 additions & 1 deletion sdrbase/dsp/spectrumvis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ SpectrumVis::SpectrumVis(GLSpectrum* glSpectrum) :
m_logPowerSpectrum(MAX_FFT_SIZE),
m_fftBufferFill(0),
m_needMoreSamples(false),
m_glSpectrum(glSpectrum)
m_glSpectrum(glSpectrum),
m_mutex(QMutex::Recursive)
{
setObjectName("SpectrumVis");
handleConfigure(1024, 0, FFTWindow::BlackmanHarris);
Expand Down Expand Up @@ -77,6 +78,8 @@ void SpectrumVis::feed(const SampleVector::const_iterator& cbegin, const SampleV

if (todo >= samplesNeeded)
{
QMutexLocker mutexLocker(&m_mutex);

// fill up the buffer
std::vector<Complex>::iterator it = m_fftBuffer.begin() + m_fftBufferFill;

Expand Down Expand Up @@ -174,6 +177,8 @@ bool SpectrumVis::handleMessage(const Message& message)

void SpectrumVis::handleConfigure(int fftSize, int overlapPercent, FFTWindow::Function window)
{
QMutexLocker mutexLocker(&m_mutex);

if (fftSize > MAX_FFT_SIZE)
{
fftSize = MAX_FFT_SIZE;
Expand Down

0 comments on commit 6a59ac7

Please sign in to comment.