MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Taper.hpp
Go to the documentation of this file.
1#pragma once
2
3/**
4 * @file Taper.hpp
5 * @brief Discrete taper (window) coefficient generation and in-place application
6 * for MayaFlux::Kinesis
7 *
8 * Pure numerical functions producing taper coefficient vectors and applying
9 * them in-place to contiguous double-precision spans.
10 * No MayaFlux type dependencies. Domain-agnostic.
11 *
12 * Two usage patterns are supported:
13 *
14 * 1. Generate then apply separately:
15 * auto t = Kinesis::Discrete::hann(n);
16 * Kinesis::Discrete::apply_taper(signal, t);
17 *
18 * 2. Apply directly without materialising coefficients:
19 * Kinesis::Discrete::apply_hann(signal);
20 *
21 * All generation functions return a vector of length @p n.
22 * The single-sample edge case always returns { 1.0 }.
23 *
24 * SIMD notes:
25 * apply_taper and apply_rectangular are auto-vectorisable under
26 * -O2 -march=native. Generation functions invoke std::cos and are scalar.
27 */
28
30
31// ============================================================================
32// Coefficient generation
33// ============================================================================
34
35/**
36 * @brief Hann (raised cosine) taper coefficients
37 * @param n Length in samples
38 * @return Coefficient vector of length n
39 */
40[[nodiscard]] std::vector<double> hann(size_t n);
41
42/**
43 * @brief Hamming taper coefficients
44 * @param n Length in samples
45 * @return Coefficient vector of length n
46 */
47[[nodiscard]] std::vector<double> hamming(size_t n);
48
49/**
50 * @brief Blackman taper coefficients
51 * @param n Length in samples
52 * @return Coefficient vector of length n
53 */
54[[nodiscard]] std::vector<double> blackman(size_t n);
55
56/**
57 * @brief Rectangular (unity) taper coefficients
58 * @param n Length in samples
59 * @return Coefficient vector of length n, all 1.0
60 */
61[[nodiscard]] std::vector<double> rectangular(size_t n);
62
63/**
64 * @brief Trapezoid taper coefficients with configurable flat region
65 *
66 * Linear ramp-in over @p fade_len samples, unity plateau, linear ramp-out
67 * over @p fade_len samples. If 2 * fade_len >= n the ramps are clamped so
68 * they meet at the centre with no plateau.
69 *
70 * @param n Length in samples
71 * @param fade_len Ramp length in samples at each end
72 * @return Coefficient vector of length n
73 */
74[[nodiscard]] std::vector<double> trapezoid(size_t n, size_t fade_len);
75
76// ============================================================================
77// In-place application
78// ============================================================================
79
80/**
81 * @brief Multiply @p data element-wise by a precomputed taper
82 *
83 * Applied cyclically if @p taper is shorter than @p data; truncated if longer.
84 * The common case (equal sizes) is a straight element-wise multiply.
85 *
86 * @param data Target span (modified in place)
87 * @param taper Coefficient span
88 */
89void apply_taper(std::span<double> data, std::span<const double> taper) noexcept;
90
91/**
92 * @brief Apply a Hann taper in-place without materialising coefficients
93 * @param data Target span (modified in place)
94 */
95void apply_hann(std::span<double> data) noexcept;
96
97/**
98 * @brief Apply a Hamming taper in-place without materialising coefficients
99 * @param data Target span (modified in place)
100 */
101void apply_hamming(std::span<double> data) noexcept;
102
103/**
104 * @brief Apply a Blackman taper in-place without materialising coefficients
105 * @param data Target span (modified in place)
106 */
107void apply_blackman(std::span<double> data) noexcept;
108
109/**
110 * @brief Apply a trapezoid taper in-place without materialising coefficients
111 * @param data Target span (modified in place)
112 * @param fade_len Ramp length in samples at each end
113 */
114void apply_trapezoid(std::span<double> data, size_t fade_len) noexcept;
115
116} // namespace MayaFlux::Kinesis::Discrete
std::vector< double > blackman(size_t n)
Blackman taper coefficients.
Definition Taper.cpp:35
void apply_blackman(std::span< double > data) noexcept
Apply a Blackman taper in-place without materialising coefficients.
Definition Taper.cpp:110
std::vector< double > rectangular(size_t n)
Rectangular (unity) taper coefficients.
Definition Taper.cpp:50
std::vector< double > hamming(size_t n)
Hamming taper coefficients.
Definition Taper.cpp:22
void apply_hann(std::span< double > data) noexcept
Apply a Hann taper in-place without materialising coefficients.
Definition Taper.cpp:90
void apply_hamming(std::span< double > data) noexcept
Apply a Hamming taper in-place without materialising coefficients.
Definition Taper.cpp:100
void apply_trapezoid(std::span< double > data, size_t fade_len) noexcept
Apply a trapezoid taper in-place without materialising coefficients.
Definition Taper.cpp:122
std::vector< double > hann(size_t n)
Hann (raised cosine) taper coefficients.
Definition Taper.cpp:9
void apply_taper(std::span< double > data, std::span< const double > taper) noexcept
Multiply data element-wise by a precomputed taper.
Definition Taper.cpp:75
std::vector< double > trapezoid(size_t n, size_t fade_len)
Trapezoid taper coefficients with configurable flat region.
Definition Taper.cpp:55