OSSIA
Open Scenario System for Interactive Application
Loading...
Searching...
No Matches
fft.hpp
1#pragma once
2#include <ossia/detail/config.hpp>
3
4#include <ossia/detail/pod_vector.hpp>
5
6#include <array>
7#include <cinttypes>
8#include <cstddef>
9
10#if defined(OSSIA_FFT_FFTW)
11#if defined(OSSIA_FFTW_SINGLE_ONLY)
12using fftw_plan = struct fftw_plan_s*;
13using fftwf_plan = struct fftwf_plan_s*;
14namespace ossia
15{
16using fft_plan = fftwf_plan;
17using fft_real = float;
18using fft_complex = float[2];
19struct fft_temp_storage
20{
21};
22}
23#elif defined(OSSIA_FFTW_DOUBLE_ONLY)
24using fftw_plan = struct fftw_plan_s*;
25using fftwf_plan = struct fftwf_plan_s*;
26namespace ossia
27{
28using fft_plan = fftw_plan;
29using fft_real = double;
30using fft_complex = double[2];
31struct fft_temp_storage
32{
33};
34}
35#endif
36#elif defined(OSSIA_FFT_KFR)
37namespace ossia
38{
39using fft_plan = void*;
40using fft_real = double;
41using fft_complex = double[2];
42using fft_temp_storage = ossia::pod_vector<uint8_t>;
43}
44#else
45namespace ossia
46{
47using fft_plan = void*;
48using fft_real = double;
49using fft_complex = double[2];
50struct fft_temp_storage
51{
52};
53}
54#endif
55
56namespace ossia
57{
58class OSSIA_EXPORT fft
59{
60public:
61 explicit fft(std::size_t newSize) noexcept;
62 fft() noexcept
63 : fft{16}
64 {
65 }
66
67 ~fft();
68
69 static constexpr double norm(std::size_t sz) noexcept { return 1. / sz; }
70
73 void reset(std::size_t newSize);
76 void prepare(std::size_t newSize);
77
78 fft_complex* execute(float* input, std::size_t sz) noexcept;
79 fft_complex* execute() noexcept;
80
81 [[nodiscard]] fft_real* input() const noexcept { return m_input; }
83 [[nodiscard]] std::size_t size() const noexcept { return m_size; }
84 [[nodiscard]] std::size_t storage_size() const noexcept { return m_storage_size; }
85
86private:
87 void build(std::size_t newSize, bool measure) noexcept;
88 void release() noexcept;
89 void use(std::size_t newSize, bool measure);
90
91 fft_plan m_fw = {};
92 std::size_t m_size = 0;
93 std::size_t m_storage_size = 0;
94 fft_real* m_input{};
95 fft_complex* m_output{};
96 fft_temp_storage m_storage;
97
100 struct spare
101 {
102 fft_plan fw = {};
103 std::size_t size = 0;
104 std::size_t storage_size = 0;
105 fft_real* input{};
106 fft_complex* output{};
107 fft_temp_storage storage;
108 std::size_t used = 0;
109 };
110 void swap(spare& s) noexcept;
111 std::array<spare, 3> m_spares{};
112 std::size_t m_uses = 0;
113};
114
115class OSSIA_EXPORT rfft
116{
117public:
118 explicit rfft(std::size_t newSize) noexcept;
119 ~rfft();
120
121 static constexpr double norm(std::size_t sz) noexcept { return 1. / sz; }
122
123 void reset(std::size_t newSize);
124
125 fft_real* execute(fft_complex* input) noexcept;
126 fft_real* execute() noexcept;
127
128 [[nodiscard]] fft_complex* input() const noexcept { return m_input; }
129
130private:
131 fft_plan m_fw = {};
132 std::size_t m_size = 0;
133 std::size_t m_storage_size = 0;
134 fft_complex* m_input{};
135 fft_real* m_output{};
136 fft_temp_storage m_storage;
137};
138}
Definition git_info.h:7