LMMS
Loading...
Searching...
No Matches
juce_SpecialFunctions.cpp
Go to the documentation of this file.
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
26namespace juce
27{
28namespace dsp
29{
30
31double SpecialFunctions::besselI0 (double x) noexcept
32{
33 auto ax = std::abs (x);
34
35 if (ax < 3.75)
36 {
37 auto y = x / 3.75;
38 y *= y;
39
40 return 1.0 + y * (3.5156229 + y * (3.0899424 + y * (1.2067492
41 + y * (0.2659732 + y * (0.360768e-1 + y * 0.45813e-2)))));
42 }
43
44 auto y = 3.75 / ax;
45
46 return (std::exp (ax) / std::sqrt (ax))
47 * (0.39894228 + y * (0.1328592e-1 + y * (0.225319e-2 + y * (-0.157565e-2 + y * (0.916281e-2
48 + y * (-0.2057706e-1 + y * (0.2635537e-1 + y * (-0.1647633e-1 + y * 0.392377e-2))))))));
49}
50
51void SpecialFunctions::ellipticIntegralK (double k, double& K, double& Kp) noexcept
52{
53 constexpr int M = 4;
54
56 auto lastK = k;
57
58 for (int i = 0; i < M; ++i)
59 {
60 lastK = std::pow (lastK / (1 + std::sqrt (1 - std::pow (lastK, 2.0))), 2.0);
61 K *= 1 + lastK;
62 }
63
65 auto last = std::sqrt (1 - k * k);
66
67 for (int i = 0; i < M; ++i)
68 {
69 last = std::pow (last / (1.0 + std::sqrt (1.0 - std::pow (last, 2.0))), 2.0);
70 Kp *= 1 + last;
71 }
72}
73
75{
76 constexpr int M = 4;
77
78 double ke[M + 1];
79 double* kei = ke;
80 *kei = k;
81
82 for (int i = 0; i < M; ++i)
83 {
84 auto next = std::pow (*kei / (1.0 + std::sqrt (1.0 - std::pow (*kei, 2.0))), 2.0);
85 *++kei = next;
86 }
87
88 // NB: the spurious cast to double here is a workaround for a very odd link-time failure
89 std::complex<double> last = std::cos (u * (double) MathConstants<double>::halfPi);
90
91 for (int i = M - 1; i >= 0; --i)
92 last = (1.0 + ke[i + 1]) / (1.0 / last + ke[i + 1] * last);
93
94 return last;
95}
96
98{
99 constexpr int M = 4;
100
101 double ke[M + 1];
102 double* kei = ke;
103 *kei = k;
104
105 for (int i = 0; i < M; ++i)
106 {
107 auto next = std::pow (*kei / (1 + std::sqrt (1 - std::pow (*kei, 2.0))), 2.0);
108 *++kei = next;
109 }
110
111 // NB: the spurious cast to double here is a workaround for a very odd link-time failure
112 std::complex<double> last = std::sin (u * (double) MathConstants<double>::halfPi);
113
114 for (int i = M - 1; i >= 0; --i)
115 last = (1.0 + ke[i + 1]) / (1.0 / last + ke[i + 1] * last);
116
117 return last;
118}
119
121{
122 constexpr int M = 4;
123
124 double ke[M + 1];
125 double* kei = ke;
126 *kei = k;
127
128 for (int i = 0; i < M; ++i)
129 {
130 auto next = std::pow (*kei / (1.0 + std::sqrt (1.0 - std::pow (*kei, 2.0))), 2.0);
131 *++kei = next;
132 }
133
134 std::complex<double> last = w;
135
136 for (int i = 1; i <= M; ++i)
137 last = 2.0 * last / ((1.0 + ke[i]) * (1.0 + std::sqrt (1.0 - std::pow (ke[i - 1] * last, 2.0))));
138
139 return 2.0 / MathConstants<double>::pi * std::asin (last);
140}
141
142} // namespace dsp
143} // namespace juce
UINT_D64 w
Definition inflate.c:942
register unsigned k
Definition inflate.c:946
int y
Definition inflate.c:1588
struct huft * u[BMAX]
Definition inflate.c:1583
register unsigned i
Definition inflate.c:1575
unsigned x[BMAX+1]
Definition inflate.c:1586
Definition juce_AudioBlock.h:29
std::complex< Type > Complex
Definition juce_dsp.h:194
Definition carla_juce.cpp:31
#define M
Definition nseel-cfunc.c:37
static constexpr FloatType halfPi
Definition juce_MathsFunctions.h:388
static constexpr FloatType pi
Definition juce_MathsFunctions.h:382
static Complex< double > sne(Complex< double > u, double k) noexcept
Definition juce_SpecialFunctions.cpp:97
static double besselI0(double x) noexcept
Definition juce_SpecialFunctions.cpp:31
static Complex< double > cde(Complex< double > u, double k) noexcept
Definition juce_SpecialFunctions.cpp:74
static Complex< double > asne(Complex< double > w, double k) noexcept
Definition juce_SpecialFunctions.cpp:120
static void ellipticIntegralK(double k, double &K, double &Kp) noexcept
Definition juce_SpecialFunctions.cpp:51
Definition globals.h:33