23 const float* data,
size_t width,
size_t windowSize,
float* output,
24 bool autocorrelation,
int windowFunc)
26 if (width < windowSize)
32 Floats processed{ windowSize };
34 for (
size_t i = 0; i < windowSize; i++)
35 processed[i] =
float(0.0);
36 auto half = windowSize / 2;
44 while (start + windowSize <= width) {
45 for (
size_t i = 0; i < windowSize; i++)
46 in[i] = data[start + i];
50 if (autocorrelation) {
52 RealFFT(windowSize, in.get(), out.get(), out2.get());
54 for (
size_t i = 0; i < windowSize; i++)
55 in[i] = (out[i] * out[i]) + (out2[i] * out2[i]);
60 for (
size_t i = 0; i < windowSize; i++)
61 in[i] = powf(in[i], 1.0f / 3.0f);
64 RealFFT(windowSize, in.get(), out.get(), out2.get());
70 for (
size_t i = 0; i < half; i++)
71 processed[i] += out[i];
77 if (autocorrelation) {
85 for (
size_t i = 0; i < half; i++) {
87 if (processed[i] < 0.0)
88 processed[i] = float(0.0);
89 out[i] = processed[i];
93 processed[i] -= out[i / 2];
95 processed[i] -= ((out[i / 2] + out[i / 2 + 1]) / 2);
98 if (processed[i] < 0.0)
99 processed[i] = float(0.0);
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];
110 for (
size_t i = 0; i < half; i++){
111 float temp=(processed[i] / windowSize / windows);
113 processed[i] = 10 * log10(temp);
119 for(
size_t i = 0; i < half; i++)
120 output[i] = processed[i];
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)
bool ComputeSpectrum(const float *data, size_t width, size_t windowSize, float *output, bool autocorrelation, int windowFunc)