pixel column counts and sample window sizes use unsigned types

This commit is contained in:
Paul Licameli 2016-09-08 14:28:34 -04:00
parent b910bf63da
commit ed21545c80
36 changed files with 1031 additions and 1010 deletions

View File

@ -50,15 +50,12 @@
#include "Experimental.h" #include "Experimental.h"
static int **gFFTBitTable = NULL; static int **gFFTBitTable = NULL;
static const int MaxFastBits = 16; static const size_t MaxFastBits = 16;
/* Declare Static functions */ /* Declare Static functions */
static int IsPowerOfTwo(int x);
static int NumberOfBitsNeeded(int PowerOfTwo);
static int ReverseBits(int index, int NumBits);
static void InitFFT(); static void InitFFT();
int IsPowerOfTwo(int x) static bool IsPowerOfTwo(size_t x)
{ {
if (x < 2) if (x < 2)
return false; return false;
@ -69,23 +66,23 @@ int IsPowerOfTwo(int x)
return true; return true;
} }
int NumberOfBitsNeeded(int PowerOfTwo) static size_t NumberOfBitsNeeded(size_t PowerOfTwo)
{ {
int i;
if (PowerOfTwo < 2) { if (PowerOfTwo < 2) {
fprintf(stderr, "Error: FFT called with size %d\n", PowerOfTwo); fprintf(stderr, "Error: FFT called with size %ld\n", PowerOfTwo);
exit(1); exit(1);
} }
for (i = 0;; i++) size_t i = 0;
if (PowerOfTwo & (1 << i)) while (PowerOfTwo > 1)
PowerOfTwo >>= 1, ++i;
return i; return i;
} }
int ReverseBits(int index, int NumBits) int ReverseBits(size_t index, size_t NumBits)
{ {
int i, rev; size_t i, rev;
for (i = rev = 0; i < NumBits; i++) { for (i = rev = 0; i < NumBits; i++) {
rev = (rev << 1) | (index & 1); rev = (rev << 1) | (index & 1);
@ -99,12 +96,12 @@ void InitFFT()
{ {
gFFTBitTable = new int *[MaxFastBits]; gFFTBitTable = new int *[MaxFastBits];
int len = 2; size_t len = 2;
for (int b = 1; b <= MaxFastBits; b++) { for (size_t b = 1; b <= MaxFastBits; b++) {
gFFTBitTable[b - 1] = new int[len]; gFFTBitTable[b - 1] = new int[len];
for (int i = 0; i < len; i++) for (size_t i = 0; i < len; i++)
gFFTBitTable[b - 1][i] = ReverseBits(i, b); gFFTBitTable[b - 1][i] = ReverseBits(i, b);
len <<= 1; len <<= 1;
@ -114,7 +111,7 @@ void InitFFT()
void DeinitFFT() void DeinitFFT()
{ {
if (gFFTBitTable) { if (gFFTBitTable) {
for (int b = 1; b <= MaxFastBits; b++) { for (size_t b = 1; b <= MaxFastBits; b++) {
delete[] gFFTBitTable[b-1]; delete[] gFFTBitTable[b-1];
} }
delete[] gFFTBitTable; delete[] gFFTBitTable;
@ -123,7 +120,7 @@ void DeinitFFT()
CleanupFFT(); CleanupFFT();
} }
inline int FastReverseBits(int i, int NumBits) static inline size_t FastReverseBits(size_t i, size_t NumBits)
{ {
if (NumBits <= MaxFastBits) if (NumBits <= MaxFastBits)
return gFFTBitTable[NumBits - 1][i]; return gFFTBitTable[NumBits - 1][i];
@ -135,20 +132,16 @@ inline int FastReverseBits(int i, int NumBits)
* Complex Fast Fourier Transform * Complex Fast Fourier Transform
*/ */
void FFT(int NumSamples, void FFT(size_t NumSamples,
bool InverseTransform, bool InverseTransform,
const float *RealIn, const float *ImagIn, const float *RealIn, const float *ImagIn,
float *RealOut, float *ImagOut) float *RealOut, float *ImagOut)
{ {
int NumBits; /* Number of bits needed to store indices */
int i, j, k, n;
int BlockSize, BlockEnd;
double angle_numerator = 2.0 * M_PI; double angle_numerator = 2.0 * M_PI;
double tr, ti; /* temp real, temp imaginary */ double tr, ti; /* temp real, temp imaginary */
if (!IsPowerOfTwo(NumSamples)) { if (!IsPowerOfTwo(NumSamples)) {
fprintf(stderr, "%d is not a power of two\n", NumSamples); fprintf(stderr, "%ld is not a power of two\n", NumSamples);
exit(1); exit(1);
} }
@ -158,14 +151,15 @@ void FFT(int NumSamples,
if (!InverseTransform) if (!InverseTransform)
angle_numerator = -angle_numerator; angle_numerator = -angle_numerator;
NumBits = NumberOfBitsNeeded(NumSamples); /* Number of bits needed to store indices */
auto NumBits = NumberOfBitsNeeded(NumSamples);
/* /*
** Do simultaneous data copy and bit-reversal ordering into outputs... ** Do simultaneous data copy and bit-reversal ordering into outputs...
*/ */
for (i = 0; i < NumSamples; i++) { for (size_t i = 0; i < NumSamples; i++) {
j = FastReverseBits(i, NumBits); auto j = FastReverseBits(i, NumBits);
RealOut[j] = RealIn[i]; RealOut[j] = RealIn[i];
ImagOut[j] = (ImagIn == NULL) ? 0.0 : ImagIn[i]; ImagOut[j] = (ImagIn == NULL) ? 0.0 : ImagIn[i];
} }
@ -174,8 +168,8 @@ void FFT(int NumSamples,
** Do the FFT itself... ** Do the FFT itself...
*/ */
BlockEnd = 1; size_t BlockEnd = 1;
for (BlockSize = 2; BlockSize <= NumSamples; BlockSize <<= 1) { for (size_t BlockSize = 2; BlockSize <= NumSamples; BlockSize <<= 1) {
double delta_angle = angle_numerator / (double) BlockSize; double delta_angle = angle_numerator / (double) BlockSize;
@ -186,14 +180,14 @@ void FFT(int NumSamples,
double w = 2 * cm1; double w = 2 * cm1;
double ar0, ar1, ar2, ai0, ai1, ai2; double ar0, ar1, ar2, ai0, ai1, ai2;
for (i = 0; i < NumSamples; i += BlockSize) { for (size_t i = 0; i < NumSamples; i += BlockSize) {
ar2 = cm2; ar2 = cm2;
ar1 = cm1; ar1 = cm1;
ai2 = sm2; ai2 = sm2;
ai1 = sm1; ai1 = sm1;
for (j = i, n = 0; n < BlockEnd; j++, n++) { for (size_t j = i, n = 0; n < BlockEnd; j++, n++) {
ar0 = w * ar1 - ar2; ar0 = w * ar1 - ar2;
ar2 = ar1; ar2 = ar1;
ar1 = ar0; ar1 = ar0;
@ -202,7 +196,7 @@ void FFT(int NumSamples,
ai2 = ai1; ai2 = ai1;
ai1 = ai0; ai1 = ai0;
k = j + BlockEnd; size_t k = j + BlockEnd;
tr = ar0 * RealOut[k] - ai0 * ImagOut[k]; tr = ar0 * RealOut[k] - ai0 * ImagOut[k];
ti = ar0 * ImagOut[k] + ai0 * RealOut[k]; ti = ar0 * ImagOut[k] + ai0 * RealOut[k];
@ -224,7 +218,7 @@ void FFT(int NumSamples,
if (InverseTransform) { if (InverseTransform) {
float denom = (float) NumSamples; float denom = (float) NumSamples;
for (i = 0; i < NumSamples; i++) { for (size_t i = 0; i < NumSamples; i++) {
RealOut[i] /= denom; RealOut[i] /= denom;
ImagOut[i] /= denom; ImagOut[i] /= denom;
} }
@ -237,9 +231,9 @@ void FFT(int NumSamples,
* This is merely a wrapper of RealFFTf() from RealFFTf.h. * This is merely a wrapper of RealFFTf() from RealFFTf.h.
*/ */
void RealFFT(int NumSamples, const float *RealIn, float *RealOut, float *ImagOut) void RealFFT(size_t NumSamples, const float *RealIn, float *RealOut, float *ImagOut)
{ {
int i; size_t i;
HFFT hFFT = GetFFT(NumSamples); HFFT hFFT = GetFFT(NumSamples);
float *pFFT = new float[NumSamples]; float *pFFT = new float[NumSamples];
// Copy the data into the processing buffer // Copy the data into the processing buffer
@ -278,10 +272,10 @@ void RealFFT(int NumSamples, const float *RealIn, float *RealOut, float *ImagOut
* *
* This is merely a wrapper of InverseRealFFTf() from RealFFTf.h. * This is merely a wrapper of InverseRealFFTf() from RealFFTf.h.
*/ */
void InverseRealFFT(int NumSamples, const float *RealIn, const float *ImagIn, void InverseRealFFT(size_t NumSamples, const float *RealIn, const float *ImagIn,
float *RealOut) float *RealOut)
{ {
int i; size_t i;
HFFT hFFT = GetFFT(NumSamples); HFFT hFFT = GetFFT(NumSamples);
float *pFFT = new float[NumSamples]; float *pFFT = new float[NumSamples];
// Copy the data into the processing buffer // Copy the data into the processing buffer
@ -318,9 +312,9 @@ void InverseRealFFT(int NumSamples, const float *RealIn, const float *ImagIn,
* of its code. * of its code.
*/ */
void PowerSpectrum(int NumSamples, const float *In, float *Out) void PowerSpectrum(size_t NumSamples, const float *In, float *Out)
{ {
int i; size_t i;
HFFT hFFT = GetFFT(NumSamples); HFFT hFFT = GetFFT(NumSamples);
float *pFFT = new float[NumSamples]; float *pFFT = new float[NumSamples];
// Copy the data into the processing buffer // Copy the data into the processing buffer
@ -378,10 +372,13 @@ const wxChar *WindowFuncName(int whichFunction)
} }
} }
void NewWindowFunc(int whichFunction, int NumSamples, bool extraSample, float *in) void NewWindowFunc(int whichFunction, size_t NumSamples, bool extraSample, float *in)
{ {
if (extraSample) if (extraSample) {
wxASSERT(NumSamples > 0);
--NumSamples; --NumSamples;
}
wxASSERT(NumSamples > 0);
switch (whichFunction) { switch (whichFunction) {
default: default:
@ -519,7 +516,7 @@ void NewWindowFunc(int whichFunction, int NumSamples, bool extraSample, float *i
} }
// See cautions in FFT.h ! // See cautions in FFT.h !
void WindowFunc(int whichFunction, int NumSamples, float *in) void WindowFunc(int whichFunction, size_t NumSamples, float *in)
{ {
bool extraSample = false; bool extraSample = false;
switch (whichFunction) switch (whichFunction)
@ -542,12 +539,13 @@ void WindowFunc(int whichFunction, int NumSamples, float *in)
NewWindowFunc(whichFunction, NumSamples, extraSample, in); NewWindowFunc(whichFunction, NumSamples, extraSample, in);
} }
void DerivativeOfWindowFunc(int whichFunction, int NumSamples, bool extraSample, float *in) void DerivativeOfWindowFunc(int whichFunction, size_t NumSamples, bool extraSample, float *in)
{ {
if (eWinFuncRectangular == whichFunction) if (eWinFuncRectangular == whichFunction)
{ {
// Rectangular // Rectangular
// There are deltas at the ends // There are deltas at the ends
wxASSERT(NumSamples > 0);
--NumSamples; --NumSamples;
// in[0] *= 1.0f; // in[0] *= 1.0f;
for (int ii = 1; ii < NumSamples; ++ii) for (int ii = 1; ii < NumSamples; ++ii)
@ -556,8 +554,12 @@ void DerivativeOfWindowFunc(int whichFunction, int NumSamples, bool extraSample,
return; return;
} }
if (extraSample) if (extraSample) {
wxASSERT(NumSamples > 0);
--NumSamples; --NumSamples;
}
wxASSERT(NumSamples > 0);
double A; double A;
switch (whichFunction) { switch (whichFunction) {

View File

@ -61,7 +61,7 @@
* input array, and that NumSamples must be a power of two. * input array, and that NumSamples must be a power of two.
*/ */
void PowerSpectrum(int NumSamples, const float *In, float *Out); void PowerSpectrum(size_t NumSamples, const float *In, float *Out);
/* /*
* Computes an FFT when the input data is real but you still * Computes an FFT when the input data is real but you still
@ -70,7 +70,7 @@ void PowerSpectrum(int NumSamples, const float *In, float *Out);
* NumSamples must be a power of two. * NumSamples must be a power of two.
*/ */
void RealFFT(int NumSamples, void RealFFT(size_t NumSamples,
const float *RealIn, float *RealOut, float *ImagOut); const float *RealIn, float *RealOut, float *ImagOut);
/* /*
@ -78,7 +78,7 @@ void RealFFT(int NumSamples,
* so the output is purely real. NumSamples must be a power of * so the output is purely real. NumSamples must be a power of
* two. * two.
*/ */
void InverseRealFFT(int NumSamples, void InverseRealFFT(size_t NumSamples,
const float *RealIn, const float *ImagIn, float *RealOut); const float *RealIn, const float *ImagIn, float *RealOut);
/* /*
@ -87,7 +87,7 @@ void InverseRealFFT(int NumSamples,
* inverse transform as well. * inverse transform as well.
*/ */
void FFT(int NumSamples, void FFT(size_t NumSamples,
bool InverseTransform, bool InverseTransform,
const float *RealIn, const float *ImagIn, float *RealOut, float *ImagOut); const float *RealIn, const float *ImagIn, float *RealOut, float *ImagOut);
@ -115,7 +115,7 @@ enum eWindowFunctions
eWinFuncCount eWinFuncCount
}; };
void WindowFunc(int whichFunction, int NumSamples, float *data); void WindowFunc(int whichFunction, size_t NumSamples, float *data);
/* /*
* Multiply values in data by values of the chosen function * Multiply values in data by values of the chosen function
@ -123,7 +123,7 @@ void WindowFunc(int whichFunction, int NumSamples, float *data);
* otherwise about (NumSamples - 1) / 2 * otherwise about (NumSamples - 1) / 2
* All functions have 0 in data[0] except Rectangular, Hamming and Gaussians * All functions have 0 in data[0] except Rectangular, Hamming and Gaussians
*/ */
void NewWindowFunc(int whichFunction, int NumSamples, bool extraSample, float *data); void NewWindowFunc(int whichFunction, size_t NumSamples, bool extraSample, float *data);
/* /*
* Multiply values in data by derivative of the chosen function, assuming * Multiply values in data by derivative of the chosen function, assuming
@ -132,7 +132,7 @@ void NewWindowFunc(int whichFunction, int NumSamples, bool extraSample, float *d
* otherwise about (NumSamples - 1) / 2 * otherwise about (NumSamples - 1) / 2
* All functions have 0 in data[0] except Rectangular, Hamming and Gaussians * All functions have 0 in data[0] except Rectangular, Hamming and Gaussians
*/ */
void DerivativeOfWindowFunc(int whichFunction, int NumSamples, bool extraSample, float *data); void DerivativeOfWindowFunc(int whichFunction, size_t NumSamples, bool extraSample, float *data);
/* /*
* Returns the name of the windowing function (for UI display) * Returns the name of the windowing function (for UI display)

View File

@ -584,7 +584,7 @@ void FreqWindow::GetAudio()
auto start = track->TimeToLongSamples(p->mViewInfo.selectedRegion.t0()); auto start = track->TimeToLongSamples(p->mViewInfo.selectedRegion.t0());
float *buffer2 = new float[mDataLen]; float *buffer2 = new float[mDataLen];
track->Get((samplePtr)buffer2, floatSample, start, mDataLen); track->Get((samplePtr)buffer2, floatSample, start, mDataLen);
for (int i = 0; i < mDataLen; i++) for (size_t i = 0; i < mDataLen; i++)
mData[i] += buffer2[i]; mData[i] += buffer2[i];
delete[] buffer2; delete[] buffer2;
} }
@ -1169,8 +1169,8 @@ void FreqGauge::Reset()
} }
bool SpectrumAnalyst::Calculate(Algorithm alg, int windowFunc, bool SpectrumAnalyst::Calculate(Algorithm alg, int windowFunc,
int windowSize, double rate, size_t windowSize, double rate,
const float *data, int dataLen, const float *data, size_t dataLen,
float *pYMin, float *pYMax, float *pYMin, float *pYMax,
FreqGauge *progress) FreqGauge *progress)
{ {
@ -1198,7 +1198,7 @@ bool SpectrumAnalyst::Calculate(Algorithm alg, int windowFunc,
mWindowSize = windowSize; mWindowSize = windowSize;
mAlg = alg; mAlg = alg;
int half = mWindowSize / 2; auto half = mWindowSize / 2;
mProcessed.resize(mWindowSize); mProcessed.resize(mWindowSize);
float *in = new float[mWindowSize]; float *in = new float[mWindowSize];
@ -1206,7 +1206,7 @@ bool SpectrumAnalyst::Calculate(Algorithm alg, int windowFunc,
float *out2 = new float[mWindowSize]; float *out2 = new float[mWindowSize];
float *win = new float[mWindowSize]; float *win = new float[mWindowSize];
for (int i = 0; i < mWindowSize; i++) { for (size_t i = 0; i < mWindowSize; i++) {
mProcessed[i] = 0.0f; mProcessed[i] = 0.0f;
win[i] = 1.0f; win[i] = 1.0f;
} }
@ -1216,7 +1216,7 @@ bool SpectrumAnalyst::Calculate(Algorithm alg, int windowFunc,
// Scale window such that an amplitude of 1.0 in the time domain // Scale window such that an amplitude of 1.0 in the time domain
// shows an amplitude of 0dB in the frequency domain // shows an amplitude of 0dB in the frequency domain
double wss = 0; double wss = 0;
for(int i=0; i<mWindowSize; i++) for(size_t i = 0; i < mWindowSize; i++)
wss += win[i]; wss += win[i];
if(wss > 0) if(wss > 0)
wss = 4.0 / (wss*wss); wss = 4.0 / (wss*wss);
@ -1227,17 +1227,17 @@ bool SpectrumAnalyst::Calculate(Algorithm alg, int windowFunc,
progress->SetRange(dataLen); progress->SetRange(dataLen);
} }
int start = 0; size_t start = 0;
int windows = 0; int windows = 0;
while (start + mWindowSize <= dataLen) { while (start + mWindowSize <= dataLen) {
for (int i = 0; i < mWindowSize; i++) for (size_t i = 0; i < mWindowSize; i++)
in[i] = win[i] * data[start + i]; in[i] = win[i] * data[start + i];
switch (alg) { switch (alg) {
case Spectrum: case Spectrum:
PowerSpectrum(mWindowSize, in, out); PowerSpectrum(mWindowSize, in, out);
for (int i = 0; i < half; i++) for (size_t i = 0; i < half; i++)
mProcessed[i] += out[i]; mProcessed[i] += out[i];
break; break;
@ -1248,11 +1248,11 @@ bool SpectrumAnalyst::Calculate(Algorithm alg, int windowFunc,
// Take FFT // Take FFT
RealFFT(mWindowSize, in, out, out2); RealFFT(mWindowSize, in, out, out2);
// Compute power // Compute power
for (int i = 0; i < mWindowSize; i++) for (size_t i = 0; i < mWindowSize; i++)
in[i] = (out[i] * out[i]) + (out2[i] * out2[i]); in[i] = (out[i] * out[i]) + (out2[i] * out2[i]);
if (alg == Autocorrelation) { if (alg == Autocorrelation) {
for (int i = 0; i < mWindowSize; i++) for (size_t i = 0; i < mWindowSize; i++)
in[i] = sqrt(in[i]); in[i] = sqrt(in[i]);
} }
if (alg == CubeRootAutocorrelation || if (alg == CubeRootAutocorrelation ||
@ -1260,14 +1260,14 @@ bool SpectrumAnalyst::Calculate(Algorithm alg, int windowFunc,
// Tolonen and Karjalainen recommend taking the cube root // Tolonen and Karjalainen recommend taking the cube root
// of the power, instead of the square root // of the power, instead of the square root
for (int i = 0; i < mWindowSize; i++) for (size_t i = 0; i < mWindowSize; i++)
in[i] = pow(in[i], 1.0f / 3.0f); in[i] = pow(in[i], 1.0f / 3.0f);
} }
// Take FFT // Take FFT
RealFFT(mWindowSize, in, out, out2); RealFFT(mWindowSize, in, out, out2);
// Take real part of result // Take real part of result
for (int i = 0; i < half; i++) for (size_t i = 0; i < half; i++)
mProcessed[i] += out[i]; mProcessed[i] += out[i];
break; break;
@ -1278,7 +1278,7 @@ bool SpectrumAnalyst::Calculate(Algorithm alg, int windowFunc,
{ {
float power; float power;
float minpower = 1e-20*mWindowSize*mWindowSize; float minpower = 1e-20*mWindowSize*mWindowSize;
for (int i = 0; i < mWindowSize; i++) for (size_t i = 0; i < mWindowSize; i++)
{ {
power = (out[i] * out[i]) + (out2[i] * out2[i]); power = (out[i] * out[i]) + (out2[i] * out2[i]);
if(power < minpower) if(power < minpower)
@ -1290,7 +1290,7 @@ bool SpectrumAnalyst::Calculate(Algorithm alg, int windowFunc,
InverseRealFFT(mWindowSize, in, NULL, out); InverseRealFFT(mWindowSize, in, NULL, out);
// Take real part of result // Take real part of result
for (int i = 0; i < half; i++) for (size_t i = 0; i < half; i++)
mProcessed[i] += out[i]; mProcessed[i] += out[i];
} }
@ -1323,7 +1323,7 @@ bool SpectrumAnalyst::Calculate(Algorithm alg, int windowFunc,
mYMin = 1000000.; mYMin = 1000000.;
mYMax = -1000000.; mYMax = -1000000.;
scale = wss / (double)windows; scale = wss / (double)windows;
for (int i = 0; i < half; i++) for (size_t i = 0; i < half; i++)
{ {
mProcessed[i] = 10 * log10(mProcessed[i] * scale); mProcessed[i] = 10 * log10(mProcessed[i] * scale);
if(mProcessed[i] > mYMax) if(mProcessed[i] > mYMax)
@ -1335,13 +1335,13 @@ bool SpectrumAnalyst::Calculate(Algorithm alg, int windowFunc,
case Autocorrelation: case Autocorrelation:
case CubeRootAutocorrelation: case CubeRootAutocorrelation:
for (int i = 0; i < half; i++) for (size_t i = 0; i < half; i++)
mProcessed[i] = mProcessed[i] / windows; mProcessed[i] = mProcessed[i] / windows;
// Find min/max // Find min/max
mYMin = mProcessed[0]; mYMin = mProcessed[0];
mYMax = mProcessed[0]; mYMax = mProcessed[0];
for (int i = 1; i < half; i++) for (size_t i = 1; i < half; i++)
if (mProcessed[i] > mYMax) if (mProcessed[i] > mYMax)
mYMax = mProcessed[i]; mYMax = mProcessed[i];
else if (mProcessed[i] < mYMin) else if (mProcessed[i] < mYMin)
@ -1349,13 +1349,13 @@ bool SpectrumAnalyst::Calculate(Algorithm alg, int windowFunc,
break; break;
case EnhancedAutocorrelation: case EnhancedAutocorrelation:
for (int i = 0; i < half; i++) for (size_t i = 0; i < half; i++)
mProcessed[i] = mProcessed[i] / windows; mProcessed[i] = mProcessed[i] / windows;
// Peak Pruning as described by Tolonen and Karjalainen, 2000 // Peak Pruning as described by Tolonen and Karjalainen, 2000
// Clip at zero, copy to temp array // Clip at zero, copy to temp array
for (int i = 0; i < half; i++) { for (size_t i = 0; i < half; i++) {
if (mProcessed[i] < 0.0) if (mProcessed[i] < 0.0)
mProcessed[i] = float(0.0); mProcessed[i] = float(0.0);
out[i] = mProcessed[i]; out[i] = mProcessed[i];
@ -1363,21 +1363,21 @@ bool SpectrumAnalyst::Calculate(Algorithm alg, int windowFunc,
// Subtract a time-doubled signal (linearly interp.) from the original // Subtract a time-doubled signal (linearly interp.) from the original
// (clipped) signal // (clipped) signal
for (int i = 0; i < half; i++) for (size_t i = 0; i < half; i++)
if ((i % 2) == 0) if ((i % 2) == 0)
mProcessed[i] -= out[i / 2]; mProcessed[i] -= out[i / 2];
else else
mProcessed[i] -= ((out[i / 2] + out[i / 2 + 1]) / 2); mProcessed[i] -= ((out[i / 2] + out[i / 2 + 1]) / 2);
// Clip at zero again // Clip at zero again
for (int i = 0; i < half; i++) for (size_t i = 0; i < half; i++)
if (mProcessed[i] < 0.0) if (mProcessed[i] < 0.0)
mProcessed[i] = float(0.0); mProcessed[i] = float(0.0);
// Find NEW min/max // Find NEW min/max
mYMin = mProcessed[0]; mYMin = mProcessed[0];
mYMax = mProcessed[0]; mYMax = mProcessed[0];
for (int i = 1; i < half; i++) for (size_t i = 1; i < half; i++)
if (mProcessed[i] > mYMax) if (mProcessed[i] > mYMax)
mYMax = mProcessed[i]; mYMax = mProcessed[i];
else if (mProcessed[i] < mYMin) else if (mProcessed[i] < mYMin)
@ -1385,15 +1385,15 @@ bool SpectrumAnalyst::Calculate(Algorithm alg, int windowFunc,
break; break;
case Cepstrum: case Cepstrum:
for (int i = 0; i < half; i++) for (size_t i = 0; i < half; i++)
mProcessed[i] = mProcessed[i] / windows; mProcessed[i] = mProcessed[i] / windows;
// Find min/max, ignoring first and last few values // Find min/max, ignoring first and last few values
{ {
int ignore = 4; size_t ignore = 4;
mYMin = mProcessed[ignore]; mYMin = mProcessed[ignore];
mYMax = mProcessed[ignore]; mYMax = mProcessed[ignore];
for (int i = ignore + 1; i < half - ignore; i++) for (size_t i = ignore + 1; i + ignore < half; i++)
if (mProcessed[i] > mYMax) if (mProcessed[i] > mYMax)
mYMax = mProcessed[i]; mYMax = mProcessed[i];
else if (mProcessed[i] < mYMin) else if (mProcessed[i] < mYMin)

View File

@ -62,8 +62,8 @@ public:
// Return true iff successful // Return true iff successful
bool Calculate(Algorithm alg, bool Calculate(Algorithm alg,
int windowFunc, // see FFT.h for values int windowFunc, // see FFT.h for values
int windowSize, double rate, size_t windowSize, double rate,
const float *data, int dataLen, const float *data, size_t dataLen,
float *pYMin = NULL, float *pYMax = NULL, // outputs float *pYMin = NULL, float *pYMax = NULL, // outputs
FreqGauge *progress = NULL); FreqGauge *progress = NULL);
@ -80,7 +80,7 @@ private:
private: private:
Algorithm mAlg; Algorithm mAlg;
double mRate; double mRate;
int mWindowSize; size_t mWindowSize;
std::vector<float> mProcessed; std::vector<float> mProcessed;
}; };
@ -199,9 +199,9 @@ private:
double mRate; double mRate;
int mDataLen; size_t mDataLen;
float *mData; float *mData;
int mWindowSize; size_t mWindowSize;
bool mLogAxis; bool mLogAxis;
float mYMin; float mYMin;

View File

@ -54,11 +54,9 @@
* Initialize the Sine table and Twiddle pointers (bit-reversed pointers) * Initialize the Sine table and Twiddle pointers (bit-reversed pointers)
* for the FFT routine. * for the FFT routine.
*/ */
HFFT InitializeFFT(int fftlen) HFFT InitializeFFT(size_t fftlen)
{ {
int i;
int temp; int temp;
int mask;
HFFT h; HFFT h;
if((h=(HFFT)malloc(sizeof(FFTParam)))==NULL) if((h=(HFFT)malloc(sizeof(FFTParam)))==NULL)
@ -85,16 +83,16 @@ HFFT InitializeFFT(int fftlen)
exit(8); exit(8);
} }
for(i=0;i<h->Points;i++) for(size_t i = 0; i < h->Points; i++)
{ {
temp = 0; temp = 0;
for(mask=h->Points/2;mask>0;mask >>= 1) for(size_t mask = h->Points / 2; mask > 0; mask >>= 1)
temp = (temp >> 1) + (i & mask ? h->Points : 0); temp = (temp >> 1) + (i & mask ? h->Points : 0);
h->BitReversed[i] = temp; h->BitReversed[i] = temp;
} }
for(i=0;i<h->Points;i++) for(size_t i = 0; i < h->Points; i++)
{ {
h->SinTable[h->BitReversed[i] ]=(fft_type)-sin(2*M_PI*i/(2*h->Points)); h->SinTable[h->BitReversed[i] ]=(fft_type)-sin(2*M_PI*i/(2*h->Points));
h->SinTable[h->BitReversed[i]+1]=(fft_type)-cos(2*M_PI*i/(2*h->Points)); h->SinTable[h->BitReversed[i]+1]=(fft_type)-cos(2*M_PI*i/(2*h->Points));
@ -102,7 +100,7 @@ HFFT InitializeFFT(int fftlen)
#ifdef EXPERIMENTAL_EQ_SSE_THREADED #ifdef EXPERIMENTAL_EQ_SSE_THREADED
// NEW SSE FFT routines work on live data // NEW SSE FFT routines work on live data
for(i=0;i<32;i++) for(size_t i = 0; i < 32; i++)
if((1 << i) & fftlen) if((1 << i) & fftlen)
h->pow2Bits = i; h->pow2Bits = i;
#endif #endif
@ -123,16 +121,20 @@ void EndFFT(HFFT h)
free(h); free(h);
} }
#define MAX_HFFT 10 enum : size_t { MAX_HFFT = 10 };
static HFFT hFFTArray[MAX_HFFT] = { NULL }; static HFFT hFFTArray[MAX_HFFT] = { NULL };
static int nFFTLockCount[MAX_HFFT] = { 0 }; static int nFFTLockCount[MAX_HFFT] = { 0 };
/* Get a handle to the FFT tables of the desired length */ /* Get a handle to the FFT tables of the desired length */
/* This version keeps common tables rather than allocating a NEW table every time */ /* This version keeps common tables rather than allocating a NEW table every time */
HFFT GetFFT(int fftlen) HFFT GetFFT(size_t fftlen)
{ {
int h,n = fftlen/2; size_t h = 0;
for(h=0; (h<MAX_HFFT) && (hFFTArray[h] != NULL) && (n != hFFTArray[h]->Points); h++); auto n = fftlen/2;
for(;
(h < MAX_HFFT) && (hFFTArray[h] != NULL) && (n != hFFTArray[h]->Points);
h++)
;
if(h < MAX_HFFT) { if(h < MAX_HFFT) {
if(hFFTArray[h] == NULL) { if(hFFTArray[h] == NULL) {
hFFTArray[h] = InitializeFFT(fftlen); hFFTArray[h] = InitializeFFT(fftlen);
@ -142,7 +144,7 @@ HFFT GetFFT(int fftlen)
return hFFTArray[h]; return hFFTArray[h];
} else { } else {
// All buffers used, so fall back to allocating a NEW set of tables // All buffers used, so fall back to allocating a NEW set of tables
return InitializeFFT(fftlen);; return InitializeFFT(fftlen);
} }
} }
@ -197,7 +199,7 @@ void RealFFTf(fft_type *buffer,HFFT h)
fft_type HRplus,HRminus,HIplus,HIminus; fft_type HRplus,HRminus,HIplus,HIminus;
fft_type v1,v2,sin,cos; fft_type v1,v2,sin,cos;
int ButterfliesPerGroup=h->Points/2; auto ButterfliesPerGroup = h->Points/2;
/* /*
* Butterfly: * Butterfly:
@ -299,7 +301,7 @@ void InverseRealFFTf(fft_type *buffer,HFFT h)
fft_type HRplus,HRminus,HIplus,HIminus; fft_type HRplus,HRminus,HIplus,HIminus;
fft_type v1,v2,sin,cos; fft_type v1,v2,sin,cos;
int ButterfliesPerGroup=h->Points/2; auto ButterfliesPerGroup = h->Points / 2;
/* Massage input to get the input for a real output sequence. */ /* Massage input to get the input for a real output sequence. */
A = buffer + 2; A = buffer + 2;
@ -377,7 +379,7 @@ void ReorderToFreq(HFFT hFFT, const fft_type *buffer,
fft_type *RealOut, fft_type *ImagOut) fft_type *RealOut, fft_type *ImagOut)
{ {
// Copy the data into the real and imaginary outputs // Copy the data into the real and imaginary outputs
for(int i=1;i<hFFT->Points;i++) { for(size_t i = 1; i < hFFT->Points; i++) {
RealOut[i] = buffer[hFFT->BitReversed[i] ]; RealOut[i] = buffer[hFFT->BitReversed[i] ];
ImagOut[i] = buffer[hFFT->BitReversed[i]+1]; ImagOut[i] = buffer[hFFT->BitReversed[i]+1];
} }
@ -390,7 +392,7 @@ void ReorderToFreq(HFFT hFFT, const fft_type *buffer,
void ReorderToTime(HFFT hFFT, const fft_type *buffer, fft_type *TimeOut) void ReorderToTime(HFFT hFFT, const fft_type *buffer, fft_type *TimeOut)
{ {
// Copy the data into the real outputs // Copy the data into the real outputs
for(int i=0;i<hFFT->Points;i++) { for(size_t i = 0; i < hFFT->Points; i++) {
TimeOut[i*2 ]=buffer[hFFT->BitReversed[i] ]; TimeOut[i*2 ]=buffer[hFFT->BitReversed[i] ];
TimeOut[i*2+1]=buffer[hFFT->BitReversed[i]+1]; TimeOut[i*2+1]=buffer[hFFT->BitReversed[i]+1];
} }

View File

@ -7,16 +7,16 @@
struct FFTParam { struct FFTParam {
int *BitReversed; int *BitReversed;
fft_type *SinTable; fft_type *SinTable;
int Points; size_t Points;
#ifdef EXPERIMENTAL_EQ_SSE_THREADED #ifdef EXPERIMENTAL_EQ_SSE_THREADED
int pow2Bits; int pow2Bits;
#endif #endif
}; };
typedef FFTParam * HFFT; typedef FFTParam * HFFT;
HFFT InitializeFFT(int); HFFT InitializeFFT(size_t);
void EndFFT(HFFT); void EndFFT(HFFT);
HFFT GetFFT(int); HFFT GetFFT(size_t);
void ReleaseFFT(HFFT); void ReleaseFFT(HFFT);
void CleanupFFT(); void CleanupFFT();
void RealFFTf(fft_type *,HFFT); void RealFFTf(fft_type *,HFFT);

View File

@ -343,7 +343,7 @@ void RealFFTf1xSinCosBRTable(fft_type *buffer,HFFT h)
fft_type HRplus,HRminus,HIplus,HIminus; fft_type HRplus,HRminus,HIplus,HIminus;
fft_type v1,v2,sin,cos; fft_type v1,v2,sin,cos;
int ButterfliesPerGroup=h->Points/2; auto ButterfliesPerGroup = h->Points / 2;
/* /*
* Butterfly: * Butterfly:
@ -445,7 +445,7 @@ void InverseRealFFTf1xSinCosBRTable(fft_type *buffer,HFFT h)
fft_type HRplus,HRminus,HIplus,HIminus; fft_type HRplus,HRminus,HIplus,HIminus;
fft_type v1,v2,sin,cos; fft_type v1,v2,sin,cos;
int ButterfliesPerGroup=h->Points/2; auto ButterfliesPerGroup = h->Points / 2;
/* Massage input to get the input for a real output sequence. */ /* Massage input to get the input for a real output sequence. */
A = buffer + 2; A = buffer + 2;
@ -522,7 +522,7 @@ void InverseRealFFTf1xSinCosBRTable(fft_type *buffer,HFFT h)
void ReorderToFreq1xSinCosBRTable(HFFT hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut) void ReorderToFreq1xSinCosBRTable(HFFT hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut)
{ {
// Copy the data into the real and imaginary outputs // Copy the data into the real and imaginary outputs
for(int i=1;i<hFFT->Points;i++) { for(size_t i = 1; i < hFFT->Points; i++) {
RealOut[i]=buffer[hFFT->BitReversed[i] ]; RealOut[i]=buffer[hFFT->BitReversed[i] ];
ImagOut[i]=buffer[hFFT->BitReversed[i]+1]; ImagOut[i]=buffer[hFFT->BitReversed[i]+1];
} }
@ -535,7 +535,7 @@ void ReorderToFreq1xSinCosBRTable(HFFT hFFT, fft_type *buffer, fft_type *RealOut
void ReorderToTime1xSinCosBRTable(HFFT hFFT, fft_type *buffer, fft_type *TimeOut) void ReorderToTime1xSinCosBRTable(HFFT hFFT, fft_type *buffer, fft_type *TimeOut)
{ {
// Copy the data into the real outputs // Copy the data into the real outputs
for(int i=0;i<hFFT->Points;i++) { for(size_t i = 0; i < hFFT->Points; i++) {
TimeOut[i*2 ]=buffer[hFFT->BitReversed[i] ]; TimeOut[i*2 ]=buffer[hFFT->BitReversed[i] ];
TimeOut[i*2+1]=buffer[hFFT->BitReversed[i]+1]; TimeOut[i*2+1]=buffer[hFFT->BitReversed[i]+1];
} }
@ -554,7 +554,7 @@ void RealFFTf4xSinCosBRTable(fft_type *buffer,HFFT h)
int br1Value, br2Value; int br1Value, br2Value;
__m128 HRplus,HRminus,HIplus,HIminus; __m128 HRplus,HRminus,HIplus,HIminus;
__m128 v1,v2,sin,cos; __m128 v1,v2,sin,cos;
int ButterfliesPerGroup=h->Points/2; auto ButterfliesPerGroup = h->Points / 2;
/* /*
* Butterfly: * Butterfly:
@ -660,7 +660,7 @@ void InverseRealFFTf4xSinCosBRTable(fft_type *buffer,HFFT h)
__m128 HRplus,HRminus,HIplus,HIminus; __m128 HRplus,HRminus,HIplus,HIminus;
__m128 v1,v2,sin,cos; __m128 v1,v2,sin,cos;
int ButterfliesPerGroup=h->Points/2; auto ButterfliesPerGroup = h->Points / 2;
/* Massage input to get the input for a real output sequence. */ /* Massage input to get the input for a real output sequence. */
A = localBuffer + 2; A = localBuffer + 2;
@ -745,7 +745,7 @@ void ReorderToFreq4xSinCosBRTable(HFFT hFFT, fft_type *buffer, fft_type *RealOut
__m128 *localImagOut=(__m128 *)ImagOut; __m128 *localImagOut=(__m128 *)ImagOut;
// Copy the data into the real and imaginary outputs // Copy the data into the real and imaginary outputs
for(int i=1;i<hFFT->Points;i++) { for(size_t i = 1; i < hFFT->Points; i++) {
int brValue; int brValue;
brValue=hFFT->BitReversed[i]; brValue=hFFT->BitReversed[i];
localRealOut[i]=localBuffer[brValue ]; localRealOut[i]=localBuffer[brValue ];
@ -762,7 +762,7 @@ void ReorderToTime4xSinCosBRTable(HFFT hFFT, fft_type *buffer, fft_type *TimeOut
__m128 *localBuffer=(__m128 *)buffer; __m128 *localBuffer=(__m128 *)buffer;
__m128 *localTimeOut=(__m128 *)TimeOut; __m128 *localTimeOut=(__m128 *)TimeOut;
// Copy the data into the real outputs // Copy the data into the real outputs
for(int i=0;i<hFFT->Points;i++) { for(size_t i = 0; i < hFFT->Points; i++) {
int brValue; int brValue;
brValue = hFFT->BitReversed[i]; brValue = hFFT->BitReversed[i];
localTimeOut[i*2 ] = localBuffer[brValue ]; localTimeOut[i*2 ] = localBuffer[brValue ];
@ -801,7 +801,7 @@ void RealFFTf1xSinCosTableVBR16(fft_type *buffer,HFFT h)
int br1Value, br2Value; int br1Value, br2Value;
fft_type HRplus,HRminus,HIplus,HIminus; fft_type HRplus,HRminus,HIplus,HIminus;
fft_type v1,v2,sin,cos; fft_type v1,v2,sin,cos;
int ButterfliesPerGroup=h->Points/2; auto ButterfliesPerGroup = h->Points / 2;
int pow2BitsMinus1 = h->pow2Bits - 1; int pow2BitsMinus1 = h->pow2Bits - 1;
int sinCosShift = (sSinCosTable.mSinCosTablePow - pow2BitsMinus1); int sinCosShift = (sSinCosTable.mSinCosTablePow - pow2BitsMinus1);
@ -899,7 +899,7 @@ void InverseRealFFTf1xSinCosTableVBR16(fft_type *buffer,HFFT h)
int *br1; int *br1;
fft_type HRplus,HRminus,HIplus,HIminus; fft_type HRplus,HRminus,HIplus,HIminus;
fft_type v1,v2,sin,cos; fft_type v1,v2,sin,cos;
int ButterfliesPerGroup=h->Points/2; auto ButterfliesPerGroup = h->Points / 2;
int pow2BitsMinus1 = h->pow2Bits - 1; int pow2BitsMinus1 = h->pow2Bits - 1;
int sinCosShift = (sSinCosTable.mSinCosTablePow - pow2BitsMinus1); int sinCosShift = (sSinCosTable.mSinCosTablePow - pow2BitsMinus1);
@ -982,7 +982,7 @@ void InverseRealFFTf1xSinCosTableVBR16(fft_type *buffer,HFFT h)
void ReorderToTime1xSinCosTableVBR16(HFFT hFFT, fft_type *buffer, fft_type *TimeOut) void ReorderToTime1xSinCosTableVBR16(HFFT hFFT, fft_type *buffer, fft_type *TimeOut)
{ {
// Copy the data into the real outputs // Copy the data into the real outputs
for(int i=0;i<hFFT->Points;i++) { for(size_t i = 0;i < hFFT->Points; i++) {
int brValue; int brValue;
brValue=(*SmallVRB[hFFT->pow2Bits])(i); brValue=(*SmallVRB[hFFT->pow2Bits])(i);
TimeOut[i*2 ] = buffer[brValue ]; TimeOut[i*2 ] = buffer[brValue ];
@ -993,7 +993,7 @@ void ReorderToTime1xSinCosTableVBR16(HFFT hFFT, fft_type *buffer, fft_type *Time
void ReorderToFreq1xSinCosTableVBR16(HFFT hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut) void ReorderToFreq1xSinCosTableVBR16(HFFT hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut)
{ {
// Copy the data into the real and imaginary outputs // Copy the data into the real and imaginary outputs
for(int i=1;i<hFFT->Points;i++) { for(size_t i = 1; i < hFFT->Points; i++) {
int brValue; int brValue;
brValue = (*SmallVRB[hFFT->pow2Bits])(i); brValue = (*SmallVRB[hFFT->pow2Bits])(i);
RealOut[i] = buffer[brValue ]; RealOut[i] = buffer[brValue ];
@ -1017,7 +1017,7 @@ void RealFFTf4xSinCosTableVBR16(fft_type *buffer,HFFT h)
int br1Value, br2Value; int br1Value, br2Value;
__m128 HRplus,HRminus,HIplus,HIminus; __m128 HRplus,HRminus,HIplus,HIminus;
__m128 v1,v2,sin,cos; __m128 v1,v2,sin,cos;
int ButterfliesPerGroup=h->Points/2; auto ButterfliesPerGroup = h->Points / 2;
int pow2BitsMinus1 = h->pow2Bits - 1; int pow2BitsMinus1 = h->pow2Bits - 1;
int sinCosShift = (sSinCosTable.mSinCosTablePow - pow2BitsMinus1); int sinCosShift = (sSinCosTable.mSinCosTablePow - pow2BitsMinus1);
@ -1126,7 +1126,7 @@ void InverseRealFFTf4xSinCosTableVBR16(fft_type *buffer,HFFT h)
int br1Index, br1Value; int br1Index, br1Value;
__m128 HRplus, HRminus, HIplus, HIminus; __m128 HRplus, HRminus, HIplus, HIminus;
__m128 v1, v2, sin, cos; __m128 v1, v2, sin, cos;
int ButterfliesPerGroup=h->Points/2; auto ButterfliesPerGroup = h->Points / 2;
int pow2BitsMinus1 = h->pow2Bits - 1; int pow2BitsMinus1 = h->pow2Bits - 1;
int sinCosShift = (sSinCosTable.mSinCosTablePow - pow2BitsMinus1); int sinCosShift = (sSinCosTable.mSinCosTablePow - pow2BitsMinus1);
@ -1214,7 +1214,7 @@ void ReorderToTime4xSinCosTableVBR16(HFFT hFFT, fft_type *buffer, fft_type *Time
__m128 *localBuffer = (__m128 *)buffer; __m128 *localBuffer = (__m128 *)buffer;
__m128 *localTimeOut = (__m128 *)TimeOut; __m128 *localTimeOut = (__m128 *)TimeOut;
// Copy the data into the real outputs // Copy the data into the real outputs
for(int i=0;i<hFFT->Points;i++) { for(size_t i = 0; i < hFFT->Points; i++) {
int brValue; int brValue;
brValue = (*SmallVRB[hFFT->pow2Bits])(i); brValue = (*SmallVRB[hFFT->pow2Bits])(i);
localTimeOut[i*2 ] = localBuffer[brValue ]; localTimeOut[i*2 ] = localBuffer[brValue ];
@ -1229,7 +1229,7 @@ void ReorderToFreq4xSinCosTableVBR16(HFFT hFFT, fft_type *buffer, fft_type *Real
__m128 *localImagOut = (__m128 *)ImagOut; __m128 *localImagOut = (__m128 *)ImagOut;
// Copy the data into the real and imaginary outputs // Copy the data into the real and imaginary outputs
for(int i=1;i<hFFT->Points;i++) { for(size_t i = 1; i < hFFT->Points; i++) {
int brValue; int brValue;
brValue = (*SmallVRB[hFFT->pow2Bits])(i); brValue = (*SmallVRB[hFFT->pow2Bits])(i);
localRealOut[i] = localBuffer[brValue ]; localRealOut[i] = localBuffer[brValue ];
@ -1271,7 +1271,7 @@ void RealFFTf1xSinCosTableBR16(fft_type *buffer,HFFT h)
int br1Value, br2Value; int br1Value, br2Value;
fft_type HRplus, HRminus, HIplus, HIminus; fft_type HRplus, HRminus, HIplus, HIminus;
fft_type v1, v2, sin, cos; fft_type v1, v2, sin, cos;
int ButterfliesPerGroup=h->Points/2; auto ButterfliesPerGroup = h->Points / 2;
int pow2BitsMinus1 = h->pow2Bits - 1; int pow2BitsMinus1 = h->pow2Bits - 1;
int bitReverseShiftM1 = 17 - h->pow2Bits; int bitReverseShiftM1 = 17 - h->pow2Bits;
int bitReverseShift = bitReverseShiftM1 - 1; int bitReverseShift = bitReverseShiftM1 - 1;
@ -1372,7 +1372,7 @@ void InverseRealFFTf1xSinCosTableBR16(fft_type *buffer,HFFT h)
int br1Index; int br1Index;
fft_type HRplus, HRminus, HIplus, HIminus; fft_type HRplus, HRminus, HIplus, HIminus;
fft_type v1, v2, sin, cos; fft_type v1, v2, sin, cos;
int ButterfliesPerGroup=h->Points/2; auto ButterfliesPerGroup = h->Points / 2;
int pow2BitsMinus1 = h->pow2Bits - 1; int pow2BitsMinus1 = h->pow2Bits - 1;
int sinCosShift = (sSinCosTable.mSinCosTablePow-pow2BitsMinus1); int sinCosShift = (sSinCosTable.mSinCosTablePow-pow2BitsMinus1);
int bitReverseShiftM1 = 17 - h->pow2Bits; int bitReverseShiftM1 = 17 - h->pow2Bits;
@ -1456,7 +1456,7 @@ void ReorderToFreq1xSinCosTableBR16(HFFT hFFT, fft_type *buffer, fft_type *RealO
{ {
int bitReverseShift=16-hFFT->pow2Bits; int bitReverseShift=16-hFFT->pow2Bits;
// Copy the data into the real and imaginary outputs // Copy the data into the real and imaginary outputs
for(int i=1;i<hFFT->Points;i++) { for(size_t i = 1; i < hFFT->Points; i++) {
int brValue; int brValue;
// brValue=(*SmallVRB[hFFT->pow2Bits])(i); // brValue=(*SmallVRB[hFFT->pow2Bits])(i);
brValue = ( ((sSmallRBTable[*((unsigned char *)&i)]<<8) + (sSmallRBTable[*(((unsigned char *)&i)+1)]) )>>bitReverseShift); brValue = ( ((sSmallRBTable[*((unsigned char *)&i)]<<8) + (sSmallRBTable[*(((unsigned char *)&i)+1)]) )>>bitReverseShift);
@ -1473,7 +1473,7 @@ void ReorderToTime1xSinCosTableBR16(HFFT hFFT, fft_type *buffer, fft_type *TimeO
{ {
int bitReverseShift=16-hFFT->pow2Bits; int bitReverseShift=16-hFFT->pow2Bits;
// Copy the data into the real outputs // Copy the data into the real outputs
for(int i=0;i<hFFT->Points;i++) { for(size_t i = 0; i < hFFT->Points; i++) {
int brValue; int brValue;
// brValue=(*SmallVRB[hFFT->pow2Bits])(i); // brValue=(*SmallVRB[hFFT->pow2Bits])(i);
brValue=( ((sSmallRBTable[*((unsigned char *)&i)]<<8) + (sSmallRBTable[*(((unsigned char *)&i)+1)]) )>>bitReverseShift); brValue=( ((sSmallRBTable[*((unsigned char *)&i)]<<8) + (sSmallRBTable[*(((unsigned char *)&i)+1)]) )>>bitReverseShift);
@ -1494,7 +1494,7 @@ void RealFFTf4xSinCosTableBR16(fft_type *buffer,HFFT h)
int br1Value, br2Value; int br1Value, br2Value;
__m128 HRplus, HRminus, HIplus, HIminus; __m128 HRplus, HRminus, HIplus, HIminus;
__m128 v1, v2, sin, cos; __m128 v1, v2, sin, cos;
int ButterfliesPerGroup=h->Points/2; auto ButterfliesPerGroup = h->Points / 2;
int pow2BitsMinus1 = h->pow2Bits - 1; int pow2BitsMinus1 = h->pow2Bits - 1;
int sinCosShift = (sSinCosTable.mSinCosTablePow-pow2BitsMinus1); int sinCosShift = (sSinCosTable.mSinCosTablePow-pow2BitsMinus1);
int bitReverseShiftM1 = 17 - h->pow2Bits; int bitReverseShiftM1 = 17 - h->pow2Bits;
@ -1607,7 +1607,7 @@ void InverseRealFFTf4xSinCosTableBR16(fft_type *buffer,HFFT h)
int br1Index; int br1Index;
__m128 HRplus, HRminus, HIplus, HIminus; __m128 HRplus, HRminus, HIplus, HIminus;
__m128 v1, v2, sin, cos; __m128 v1, v2, sin, cos;
int ButterfliesPerGroup=h->Points/2; auto ButterfliesPerGroup = h->Points / 2;
int pow2BitsMinus1 = h->pow2Bits - 1; int pow2BitsMinus1 = h->pow2Bits - 1;
int sinCosShift = (sSinCosTable.mSinCosTablePow-pow2BitsMinus1); int sinCosShift = (sSinCosTable.mSinCosTablePow-pow2BitsMinus1);
int bitReverseShiftM1 = 17 - h->pow2Bits; int bitReverseShiftM1 = 17 - h->pow2Bits;
@ -1698,7 +1698,7 @@ void ReorderToTime4xSinCosTableBR16(HFFT hFFT, fft_type *buffer, fft_type *TimeO
int bitReverseShift = 16 - hFFT->pow2Bits; int bitReverseShift = 16 - hFFT->pow2Bits;
// Copy the data into the real outputs // Copy the data into the real outputs
for(int i=0;i<hFFT->Points;i++) { for(size_t i = 0; i < hFFT->Points; i++) {
int brValue; int brValue;
brValue=( ((sSmallRBTable[*((unsigned char *)&i)]<<8) + (sSmallRBTable[*(((unsigned char *)&i)+1)]) )>>bitReverseShift); brValue=( ((sSmallRBTable[*((unsigned char *)&i)]<<8) + (sSmallRBTable[*(((unsigned char *)&i)+1)]) )>>bitReverseShift);
// brValue=(*SmallVRB[hFFT->pow2Bits])(i); // brValue=(*SmallVRB[hFFT->pow2Bits])(i);
@ -1715,7 +1715,7 @@ void ReorderToFreq4xSinCosTableBR16(HFFT hFFT, fft_type *buffer, fft_type *RealO
int bitReverseShift = 16 - hFFT->pow2Bits; int bitReverseShift = 16 - hFFT->pow2Bits;
// Copy the data into the real and imaginary outputs // Copy the data into the real and imaginary outputs
for(int i=1;i<hFFT->Points;i++) { for(size_t i = 1; i < hFFT->Points; i++) {
int brValue; int brValue;
brValue=( ((sSmallRBTable[*((unsigned char *)&i)]<<8) + (sSmallRBTable[*(((unsigned char *)&i)+1)]) )>>bitReverseShift); brValue=( ((sSmallRBTable[*((unsigned char *)&i)]<<8) + (sSmallRBTable[*(((unsigned char *)&i)+1)]) )>>bitReverseShift);
// brValue=(*SmallVRB[hFFT->pow2Bits])(i); // brValue=(*SmallVRB[hFFT->pow2Bits])(i);
@ -1761,7 +1761,7 @@ void RealFFTf1xFastMathBR24(fft_type *buffer,HFFT h)
fft_type iToRad = 2 * M_PI/(2 * h->Points); fft_type iToRad = 2 * M_PI/(2 * h->Points);
int bitReverseShift = 24 - h->pow2Bits; int bitReverseShift = 24 - h->pow2Bits;
int bitReverseShiftM1 = bitReverseShift + 1; int bitReverseShiftM1 = bitReverseShift + 1;
int ButterfliesPerGroup=h->Points/2; auto ButterfliesPerGroup = h->Points / 2;
/* /*
* Butterfly: * Butterfly:
@ -1907,7 +1907,7 @@ void InverseRealFFTf1xFastMathBR24(fft_type *buffer,HFFT h)
fft_type iToRad = 2 * M_PI / (2 * h->Points); fft_type iToRad = 2 * M_PI / (2 * h->Points);
int bitReverseShiftM1 = 25 - h->pow2Bits; int bitReverseShiftM1 = 25 - h->pow2Bits;
int ButterfliesPerGroup=h->Points/2; auto ButterfliesPerGroup = h->Points / 2;
/* Massage input to get the input for a real output sequence. */ /* Massage input to get the input for a real output sequence. */
A = buffer + 2; A = buffer + 2;
@ -2022,7 +2022,7 @@ void ReorderToFreq1xFastMathBR24(HFFT hFFT, fft_type *buffer, fft_type *RealOut,
{ {
int bitReverseShift = 24 - hFFT->pow2Bits; int bitReverseShift = 24 - hFFT->pow2Bits;
// Copy the data into the real and imaginary outputs // Copy the data into the real and imaginary outputs
for(int i=1;i<hFFT->Points;i++) { for(size_t i = 1; i < hFFT->Points; i++) {
int brValue; int brValue;
// brValue=(*SmallVRB[hFFT->pow2Bits])(i); // brValue=(*SmallVRB[hFFT->pow2Bits])(i);
brValue=( ((sSmallRBTable[*((unsigned char *)&i)]<<16) + (sSmallRBTable[*(((unsigned char *)&i)+1)]<<8) + sSmallRBTable[*(((unsigned char *)&i)+2)] )>>bitReverseShift); brValue=( ((sSmallRBTable[*((unsigned char *)&i)]<<16) + (sSmallRBTable[*(((unsigned char *)&i)+1)]<<8) + sSmallRBTable[*(((unsigned char *)&i)+2)] )>>bitReverseShift);
@ -2040,7 +2040,7 @@ void ReorderToTime1xFastMathBR24(HFFT hFFT, fft_type *buffer, fft_type *TimeOut)
{ {
int bitReverseShift = 24 - hFFT->pow2Bits; int bitReverseShift = 24 - hFFT->pow2Bits;
// Copy the data into the real outputs // Copy the data into the real outputs
for(int i=0;i<hFFT->Points;i++) { for(size_t i = 0; i < hFFT->Points; i++) {
int brValue; int brValue;
brValue=( ((sSmallRBTable[*((unsigned char *)&i)]<<16) + (sSmallRBTable[*(((unsigned char *)&i)+1)]<<8) + sSmallRBTable[*(((unsigned char *)&i)+2)] )>>bitReverseShift); brValue=( ((sSmallRBTable[*((unsigned char *)&i)]<<16) + (sSmallRBTable[*(((unsigned char *)&i)+1)]<<8) + sSmallRBTable[*(((unsigned char *)&i)+2)] )>>bitReverseShift);
// brValue=(*SmallVRB[hFFT->pow2Bits])(i); // brValue=(*SmallVRB[hFFT->pow2Bits])(i);
@ -2061,7 +2061,7 @@ void RealFFTf4xFastMathBR24(fft_type *buffer,HFFT h)
__m128 HRplus,HRminus,HIplus,HIminus; __m128 HRplus,HRminus,HIplus,HIminus;
__m128 v1,v2,sin,cos; __m128 v1,v2,sin,cos;
fft_type iToRad = 2 * M_PI/(2 * h->Points); fft_type iToRad = 2 * M_PI/(2 * h->Points);
int ButterfliesPerGroup=h->Points/2; auto ButterfliesPerGroup = h->Points / 2;
int bitReverseShift = 24 - h->pow2Bits; int bitReverseShift = 24 - h->pow2Bits;
int bitReverseShiftM1 = bitReverseShift + 1; int bitReverseShiftM1 = bitReverseShift + 1;
@ -2209,7 +2209,7 @@ void InverseRealFFTf4xFastMathBR24(fft_type *buffer,HFFT h)
__m128 v1,v2,sin,cos; __m128 v1,v2,sin,cos;
fft_type iToRad = 2 * M_PI/(2 * h->Points); fft_type iToRad = 2 * M_PI/(2 * h->Points);
int bitReverseShiftM1 = 25 - h->pow2Bits; int bitReverseShiftM1 = 25 - h->pow2Bits;
int ButterfliesPerGroup=h->Points/2; auto ButterfliesPerGroup = h->Points / 2;
/* Massage input to get the input for a real output sequence. */ /* Massage input to get the input for a real output sequence. */
A = localBuffer + 2; A = localBuffer + 2;
@ -2333,7 +2333,7 @@ void ReorderToFreq4xFastMathBR24(HFFT hFFT, fft_type *buffer, fft_type *RealOut,
// Copy the data into the real and imaginary outputs // Copy the data into the real and imaginary outputs
for(int i=1;i<hFFT->Points;i++) { for(size_t i = 1; i < hFFT->Points; i++) {
int brValue; int brValue;
brValue=( ((sSmallRBTable[*((unsigned char *)&i)]<<16) + (sSmallRBTable[*(((unsigned char *)&i)+1)]<<8) + sSmallRBTable[*(((unsigned char *)&i)+2)] )>>bitReverseShift); brValue=( ((sSmallRBTable[*((unsigned char *)&i)]<<16) + (sSmallRBTable[*(((unsigned char *)&i)+1)]<<8) + sSmallRBTable[*(((unsigned char *)&i)+2)] )>>bitReverseShift);
// brValue=(*SmallVRB[hFFT->pow2Bits])(i); // brValue=(*SmallVRB[hFFT->pow2Bits])(i);
@ -2353,7 +2353,7 @@ void ReorderToTime4xFastMathBR24(HFFT hFFT, fft_type *buffer, fft_type *TimeOut)
int bitReverseShift = 24-hFFT->pow2Bits; int bitReverseShift = 24-hFFT->pow2Bits;
// Copy the data into the real outputs // Copy the data into the real outputs
for(int i=0;i<hFFT->Points;i++) { for(size_t i = 0; i < hFFT->Points; i++) {
int brValue; int brValue;
brValue=( ((sSmallRBTable[*((unsigned char *)&i)]<<16) + (sSmallRBTable[*(((unsigned char *)&i)+1)]<<8) + sSmallRBTable[*(((unsigned char *)&i)+2)] )>>bitReverseShift); brValue=( ((sSmallRBTable[*((unsigned char *)&i)]<<16) + (sSmallRBTable[*(((unsigned char *)&i)+1)]<<8) + sSmallRBTable[*(((unsigned char *)&i)+2)] )>>bitReverseShift);
// brValue=(*SmallVRB[hFFT->pow2Bits])(i); // brValue=(*SmallVRB[hFFT->pow2Bits])(i);
@ -2396,7 +2396,7 @@ void RealFFTf1xFastMathBR16(fft_type *buffer,HFFT h)
fft_type iToRad = 2 * M_PI / (2 * h->Points); fft_type iToRad = 2 * M_PI / (2 * h->Points);
int bitReverseShiftM1 = 17 - h->pow2Bits; int bitReverseShiftM1 = 17 - h->pow2Bits;
int bitReverseShift = bitReverseShiftM1 - 1; int bitReverseShift = bitReverseShiftM1 - 1;
int ButterfliesPerGroup=h->Points/2; auto ButterfliesPerGroup = h->Points / 2;
/* /*
* Butterfly: * Butterfly:
@ -2538,7 +2538,7 @@ void InverseRealFFTf1xFastMathBR16(fft_type *buffer,HFFT h)
fft_type iToRad=2 * M_PI / (2 * h->Points); fft_type iToRad=2 * M_PI / (2 * h->Points);
int bitReverseShiftM1=17-h->pow2Bits; int bitReverseShiftM1=17-h->pow2Bits;
int ButterfliesPerGroup=h->Points/2; auto ButterfliesPerGroup = h->Points / 2;
/* Massage input to get the input for a real output sequence. */ /* Massage input to get the input for a real output sequence. */
A = buffer + 2; A = buffer + 2;
@ -2653,7 +2653,7 @@ void ReorderToFreq1xFastMathBR16(HFFT hFFT, fft_type *buffer, fft_type *RealOut,
{ {
int bitReverseShift = 16 - hFFT->pow2Bits; int bitReverseShift = 16 - hFFT->pow2Bits;
// Copy the data into the real and imaginary outputs // Copy the data into the real and imaginary outputs
for(int i=1;i<hFFT->Points;i++) { for(size_t i = 1; i < hFFT->Points; i++) {
int brValue; int brValue;
// brValue=(*SmallVRB[hFFT->pow2Bits])(i); // brValue=(*SmallVRB[hFFT->pow2Bits])(i);
brValue=( ((sSmallRBTable[*((unsigned char *)&i)]<<8) + (sSmallRBTable[*(((unsigned char *)&i)+1)]) )>>bitReverseShift); brValue=( ((sSmallRBTable[*((unsigned char *)&i)]<<8) + (sSmallRBTable[*(((unsigned char *)&i)+1)]) )>>bitReverseShift);
@ -2670,7 +2670,7 @@ void ReorderToTime1xFastMathBR16(HFFT hFFT, fft_type *buffer, fft_type *TimeOut)
{ {
int bitReverseShift=16-hFFT->pow2Bits; int bitReverseShift=16-hFFT->pow2Bits;
// Copy the data into the real outputs // Copy the data into the real outputs
for(int i=0;i<hFFT->Points;i++) { for(size_t i = 0; i < hFFT->Points; i++) {
int brValue; int brValue;
brValue=( ((sSmallRBTable[*((unsigned char *)&i)]<<8) + (sSmallRBTable[*(((unsigned char *)&i)+1)]) )>>bitReverseShift); brValue=( ((sSmallRBTable[*((unsigned char *)&i)]<<8) + (sSmallRBTable[*(((unsigned char *)&i)+1)]) )>>bitReverseShift);
// brValue=(*SmallVRB[hFFT->pow2Bits])(i); // brValue=(*SmallVRB[hFFT->pow2Bits])(i);
@ -2691,7 +2691,7 @@ void RealFFTf4xFastMathBR16(fft_type *buffer,HFFT h)
__m128 HRplus, HRminus, HIplus, HIminus; __m128 HRplus, HRminus, HIplus, HIminus;
__m128 v1, v2, sin, cos; __m128 v1, v2, sin, cos;
fft_type iToRad = 2 * M_PI/(2 * h->Points); fft_type iToRad = 2 * M_PI/(2 * h->Points);
int ButterfliesPerGroup=h->Points/2; auto ButterfliesPerGroup = h->Points / 2;
int bitReverseShiftM1 = 17 - h->pow2Bits; int bitReverseShiftM1 = 17 - h->pow2Bits;
int bitReverseShift = bitReverseShiftM1 - 1; int bitReverseShift = bitReverseShiftM1 - 1;
@ -2839,7 +2839,7 @@ void InverseRealFFTf4xFastMathBR16(fft_type *buffer,HFFT h)
__m128 v1, v2, sin, cos; __m128 v1, v2, sin, cos;
fft_type iToRad = 2 * M_PI/(2 * h->Points); fft_type iToRad = 2 * M_PI/(2 * h->Points);
int bitReverseShiftM1 = 17 - h->pow2Bits; int bitReverseShiftM1 = 17 - h->pow2Bits;
int ButterfliesPerGroup=h->Points/2; auto ButterfliesPerGroup = h->Points / 2;
/* Massage input to get the input for a real output sequence. */ /* Massage input to get the input for a real output sequence. */
A = localBuffer + 2; A = localBuffer + 2;
@ -2963,7 +2963,7 @@ void ReorderToFreq4xFastMathBR16(HFFT hFFT, fft_type *buffer, fft_type *RealOut,
// Copy the data into the real and imaginary outputs // Copy the data into the real and imaginary outputs
for(int i=1;i<hFFT->Points;i++) { for(size_t i = 1; i < hFFT->Points; i++) {
int brValue; int brValue;
brValue=( ((sSmallRBTable[*((unsigned char *)&i)]<<8) + (sSmallRBTable[*(((unsigned char *)&i)+1)]) )>>bitReverseShift); brValue=( ((sSmallRBTable[*((unsigned char *)&i)]<<8) + (sSmallRBTable[*(((unsigned char *)&i)+1)]) )>>bitReverseShift);
// brValue=(*SmallVRB[hFFT->pow2Bits])(i); // brValue=(*SmallVRB[hFFT->pow2Bits])(i);
@ -2983,7 +2983,7 @@ void ReorderToTime4xFastMathBR16(HFFT hFFT, fft_type *buffer, fft_type *TimeOut)
int bitReverseShift=16-hFFT->pow2Bits; int bitReverseShift=16-hFFT->pow2Bits;
// Copy the data into the real outputs // Copy the data into the real outputs
for(int i=0;i<hFFT->Points;i++) { for(size_t i = 0; i < hFFT->Points; i++) {
int brValue; int brValue;
brValue=( ((sSmallRBTable[*((unsigned char *)&i)]<<8) + (sSmallRBTable[*(((unsigned char *)&i)+1)]) )>>bitReverseShift); brValue=( ((sSmallRBTable[*((unsigned char *)&i)]<<8) + (sSmallRBTable[*(((unsigned char *)&i)+1)]) )>>bitReverseShift);
// brValue=(*SmallVRB[hFFT->pow2Bits])(i); // brValue=(*SmallVRB[hFFT->pow2Bits])(i);

View File

@ -1262,8 +1262,9 @@ struct MinMaxSumsq
} }
bool Sequence::GetWaveDisplay(float *min, float *max, float *rms, int* bl, bool Sequence::GetWaveDisplay(float *min, float *max, float *rms, int* bl,
int len, const sampleCount *where) size_t len, const sampleCount *where)
{ {
wxASSERT(len > 0);
const auto s0 = std::max(sampleCount(0), where[0]); const auto s0 = std::max(sampleCount(0), where[0]);
if (s0 >= mNumSamples) if (s0 >= mNumSamples)
// None of the samples asked for are in range. Abandon. // None of the samples asked for are in range. Abandon.
@ -1276,7 +1277,7 @@ bool Sequence::GetWaveDisplay(float *min, float *max, float *rms, int* bl,
std::min(mNumSamples, std::max(1 + where[len - 1], where[len])); std::min(mNumSamples, std::max(1 + where[len - 1], where[len]));
float *temp = new float[mMaxSamples]; float *temp = new float[mMaxSamples];
int pixel = 0; decltype(len) pixel = 0;
auto srcX = s0; auto srcX = s0;
decltype(srcX) nextSrcX = 0; decltype(srcX) nextSrcX = 0;
@ -1305,7 +1306,7 @@ bool Sequence::GetWaveDisplay(float *min, float *max, float *rms, int* bl,
// Find the range of pixels covered by the current block file // Find the range of pixels covered by the current block file
// (Their starting samples covered by it, to be exact) // (Their starting samples covered by it, to be exact)
int nextPixel; decltype(len) nextPixel;
if (nextSrcX >= s1) if (nextSrcX >= s1)
// last pass // last pass
nextPixel = len; nextPixel = len;
@ -1416,7 +1417,7 @@ bool Sequence::GetWaveDisplay(float *min, float *max, float *rms, int* bl,
// (normally just one, but maybe more when zoomed very close) // (normally just one, but maybe more when zoomed very close)
// and the range of positions for those columns // and the range of positions for those columns
// (normally one or more, for that one column) // (normally one or more, for that one column)
int pixelX = pixel + 1; auto pixelX = pixel + 1;
decltype(filePosition) positionX = 0; decltype(filePosition) positionX = 0;
while (pixelX < nextPixel && while (pixelX < nextPixel &&
filePosition == filePosition ==

View File

@ -100,7 +100,7 @@ class PROFILE_DLL_API Sequence final : public XMLTagHandler{
// bl is negative wherever data are not yet available. // bl is negative wherever data are not yet available.
// Return true if successful. // Return true if successful.
bool GetWaveDisplay(float *min, float *max, float *rms, int* bl, bool GetWaveDisplay(float *min, float *max, float *rms, int* bl,
int len, const sampleCount *where); size_t len, const sampleCount *where);
bool Copy(sampleCount s0, sampleCount s1, std::unique_ptr<Sequence> &dest) const; bool Copy(sampleCount s0, sampleCount s1, std::unique_ptr<Sequence> &dest) const;
bool Paste(sampleCount s0, const Sequence *src); bool Paste(sampleCount s0, const Sequence *src);

View File

@ -20,8 +20,8 @@
#include "Experimental.h" #include "Experimental.h"
bool ComputeSpectrum(const float * data, int width, bool ComputeSpectrum(const float * data, size_t width,
int windowSize, size_t windowSize,
double WXUNUSED(rate), float *output, double WXUNUSED(rate), float *output,
bool autocorrelation, int windowFunc) bool autocorrelation, int windowFunc)
{ {
@ -33,19 +33,18 @@ bool ComputeSpectrum(const float * data, int width,
float *processed = new float[windowSize]; float *processed = new float[windowSize];
int i; for (size_t i = 0; i < windowSize; i++)
for (i = 0; i < windowSize; i++)
processed[i] = float(0.0); processed[i] = float(0.0);
int half = windowSize / 2; auto half = windowSize / 2;
float *in = new float[windowSize]; float *in = new float[windowSize];
float *out = new float[windowSize]; float *out = new float[windowSize];
float *out2 = new float[windowSize]; float *out2 = new float[windowSize];
int start = 0; size_t start = 0;
int windows = 0; unsigned windows = 0;
while (start + windowSize <= width) { while (start + windowSize <= width) {
for (i = 0; i < windowSize; i++) for (size_t i = 0; i < windowSize; i++)
in[i] = data[start + i]; in[i] = data[start + i];
WindowFunc(windowFunc, windowSize, in); WindowFunc(windowFunc, windowSize, in);
@ -54,13 +53,13 @@ bool ComputeSpectrum(const float * data, int width,
// Take FFT // Take FFT
RealFFT(windowSize, in, out, out2); RealFFT(windowSize, in, out, out2);
// Compute power // Compute power
for (i = 0; i < windowSize; i++) for (size_t i = 0; i < windowSize; i++)
in[i] = (out[i] * out[i]) + (out2[i] * out2[i]); in[i] = (out[i] * out[i]) + (out2[i] * out2[i]);
// Tolonen and Karjalainen recommend taking the cube root // Tolonen and Karjalainen recommend taking the cube root
// of the power, instead of the square root // of the power, instead of the square root
for (i = 0; i < windowSize; i++) for (size_t i = 0; i < windowSize; i++)
in[i] = powf(in[i], 1.0f / 3.0f); in[i] = powf(in[i], 1.0f / 3.0f);
// Take FFT // Take FFT
@ -70,7 +69,7 @@ bool ComputeSpectrum(const float * data, int width,
PowerSpectrum(windowSize, in, out); PowerSpectrum(windowSize, in, out);
// Take real part of result // Take real part of result
for (i = 0; i < half; i++) for (size_t i = 0; i < half; i++)
processed[i] += out[i]; processed[i] += out[i];
start += half; start += half;
@ -85,7 +84,7 @@ bool ComputeSpectrum(const float * data, int width,
It should be safe, as indexes refer only to current and previous elements, It should be safe, as indexes refer only to current and previous elements,
that have already been clipped, etc... that have already been clipped, etc...
*/ */
for (i = 0; i < half; i++) { for (size_t i = 0; i < half; i++) {
// Clip at zero, copy to temp array // Clip at zero, copy to temp array
if (processed[i] < 0.0) if (processed[i] < 0.0)
processed[i] = float(0.0); processed[i] = float(0.0);
@ -103,14 +102,14 @@ bool ComputeSpectrum(const float * data, int width,
} }
// Reverse and scale // Reverse and scale
for (i = 0; i < half; i++) for (size_t i = 0; i < half; i++)
in[i] = processed[i] / (windowSize / 4); in[i] = processed[i] / (windowSize / 4);
for (i = 0; i < half; i++) for (size_t i = 0; i < half; i++)
processed[half - 1 - i] = in[i]; processed[half - 1 - i] = in[i];
} else { } else {
// Convert to decibels // Convert to decibels
// But do it safely; -Inf is nobody's friend // But do it safely; -Inf is nobody's friend
for (i = 0; i < half; i++){ for (size_t i = 0; i < half; i++){
float temp=(processed[i] / windowSize / windows); float temp=(processed[i] / windowSize / windows);
if (temp > 0.0) if (temp > 0.0)
processed[i] = 10 * log10(temp); processed[i] = 10 * log10(temp);
@ -119,7 +118,7 @@ bool ComputeSpectrum(const float * data, int width,
} }
} }
for(i=0;i<half;i++) for(size_t i = 0; i < half; i++)
output[i] = processed[i]; output[i] = processed[i];
delete[]in; delete[]in;
delete[]out; delete[]out;

View File

@ -21,7 +21,7 @@
calculates windowSize/2 frequency samples calculates windowSize/2 frequency samples
*/ */
bool ComputeSpectrum(const float * data, int width, int windowSize, bool ComputeSpectrum(const float * data, size_t width, size_t windowSize,
double rate, float *out, bool autocorrelation, double rate, float *out, bool autocorrelation,
int windowFunc = eWinFuncHanning); int windowFunc = eWinFuncHanning);

View File

@ -2015,7 +2015,7 @@ void TrackArtist::DrawSpectrum(const WaveTrack *track,
} }
static inline float findValue static inline float findValue
(const float *spectrum, float bin0, float bin1, int half, (const float *spectrum, float bin0, float bin1, unsigned half,
bool autocorrelation, int gain, int range) bool autocorrelation, int gain, int range)
{ {
float value; float value;
@ -2035,7 +2035,7 @@ static inline float findValue
bin0 += 1.0; bin0 += 1.0;
} }
// Do not reference past end of freq array. // Do not reference past end of freq array.
if (int(bin1) >= half) { if (int(bin1) >= (int)half) {
bin1 -= 1.0; bin1 -= 1.0;
} }
@ -2043,7 +2043,6 @@ static inline float findValue
value /= binwidth; value /= binwidth;
} }
#else #else
wxUnusedVar(half);
// Maximum method, and no apportionment of any single bins over multiple pixel rows // Maximum method, and no apportionment of any single bins over multiple pixel rows
// See Bug971 // See Bug971
int index, limitIndex; int index, limitIndex;
@ -2058,8 +2057,8 @@ static inline float findValue
)); ));
} }
else { else {
index = std::min(half - 1, int(floor(0.5 + bin0))); index = std::min<int>(half - 1, int(floor(0.5 + bin0)));
limitIndex = std::min(half, int(floor(0.5 + bin1))); limitIndex = std::min<int>(half, int(floor(0.5 + bin1)));
} }
value = spectrum[index]; value = spectrum[index];
while (++index < limitIndex) while (++index < limitIndex)
@ -2166,14 +2165,15 @@ void TrackArtist::DrawClipSpectrum(WaveTrackCache &waveTrackCache,
return; return;
unsigned char *data = image.GetData(); unsigned char *data = image.GetData();
const int half = settings.GetFFTLength() / 2; const auto half = settings.GetFFTLength() / 2;
const double binUnit = rate / (2 * half); const double binUnit = rate / (2 * half);
const float *freq = 0; const float *freq = 0;
const sampleCount *where = 0; const sampleCount *where = 0;
bool updated; bool updated;
{ {
const double pps = averagePixelsPerSample * rate; const double pps = averagePixelsPerSample * rate;
updated = clip->GetSpectrogram(waveTrackCache, freq, where, hiddenMid.width, updated = clip->GetSpectrogram(waveTrackCache, freq, where,
(size_t)hiddenMid.width,
t0, pps); t0, pps);
} }
@ -2399,12 +2399,12 @@ void TrackArtist::DrawClipSpectrum(WaveTrackCache &waveTrackCache,
const int end = hidden const int end = hidden
? 0 ? 0
: std::min(mid.width, int(zoomInfo.GetFisheyeRightBoundary(-leftOffset))); : std::min(mid.width, int(zoomInfo.GetFisheyeRightBoundary(-leftOffset)));
const int numPixels = std::max(0, end - begin); const size_t numPixels = std::max(0, end - begin);
const int zeroPaddingFactor = autocorrelation ? 1 : settings.zeroPaddingFactor; const size_t zeroPaddingFactor = autocorrelation ? 1 : settings.ZeroPaddingFactor();
SpecCache specCache SpecCache specCache
(numPixels, settings.algorithm, -1, (numPixels, settings.algorithm, -1,
t0, settings.windowType, t0, settings.windowType,
settings.windowSize, zeroPaddingFactor, settings.frequencyGain); settings.WindowSize(), zeroPaddingFactor, settings.frequencyGain);
if (numPixels > 0) { if (numPixels > 0) {
for (int ii = begin; ii < end; ++ii) { for (int ii = begin; ii < end; ++ii) {
const double time = zoomInfo.PositionToTime(ii, -leftOffset) - tOffset; const double time = zoomInfo.PositionToTime(ii, -leftOffset) - tOffset;

View File

@ -2346,7 +2346,7 @@ inline double findMaxRatio(double center, double rate)
void TrackPanel::SnapCenterOnce(const WaveTrack *pTrack, bool up) void TrackPanel::SnapCenterOnce(const WaveTrack *pTrack, bool up)
{ {
const SpectrogramSettings &settings = pTrack->GetSpectrogramSettings(); const SpectrogramSettings &settings = pTrack->GetSpectrogramSettings();
const int windowSize = settings.GetFFTLength(); const auto windowSize = settings.GetFFTLength();
const double rate = pTrack->GetRate(); const double rate = pTrack->GetRate();
const double nyq = rate / 2.0; const double nyq = rate / 2.0;
const double binFrequency = rate / windowSize; const double binFrequency = rate / windowSize;
@ -2409,7 +2409,7 @@ void TrackPanel::StartSnappingFreqSelection (const WaveTrack *pTrack)
// except, shrink the window as needed so we get some answers // except, shrink the window as needed so we get some answers
const SpectrogramSettings &settings = pTrack->GetSpectrogramSettings(); const SpectrogramSettings &settings = pTrack->GetSpectrogramSettings();
int windowSize = settings.GetFFTLength(); auto windowSize = settings.GetFFTLength();
while(windowSize > effectiveLength) while(windowSize > effectiveLength)
windowSize >>= 1; windowSize >>= 1;
@ -4102,7 +4102,7 @@ void TrackPanel::HandleWaveTrackVZoom
if (spectral) { if (spectral) {
track->GetSpectrumBounds(&min, &max); track->GetSpectrumBounds(&min, &max);
scale = (settings.GetScale(min, max, rate, false)); scale = (settings.GetScale(min, max, rate, false));
const int fftLength = settings.GetFFTLength(); const auto fftLength = settings.GetFFTLength();
const float binSize = rate / fftLength; const float binSize = rate / fftLength;
// JKC: Following discussions of Bug 1208 I'm allowing zooming in // JKC: Following discussions of Bug 1208 I'm allowing zooming in

View File

@ -177,7 +177,7 @@ sampleCount VoiceKey::OnForward (WaveTrack & t, sampleCount start, sampleCount l
//Now, go through the sound again, sample by sample. //Now, go through the sound again, sample by sample.
wxASSERT(WindowSizeInt < SignalWindowSizeInt); wxASSERT(WindowSizeInt < SignalWindowSizeInt);
size_t i; size_t i;
for(i = 0; i < SignalWindowSizeInt - WindowSizeInt; i++) { for(i = 0; i + WindowSizeInt < SignalWindowSizeInt; i++) {
int tests = 0; int tests = 0;
int testThreshold = 0; int testThreshold = 0;

View File

@ -57,7 +57,6 @@ class WaveCache {
public: public:
WaveCache() WaveCache()
: dirty(-1) : dirty(-1)
, len(-1)
, start(-1) , start(-1)
, pps(0) , pps(0)
, rate(-1) , rate(-1)
@ -70,7 +69,7 @@ public:
{ {
} }
WaveCache(int len_, double pixelsPerSecond, double rate_, double t0, int dirty_) WaveCache(size_t len_, double pixelsPerSecond, double rate_, double t0, int dirty_)
: dirty(dirty_) : dirty(dirty_)
, len(len_) , len(len_)
, start(t0) , start(t0)
@ -94,7 +93,7 @@ public:
} }
int dirty; int dirty;
const int len; // counts pixels, not samples const size_t len { 0 }; // counts pixels, not samples
const double start; const double start;
const double pps; const double pps;
const int rate; const int rate;
@ -108,10 +107,12 @@ public:
class InvalidRegion class InvalidRegion
{ {
public: public:
InvalidRegion(int s, int e):start(s),end(e){} InvalidRegion(size_t s, size_t e)
: start(s), end(e)
{}
//start and end pixel count. (not samples) //start and end pixel count. (not samples)
int start; size_t start;
int end; size_t end;
}; };
@ -157,7 +158,7 @@ public:
//if the regions intersect OR are pixel adjacent //if the regions intersect OR are pixel adjacent
InvalidRegion &region = mRegions[i]; InvalidRegion &region = mRegions[i];
if(region.start <= invalEnd+1 if(region.start <= invalEnd+1
&& region.end >= invalStart-1) && region.end + 1 >= invalStart)
{ {
//take the union region //take the union region
if(region.start > invalStart) if(region.start > invalStart)
@ -195,7 +196,7 @@ public:
InvalidRegion &region = mRegions[i]; InvalidRegion &region = mRegions[i];
InvalidRegion &prevRegion = mRegions[i - 1]; InvalidRegion &prevRegion = mRegions[i - 1];
if(region.start <= prevRegion.end+1 if(region.start <= prevRegion.end+1
&& region.end >= prevRegion.start-1) && region.end + 1 >= prevRegion.start)
{ {
//take the union region //take the union region
if(region.start > prevRegion.start) if(region.start > prevRegion.start)
@ -218,8 +219,8 @@ public:
//lock before calling these in a section. unlock after finished. //lock before calling these in a section. unlock after finished.
int GetNumInvalidRegions() const {return mRegions.size();} int GetNumInvalidRegions() const {return mRegions.size();}
int GetInvalidRegionStart(int i) const {return mRegions[i].start;} size_t GetInvalidRegionStart(int i) const {return mRegions[i].start;}
int GetInvalidRegionEnd(int i) const {return mRegions[i].end;} size_t GetInvalidRegionEnd(int i) const {return mRegions[i].end;}
void ClearInvalidRegions() void ClearInvalidRegions()
{ {
@ -228,8 +229,8 @@ public:
void LoadInvalidRegion(int ii, Sequence *sequence, bool updateODCount) void LoadInvalidRegion(int ii, Sequence *sequence, bool updateODCount)
{ {
const int invStart = GetInvalidRegionStart(ii); const auto invStart = GetInvalidRegionStart(ii);
const int invEnd = GetInvalidRegionEnd(ii); const auto invEnd = GetInvalidRegionEnd(ii);
//before check number of ODPixels //before check number of ODPixels
int regionODPixels = 0; int regionODPixels = 0;
@ -258,7 +259,7 @@ public:
LoadInvalidRegion(i, sequence, updateODCount); LoadInvalidRegion(i, sequence, updateODCount);
} }
int CountODPixels(int start, int end) int CountODPixels(size_t start, size_t end)
{ {
using namespace std; using namespace std;
const int *begin = &bl[0]; const int *begin = &bl[0];
@ -272,9 +273,9 @@ protected:
}; };
static void ComputeSpectrumUsingRealFFTf static void ComputeSpectrumUsingRealFFTf
(float * __restrict buffer, HFFT hFFT, const float * __restrict window, int len, float * __restrict out) (float * __restrict buffer, HFFT hFFT, const float * __restrict window, size_t len, float * __restrict out)
{ {
int i; size_t i;
if(len > hFFT->Points * 2) if(len > hFFT->Points * 2)
len = hFFT->Points * 2; len = hFFT->Points * 2;
for(i = 0; i < len; i++) for(i = 0; i < len; i++)
@ -435,7 +436,8 @@ void WaveClip::AddInvalidRegion(sampleCount startSample, sampleCount endSample)
namespace { namespace {
inline inline
void findCorrection(const std::vector<sampleCount> &oldWhere, int oldLen, int newLen, void findCorrection(const std::vector<sampleCount> &oldWhere, size_t oldLen,
size_t newLen,
double t0, double rate, double samplesPerPixel, double t0, double rate, double samplesPerPixel,
int &oldX0, double &correction) int &oldX0, double &correction)
{ {
@ -478,7 +480,7 @@ void findCorrection(const std::vector<sampleCount> &oldWhere, int oldLen, int ne
} }
inline void inline void
fillWhere(std::vector<sampleCount> &where, int len, double bias, double correction, fillWhere(std::vector<sampleCount> &where, size_t len, double bias, double correction,
double t0, double rate, double samplesPerPixel) double t0, double rate, double samplesPerPixel)
{ {
// Be careful to make the first value non-negative // Be careful to make the first value non-negative
@ -500,10 +502,10 @@ bool WaveClip::GetWaveDisplay(WaveDisplay &display, double t0,
{ {
const bool allocated = (display.where != 0); const bool allocated = (display.where != 0);
const int numPixels = display.width; const size_t numPixels = (int)display.width;
int p0 = 0; // least column requiring computation size_t p0 = 0; // least column requiring computation
int p1 = numPixels; // greatest column requiring computation, plus one size_t p1 = numPixels; // greatest column requiring computation, plus one
float *min; float *min;
float *max; float *max;
@ -558,7 +560,7 @@ bool WaveClip::GetWaveDisplay(WaveDisplay &display, double t0,
int oldX0 = 0; int oldX0 = 0;
double correction = 0.0; double correction = 0.0;
int copyBegin = 0, copyEnd = 0; size_t copyBegin = 0, copyEnd = 0;
if (match) { if (match) {
findCorrection(oldCache->where, oldCache->len, numPixels, findCorrection(oldCache->where, oldCache->len, numPixels,
t0, mRate, samplesPerPixel, t0, mRate, samplesPerPixel,
@ -566,9 +568,10 @@ bool WaveClip::GetWaveDisplay(WaveDisplay &display, double t0,
// Remember our first pixel maps to oldX0 in the old cache, // Remember our first pixel maps to oldX0 in the old cache,
// possibly out of bounds. // possibly out of bounds.
// For what range of pixels can data be copied? // For what range of pixels can data be copied?
copyBegin = std::min(numPixels, std::max(0, -oldX0)); copyBegin = std::min<size_t>(numPixels, std::max(0, -oldX0));
copyEnd = std::min(numPixels, copyEnd = std::min<size_t>(numPixels,
copyBegin + oldCache->len - std::max(0, oldX0) std::max(0,
(int)copyBegin + (int)oldCache->len - std::max(0, oldX0))
); );
} }
if (!(copyEnd > copyBegin)) if (!(copyEnd > copyBegin))
@ -603,7 +606,7 @@ bool WaveClip::GetWaveDisplay(WaveDisplay &display, double t0,
// Copy what we can from the old cache. // Copy what we can from the old cache.
const int length = copyEnd - copyBegin; const int length = copyEnd - copyBegin;
const size_t sizeFloats = length * sizeof(float); const size_t sizeFloats = length * sizeof(float);
const int srcIdx = copyBegin + oldX0; const int srcIdx = (int)copyBegin + oldX0;
memcpy(&min[copyBegin], &oldCache->min[srcIdx], sizeFloats); memcpy(&min[copyBegin], &oldCache->min[srcIdx], sizeFloats);
memcpy(&max[copyBegin], &oldCache->max[srcIdx], sizeFloats); memcpy(&max[copyBegin], &oldCache->max[srcIdx], sizeFloats);
memcpy(&rms[copyBegin], &oldCache->rms[srcIdx], sizeFloats); memcpy(&rms[copyBegin], &oldCache->rms[srcIdx], sizeFloats);
@ -618,11 +621,11 @@ bool WaveClip::GetWaveDisplay(WaveDisplay &display, double t0,
/* handle values in the append buffer */ /* handle values in the append buffer */
auto numSamples = mSequence->GetNumSamples(); auto numSamples = mSequence->GetNumSamples();
int a; auto a = p0;
// Not all of the required columns might be in the sequence. // Not all of the required columns might be in the sequence.
// Some might be in the append buffer. // Some might be in the append buffer.
for (a = p0; a < p1; ++a) { for (; a < p1; ++a) {
if (where[a + 1] > numSamples) if (where[a + 1] > numSamples)
break; break;
} }
@ -630,11 +633,9 @@ bool WaveClip::GetWaveDisplay(WaveDisplay &display, double t0,
// Handle the columns that land in the append buffer. // Handle the columns that land in the append buffer.
//compute the values that are outside the overlap from scratch. //compute the values that are outside the overlap from scratch.
if (a < p1) { if (a < p1) {
int i;
sampleFormat seqFormat = mSequence->GetSampleFormat(); sampleFormat seqFormat = mSequence->GetSampleFormat();
bool didUpdate = false; bool didUpdate = false;
for(i=a; i<p1; i++) { for(auto i = a; i < p1; i++) {
auto left = std::max(sampleCount{ 0 }, auto left = std::max(sampleCount{ 0 },
where[i] - numSamples); where[i] - numSamples);
auto right = std::min(sampleCount{ mAppendBufferLen }, auto right = std::min(sampleCount{ mAppendBufferLen },
@ -724,7 +725,7 @@ bool WaveClip::GetWaveDisplay(WaveDisplay &display, double t0,
namespace { namespace {
void ComputeSpectrogramGainFactors void ComputeSpectrogramGainFactors
(int fftLen, double rate, int frequencyGain, std::vector<float> &gainFactors) (size_t fftLen, double rate, int frequencyGain, std::vector<float> &gainFactors)
{ {
if (frequencyGain > 0) { if (frequencyGain > 0) {
// Compute a frequency-dependent gain factor // Compute a frequency-dependent gain factor
@ -733,7 +734,7 @@ void ComputeSpectrogramGainFactors
// This is the reciprocal of the bin number of 1000 Hz: // This is the reciprocal of the bin number of 1000 Hz:
const double factor = ((double)rate / (double)fftLen) / 1000.0; const double factor = ((double)rate / (double)fftLen) / 1000.0;
int half = fftLen / 2; auto half = fftLen / 2;
gainFactors.reserve(half); gainFactors.reserve(half);
// Don't take logarithm of zero! Let bin 0 replicate the gain factor for bin 1. // Don't take logarithm of zero! Let bin 0 replicate the gain factor for bin 1.
gainFactors.push_back(frequencyGain*log10(factor)); gainFactors.push_back(frequencyGain*log10(factor));
@ -760,8 +761,8 @@ bool SpecCache::Matches
ppsMatch && ppsMatch &&
dirty == dirty_ && dirty == dirty_ &&
windowType == settings.windowType && windowType == settings.windowType &&
windowSize == settings.windowSize && windowSize == settings.WindowSize() &&
zeroPaddingFactor == settings.zeroPaddingFactor && zeroPaddingFactor == settings.ZeroPaddingFactor() &&
frequencyGain == settings.frequencyGain && frequencyGain == settings.frequencyGain &&
algorithm == settings.algorithm; algorithm == settings.algorithm;
} }
@ -778,7 +779,7 @@ bool SpecCache::CalculateOneSpectrum
bool result = false; bool result = false;
const bool reassignment = const bool reassignment =
(settings.algorithm == SpectrogramSettings::algReassignment); (settings.algorithm == SpectrogramSettings::algReassignment);
const int windowSize = settings.windowSize; const size_t windowSize = settings.WindowSize();
sampleCount start; sampleCount start;
if (xx < 0) if (xx < 0)
@ -790,10 +791,10 @@ bool SpecCache::CalculateOneSpectrum
const bool autocorrelation = const bool autocorrelation =
settings.algorithm == SpectrogramSettings::algPitchEAC; settings.algorithm == SpectrogramSettings::algPitchEAC;
const int zeroPaddingFactor = (autocorrelation ? 1 : settings.zeroPaddingFactor); const size_t zeroPaddingFactor = (autocorrelation ? 1 : settings.ZeroPaddingFactor());
const int padding = (windowSize * (zeroPaddingFactor - 1)) / 2; const size_t padding = (windowSize * (zeroPaddingFactor - 1)) / 2;
const int fftLen = windowSize * zeroPaddingFactor; const size_t fftLen = windowSize * zeroPaddingFactor;
const int half = fftLen / 2; const auto half = fftLen / 2;
if (start <= 0 || start >= numSamples) { if (start <= 0 || start >= numSamples) {
if (xx >= 0 && xx < len) { if (xx >= 0 && xx < len) {
@ -864,26 +865,26 @@ bool SpecCache::CalculateOneSpectrum
{ {
const float *const window = settings.window; const float *const window = settings.window;
for (int ii = 0; ii < fftLen; ++ii) for (size_t ii = 0; ii < fftLen; ++ii)
scratch[ii] *= window[ii]; scratch[ii] *= window[ii];
RealFFTf(scratch, hFFT); RealFFTf(scratch, hFFT);
} }
{ {
const float *const dWindow = settings.dWindow; const float *const dWindow = settings.dWindow;
for (int ii = 0; ii < fftLen; ++ii) for (size_t ii = 0; ii < fftLen; ++ii)
scratch2[ii] *= dWindow[ii]; scratch2[ii] *= dWindow[ii];
RealFFTf(scratch2, hFFT); RealFFTf(scratch2, hFFT);
} }
{ {
const float *const tWindow = settings.tWindow; const float *const tWindow = settings.tWindow;
for (int ii = 0; ii < fftLen; ++ii) for (size_t ii = 0; ii < fftLen; ++ii)
scratch3[ii] *= tWindow[ii]; scratch3[ii] *= tWindow[ii];
RealFFTf(scratch3, hFFT); RealFFTf(scratch3, hFFT);
} }
for (int ii = 0; ii < hFFT->Points; ++ii) { for (size_t ii = 0; ii < hFFT->Points; ++ii) {
const int index = hFFT->BitReversed[ii]; const int index = hFFT->BitReversed[ii];
const float const float
denomRe = scratch[index], denomRe = scratch[index],
@ -895,7 +896,7 @@ bool SpecCache::CalculateOneSpectrum
double freqCorrection; double freqCorrection;
{ {
const double multiplier = -fftLen / (2.0f * M_PI); const double multiplier = -(fftLen / (2.0f * M_PI));
const float const float
numRe = scratch2[index], numRe = scratch2[index],
numIm = ii == 0 ? 0 : scratch2[index + 1]; numIm = ii == 0 ? 0 : scratch2[index + 1];
@ -929,7 +930,8 @@ bool SpecCache::CalculateOneSpectrum
{ {
result = true; result = true;
int index = half * correctedX + bin; // Can this be negative?
int index = (int)half * correctedX + bin;
#ifdef _OPENMP #ifdef _OPENMP
// This assignment can race if index reaches into another thread's bins. // This assignment can race if index reaches into another thread's bins.
// The probability of a race very low, so this carries little overhead, // The probability of a race very low, so this carries little overhead,
@ -954,7 +956,7 @@ bool SpecCache::CalculateOneSpectrum
(useBuffer, settings.hFFT, settings.window, fftLen, results); (useBuffer, settings.hFFT, settings.window, fftLen, results);
if (!gainFactors.empty()) { if (!gainFactors.empty()) {
// Apply a frequency-dependant gain factor // Apply a frequency-dependant gain factor
for (int ii = 0; ii < half; ++ii) for (size_t ii = 0; ii < half; ++ii)
results[ii] += gainFactors[ii]; results[ii] += gainFactors[ii];
} }
} }
@ -965,28 +967,28 @@ bool SpecCache::CalculateOneSpectrum
void SpecCache::Populate void SpecCache::Populate
(const SpectrogramSettings &settings, WaveTrackCache &waveTrackCache, (const SpectrogramSettings &settings, WaveTrackCache &waveTrackCache,
int copyBegin, int copyEnd, int numPixels, int copyBegin, int copyEnd, size_t numPixels,
sampleCount numSamples, sampleCount numSamples,
double offset, double rate, double pixelsPerSecond) double offset, double rate, double pixelsPerSecond)
{ {
settings.CacheWindows(); settings.CacheWindows();
const int &frequencyGain = settings.frequencyGain; const int &frequencyGain = settings.frequencyGain;
const int &windowSize = settings.windowSize; const size_t windowSize = settings.WindowSize();
const bool autocorrelation = const bool autocorrelation =
settings.algorithm == SpectrogramSettings::algPitchEAC; settings.algorithm == SpectrogramSettings::algPitchEAC;
const bool reassignment = const bool reassignment =
settings.algorithm == SpectrogramSettings::algReassignment; settings.algorithm == SpectrogramSettings::algReassignment;
#ifdef EXPERIMENTAL_ZERO_PADDED_SPECTROGRAMS #ifdef EXPERIMENTAL_ZERO_PADDED_SPECTROGRAMS
const int &zeroPaddingFactor = autocorrelation ? 1 : settings.zeroPaddingFactor; const size_t zeroPaddingFactor = autocorrelation ? 1 : settings.ZeroPaddingFactor();
#else #else
const int zeroPaddingFactor = 1; const size_t zeroPaddingFactor = 1;
#endif #endif
// FFT length may be longer than the window of samples that affect results // FFT length may be longer than the window of samples that affect results
// because of zero padding done for increased frequency resolution // because of zero padding done for increased frequency resolution
const int fftLen = windowSize * zeroPaddingFactor; const size_t fftLen = windowSize * zeroPaddingFactor;
const int half = fftLen / 2; const auto half = fftLen / 2;
const size_t bufferSize = fftLen; const size_t bufferSize = fftLen;
const size_t scratchSize = reassignment ? 3 * bufferSize : bufferSize; const size_t scratchSize = reassignment ? 3 * bufferSize : bufferSize;
@ -1078,7 +1080,7 @@ void SpecCache::Populate
for (auto xx = lowerBoundX; xx < upperBoundX; ++xx) { for (auto xx = lowerBoundX; xx < upperBoundX; ++xx) {
float *const results = &freq[half * xx]; float *const results = &freq[half * xx];
const HFFT hFFT = settings.hFFT; const HFFT hFFT = settings.hFFT;
for (int ii = 0; ii < hFFT->Points; ++ii) { for (size_t ii = 0; ii < hFFT->Points; ++ii) {
float &power = results[ii]; float &power = results[ii];
if (power <= 0) if (power <= 0)
power = -160.0; power = -160.0;
@ -1087,7 +1089,7 @@ void SpecCache::Populate
} }
if (!gainFactors.empty()) { if (!gainFactors.empty()) {
// Apply a frequency-dependant gain factor // Apply a frequency-dependant gain factor
for (int ii = 0; ii < half; ++ii) for (size_t ii = 0; ii < half; ++ii)
results[ii] += gainFactors[ii]; results[ii] += gainFactors[ii];
} }
} }
@ -1097,7 +1099,7 @@ void SpecCache::Populate
bool WaveClip::GetSpectrogram(WaveTrackCache &waveTrackCache, bool WaveClip::GetSpectrogram(WaveTrackCache &waveTrackCache,
const float *& spectrogram, const sampleCount *& where, const float *& spectrogram, const sampleCount *& where,
int numPixels, size_t numPixels,
double t0, double pixelsPerSecond) const double t0, double pixelsPerSecond) const
{ {
BEGIN_TASK_PROFILING("GetSpectrogram"); BEGIN_TASK_PROFILING("GetSpectrogram");
@ -1107,18 +1109,18 @@ bool WaveClip::GetSpectrogram(WaveTrackCache &waveTrackCache,
const bool autocorrelation = const bool autocorrelation =
settings.algorithm == SpectrogramSettings::algPitchEAC; settings.algorithm == SpectrogramSettings::algPitchEAC;
const int &frequencyGain = settings.frequencyGain; const int &frequencyGain = settings.frequencyGain;
const int &windowSize = settings.windowSize; const size_t windowSize = settings.WindowSize();
const int &windowType = settings.windowType; const int &windowType = settings.windowType;
#ifdef EXPERIMENTAL_ZERO_PADDED_SPECTROGRAMS #ifdef EXPERIMENTAL_ZERO_PADDED_SPECTROGRAMS
const int &zeroPaddingFactor = autocorrelation ? 1 : settings.zeroPaddingFactor; const size_t zeroPaddingFactor = autocorrelation ? 1 : settings.ZeroPaddingFactor();
#else #else
const int zeroPaddingFactor = 1; const size_t zeroPaddingFactor = 1;
#endif #endif
// FFT length may be longer than the window of samples that affect results // FFT length may be longer than the window of samples that affect results
// because of zero padding done for increased frequency resolution // because of zero padding done for increased frequency resolution
const int fftLen = windowSize * zeroPaddingFactor; const size_t fftLen = windowSize * zeroPaddingFactor;
const int half = fftLen / 2; const auto half = fftLen / 2;
bool match = bool match =
mSpecCache && mSpecCache &&
@ -1158,9 +1160,9 @@ bool WaveClip::GetSpectrogram(WaveTrackCache &waveTrackCache,
// Remember our first pixel maps to oldX0 in the old cache, // Remember our first pixel maps to oldX0 in the old cache,
// possibly out of bounds. // possibly out of bounds.
// For what range of pixels can data be copied? // For what range of pixels can data be copied?
copyBegin = std::min(numPixels, std::max(0, -oldX0)); copyBegin = std::min((int)numPixels, std::max(0, -oldX0));
copyEnd = std::min(numPixels, copyEnd = std::min((int)numPixels,
copyBegin + oldCache->len - std::max(0, oldX0) copyBegin + (int)oldCache->len - std::max(0, oldX0)
); );
} }

View File

@ -41,13 +41,10 @@ public:
// Make invalid cache // Make invalid cache
SpecCache() SpecCache()
: len(-1) : algorithm(-1)
, algorithm(-1)
, pps(-1.0) , pps(-1.0)
, start(-1.0) , start(-1.0)
, windowType(-1) , windowType(-1)
, windowSize(-1)
, zeroPaddingFactor(-1)
, frequencyGain(-1) , frequencyGain(-1)
#if 0 #if 0
, freq(NULL) , freq(NULL)
@ -58,9 +55,9 @@ public:
} }
// Make valid cache, to be filled in // Make valid cache, to be filled in
SpecCache(int cacheLen, int algorithm_, SpecCache(size_t cacheLen, int algorithm_,
double pps_, double start_, int windowType_, int windowSize_, double pps_, double start_, int windowType_, size_t windowSize_,
int zeroPaddingFactor_, int frequencyGain_) unsigned zeroPaddingFactor_, int frequencyGain_)
: len(cacheLen) : len(cacheLen)
, algorithm(algorithm_) , algorithm(algorithm_)
, pps(pps_) , pps(pps_)
@ -102,17 +99,17 @@ public:
void Populate void Populate
(const SpectrogramSettings &settings, WaveTrackCache &waveTrackCache, (const SpectrogramSettings &settings, WaveTrackCache &waveTrackCache,
int copyBegin, int copyEnd, int numPixels, int copyBegin, int copyEnd, size_t numPixels,
sampleCount numSamples, sampleCount numSamples,
double offset, double rate, double pixelsPerSecond); double offset, double rate, double pixelsPerSecond);
const int len; // counts pixels, not samples const size_t len { 0 }; // counts pixels, not samples
const int algorithm; const int algorithm;
const double pps; const double pps;
const double start; const double start;
const int windowType; const int windowType;
const int windowSize; const size_t windowSize { 0 };
const int zeroPaddingFactor; const unsigned zeroPaddingFactor { 0 };
const int frequencyGain; const int frequencyGain;
std::vector<float> freq; std::vector<float> freq;
std::vector<sampleCount> where; std::vector<sampleCount> where;
@ -280,7 +277,7 @@ public:
double t0, double pixelsPerSecond, bool &isLoadingOD) const; double t0, double pixelsPerSecond, bool &isLoadingOD) const;
bool GetSpectrogram(WaveTrackCache &cache, bool GetSpectrogram(WaveTrackCache &cache,
const float *& spectrogram, const sampleCount *& where, const float *& spectrogram, const sampleCount *& where,
int numPixels, size_t numPixels,
double t0, double pixelsPerSecond) const; double t0, double pixelsPerSecond) const;
bool GetMinMax(float *min, float *max, double t0, double t1) const; bool GetMinMax(float *min, float *max, double t0, double t1) const;
bool GetRMS(float *rms, double t0, double t1); bool GetRMS(float *rms, double t0, double t1);

View File

@ -314,7 +314,7 @@ void WaveTrack::GetSpectrumBounds(float *min, float *max) const
bottom = 0.0f; bottom = 0.0f;
else if (type == SpectrogramSettings::stPeriod) { else if (type == SpectrogramSettings::stPeriod) {
// special case // special case
const int half = settings.GetFFTLength() / 2; const auto half = settings.GetFFTLength() / 2;
// EAC returns no data for below this frequency: // EAC returns no data for below this frequency:
const float bin2 = rate / half; const float bin2 = rate / half;
bottom = bin2; bottom = bin2;

View File

@ -50,8 +50,8 @@ Param( MaximumPause, double, XO("MaximumPause"), 1.0, 0.0, DB
* Common constants * Common constants
*/ */
static const int kBufSize = 131072; // number of samples to process at once enum : size_t { kBufSize = 131072 }; // number of samples to process at once
static const int kRMSWindowSize = 100; // samples in circular RMS window buffer enum : size_t { kRMSWindowSize = 100 }; // samples in circular RMS window buffer
/* /*
* A auto duck region and an array of auto duck regions * A auto duck region and an array of auto duck regions

View File

@ -406,20 +406,20 @@ void EffectChangePitch::DeduceFrequencies()
// Aim for around 2048 samples at 44.1 kHz (good down to about 100 Hz). // Aim for around 2048 samples at 44.1 kHz (good down to about 100 Hz).
// To detect single notes, analysis period should be about 0.2 seconds. // To detect single notes, analysis period should be about 0.2 seconds.
// windowSize must be a power of 2. // windowSize must be a power of 2.
int windowSize = wxRound(pow(2.0, floor((log(rate / 20.0)/log(2.0)) + 0.5))); const size_t windowSize =
// windowSize < 256 too inaccurate // windowSize < 256 too inaccurate
windowSize = (windowSize > 256)? windowSize : 256; std::max(256, wxRound(pow(2.0, floor((log(rate / 20.0)/log(2.0)) + 0.5))));
// we want about 0.2 seconds to catch the first note. // we want about 0.2 seconds to catch the first note.
// number of windows rounded to nearest integer >= 1. // number of windows rounded to nearest integer >= 1.
int numWindows = wxRound((double)(rate / (5.0f * windowSize))); const unsigned numWindows =
numWindows = (numWindows > 0)? numWindows : 1; std::max(1, wxRound((double)(rate / (5.0f * windowSize))));
double trackStart = track->GetStartTime(); double trackStart = track->GetStartTime();
double t0 = mT0 < trackStart? trackStart: mT0; double t0 = mT0 < trackStart? trackStart: mT0;
auto start = track->TimeToLongSamples(t0); auto start = track->TimeToLongSamples(t0);
int analyzeSize = windowSize * numWindows; auto analyzeSize = windowSize * numWindows;
float * buffer; float * buffer;
buffer = new float[analyzeSize]; buffer = new float[analyzeSize];
@ -429,21 +429,18 @@ void EffectChangePitch::DeduceFrequencies()
float * freqa; float * freqa;
freqa = new float[windowSize / 2]; freqa = new float[windowSize / 2];
int i, j, argmax; for(size_t j = 0; j < windowSize / 2; j++)
int lag;
for(j=0; j<windowSize/2; j++)
freqa[j] = 0; freqa[j] = 0;
track->Get((samplePtr) buffer, floatSample, start, analyzeSize); track->Get((samplePtr) buffer, floatSample, start, analyzeSize);
for(i=0; i<numWindows; i++) { for(unsigned i = 0; i < numWindows; i++) {
ComputeSpectrum(buffer + i * windowSize, windowSize, ComputeSpectrum(buffer + i * windowSize, windowSize,
windowSize, rate, freq, true); windowSize, rate, freq, true);
for(j=0; j<windowSize/2; j++) for(size_t j = 0; j < windowSize / 2; j++)
freqa[j] += freq[j]; freqa[j] += freq[j];
} }
argmax=0; size_t argmax = 0;
for(j=1; j<windowSize/2; j++) for(size_t j = 1; j < windowSize / 2; j++)
if (freqa[j] > freqa[argmax]) if (freqa[j] > freqa[argmax])
argmax = j; argmax = j;
@ -451,7 +448,7 @@ void EffectChangePitch::DeduceFrequencies()
delete [] freqa; delete [] freqa;
delete [] buffer; delete [] buffer;
lag = (windowSize/2 - 1) - argmax; auto lag = (windowSize / 2 - 1) - argmax;
m_dStartFrequency = rate / lag; m_dStartFrequency = rate / lag;
} }

View File

@ -201,7 +201,8 @@ bool EffectClickRemoval::ProcessOne(int count, WaveTrack * track, sampleCount st
if (len <= windowSize / 2) if (len <= windowSize / 2)
{ {
wxMessageBox( wxMessageBox(
wxString::Format(_("Selection must be larger than %d samples."), windowSize/2), wxString::Format(_("Selection must be larger than %d samples."),
windowSize / 2),
GetName(), GetName(),
wxOK | wxICON_ERROR); wxOK | wxICON_ERROR);
return false; return false;
@ -215,27 +216,24 @@ bool EffectClickRemoval::ProcessOne(int count, WaveTrack * track, sampleCount st
decltype(len) s = 0; decltype(len) s = 0;
float *buffer = new float[idealBlockLen]; float *buffer = new float[idealBlockLen];
float *datawindow = new float[windowSize]; float *datawindow = new float[windowSize];
while ((s < len) && ((len - s) > windowSize/2)) while ((len - s) > windowSize / 2)
{ {
auto block = limitSampleBufferSize( idealBlockLen, len - s ); auto block = limitSampleBufferSize( idealBlockLen, len - s );
track->Get((samplePtr) buffer, floatSample, start + s, block); track->Get((samplePtr) buffer, floatSample, start + s, block);
for (int i=0; i < (block-windowSize/2); i += windowSize/2) for (decltype(block) i = 0; i + windowSize / 2 < block; i += windowSize / 2)
{ {
int wcopy = windowSize; auto wcopy = std::min( windowSize, block - i );
if (i + wcopy > block)
wcopy = block - i;
int j; for(decltype(wcopy) j = 0; j < wcopy; j++)
for(j=0; j<wcopy; j++)
datawindow[j] = buffer[i+j]; datawindow[j] = buffer[i+j];
for(j=wcopy; j<windowSize; j++) for(auto j = wcopy; j < windowSize; j++)
datawindow[j] = 0; datawindow[j] = 0;
mbDidSomething |= RemoveClicks(windowSize, datawindow); mbDidSomething |= RemoveClicks(windowSize, datawindow);
for(j=0; j<wcopy; j++) for(decltype(wcopy) j = 0; j < wcopy; j++)
buffer[i+j] = datawindow[j]; buffer[i+j] = datawindow[j];
} }

View File

@ -72,7 +72,7 @@ private:
Envelope *mEnvelope; Envelope *mEnvelope;
bool mbDidSomething; // This effect usually does nothing on real-world data. bool mbDidSomething; // This effect usually does nothing on real-world data.
int windowSize; size_t windowSize;
int mThresholdLevel; int mThresholdLevel;
int mClickWidth; int mClickWidth;
int sep; int sep;

View File

@ -434,7 +434,9 @@ bool EffectEqualization::Startup()
if (gPrefs->Exists(base)) if (gPrefs->Exists(base))
{ {
// These get saved to the current preset // These get saved to the current preset
gPrefs->Read(base + wxT("FilterLength"), &mM, 4001); int filterLength;
gPrefs->Read(base + wxT("FilterLength"), &filterLength, 4001);
mM = std::max(0, filterLength);
if ((mM < 21) || (mM > 8191)) { // corrupted Prefs? if ((mM < 21) || (mM > 8191)) { // corrupted Prefs?
mM = 4001; //default mM = 4001; //default
} }
@ -816,7 +818,7 @@ void EffectEqualization::PopulateOrExchange(ShuttleGui & S)
S.StartHorizontalLay(wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, 0); S.StartHorizontalLay(wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, 0);
{ {
wxString label; wxString label;
label.Printf(wxT("%d"), mM); label.Printf(wxT("%ld"), mM);
mMText = S.AddVariableText(label); mMText = S.AddVariableText(label);
mMText->SetName(label); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs) mMText->SetName(label); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
} }
@ -1060,7 +1062,8 @@ bool EffectEqualization::ProcessOne(int count, WaveTrack * t,
AudacityProject *p = GetActiveProject(); AudacityProject *p = GetActiveProject();
auto output = p->GetTrackFactory()->NewWaveTrack(floatSample, t->GetRate()); auto output = p->GetTrackFactory()->NewWaveTrack(floatSample, t->GetRate());
int L = windowSize - (mM - 1); //Process L samples at a go wxASSERT(mM - 1 < windowSize);
size_t L = windowSize - (mM - 1); //Process L samples at a go
auto s = start; auto s = start;
auto idealBlockLen = t->GetMaxBlockSize() * 4; auto idealBlockLen = t->GetMaxBlockSize() * 4;
if (idealBlockLen % L != 0) if (idealBlockLen % L != 0)
@ -1075,13 +1078,12 @@ bool EffectEqualization::ProcessOne(int count, WaveTrack * t,
auto originalLen = len; auto originalLen = len;
int i,j; for(size_t i = 0; i < windowSize; i++)
for(i=0; i<windowSize; i++)
lastWindow[i] = 0; lastWindow[i] = 0;
TrackProgress(count, 0.); TrackProgress(count, 0.);
bool bLoopSuccess = true; bool bLoopSuccess = true;
int wcopy = 0; size_t wcopy = 0;
int offset = (mM - 1) / 2; int offset = (mM - 1) / 2;
while (len != 0) while (len != 0)
@ -1090,20 +1092,20 @@ bool EffectEqualization::ProcessOne(int count, WaveTrack * t,
t->Get((samplePtr)buffer, floatSample, s, block); t->Get((samplePtr)buffer, floatSample, s, block);
for(i=0; i<block; i+=L) //go through block in lumps of length L for(size_t i = 0; i < block; i += L) //go through block in lumps of length L
{ {
wcopy = std::min <int> (L, block - i); wcopy = std::min <size_t> (L, block - i);
for(j=0; j<wcopy; j++) for(size_t j = 0; j < wcopy; j++)
thisWindow[j] = buffer[i+j]; //copy the L (or remaining) samples thisWindow[j] = buffer[i+j]; //copy the L (or remaining) samples
for(j=wcopy; j<windowSize; j++) for(auto j = wcopy; j < windowSize; j++)
thisWindow[j] = 0; //this includes the padding thisWindow[j] = 0; //this includes the padding
Filter(windowSize, thisWindow); Filter(windowSize, thisWindow);
// Overlap - Add // Overlap - Add
for(j=0; (j<mM-1) && (j<wcopy); j++) for(size_t j = 0; (j < mM - 1) && (j < wcopy); j++)
buffer[i+j] = thisWindow[j] + lastWindow[L + j]; buffer[i+j] = thisWindow[j] + lastWindow[L + j];
for(j=mM-1; j<wcopy; j++) for(size_t j = mM - 1; j < wcopy; j++)
buffer[i+j] = thisWindow[j]; buffer[i+j] = thisWindow[j];
float *tempP = thisWindow; float *tempP = thisWindow;
@ -1129,13 +1131,14 @@ bool EffectEqualization::ProcessOne(int count, WaveTrack * t,
// Still have some overlap left to process // Still have some overlap left to process
// (note that lastWindow and thisWindow have been exchanged at this point // (note that lastWindow and thisWindow have been exchanged at this point
// so that 'thisWindow' is really the window prior to 'lastWindow') // so that 'thisWindow' is really the window prior to 'lastWindow')
for(j=0; j<mM-1-wcopy; j++) size_t j = 0;
for(; j < mM - 1 - wcopy; j++)
buffer[j] = lastWindow[wcopy + j] + thisWindow[L + wcopy + j]; buffer[j] = lastWindow[wcopy + j] + thisWindow[L + wcopy + j];
// And fill in the remainder after the overlap // And fill in the remainder after the overlap
for( ; j < mM - 1; j++) for( ; j < mM - 1; j++)
buffer[j] = lastWindow[wcopy + j]; buffer[j] = lastWindow[wcopy + j];
} else { } else {
for(j=0; j<mM-1; j++) for(size_t j = 0; j < mM - 1; j++)
buffer[j] = lastWindow[wcopy + j]; buffer[j] = lastWindow[wcopy + j];
} }
output->Append((samplePtr)buffer, floatSample, mM - 1); output->Append((samplePtr)buffer, floatSample, mM - 1);
@ -1234,8 +1237,7 @@ bool EffectEqualization::CalcFilter()
mFilterFuncR[0] = val0; mFilterFuncR[0] = val0;
double freq = delta; double freq = delta;
int i; for(size_t i = 1; i <= mWindowSize / 2; i++)
for(i=1; i<=mWindowSize/2; i++)
{ {
double when; double when;
if( IsLinear() ) if( IsLinear() )
@ -1262,23 +1264,32 @@ bool EffectEqualization::CalcFilter()
mFilterFuncR[mWindowSize / 2] = val1; mFilterFuncR[mWindowSize / 2] = val1;
mFilterFuncR[0] = DB_TO_LINEAR(mFilterFuncR[0]); mFilterFuncR[0] = DB_TO_LINEAR(mFilterFuncR[0]);
for(i=1;i<mWindowSize/2;i++)
{
size_t i = 1;
for(; i < mWindowSize / 2; i++)
{ {
mFilterFuncR[i] = DB_TO_LINEAR(mFilterFuncR[i]); mFilterFuncR[i] = DB_TO_LINEAR(mFilterFuncR[i]);
mFilterFuncR[mWindowSize - i] = mFilterFuncR[i]; //Fill entire array mFilterFuncR[mWindowSize - i] = mFilterFuncR[i]; //Fill entire array
} }
mFilterFuncR[i] = DB_TO_LINEAR(mFilterFuncR[i]); //do last one mFilterFuncR[i] = DB_TO_LINEAR(mFilterFuncR[i]); //do last one
}
//transfer to time domain to do the padding and windowing //transfer to time domain to do the padding and windowing
float *outr = new float[mWindowSize]; float *outr = new float[mWindowSize];
float *outi = new float[mWindowSize]; float *outi = new float[mWindowSize];
InverseRealFFT(mWindowSize, mFilterFuncR, NULL, outr); // To time domain InverseRealFFT(mWindowSize, mFilterFuncR, NULL, outr); // To time domain
for(i=0;i<=(mM-1)/2;i++) {
size_t i = 0;
for(; i <= (mM - 1) / 2; i++)
{ //Windowing - could give a choice, fixed for now - MJS { //Windowing - could give a choice, fixed for now - MJS
// double mult=0.54-0.46*cos(2*M_PI*(i+(mM-1)/2.0)/(mM-1)); //Hamming // double mult=0.54-0.46*cos(2*M_PI*(i+(mM-1)/2.0)/(mM-1)); //Hamming
//Blackman //Blackman
double mult=0.42-0.5*cos(2*M_PI*(i+(mM-1)/2.0)/(mM-1))+.08*cos(4*M_PI*(i+(mM-1)/2.0)/(mM-1)); double mult =
0.42 -
0.5 * cos(2 * M_PI * (i + (mM - 1) / 2.0) / (mM - 1)) +
.08 * cos(4 * M_PI * (i + (mM - 1) / 2.0) / (mM - 1));
outr[i] *= mult; outr[i] *= mult;
if(i != 0){ if(i != 0){
outr[mWindowSize - i] *= mult; outr[mWindowSize - i] *= mult;
@ -1289,19 +1300,23 @@ bool EffectEqualization::CalcFilter()
outr[i] = 0; outr[i] = 0;
outr[mWindowSize - i] = 0; outr[mWindowSize - i] = 0;
} }
}
float *tempr = new float[mM]; float *tempr = new float[mM];
for(i=0;i<(mM-1)/2;i++) {
size_t i = 0;
for(; i < (mM - 1) / 2; i++)
{ //shift so that padding on right { //shift so that padding on right
tempr[(mM - 1) / 2 + i] = outr[i]; tempr[(mM - 1) / 2 + i] = outr[i];
tempr[i] = outr[mWindowSize - (mM - 1) / 2 + i]; tempr[i] = outr[mWindowSize - (mM - 1) / 2 + i];
} }
tempr[(mM - 1) / 2 + i] = outr[i]; tempr[(mM - 1) / 2 + i] = outr[i];
}
for(i=0;i<mM;i++) for(size_t i = 0; i < mM; i++)
{ //and copy useful values back { //and copy useful values back
outr[i] = tempr[i]; outr[i] = tempr[i];
} }
for(i=mM;i<mWindowSize;i++) for(size_t i = mM; i < mWindowSize; i++)
{ //rest is padding { //rest is padding
outr[i]=0.; outr[i]=0.;
} }
@ -1316,9 +1331,8 @@ bool EffectEqualization::CalcFilter()
return TRUE; return TRUE;
} }
void EffectEqualization::Filter(sampleCount len, float *buffer) void EffectEqualization::Filter(size_t len, float *buffer)
{ {
int i;
float re,im; float re,im;
// Apply FFT // Apply FFT
RealFFTf(buffer, hFFT); RealFFTf(buffer, hFFT);
@ -1327,7 +1341,7 @@ void EffectEqualization::Filter(sampleCount len, float *buffer)
// Apply filter // Apply filter
// DC component is purely real // DC component is purely real
mFFTBuffer[0] = buffer[0] * mFilterFuncR[0]; mFFTBuffer[0] = buffer[0] * mFilterFuncR[0];
for(i=1; i<(len/2); i++) for(size_t i = 1; i < (len / 2); i++)
{ {
re=buffer[hFFT->BitReversed[i] ]; re=buffer[hFFT->BitReversed[i] ];
im=buffer[hFFT->BitReversed[i]+1]; im=buffer[hFFT->BitReversed[i]+1];

View File

@ -124,7 +124,7 @@ private:
// EffectEqualization implementation // EffectEqualization implementation
// Number of samples in an FFT window // Number of samples in an FFT window
enum {windowSize=16384}; //MJS - work out the optimum for this at run time? Have a dialog box for it? enum : size_t {windowSize=16384}; //MJS - work out the optimum for this at run time? Have a dialog box for it?
// Low frequency of the FFT. 20Hz is the // Low frequency of the FFT. 20Hz is the
// low range of human hearing // low range of human hearing
@ -133,7 +133,7 @@ private:
bool ProcessOne(int count, WaveTrack * t, bool ProcessOne(int count, WaveTrack * t,
sampleCount start, sampleCount len); sampleCount start, sampleCount len);
bool CalcFilter(); bool CalcFilter();
void Filter(sampleCount len, float *buffer); void Filter(size_t len, float *buffer);
void Flatten(); void Flatten();
void ForceRecalc(); void ForceRecalc();
@ -193,7 +193,7 @@ private:
float *mFFTBuffer; float *mFFTBuffer;
float *mFilterFuncR; float *mFilterFuncR;
float *mFilterFuncI; float *mFilterFuncI;
int mM; size_t mM;
wxString mCurveName; wxString mCurveName;
bool mLin; bool mLin;
float mdBMax; float mdBMax;
@ -212,7 +212,7 @@ private:
bool mDisallowCustom; bool mDisallowCustom;
double mLoFreq; double mLoFreq;
double mHiFreq; double mHiFreq;
long mWindowSize; size_t mWindowSize;
bool mDirty; bool mDirty;
int mSlidersOld[NUMBER_OF_BANDS]; int mSlidersOld[NUMBER_OF_BANDS];
double mEQVals[NUMBER_OF_BANDS+1]; double mEQVals[NUMBER_OF_BANDS+1];
@ -315,7 +315,7 @@ private:
wxRect mEnvRect; wxRect mEnvRect;
int mWidth; int mWidth;
int mHeight; int mHeight;
// long mWindowSize; // size_t mWindowSize;
// float *mFilterFuncR; // float *mFilterFuncR;
// float *mFilterFuncI; // float *mFilterFuncI;
float *mOutr; float *mOutr;

View File

@ -180,6 +180,7 @@ bool EffectEqualization48x::AllocateBuffersWorkers(int nThreads)
FreeBuffersWorkers(); FreeBuffersWorkers();
mFilterSize=(mEffectEqualization->mM-1)&(~15); // 4000 !!! Filter MUST BE QUAD WORD ALIGNED !!!! mFilterSize=(mEffectEqualization->mM-1)&(~15); // 4000 !!! Filter MUST BE QUAD WORD ALIGNED !!!!
mWindowSize=mEffectEqualization->windowSize; mWindowSize=mEffectEqualization->windowSize;
wxASSERT(mFilterSize < mWindowSize);
mBlockSize=mWindowSize-mFilterSize; // 12,384 mBlockSize=mWindowSize-mFilterSize; // 12,384
mThreaded = (nThreads > 0 ); mThreaded = (nThreads > 0 );
if(mThreaded) if(mThreaded)
@ -680,7 +681,7 @@ bool EffectEqualization48x::ProcessOne1x(int count, WaveTrack * t,
return bBreakLoop; return bBreakLoop;
} }
void EffectEqualization48x::Filter1x(sampleCount len, void EffectEqualization48x::Filter1x(size_t len,
float *buffer, float *scratchBuffer) float *buffer, float *scratchBuffer)
{ {
int i; int i;
@ -694,7 +695,7 @@ void EffectEqualization48x::Filter1x(sampleCount len,
float filterFuncR, filterFuncI; float filterFuncR, filterFuncI;
filterFuncR = mEffectEqualization->mFilterFuncR[0]; filterFuncR = mEffectEqualization->mFilterFuncR[0];
scratchBuffer[0] = buffer[0] * filterFuncR; scratchBuffer[0] = buffer[0] * filterFuncR;
int halfLength=(len/2); auto halfLength = (len / 2);
bool useBitReverseTable=sMathPath&1; bool useBitReverseTable=sMathPath&1;
@ -973,7 +974,7 @@ bool EffectEqualization48x::ProcessOne1x4xThreaded(int count, WaveTrack * t,
return bBreakLoop; return bBreakLoop;
} }
void EffectEqualization48x::Filter4x(sampleCount len, void EffectEqualization48x::Filter4x(size_t len,
float *buffer, float *scratchBuffer) float *buffer, float *scratchBuffer)
{ {
int i; int i;
@ -989,7 +990,7 @@ void EffectEqualization48x::Filter4x(sampleCount len,
__m128 filterFuncR, filterFuncI; __m128 filterFuncR, filterFuncI;
filterFuncR = _mm_set1_ps(mEffectEqualization->mFilterFuncR[0]); filterFuncR = _mm_set1_ps(mEffectEqualization->mFilterFuncR[0]);
localFFTBuffer[0] = _mm_mul_ps(localBuffer[0], filterFuncR); localFFTBuffer[0] = _mm_mul_ps(localBuffer[0], filterFuncR);
int halfLength=(len/2); auto halfLength = (len / 2);
bool useBitReverseTable = sMathPath & 1; bool useBitReverseTable = sMathPath & 1;
@ -1273,7 +1274,7 @@ bool EffectEqualization48x::ProcessOne8xThreaded(int count, WaveTrack * t,
void EffectEqualization48x::Filter8x(sampleCount len, void EffectEqualization48x::Filter8x(size_t len,
float *buffer, float *scratchBuffer) float *buffer, float *scratchBuffer)
{ {
int i; int i;
@ -1289,7 +1290,7 @@ void EffectEqualization48x::Filter8x(sampleCount len,
__m256 filterFuncR, filterFuncI; __m256 filterFuncR, filterFuncI;
filterFuncR = _mm256_set1_ps(mEffectEqualization->mFilterFuncR[0]); filterFuncR = _mm256_set1_ps(mEffectEqualization->mFilterFuncR[0]);
localFFTBuffer[0] = _mm256_mul_ps(localBuffer[0], filterFuncR); localFFTBuffer[0] = _mm256_mul_ps(localBuffer[0], filterFuncR);
int halfLength=(len/2); auto halfLength = (len / 2);
bool useBitReverseTable = sMathPath & 1; bool useBitReverseTable = sMathPath & 1;

View File

@ -130,25 +130,25 @@ private:
bool ProcessBuffer(fft_type *sourceBuffer, fft_type *destBuffer, sampleCount bufferLength); bool ProcessBuffer(fft_type *sourceBuffer, fft_type *destBuffer, sampleCount bufferLength);
bool ProcessBuffer1x(BufferInfo *bufferInfo); bool ProcessBuffer1x(BufferInfo *bufferInfo);
bool ProcessOne1x(int count, WaveTrack * t, sampleCount start, sampleCount len); bool ProcessOne1x(int count, WaveTrack * t, sampleCount start, sampleCount len);
void Filter1x(sampleCount len, float *buffer, float *scratchBuffer); void Filter1x(size_t len, float *buffer, float *scratchBuffer);
bool ProcessBuffer4x(BufferInfo *bufferInfo); bool ProcessBuffer4x(BufferInfo *bufferInfo);
bool ProcessOne4x(int count, WaveTrack * t, sampleCount start, sampleCount len); bool ProcessOne4x(int count, WaveTrack * t, sampleCount start, sampleCount len);
bool ProcessOne1x4xThreaded(int count, WaveTrack * t, sampleCount start, sampleCount len, int processingType=4); bool ProcessOne1x4xThreaded(int count, WaveTrack * t, sampleCount start, sampleCount len, int processingType=4);
void Filter4x(sampleCount len, float *buffer, float *scratchBuffer); void Filter4x(size_t len, float *buffer, float *scratchBuffer);
#ifdef __AVX_ENABLED #ifdef __AVX_ENABLED
bool ProcessBuffer8x(BufferInfo *bufferInfo); bool ProcessBuffer8x(BufferInfo *bufferInfo);
bool ProcessOne8x(int count, WaveTrack * t, sampleCount start, sampleCount len); bool ProcessOne8x(int count, WaveTrack * t, sampleCount start, sampleCount len);
bool ProcessOne8xThreaded(int count, WaveTrack * t, sampleCount start, sampleCount len); bool ProcessOne8xThreaded(int count, WaveTrack * t, sampleCount start, sampleCount len);
void Filter8x(sampleCount len, float *buffer, float *scratchBuffer); void Filter8x(size_t len, float *buffer, float *scratchBuffer);
#endif #endif
EffectEqualization* mEffectEqualization; EffectEqualization* mEffectEqualization;
int mThreadCount; int mThreadCount;
sampleCount mFilterSize; size_t mFilterSize;
sampleCount mBlockSize; size_t mBlockSize;
sampleCount mWindowSize; size_t mWindowSize;
int mBufferCount; int mBufferCount;
int mWorkerDataCount; int mWorkerDataCount;
int mBlocksPerBuffer; int mBlocksPerBuffer;

View File

@ -121,7 +121,7 @@ enum WindowTypes {
const struct WindowTypesInfo { const struct WindowTypesInfo {
const wxChar *name; const wxChar *name;
int minSteps; unsigned minSteps;
double inCoefficients[3]; double inCoefficients[3];
double outCoefficients[3]; double outCoefficients[3];
double productConstantTerm; double productConstantTerm;
@ -159,7 +159,7 @@ enum NoiseReductionChoice {
class EffectNoiseReduction::Statistics class EffectNoiseReduction::Statistics
{ {
public: public:
Statistics(int spectrumSize, double rate, int windowTypes) Statistics(size_t spectrumSize, double rate, int windowTypes)
: mRate(rate) : mRate(rate)
, mWindowSize((spectrumSize - 1) * 2) , mWindowSize((spectrumSize - 1) * 2)
, mWindowTypes(windowTypes) , mWindowTypes(windowTypes)
@ -175,7 +175,7 @@ public:
// Noise profile statistics follow // Noise profile statistics follow
double mRate; // Rate of profile track(s) -- processed tracks must match double mRate; // Rate of profile track(s) -- processed tracks must match
int mWindowSize; size_t mWindowSize;
int mWindowTypes; int mWindowTypes;
int mTotalWindows; int mTotalWindows;
@ -206,8 +206,8 @@ public:
bool PrefsIO(bool read); bool PrefsIO(bool read);
bool Validate() const; bool Validate() const;
int WindowSize() const { return 1 << (3 + mWindowSizeChoice); } size_t WindowSize() const { return 1u << (3 + mWindowSizeChoice); }
int StepsPerWindow() const { return 1 << (1 + mStepsPerWindowChoice); } unsigned StepsPerWindow() const { return 1u << (1 + mStepsPerWindowChoice); }
bool mDoProfile; bool mDoProfile;
@ -286,7 +286,7 @@ private:
const double mSampleRate; const double mSampleRate;
const int mWindowSize; const size_t mWindowSize;
// These have that size: // These have that size:
HFFT hFFT; HFFT hFFT;
FloatVector mFFTBuffer; FloatVector mFFTBuffer;
@ -296,16 +296,16 @@ private:
FloatVector mInWindow; FloatVector mInWindow;
FloatVector mOutWindow; FloatVector mOutWindow;
const int mSpectrumSize; const size_t mSpectrumSize;
FloatVector mFreqSmoothingScratch; FloatVector mFreqSmoothingScratch;
const int mFreqSmoothingBins; const size_t mFreqSmoothingBins;
// When spectral selection limits the affected band: // When spectral selection limits the affected band:
int mBinLow; // inclusive lower bound int mBinLow; // inclusive lower bound
int mBinHigh; // exclusive upper bound int mBinHigh; // exclusive upper bound
const int mNoiseReductionChoice; const int mNoiseReductionChoice;
const int mStepsPerWindow; const unsigned mStepsPerWindow;
const int mStepSize; const size_t mStepSize;
const int mMethod; const int mMethod;
const double mNewSensitivity; const double mNewSensitivity;
@ -319,13 +319,13 @@ private:
float mNoiseAttenFactor; float mNoiseAttenFactor;
float mOldSensitivityFactor; float mOldSensitivityFactor;
int mNWindowsToExamine; unsigned mNWindowsToExamine;
int mCenter; unsigned mCenter;
int mHistoryLen; unsigned mHistoryLen;
struct Record struct Record
{ {
Record(int spectrumSize) Record(size_t spectrumSize)
: mSpectrums(spectrumSize) : mSpectrums(spectrumSize)
, mGains(spectrumSize) , mGains(spectrumSize)
, mRealFFTs(spectrumSize - 1) , mRealFFTs(spectrumSize - 1)
@ -608,7 +608,7 @@ bool EffectNoiseReduction::Process()
// Initialize statistics if gathering them, or check for mismatched (advanced) // Initialize statistics if gathering them, or check for mismatched (advanced)
// settings if reducing noise. // settings if reducing noise.
if (mSettings->mDoProfile) { if (mSettings->mDoProfile) {
int spectrumSize = 1 + mSettings->WindowSize() / 2; size_t spectrumSize = 1 + mSettings->WindowSize() / 2;
mStatistics = std::make_unique<Statistics> mStatistics = std::make_unique<Statistics>
(spectrumSize, track->GetRate(), mSettings->mWindowTypes); (spectrumSize, track->GetRate(), mSettings->mWindowTypes);
} }
@ -704,7 +704,7 @@ void EffectNoiseReduction::Worker::ApplyFreqSmoothing(FloatVector &gains)
gains[ii] = log(gains[ii]); gains[ii] = log(gains[ii]);
for (int ii = 0; ii < mSpectrumSize; ++ii) { for (int ii = 0; ii < mSpectrumSize; ++ii) {
const int j0 = std::max(0, ii - mFreqSmoothingBins); const int j0 = std::max(0, ii - (int)mFreqSmoothingBins);
const int j1 = std::min(mSpectrumSize - 1, ii + mFreqSmoothingBins); const int j1 = std::min(mSpectrumSize - 1, ii + mFreqSmoothingBins);
for(int jj = j0; jj <= j1; ++jj) { for(int jj = j0; jj <= j1; ++jj) {
mFreqSmoothingScratch[ii] += gains[jj]; mFreqSmoothingScratch[ii] += gains[jj];
@ -763,8 +763,8 @@ EffectNoiseReduction::Worker::Worker
#endif #endif
const double noiseGain = -settings.mNoiseGain; const double noiseGain = -settings.mNoiseGain;
const int nAttackBlocks = 1 + (int)(settings.mAttackTime * sampleRate / mStepSize); const unsigned nAttackBlocks = 1 + (int)(settings.mAttackTime * sampleRate / mStepSize);
const int nReleaseBlocks = 1 + (int)(settings.mReleaseTime * sampleRate / mStepSize); const unsigned nReleaseBlocks = 1 + (int)(settings.mReleaseTime * sampleRate / mStepSize);
// Applies to amplitudes, divide by 20: // Applies to amplitudes, divide by 20:
mNoiseAttenFactor = DB_TO_LINEAR(noiseGain); mNoiseAttenFactor = DB_TO_LINEAR(noiseGain);
// Apply to gain factors which apply to amplitudes, divide by 20: // Apply to gain factors which apply to amplitudes, divide by 20:
@ -794,7 +794,7 @@ EffectNoiseReduction::Worker::Worker
} }
mQueue.resize(mHistoryLen); mQueue.resize(mHistoryLen);
for (int ii = 0; ii < mHistoryLen; ++ii) for (unsigned ii = 0; ii < mHistoryLen; ++ii)
mQueue[ii] = make_movable<Record>(mSpectrumSize); mQueue[ii] = make_movable<Record>(mSpectrumSize);
// Create windows // Create windows
@ -823,7 +823,7 @@ EffectNoiseReduction::Worker::Worker
const double c1 = coefficients[1]; const double c1 = coefficients[1];
const double c2 = coefficients[2]; const double c2 = coefficients[2];
mInWindow.resize(mWindowSize); mInWindow.resize(mWindowSize);
for (int ii = 0; ii < mWindowSize; ++ii) for (size_t ii = 0; ii < mWindowSize; ++ii)
mInWindow[ii] = m * mInWindow[ii] = m *
(c0 + c1 * cos((2.0*M_PI*ii) / mWindowSize) (c0 + c1 * cos((2.0*M_PI*ii) / mWindowSize)
+ c2 * cos((4.0*M_PI*ii) / mWindowSize)); + c2 * cos((4.0*M_PI*ii) / mWindowSize));
@ -840,7 +840,7 @@ EffectNoiseReduction::Worker::Worker
case WT_HAMMING_INV_HAMMING: case WT_HAMMING_INV_HAMMING:
{ {
mOutWindow.resize(mWindowSize); mOutWindow.resize(mWindowSize);
for (int ii = 0; ii < mWindowSize; ++ii) for (size_t ii = 0; ii < mWindowSize; ++ii)
mOutWindow[ii] = multiplier / mInWindow[ii]; mOutWindow[ii] = multiplier / mInWindow[ii];
} }
break; break;
@ -852,7 +852,7 @@ EffectNoiseReduction::Worker::Worker
const double c1 = coefficients[1]; const double c1 = coefficients[1];
const double c2 = coefficients[2]; const double c2 = coefficients[2];
mOutWindow.resize(mWindowSize); mOutWindow.resize(mWindowSize);
for (int ii = 0; ii < mWindowSize; ++ii) for (size_t ii = 0; ii < mWindowSize; ++ii)
mOutWindow[ii] = multiplier * mOutWindow[ii] = multiplier *
(c0 + c1 * cos((2.0 * M_PI * ii) / mWindowSize) (c0 + c1 * cos((2.0 * M_PI * ii) / mWindowSize)
+ c2 * cos((4.0 * M_PI * ii) / mWindowSize)); + c2 * cos((4.0 * M_PI * ii) / mWindowSize));
@ -865,7 +865,7 @@ EffectNoiseReduction::Worker::Worker
void EffectNoiseReduction::Worker::StartNewTrack() void EffectNoiseReduction::Worker::StartNewTrack()
{ {
float *pFill; float *pFill;
for(int ii = 0; ii < mHistoryLen; ++ii) { for(unsigned ii = 0; ii < mHistoryLen; ++ii) {
Record &record = *mQueue[ii]; Record &record = *mQueue[ii];
pFill = &record.mSpectrums[0]; pFill = &record.mSpectrums[0];
@ -891,7 +891,7 @@ void EffectNoiseReduction::Worker::StartNewTrack()
{ {
// We do not want leading zero padded windows // We do not want leading zero padded windows
mInWavePos = 0; mInWavePos = 0;
mOutStepCount = -(mHistoryLen - 1); mOutStepCount = -(int)(mHistoryLen - 1);
} }
else else
{ {
@ -900,7 +900,7 @@ void EffectNoiseReduction::Worker::StartNewTrack()
// samples of wave data: // samples of wave data:
mInWavePos = mWindowSize - mStepSize; mInWavePos = mWindowSize - mStepSize;
// This starts negative, to count up until the queue fills: // This starts negative, to count up until the queue fills:
mOutStepCount = -(mHistoryLen - 1) mOutStepCount = -(int)(mHistoryLen - 1)
// ... and then must pass over the padded windows, // ... and then must pass over the padded windows,
// before the first full window: // before the first full window:
- (mStepsPerWindow - 1); - (mStepsPerWindow - 1);
@ -914,7 +914,7 @@ void EffectNoiseReduction::Worker::ProcessSamples
sampleCount len, float *buffer) sampleCount len, float *buffer)
{ {
while (len && mOutStepCount * mStepSize < mInSampleCount) { while (len && mOutStepCount * mStepSize < mInSampleCount) {
int avail = std::min(int(len), mWindowSize - mInWavePos); auto avail = std::min(len, sampleCount(mWindowSize - mInWavePos));
memmove(&mInWaveBuffer[mInWavePos], buffer, avail * sizeof(float)); memmove(&mInWaveBuffer[mInWavePos], buffer, avail * sizeof(float));
buffer += avail; buffer += avail;
len -= avail; len -= avail;
@ -941,7 +941,7 @@ void EffectNoiseReduction::Worker::FillFirstHistoryWindow()
{ {
// Transform samples to frequency domain, windowed as needed // Transform samples to frequency domain, windowed as needed
if (mInWindow.size() > 0) if (mInWindow.size() > 0)
for (int ii = 0; ii < mWindowSize; ++ii) for (size_t ii = 0; ii < mWindowSize; ++ii)
mFFTBuffer[ii] = mInWaveBuffer[ii] * mInWindow[ii]; mFFTBuffer[ii] = mInWaveBuffer[ii] * mInWindow[ii];
else else
memmove(&mFFTBuffer[0], &mInWaveBuffer[0], mWindowSize * sizeof(float)); memmove(&mFFTBuffer[0], &mInWaveBuffer[0], mWindowSize * sizeof(float));
@ -956,7 +956,7 @@ void EffectNoiseReduction::Worker::FillFirstHistoryWindow()
float *pImag = &record.mImagFFTs[1]; float *pImag = &record.mImagFFTs[1];
float *pPower = &record.mSpectrums[1]; float *pPower = &record.mSpectrums[1];
int *pBitReversed = &hFFT->BitReversed[1]; int *pBitReversed = &hFFT->BitReversed[1];
const int last = mSpectrumSize - 1; const auto last = mSpectrumSize - 1;
for (int ii = 1; ii < last; ++ii) { for (int ii = 1; ii < last; ++ii) {
const int kk = *pBitReversed++; const int kk = *pBitReversed++;
const float realPart = *pReal++ = mFFTBuffer[kk]; const float realPart = *pReal++ = mFFTBuffer[kk];
@ -1043,7 +1043,7 @@ void EffectNoiseReduction::Worker::GatherStatistics(Statistics &statistics)
// level achieved at that frequency for a minimum of // level achieved at that frequency for a minimum of
// mMinSignalBlocks blocks in a row - the max of a min. // mMinSignalBlocks blocks in a row - the max of a min.
int finish = mHistoryLen; auto finish = mHistoryLen;
{ {
// old statistics // old statistics
@ -1051,7 +1051,7 @@ void EffectNoiseReduction::Worker::GatherStatistics(Statistics &statistics)
float *pThreshold = &statistics.mNoiseThreshold[0]; float *pThreshold = &statistics.mNoiseThreshold[0];
for (int jj = 0; jj < mSpectrumSize; ++jj) { for (int jj = 0; jj < mSpectrumSize; ++jj) {
float min = *pPower++; float min = *pPower++;
for (int ii = 1; ii < finish; ++ii) for (unsigned ii = 1; ii < finish; ++ii)
min = std::min(min, mQueue[ii]->mSpectrums[jj]); min = std::min(min, mQueue[ii]->mSpectrums[jj]);
*pThreshold = std::max(*pThreshold, min); *pThreshold = std::max(*pThreshold, min);
++pThreshold; ++pThreshold;
@ -1070,7 +1070,7 @@ bool EffectNoiseReduction::Worker::Classify(const Statistics &statistics, int ba
case DM_OLD_METHOD: case DM_OLD_METHOD:
{ {
float min = mQueue[0]->mSpectrums[band]; float min = mQueue[0]->mSpectrums[band];
for (int ii = 1; ii < mNWindowsToExamine; ++ii) for (unsigned ii = 1; ii < mNWindowsToExamine; ++ii)
min = std::min(min, mQueue[ii]->mSpectrums[band]); min = std::min(min, mQueue[ii]->mSpectrums[band]);
return min <= mOldSensitivityFactor * statistics.mNoiseThreshold[band]; return min <= mOldSensitivityFactor * statistics.mNoiseThreshold[band];
} }
@ -1094,7 +1094,7 @@ bool EffectNoiseReduction::Worker::Classify(const Statistics &statistics, int ba
else if (mNWindowsToExamine == 5) else if (mNWindowsToExamine == 5)
{ {
float greatest = 0.0, second = 0.0, third = 0.0; float greatest = 0.0, second = 0.0, third = 0.0;
for (int ii = 0; ii < mNWindowsToExamine; ++ii) { for (unsigned ii = 0; ii < mNWindowsToExamine; ++ii) {
const float power = mQueue[ii]->mSpectrums[band]; const float power = mQueue[ii]->mSpectrums[band];
if (power >= greatest) if (power >= greatest)
third = second, second = greatest, greatest = power; third = second, second = greatest, greatest = power;
@ -1116,7 +1116,7 @@ bool EffectNoiseReduction::Worker::Classify(const Statistics &statistics, int ba
// should be less prone to distortions and more prone to // should be less prone to distortions and more prone to
// chimes. // chimes.
float greatest = 0.0, second = 0.0; float greatest = 0.0, second = 0.0;
for (int ii = 0; ii < mNWindowsToExamine; ++ii) { for (unsigned ii = 0; ii < mNWindowsToExamine; ++ii) {
const float power = mQueue[ii]->mSpectrums[band]; const float power = mQueue[ii]->mSpectrums[band];
if (power >= greatest) if (power >= greatest)
second = greatest, greatest = power; second = greatest, greatest = power;
@ -1171,7 +1171,7 @@ void EffectNoiseReduction::Worker::ReduceNoise
// First, the attack, which goes backward in time, which is, // First, the attack, which goes backward in time, which is,
// toward higher indices in the queue. // toward higher indices in the queue.
for (int jj = 0; jj < mSpectrumSize; ++jj) { for (int jj = 0; jj < mSpectrumSize; ++jj) {
for (int ii = mCenter + 1; ii < mHistoryLen; ++ii) { for (unsigned ii = mCenter + 1; ii < mHistoryLen; ++ii) {
const float minimum = const float minimum =
std::max(mNoiseAttenFactor, std::max(mNoiseAttenFactor,
mQueue[ii - 1]->mGains[jj] * mOneBlockAttack); mQueue[ii - 1]->mGains[jj] * mOneBlockAttack);
@ -1204,7 +1204,7 @@ void EffectNoiseReduction::Worker::ReduceNoise
if (mOutStepCount >= -(mStepsPerWindow - 1)) { if (mOutStepCount >= -(mStepsPerWindow - 1)) {
Record &record = *mQueue[mHistoryLen - 1]; // end of the queue Record &record = *mQueue[mHistoryLen - 1]; // end of the queue
const int last = mSpectrumSize - 1; const auto last = mSpectrumSize - 1;
if (mNoiseReductionChoice != NRC_ISOLATE_NOISE) if (mNoiseReductionChoice != NRC_ISOLATE_NOISE)
// Apply frequency smoothing to output gain // Apply frequency smoothing to output gain
@ -1217,7 +1217,7 @@ void EffectNoiseReduction::Worker::ReduceNoise
const float *pReal = &record.mRealFFTs[1]; const float *pReal = &record.mRealFFTs[1];
const float *pImag = &record.mImagFFTs[1]; const float *pImag = &record.mImagFFTs[1];
float *pBuffer = &mFFTBuffer[2]; float *pBuffer = &mFFTBuffer[2];
int nn = mSpectrumSize - 2; auto nn = mSpectrumSize - 2;
if (mNoiseReductionChoice == NRC_LEAVE_RESIDUE) { if (mNoiseReductionChoice == NRC_LEAVE_RESIDUE) {
for (; nn--;) { for (; nn--;) {
// Subtract the gain we would otherwise apply from 1, and // Subtract the gain we would otherwise apply from 1, and

View File

@ -363,7 +363,7 @@ void EffectNoiseRemoval::StartNewTrack()
mInputPos = 0; mInputPos = 0;
mInSampleCount = 0; mInSampleCount = 0;
mOutSampleCount = -(mWindowSize / 2) * (mHistoryLen - 1); mOutSampleCount = -(int)((mWindowSize / 2) * (mHistoryLen - 1));
} }
void EffectNoiseRemoval::ProcessSamples(sampleCount len, float *buffer) void EffectNoiseRemoval::ProcessSamples(sampleCount len, float *buffer)

View File

@ -69,7 +69,7 @@ private:
// Parameters chosen before the first phase // Parameters chosen before the first phase
double mSampleRate; double mSampleRate;
int mWindowSize; size_t mWindowSize;
int mSpectrumSize; int mSpectrumSize;
float mMinSignalTime; // in secs float mMinSignalTime; // in secs

View File

@ -28,7 +28,6 @@ for classification of the sample format and the used endianness.
#include <wx/defs.h> #include <wx/defs.h>
#include "MultiFormatReader.h" #include "MultiFormatReader.h"
#include "SpecPowerMeter.h"
#include "sndfile.h" #include "sndfile.h"
FormatClassifier::FormatClassifier(const char* filename) : FormatClassifier::FormatClassifier(const char* filename) :

View File

@ -52,7 +52,6 @@ and sample size to help you importing data of an unknown format.
// #include "RawAudioGuess.h" // #include "RawAudioGuess.h"
#include "MultiFormatReader.h" #include "MultiFormatReader.h"
#include "SpecPowerMeter.h"
#include "FormatClassifier.h" #include "FormatClassifier.h"
#include "sndfile.h" #include "sndfile.h"

View File

@ -24,9 +24,9 @@ measurements in subbands or in the entire signal band.
#include "../FFT.h" #include "../FFT.h"
SpecPowerMeter::SpecPowerMeter(int sigLen) SpecPowerMeter::SpecPowerMeter(size_t sigLen)
: mSigLen(sigLen)
{ {
mSigLen = sigLen;
// Init buffers // Init buffers
mSigI = new float[sigLen]; mSigI = new float[sigLen];
@ -85,7 +85,7 @@ int SpecPowerMeter::Freq2Bin(float fc)
// There is no round() in (older) MSVSs ... // There is no round() in (older) MSVSs ...
bin = floor((double)fc * mSigLen); bin = floor((double)fc * mSigLen);
bin %= mSigLen; bin %= (int)mSigLen;
return bin; return bin;
} }

View File

@ -11,9 +11,11 @@
#ifndef __AUDACITY_SPECPOWERMETER_H_ #ifndef __AUDACITY_SPECPOWERMETER_H_
#define __AUDACITY_SPECPOWERMETER_H_ #define __AUDACITY_SPECPOWERMETER_H_
#include <cstddef>
class SpecPowerMeter class SpecPowerMeter
{ {
int mSigLen; const size_t mSigLen;
float* mSigI; float* mSigI;
float* mSigFR; float* mSigFR;
@ -22,7 +24,7 @@ class SpecPowerMeter
float CalcBinPower(float* sig_f_r, float* sig_f_i, int loBin, int hiBin); float CalcBinPower(float* sig_f_r, float* sig_f_i, int loBin, int hiBin);
int Freq2Bin(float fc); int Freq2Bin(float fc);
public: public:
SpecPowerMeter(int sigLen); SpecPowerMeter(size_t sigLen);
~SpecPowerMeter(); ~SpecPowerMeter();
float CalcPower(float* sig, float fc, float bw); float CalcPower(float* sig, float fc, float bw);

View File

@ -371,8 +371,8 @@ namespace
{ {
enum { WINDOW, TWINDOW, DWINDOW }; enum { WINDOW, TWINDOW, DWINDOW };
void RecreateWindow( void RecreateWindow(
float *&window, int which, int fftLen, float *&window, int which, size_t fftLen,
int padding, int windowType, int windowSize, double &scale) size_t padding, int windowType, size_t windowSize, double &scale)
{ {
if (window != NULL) if (window != NULL)
delete[] window; delete[] window;
@ -402,7 +402,7 @@ namespace
// Future, reassignment // Future, reassignment
case TWINDOW: case TWINDOW:
NewWindowFunc(windowType, windowSize, extra, window + padding); NewWindowFunc(windowType, windowSize, extra, window + padding);
for (int ii = padding, multiplier = -windowSize / 2; ii < endOfWindow; ++ii, ++multiplier) for (int ii = padding, multiplier = -(int)windowSize / 2; ii < endOfWindow; ++ii, ++multiplier)
window[ii] *= multiplier; window[ii] *= multiplier;
break; break;
case DWINDOW: case DWINDOW:
@ -429,8 +429,8 @@ void SpectrogramSettings::CacheWindows() const
if (hFFT == NULL || window == NULL) { if (hFFT == NULL || window == NULL) {
double scale; double scale;
const int fftLen = windowSize * zeroPaddingFactor; const auto fftLen = WindowSize() * ZeroPaddingFactor();
const int padding = (windowSize * (zeroPaddingFactor - 1)) / 2; const auto padding = (windowSize * (zeroPaddingFactor - 1)) / 2;
if (hFFT != NULL) if (hFFT != NULL)
EndFFT(hFFT); EndFFT(hFFT);
@ -475,7 +475,7 @@ void SpectrogramSettings::ConvertToActualWindowSizes()
#endif #endif
} }
int SpectrogramSettings::GetFFTLength() const size_t SpectrogramSettings::GetFFTLength() const
{ {
return windowSize return windowSize
#ifdef EXPERIMENTAL_ZERO_PADDED_SPECTROGRAMS #ifdef EXPERIMENTAL_ZERO_PADDED_SPECTROGRAMS
@ -488,7 +488,7 @@ NumberScale SpectrogramSettings::GetScale
(float minFreq, float maxFreq, double rate, bool bins) const (float minFreq, float maxFreq, double rate, bool bins) const
{ {
NumberScaleType type = nstLinear; NumberScaleType type = nstLinear;
const int half = GetFFTLength() / 2; const auto half = GetFFTLength() / 2;
// Don't assume the correspondence of the enums will remain direct in the future. // Don't assume the correspondence of the enums will remain direct in the future.
// Do this switch. // Do this switch.

View File

@ -100,12 +100,20 @@ public:
int frequencyGain; int frequencyGain;
int windowType; int windowType;
private:
int windowSize; int windowSize;
public:
size_t WindowSize() const { return windowSize; }
#ifdef EXPERIMENTAL_ZERO_PADDED_SPECTROGRAMS #ifdef EXPERIMENTAL_ZERO_PADDED_SPECTROGRAMS
private:
int zeroPaddingFactor; int zeroPaddingFactor;
public:
size_t ZeroPaddingFactor() const { return zeroPaddingFactor; }
#endif #endif
int GetFFTLength() const; // window size (times zero padding, if STFT) size_t GetFFTLength() const; // window size (times zero padding, if STFT)
bool isGrayscale; bool isGrayscale;

View File

@ -51,7 +51,7 @@ SpectrumPrefs::SpectrumPrefs(wxWindow * parent, WaveTrack *wt)
mDefaulted = false; mDefaulted = false;
} }
const int windowSize = mTempSettings.windowSize; const auto windowSize = mTempSettings.WindowSize();
mTempSettings.ConvertToEnumeratedWindowSizes(); mTempSettings.ConvertToEnumeratedWindowSizes();
Populate(windowSize); Populate(windowSize);
} }
@ -78,7 +78,7 @@ enum {
ID_DEFAULTS, ID_DEFAULTS,
}; };
void SpectrumPrefs::Populate(int windowSize) void SpectrumPrefs::Populate(size_t windowSize)
{ {
mSizeChoices.Add(_("8 - most wideband")); mSizeChoices.Add(_("8 - most wideband"));
mSizeChoices.Add(wxT("16")); mSizeChoices.Add(wxT("16"));
@ -112,7 +112,7 @@ void SpectrumPrefs::Populate(int windowSize)
// ----------------------- End of main section -------------- // ----------------------- End of main section --------------
} }
void SpectrumPrefs::PopulatePaddingChoices(int windowSize) void SpectrumPrefs::PopulatePaddingChoices(size_t windowSize)
{ {
#ifdef EXPERIMENTAL_ZERO_PADDED_SPECTROGRAMS #ifdef EXPERIMENTAL_ZERO_PADDED_SPECTROGRAMS
mZeroPaddingChoice = 1; mZeroPaddingChoice = 1;
@ -132,9 +132,9 @@ void SpectrumPrefs::PopulatePaddingChoices(int windowSize)
pPaddingSizeControl->Clear(); pPaddingSizeControl->Clear();
} }
int padding = 1; unsigned padding = 1;
int numChoices = 0; int numChoices = 0;
const int maxWindowSize = 1 << (SpectrogramSettings::LogMaxWindowSize); const size_t maxWindowSize = 1 << (SpectrogramSettings::LogMaxWindowSize);
while (windowSize <= maxWindowSize) { while (windowSize <= maxWindowSize) {
const wxString numeral = wxString::Format(wxT("%d"), padding); const wxString numeral = wxString::Format(wxT("%d"), padding);
mZeroPaddingChoices.Add(numeral); mZeroPaddingChoices.Add(numeral);
@ -449,7 +449,7 @@ void SpectrumPrefs::OnWindowSize(wxCommandEvent &evt)
// size and padding may not exceed the largest window size. // size and padding may not exceed the largest window size.
wxChoice *const pWindowSizeControl = wxChoice *const pWindowSizeControl =
static_cast<wxChoice*>(wxWindow::FindWindowById(ID_WINDOW_SIZE, this)); static_cast<wxChoice*>(wxWindow::FindWindowById(ID_WINDOW_SIZE, this));
int windowSize = 1 << size_t windowSize = 1 <<
(pWindowSizeControl->GetSelection() + SpectrogramSettings::LogMinWindowSize); (pWindowSizeControl->GetSelection() + SpectrogramSettings::LogMinWindowSize);
PopulatePaddingChoices(windowSize); PopulatePaddingChoices(windowSize);

View File

@ -48,8 +48,8 @@ class SpectrumPrefs final : public PrefsPanel
bool Validate() override; bool Validate() override;
private: private:
void Populate(int windowSize); void Populate(size_t windowSize);
void PopulatePaddingChoices(int windowSize); void PopulatePaddingChoices(size_t windowSize);
void PopulateOrExchange(ShuttleGui & S); void PopulateOrExchange(ShuttleGui & S);
void OnControl(wxCommandEvent &event); void OnControl(wxCommandEvent &event);