diff stitch/funcs.c @ 0:5242703e91d3 tip

Initial checkin for AIM92 aimR8.2 (last updated May 1997).
author tomwalters
date Fri, 20 May 2011 15:19:45 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/stitch/funcs.c	Fri May 20 15:19:45 2011 +0100
@@ -0,0 +1,176 @@
+/*
+    Copyright (c) Applied Psychology Unit, Medical Research Council. 1988, 1989
+    ===========================================================================
+
+    Permission to use, copy, modify, and distribute this software without fee 
+    is hereby granted for research purposes, provided that this copyright 
+    notice appears in all copies and in all supporting documentation, and that 
+    the software is not redistributed for any fee (except for a nominal shipping 
+    charge). Anyone wanting to incorporate all or part of this software in a
+    commercial product must obtain a license from the Medical Research Council.
+
+    The MRC makes no representations about the suitability of this 
+    software for any purpose.  It is provided "as is" without express or implied 
+    warranty.
+ 
+    THE MRC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 
+    ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL THE
+    A.P.U. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY 
+    DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 
+    AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 
+    OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+*/
+
+/*
+    funcs.c
+    =======
+
+
+
+
+*/
+
+#include <math.h>
+
+#include "stitch.h"
+#include "source.h"
+#include "funcs.h"
+#include "ops.h"
+
+#if !defined(PC) && !defined(DSP32)
+DoubleSource LogarithmDoubleSource( source )
+DoubleSource                        source ;
+{
+    return ( CallingDoubleSource( source, log ) ) ;
+}
+
+DoubleSource ExponentialDoubleSource( source )
+DoubleSource                          source ;
+{
+    return ( CallingDoubleSource( source, exp) ) ;
+}
+
+DoubleSource SineDoubleSource( source )
+DoubleSource                   source ;
+{
+    return ( CallingDoubleSource( source, sin ) ) ;
+}
+
+DoubleSource CosineDoubleSource( source )
+DoubleSource                     source ;
+{
+    return ( CallingDoubleSource( source, cos ) ) ;
+}
+
+DoubleSource SquareRootDoubleSource( source )
+DoubleSource                         source ;
+{
+    return ( CallingDoubleSource( source, sqrt ) ) ;
+}
+
+DoubleSource DoubleAbsDoubleSource( source )
+DoubleSource                        source ;
+{
+    return ( CallingDoubleSource( source, fabs ) ) ;
+}
+
+DoubleSource OscilatorDoubleSource( input, samplerate, phase0 )
+DoubleSource                        input ;
+				    double samplerate, phase0 ;
+{
+    double TwoPi = atan( 1. ) * 8. ;
+
+    return (
+      CosineDoubleSource(
+	IntegrateDoubleSource(
+	  MultiplyDoubleSources(
+	      input,
+	      ConstantDoubleSource( TwoPi / samplerate )
+	  ),
+	  phase0 / 360. * TwoPi
+	)
+      )
+    ) ;
+}
+
+DoubleSource CosinewaveDoubleSource( frequency, amplitude, phase0 )
+			      double frequency, amplitude, phase0 ;
+{
+    return ( MultiplyDoubleSources( OscilatorDoubleSource( ConstantDoubleSource( frequency ), 1., phase0 ), ConstantDoubleSource( amplitude ) ) ) ;
+}
+
+DoubleSource SinewaveDoubleSource( frequency, amplitude, phase0 )
+			    double frequency, amplitude, phase0 ;
+{
+    return ( CosinewaveDoubleSource( frequency, amplitude, phase0 - 90. ) ) ;
+}
+
+DoubleSource RaisedCosinewaveDoubleSource( frequency, amplitude, phase0 )
+				    double frequency, amplitude, phase0 ;
+{
+    return ( AddDoubleSources( CosinewaveDoubleSource( frequency, amplitude / 2., phase0 ), ConstantDoubleSource( amplitude / 2. ) ) ) ;
+}
+
+DoubleSource RaisedSinewaveDoubleSource( frequency, amplitude, phase0 )
+				  double frequency, amplitude, phase0 ;
+{
+    return ( RaisedCosinewaveDoubleSource( frequency, amplitude, phase0 - 90. ) ) ;
+}
+#endif
+
+#define LOG_ZERO (-10)
+
+static short imB( number )
+	    short number ;
+{
+    register int i, out ;
+    register long in ;
+    static int precision = 12 ;
+    static int *table = { ( int * ) 0 } ;
+    static unsigned table_size ;
+    static int inc ;
+    double k ;
+
+    if( table == ( int * ) 0 ) {
+
+	table_size = 1 << precision ;
+
+	k   = 2000. / log( 10. ) ;
+	inc = k     * log(  2. ) + 0.5 ;
+
+	table = (int *) stitch_malloc( table_size * sizeof( *table ), "imb.c for log table" ) ;
+
+	for( i=0 ; i < table_size ; i++ )
+	    table[ i ] = log( (double) ( table_size + i ) / table_size ) * k + 0.5 ;
+    }
+
+    if( number > 0 ) {
+
+	in = number ;
+
+	out = precision * inc ;
+
+	if( number < table_size )
+	    do {
+		in <<= 1 ;
+		out -= inc ;
+	    }
+	    while( in < table_size ) ;
+	else
+	    while( in - table_size >= table_size ) {
+		in >>= 1 ;
+		out += inc ;
+	    }
+
+	return ( out + table[ in - table_size ] ) ;
+    }
+    else
+	return ( LOG_ZERO ) ;
+}
+
+ShortSource milliBellShortSource( source )
+ShortSource                       source ;
+{
+    return ( CallingShortSource( source, imB ) ) ;
+}
+