EchoMap 2026-07-25 6d3977c
An experimental cross-platform digital signal processing application for sound-source localisation.
Loading...
Searching...
No Matches
WindowFunctions.hpp
Go to the documentation of this file.
1
9
10#ifndef ECHOMAP_WINDOWFUNCTIONS_HPP
11#define ECHOMAP_WINDOWFUNCTIONS_HPP
12
13#include <algorithm>
14#include <cstddef>
15#include <ranges>
16#include <string_view>
17
18namespace echomap
19{
20
21template <class T>
23 std::default_initializable<std::remove_cvref_t<T>> && requires(std::size_t index, std::size_t size) {
24 { std::remove_cvref_t<T>{}(index, size) } -> std::convertible_to<float>;
25 };
26
33{
34public:
35 template <
36 class WindowT,
37 class BuffersT,
38 class InputT>
39 static float apply_window(
40 BuffersT& buffers,
41 const InputT& input
42 )
43 {
44 using Window = std::remove_cvref_t<WindowT>;
45 static_assert(WindowFunction<Window>, "WindowT does not satisfy WindowFunction.");
46
47 float scale_divisor = 0.0f;
48
49 for (std::size_t index = 0; index < buffers.input_size; ++index) {
50 const float window_value = Window{}(index, buffers.input_size);
51 scale_divisor += window_value;
52 buffers.input[index] = input[index] * window_value;
53 }
54
55 return scale_divisor;
56 }
57
61 struct Constant
62 {
70 static float operator()(
71 std::size_t index,
72 std::size_t size
73 ) noexcept;
74 };
75
79 struct Hann
80 {
100 static float operator()(
101 std::size_t index,
102 std::size_t size
103 ) noexcept;
104 };
105
109 struct Hamming
110 {
136 static float operator()(
137 std::size_t index,
138 std::size_t size
139 ) noexcept;
140 };
141
145 struct Bartlett
146 {
171 static float operator()(
172 std::size_t index,
173 std::size_t size
174 ) noexcept;
175 };
176
180 struct Blackman
181 {
204 static float operator()(
205 std::size_t index,
206 std::size_t size
207 ) noexcept;
208 };
209
214 {
246 static float operator()(
247 std::size_t index,
248 std::size_t size
249 ) noexcept;
250 };
251
255 struct Welch
256 {
279 static float operator()(
280 std::size_t index,
281 std::size_t size
282 ) noexcept;
283 };
284
286
292 template <WindowFunction> static constexpr std::string_view get_window_name()
293 {
294 // ReSharper disable once CppStaticAssertFailure
295 static_assert(false, "Missing window function name.");
296 return {};
297 }
298
303 {
304 template <class T> static consteval std::string_view get()
305 {
307 }
308 };
309};
310
312{
313 return "Constant";
314}
315
316template <> constexpr std::string_view WindowFunctions::get_window_name<WindowFunctions::Hann>()
317{
318 return "Hann";
319}
320
321template <> constexpr std::string_view WindowFunctions::get_window_name<WindowFunctions::Hamming>()
322{
323 return "Hamming";
324}
325
326template <> constexpr std::string_view WindowFunctions::get_window_name<WindowFunctions::Bartlett>()
327{
328 return "Bartlett";
329}
330
331template <> constexpr std::string_view WindowFunctions::get_window_name<WindowFunctions::Blackman>()
332{
333 return "Blackman";
334}
335
336template <> constexpr std::string_view WindowFunctions::get_window_name<WindowFunctions::BlackmanHarris>()
337{
338 return "Blackman-Harris";
339}
340
341template <> constexpr std::string_view WindowFunctions::get_window_name<WindowFunctions::Welch>()
342{
343 return "Welch";
344}
345
346} // namespace echomap
347
348#endif // ECHOMAP_WINDOWFUNCTIONS_HPP
Aggregation of callable DSP window functions.
static constexpr std::string_view get_window_name()
Retrieve a human-readable name for the templated window function.
The main EchoMap outermost namespace for all non-exported symbols.
The Bartlett triangular window.
static float operator()(std::size_t index, std::size_t size) noexcept
Maps the index into the Bartlett function.
The minimum four-term Blackman-Harris cosine-sum window.
static float operator()(std::size_t index, std::size_t size) noexcept
Maps the index into the Blackman-Harris function.
The Blackman cosine-sum window.
static float operator()(std::size_t index, std::size_t size) noexcept
Maps the index into the Blackman function.
The Constant invocable window function.
static float operator()(std::size_t index, std::size_t size) noexcept
Maps the index to the constant 1.0.
The Hamming raised-cosine window.
static float operator()(std::size_t index, std::size_t size) noexcept
Maps the index into the Hamming function.
The Hann raised-cosine window.
static float operator()(std::size_t index, std::size_t size) noexcept
Maps the index into the Hann function.
Provides a callable type for statically invoking the name getter.
The Welch parabolic window.
static float operator()(std::size_t index, std::size_t size) noexcept
Maps the index into the Welch function.