forked from s-e-a-m/faust-libraries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathambisonic.lib
164 lines (153 loc) · 5.96 KB
/
ambisonic.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
//############################################################ ambisonic.lib ###
//
// A library for general ambisonic documentation
//
// * ENCODERS
// * DECODERS
// *
// *
// *
//
//##############################################################################
/*******************************************************************************
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 "Ambisonic Elements Faust Library";
declare version "0.1";
declare author "Giuseppe Silvi";
declare license "CC4";
//================================================================= ENCODERS ===
//==============================================================================
//------------------------------------------------------------------------------
// MS STEREO TO FIRST ORDER B-FORMAT ENCODER
//------------------------------------------------------------------------------
// Converts a Mid-Side Stereo stream into Firts Order B-Format
//
// #### Reference
//
// #### Usage
//
// ```
// _,_ : ms2bfmt : _,_,_,_
// ```
//
// Where the two inputs are respectively:
// Mid and Side
//
// Where the four outpust are respectively:
// W,X,Y,Z
//
//------------------------------------------------------------------------------
ms2bfmt = (_ <: _,_), _;
//------------------------------------------------------------------------------
// LR STEREO TO FIRST ORDER B-FORMAT ENCODER
//------------------------------------------------------------------------------
// Converts a Left-Right Stereo stream into Mid-Side and then into
// Firts Order B-Format
//
// #### Reference
//
// #### Usage
//
// ```
// _,_ : lr2bfmt : _,_,_,_
// ```
//
// Where the two inputs are respectively:
// L,R
//
// Where the four outpust are respectively:
// W,X,Y,Z
//
//------------------------------------------------------------------------------
lr2ms2bfmt = sdmx : ms2bfmt;
//================================================================= DECODERS ===
//==============================================================================
//------------------------------------------------------------------------------
// FIRST ORDER PLANAR B-FORMAT TO MONO DECODER
//------------------------------------------------------------------------------
// Converts a First Order Planar B-Format into mono first order signal
//
// #### Reference
// https://en.wikipedia.org/wiki/Ambisonics
//
// The B-format components can be combined to derive virtual microphones with
// any first-order polar pattern (omnidirectional, cardioid, hypercardioid,
// figure-of-eight or anything in between) pointing in any direction. Several
// such microphones with different parameters can be derived at the same time,
// to create coincident stereo pairs (such as a Blumlein) or surround arrays.
// A horizontal virtual microphone at horizontal angle Θ \Theta with pattern
// 0 ≤ p ≤ 1 0 \leq p \leq 1 is given by
//
// This virtual mic is free-field normalised, which means it has a constant
// gain of one for on-axis sounds. The illustration on the left shows some
// examples created with this formula. Virtual microphones can be manipulated
// in post-production: desired sounds can be picked out, unwanted ones
// suppressed, and the balance between direct and reverberant sound can be
// fine-tuned during mixing.
//
// #### Usage
//
// ```
// encoder(x) = hgroup("BFMT MONO-DECODER", x);
// azi = encoder(vslider("[01] Azimuth [style:knob]", 0, 0, 360, 0.1) : deg2rad : si.smoo);
// p = encoder(vslider("[02] Polar [style:knob]", 0.5, 0, 1, 0.01) : si.smoo);
// deg2rad = *(ma.PI/180);
// process = _,_,_ : pbf2hm(azi,p) : _;
// ```
//
// Where the four inputs are respectively:
// W,X,Y
//
// Where the output is a mono signal with modulable polar pattern:
// out: m
// polar pattern: p
//
//------------------------------------------------------------------------------
pbf2hm(azi,p) = p*(sqrt(2)*(_))+((1-p)*((_*cos(azi))+(_*sin(azi))));
//------------------------------------------------------------------------------
// FIRST ORDER B-FORMAT TO REGULAR POLYGON
//------------------------------------------------------------------------------
// Converts a First Order B-Format n mono first order signal on the edge of a
// polygon
//
// #### Reference
// https://en.wikipedia.org/wiki/Ambisonics
//
// #### Usage
//
// ```
// _,_,_ : bfmt2m : _
// ```
//
// Where the two inputs are respectively:
// W,X,Y,Z
//
// Where the output is a mono signal with modulable polar pattern:
// m
//
//------------------------------------------------------------------------------
pbf2poly(n,p) = polygon
with{
azi(n) = 360/(n) : deg2rad;
polygon(n) = par(i, n, pbf2m);
};