Files
inspectrum/spectrogram.h
Mike Walters 4eb33aef1e Pre-calculate color map
Huge time savings in spectrogram generation.
Bit hacky at the moment with hard-coded size scattered everywhere.
Plan is to rejig this for custom color maps in the future, ref #4
2015-09-11 00:20:22 +01:00

52 lines
971 B
C++

#pragma once
#include <QWidget>
#include "fft.h"
#include "inputsource.h"
#include <math.h>
static const double Tau = M_PI * 2.0;
class Spectrogram : public QWidget {
Q_OBJECT
public:
Spectrogram();
~Spectrogram();
QSize sizeHint() const;
int getHeight();
int getStride();
public slots:
void openFile(QString fileName);
void setSampleRate(int rate);
void setFFTSize(int size);
void setPowerMax(int power);
void setPowerMin(int power);
void setZoomLevel(int zoom);
protected:
void paintEvent(QPaintEvent *event);
private:
const int linesPerGraduation = 50;
InputSource *inputSource = nullptr;
FFT *fft = nullptr;
std::unique_ptr<float[]> window;
fftwf_complex *lineBuffer = nullptr;
uint colormap[256];
int sampleRate;
int fftSize;
int zoomLevel;
float powerMax;
float powerMin;
void getLine(float *dest, int y);
void paintTimeAxis(QPainter *painter, QRect rect);
off_t lineToSample(int line);
QString sampleToTime(off_t sample);
};