comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:5242703e91d3
1 /*
2 Copyright (c) Applied Psychology Unit, Medical Research Council. 1988, 1989
3 ===========================================================================
4
5 Permission to use, copy, modify, and distribute this software without fee
6 is hereby granted for research purposes, provided that this copyright
7 notice appears in all copies and in all supporting documentation, and that
8 the software is not redistributed for any fee (except for a nominal shipping
9 charge). Anyone wanting to incorporate all or part of this software in a
10 commercial product must obtain a license from the Medical Research Council.
11
12 The MRC makes no representations about the suitability of this
13 software for any purpose. It is provided "as is" without express or implied
14 warranty.
15
16 THE MRC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
17 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL THE
18 A.P.U. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
19 DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
20 AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
21 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 */
23
24 /*
25 funcs.c
26 =======
27
28
29
30
31 */
32
33 #include <math.h>
34
35 #include "stitch.h"
36 #include "source.h"
37 #include "funcs.h"
38 #include "ops.h"
39
40 #if !defined(PC) && !defined(DSP32)
41 DoubleSource LogarithmDoubleSource( source )
42 DoubleSource source ;
43 {
44 return ( CallingDoubleSource( source, log ) ) ;
45 }
46
47 DoubleSource ExponentialDoubleSource( source )
48 DoubleSource source ;
49 {
50 return ( CallingDoubleSource( source, exp) ) ;
51 }
52
53 DoubleSource SineDoubleSource( source )
54 DoubleSource source ;
55 {
56 return ( CallingDoubleSource( source, sin ) ) ;
57 }
58
59 DoubleSource CosineDoubleSource( source )
60 DoubleSource source ;
61 {
62 return ( CallingDoubleSource( source, cos ) ) ;
63 }
64
65 DoubleSource SquareRootDoubleSource( source )
66 DoubleSource source ;
67 {
68 return ( CallingDoubleSource( source, sqrt ) ) ;
69 }
70
71 DoubleSource DoubleAbsDoubleSource( source )
72 DoubleSource source ;
73 {
74 return ( CallingDoubleSource( source, fabs ) ) ;
75 }
76
77 DoubleSource OscilatorDoubleSource( input, samplerate, phase0 )
78 DoubleSource input ;
79 double samplerate, phase0 ;
80 {
81 double TwoPi = atan( 1. ) * 8. ;
82
83 return (
84 CosineDoubleSource(
85 IntegrateDoubleSource(
86 MultiplyDoubleSources(
87 input,
88 ConstantDoubleSource( TwoPi / samplerate )
89 ),
90 phase0 / 360. * TwoPi
91 )
92 )
93 ) ;
94 }
95
96 DoubleSource CosinewaveDoubleSource( frequency, amplitude, phase0 )
97 double frequency, amplitude, phase0 ;
98 {
99 return ( MultiplyDoubleSources( OscilatorDoubleSource( ConstantDoubleSource( frequency ), 1., phase0 ), ConstantDoubleSource( amplitude ) ) ) ;
100 }
101
102 DoubleSource SinewaveDoubleSource( frequency, amplitude, phase0 )
103 double frequency, amplitude, phase0 ;
104 {
105 return ( CosinewaveDoubleSource( frequency, amplitude, phase0 - 90. ) ) ;
106 }
107
108 DoubleSource RaisedCosinewaveDoubleSource( frequency, amplitude, phase0 )
109 double frequency, amplitude, phase0 ;
110 {
111 return ( AddDoubleSources( CosinewaveDoubleSource( frequency, amplitude / 2., phase0 ), ConstantDoubleSource( amplitude / 2. ) ) ) ;
112 }
113
114 DoubleSource RaisedSinewaveDoubleSource( frequency, amplitude, phase0 )
115 double frequency, amplitude, phase0 ;
116 {
117 return ( RaisedCosinewaveDoubleSource( frequency, amplitude, phase0 - 90. ) ) ;
118 }
119 #endif
120
121 #define LOG_ZERO (-10)
122
123 static short imB( number )
124 short number ;
125 {
126 register int i, out ;
127 register long in ;
128 static int precision = 12 ;
129 static int *table = { ( int * ) 0 } ;
130 static unsigned table_size ;
131 static int inc ;
132 double k ;
133
134 if( table == ( int * ) 0 ) {
135
136 table_size = 1 << precision ;
137
138 k = 2000. / log( 10. ) ;
139 inc = k * log( 2. ) + 0.5 ;
140
141 table = (int *) stitch_malloc( table_size * sizeof( *table ), "imb.c for log table" ) ;
142
143 for( i=0 ; i < table_size ; i++ )
144 table[ i ] = log( (double) ( table_size + i ) / table_size ) * k + 0.5 ;
145 }
146
147 if( number > 0 ) {
148
149 in = number ;
150
151 out = precision * inc ;
152
153 if( number < table_size )
154 do {
155 in <<= 1 ;
156 out -= inc ;
157 }
158 while( in < table_size ) ;
159 else
160 while( in - table_size >= table_size ) {
161 in >>= 1 ;
162 out += inc ;
163 }
164
165 return ( out + table[ in - table_size ] ) ;
166 }
167 else
168 return ( LOG_ZERO ) ;
169 }
170
171 ShortSource milliBellShortSource( source )
172 ShortSource source ;
173 {
174 return ( CallingShortSource( source, imB ) ) ;
175 }
176