forked from s-e-a-m/faust-libraries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseam.analyzers.lib
176 lines (155 loc) · 6.66 KB
/
seam.analyzers.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
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
an = library("analyzers.lib");
//########################################################## measurement.lib ###
//
// A library for analise and measure signals. Its official prefix is `me`.
//
// * AMPLITUDE ANALYSIS
// * SOUND LEVEL WEIGHTING
// * FREQUENCY
// *
// *
//
//##############################################################################
/*******************************************************************************
Except where noted otherwise, Copyright (C) 2019-2020 by SEAM
GRAME LICENSE
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 Ambisonic Element Library";
declare version "0.1";
declare author "Giuseppe Silvi";
declare license "CC4";
san = library("seam.analyzers.lib");
//======================================================= AMPLITUDE ANALYSIS ===
//==============================================================================
//--------------------------------------------------------------- PEAK METERS --
pvmeter(x) = attach(x, an.amp_follower(0.150, x) : ba.linear2db :
vbargraph("[90][unit:dB]", -70, +6));
phmeter(x) = attach(x, an.amp_follower(0.150, x) : ba.linear2db :
hbargraph("[90][unit:dB]", -70, +6));
//
//==================================================== SOUND LEVEL WEIGHTING ===
//==============================================================================
//
//--------------------------------------------------- ANSI S1.43-1997 - 2007 ---
//---------------------------------------------- AMERICAN NATIONAL STANDARDS ---
//--------------------- SPECIFICATIONS FOR INTEGRATING-AVERAGING SOUND LEVEL ---
//
// https://en.wikipedia.org/wiki/A-weighting
// https://github.com/s-e-a-m/References/blob/master/aavv/ansi.s1.43.1997.pdf
//
//-------------------------------------------------------------- FREQUENCIES ---
awf1 = 20.598997;
awf2 = 107.65265;
awf3 = 737.86223;
awf4 = 12194.22;
awf5 = 158.48932;
//-------------------------------------- SCALE FACTORS TO HAVE 0dB at 1000Hz ---
C1000 = 0.0619;
B1000 = 0.1696;
A1000 = 1.9997;
//--------------------------------------------------------- A WEIGHTING OF f ---
aweight(f) = 20*log10(
(awf4^2*f^4) /
((f^2+awf1^2) * sqrt((f^2+awf2^2) * (f^2+awf3^2)) * (f^2+awf4^2))
) +(A1000);
//process = aweight(1000);
//--------------------------------------------------------- B WEIGHTING OF f ---
bweight(f) = 20*log10(
(awf4^2*f^3) /
((f^2+awf1^2) * (f^2+awf4^2) * sqrt((f^2+awf5^2)))
) +(B1000);
//process = bweight(1000);
//--------------------------------------------------------- C WEIGHTING OF f ---
cweight(f) = 20*log10(
(awf4^2*f^2) /
((f^2+awf1^2) * (f^2+awf4^2))
) +(C1000);
//process = cweight(1000);
//
//================================================================ FREQUENCY ===
//==============================================================================
// Universal Pitch Tracker
// From faust documentation
upt(a,x) = a*ma.SR / max(M,1) - a * ma.SR * (M == 0)
with{
// positive zero crossing
xcr = (x' < 0) & (x >= 0);
// counts of crossing
xcnt = +(xcr)~ %(int(a));
// windows of counts
wnd = xcr & (xcnt == a);
// counting samples inside windows
N = (+(1) : *(1 - wnd)) ~ _;
// sample and hold the number of cycles
M = ba.sAndH(N == 0, N' + 1);
};
//a = hslider("n cycles", 1, 1, 100, 1);
ptrack(x,a) = x : fi.dcblockerat(80) : (fi.lowpass(1) : upt(a)) ~ max(100);
//process = ptrack;
//---------------------------------------------------------------- RMS METERS --
//svmeter(x) = attach(x, RMS(1000, x) : ba.linear2db : vbargraph("[90][unit:dB]", -70, +6));
//shmeter(x) = attach(x, RMS(1000, x) : ba.linear2db : hbargraph("[90][unit:dB]", -70, +6));
//================================================================= LOUDNESS ===
//==============================================================================
//------------------------------------------------------------------------------
// RMS - ROOT MEAN SQUARE
//------------------------------------------------------------------------------
//RMS(n) = ba.slidingRMSn(n,1024);
//------------------------------------------------------------------------------
// BS1770
//------------------------------------------------------------------------------
pfs1 = fi.highshelf(2,4,1100);
pfs2 = fi.highpass(2,55);
tg = ba.sec2samp(0.400);
bs1770 = pfs1 : pfs2 <: _ , int(@(0.75*tg)) : 0.5*(RMS(tg)+RMS(tg));
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");