forked from grame-cncm/faustlibraries
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfloat.lib
More file actions
70 lines (58 loc) · 3.11 KB
/
float.lib
File metadata and controls
70 lines (58 loc) · 3.11 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
//#################################### float.lib ########################################
// A library to handle float specific code in Faust.
//########################################################################################
/************************************************************************
************************************************************************
FAUST library file
Copyright (C) 2019 GRAME, Centre National de Creation Musicale
----------------------------------------------------------------------
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
EXCEPTION TO THE LGPL LICENSE : As a special exception, you may create a
larger FAUST program which directly or indirectly imports this library
file and still distribute the compiled code generated by the FAUST
compiler, or a modified version of this compiled code, under your own
copyright and license. This EXCEPTION TO THE LGPL LICENSE explicitly
grants you the right to freely choose the license for the resulting
compiled code. In particular the resulting compiled code has no obligation
to be LGPL or GPL. For example you are free to choose a commercial or
closed source license or any other license if you decide so.
************************************************************************
************************************************************************/
declare name "Faust float Library";
declare version "0.1";
/*
Simple index signal that is not precise enough in float (OK in double)
raise(trig, step, length) = (+(step):*(reset(trig)))~_ with { reset(trig) = (trig-trig') <= 0; };
*/
// 'idv' is to be used as a read index. In -float mode, we use a technique using a
// pure integer index with a fractional part in [0,1] range in to avoid accumulating errors
int_part(idv) = idv : _,!;
frac_part(idv) = idv : !,_;
reset(trig) = (trig-trig') <= 0;
// Infinite raising index
raise(trig, step, length) = id, dv
letrec {
'id = (id + int(step) + int(dv + ma.frac(step))) * reset(trig);
'dv = ma.frac(dv + ma.frac(step)) * reset(trig);
};
// Modulo based raising index
raise_modulo(trig, step, length) = id, dv
letrec {
'id = fmod(id + int(step) + int(dv + ma.frac(step)), length) * reset(trig);
'dv = ma.frac(dv + ma.frac(step)) * reset(trig);
};
// Decreasing index starting at 'length'
decrease(trig, step, length) = raise(trig, -step, length) : (+(length), _);
// Modulo decreasing index starting at 'length'
decrease_modulo(trig, step, length) = raise_modulo(trig, -step, length) : (+(length), _);