1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-25 17:28:50 -05:00

Spectrum: set overlap by value not by percentage

This commit is contained in:
f4exb 2021-02-08 23:40:28 +01:00
parent f541b53454
commit 84c26e9678
4 changed files with 19 additions and 25 deletions

View File

@ -60,7 +60,7 @@ QByteArray GLSpectrumSettings::serialize() const
{
SimpleSerializer s(1);
s.writeU32(1, m_fftSize);
s.writeS32(1, m_fftSize);
s.writeS32(2, m_fftOverlap);
s.writeS32(3, (int) m_fftWindow);
s.writeReal(4, m_refLevel);
@ -102,7 +102,7 @@ bool GLSpectrumSettings::deserialize(const QByteArray& data)
if (d.getVersion() == 1)
{
d.readU32(1, &m_fftSize, 1024);
d.readS32(1, &m_fftSize, 1024);
d.readS32(2, &m_fftOverlap, 0);
d.readS32(3, &tmp, (int) FFTWindow::Hanning);
m_fftWindow = (FFTWindow::Function) tmp;

View File

@ -36,7 +36,7 @@ public:
AvgModeMax
};
unsigned int m_fftSize;
int m_fftSize;
int m_fftOverlap;
FFTWindow::Function m_fftWindow;
Real m_refLevel;

View File

@ -123,9 +123,9 @@ void SpectrumVis::feed(const Complex *begin, unsigned int length)
if (m_settings.m_averagingMode == GLSpectrumSettings::AvgModeNone)
{
for (unsigned int i = 0; i < m_settings.m_fftSize; i++)
for (int i = 0; i < m_settings.m_fftSize; i++)
{
if (i < length) {
if (i < (int) length) {
c = begin[i];
} else {
c = Complex{0,0};
@ -157,9 +157,9 @@ void SpectrumVis::feed(const Complex *begin, unsigned int length)
}
else if (m_settings.m_averagingMode == GLSpectrumSettings::AvgModeMoving)
{
for (unsigned int i = 0; i < m_settings.m_fftSize; i++)
for (int i = 0; i < m_settings.m_fftSize; i++)
{
if (i < length) {
if (i < (int) length) {
c = begin[i];
} else {
c = Complex{0,0};
@ -196,9 +196,9 @@ void SpectrumVis::feed(const Complex *begin, unsigned int length)
{
double avg;
for (unsigned int i = 0; i < m_settings.m_fftSize; i++)
for (int i = 0; i < m_settings.m_fftSize; i++)
{
if (i < length) {
if (i < (int) length) {
c = begin[i];
} else {
c = Complex{0,0};
@ -241,9 +241,9 @@ void SpectrumVis::feed(const Complex *begin, unsigned int length)
{
double max;
for (unsigned int i = 0; i < m_settings.m_fftSize; i++)
for (int i = 0; i < m_settings.m_fftSize; i++)
{
if (i < length) {
if (i < (int) length) {
c = begin[i];
} else {
c = Complex{0,0};
@ -690,22 +690,16 @@ void SpectrumVis::applySettings(const GLSpectrumSettings& settings, bool force)
{
QMutexLocker mutexLocker(&m_mutex);
unsigned int fftSize = settings.m_fftSize > MAX_FFT_SIZE ?
int fftSize = settings.m_fftSize > MAX_FFT_SIZE ?
MAX_FFT_SIZE :
settings.m_fftSize < 64 ?
64 :
settings.m_fftSize;
int overlapPercent = settings.m_fftOverlap > 100 ?
100 :
settings.m_fftOverlap < 0 ?
0 :
settings.m_fftOverlap;
qDebug() << "SpectrumVis::applySettings:"
<< " m_fftSize: " << fftSize
<< " m_fftWindow: " << settings.m_fftWindow
<< " m_fftOverlap: " << overlapPercent
<< " m_fftOverlap: " << settings.m_fftOverlap
<< " m_averagingIndex: " << settings.m_averagingIndex
<< " m_averagingMode: " << settings.m_averagingMode
<< " m_refLevel: " << settings.m_refLevel
@ -738,9 +732,10 @@ void SpectrumVis::applySettings(const GLSpectrumSettings& settings, bool force)
}
if ((fftSize != m_settings.m_fftSize)
|| (overlapPercent != m_settings.m_fftOverlap) || force)
|| (settings.m_fftOverlap != m_settings.m_fftOverlap) || force)
{
m_overlapSize = (fftSize * overlapPercent) / 100;
m_overlapSize = settings.m_fftOverlap >= fftSize ? fftSize - 1 :
settings.m_fftOverlap < 0 ? 0 : settings.m_fftOverlap;
m_refillSize = fftSize - m_overlapSize;
m_fftBufferFill = m_overlapSize;
}
@ -762,7 +757,6 @@ void SpectrumVis::applySettings(const GLSpectrumSettings& settings, bool force)
m_settings = settings;
m_settings.m_fftSize = fftSize;
m_settings.m_fftOverlap = overlapPercent;
}
void SpectrumVis::handleConfigureDSP(uint64_t centerFrequency, int sampleRate)

View File

@ -190,9 +190,9 @@ private:
std::vector<Real> m_powerSpectrum;
GLSpectrumSettings m_settings;
std::size_t m_overlapSize;
std::size_t m_refillSize;
std::size_t m_fftBufferFill;
int m_overlapSize;
int m_refillSize;
int m_fftBufferFill;
bool m_needMoreSamples;
Real m_scalef;