File indexing completed on 2024-06-23 05:42:09
0001 /* 0002 * Copyright (c) 2016 Daniel Holanda Noronha. All rights reserved. 0003 * 0004 * This work is licensed under the terms of the MIT license. 0005 * For a copy, see <https://opensource.org/licenses/MIT>. 0006 * 0007 */ 0008 0009 #ifndef FFTCALC_H 0010 #define FFTCALC_H 0011 0012 #include <QThread> 0013 #include <QWaitCondition> 0014 #include <QMutex> 0015 #include <QVector> 0016 #include <QDebug> 0017 #include <QTimer> 0018 #include <QObject> 0019 #include "fft.h" 0020 0021 #define SPECSIZE 512 0022 0023 class BufferProcessor: public QObject{ 0024 Q_OBJECT 0025 QVector<double> array; 0026 QVector<double> window; 0027 QVector<double> spectrum; 0028 QVector<double> logscale; 0029 QTimer *timer; 0030 bool compressed; 0031 bool running; 0032 int numberOfChunks; 0033 int interval; 0034 int pass; 0035 CArray complexFrame; 0036 0037 public slots: 0038 void processBuffer(QVector<double> _array, int duration); 0039 signals: 0040 void calculatedSpectrum(QVector<double> spectrum); 0041 void allDone(void); 0042 protected slots: 0043 void run(); 0044 public: 0045 explicit BufferProcessor(QObject *parent=0); 0046 ~BufferProcessor(); 0047 void calc(QVector<double> &_array, int duration); 0048 }; 0049 class FFTCalc : public QObject{ 0050 Q_OBJECT 0051 private: 0052 bool isBusy; 0053 BufferProcessor processor; 0054 QThread processorThread; 0055 0056 public: 0057 explicit FFTCalc(QObject *parent = 0); 0058 ~FFTCalc(); 0059 void calc(QVector<double> &_array, int duration); 0060 public slots: 0061 void setSpectrum(QVector<double> spectrum); 0062 void freeCalc(); 0063 signals: 0064 void calculatedSpectrum(QVector<double> spectrum); 0065 }; 0066 0067 #endif // FFTCALC_H