41 size_t windowSize,
double rate,
42 const float *data,
size_t dataLen,
43 float *pYMin,
float *pYMax,
54 if (!(windowSize >= 32 && windowSize <= 131072 &&
57 windowFunc >= 0 && windowFunc < f)) {
61 if (dataLen < windowSize) {
91 wss = 4.0 / (wss*wss);
99 in[i] = win[i] * data[start + i];
105 for (
size_t i = 0; i < half; i++)
117 in[i] = (out[i] * out[i]) + (out2[i] * out2[i]);
129 in[i] = pow(in[i], 1.0f / 3.0f);
135 for (
size_t i = 0; i < half; i++)
149 power = (out[i] * out[i]) + (out2[i] * out2[i]);
151 in[i] = log(minpower);
159 for (
size_t i = 0; i < half; i++)
171 progress(start, dataLen);
178 float mYMin = 1000000, mYMax = -1000000;
185 scale = wss / (double)windows;
186 for (
size_t i = 0; i < half; i++)
198 for (
size_t i = 0; i < half; i++)
204 for (
size_t i = 1; i < half; i++)
212 for (
size_t i = 0; i < half; i++)
218 for (
size_t i = 0; i < half; i++) {
226 for (
size_t i = 0; i < half; i++)
230 mProcessed[i] -= ((out[i / 2] + out[i / 2 + 1]) / 2);
233 for (
size_t i = 0; i < half; i++)
240 for (
size_t i = 1; i < half; i++)
248 for (
size_t i = 0; i < half; i++)
289 float bin0, bin1, binwidth;
295 bin0 = freq0 *
mRate;
296 bin1 = freq1 *
mRate;
298 binwidth = bin1 - bin0;
300 float value = float(0.0);
302 if (binwidth < 1.0) {
303 float binmid = (bin0 + bin1) / 2.0;
304 int ibin = (int)(binmid) - 1;
321 if ((
int)(bin1) > (
int)(bin0))
322 value +=
mProcessed[(int)(bin0)] * ((int)(bin0) + 1 - bin0);
323 bin0 = 1 + (int)(bin0);
324 while (bin0 < (
int)(bin1)) {
328 value +=
mProcessed[(int)(bin1)] * (bin1 - (int)(bin1));
338 float bestpeak = 0.0f;
339 float bestValue = 0.0;
342 float bestdist = 1000000;
347 int leftbin = bin - 2;
352 float valueAtMax = 0.0;
363 thispeak = max /
mRate;
365 if (fabs(thispeak - xPos) < bestdist) {
367 bestdist = fabs(thispeak - xPos);
368 bestValue = valueAtMax;
392 a = y0 / -6.0 + y1 / 2.0 - y2 / 2.0 + y3 / 6.0;
393 b = y0 - 5.0 * y1 / 2.0 + 2.0 * y2 - y3 / 2.0;
394 c = -11.0 * y0 / 6.0 + 3.0 * y1 - 3.0 * y2 / 2.0 + y3 / 3.0;
400 return (a * xxx + b * xx + c * x + d);
409 a = y0 / -6.0 + y1 / 2.0 - y2 / 2.0 + y3 / 6.0;
410 b = y0 - 5.0 * y1 / 2.0 + 2.0 * y2 - y3 / 2.0;
411 c = -11.0 * y0 / 6.0 + 3.0 * y1 - 3.0 * y2 / 2.0 + y3 / 3.0;
424 float discriminant = db * db - 4 * da * dc;
425 if (discriminant < 0.0)
428 float x1 = (-db +
sqrt(discriminant)) / (2 * da);
429 float x2 = (-db -
sqrt(discriminant)) / (2 * da);
438 if (dda * x1 + ddb < 0)
440 *max = a*x1*x1*x1+b*x1*x1+c*x1+d;
445 *max = a*x2*x2*x2+b*x2*x2+c*x2+d;
void WindowFunc(int whichFunction, size_t NumSamples, float *in)
void PowerSpectrum(size_t NumSamples, const float *In, float *Out)
void InverseRealFFT(size_t NumSamples, const float *RealIn, const float *ImagIn, float *RealOut)
void RealFFT(size_t NumSamples, const float *RealIn, float *RealOut, float *ImagOut)
const float * GetProcessed() const
std::vector< float > mProcessed
@ EnhancedAutocorrelation
@ CubeRootAutocorrelation
float CubicMaximize(float y0, float y1, float y2, float y3, float *max) const
float CubicInterpolate(float y0, float y1, float y2, float y3, float x) const
float FindPeak(float xPos, float *pY) const
float GetProcessedValue(float freq0, float freq1) const
std::function< void(long long num, long long den)> ProgressFn
int GetProcessedSize() const
bool Calculate(Algorithm alg, int windowFunc, size_t windowSize, double rate, const float *data, size_t dataLen, float *pYMin=NULL, float *pYMax=NULL, ProgressFn progress=NULL)
constexpr fastfloat_really_inline int32_t power(int32_t q) noexcept
__finl float_x4 __vecc sqrt(const float_x4 &a)