Jamoma API  0.6.0.a19
Torus3D.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspTrajectoryLib
4  *
5  * @brief Torus Knot Unit in 3D for Jamoma DSP
6  *
7  * @details see http://en.wikipedia.org/wiki/Torus_knot for details @n
8  *
9  * @authors Nils Peters
10  *
11  * @copyright Copyright © 2011 by Nils Peters @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 "Torus3D.h"
17 
18 #define thisTTClass Torus3D
19 #define thisTTClassName "torus.knot.3D"
20 #define thisTTClassTags "audio, trajectory, knot, 3D"
21 
22 
23 TT_AUDIO_CONSTRUCTOR
26 
27  setAttributeValue(TT("a"), 3.0);
28  setAttributeValue(TT("b"), 7.0);
29 
30 
31 
32  setProcessMethod(processAudio);
33 // setCalculateMethod(calculateValue);
34 }
35 
36 
37 Torus3D::~Torus3D()
38 {
39  ;
40 }
41 
42 //TTErr Torus3D::calculateValue(const TTFloat64& x, TTFloat64& y, TTPtrSizedInt data)
43 //{
44 // y = x;
45 // return kTTErrNone;
46 //}
47 
48 
49 TTErr Torus3D::processAudio(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
50 {
51 
52  TTAudioSignal& out = outputs->getSignal(0);
53  TTChannelCount numOutputChannels = out.getNumChannelsAsInt();
54 
55  if (numOutputChannels != 3) {
56  TTValue v = 3;
57  out.setMaxNumChannels(v);
58  out.setNumChannels(v);
59  }
60 
61  TTAudioSignal& in0 = inputs->getSignal(0);
62 
63  TTUInt16 vs = in0.getVectorSizeAsInt();
64 
65  TTSampleValuePtr inSampleX = in0.mSampleVectors[0];
66  TTSampleValuePtr outSampleX = out.mSampleVectors[0];
67  TTSampleValuePtr outSampleY = out.mSampleVectors[1];
68  TTSampleValuePtr outSampleZ = out.mSampleVectors[2];
69  TTFloat64 phi, r;
70 
71  for (int i=0; i<vs; i++) {
72  phi = inSampleX[i] * kTTPi; // 0 .. 2Pi
73  r = cos(mB * phi) + 2.0;
74  outSampleX[i] = r * cos(mA * phi);
75  outSampleY[i] = r * sin(mA * phi);
76  outSampleZ[i] = sin(mB * phi);
77  }
78 return kTTErrNone;
79 }
80 
81 
82 
std::uint16_t TTUInt16
16 bit unsigned integer
Definition: TTBase.h:176
#define addAttribute(name, type)
A convenience macro to be used by subclasses for registering attributes with a custom getter...
Definition: TTAttribute.h:29
#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
#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
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
Torus Knot Unit in 3D for Jamoma DSP.
A simple container for an array of TTAudioSignal pointers.
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
No Error.
Definition: TTBase.h:343
TTFOUNDATION_EXPORT const TTFloat64 kTTPi
[doxygenAppendixC_constExample]
Definition: TTBase.cpp:23
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34