EchoMap
2026-07-25 6d3977c
An experimental cross-platform digital signal processing application for sound-source localisation.
Toggle main menu visibility
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
18
namespace
echomap
19
{
20
21
template
<
class
T>
22
concept
WindowFunction
=
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
32
class
WindowFunctions
33
{
34
public
:
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
213
struct
BlackmanHarris
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
285
using
AllFunctions =
std::variant<Constant, Hann, Hamming, Bartlett, Blackman, BlackmanHarris, Welch>
;
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
302
struct
NameGetter
303
{
304
template
<
class
T>
static
consteval
std::string_view
get()
305
{
306
return
WindowFunctions::get_window_name<T>
();
307
}
308
};
309
};
310
311
template
<>
constexpr
std::string_view
WindowFunctions::get_window_name<WindowFunctions::Constant>
()
312
{
313
return
"Constant"
;
314
}
315
316
template
<>
constexpr
std::string_view
WindowFunctions::get_window_name<WindowFunctions::Hann>()
317
{
318
return
"Hann"
;
319
}
320
321
template
<>
constexpr
std::string_view
WindowFunctions::get_window_name<WindowFunctions::Hamming>
()
322
{
323
return
"Hamming"
;
324
}
325
326
template
<>
constexpr
std::string_view
WindowFunctions::get_window_name<WindowFunctions::Bartlett>
()
327
{
328
return
"Bartlett"
;
329
}
330
331
template
<>
constexpr
std::string_view
WindowFunctions::get_window_name<WindowFunctions::Blackman>
()
332
{
333
return
"Blackman"
;
334
}
335
336
template
<>
constexpr
std::string_view
WindowFunctions::get_window_name<WindowFunctions::BlackmanHarris>
()
337
{
338
return
"Blackman-Harris"
;
339
}
340
341
template
<>
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
algorithm
std::string_view
echomap::WindowFunctions
Aggregation of callable DSP window functions.
Definition
WindowFunctions.hpp:33
echomap::WindowFunctions::get_window_name
static constexpr std::string_view get_window_name()
Retrieve a human-readable name for the templated window function.
Definition
WindowFunctions.hpp:292
echomap::WindowFunction
Definition
WindowFunctions.hpp:22
cstddef
echomap
The main EchoMap outermost namespace for all non-exported symbols.
Definition
ActionController.hpp:20
ranges
std::remove_cvref_t
std::size_t
string_view
echomap::WindowFunctions::Bartlett
The Bartlett triangular window.
Definition
WindowFunctions.hpp:146
echomap::WindowFunctions::Bartlett::operator()
static float operator()(std::size_t index, std::size_t size) noexcept
Maps the index into the Bartlett function.
Definition
WindowFunctions.cpp:53
echomap::WindowFunctions::BlackmanHarris
The minimum four-term Blackman-Harris cosine-sum window.
Definition
WindowFunctions.hpp:214
echomap::WindowFunctions::BlackmanHarris::operator()
static float operator()(std::size_t index, std::size_t size) noexcept
Maps the index into the Blackman-Harris function.
Definition
WindowFunctions.cpp:77
echomap::WindowFunctions::Blackman
The Blackman cosine-sum window.
Definition
WindowFunctions.hpp:181
echomap::WindowFunctions::Blackman::operator()
static float operator()(std::size_t index, std::size_t size) noexcept
Maps the index into the Blackman function.
Definition
WindowFunctions.cpp:65
echomap::WindowFunctions::Constant
The Constant invocable window function.
Definition
WindowFunctions.hpp:62
echomap::WindowFunctions::Constant::operator()
static float operator()(std::size_t index, std::size_t size) noexcept
Maps the index to the constant 1.0.
Definition
WindowFunctions.cpp:45
echomap::WindowFunctions::Hamming
The Hamming raised-cosine window.
Definition
WindowFunctions.hpp:110
echomap::WindowFunctions::Hamming::operator()
static float operator()(std::size_t index, std::size_t size) noexcept
Maps the index into the Hamming function.
Definition
WindowFunctions.cpp:30
echomap::WindowFunctions::Hann
The Hann raised-cosine window.
Definition
WindowFunctions.hpp:80
echomap::WindowFunctions::Hann::operator()
static float operator()(std::size_t index, std::size_t size) noexcept
Maps the index into the Hann function.
Definition
WindowFunctions.cpp:18
echomap::WindowFunctions::NameGetter
Provides a callable type for statically invoking the name getter.
Definition
WindowFunctions.hpp:303
echomap::WindowFunctions::Welch
The Welch parabolic window.
Definition
WindowFunctions.hpp:256
echomap::WindowFunctions::Welch::operator()
static float operator()(std::size_t index, std::size_t size) noexcept
Maps the index into the Welch function.
Definition
WindowFunctions.cpp:96
std::variant
src
objects
factories
WindowFunctions.hpp
Generated by
1.17.0