Jamoma API  0.6.0.a19
TTLogFunction.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspFunctionLib
4  *
5  * @brief #TTLogFunction 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 "TTLogFunction.h"
18 #include <math.h>
19 
20 #define thisTTClass TTLogFunction
21 #define thisTTClassName "logarithm"
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 
33  // Set Defaults (should be sufficient resolution for a while):
34 #ifdef TT_PLATFORM_MAC
35  setAttributeValue(TT("base"), 2.718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427427466391932003059921817413596629043572900334295260595630738132328627943490763);
36 #else
37  setAttributeValue(TT("base"), 2.718281828459045235360287471352662497757247093699959574);
38 #endif
39 
40  setProcessMethod(processAudio);
41  setCalculateMethod(calculateValue);
42 }
43 
44 
45 TTLogFunction::~TTLogFunction()
46 {
47  ;
48 }
49 
50 
52 {
53  mBase = newValue;
54  k = 1. / log(mBase);
55  l = mBase - 1.;
56  if (mBase == 1) {
57  setProcessMethod(processAudioBypass);
58  setCalculateMethod(calculateValueBypass);
59  }
60  else{
63  }
64  return kTTErrNone;
65 }
66 
67 
69 {
70  /*double temp = x*l+1.0;
71  if (temp > 0.0) {
72  y = k * log(temp); //avoiding nan and -inf
73  return kTTErrNone;
74  }
75  else
76  return kTTErrInvalidValue;*/
77 
78  y = k * log(x*l+1.0); //TODO: we need to make sure that log10() is not -inf or nan
79  return kTTErrNone;
80 }
81 
82 TTErr TTLogFunction::calculateValueBypass(const TTFloat64& x, TTFloat64& y, TTPtrSizedInt data)
83 {
84  // Avoid multiplication by zero
85  y = x;
86  return kTTErrNone;
87 }
88 
90 {
91  TT_WRAP_CALCULATE_METHOD(calculateValue);
92 }
93 
94 
95 TTErr TTLogFunction::processAudioBypass(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
96 {
97  TT_WRAP_CALCULATE_METHOD(calculateValueBypass);
98 }
#define setProcessMethod(methodName)
A convenience macro to be used by subclasses for setting the process method.
TTFloat64 mBase
Base for the exponential function.
Definition: TTLogFunction.h:31
TTErr processAudio(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
A standard audio processing method as used by TTBlue objects.
TTErr setBase(const TTValue &value)
Calculate coefficients when this attr is set.
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
TTErr calculateValue(const TTFloat64 &x, TTFloat64 &y, TTPtrSizedInt data)
y = f(x) for a single value
#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
double l
Internal coefficient.
Definition: TTLogFunction.h:33
double k
Internal coefficient.
Definition: TTLogFunction.h:32
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
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
TTLogFunction Unit for Jamoms DSP
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34