Skip to content

Commit

Permalink
Use std namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexHarker committed Aug 8, 2022
1 parent 2c5ce17 commit c7b09d0
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 32 deletions.
6 changes: 3 additions & 3 deletions FrameLib_Dependencies/RandomGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ class random_generator
R = (x * x) + (y * y);
}

R = sqrt((-2.0 * log(R)) / R);
R = sqrt((-2.0 * std::log(R)) / R);
}

// This is adapted from http://home.online.no/~pjacklam/notes/invnorm/impl/sprouse/ltqnorm.c
Expand Down Expand Up @@ -310,15 +310,15 @@ class random_generator
{
/* Rational approximation for lower region */

q = sqrt(-2.0*log(p));
q = sqrt(-2.0*std::log(p));
return (((((c[0]*q+c[1])*q+c[2])*q+c[3])*q+c[4])*q+c[5]) /
((((d[0]*q+d[1])*q+d[2])*q+d[3])*q+1);
}
else if (p > high)
{
/* Rational approximation for upper region */

q = sqrt(-2.0*log(1-p));
q = sqrt(-2.0*std::log(1-p));
return -(((((c[0]*q+c[1])*q+c[2])*q+c[3])*q+c[4])*q+c[5]) /
((((d[0]*q+d[1])*q+d[2])*q+d[3])*q+1);
}
Expand Down
2 changes: 1 addition & 1 deletion FrameLib_Dependencies/SpectralFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ namespace impl
void operator()(T& r_out, T& i_out, const T& r_in, const T& i_in, uintptr_t i)
{
static T min_power = std::pow(10.0, -300.0 / 10.0);
store(r_out, i_out, T(0.5) * log(std::max(r_in * r_in + i_in * i_in, min_power)), T(0));
store(r_out, i_out, T(0.5) * std::log(std::max(r_in * r_in + i_in * i_in, min_power)), T(0));
}
};

Expand Down
14 changes: 7 additions & 7 deletions FrameLib_Dependencies/Statistics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ namespace impl
struct pow3 { template <class T> T operator()(T a) const { return a * a * a; } };
struct pow4 { template <class T> T operator()(T a) const { return pow2()(pow2()(a)); } };
struct absolute { template <class T> T operator()(T a) const { return std::abs(a); } };
struct logarithm { template <class T> T operator()(T a) const { return log(a); } };
struct logarithm { template <class T> T operator()(T a) const { return std::log(a); } };

struct indices { template <class T> double operator[](T a) const { return static_cast<double>(a); } };
struct log_indices { template <class T> double operator[](T a) const { return a ? log2(static_cast<double>(a)) : 0.0; } };
struct log_indices { template <class T> double operator[](T a) const { return a ? std::log2(static_cast<double>(a)) : 0.0; } };

template <class T, typename Op>
struct modified_data
Expand Down Expand Up @@ -256,7 +256,7 @@ double stat_mean_squares(const T input, size_t size)
template <class T>
double stat_geometric_mean(const T input, size_t size)
{
return exp(stat_sum_logs(input, size) / stat_length(input, size));
return std::exp(stat_sum_logs(input, size) / stat_length(input, size));
}

// Variance
Expand Down Expand Up @@ -331,30 +331,30 @@ double stat_kurtosis(const T input, size_t size)
template <class T>
double stat_log_centroid(const T input, size_t size)
{
return exp2(stat_weighted_sum(impl::log_indices(), input, size) / (stat_sum(input, size)));
return std::exp2(stat_weighted_sum(impl::log_indices(), input, size) / (stat_sum(input, size)));
}

template <class T>
double stat_log_spread(const T input, size_t size)
{
double centroid = stat_log_centroid(input, size);
return sqrt(stat_weighted_sum(impl::log_indices_diff_op<impl::pow2>(log2(centroid)), input, size) / stat_sum(input, size));
return sqrt(stat_weighted_sum(impl::log_indices_diff_op<impl::pow2>(std::log2(centroid)), input, size) / stat_sum(input, size));
}

template <class T>
double stat_log_skewness(const T input, size_t size)
{
double centroid = stat_log_centroid(input, size);
double denominator = impl::pow3()(stat_log_spread(input, size)) * stat_sum(input, size);
return denominator ? stat_weighted_sum(impl::log_indices_diff_op<impl::pow3>(log2(centroid)), input, size) / denominator : 0.0;
return denominator ? stat_weighted_sum(impl::log_indices_diff_op<impl::pow3>(std::log2(centroid)), input, size) / denominator : 0.0;
}

