29#include <wx/dcclient.h>
32: wxStatusBar(parent, winid, wxST_SIZEGRIP)
43 GetFieldRect(0,
mRect);
61 dc.SetPen(*wxTRANSPARENT_PEN);
62 dc.SetBrush(wxColour(100, 100, 220));
68 dc.DrawRectangle(
mRect);
92 size_t windowSize,
double rate,
93 const float *data,
size_t dataLen,
94 float *pYMin,
float *pYMax,
105 if (!(windowSize >= 32 && windowSize <= 131072 &&
108 windowFunc >= 0 && windowFunc < f)) {
112 if (dataLen < windowSize) {
142 wss = 4.0 / (wss*wss);
154 in[i] = win[i] * data[start + i];
160 for (
size_t i = 0; i < half; i++)
172 in[i] = (out[i] * out[i]) + (out2[i] * out2[i]);
184 in[i] = pow(in[i], 1.0f / 3.0f);
190 for (
size_t i = 0; i < half; i++)
204 power = (out[i] * out[i]) + (out2[i] * out2[i]);
206 in[i] = log(minpower);
214 for (
size_t i = 0; i < half; i++)
239 float mYMin = 1000000, mYMax = -1000000;
246 scale = wss / (double)windows;
247 for (
size_t i = 0; i < half; i++)
259 for (
size_t i = 0; i < half; i++)
265 for (
size_t i = 1; i < half; i++)
273 for (
size_t i = 0; i < half; i++)
279 for (
size_t i = 0; i < half; i++) {
287 for (
size_t i = 0; i < half; i++)
291 mProcessed[i] -= ((out[i / 2] + out[i / 2 + 1]) / 2);
294 for (
size_t i = 0; i < half; i++)
301 for (
size_t i = 1; i < half; i++)
309 for (
size_t i = 0; i < half; i++)
317 for (
size_t i = ignore + 1; i + ignore < half; i++)
350 float bin0, bin1, binwidth;
356 bin0 = freq0 *
mRate;
357 bin1 = freq1 *
mRate;
359 binwidth = bin1 - bin0;
361 float value = float(0.0);
363 if (binwidth < 1.0) {
364 float binmid = (bin0 + bin1) / 2.0;
365 int ibin = (int)(binmid) - 1;
382 if ((
int)(bin1) > (
int)(bin0))
383 value +=
mProcessed[(int)(bin0)] * ((int)(bin0) + 1 - bin0);
384 bin0 = 1 + (int)(bin0);
385 while (bin0 < (
int)(bin1)) {
389 value +=
mProcessed[(int)(bin1)] * (bin1 - (int)(bin1));
399 float bestpeak = 0.0f;
400 float bestValue = 0.0;
403 float bestdist = 1000000;
408 int leftbin = bin - 2;
413 float valueAtMax = 0.0;
424 thispeak = max /
mRate;
426 if (fabs(thispeak - xPos) < bestdist) {
428 bestdist = fabs(thispeak - xPos);
429 bestValue = valueAtMax;
453 a = y0 / -6.0 + y1 / 2.0 - y2 / 2.0 + y3 / 6.0;
454 b = y0 - 5.0 * y1 / 2.0 + 2.0 * y2 - y3 / 2.0;
455 c = -11.0 * y0 / 6.0 + 3.0 * y1 - 3.0 * y2 / 2.0 + y3 / 3.0;
461 return (a * xxx + b * xx + c * x + d);
470 a = y0 / -6.0 + y1 / 2.0 - y2 / 2.0 + y3 / 6.0;
471 b = y0 - 5.0 * y1 / 2.0 + 2.0 * y2 - y3 / 2.0;
472 c = -11.0 * y0 / 6.0 + 3.0 * y1 - 3.0 * y2 / 2.0 + y3 / 3.0;
485 float discriminant = db * db - 4 * da * dc;
486 if (discriminant < 0.0)
489 float x1 = (-db + sqrt(discriminant)) / (2 * da);
490 float x2 = (-db - sqrt(discriminant)) / (2 * da);
499 if (dda * x1 + ddb < 0)
501 *max = a*x1*x1*x1+b*x1*x1+c*x1+d;
506 *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)
void SetRange(int range, int bar=12, int gap=3)
FreqGauge(wxWindow *parent, wxWindowID winid)
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
bool Calculate(Algorithm alg, int windowFunc, size_t windowSize, double rate, const float *data, size_t dataLen, float *pYMin=NULL, float *pYMax=NULL, FreqGauge *progress=NULL)
int GetProcessedSize() const
constexpr fastfloat_really_inline int32_t power(int32_t q) noexcept