Jamoma API  0.6.0.a19
TTPowerFunction.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspFunctionLib
4  *
5  * @brief #TTPowerFunction Unit for Jamoms DSP
6  *
7  * @details
8  *
9  * @authors Trond Lossius
10  *
14  */
15
16
17 #include "TTPowerFunction.h"
18
19 #define thisTTClass TTPowerFunction
20 #define thisTTClassName "power"
21 #define thisTTClassTags "dspFunctionLib, audio, processor, function"
22
23
24 TT_AUDIO_CONSTRUCTOR
25 {
28
29  setAttributeValue(TT("powerValue"), 1.0);
30  setAttributeValue(TT("symmetry"), TT("none"));
31
32  setProcessMethod(processAudio);
33 }
34
35
36 TTPowerFunction::~TTPowerFunction()
37 {
38  ;
39 }
40
41
43 {
44  mSymmetry = newValue;
45
46  if (mSymmetry == TT("point"))
48  else if (mSymmetry == TT("axis"))
49  setCalculateMethod(calculateAxis);
50  else // none
51  setCalculateMethod(calculateNoSymmetry);
52  return kTTErrNone;
53 }
54
55
57 {
58  mPowerValue = newValue;
59  mK = pow(2, mPowerValue);
60  return kTTErrNone;
61 }
62
63
64 // With point symmetry we first map x from [0,1] to [-1,1]. Then we calculate y=f(fabs(x)), and finally invert the sign of y if x<0.
66 {
67  TTFloat64 sign;
68
69  y = 2*x-1;
70  if (y<0)
71  sign = -1;
72  else
73  sign = 1;
74  y = 0.5 * (sign * pow(fabs(y), mK) + 1);
75
76  return kTTErrNone;
77 }
78
79
80 // With axis symmetry we first map x from [0,1] to [-1,1] range, and then calculate y=f(fabs(x))
81 TTErr TTPowerFunction::calculateAxis(const TTFloat64& x, TTFloat64& y, TTPtrSizedInt data)
82 {
83  y = pow(fabs(2*x-1), mK);
84  return kTTErrNone;
85 }
86
87
88 TTErr TTPowerFunction::calculateNoSymmetry(const TTFloat64& x, TTFloat64& y, TTPtrSizedInt data)
89 {
90  y = pow(x, mK);
91  return kTTErrNone;
92 }
93
94
96 {
97  TTAudioSignal& in = inputs->getSignal(0);
98  TTAudioSignal& out = outputs->getSignal(0);
99  TTUInt16 vs;
100  TTSampleValue* inSample;
101  TTSampleValue* outSample;
102  TTChannelCount numchannels = TTAudioSignal::getMinChannelCount(in, out);
103  TTPtrSizedInt channel;
104
105  for (channel=0; channel<numchannels; channel++) {
106  inSample = in.mSampleVectors[channel];
107  outSample = out.mSampleVectors[channel];
108  vs = in.getVectorSizeAsInt();
109
110  while (vs--) {
111  (this->*calculateMethod)(*inSample, *outSample, TTPtr(channel));
112  outSample++;
113  inSample++;
114  }
115  }
116  return kTTErrNone;
117 }
118
119
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.
Symbol type.
Definition: TTBase.h:282
double TTFloat64
64 bit floating point number
Definition: TTBase.h:188
TTPowerFunction Unit for Jamoms DSP
#define TT
This macro is defined as a shortcut for doing a lookup in the symbol table.
Definition: TTSymbol.h:155
void * TTPtr
A generic pointer.
Definition: TTBase.h:248
#define setCalculateMethod(methodName)
A convenience macro to be used by subclasses for setting the calculate method.
64-bit floating point
Definition: TTBase.h:272
TTErr setPowerValue(const TTValue &newValue)
Attribute setter.
TTCalculateMethod calculateMethod
This function pointer points to the active (non-bypass) calculate routine.
TTSymbol mSymmetry
Mode: none, point or axis.
double mPowerValue
Parameter for function: y pow(x,pow(2,powerValue))
static TTChannelCount getMinChannelCount(const TTAudioSignal &signal1, const TTAudioSignal &signal2)
Use this class method to determine the least number of channels the two signals have in common...
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.
double mK
k = pow(2,powerValue)
long TTPtrSizedInt
An integer that is the same size as a pointer.
Definition: TTBase.h:240
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
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
TTErr setSymmetry(const TTValue &newValue)
Attribute setter.
TTFloat64 TTSampleValue
A value representing a single audio sample.
Definition: TTBase.h:230
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
TTErr calculatePoint(const TTFloat64 &x, TTFloat64 &y, TTPtrSizedInt data)
y = f(x) for a single value
TTErr processAudio(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
A standard audio processing method as used by TTBlue objects.