00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef _TemplateLibrary_FUNCTIONS_H_
00017 #define _TemplateLibrary_FUNCTIONS_H_ 1
00018
00019 #include <lib/sconfig.h>
00020 #include <num_math.h>
00021 namespace NUM {
00022
00023
00028 template <class T, class U>
00029 T cosinterp(U x, T v0, T v1) {
00030 U f;
00031 f=U(0.5)*(U(1.0)-cos(U(M_PI)*x));
00032 return v0*(T(1.0)-f)+v1*f;
00033 }
00034
00039 template <class T, class U>
00040 T cubinterp(U x, T v0, T v1, T v2, T v3) {
00041 T p,q,r,res;
00042 r=v0-v1;
00043 p=(v3-v2)-r;
00044 q=r-p;
00045 res=v1;
00046 res+=(v2-v0)*x;
00047 x*=x;
00048 res+=q*x;
00049 x*=x;
00050 res+=p*x;
00051 return res;
00052 }
00053
00055 template <class T>
00056 T step (const T a, const T b) {
00057 return (a>=b)?1.0:0.0;
00058 }
00059
00061 template <class T>
00062 T pulse (const T x, const T a, const T b) {
00063 return (step(x,a)-step(x,b));
00064 }
00065
00069 template <class T>
00070 T bias(T b, T x) {
00071 return pow(x,-log2(b));
00072 }
00073
00077 template <class T>
00078 T sbias(T b, T x) {
00079 return x*T(1.0)/( (T(1.0)-x)*(T(1.0)/(b-T(2.0)))+T(1.0) );
00080 }
00081
00085 template <class T>
00086 T gain(T g, T x) {
00087 return (x<T(0.5))
00088 ?T(0.5)*bias<T>(T(1.0)-g,T(2.0)*x)
00089 :T(1.0)-bias<T>(T(1.0)-g,T(2.0)-T(2.0)*x)*T(0.5);
00090 }
00091
00095 template <class T>
00096 T sgain(T g, T x) {
00097 T t = (T(1.0)-T(2.0)*x)*((T(1.0)/g)-T(2.0));
00098 return (x<T(0.5))
00099 ? x *T(1.0)/( t+T(1.0))
00100 :(t-x)*T(1.0)/( t-T(1.0));
00101 }
00102
00103
00105
00106
00107
00108
00109
00110
00111 };
00112 #endif