Jamoma API  0.6.0.a19
Viviani3D.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspTrajectoryLib
4  *
5  * @brief Viviani curve Unit in 3D for Jamoma DSP
6  *
7  * @details see http://mathworld.wolfram.com/VivianisCurve.html 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 
17 #include "Viviani3D.h"
18 
19 
20 #define thisTTClass Viviani3D
21 #define thisTTClassName "viviani.3D"
22 #define thisTTClassTags "audio, trajectory, 3D"
23 
24 
25 TT_AUDIO_CONSTRUCTOR
26 {
27  setProcessMethod(processAudio);
28 // setCalculateMethod(calculateValue);
29 }
30 
31 
32 Viviani3D::~Viviani3D()
33 {
34  ;
35 }
36 
37 //TTErr Viviani3D::calculateValue(const TTFloat64& x, TTFloat64& y, TTPtrSizedInt data)
38 //{
39 // y = x;
40 // return kTTErrNone;
41 //}
42 
43 
44 TTErr Viviani3D::processAudio(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
45 {
46  TTAudioSignal& out = outputs->getSignal(0);
47  TTChannelCount numOutputChannels = out.getNumChannelsAsInt();
48 
49  if (numOutputChannels != 3) {
50  TTValue v = 3;
51  out.setMaxNumChannels(v);
52  out.setNumChannels(v);
53  }
54 
55  TTAudioSignal& in0 = inputs->getSignal(0);
56  TTUInt16 vs = in0.getVectorSizeAsInt();
57 
58  TTSampleValuePtr inSampleX = in0.mSampleVectors[0];
59  TTSampleValuePtr outSampleX = out.mSampleVectors[0];
60  TTSampleValuePtr outSampleY = out.mSampleVectors[1];
61  TTSampleValuePtr outSampleZ = out.mSampleVectors[2];
62 
63  TTFloat64 phi;
64 
65  for (int i=0; i<vs; i++) {
66 
67  phi = inSampleX[i] * kTTTwoPi; // 0 .. 4Pi
68  outSampleX[i] = 0.5 + 0.5 * cos(phi);
69  outSampleY[i] = 0.5 * sin(phi);
70  outSampleZ[i] = sin(0.5 * phi);
71 
72  }
73 return kTTErrNone;
74 }
std::uint16_t TTUInt16
16 bit unsigned integer
Definition: TTBase.h:176
TTFOUNDATION_EXPORT const TTFloat64 kTTTwoPi
Pre-calculated value of pi * 2.
Definition: TTBase.cpp:24
#define setProcessMethod(methodName)
A convenience macro to be used by subclasses for setting the process method.
Viviani curve Unit in 3D for Jamoma DSP.
double TTFloat64
64 bit floating point number
Definition: TTBase.h:188
TTErr setMaxNumChannels(const TTValue &newMaxNumChannels)
Attribute accessor.
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.
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
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34