OpenShot Audio Library | OpenShotAudio
1.0.0
Toggle main menu visibility
Loading...
Searching...
No Matches
juce_SpecialFunctions.cpp
1
/*
2
==============================================================================
3
4
This file is part of the JUCE library.
5
Copyright (c) 2022 - Raw Material Software Limited
6
7
JUCE is an open source library subject to commercial or open-source
8
licensing.
9
10
By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11
Agreement and JUCE Privacy Policy.
12
13
End User License Agreement: www.juce.com/juce-7-licence
14
Privacy Policy: www.juce.com/juce-privacy-policy
15
16
Or: You may also use this code under the terms of the GPL v3 (see
17
www.gnu.org/licenses).
18
19
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21
DISCLAIMED.
22
23
==============================================================================
24
*/
25
26
namespace
juce::dsp
27
{
28
29
double
SpecialFunctions::besselI0
(
double
x)
noexcept
30
{
31
auto
ax = std::abs (x);
32
33
if
(ax < 3.75)
34
{
35
auto
y = x / 3.75;
36
y *= y;
37
38
return
1.0 + y * (3.5156229 + y * (3.0899424 + y * (1.2067492
39
+ y * (0.2659732 + y * (0.360768e-1 + y * 0.45813e-2)))));
40
}
41
42
auto
y = 3.75 / ax;
43
44
return
(std::exp (ax) / std::sqrt (ax))
45
* (0.39894228 + y * (0.1328592e-1 + y * (0.225319e-2 + y * (-0.157565e-2 + y * (0.916281e-2
46
+ y * (-0.2057706e-1 + y * (0.2635537e-1 + y * (-0.1647633e-1 + y * 0.392377e-2))))))));
47
}
48
49
void
SpecialFunctions::ellipticIntegralK
(
double
k,
double
& K,
double
& Kp)
noexcept
50
{
51
constexpr
int
M = 4;
52
53
K =
MathConstants<double>::halfPi
;
54
auto
lastK = k;
55
56
for
(
int
i = 0; i < M; ++i)
57
{
58
lastK = std::pow (lastK / (1 + std::sqrt (1 - std::pow (lastK, 2.0))), 2.0);
59
K *= 1 + lastK;
60
}
61
62
Kp =
MathConstants<double>::halfPi
;
63
auto
last = std::sqrt (1 - k * k);
64
65
for
(
int
i = 0; i < M; ++i)
66
{
67
last = std::pow (last / (1.0 + std::sqrt (1.0 - std::pow (last, 2.0))), 2.0);
68
Kp *= 1 + last;
69
}
70
}
71
72
Complex<double>
SpecialFunctions::cde
(Complex<double> u,
double
k)
noexcept
73
{
74
constexpr
int
M = 4;
75
76
double
ke[M + 1];
77
double
* kei = ke;
78
*kei = k;
79
80
for
(
int
i = 0; i < M; ++i)
81
{
82
auto
next = std::pow (*kei / (1.0 + std::sqrt (1.0 - std::pow (*kei, 2.0))), 2.0);
83
*++kei = next;
84
}
85
86
// NB: the spurious cast to double here is a workaround for a very odd link-time failure
87
std::complex<double> last = std::cos (u * (
double
)
MathConstants<double>::halfPi
);
88
89
for
(
int
i = M - 1; i >= 0; --i)
90
last = (1.0 + ke[i + 1]) / (1.0 / last + ke[i + 1] * last);
91
92
return
last;
93
}
94
95
Complex<double>
SpecialFunctions::sne
(Complex<double> u,
double
k)
noexcept
96
{
97
constexpr
int
M = 4;
98
99
double
ke[M + 1];
100
double
* kei = ke;
101
*kei = k;
102
103
for
(
int
i = 0; i < M; ++i)
104
{
105
auto
next = std::pow (*kei / (1 + std::sqrt (1 - std::pow (*kei, 2.0))), 2.0);
106
*++kei = next;
107
}
108
109
// NB: the spurious cast to double here is a workaround for a very odd link-time failure
110
std::complex<double> last = std::sin (u * (
double
)
MathConstants<double>::halfPi
);
111
112
for
(
int
i = M - 1; i >= 0; --i)
113
last = (1.0 + ke[i + 1]) / (1.0 / last + ke[i + 1] * last);
114
115
return
last;
116
}
117
118
Complex<double>
SpecialFunctions::asne
(Complex<double> w,
double
k)
noexcept
119
{
120
constexpr
int
M = 4;
121
122
double
ke[M + 1];
123
double
* kei = ke;
124
*kei = k;
125
126
for
(
int
i = 0; i < M; ++i)
127
{
128
auto
next = std::pow (*kei / (1.0 + std::sqrt (1.0 - std::pow (*kei, 2.0))), 2.0);
129
*++kei = next;
130
}
131
132
std::complex<double> last = w;
133
134
for
(
int
i = 1; i <= M; ++i)
135
last = 2.0 * last / ((1.0 + ke[i]) * (1.0 + std::sqrt (1.0 - std::pow (ke[i - 1] * last, 2.0))));
136
137
return
2.0 /
MathConstants<double>::pi
* std::asin (last);
138
}
139
140
}
// namespace juce::dsp
juce::MathConstants::halfPi
static constexpr FloatType halfPi
Definition
juce_MathsFunctions.h:147
juce::MathConstants::pi
static constexpr FloatType pi
Definition
juce_MathsFunctions.h:141
juce::dsp::SpecialFunctions::sne
static Complex< double > sne(Complex< double > u, double k) noexcept
Definition
juce_SpecialFunctions.cpp:95
juce::dsp::SpecialFunctions::besselI0
static double besselI0(double x) noexcept
Definition
juce_SpecialFunctions.cpp:29
juce::dsp::SpecialFunctions::cde
static Complex< double > cde(Complex< double > u, double k) noexcept
Definition
juce_SpecialFunctions.cpp:72
juce::dsp::SpecialFunctions::asne
static Complex< double > asne(Complex< double > w, double k) noexcept
Definition
juce_SpecialFunctions.cpp:118
juce::dsp::SpecialFunctions::ellipticIntegralK
static void ellipticIntegralK(double k, double &K, double &Kp) noexcept
Definition
juce_SpecialFunctions.cpp:49
libopenshot-audio
JuceLibraryCode
modules
juce_dsp
maths
juce_SpecialFunctions.cpp
Generated by
1.18.0