/*************************************************************************** source::worx raDIYo Copyright © 2020-2022 c.holzheuer chris@sourceworx.org This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. ***************************************************************************/ #ifndef SWFFTCALC_H #define SWFFTCALC_H #include #include #include #include #include #include #include #include #include #include // Scale PCM value to [-1.0, 1.0] qreal xpcmToReal(qint16 pcm); /** * @brief Berechnet mittels FFT ein Spectrum * aus dem @see @QAudioBuffer. Das Spectrum wird beim * Abspielen eines Songs angezeigt. * @see SWSpectrumWidget * @see SWPlayerControl */ class SWFFTCalc : public QObject { Q_OBJECT public: explicit SWFFTCalc( QObject* parent = nullptr ); virtual ~SWFFTCalc(); signals: void spectrumReady( const SWValVec& spectrum ); public slots: void onAudioProbed( const QAudioBuffer& audiobuffer ); protected: using Complex = std::complex; using CArray = std::valarray; void bareFFT( CArray& x ); static constexpr const int SWNumSamples = 4096; const double PI = 3.141592653589793238460; // Fudge factor used to calculate the spectrum bar heights //const qreal SpectrumAnalyserMultiplier = 0.15; const qreal SWFudgeFactor = 0.17; int _bufferDuration = 0; QElapsedTimer _timer; SWValVec _frames; SWValVec _hannWindow; // überdenken: geht das so schneller? // SWValVec _logscale; SWValVec _spectrum; CArray _complexFrame; }; #endif // SWFFTCALC_H