MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
WindowGenerator.cpp
Go to the documentation of this file.
1#include "WindowGenerator.hpp"
2
4
5std::vector<double> HannWindow(size_t length)
6{
7 std::vector<double> window(length);
8 if (length == 1)
9 return { 1.0 };
10 const double scale = 1.0 / (length - 1);
11 for (size_t i = 0; i < length; ++i) {
12 window[i] = 0.5 * (1.0 - std::cos(2.0 * M_PI * i * scale));
13 }
14 return window;
15}
16
17std::vector<double> HammingWindow(size_t length)
18{
19 std::vector<double> window(length);
20 if (length == 1)
21 return { 1.0 };
22 const double scale = 1.0 / (length - 1);
23 for (size_t i = 0; i < length; ++i) {
24 window[i] = 0.54 - 0.46 * std::cos(2.0 * M_PI * i * scale);
25 }
26 return window;
27}
28
29std::vector<double> BlackmanWindow(size_t length)
30{
31 std::vector<double> window(length);
32 if (length == 1)
33 return { 1.0 };
34 const double scale = 1.0 / (length - 1);
35 for (size_t i = 0; i < length; ++i) {
36 const double x = 2.0 * M_PI * i * scale;
37 window[i] = 0.42 - 0.5 * std::cos(x) + 0.08 * std::cos(2.0 * x);
38 }
39 return window;
40}
41
42std::vector<double> LinearRamp(size_t length, double start, double end)
43{
44 std::vector<double> ramp(length);
45 if (length == 1)
46 return { start };
47 const double step = (end - start) / (length - 1);
48 for (size_t i = 0; i < length; ++i) {
49 ramp[i] = start + i * step;
50 }
51 return ramp;
52}
53
54std::vector<double> ExponentialRamp(size_t length, double start, double end)
55{
56 std::vector<double> ramp(length);
57 if (length == 1)
58 return { start };
59 const double growth = std::pow(end / start, 1.0 / (length - 1));
60 ramp[0] = start;
61 for (size_t i = 1; i < length; ++i) {
62 ramp[i] = ramp[i - 1] * growth;
63 }
64 return ramp;
65}
66
67std::vector<double> generate_window(uint32_t size, WindowType window_type)
68{
69 switch (window_type) {
71 return HammingWindow(size);
73 return BlackmanWindow(size);
75 default:
76 return HannWindow(size);
77 }
78}
79}
std::vector< double > ExponentialRamp(size_t length, double start, double end)
Creates an exponential ramp function.
std::vector< double > BlackmanWindow(size_t length)
Creates a Blackman window function.
std::vector< double > generate_window(uint32_t size, WindowType window_type)
Generate window coefficients using C++20 ranges.
std::vector< double > LinearRamp(size_t length, double start, double end)
Creates a linear ramp function.
std::vector< double > HammingWindow(size_t length)
Creates a Hamming window function.
std::vector< double > HannWindow(size_t length)
Creates a Hann window function.