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