forked from s-e-a-m/faust-libraries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseam.math.lib
119 lines (115 loc) · 4.3 KB
/
seam.math.lib
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// ---
// description: SEAM Math Library
// ---
//
// <!-- LICENSE: GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 -->
//
// # seam.math.lib
//
// ```text
declare name "SEAM Math - Library";
declare version "0.1";
declare author "Giuseppe Silvi";
declare license "CC3";
// ```
sma = library("seam.math.lib");
//======================================================================= PI ===
//==============================================================================
//----------------------------------------------- QUAD PRECISION 81 DECIMALS ---
PIq = 3.14159265358979323846264338327950288419716939937510582097494459230781640;
PIc = atan(1)*4;
// 2pi
twopi = 2*ma.PI;
tau = twopi;
//------------------------------------------------------------------------ e ---
eu = 2.71828182845904523536028747135266249775724709369995957496696762772407663;
ecalc = _ <: (1+(1/_))^_;
//-------------------------------------------------------------------- OMEGA ---
omega(fc) = fc*twopi/ma.SR;
//------------------------------------------------------- BILINEAR TRANSFORM ---
w(fc) = tan(ma.PI*fc/ma.SR);
//------------------------------------------------------------ SIN^2 - COS^2 ---
cosq(x) = cos(x)*cos(x);
sinq(x) = sin(x)*sin(x);
//======================================================== POLAR | CARTESIAN ===
//==============================================================================
//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
// https://en.wikipedia.org/wiki/Inverse_trigonometric_functions
// https://en.wikipedia.org/wiki/Spherical_coordinate_system
// https://en.wikipedia.org/wiki/Atan2
//------------------------------------------------------- DEGREES TO RADIANS ---
d2r = *(ma.PI/180);
//------------------------------------------------------- RADIANS TO DEGREES ---
r2d = _/ma.PI*180;
//--------------------------------------------------------- AED TO CARTESIAN ---
aed2xyz(a,e,d) = cx(a,e,d), cy(a,e,d), cz(a,e,d)
with{
cx(a,e,d) = d*(cos(a)*cos(e));
cy(a,e,d) = d*(sin(a)*cos(e));
cz(a,e,d) = d*(sin(e));
};
//process = aed2xyz;
//--------------------------------------------------------- CARTESIAN TO AED ---
xyz2aed(x,y,z) = a(x,y),e(x,y,z),d(x,y,z)
with{
a(x,y) = atan2(y,x);
e(x,y,z) = atan2(sqrt(x^2+y^2),z);
d(x,y,z) = sqrt(x^2+y^2+z^2);
};
//process = xyz2aed(1/sqrt(2),1/sqrt(2),1/sqrt(2)) : r2d, r2d, _ ;
//====================================================================== PHI ===
//==============================================================================
phi = *(1+(sqrt(5)))/2;
// reciprocal o the golden ratio
rphi = *(sqrt(5)-1)/2;
// phi progression
srphi(0,x) = x;
srphi(i,x) = rphi(x) : srphi(i-1);
//process = srphi(16,24000);
//=============================================================== FACTORIALS ===
//==============================================================================
factorial(0) = 1;
factorial(i) = i * factorial(i-1);
permutation(k,n) = factorial(k)/factorial(n);
//=========================================================== SPEED OF SOUND ===
//==============================================================================
esos = 344; // exterior
isos = 331.4; // interior
//-------------------------------------------------------- METERS TO SAMPLES ---
emt2samp(mt) = int(mt*ma.SR/esos);
imt2samp(mt) = int(mt*ma.SR/isos);
aa = library("aanl.lib");
sf = library("all.lib");
an = library("analyzers.lib");
ba = library("basics.lib");
co = library("compressors.lib");
de = library("delays.lib");
dm = library("demos.lib");
dx = library("dx7.lib");
en = library("envelopes.lib");
fd = library("fds.lib");
fi = library("filters.lib");
ho = library("hoa.lib");
it = library("interpolators.lib");
ma = library("maths.lib");
mi = library("mi.lib");
ef = library("misceffects.lib");
os = library("oscillators.lib");
no = library("noises.lib");
pf = library("phaflangers.lib");
pl = library("platform.lib");
pm = library("physmodels.lib");
qu = library("quantizers.lib");
rm = library("reducemaps.lib");
re = library("reverbs.lib");
ro = library("routes.lib");
sp = library("spats.lib");
si = library("signals.lib");
so = library("soundfiles.lib");
sy = library("synths.lib");
ve = library("vaeffects.lib");
vl = library("version.lib");
wa = library("webaudio.lib");
wd = library("wdmodels.lib");