template <class T>
double stat_log_kurtosis(const T input, size_t size)
{
double centroid = stat_log_centroid(input, size);
double denominator = impl::pow4()(stat_log_spread(input, size)) * stat_sum(input, size);
return denominator ? stat_weighted_sum(impl::log_indices_diff_op<impl::pow4>(log2(centroid)), input, size) / denominator : std::numeric_limits<double>::infinity();
return denominator ? stat_weighted_sum(impl::log_indices_diff_op<impl::pow4>(std::log2(centroid)), input, size) / denominator : std::numeric_limits<double>::infinity();
}

// Flatness
Expand Down
2 changes: 1 addition & 1 deletion FrameLib_Framework/FrameLib_FixedPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ FL_FP::FL_FP(const double& val)
else
{
mInt = static_cast<uint64_t>(absVal);
mFrac = static_cast<uint64_t>(round((absVal - floor(absVal)) * 18446744073709551616.0));
mFrac = static_cast<uint64_t>(round((absVal - std::floor(absVal)) * 18446744073709551616.0));
}
}

Expand Down
26 changes: 13 additions & 13 deletions FrameLib_Objects/Common_Utilities/FrameLib_Scaling_Functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@
// Common Conversions

template <class T>
T dbToAmp(T x) { return pow(10.0, x / 20.0); }
T dbToAmp(T x) { return std::pow(10.0, x / 20.0); }

template <class T>
T ampToDb(T x) { return log10(x) * 20.0; }
T ampToDb(T x) { return std::log10(x) * 20.0; }

template <class T>
T midiToFreq(T x) { return exp2((x - 69.0) / 12.0) * 440.0; }
T midiToFreq(T x) { return std::exp2((x - 69.0) / 12.0) * 440.0; }

template <class T>
T freqToMidi(T x) { return log2(x / 440.0) * 12.0 + 69.0; }
T freqToMidi(T x) { return std::log2(x / 440.0) * 12.0 + 69.0; }

template <class T>
T semitonesToRatio(T x) { return exp2(x / 12.0); }
T semitonesToRatio(T x) { return std::exp2(x / 12.0); }

template <class T>
T ratioToSemitones(T x) { return log2(x) * 12.0; }
T ratioToSemitones(T x) { return std::log2(x) * 12.0; }

// Scaling of Vectors

Expand Down Expand Up @@ -69,17 +69,17 @@ struct LinScaler : public ScaleCoefficients<T>
template <class T>
struct LogScaler : public ScaleCoefficients<T>
{
LogScaler(T inLo, T inHi, T outLo, T outHi) : ScaleCoefficients<T>(log(inLo), log(inHi), outLo, outHi) {}
LogScaler(T inLo, T inHi, T outLo, T outHi) : ScaleCoefficients<T>(std::log(inLo), std::log(inHi), outLo, outHi) {}
LogScaler(const ScaleCoefficients<T>& coeff) : ScaleCoefficients<T>(coeff) {}

template <class U> U operator()(U x) const { return log(x) * ScaleCoefficients<T>::mMul - ScaleCoefficients<T>::mSub; }
template <class U> U operator()(U x) const { return std::log(x) * ScaleCoefficients<T>::mMul - ScaleCoefficients<T>::mSub; }
template <class U> void operator()(U *output, const U *input, unsigned long size) const { scaleVector(output, input, size, *this); }
};

template <class T>
struct ExpScaler : public ScaleCoefficients<T>
{
ExpScaler(T inLo, T inHi, T outLo, T outHi) : ScaleCoefficients<T>(inLo, inHi, log(outLo), log(outHi)) {}
ExpScaler(T inLo, T inHi, T outLo, T outHi) : ScaleCoefficients<T>(inLo, inHi, std::log(outLo), std::log(outHi)) {}
ExpScaler(const ScaleCoefficients<T>& coeff) : ScaleCoefficients<T>(coeff) {}

template <class U> U operator()(U x) const { return exp((x * ScaleCoefficients<T>::mMul) - ScaleCoefficients<T>::mSub); }
Expand All @@ -100,7 +100,7 @@ struct PowScaler
exponent = mExponent;
}

template <class U> U operator()(U x) const { return mOutputScaler(pow(mInputScaler(x), mExponent)); }
template <class U> U operator()(U x) const { return mOutputScaler(std::pow(mInputScaler(x), mExponent)); }
template <class U> void operator()(U *output, const U *input, unsigned long size) const { scaleVector(output, input, size, *this); }

LinScaler<T> mInputScaler;
Expand Down Expand Up @@ -135,22 +135,22 @@ LinClipScaler : public ClipScaler<T, LinScaler<T>>
template <class T>
struct LogClipScaler : public ClipScaler<T, LogScaler<T>>
{
LogClipScaler(T inLo, T inHi, T outLo, T outHi) : ClipScaler<T, LogScaler<T>>(log(inLo), log(inHi), outLo, outHi) {}
LogClipScaler(T inLo, T inHi, T outLo, T outHi) : ClipScaler<T, LogScaler<T>>(std::log(inLo), std::log(inHi), outLo, outHi) {}
LogClipScaler(const ScaleCoefficients<T>& coeff, T min, T max) : ClipScaler<T, LogScaler<T>>(LogScaler<T>(coeff), min, max) {}
};

