Jamoma API  0.6.0.a19
TTSpatBase.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspSpatLib
4  *
5  * @brief 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 of the "New BSD License" @n
13  * http://creativecommons.org/licenses/BSD/
14  */
15 
16 #include "TTSpatBase.h"
17 
18 #define thisTTClass TTSpatBase
19 #define thisTTClassName "spat.base"
20 #define thisTTClassTags "audio, base"
21 
22 
23 TT_AUDIO_CONSTRUCTOR
24 {
25  mSources.resize(1);
26  mSinks.resize(1);
27 
30 
31  addMessageWithArguments(setSourcePosition);
32  addMessageWithArguments(getSourcePosition);
33 
34  addMessageWithArguments(setSinkPosition);
35  addMessageWithArguments(getSinkPosition);
36 
37  setProcessMethod(processAudio);
38 }
39 
40 
41 TTSpatBase::~TTSpatBase()
42 {
43 
44 }
45 
46 
47 TTErr TTSpatBase::processAudio(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
48 {
49  return mRenderer->processAudio(inputs, outputs);
50 }
51 
52 
53 
55 {
56  value = TTUInt32(mSources.size());
57  return kTTErrNone;
58 }
59 
61 {
62 
63  TTInt32 number = value;
64 
65  TTLimitMin<TTInt32>(number, 1);
66  mSources.resize(number);
67  mRenderer->recalculateMatrixCoefficients(mSources, mSinks);
68  return kTTErrNone;
69 }
70 
71 
73 {
74  value = TTUInt32(mSinks.size());
75  return kTTErrNone;
76 }
77 
78 
80 {
81  TTInt32 number = value;
82 
83  TTLimitMin<TTInt32>(number, 1);
84  mSinks.resize(number);
85  mRenderer->recalculateMatrixCoefficients(mSources, mSinks);
86  return kTTErrNone;
87 }
88 
89 
91 {
92  // Ensure that source number is within range
93  TTInt32 source = sourceNumber - 1;
94  source = TTClip<TTInt32>(source, 0, mSources.size()-1);
95 
96  mSources[source].getPosition(x, y, z);
97 }
98 
99 
100 TTErr TTSpatBase::getSourcePosition(const TTValue& requestedChannel, TTValue& aPosition)
101 {
102  TTInt16 sourceNumber;
103  TTFloat64 x, y, z;
104 
105  // TODO: We need to think of what to do if there are no arguments...
106  // or if sinkNumber is out of range of the available sources
107 
108  sourceNumber = requestedChannel[0];
109 
110  getOneSourcePosition(sourceNumber, x, y, z);
111 
112  aPosition.resize(4);
113 
114  aPosition[0] = sourceNumber;
115  aPosition[1] = x;
116  aPosition[2] = y;
117  aPosition[3] = z;
118 
119  return kTTErrNone;
120 }
121 
122 
124 {
125  // Ensure that source number is within range
126  TTInt32 source = sourceNumber - 1;
127  source = TTClip<TTInt32>(source, 0, mSources.size()-1);
128 
129  mSources[source].setPosition(x, y, z);
130  mRenderer->recalculateMatrixCoefficients(mSources, mSinks);
131 }
132 
134 {
135  TTInt32 sourceNumber;
136  TTFloat64 x, y, z;
137 
138  // TODO: We need to think of what to do if there are not four arguments...
139 
140  sourceNumber = aPosition[0];
141  x = aPosition[1];
142  y = aPosition[2];
143  z = aPosition[3];
144 
145  setOneSourcePosition(sourceNumber, x, y, z);
146 
147  return kTTErrNone; // Return something else if we don't have four arguments
148 }
149 
150 
152 {
153  // Ensure that sink number is within range
154  TTInt32 sink = sinkNumber - 1;
155  sink = TTClip<TTInt32>(sink, 0, mSinks.size()-1);
156 
157  mSinks[sink].getPosition(x, y, z);
158  mRenderer->recalculateMatrixCoefficients(mSources, mSinks);
159 }
160 
161 
162 TTErr TTSpatBase::getSinkPosition(const TTValue& requestedChannel, TTValue& aPosition)
163 {
164  TTInt16 sinkNumber;
165  TTFloat64 x, y, z;
166 
167  // TODO: We need to think of what to do if there are no arguments...
168  // or if sinkNumber is out of range of the available sources
169 
170  sinkNumber = requestedChannel[0];
171 
172  getOneSinkPosition(sinkNumber, x, y, z);
173 
174  aPosition.resize(4);
175 
176  aPosition[0] = sinkNumber;
177  aPosition[1] = x;
178  aPosition[2] = y;
179  aPosition[3] = z;
180 
181  return kTTErrNone;
182 }
183 
184 
186 {
187  // Ensure that sink number is within range
188  TTInt32 sink = sinkNumber - 1;
189  sink = TTClip<TTInt32>(sink, 0, mSinks.size()-1);
190 
191  mSinks[sink].setPosition(x, y, z);
192 }
193 
194 
196 {
197  TTInt32 sinkNumber;
198  TTFloat64 x, y, z;
199 
200  // TODO: We need to think of what to do if there are not four arguments...
201 
202  sinkNumber = aPosition[0];
203  x = aPosition[1];
204  y = aPosition[2];
205  z = aPosition[3];
206 
207  setOneSinkPosition(sinkNumber, x, y, z);
208 
209  return kTTErrNone; // Return something else if we don't have four arguments
210 }
211 
212 
TTErr setSinkCount(const TTValue &value)
Set the number of sinks.
Definition: TTSpatBase.cpp:79
virtual TTErr processAudio(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
A standard matrix-based audio processing method which may be used for matrix-based spatialization alg...
virtual void recalculateMatrixCoefficients(TTSpatSourceVector &sources, TTSpatSinkVector &sinks)=0
This method must be defined by subclasses.
TTErr setSinkPosition(const TTValue &aPosition, TTValue &unused)
Set the position of one sink.
Definition: TTSpatBase.cpp:195
A basic proof-of-concept spatial renderer where the audio of a source will snap to the nearest sink...
TTErr getSinkCount(TTValue &value)
Get the number of sinks.
Definition: TTSpatBase.cpp:72
void getOneSourcePosition(TTInt32 sourceNumber, TTFloat64 &x, TTFloat64 &y, TTFloat64 &z)
Get the position of one source.
Definition: TTSpatBase.cpp:90
#define setProcessMethod(methodName)
A convenience macro to be used by subclasses for setting the process method.
double TTFloat64
64 bit floating point number
Definition: TTBase.h:188
std::int16_t TTInt16
16 bit signed integer
Definition: TTBase.h:175
void setOneSinkPosition(TTInt32 sinkNumber, TTFloat64 x, TTFloat64 y, TTFloat64 z)
Set the position of one sink.
Definition: TTSpatBase.cpp:185
TTErr getSinkPosition(const TTValue &requestedChannel, TTValue &aPosition)
Get the position of one sink.
Definition: TTSpatBase.cpp:162
#define addMessageWithArguments(name)
A convenience macro to be used by subclasses for registering messages.
Definition: TTMessage.h:27
TTErr setSourcePosition(const TTValue &aPosition, TTValue &unused)
Get the position of one source.
Definition: TTSpatBase.cpp:133
std::int32_t TTInt32
32 bit signed integer
Definition: TTBase.h:177
TTErr setSourceCount(const TTValue &value)
Set the number of sources.
Definition: TTSpatBase.cpp:60
A simple container for an array of TTAudioSignal pointers.
TTErr getSourceCount(TTValue &value)
Get the number of sources.
Definition: TTSpatBase.cpp:54
32-bit signed integer, range is -2,147,483,648 through 2,147,483,647.
Definition: TTBase.h:277
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
void getOneSinkPosition(TTInt32 sinkNumber, TTFloat64 &x, TTFloat64 &y, TTFloat64 &z)
Get the position of one sink.
Definition: TTSpatBase.cpp:151
std::uint32_t TTUInt32
32 bit unsigned integer
Definition: TTBase.h:178
void setOneSourcePosition(TTInt32 sourceNumber, TTFloat64 x, TTFloat64 y, TTFloat64 z)
Set the position of one source.
Definition: TTSpatBase.cpp:123
No Error.
Definition: TTBase.h:343
TTErr getSourcePosition(const TTValue &requestedChannel, TTValue &aPosition)
Get the position of one source.
Definition: TTSpatBase.cpp:100
void resize(size_type n)
Change the number of elements.
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
#define addAttributeWithGetterAndSetter(name, type)
A convenience macro to be used by subclasses for registering attributes with a custom getter and sett...
Definition: TTAttribute.h:57