VCV Rack API v2
Loading...
Searching...
No Matches
window.hpp
Go to the documentation of this file.
1#pragma once
2#include <math.hpp>
3#include <simd/Vector.hpp>
4#include <simd/functions.hpp>
5
6
7namespace rack {
8namespace dsp {
9
10
15template <typename T>
16inline T hann(T p) {
17 return T(0.5) * (1 - simd::cos(2 * T(M_PI) * p));
18}
19
21inline void hannWindow(float* x, int len) {
22 for (int i = 0; i < len; i++) {
23 x[i] *= hann(float(i) / (len - 1));
24 }
25}
26
31template <typename T>
32inline T blackman(T alpha, T p) {
33 return
34 + (1 - alpha) / 2
35 - T(1) / 2 * simd::cos(2 * T(M_PI) * p)
36 + alpha / 2 * simd::cos(4 * T(M_PI) * p);
37}
38
39inline void blackmanWindow(float alpha, float* x, int len) {
40 for (int i = 0; i < len; i++) {
41 x[i] *= blackman(alpha, float(i) / (len - 1));
42 }
43}
44
45
49template <typename T>
50inline T blackmanNuttall(T p) {
51 return
52 + T(0.3635819)
53 - T(0.4891775) * simd::cos(2 * T(M_PI) * p)
54 + T(0.1365995) * simd::cos(4 * T(M_PI) * p)
55 - T(0.0106411) * simd::cos(6 * T(M_PI) * p);
56}
57
58inline void blackmanNuttallWindow(float* x, int len) {
59 for (int i = 0; i < len; i++) {
60 x[i] *= blackmanNuttall(float(i) / (len - 1));
61 }
62}
63
67template <typename T>
68inline T blackmanHarris(T p) {
69 return
70 + T(0.35875)
71 - T(0.48829) * simd::cos(2 * T(M_PI) * p)
72 + T(0.14128) * simd::cos(4 * T(M_PI) * p)
73 - T(0.01168) * simd::cos(6 * T(M_PI) * p);
74}
75
76inline void blackmanHarrisWindow(float* x, int len) {
77 for (int i = 0; i < len; i++) {
78 x[i] *= blackmanHarris(float(i) / (len - 1));
79 }
80}
81
82
83} // namespace dsp
84} // namespace rack
void hannWindow(float *x, int len)
Multiplies the Hann window by a signal x of length len in-place.
Definition window.hpp:21
void blackmanWindow(float alpha, float *x, int len)
Definition window.hpp:39
T hann(T p)
Hann window function.
Definition window.hpp:16
T blackman(T alpha, T p)
Blackman window function.
Definition window.hpp:32
T blackmanHarris(T p)
Blackman-Harris window function.
Definition window.hpp:68
void blackmanNuttallWindow(float *x, int len)
Definition window.hpp:58
void blackmanHarrisWindow(float *x, int len)
Definition window.hpp:76
T blackmanNuttall(T p)
Blackman-Nuttall window function.
Definition window.hpp:50
float_4 cos(float_4 x)
Definition functions.hpp:138
Root namespace for the Rack API.
Definition AudioDisplay.hpp:9