OSSIA
Open Scenario System for Interactive Application
fft.hpp
1 #pragma once
2 #include <ossia/detail/config.hpp>
3 
4 #include <ossia/detail/pod_vector.hpp>
5 
6 #include <cinttypes>
7 #include <cstddef>
8 
9 #if defined(OSSIA_FFT_FFTW)
10 #if defined(OSSIA_FFTW_SINGLE_ONLY)
11 using fftw_plan = struct fftw_plan_s*;
12 using fftwf_plan = struct fftwf_plan_s*;
13 namespace ossia
14 {
15 using fft_plan = fftwf_plan;
16 using fft_real = float;
17 using fft_complex = float[2];
18 struct fft_temp_storage
19 {
20 };
21 }
22 #elif defined(OSSIA_FFTW_DOUBLE_ONLY)
23 using fftw_plan = struct fftw_plan_s*;
24 using fftwf_plan = struct fftwf_plan_s*;
25 namespace ossia
26 {
27 using fft_plan = fftw_plan;
28 using fft_real = double;
29 using fft_complex = double[2];
30 struct fft_temp_storage
31 {
32 };
33 }
34 #endif
35 #elif defined(OSSIA_FFT_KFR)
36 namespace ossia
37 {
38 using fft_plan = void*;
39 using fft_real = double;
40 using fft_complex = double[2];
41 using fft_temp_storage = ossia::pod_vector<uint8_t>;
42 }
43 #else
44 namespace ossia
45 {
46 using fft_plan = void*;
47 using fft_real = double;
48 using fft_complex = double[2];
49 struct fft_temp_storage
50 {
51 };
52 }
53 #endif
54 
55 namespace ossia
56 {
57 class OSSIA_EXPORT fft
58 {
59 public:
60  explicit fft(std::size_t newSize) noexcept;
61  fft() noexcept
62  : fft{16}
63  {
64  }
65 
66  ~fft();
67 
68  static constexpr double norm(std::size_t sz) noexcept { return 1. / sz; }
69 
70  void reset(std::size_t newSize);
71 
72  fft_complex* execute(float* input, std::size_t sz) noexcept;
73  fft_complex* execute() noexcept;
74 
75  [[nodiscard]] fft_real* input() const noexcept { return m_input; }
76 
77 private:
78  fft_plan m_fw = {};
79  std::size_t m_size = 0;
80  fft_real* m_input{};
81  fft_complex* m_output{};
82  fft_temp_storage m_storage;
83 };
84 
85 class OSSIA_EXPORT rfft
86 {
87 public:
88  explicit rfft(std::size_t newSize) noexcept;
89  ~rfft();
90 
91  static constexpr double norm(std::size_t sz) noexcept { return 1. / sz; }
92 
93  void reset(std::size_t newSize);
94 
95  fft_real* execute(fft_complex* input) noexcept;
96  fft_real* execute() noexcept;
97 
98  [[nodiscard]] fft_complex* input() const noexcept { return m_input; }
99 
100 private:
101  fft_plan m_fw = {};
102  std::size_t m_size = 0;
103  fft_complex* m_input{};
104  fft_real* m_output{};
105  fft_temp_storage m_storage;
106 };
107 }
Definition: git_info.h:7