From de9be2025799c3676ecd346aadd7556cb889a1e8 Mon Sep 17 00:00:00 2001 From: Mike Walters Date: Fri, 11 Sep 2015 20:10:16 +0100 Subject: [PATCH] Use QCache to cache FFT results --- spectrogram.cpp | 6 +++--- spectrogram.h | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/spectrogram.cpp b/spectrogram.cpp index 0599186..189f97f 100644 --- a/spectrogram.cpp +++ b/spectrogram.cpp @@ -98,9 +98,9 @@ void Spectrogram::paintEvent(QPaintEvent *event) float* Spectrogram::getTile(off_t tile) { - auto iter = fftCache.find(qMakePair(fftSize, tile)); - if (iter != fftCache.end()) - return iter.value(); + float *obj = fftCache.object(qMakePair(fftSize, tile)); + if (obj != 0) + return obj; float *dest = new float[tileSize]; float *ptr = dest; diff --git a/spectrogram.h b/spectrogram.h index 41c3902..cf748a2 100644 --- a/spectrogram.h +++ b/spectrogram.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include "fft.h" #include "inputsource.h" @@ -38,7 +39,7 @@ private: FFT *fft = nullptr; std::unique_ptr window; fftwf_complex *lineBuffer = nullptr; - QHash, float*> fftCache; + QCache, float> fftCache; uint colormap[256]; int sampleRate;