Jamoma API  0.6.0.a19
TTTanhFunction.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspFunctionLib
4  *
5  * @brief #TTTanhFunction Unit for Jamoms DSP
6  *
7  * @details
8  *
9  * @authors Trond Lossius
10  *
11  * @copyright Copyright © 2007 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 "TTTanhFunction.h"
18 #include <math.h>
19 
20 #define thisTTClass TTTanhFunction
21 #define thisTTClassName "tanh"
22 #define thisTTClassTags "dspFunctionLib, audio, processor, function"
23 
24 
25 TT_AUDIO_CONSTRUCTOR
26 {
27  // Register Attributes...
30 
31  // Set Defaults...
32  setAttributeValue(TT("offset"), 0.0);
33  setAttributeValue(TT("width"), 0.5);
34 
35  setProcessMethod(processAudio);
36  setCalculateMethod(calculateValue);
37 }
38 
39 
40 TTTanhFunction::~TTTanhFunction()
41 {
42  ;
43 }
44 
45 
47 {
48  mOffset = newValue;
49  b = 0.5 * (mOffset+1);
51  return kTTErrNone;
52 }
53 
54 
56 {
57  mWidth = newValue;
58  if (mWidth <= 0)
59  a = log(7.0);
60  else
61  a = log(7.0)/mWidth;
63  return kTTErrNone;
64 }
65 
66 
68 {
69  double f0, f1;
70 
71  f0 = tanh(a*(-b));
72  f1 = tanh(a*(1-b));
73  // This will never be division by zero, due to the fact that we always have width > 0
74  alpha = 1/(f1-f0);
75  beta = f0;
76 }
77 
78 
80 {
81  y = alpha * (tanh(a * (x-b)) - beta);
82  return kTTErrNone;
83 }
84 
85 
87 {
88  TT_WRAP_CALCULATE_METHOD(calculateValue);
89 }
90 
TTFloat64 mWidth
Parameter for function: y pow(x,pow(2,powerValue))
double b
Internal coefficient.
#define setProcessMethod(methodName)
A convenience macro to be used by subclasses for setting the process method.
void calculateOutputScaling(void)
Calculate coefficients.
double TTFloat64
64 bit floating point number
Definition: TTBase.h:188
double a
Internal coefficient.
#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.
TTTanhFunction Unit for Jamoms DSP
TTErr calculateValue(const TTFloat64 &x, TTFloat64 &y, TTPtrSizedInt data)
y = f(x) for a single value
64-bit floating point
Definition: TTBase.h:272
TTErr setOffset(const TTValue &value)
Calculate coefficients when this attr is set.
A simple container for an array of TTAudioSignal pointers.
TTErr setWidth(const TTValue &value)
Calculate coefficients when this attr is set.
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
TTErr processAudio(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
A standard audio processing method as used by TTBlue objects.
TTFloat64 mOffset
k = pow(2,powerValue)
#define addAttributeWithSetter(name, type)
A convenience macro to be used by subclasses for registering attributes with a custom setter...
Definition: TTAttribute.h:47
double beta
Internal coefficient.
No Error.
Definition: TTBase.h:343
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
double alpha
Internal coefficient.