25{
26 if (width < windowSize)
27 return false;
28
29 if (!data || !output)
30 return true;
31
32 Floats processed{ windowSize };
33
34 for (size_t i = 0; i < windowSize; i++)
35 processed[i] = float(0.0);
36 auto half = windowSize / 2;
37
41
42 size_t start = 0;
43 unsigned windows = 0;
44 while (start + windowSize <= width) {
45 for (size_t i = 0; i < windowSize; i++)
46 in[i] = data[start + i];
47
49
50 if (autocorrelation) {
51
52 RealFFT(windowSize, in.get(), out.get(), out2.get());
53
54 for (size_t i = 0; i < windowSize; i++)
55 in[i] = (out[i] * out[i]) + (out2[i] * out2[i]);
56
57
58
59
60 for (size_t i = 0; i < windowSize; i++)
61 in[i] = powf(in[i], 1.0f / 3.0f);
62
63
64 RealFFT(windowSize, in.get(), out.get(), out2.get());
65 }
66 else
68
69
70 for (size_t i = 0; i < half; i++)
71 processed[i] += out[i];
72
73 start += half;
74 windows++;
75 }
76
77 if (autocorrelation) {
78
79
80
81
82
83
84
85 for (size_t i = 0; i < half; i++) {
86
87 if (processed[i] < 0.0)
88 processed[i] = float(0.0);
89 out[i] = processed[i];
90
91
92 if ((i % 2) == 0)
93 processed[i] -= out[i / 2];
94 else
95 processed[i] -= ((out[i / 2] + out[i / 2 + 1]) / 2);
96
97
98 if (processed[i] < 0.0)
99 processed[i] = float(0.0);
100 }
101
102
103 for (size_t i = 0; i < half; i++)
104 in[i] = processed[i] / (windowSize / 4);
105 for (size_t i = 0; i < half; i++)
106 processed[half - 1 - i] = in[i];
107 } else {
108
109
110 for (size_t i = 0; i < half; i++){
111 float temp=(processed[i] / windowSize / windows);
112 if (temp > 0.0)
113 processed[i] = 10 * log10(temp);
114 else
115 processed[i] = 0;
116 }
117 }
118
119 for(size_t i = 0; i < half; i++)
120 output[i] = processed[i];
121
122 return true;
123}
void WindowFunc(int whichFunction, size_t NumSamples, float *in)
void PowerSpectrum(size_t NumSamples, const float *In, float *Out)
void RealFFT(size_t NumSamples, const float *RealIn, float *RealOut, float *ImagOut)