25 const auto size = fftSize / 2 + 1;
27 std::vector<float> tmp(
end);
28 for (
size_t i = 0; i <
end; ++i)
30 const int int_pos = i / factor;
31 const float frac_pos = 1.f * i / factor - int_pos;
34 tmp[i] = (1 - frac_pos) * x[k] + frac_pos * x[l];
38 std::fill(x +
end, x +
size, 0.f);
46 : cutoffQuefrency { cutoffQuefrency }
54 mFft = std::make_unique<staffpad::audio::FourierTransform>(
55 static_cast<int32_t
>(fftSize));
56 const auto numBins = fftSize / 2 + 1;
69 const float* powSpec, std::complex<float>* spec,
double factor)
75 const auto fftSize =
mFft->getSize();
76 const auto numBins = fftSize / 2 + 1;
83 const float normalizer =
FastLog2(fftSize);
84 std::transform(powSpec, powSpec + numBins, pEnv, [&](
float power) {
95 if (binCutoff < fftSize / 2)
96 std::fill(pCepst + binCutoff + 1, pCepst + fftSize - binCutoff, 0.f);
97 mLogger.
Log(pCepst, fftSize,
"cepstrumLiftered");
103 [fftSize = fftSize](
const std::complex<float>& env) {
104 return std::exp2(env.real() / fftSize);
112 [](
float env) { return std::isnormal(env) ? 1.f / env : 0.f; });
114 const auto lastNonZeroedBin =
120 mWeights.begin(), [](
float env,
float weight) {
125 return std::min(env * weight, 100.f);
140 spec, numBins,
"magnitude",
141 [fftSize = fftSize](
const std::complex<float>& spec) {
142 return std::abs(spec) / fftSize;
147 spec, spec + numBins,
mWeights.begin(), spec,
148 std::multiplies<std::complex<float>>());
151 spec, numBins,
"weightedMagnitude",
152 [fftSize = fftSize](
const std::complex<float>& spec) {
153 return std::abs(spec) / fftSize;
constexpr auto MapToPositiveHalfIndex(int index, int fullSize)
Useful when dealing with symmetric spectra reduced only to their positive half. See tests below for m...
constexpr float FastLog2(float x)
Approximates the base-2 logarithm of a float to two decimal places, adapted from https://stackoverflo...
void setSize(int32_t numChannels, int32_t samples)
T * getPtr(int32_t channel)
constexpr auto sampleRate
const char * end(const char *str) noexcept
constexpr fastfloat_really_inline int32_t power(int32_t q) noexcept
void copy(const T *src, T *dst, int32_t n)