Jamoma API  0.6.0.a19
Butterfly2D.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspTrajectoryLib
4  *
5  * @brief Butterfly2D Unit for Jamoma DSP
6  *
7  * @details Implementation of the buterfly trajectory function http://mathworld.wolfram.com/ButterflyCurve.html @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 "Butterfly2D.h"
17 
18 
19 #define thisTTClass Butterfly2D
20 #define thisTTClassName "butterfly.2D"
21 #define thisTTClassTags "audio, trajectory, 2D"
22 
23 
24 TT_AUDIO_CONSTRUCTOR
25 {
26  setProcessMethod(processAudio);
27 // setCalculateMethod(calculateValue);
28 }
29 
30 
31 Butterfly2D::~Butterfly2D()
32 {
33  ;
34 }
35 
36 //TTErr Butterfly2D::calculateValue(const TTFloat64& x, TTFloat64& y, TTPtrSizedInt data)
37 //{
38 // y = x;
39 // return kTTErrNone;
40 //}
41 
42 
43 TTErr Butterfly2D::processAudio(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
44 {
45  TTAudioSignal& out = outputs->getSignal(0);
46  TTChannelCount numOutputChannels = out.getNumChannelsAsInt();
47 
48  if (numOutputChannels != 2) {
49  TTValue v = 2;
50  out.setMaxNumChannels(v);
51  out.setNumChannels(v);
52  }
53 
54  TTAudioSignal& in0 = inputs->getSignal(0);
55  TTUInt16 vs = in0.getVectorSizeAsInt();
56 
57  TTSampleValuePtr inSampleX = in0.mSampleVectors[0];
58  TTSampleValuePtr outSampleX = out.mSampleVectors[0];
59  TTSampleValuePtr outSampleY = out.mSampleVectors[1];
60  TTFloat64 phi, r, temp;
61 
62  for (int i=0; i<vs; i++) {
63 
64  phi = inSampleX[i] * kTTPi; // 0 .. 2Pi
65  temp = sin(1/24*(2*phi-kTTPi));
66  r = exp(sin(phi)) - 2*cos(4*phi)+pow(temp,5);
67 
68  outSampleX[i] = sin(phi) * r;
69  outSampleY[i] = cos(phi) * r;
70 
71  }
72 return kTTErrNone;
73 }
std::uint16_t TTUInt16
16 bit unsigned integer
Definition: TTBase.h:176
#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
Butterfly2D Unit for Jamoma DSP.
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
TTFOUNDATION_EXPORT const TTFloat64 kTTPi
[doxygenAppendixC_constExample]
Definition: TTBase.cpp:23
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34