template <class T>
struct ExpClipScaler : public ClipScaler<T, ExpScaler<T>>
{
ExpClipScaler(T inLo, T inHi, T outLo, T outHi) : ClipScaler<T, ExpScaler<T>>(ExpScaler<T>(inLo, inHi, log(outLo), log(outHi)), outLo, outHi) {}
ExpClipScaler(T inLo, T inHi, T outLo, T outHi) : ClipScaler<T, ExpScaler<T>>(ExpScaler<T>(inLo, inHi, std::log(outLo), std::log(outHi)), outLo, outHi) {}
ExpClipScaler(const ScaleCoefficients<T>& coeff, T min, T max) : ClipScaler<T, ExpScaler<T>>(ExpScaler<T>(coeff), min, max) {}
};

template <class T>
struct PowClipScaler : public ClipScaler<T, PowScaler<T>>
{
PowClipScaler(T inLo, T inHi, T outLo, T outHi, T exponent)
: ClipScaler<T, PowScaler<T>>(PowScaler<T>(inLo, inHi, log(outLo), log(outHi)), outLo, outHi, exponent) {}
: ClipScaler<T, PowScaler<T>>(PowScaler<T>(inLo, inHi, std::log(outLo), std::log(outHi)), outLo, outHi, exponent) {}
PowClipScaler(const ScaleCoefficients<T>& inCoeff, const ScaleCoefficients<T>& outCoeff, T exponent, T min, T max)
: ClipScaler<T, PowScaler<T>>(PowScaler<T>(inCoeff, outCoeff, exponent), min, max) {}
};
Expand Down
4 changes: 2 additions & 2 deletions FrameLib_Objects/Spatial/FrameLib_Spatial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ void FrameLib_Spatial::process()
const double rolloff = mParameters.getValue(kRolloff);
const double pointFactor = mParameters.getValue(kPointFactor);

const double rolloffFactor = rolloff / (20 * log10(2.0));
const double rolloffFactor = rolloff / (20 * std::log10(2.0));
const double blur2 = blur * blur;

maxSpeakers = maxSpeakers == 0 ? numSpeakers : maxSpeakers;
Expand Down Expand Up @@ -573,7 +573,7 @@ void FrameLib_Spatial::process()
double sqDistance = xDelta * xDelta + yDelta * yDelta + zDelta * zDelta;
double weight = i < weightsSize ? weights[i] : 1.0;

coefficients[i] = weight / pow(sqDistance + blur2, 0.5 * rolloffFactor);
coefficients[i] = weight / std::pow(sqDistance + blur2, 0.5 * rolloffFactor);

if (i == 0 || (sqDistance < minDistance))
{
Expand Down
4 changes: 2 additions & 2 deletions FrameLib_Objects/Time_Smoothing/FrameLib_TimeMedian.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ void FrameLib_TimeMedian::resetSize(unsigned long maxFrames, unsigned long size)

bool compareLess(double a, double b)
{
return (a < b || (isnan(b) && !isnan(a)));
return (a < b || (std::isnan(b) && !std::isnan(a)));
}

bool compareMore(double a, double b)
{
return (a > b || (isnan(a) && !isnan(b)));
return (a > b || (std::isnan(a) && !std::isnan(b)));
}

unsigned long find(double input, double *channel, unsigned long numFrames)
Expand Down
6 changes: 3 additions & 3 deletions FrameLib_Objects/Vector/FrameLib_Peaks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,14 @@ void refineParabolicLog(double *positions, double *values, const double *data, u
// N.B. we assume a max of -80dB difference between samples to prevent extreme overshoot

double limit = std::max(std::max(data[idx-1], data[idx+1]) * 0.0001, std::numeric_limits<double>::min());
auto logLim = [&](double x) { return log(std::max(x, limit)); };
auto logLim = [&](double x) { return std::log(std::max(x, limit)); };

double position, value;

parabolicInterp(position, value, idx, logLim(data[idx-1]), logLim(data[idx]), logLim(data[idx+1]));

positions[peak] = position;
values[peak] = exp(value);
values[peak] = std::exp(value);
}

// Process
Expand Down Expand Up @@ -302,7 +302,7 @@ void FrameLib_Peaks::process()

case kMidpoint:
{
peakEnd = static_cast<unsigned long>(ceil((output2[peak] + output2[peak + 1]) / 2.0));
peakEnd = static_cast<unsigned long>(std::ceil((output2[peak] + output2[peak + 1]) / 2.0));
break;
}
}
Expand Down

0 comments on commit c7b09d0

Please sign in to comment.