Use Pimpl idiom for LookupBackend
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <cmath>
|
||||
#include <vector>
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
|
||||
#include "interface.hpp"
|
||||
|
||||
template <size_t NR_SAMPLES> class LookupBackend : public Backend {
|
||||
public:
|
||||
LookupBackend();
|
||||
~LookupBackend() override;
|
||||
|
||||
void init() override;
|
||||
void compute_sinf(size_t n, const float *x, float *s) const override;
|
||||
void compute_cosf(size_t n, const float *x, float *c) const override;
|
||||
@@ -14,9 +17,6 @@ public:
|
||||
float *c) const override;
|
||||
|
||||
private:
|
||||
std::vector<float> lookup;
|
||||
static constexpr size_t MASK = NR_SAMPLES - 1;
|
||||
static constexpr float SCALE = NR_SAMPLES / (2.0f * float(M_PI));
|
||||
struct Impl;
|
||||
std::unique_ptr<Impl> impl;
|
||||
};
|
||||
|
||||
#include "lookup.tpp" // include implementation
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <cmath>
|
||||
|
||||
template <size_t NR_SAMPLES>
|
||||
void LookupBackend<NR_SAMPLES>::init() {
|
||||
lookup.resize(NR_SAMPLES);
|
||||
for (size_t i = 0; i < NR_SAMPLES; ++i)
|
||||
lookup[i] = std::sinf(i * (2.0f * float(M_PI) / NR_SAMPLES));
|
||||
}
|
||||
|
||||
template <size_t NR_SAMPLES>
|
||||
void LookupBackend<NR_SAMPLES>::compute_sinf(size_t n,
|
||||
const float* x,
|
||||
float* s) const {
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
size_t idx = static_cast<size_t>(x[i] * SCALE) & MASK;
|
||||
s[i] = lookup[idx];
|
||||
}
|
||||
}
|
||||
|
||||
template <size_t NR_SAMPLES>
|
||||
void LookupBackend<NR_SAMPLES>::compute_cosf(size_t n,
|
||||
const float* x,
|
||||
float* c) const {
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
size_t idx = static_cast<size_t>(x[i] * SCALE) & MASK;
|
||||
size_t idx_cos = (idx + NR_SAMPLES / 4) & MASK;
|
||||
c[i] = lookup[idx_cos];
|
||||
}
|
||||
}
|
||||
|
||||
template <size_t NR_SAMPLES>
|
||||
void LookupBackend<NR_SAMPLES>::compute_sincosf(size_t n,
|
||||
const float* x,
|
||||
float* s,
|
||||
float* c) const {
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
size_t idx = static_cast<size_t>(x[i] * SCALE) & MASK;
|
||||
size_t idx_cos = (idx + NR_SAMPLES / 4) & MASK;
|
||||
s[i] = lookup[idx];
|
||||
c[i] = lookup[idx_cos];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user