Jamoma API  0.6.0.a19
j.dbap.h
Go to the documentation of this file.
1 /** @file
2  * @ingroup implementationMaxExternals
3  *
4  * @brief j.dbap - Distance Based Amplitude Panning
5  *
6  * @details
7  *
8  * @authors Trond Lossius, Tim Place, Théo de la Hogue
9  *
10  * @copyright Copyright © 2009, Trond Lossius @n
11  * This code is licensed under the terms of the "New BSD License" @n
12  * http://creativecommons.org/licenses/BSD/
13  */
14 
15 #include "jit.common.h"
16 #include "hull2D.h"
17 
18 // This seems to be the current restrictions of matrix~
19 const long MAX_NUM_SOURCES = 128;
20 const long MAX_NUM_DESTINATIONS = 128;
21 
22 const long MAX_NUM_WEIGHTED_SOURCES = 64;
23 const long MAX_NUM_WEIGHTED_DESTINATIONS = 32;
24 
25 const long MAX_SIZE_VIEW_X = 80;
26 const long MAX_SIZE_VIEW_Y = 60;
27 
28 t_symbol *ps_rollloff,
29  *ps_dimensions,
30  *ps_rolloff,
31  *ps_num_sources,
32  *ps_num_destinations,
33  *ps_dst_position,
34  *ps_src_position,
35  *ps_src_gain,
36  *ps_src_mute,
37  *ps_src_blur,
38  *ps_jit_matrix,
39  *ps_getdata,
40  *ps_setinfo;
41 
42 /** Data structure for storing a 1,2 or 3 dimensional space data */
43 typedef struct _xyz{
44  double x; ///< x position
45  double y; ///< y position
46  double z; ///< z position
47 } t_xyz; ///< Cartesian coordinate of a point
48 
49 /** Data structure for 1 dimensional convex hull */
50 typedef struct _hull1{
51  double min; ///< minimum x value
52  double max; ///< maximum x value
53 } t_hull1; ///< Convex hull in 1 dimension
54 
55 /** Data structure for 2 dimensional convex hull */
56 typedef struct _hull2{
57  long num_dst; ///< number dst in the convex hull
58  long id_dst[MAX_NUM_DESTINATIONS]; ///< index of dst in dst_position[]
59  double dst2next[MAX_NUM_DESTINATIONS]; ///< squared length of each border of the hull
60 } t_hull2; ///< Convex hull in 2 dimensions
61 
62 typedef struct _dbap{ ///< Data structure for this object
63  t_object ob; ///< Must always be the first field; used by Max
64  t_xyz src_position[MAX_NUM_SOURCES]; ///< Positions of the virtual source
65  double blur[MAX_NUM_SOURCES]; ///< Spatial bluriness ratio in percents for each source
66  double src_gain[MAX_NUM_SOURCES]; ///< Linear gain for each source, not yet used
67  double src_weight[MAX_NUM_WEIGHTED_SOURCES][MAX_NUM_WEIGHTED_DESTINATIONS];///< Weight for each source for each destination
68  double src_not_muted[MAX_NUM_SOURCES]; ///< Mute and unmute sources
69  double master_gain; ///< Mater gain for all of the algorithm
70  t_xyz dst_position[MAX_NUM_DESTINATIONS]; ///< Array of speaker positions
71  t_xyz mean_dst_position; ///< Mean position of the field of destination points
72  bool hull_io; ///< On/off calculation of distances to hull
73  t_hull1 hull1; ///< Convex hull in 1 dimension
74  t_hull2 hull2; ///< Convex hull in 2 dimensions
75  double variance; ///< Bias-corrected variance of distance from destination points to mean destination point
76  long attr_dimensions; ///< Number of dimensions of the speaker and source system
77  double attr_rolloff; ///< Set rolloff with distance in dB.
78  long attr_num_sources; ///< number of active sources
79  long attr_num_destinations; ///< number of active destinations
80 
81  void *view_matrix; ///< a jitter matrix to handle the view
82  t_symbol *view_name; ///< a unique name for the jitter matrix
83  t_jit_matrix_info view_info; ///< a data structure to handle the jitter matrix properties
84  t_xyz attr_view_start; ///< coordinate of the start point of the view
85  t_xyz attr_view_end; ///< coordinate of the end point of the view
86  bool attr_view_update; ///< IO the view updating
87  t_atom last_view[2]; ///< memorize the last view [dst src]
88 
89  double a; ///< Constant: Exponent controlling amplitude dependance on distance. Depends on attr_rolloff
90  void *outlet[3]; ////< Pointer to outlets. Need one for each outlet
91 } t_dbap;
92 
93 // Prototypes for methods: need a method for each incoming message
94 
95 void *dbap_new(t_symbol *msg, long argc, t_atom *argv);
96 t_max_err dbap_setstep(t_dbap *x, void *attr, long argc, t_atom *argv);
97 
98 void dbap_free(t_dbap *x);
99 
100 /** Set spatial blur for nth source. */
101 void dbap_blur(t_dbap *x, t_symbol *msg, long argc, t_atom *argv);
102 
103 /** Set spatial blur for all sources. */
104 void dbap_blurall(t_dbap *x, double f);
105 
106 /** Set the position of the nth virtual source. */
107 void dbap_source(t_dbap *x, void *msg, long argc, t_atom *argv);
108 
109 /** Set the position of the nth speaker. */
110 void dbap_destination(t_dbap *x, void *msg, long argc, t_atom *argv);
111 
112 /** Set input gain for nth source. */
113 void dbap_sourcegain(t_dbap *x, void *msg, long argc, t_atom *argv);
114 
115 /** Set master gain for all values passed from the object to matrix~. */
116 void dbap_mastergain(t_dbap *x, double f);
117 
118 /** Set weight for nth source by passing a list to balance each destination. */
119 void dbap_sourceweight(t_dbap *x, t_symbol *msg, long argc, t_atom *argv);
120 
121 /** Mute and unmute sources */
122 void dbap_sourcemute(t_dbap *x, void *msg, long argc, t_atom *argv);
123 
124 /** Turn on/off the calculation of distance to hull */
125 void dbap_hull(t_dbap *x, long f);
126 
127 /** Display a hitmap view of the dbap for a destination and a source weight config or all (on the info outlet ?) */
128 void dbap_view(t_dbap *x, void *msg, long argc, t_atom *argv);
129 
130 /** Turn on/off the auto view updating */
131 void dbap_view_update(t_dbap *x, long io);
132 
133 /** Set the size of hitmap view window */
134 void dbap_view_size(t_dbap *x, long sizeX, long sizeY);
135 
136 /** Set the start point of the hitmap view window */
137 void dbap_view_start(t_dbap *x, void *msg, long argc, t_atom *argv);
138 
139 /** Set the end point of the hitmap view window */
140 void dbap_view_end(t_dbap *x, void *msg, long argc, t_atom *argv);
141 
142 /** Get info on destination setup ++ */
143 void dbap_info(t_dbap *x);
144 
145 /** Display assist strings while patching. */
146 void dbap_assist(t_dbap *x, void *b, long msg, long arg, char *dst);
147 
148 /** Set number of dimensions of the system. */
149 t_max_err dbap_attr_setdimensions(t_dbap *x, void *attr, long argc, t_atom *argv);
150 
151 /** Set the number of sources of the system. */
152 t_max_err dbap_attr_setnum_sources(t_dbap *x, void *attr, long argc, t_atom *argv);
153 
154 /** Set the number of destinations of the system. */
155 t_max_err dbap_attr_setnum_destinations(t_dbap *x, void *attr, long argc, t_atom *argv);
156 
157 /** Set spatial blur coefficient */
158 t_max_err dbap_attr_setblur(t_dbap *x, void *attr, long argc, t_atom *argv);
159 
160 /** Set rolloff in dB */
161 t_max_err dbap_attr_setrolloff(t_dbap *x, void *attr, long argc, t_atom *argv);
162 
163 /** Calculation of exponent coefficient based on rolloff */
164 void dbap_calculate_a(t_dbap *x);
165 
166 /** General method for calculation of matrix coefficient for nth source. */
167 void dbap_calculate(t_dbap *x, long n);
168 
169 /** Calculate matrix coefficients for nth source: 1D space. */
170 void dbap_calculate1D(t_dbap *x, long n);
171 
172 /** Calculate matrix coefficients for nth source: 2D space. */
173 void dbap_calculate2D(t_dbap *x, long n);
174 
175 /** Calculate matrix coefficients for nth source: 3D space. */
176 void dbap_calculate3D(t_dbap *x, long n);
177 
178 /** Calculate mean position of the destination points. */
179 void dbap_calculate_mean_dst_position(t_dbap *x);
180 
181 /** Calculate bias-corrected variance of distance from destination points to mean destination point. */
182 void dbap_calculate_variance(t_dbap *x);
183 
184 /** Calculate convex hull of space spanned by destination points. */
185 void dbap_calculate_hull(t_dbap *x, long n);
186 
187 /** Calculate convex hull of space spanned by destination points: 1D */
188 void dbap_calculate_hull1D(t_dbap *x, long n);
189 
190 /** Calculate convex hull of space spanned by destination points: 2D */
191 void dbap_calculate_hull2D(t_dbap *x, long n);
192 void dbap_hull2_postpoint(t_dbap *x, t_H2D h2); // debug
193 
194 /** Calculate convex hull of space spanned by destination points: 3D */
195 void dbap_calculate_hull3D(t_dbap *x, long n);
196 
197 /** Calculate the view (2D-matrix) */
198 void dbap_calculate_view(t_dbap *x, long dst, long src);
199 
200 /** If the attr_view_update is true : calculate the last view */
201 void dbap_update_view(t_dbap *x);
202 
203 /** Calculate the view (2D-matrix) : 1D */
204 void dbap_calculate_view1D(t_dbap *x, long dst, long src);
205 
206 /** Calculate the view (2D-matrix) : 2D */
207 void dbap_calculate_view2D(t_dbap *x, long dst, long src);
208 
209 /** Calculate the view (2D-matrix) : 3D */
210 void dbap_calculate_view3D(t_dbap *x, long dst, long src);
211 
212 /** Output the calculated view */
213 void dbap_output_view(t_dbap *x);
void dbap_calculate_view2D(t_dbap *x, long dst, long src)
Calculate the view (2D-matrix) : 2D.
Definition: j.dbap.cpp:1173
t_max_err dbap_attr_setnum_destinations(t_dbap *x, void *attr, long argc, t_atom *argv)
Set the number of destinations of the system.
Definition: j.dbap.cpp:673
void dbap_blurall(t_dbap *x, double f)
Set spatial blur for all sources.
Definition: j.dbap.cpp:226
void dbap_calculate_view(t_dbap *x, long dst, long src)
Calculate the view (2D-matrix)
Definition: j.dbap.cpp:1147
void dbap_calculate3D(t_dbap *x, long n)
Calculate matrix coefficients for nth source: 3D space.
Definition: j.dbap.cpp:878
double min
minimum x value
Definition: j.dbap.h:51
void dbap_sourceweight(t_dbap *x, t_symbol *msg, long argc, t_atom *argv)
Set weight for nth source by passing a list to balance each destination.
Definition: j.dbap.cpp:345
void dbap_view_update(t_dbap *x, long io)
Turn on/off the auto view updating.
Definition: j.dbap.cpp:475
double max
maximum x value
Definition: j.dbap.h:52
void dbap_view(t_dbap *x, void *msg, long argc, t_atom *argv)
Display a hitmap view of the dbap for a destination and a source weight config or all (on the info ou...
Definition: j.dbap.cpp:429
void dbap_calculate_variance(t_dbap *x)
Calculate bias-corrected variance of distance from destination points to mean destination point...
Definition: j.dbap.cpp:938
t_max_err dbap_attr_setnum_sources(t_dbap *x, void *attr, long argc, t_atom *argv)
Set the number of sources of the system.
Definition: j.dbap.cpp:657
void dbap_blur(t_dbap *x, t_symbol *msg, long argc, t_atom *argv)
Set spatial blur for nth source.
Definition: j.dbap.cpp:202
void dbap_calculate_hull2D(t_dbap *x, long n)
Calculate convex hull of space spanned by destination points: 2D.
Definition: j.dbap.cpp:1011
void dbap_calculate(t_dbap *x, long n)
General method for calculation of matrix coefficient for nth source.
Definition: j.dbap.cpp:721
void dbap_calculate1D(t_dbap *x, long n)
Calculate matrix coefficients for nth source: 1D space.
Definition: j.dbap.cpp:735
void dbap_calculate_a(t_dbap *x)
Calculation of exponent coefficient based on rolloff.
Definition: j.dbap.cpp:913
void dbap_calculate_hull1D(t_dbap *x, long n)
Calculate convex hull of space spanned by destination points: 1D.
Definition: j.dbap.cpp:991
void dbap_mastergain(t_dbap *x, double f)
Set master gain for all values passed from the object to matrix~.
Definition: j.dbap.cpp:332
void dbap_calculate_hull(t_dbap *x, long n)
Calculate convex hull of space spanned by destination points.
Definition: j.dbap.cpp:976
Data structure for 2 dimensional convex hull.
Definition: j.dbap.h:56
double x
x position
Definition: j.dbap.h:44
t_max_err dbap_attr_setrolloff(t_dbap *x, void *attr, long argc, t_atom *argv)
Set rolloff in dB.
Definition: j.dbap.cpp:692
void dbap_hull(t_dbap *x, long f)
Turn on/off the calculation of distance to hull.
Definition: j.dbap.cpp:409
long num_dst
number dst in the convex hull
Definition: j.dbap.h:57
void dbap_source(t_dbap *x, void *msg, long argc, t_atom *argv)
Set the position of the nth virtual source.
Definition: j.dbap.cpp:240
void dbap_view_end(t_dbap *x, void *msg, long argc, t_atom *argv)
Set the end point of the hitmap view window.
Definition: j.dbap.cpp:533
double z
z position
Definition: j.dbap.h:46
void dbap_info(t_dbap *x)
Get info on destination setup ++.
Definition: j.dbap.cpp:561
void dbap_view_size(t_dbap *x, long sizeX, long sizeY)
Set the size of hitmap view window.
Definition: j.dbap.cpp:483
Data structure for 1 dimensional convex hull.
Definition: j.dbap.h:50
void dbap_output_view(t_dbap *x)
Output the calculated view.
Definition: j.dbap.cpp:1238
void dbap_calculate_mean_dst_position(t_dbap *x)
Calculate mean position of the destination points.
Definition: j.dbap.cpp:919
void dbap_calculate_hull3D(t_dbap *x, long n)
Calculate convex hull of space spanned by destination points: 3D.
Definition: j.dbap.cpp:1142
void dbap_destination(t_dbap *x, void *msg, long argc, t_atom *argv)
Set the position of the nth speaker.
Definition: j.dbap.cpp:273
Compute convex hulls in 2 dimensions.
void dbap_sourcemute(t_dbap *x, void *msg, long argc, t_atom *argv)
Mute and unmute sources.
Definition: j.dbap.cpp:390
void dbap_update_view(t_dbap *x)
If the attr_view_update is true : calculate the last view.
Definition: j.dbap.cpp:1162
void dbap_view_start(t_dbap *x, void *msg, long argc, t_atom *argv)
Set the start point of the hitmap view window.
Definition: j.dbap.cpp:504
double y
y position
Definition: j.dbap.h:45
void dbap_calculate_view1D(t_dbap *x, long dst, long src)
Calculate the view (2D-matrix) : 1D.
Definition: j.dbap.cpp:1168
t_max_err dbap_attr_setdimensions(t_dbap *x, void *attr, long argc, t_atom *argv)
Set number of dimensions of the system.
Definition: j.dbap.cpp:641
void dbap_assist(t_dbap *x, void *b, long msg, long arg, char *dst)
Display assist strings while patching.
Definition: j.dbap.cpp:603
t_max_err dbap_attr_setblur(t_dbap *x, void *attr, long argc, t_atom *argv)
Set spatial blur coefficient.
Data structure for storing a 1,2 or 3 dimensional space data.
Definition: j.dbap.h:43
void dbap_calculate2D(t_dbap *x, long n)
Calculate matrix coefficients for nth source: 2D space.
Definition: j.dbap.cpp:787
void dbap_calculate_view3D(t_dbap *x, long dst, long src)
Calculate the view (2D-matrix) : 3D.
Definition: j.dbap.cpp:1233
void dbap_sourcegain(t_dbap *x, void *msg, long argc, t_atom *argv)
Set input gain for nth source.
Definition: j.dbap.cpp:308