Files
soothe2-re/dsp/freqpath.cpp
T

28 lines
1.0 KiB
C++

#include "freqpath.hpp"
#include <cmath>
#include <cstring>
namespace detkernel {
// Bit-faithful transcription of the warp builder loop in FUN_180530850 (0x530900).
void build_warp(float fs_total, int n, float* warp) {
const float K = std::exp(2.0723267f); // 0x1824c4208 -> exp (0x1a14cac)
const float F = (2000.0f / (fs_total * 0.5f)) * static_cast<float>(n); // 0x1824c45b4 / ([0x24]*0.5) * N
for (int i = 1; i < n; ++i) {
float x = static_cast<float>(i) / F;
float t = x / K;
t = t + 1.0f; // +1.0 (0x1824c3ea4)
float r = 1.0f / t; // divss
r = static_cast<float>(std::fabs(static_cast<double>(r))); // cvtss2sd/andpd/cvtpd2ps
warp[i] = r * x;
}
const float scale = 0.87f; // 0x1824c3e50 (also 0.87 as double 0x24c4110)
for (int i = 0; i < n; ++i) warp[i] *= scale;
warp[0] = 0.0f; // 0x5406a8[0] = 0 (DC)
}
} // namespace detkernel