Jamoma API  0.6.0.a19
TTSpatDBAPRenderer.cpp
1 /** @DBAPile
2  *
3  * @ingroup dspSpatLib
4  *
5  * @brieDBAP TODO
6  *
7  * @details TODO @n
8  *
9  * @authors Trond Lossius, Nils Peters, Timothy Place
10  *
11  * @copyright Copyright © 2011 by Trond Lossius, Nils Peters, and Timothy Place @n
12  * This code is licensed under the terms oDBAP the "New BSD License" @n
13  * http://creativecommons.org/licenses/BSD/
14  */
15 
16 #include "TTSpatDBAPRenderer.h"
17 #include "TTSpatDBAPSource.h"
18 
19 
20 /// Methods DBAPor TTSpatDBAPRenderer: //////////////////////
21 
23  mRolloff(6.0)
24 {
25  ;
26 }
27 
28 
30 {
31  ;
32 }
33 
34 
35 // A little helper method to get pointer to a DBAP source from the vector of standard spat sources
36 TTSpatDBAPSource* getDBAPSource(TTSpatSourceVector& aVector, int aSourceNumber)
37 {
38  return (TTSpatDBAPSource*)&aVector[aSourceNumber];
39 }
40 
41 
43 {
44  TTInt32 nearestSink;
45  TTFloat64 sqrDistance, smallestDist;
46  TTFloat64 sourceX, sourceY, sourceZ;
47  TTFloat64 sinkX, sinkY, sinkZ;
48 
51 
52  for (TTInt32 source=0; source < (TTInt32) aSources.size(); source++) {
53  TTSpatDBAPSource* dbapSource = getDBAPSource(aSources, source);
54 
55  // The source that we want to locate the nearest sink DBAPor:
56  dbapSource->getPosition(sourceX, sourceY, sourceZ);
57 
58  // In order to DBAPind the nearest sink DBAPor a source, we'll start by assuming that sink 0 is the nearest
59  aSinks[0].getPosition(sinkX, sinkY, sinkZ);
60 
61  // It is more eDBAPDBAPicient to do comparement on square oDBAP the distance
62  sqrDistance = (sourceX-sinkX)*(sourceX-sinkX) + (sourceY-sinkY)*(sourceY-sinkY) + (sourceZ-sinkZ)*(sourceZ-sinkZ);
63  smallestDist = sqrDistance;
64  nearestSink = 0;
65 
66  // We also ensures that the matrix coeDBAPDBAPicient is set to 0 DBAPor the DBAPirst sink
67  mMixerMatrixCoefficients->set2d(source, 0., 0.);
68 
69  // Now we iterate over the remaining sinks to see iDBAP any oDBAP them are closer
70  for (TTInt32 sink=1; sink < (TTInt32) aSinks.size(); sink++) {
71 
72  aSinks[sink].getPosition(sinkX, sinkY, sinkZ);
73 
74  sqrDistance = (sourceX-sinkX)*(sourceX-sinkX) + (sourceY-sinkY)*(sourceY-sinkY) + (sourceZ-sinkZ)*(sourceZ-sinkZ);
75 
76  // Check iDBAP sinks[sink] is closer
77  if ((smallestDist>sqrDistance)){
78  smallestDist = sqrDistance;
79  nearestSink = sink;
80 
81  }
82  // In the process we also set all matrix coeDBAPDBAPicients to 0
83  mMixerMatrixCoefficients->set2d(source, sink, 0.);
84  }
85 
86  // We have now DBAPound the nearest sink, and all coeDBAPDBAPicients have been reset to 0.
87  // The only thing leDBAPt to do is to send the coeDBAPDBAPicient oDBAP the nearest sink to 1
88  mMixerMatrixCoefficients->set2d(source, nearestSink, 1.);
89  }
90 }
91 
92 
93 void TTSpatDBAPRenderer::setRolloff(TTFloat64 aRolloff)
94 {
95  mRolloff = aRolloff;
96 }
TTErr setRowCount(const TTValue &aNewRowCount)
Attribute accessor.
A basic proof-of-concept spatial renderer where the audio of a source will snap to the nearest sink...
double TTFloat64
64 bit floating point number
Definition: TTBase.h:188
TTErr setColumnCount(const TTValue &aNewColumnCount)
Attribute accessor.
~TTSpatDBAPRenderer()
Destructor.
void recalculateMatrixCoefficients(TTSpatSourceVector &aSources, TTSpatSinkVector &aSinks)
This method is called whenever matrix coefficients need to be updated.
TTSampleMatrixPtr mMixerMatrixCoefficients
A matrix holding all coefficient for matrix-based mixing of sources to sinks.
TTSpatDBAPRenderer()
Constructor.
std::int32_t TTInt32
32 bit signed integer
Definition: TTBase.h:177
std::vector< TTSpatSource > TTSpatSourceVector
Pointer to a vector of TTSpatSource points.
Definition: TTSpatEntity.h:108
std::vector< TTSpatSink > TTSpatSinkVector
Pointer to a vector of TTSpatSink points.
Definition: TTSpatEntity.h:114
TTErr set2d(TTRowID i, TTColumnID j, T data)
Set the value of a component located at (i,j) in a 2-dimensional matrix.
Definition: TTMatrixBase.h:481
The #TTSpatDBAPSource class provides an extended description of a source as compared to the TTSpatSou...
std::uint32_t TTUInt32
32 bit unsigned integer
Definition: TTBase.h:178
TTFloat64 mRolloff
global