JPL Spatial
Sound spatialization and propagation library
Loading...
Searching...
No Matches
FractionalDelay.h
Go to the documentation of this file.
1//
2// ██╗██████╗ ██╗ ██╗██████╗ ███████╗
3// ██║██╔══██╗ ██║ ██║██╔══██╗██╔════╝ ** JPLSpatial **
4// ██║██████╔╝ ██║ ██║██████╔╝███████╗
5// ██ ██║██╔═══╝ ██║ ██║██╔══██╗╚════██║ https://github.com/Jaytheway/JPLSpatial
6// ╚█████╔╝██║ ███████╗██║██████╔╝███████║
7// ╚════╝ ╚═╝ ╚══════╝╚═╝╚═════╝ ╚══════╝
8//
9// Copyright Jaroslav Pevno, JPLSpatial is offered under the terms of the ISC license:
10//
11// Permission to use, copy, modify, and/or distribute this software for any purpose with or
12// without fee is hereby granted, provided that the above copyright notice and this permission
13// notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
14// WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
16// CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
17// WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
18// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
20#pragma once
21
22#include "JPLSpatial/Core.h"
24
25#include <span>
26
27namespace JPL
28{
29 //==========================================================================
32 {
33 public:
35
36 static constexpr uint32 InputLength = 1;
37
39 inline void SetFraction(float /*fraction*/)
40 {
41 //JPL_ASSERT(fraction >= 0.0f && fraction <= 1.0f);
42 //mFraction = static_cast<uint32_t>(fraction + 0.5f);
43 }
44
45 inline float GetFraction() const { return 0.0f; }
46
49 inline float Process(std::span<const float, InputLength> data) const noexcept
50 {
51 return data[0];
52 }
53
54 inline float Process(float data) const noexcept
55 {
56 return data;
57 }
58
59 private:
60 //uint32_t mFraction = 0;
61 };
62
63 //==========================================================================
66 {
67 public:
68 LinearInterpolator() = default;
69
70 inline static constexpr uint32 InputLength = 2;
71
73 inline void SetFraction(float fraction)
74 {
75 JPL_ASSERT(fraction >= 0.0f && fraction <= 1.0f);
76 mFraction = fraction;
77 }
78
79 inline float GetFraction() const { return mFraction; }
80
84 inline float Process(std::span<const float, InputLength> data) const noexcept
85 {
86 const float a = data[0];
87 const float b = data[1];
88 return a + mFraction * (b - a);
89 }
90
91 private:
92 float mFraction = 0.0f;
93 };
94
95 //==========================================================================
98 {
99 public:
101
102 static constexpr uint32 InputLength = 2;
103
105 inline void SetFraction(float fraction)
106 {
107 JPL_ASSERT(fraction >= 0.0f && fraction < 1.0f);
108 mA = (1.0f - fraction) / (1.0f + fraction);
109 mFraction = fraction;
110 }
111
112 inline float GetFraction() const { return mFraction; }
113
117 inline float Process(std::span<const float, InputLength> data) noexcept
118 {
119 const float x = data[0]; // current input x[n]
120 const float x1 = data[1]; // previous input x[n-1]
121 const float y = mA * (x - mY1) + x1; // all-pass difference eq.
122 mY1 = y; // y[n-1] <- y[n]
123 return y;
124 }
125
127 inline void Reset(float v = 0.0f) noexcept
128 {
129 mY1 = v;
130 }
131
132 private:
133 float mA = 0.0f; // Thiran coefficient
134 float mY1 = 0.0f; // previous output y[n-1]
135 float mFraction = 0.0f;
136 };
137
138
139} // namespace JPL
#define JPL_ASSERT(inExpression,...)
Main assert macro, usage: JPL_ASSERT(condition, message) or JPL_ASSERT(condition)
Definition ErrorReporting.h:76
Linear fractional interpolator.
Definition FractionalDelay.h:66
void SetFraction(float fraction)
Definition FractionalDelay.h:73
float GetFraction() const
Definition FractionalDelay.h:79
static constexpr uint32 InputLength
Definition FractionalDelay.h:70
float Process(std::span< const float, InputLength > data) const noexcept
Definition FractionalDelay.h:84
Nearest fractional interpolator.
Definition FractionalDelay.h:32
float Process(std::span< const float, InputLength > data) const noexcept
Definition FractionalDelay.h:49
float Process(float data) const noexcept
Definition FractionalDelay.h:54
float GetFraction() const
Definition FractionalDelay.h:45
void SetFraction(float)
Definition FractionalDelay.h:39
static constexpr uint32 InputLength
Definition FractionalDelay.h:36
First-order Thiran fractional–delay all-pass interpolator.
Definition FractionalDelay.h:98
static constexpr uint32 InputLength
Definition FractionalDelay.h:102
float Process(std::span< const float, InputLength > data) noexcept
Definition FractionalDelay.h:117
void Reset(float v=0.0f) noexcept
Zero the state.
Definition FractionalDelay.h:127
float GetFraction() const
Definition FractionalDelay.h:112
void SetFraction(float fraction)
Definition FractionalDelay.h:105
Definition AcousticMaterial.h:36
std::uint32_t uint32
Definition Core.h:311
JPL_INLINE simd min(const simd &a, const simd &b) noexcept
Element-wise min.
Definition SIMD.h:1813