raDIYo 0.4
swfftcalc.h
1/***************************************************************************
2
3 source::worx raDIYo
4 Copyright © 2020-2022 c.holzheuer
5 c.holzheuer@sourceworx.org
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12***************************************************************************/
13
14
15#ifndef SWFFTCALC_H
16#define SWFFTCALC_H
17
18#include <complex>
19#include <iostream>
20#include <valarray>
21
22#include <QObject>
23#include <QAudioFormat>
24#include <QAudioProbe>
25#include <QAudioDeviceInfo>
26#include <QElapsedTimer>
27
28#include <raDIYo.h>
29
30
31// Scale PCM value to [-1.0, 1.0]
32qreal pcmToReal(qint16 pcm);
33
34
35class SWFFTCalc : public QObject
36{
37
38 Q_OBJECT
39
40public:
41
42 explicit SWFFTCalc( QObject* parent = nullptr );
43 virtual ~SWFFTCalc();
44
45 void collectFrames( QAudioBuffer& audiobuffer );
46
47signals:
48
49 void spectrumReady( const SWDoubleVec& spectrum );
50
51protected:
52
53 typedef std::complex<double> Complex;
54 typedef std::valarray<Complex> CArray;
55
56 //template<class T>
57 //void prepareInput( QAudioBuffer& audiobuffer, T& dataType, qreal peakValue );
58
59 void bareFFT( CArray& x );
60
61 static constexpr const int SWNUMSAMPLES = 4096;
62 const double PI = 3.141592653589793238460;
63
64 // Fudge factor used to calculate the spectrum bar heights
65 //const qreal SpectrumAnalyserMultiplier = 0.15;
66 const qreal SpectrumAnalyserMultiplier = 0.10;
67
68 QAudioBuffer::S32F _s32f;
69 QAudioBuffer::S16S _s16s;
70 QAudioBuffer::S16U _s16u;
71 QAudioBuffer::S8S _s8s;
72 QAudioBuffer::S8U _s8u;
73
74 /*
75 typedef StereoFrame<unsigned char> S8U;
76 typedef StereoFrame<signed char> S8S;
77 typedef StereoFrame<unsigned short> S16U;
78 typedef StereoFrame<signed short> S16S;
79 typedef StereoFrame<float> S32F;
80 */
81
82 int _bufferDuration = 0;
83 QElapsedTimer _timer;
84 SWDoubleVec _frames;
85 SWDoubleVec _hannWindow;
86 // überdenken: geht das so schneller?
87 // SWDoubleVec _logscale;
88 SWDoubleVec _spectrum;
89 CArray _complexFrame;
90
91 /*
92 QVector<double> array;
93 QVector<double> window;
94 QVector<double> spectrum;
95
96 */
97
98};
99
100#endif // SWFFTCALC_H
void collectFrames(QAudioBuffer &audiobuffer)
Track::getPeakValue.
Definition: swfftcalc.cpp:120