-
Notifications
You must be signed in to change notification settings - Fork 7
/
Fourier.cpp
65 lines (52 loc) · 1.46 KB
/
Fourier.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright (C) 2020-2024 Parabola Research Limited
// SPDX-License-Identifier: MPL-2.0
#include "Fourier.h"
#include "Assert.h"
#include "kissfft/kiss_fftr.h"
namespace Bungee::Fourier {
struct Kiss
{
struct KernelBase
{
void *implementation;
~KernelBase();
};
template <bool isInverse>
struct Kernel :
KernelBase
{
Kernel(int log2TransformLength);
void forward(int log2TransformLength, float *t, std::complex<float> *f) const;
void inverse(int log2TransformLength, float *t, std::complex<float> *f) const;
};
typedef Kernel<false> Forward;
typedef Kernel<true> Inverse;
};
template <bool isInverse>
Kiss::Kernel<isInverse>::Kernel(int log2TransformLength) :
Kiss::KernelBase{kiss_fftr_alloc(1 << log2TransformLength, isInverse, nullptr, nullptr)}
{
}
Kiss::KernelBase::~KernelBase()
{
KISS_FFT_FREE(implementation);
}
template <bool isInverse>
void Kiss::Kernel<isInverse>::forward(int, float *t, std::complex<float> *f) const
{
static_assert(sizeof(*f) == sizeof(kiss_fft_cpx));
BUNGEE_ASSERT1(!isInverse);
kiss_fftr((kiss_fftr_cfg)implementation, t, (kiss_fft_cpx *)f);
}
template <bool isInverse>
void Kiss::Kernel<isInverse>::inverse(int, float *t, std::complex<float> *f) const
{
static_assert(sizeof(*f) == sizeof(kiss_fft_cpx));
BUNGEE_ASSERT1(isInverse);
kiss_fftri((kiss_fftr_cfg)implementation, (kiss_fft_cpx *)f, t);
}
std::unique_ptr<Transforms> transforms()
{
return std::make_unique<Cache<Kiss, 16>>();
}
} // namespace Bungee::Fourier