Jamoma API  0.6.0.a19
TTPanorama.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspEffectsLib
4  *
5  * @brief #TTPanorama performes stereo panning.
6  *
7  * @authors Tim Place, Nils Peters, Trond Lossius
8  *
9  * @copyright Copyright © 2008-2011, Tim Place, Nils Peters @n
10  * This code is licensed under the terms of the "New BSD License" @n
11  * http://creativecommons.org/licenses/BSD/
12  */
13 
14 
15 #include "TTPanorama.h"
16 
17 #define thisTTClass TTPanorama
18 #define thisTTClassName "panorama"
19 #define thisTTClassTags "dspEffectsLib, audio, processor, mixing, panning"
20 
21 
22 TT_AUDIO_CONSTRUCTOR,
23 mPosition(0.0),
24 mScaledPosition(0.5),
25 mShape(TT("equalPower")),
26 mMode(TT("lookup"))
27 {
29  addAttributeProperty( Position, range, TTValue(-1.0, 1.0));
30  addAttributeProperty( Position, rangeChecking, TT("clip"));
31 
34 
35  /*if (!zeroed) {
36  memset(zeroVector1, 0, sizeof(TTSampleValue) * 2048);
37  memset(zeroVector2, 0, sizeof(TTSampleValue) * 2048);
38  memset(zeroVector3, 0, sizeof(TTSampleValue) * 2048);
39  }*/
40 
41  // Set Defaults (the attribute setters will set the process method for us)...
42  setAttributeValue(TT("position"), 0.0);
43  setProcessMethod(processEqualPowerLookup);
44  setAttributeValue(TT("mode"), TT("lookup"));
45  setAttributeValue(TT("shape"), TT("equalPower"));
46 }
47 
48 
49 TTPanorama::~TTPanorama()
50 {;}
51 
52 
53 TTErr TTPanorama::setShape(const TTValue& newValue)
54 {
55  mShape = newValue;
56  return setProcessPointers();
57 }
58 
59 
60 TTErr TTPanorama::setMode(const TTValue& newValue)
61 {
62  mMode = newValue;
63  return setProcessPointers();
64 }
65 
66 TTErr TTPanorama::setPosition(const TTValue& newValue)
67 {
68  mPosition = newValue;
69  mScaledPosition = 0.5*(mPosition+1);
70  return kTTErrNone;
71 }
72 
73 
74 TTErr TTPanorama::setProcessPointers()
75 {
76  TTErr err = kTTErrNone;
77 
78  if (mShape == TT("equalPower") && mMode == TT("lookup")) {
79  err = setProcessMethod(processEqualPowerLookup);
80  }
81  else if (mShape == TT("equalPower") && mMode == TT("calculate")) {
82  err = setProcessMethod(processEqualPowerCalc);
83  }
84  else if (mShape == TT("squareRoot") && mMode == TT("calculate")) {
85  err = setProcessMethod(processSquareRootCalc);
86  }
87  else if (mShape == TT("squareRoot") && mMode == TT("lookup")) {
88  err = setProcessMethod(processSquareRootLookup);
89  }
90  else {
91  err = setProcessMethod(processLinear);
92  }
93  return err;
94 }
95 
96 
97 #if 0
98 #pragma mark -
99 #pragma mark Interleaved Process Methods
100 #endif
101 
102 TTErr TTPanorama::processLinear(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
103 {
104  TTAudioSignal& in = inputs->getSignal(0);
105  TTAudioSignal& out = outputs->getSignal(0);
106  TTUInt16 vs = in.getVectorSizeAsInt();
107  TTChannelCount numOutChannels = out.getNumChannelsAsInt();
108  TTChannelCount numInChannels = in.getNumChannelsAsInt();
109 
110  if (numOutChannels < 2)
111  out.setMaxNumChannels(2);
112 
113  TTSampleValuePtr inSampleA = in.mSampleVectors[0];
114  TTSampleValuePtr outSampleA = out.mSampleVectors[0];
115  TTSampleValuePtr outSampleB = out.mSampleVectors[1];
116 
117 
118  if (numInChannels > 1) { //panning a stereo source
119  TTSampleValuePtr inSampleB = in.mSampleVectors[1];
120  while (vs--){
121  *outSampleA++ = (*inSampleA++ * (1.0 - mScaledPosition));
122  *outSampleB++ = (*inSampleB++ * mScaledPosition);
123  }
124  }
125  else{ // single channel input
126  while (vs--){
127  *outSampleA++ = (*inSampleA * (1.0 - mScaledPosition));
128  *outSampleB++ = (*inSampleA++ * mScaledPosition);
129  }
130  }
131  return kTTErrNone;
132 }
133 
134 
135 TTErr TTPanorama::processEqualPowerLookup(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
136 {
137  TTAudioSignal& in = inputs->getSignal(0);
138  TTAudioSignal& out = outputs->getSignal(0);
139  TTUInt16 vs = in.getVectorSizeAsInt();
140  int index= (int)(mScaledPosition * 510.0);
141  TTChannelCount numOutChannels = out.getNumChannelsAsInt();
142  TTChannelCount numInChannels = in.getNumChannelsAsInt();
143 
144  if (numOutChannels < 2)
145  out.setMaxNumChannels(2);
146 
147  TTSampleValuePtr inSampleA = in.mSampleVectors[0];
148  TTSampleValuePtr outSampleA = out.mSampleVectors[0];
149  TTSampleValuePtr outSampleB = out.mSampleVectors[1];
150 
151 
152  if (numInChannels > 1) { //panning a stereo source
153  TTSampleValuePtr inSampleB = in.mSampleVectors[1];
154  while (vs--){
155  *outSampleA++ = (*inSampleA++ * kTTLookupEqualPowerSymetric[index]);
156  *outSampleB++ = (*inSampleB++ * kTTLookupEqualPowerSymetric[510 - index]);
157  }
158  }
159  else{ // single channel input
160  while (vs--){
161  *outSampleA++ = (*inSampleA * kTTLookupEqualPowerSymetric[index]);
162  *outSampleB++ = (*inSampleA++ * kTTLookupEqualPowerSymetric[510 - index]);
163  }
164  }
165  return kTTErrNone;
166 }
167 
168 
169 TTErr TTPanorama::processSquareRootLookup(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
170 {
171  TTAudioSignal& in = inputs->getSignal(0);
172  TTAudioSignal& out = outputs->getSignal(0);
173  TTUInt16 vs = in.getVectorSizeAsInt();
174  int index= (int)(mScaledPosition * 510.0);
175  TTChannelCount numOutChannels = out.getNumChannelsAsInt();
176  TTChannelCount numInChannels = in.getNumChannelsAsInt();
177 
178  if (numOutChannels < 2)
179  out.setMaxNumChannels(2);
180 
181  TTSampleValuePtr inSampleA = in.mSampleVectors[0];
182  TTSampleValuePtr outSampleA = out.mSampleVectors[0];
183  TTSampleValuePtr outSampleB = out.mSampleVectors[1];
184 
185 
186  if (numInChannels > 1) { //panning a stereo source
187  TTSampleValuePtr inSampleB = in.mSampleVectors[1];
188  while (vs--){
189  *outSampleA++ = (*inSampleA++ * kTTLookupSquareRootSymetric[index]);
190  *outSampleB++ = (*inSampleB++ * kTTLookupSquareRootSymetric[510 - index]);
191  }
192  }
193  else{ // single channel input
194  while (vs--){
195  *outSampleA++ = (*inSampleA * kTTLookupSquareRootSymetric[index]);
196  *outSampleB++ = (*inSampleA++ * kTTLookupSquareRootSymetric[510 - index]);
197  }
198  }
199 
200  return kTTErrNone;
201 }
202 
203 
204 TTErr TTPanorama::processEqualPowerCalc(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
205 {
206  TTAudioSignal& in = inputs->getSignal(0);
207  TTAudioSignal& out = outputs->getSignal(0);
208  TTUInt16 vs = in.getVectorSizeAsInt();
209  TTFloat64 radPosition = mScaledPosition * kTTHalfPi;
210  TTChannelCount numOutChannels = out.getNumChannelsAsInt();
211  TTChannelCount numInChannels = in.getNumChannelsAsInt();
212 
213  if (numOutChannels < 2)
214  out.setMaxNumChannels(2);
215 
216  TTSampleValuePtr inSampleA = in.mSampleVectors[0];
217  TTSampleValuePtr outSampleA = out.mSampleVectors[0];
218  TTSampleValuePtr outSampleB = out.mSampleVectors[1];
219 
220 
221  if (numInChannels > 1) { //panning a stereo source
222  TTSampleValuePtr inSampleB = in.mSampleVectors[1];
223  while (vs--){
224  *outSampleA++ = (*inSampleA++ * cos(radPosition));
225  *outSampleB++ = (*inSampleB++ * sin(radPosition));
226  }
227  }
228  else{ // single channel input
229  while (vs--){
230  *outSampleA++ = (*inSampleA * cos(radPosition));
231  *outSampleB++ = (*inSampleA++ * sin(radPosition));
232  }
233  }
234  return kTTErrNone;
235 }
236 
237 TTErr TTPanorama::processSquareRootCalc(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
238 {
239  TTAudioSignal& in = inputs->getSignal(0);
240  TTAudioSignal& out = outputs->getSignal(0);
241  TTUInt16 vs = in.getVectorSizeAsInt();
242  TTChannelCount numOutChannels = out.getNumChannelsAsInt();
243  TTChannelCount numInChannels = in.getNumChannelsAsInt();
244 
245  if (numOutChannels < 2)
246  out.setMaxNumChannels(2);
247 
248  TTSampleValuePtr inSampleA = in.mSampleVectors[0];
249  TTSampleValuePtr outSampleA = out.mSampleVectors[0];
250  TTSampleValuePtr outSampleB = out.mSampleVectors[1];
251 
252 
253  if (numInChannels > 1) { //panning a stereo source
254  TTSampleValuePtr inSampleB = in.mSampleVectors[1];
255  while (vs--){
256  *outSampleA++ = (*inSampleA++ * sqrt(1 - mScaledPosition));
257  *outSampleB++ = (*inSampleB++ * sqrt(mScaledPosition));
258  }
259  }
260  else{ // single channel input
261  while (vs--){
262  *outSampleA++ = (*inSampleA * sqrt(1 - mScaledPosition));
263  *outSampleB++ = (*inSampleA++ * sqrt(mScaledPosition));
264  }
265  }
266  return kTTErrNone;
267 }
std::uint16_t TTUInt16
16 bit unsigned integer
Definition: TTBase.h:176
#TTPanorama performes stereo panning.
TTFOUNDATION_EXPORT const TTFloat32 kTTLookupSquareRootSymetric[]
Square Root lookup table with 0.701 at element 256.
Definition: TTBase.cpp:282
#define setProcessMethod(methodName)
A convenience macro to be used by subclasses for setting the process method.
Symbol type.
Definition: TTBase.h:282
double TTFloat64
64 bit floating point number
Definition: TTBase.h:188
#define TT
This macro is defined as a shortcut for doing a lookup in the symbol table.
Definition: TTSymbol.h:155
TTErr setMaxNumChannels(const TTValue &newMaxNumChannels)
Attribute accessor.
64-bit floating point
Definition: TTBase.h:272
#define addAttributeProperty(attributeName, propertyName, initialValue)
A convenience macro to be used for registering properties of attributes.
Definition: TTAttribute.h:68
The TTAudioSignal class represents N vectors of audio samples for M channels.
Definition: TTAudioSignal.h:57
TTSampleValue ** mSampleVectors
An array of pointers to the first sample in each vector. Declared Public for fast access...
Definition: TTAudioSignal.h:74
TTUInt16 TTChannelCount
Data type used when counting the number of channels in multi-channel audio signals and processes...
Definition: TTAudioSignal.h:31
A simple container for an array of TTAudioSignal pointers.
TTFOUNDATION_EXPORT const TTFloat32 kTTLookupEqualPowerSymetric[]
Equal Power lookup table with 0.701 at element 256.
Definition: TTBase.cpp:115
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
TTFOUNDATION_EXPORT const TTFloat64 kTTHalfPi
Pre-calculated value of pi/2.
Definition: TTBase.cpp:28
#define addAttributeWithSetter(name, type)
A convenience macro to be used by subclasses for registering attributes with a custom setter...
Definition: TTAttribute.h:47
No Error.
Definition: TTBase.h:343
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34