forked from grame-cncm/faustlibraries
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmi.lib
More file actions
154 lines (144 loc) · 5.45 KB
/
mi.lib
File metadata and controls
154 lines (144 loc) · 5.45 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
//############################# mi.lib #########################################
// This ongoing work is the fruit of a collaboration between GRAME-CNCM and
// Gipsa-Lab at Grenoble INP.
//
// ## Sources
//
// All the algorithms implemented in this library are in the public domain
// and are disclosed in the following scientific publications:
// * Claude Cadoz, Annie Luciani, Jean-Loup Florens, Curtis Roads and Françoise
// Chabade. Responsive Input Devices and Sound Synthesis by Stimulation of
// Instrumental Mechanisms: The Cordis System. Computer Music Journal, Vol 8.
// No. 3, 1984.
// * Claude Cadoz, Annie Luciani and Jean Loup Florens. CORDIS-ANIMA: A Modeling
// and Simulation System for Sound and Image Synthesis: The General Formalism.
// Computer Music Journal. Vol. 17, No. 1, 1993.
// * Alexandros Kontogeorgakopoulos and Claude Cadoz. Cordis Anima Physical
// Modeling and Simulation System Analysis. In Proceedings of the Sound and Music
// Computing Conference (SMC-07), Lefkada, Greece, 2007.
// * Nicolas Castagne, Claude Cadoz, Ali Allaoui and Olivier Tache. G3: Genesis
// Software Environment Update. In Proceedings of the International Computer
// Music Conference (ICMC-09), Montreal, Canada, 2009.
// * Nicolas Castagné and Claude Cadoz. Genesis 3: Plate-forme pour la création
// musicale à l'aide des modèles physiques Cordis-Anima. In Proceedings of the
// Journée de l'Informatique Musicale, Grenoble, France, 2009.
// * Edgar Berdahl and Julius O. Smith. An Introduction to the Synth-A-Modeler
// Compiler: Modular and Open-Source Sound Synthesis using Physical Models. In
// Proceedings of the Linux Audio Conference (LAC-12), Stanford, USA, 2012.
// * James Leonard and Claude Cadoz. Physical Modelling Concepts for a Collection
// of Multisensory Virtual Musical Instruments. In Proceedings of the New
// Interfaces for Musical Expression (NIME-15) Conference, Baton Rouge, USA, 2015.
//
// ## License
//
// The MIT License (MIT)
//
// Copyright (c) <2019> <GRAME-CNCM (Lyon, France) and Gipsa-Lab (Grenoble,
// France)>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//##############################################################################
ma = library("maths.lib");
ba = library("basics.lib");
// initialize the state of a variable in a letrec system (only first order)
//initState(init) = +(init : ba.impulsify);
initState((init)) = R(0,init)
with{
R(n,(initn,init)) = +(initn : ba.impulsify@n) : R(n+1,init);
R(n,initn) = +(initn : ba.impulsify@n);
};
// integrated oscillator (mass-spring-ground system)
// m, k, z: mass, stiffness, damping (algorithmic values)
// x0, x1: initial position and delayed position
osc(m,k,z,x0,x1) = equation
with{
A = 2 - (k + z)/m;
B = z/m - 1;
C = 1/m;
equation = x
letrec{
'x = A*(x : initState(x0)) + B*(x' : initState(x1)) + *(C);
};
};
// punctual mass module
// m: mass (algorithmic value)
// x0, x1: initial position and delayed position
mass(m,x0,x1) = equation
with{
A = 2;
B = -1;
C = 1/m;
equation = x
letrec{
'x = A*(x : initState(x0)) + B*(x' : initState((x1,x0))) + *(C);
};
};
// punctual ground module
// x0: initial position
ground(x0) = equation
with{
// could this term be removed or simlified? Need "unused" input force signal for routing scheme
C = 0;
equation = x
letrec{
'x = (x : initState(x0)) + *(C);
};
};
// spring
// k,z: stiffness and daming (algorithmic values)
spring(k,z,x1r0,x2r0,x1,x2) =
k*(x1-x2) +
z*((x1 - (x1' : initState(x1r0))) - (x2 - (x2' : initState(x2r0)))) <: *(-1),_;
// nlPluck
// 1D non-linear picking Interaction algorithm
nlPluck(k,scale,x1,x2) =
select2(
absdeltapos>scale,
select2(
absdeltapos>(scale*0.5),
k*deltapos,
k*(ma.signum(deltapos)*scale*0.5 - deltapos)),
0) <: *(-1),_
with{
deltapos = x1 - x2;
absdeltapos = abs(deltapos);
};
// nlBow
// 1D non-linear bowing Interaction algorithm
nlBow(z,scale,x1r0,x2r0,x1,x2) =
select2(
absspeed>scale,
select2(
absspeed>(scale*0.333),
z*speed,
z*(ma.signum(speed)*scale*0.333) - z*0.25*speed),
0) <: *(-1),_
with{
speed = ((x1 - x1') - (x2 - x2'));
absspeed = abs(speed);
};
// collision
// k,z: stiffness and daming (algorithmic values)
// thres: position threshold for the collision to be active
collision(k,z,thres,x1r0,x2r0,x1,x2) =
spring(k,z,x1r0,x2r0,x1,x2) : (select2(comp,0,_),select2(comp,0,_))
with{
comp = (x2-x1) < thres;
};
posInput(init) = _,_ : !,_ : initState(init);