JPL Spatial
Sound spatialization and propagation library
Loading...
Searching...
No Matches
Curves.h
Go to the documentation of this file.
1//
2// ██╗██████╗ ██╗ ██╗██████╗ ███████╗
3// ██║██╔══██╗ ██║ ██║██╔══██╗██╔════╝ ** JPLSpatial **
4// ██║██████╔╝ ██║ ██║██████╔╝███████╗
5// ██ ██║██╔═══╝ ██║ ██║██╔══██╗╚════██║ https://github.com/Jaytheway/JPLSpatial
6// ╚█████╔╝██║ ███████╗██║██████╔╝███████║
7// ╚════╝ ╚═╝ ╚══════╝╚═╝╚═════╝ ╚══════╝
8//
9// Copyright 2024 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"
23
24#include <cmath>
25#include <numbers>
26#include <algorithm>
27
28namespace JPL
29{
30 namespace Curve
31 {
32 struct Point
33 {
34 float X;
35 float Y;
36 };
37
38 enum class EType
39 {
41 Linear,
44 SCurve,
45 //InvertedSCurve,
50 };
51
52 namespace Internal
53 {
54 static constexpr float halfPi = std::numbers::pi_v<float> *0.5f;
55 static const float log1_41 = std::log(1.41f);
56 static const float log1_41_inv = 1.0f / log1_41;
57 static const float log3 = std::log(3.0f);
58 static const float log3_inv = 1.0f / log3;
59 }
60
61 JPL_INLINE float EvaluateConstant(float t) { return 1.0f; }
62 JPL_INLINE float EvaluateLinear(float t) { return t; }
63 JPL_INLINE float EvaluateSineFadeIn(float t) { return std::sin(t * Internal::halfPi); }
64 JPL_INLINE float EvaluateSineFadeOut(float t) { return 1.0f - std::cos(t * Internal::halfPi); }
65 JPL_INLINE float EvaluateSCurve(float t) { return t * t * (3 - 2 * t); }
66 JPL_INLINE float EvaluateLogarithmicBase1_41(float t) { return std::log(1.0f + 0.41f * t) * Internal::log1_41_inv; }
67 JPL_INLINE float EvaluateLogarithmicBase3(float t) { return std::log(1.0f + 2.0f * t) * Internal::log3_inv; }
68 JPL_INLINE float EvaluateExponentialBase1_41(float t) { static constexpr float inv_0_41 = 1.0f / 0.41f; return (std::pow(1.41f, t) - 1.0f) * inv_0_41; }
69 JPL_INLINE float EvaluateExponentialBase3(float t) { return(std::pow(3.0f, t) - 1.0f) * 0.5f; }
70
88 } // namespace Curve
89} // namespace JPL
EType
Definition Curves.h:39
JPL_INLINE float EvaluateCurve(EType type, float t)
Definition Curves.h:71
JPL_INLINE float EvaluateSCurve(float t)
Definition Curves.h:65
JPL_INLINE float EvaluateLogarithmicBase1_41(float t)
Definition Curves.h:66
JPL_INLINE float EvaluateSineFadeOut(float t)
Definition Curves.h:64
JPL_INLINE float EvaluateExponentialBase3(float t)
Definition Curves.h:69
JPL_INLINE float EvaluateLinear(float t)
Definition Curves.h:62
JPL_INLINE float EvaluateLogarithmicBase3(float t)
Definition Curves.h:67
JPL_INLINE float EvaluateConstant(float t)
Definition Curves.h:61
JPL_INLINE float EvaluateSineFadeIn(float t)
Definition Curves.h:63
JPL_INLINE float EvaluateExponentialBase1_41(float t)
Definition Curves.h:68
Definition AcousticMaterial.h:36
JPL_INLINE simd min(const simd &a, const simd &b) noexcept
Element-wise min.
Definition SIMD.h:1813
Definition Curves.h:33
float X
Definition Curves.h:34
float Y
Definition Curves.h:35