MCPcopy Create free account
hub / github.com/audacity/audacity / Calculate

Method Calculate

libraries/lib-fft/SpectrumAnalyst.cpp:40–275  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38}
39
40bool SpectrumAnalyst::Calculate(Algorithm alg, int windowFunc,
41 size_t windowSize, double rate,
42 const float *data, size_t dataLen,
43 float *pYMin, float *pYMax,
44 ProgressFn progress)
45{
46 // Wipe old data
47 mProcessed.resize(0);
48 mRate = 0.0;
49 mWindowSize = 0;
50
51 // Validate inputs
52 int f = NumWindowFuncs();
53
54 if (!(windowSize >= 32 && windowSize <= 131072 &&
55 alg >= SpectrumAnalyst::Spectrum &&
56 alg < SpectrumAnalyst::NumAlgorithms &&
57 windowFunc >= 0 && windowFunc < f)) {
58 return false;
59 }
60
61 if (dataLen < windowSize) {
62 return false;
63 }
64
65 // Now repopulate
66 mRate = rate;
67 mWindowSize = windowSize;
68 mAlg = alg;
69
70 auto half = mWindowSize / 2;
71 mProcessed.resize(mWindowSize);
72
73 ArrayOf<float> in{ mWindowSize };
74 ArrayOf<float> out{ mWindowSize };
75 ArrayOf<float> out2{ mWindowSize };
76 ArrayOf<float> win{ mWindowSize };
77
78 for (size_t i = 0; i < mWindowSize; i++) {
79 mProcessed[i] = 0.0f;
80 win[i] = 1.0f;
81 }
82
83 WindowFunc(windowFunc, mWindowSize, win.get());
84
85 // Scale window such that an amplitude of 1.0 in the time domain
86 // shows an amplitude of 0dB in the frequency domain
87 double wss = 0;
88 for (size_t i = 0; i<mWindowSize; i++)
89 wss += win[i];
90 if(wss > 0)
91 wss = 4.0 / (wss*wss);
92 else
93 wss = 1.0;
94
95 size_t start = 0;
96 int windows = 0;
97 while (start + mWindowSize <= dataLen) {

Callers

nothing calls this directly

Calls 7

NumWindowFuncsFunction · 0.85
WindowFuncFunction · 0.85
RealFFTFunction · 0.85
InverseRealFFTFunction · 0.85
PowerSpectrumFunction · 0.70
sqrtFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected