Jamoma API  0.6.0.a19
j.dbap_bformat.h
Go to the documentation of this file.
1 /** @file
2  * @ingroup implementationMaxExternals
3  *
4  * @brief j.dbap_bformat - Distance Based Amplitude Panning using 4-channel ambisonic Bformat signals as sources.
5  *
6  * @details
7  *
8  * @authors Trond Lossius
9  *
10  * @copyright Copyright © 2011, 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 
16 // This is currently restricted if memory for struct is to be assigned using malloc
17 const long MAX_NUM_SOURCES = 16;
18 const long MAX_NUM_DESTINATIONS = 32;
19 
20 
21 t_symbol *psRollOff,
22  *psNumberOfSources,
23  *psNumberOfDestinations,
24  *psDestinationPosition,
25  *psSourcePosition,
26  *psSourceGain,
27  *psSourceMute,
28  *psSourceBlur;
29 
30 
31 /** Data structure for storing a 1,2 or 3 dimensional space data
32  @ingroup typedefs
33  */
34 typedef struct _xyz{
35  double x; ///< x position
36  double y; ///< y position
37  double z; ///< z position
38 } t_xyz; ///< Cartesian coordinate of a point
39 
40 
41 /** Data structure for storing ambisonics decoding coeficients
42  @ingroup typedefs
43  */
44 typedef struct _decodeCoefficients{
45  double w; ///< Zero order W coefficient
46  double x; ///< First order X coefficient
47  double y; ///< First order Y coefficient
48  double z; ///< First order Z coefficient
50 
51 /** Structure for the j.dbap_bformat Max object.
52  @ingroup typedefs
53  */
54 typedef struct _dbap_bformat{ ///< Data structure for this object
55  // Max stuff
56  t_object ob; ///< Must always be the first field; used by Max
57  void *outlet; ////< Pointer to outlets. Need one for each outlet
58 
59  // Sources
60  long attrNumberOfSources; ///< number of active sources
61  t_xyz sourcePosition[MAX_NUM_SOURCES]; ///< Positions of the virtual source
62  double blur[MAX_NUM_SOURCES]; ///< Spatial bluriness ratio in percents for each source
63  double polarity[MAX_NUM_SOURCES]; ///< Polarity for each source, from 0 (omni) to 1 (in-phase) decoding
64  double sourceGain[MAX_NUM_SOURCES]; ///< Linear gain for each source, not yet used
65  double sourceNotMuted[MAX_NUM_SOURCES]; ///< Mute and unmute sources
66 
67  double sourceWeight
68  [MAX_NUM_SOURCES]
69  [MAX_NUM_DESTINATIONS]; ///< Weight for each source for each destination
71  decodeCoefficients
72  [MAX_NUM_SOURCES]
73  [MAX_NUM_DESTINATIONS]; ///< Ambisonics decoding coefficients for each source for each destination
74 
75  // Destinations
76  long attrNumberOfDestinations; ///< Number of active destinations
77  t_xyz destinationPosition[MAX_NUM_DESTINATIONS]; ///< Array of speaker positions
78  t_xyz meanDestinationPosition; ///< Mean position of the field of destination points
79 
80  // Globals
81  double masterGain; ///< Mater gain for all of the algorithm
82  double variance; ///< Bias-corrected variance of distance from destination points to mean destination point
83  double attrRollOff; ///< Set rolloff with distance in dB
84  double attrVicinity; ///< Set radius of field of vicinity around speaker where decoding gets increasingly omni
85  double a; ///< Constant: Exponent controlling amplitude dependance on distance. Depends on attrRollOff
87 
88 
89 // Prototypes for methods: need a method for each incoming message
90 
91 void *dbap_bformatNew(t_symbol *msg, long argc, t_atom *argv);
92 t_max_err dbap_bformat_setstep(t_dbap_bformat *x, void *attr, long argc, t_atom *argv);
93 
94 /** Set spatial blur for nth source. */
95 void dbap_bformatBlur(t_dbap_bformat *x, t_symbol *msg, long argc, t_atom *argv);
96 
97 /** Set spatial blur for all sources. */
98 void dbap_bformatBlurAll(t_dbap_bformat *x, double f);
99 
100 /** Set polarity of the nth virtual source */
101 void dbap_bformatPolarity(t_dbap_bformat *x, t_symbol *msg, long argc, t_atom *argv);
102 
103 /** Set polarity for all sources */
104 void dbap_bformatPolarityAll(t_dbap_bformat *x, double f);
105 
106 /** Set radius of vicinity field around speaker where decoding will converge towards omni */
107 t_max_err dbap_bformatAttrSetVicinity(t_dbap_bformat *x, void *attr, long argc, t_atom *argv);
108 
109 /** Set the position of the nth virtual source. */
110 void dbap_bformatSource(t_dbap_bformat *x, void *msg, long argc, t_atom *argv);
111 
112 /** Set the position of the nth speaker. */
113 void dbap_bformatDestination(t_dbap_bformat *x, void *msg, long argc, t_atom *argv);
114 
115 /** Set input gain for nth source. */
116 void dbap_bformatSourceGain(t_dbap_bformat *x, void *msg, long argc, t_atom *argv);
117 
118 /** Set master gain for all values passed from the object to matrix~. */
119 void dbap_bformatMasterGain(t_dbap_bformat *x, double f);
120 
121 /** Set weight for nth source by passing a list to balance each destination. */
122 void dbap_bformatSourceWeight(t_dbap_bformat *x, t_symbol *msg, long argc, t_atom *argv);
123 
124 /** Mute and unmute sources */
125 void dbap_bformatSourceMute(t_dbap_bformat *x, void *msg, long argc, t_atom *argv);
126 
127 /** Get info on destination setup ++ */
129 
130 /** Display assist strings while patching. */
131 void dbap_bformatAssist(t_dbap_bformat *x, void *b, long msg, long arg, char *dst);
132 
133 /** Set the number of sources of the system. */
134 t_max_err dbap_bformatAttrSetNumberOfSources(t_dbap_bformat *x, void *attr, long argc, t_atom *argv);
135 
136 /** Set the number of destinations of the system. */
137 t_max_err dbap_bformatAttrSetNumberOfDestinations(t_dbap_bformat *x, void *attr, long argc, t_atom *argv);
138 
139 /** Set spatial blur coefficient */
140 t_max_err dbap_bformatAttrSetBlur(t_dbap_bformat *x, void *attr, long argc, t_atom *argv);
141 
142 /** Set rolloff in dB */
143 t_max_err dbap_bformatAttrSetRollOff(t_dbap_bformat *x, void *attr, long argc, t_atom *argv);
144 
145 /** Calculation of exponent coefficient based on rolloff */
147 
148 /** General method for calculation of matrix coefficient for nth source. */
149 void dbap_bformatCalculate(t_dbap_bformat *x, long n);
150 
151 /** Calculate mean position of the destination points. */
153 
154 /** Calculate bias-corrected variance of distance from destination points to mean destination point. */
156 
157 /** Calculate the view (2D-matrix) */
158 void dbap_bformatCalculateView(t_dbap_bformat *x, long dst, long src);
159 
160 /** If the attrViewMatrixUpdate is true : calculate the last view */
162 
163 /** Calculate the view (2D-matrix) : 1D */
164 void dbap_bformatCalculateView1D(t_dbap_bformat *x, long dst, long src);
165 
166 /** Calculate the view (2D-matrix) : 2D */
167 void dbap_bformatCalculateView2D(t_dbap_bformat *x, long dst, long src);
168 
169 /** Calculate the view (2D-matrix) : 3D */
170 void dbap_bformatCalculateView3D(t_dbap_bformat *x, long dst, long src);
171 
172 /** Output the calculated view */
void dbap_bformatCalculateView1D(t_dbap_bformat *x, long dst, long src)
Calculate the view (2D-matrix) : 1D.
void dbap_bformatBlurAll(t_dbap_bformat *x, double f)
Set spatial blur for all sources.
t_xyz meanDestinationPosition
Mean position of the field of destination points.
long attrNumberOfDestinations
Number of active destinations.
void dbap_bformatDestination(t_dbap_bformat *x, void *msg, long argc, t_atom *argv)
Set the position of the nth speaker.
void dbap_bformatPolarity(t_dbap_bformat *x, t_symbol *msg, long argc, t_atom *argv)
Set polarity of the nth virtual source.
void dbap_bformatMasterGain(t_dbap_bformat *x, double f)
Set master gain for all values passed from the object to matrix~.
void dbap_bformatCalculateMeanDestinationPosition(t_dbap_bformat *x)
Calculate mean position of the destination points.
Structure for the j.dbap_bformat Max object.
t_object ob
< Data structure for this object
void dbap_bformatCalculate(t_dbap_bformat *x, long n)
General method for calculation of matrix coefficient for nth source.
void dbap_bformatAssist(t_dbap_bformat *x, void *b, long msg, long arg, char *dst)
Display assist strings while patching.
Data structure for storing ambisonics decoding coeficients.
t_max_err dbap_bformatAttrSetBlur(t_dbap_bformat *x, void *attr, long argc, t_atom *argv)
Set spatial blur coefficient.
void dbap_bformatPolarityAll(t_dbap_bformat *x, double f)
Set polarity for all sources.
t_max_err dbap_bformatAttrSetRollOff(t_dbap_bformat *x, void *attr, long argc, t_atom *argv)
Set rolloff in dB.
void dbap_bformatSourceGain(t_dbap_bformat *x, void *msg, long argc, t_atom *argv)
Set input gain for nth source.
void dbap_bformatSourceWeight(t_dbap_bformat *x, t_symbol *msg, long argc, t_atom *argv)
Set weight for nth source by passing a list to balance each destination.
double w
Zero order W coefficient.
double masterGain
Mater gain for all of the algorithm.
double attrVicinity
Set radius of field of vicinity around speaker where decoding gets increasingly omni.
t_max_err dbap_bformatAttrSetVicinity(t_dbap_bformat *x, void *attr, long argc, t_atom *argv)
Set radius of vicinity field around speaker where decoding will converge towards omni.
double y
First order Y coefficient.
void dbap_bformatCalculateView(t_dbap_bformat *x, long dst, long src)
Calculate the view (2D-matrix)
void dbap_bformatUpdateView(t_dbap_bformat *x)
If the attrViewMatrixUpdate is true : calculate the last view.
void dbap_bformatSource(t_dbap_bformat *x, void *msg, long argc, t_atom *argv)
Set the position of the nth virtual source.
double attrRollOff
Set rolloff with distance in dB.
void dbap_bformatBlur(t_dbap_bformat *x, t_symbol *msg, long argc, t_atom *argv)
Set spatial blur for nth source.
t_max_err dbap_bformatAttrSetNumberOfDestinations(t_dbap_bformat *x, void *attr, long argc, t_atom *argv)
Set the number of destinations of the system.
void dbap_bformatSourceMute(t_dbap_bformat *x, void *msg, long argc, t_atom *argv)
Mute and unmute sources.
void dbap_bformatCalculateA(t_dbap_bformat *x)
Calculation of exponent coefficient based on rolloff.
t_max_err dbap_bformatAttrSetNumberOfSources(t_dbap_bformat *x, void *attr, long argc, t_atom *argv)
Set the number of sources of the system.
void dbap_bformatOutputView(t_dbap_bformat *x)
Output the calculated view.
double x
First order X coefficient.
void dbap_bformatCalculateView2D(t_dbap_bformat *x, long dst, long src)
Calculate the view (2D-matrix) : 2D.
double a
Constant: Exponent controlling amplitude dependance on distance. Depends on attrRollOff.
void dbap_bformatInfo(t_dbap_bformat *x)
Get info on destination setup ++.
void dbap_bformatCalculateVariance(t_dbap_bformat *x)
Calculate bias-corrected variance of distance from destination points to mean destination point...
Data structure for storing a 1,2 or 3 dimensional space data.
Definition: j.dbap.h:43
double z
First order Z coefficient.
double variance
Bias-corrected variance of distance from destination points to mean destination point.
long attrNumberOfSources
number of active sources
void dbap_bformatCalculateView3D(t_dbap_bformat *x, long dst, long src)
Calculate the view (2D-matrix) : 3D.