Jamoma API  0.6.0.a19
TTExpFunction.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspFunctionLib
4  *
5  * @brief #TTExpFunction Unit for Jamoms DSP
6  *
7  * @details Can be used for exponential curves.
8  *
9  * @authors Trond Lossius
10  *
11  * @copyright Copyright © 2009 by Trond Lossius @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 "TTExpFunction.h"
18 #include <math.h>
19 
20 #define thisTTClass TTExpFunction
21 #define thisTTClassName "exponential"
22 #define thisTTClassTags "dspFunctionLib, audio, processor, function"
23 
24 
25 TT_AUDIO_CONSTRUCTOR
26 {
27  // Register Attributes...
29  addAttributeProperty(Base, range, TTValue(kTTEpsilon, 100000.0));
30  addAttributeProperty(Base, rangeChecking, TT("cliplow")); // options are "clip" "cliphigh" "cliplow"
31 
32  // Set Defaults (should be sufficient resolution for a while):
33 #ifdef TT_PLATFORM_MAC
34  setAttributeValue(TT("base"), 2.718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427427466391932003059921817413596629043572900334295260595630738132328627943490763);
35 #else
36  setAttributeValue(TT("base"), 2.718281828459045235360287471352662497757247093699959574);
37 #endif
38 
39  setProcessMethod(processAudio);
40  setCalculateMethod(calculateValue);
41 }
42 
43 
44 TTExpFunction::~TTExpFunction()
45 {
46  ;
47 }
48 
49 
51 {
52  mBase = newValue;
53  k = log(mBase);
54  if (mBase != 1.0){
57  }
58  else {
59  setProcessMethod(processAudioBypass); // Avoid division by zero
60  setCalculateMethod(calculateValueBypass);
61  }
62 
63  return kTTErrNone;
64 }
65 
66 
68 {
69  y = (exp(k*x) - 1.) / (mBase - 1.);
70  return kTTErrNone;
71 }
72 
73 
75 {
76  TT_WRAP_CALCULATE_METHOD(calculateValue);
77 }
78 
79 
80 TTErr TTExpFunction::calculateValueBypass(const TTFloat64& x, TTFloat64& y, TTPtrSizedInt data)
81 {
82  y = x;
83  return kTTErrNone;
84 }
85 
86 
87 TTErr TTExpFunction::processAudioBypass(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
88 {
89  TT_WRAP_CALCULATE_METHOD(calculateValue);
90 }
TTExpFunction Unit for Jamoms DSP
TTErr processAudio(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
A standard audio processing method as used by TTBlue objects.
TTErr calculateValue(const TTFloat64 &x, TTFloat64 &y, TTPtrSizedInt data)
y = f(x) for a single value
#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
#define setCalculateMethod(methodName)
A convenience macro to be used by subclasses for setting the calculate method.
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
TTErr setBase(const TTValue &value)
Calculate coefficients when this attr is set.
A simple container for an array of TTAudioSignal pointers.
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
#define addAttributeWithSetter(name, type)
A convenience macro to be used by subclasses for registering attributes with a custom setter...
Definition: TTAttribute.h:47
TTFloat64 mBase
Base for the exponential function.
Definition: TTExpFunction.h:32
No Error.
Definition: TTBase.h:343
TTFOUNDATION_EXPORT const TTFloat64 kTTEpsilon
A very very small value, used for float equality comaprisments.
Definition: TTBase.cpp:31
double k
Internal coefficient.
Definition: TTExpFunction.h:33
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34