Mercurial > hg > aim92
comparison model/new.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 =================================================== | |
26 new.c generic C code for recursive filter section. | |
27 =================================================== | |
28 | |
29 | |
30 J. Holdsworth - 23rd February 1988. | |
31 | |
32 | |
33 Copywright (c) Applied Psychology Unit, Medical Research Council. 1988. | |
34 ======================================================================= | |
35 | |
36 | |
37 Release 2: 5th July 1988. | |
38 Rewrite : 21st Jan 1989. | |
39 | |
40 */ | |
41 | |
42 #include "stitch.h" | |
43 #include "recurse.h" | |
44 #include "phase.h" | |
45 #include "gamma_tone.h" | |
46 #include "calc.h" | |
47 | |
48 #ifdef DSP32 | |
49 #define ASM | |
50 #endif | |
51 | |
52 #define STATE_TYPE float | |
53 | |
54 #ifndef INPUT_TYPE | |
55 #define INPUT_TYPE DataType | |
56 #endif | |
57 | |
58 #ifndef OUTPUT_TYPE | |
59 #define OUTPUT_TYPE INPUT_TYPE | |
60 #endif | |
61 | |
62 #ifndef MODULE_NAME | |
63 #define MODULE_NAME DoNewFilterDataArray | |
64 #define FILTER_NAME NewFilterDataArray | |
65 #endif | |
66 | |
67 /* Code that performs the actual filtering */ | |
68 | |
69 PointCount MODULE_NAME( filter_states, delays, input, output, points, channels ) | |
70 RecursiveFilterState **filter_states ; | |
71 int *delays ; | |
72 INPUT_TYPE *input ; | |
73 OUTPUT_TYPE *output ; | |
74 int points, channels ; | |
75 { | |
76 register STATE_TYPE *start, *xpt, *ypt, *gpt ; | |
77 #ifndef ASM | |
78 register double a0, a1, del1, del2 ; | |
79 #endif | |
80 register RecursiveFilterState *filter_state ; | |
81 register OUTPUT_TYPE *output_ptr, *end ; | |
82 register INPUT_TYPE *input_ptr ; | |
83 register STATE_TYPE a3, a2 ; | |
84 int channel ; | |
85 | |
86 /* set up register pointers for speed of inner loop */ | |
87 | |
88 end = output + points * channels ; | |
89 | |
90 /* for all channels */ | |
91 | |
92 for( channel=0 ; channel < channels ; channel++ ) { | |
93 | |
94 filter_state = filter_states[ channel ] ; | |
95 | |
96 /* if first time then perform implementation specific initialisation */ | |
97 | |
98 if( filter_state->states == ( Pointer ) 0 ) { | |
99 | |
100 filter_state->states = stitch_ralloc( ( unsigned ) ( filter_state->order + 1 ) * 2 * sizeof ( STATE_TYPE ), "generic.c for filter states\n" ) ; | |
101 /* filter state stored in form of complex phasor for each cascade of filter */ | |
102 /* real and imaginary state values interleaved in state array */ | |
103 | |
104 filter_state->states_end = ( Pointer ) ( ( STATE_TYPE * ) filter_state->states + ( filter_state->order + 1 ) * 2 ) ; | |
105 | |
106 stitch_bzero( filter_state->states, filter_state->states_end - filter_state->states ) ; | |
107 | |
108 } | |
109 | |
110 if( input == ( INPUT_TYPE * ) 0 ) { | |
111 input_ptr = ( INPUT_TYPE * ) output ; | |
112 | |
113 stitch_bzero( input_ptr, ( end - output ) / channels * sizeof ( *input_ptr ) ) ; | |
114 } | |
115 else | |
116 input_ptr = input - delays[ channel ] ; | |
117 | |
118 start = ( STATE_TYPE * ) filter_state->states ; | |
119 | |
120 a2 = filter_state->k1 ; | |
121 #ifndef ASM | |
122 a1 = a2 * 2 ; | |
123 #endif | |
124 a3 = filter_state->k2 ; | |
125 | |
126 ypt = start + filter_state->order + 1 ; | |
127 | |
128 gpt = &filter_state->gain ; | |
129 | |
130 for( output_ptr = output + channel ; output_ptr < end ; output_ptr += channels ) { | |
131 | |
132 #ifdef ASM | |
133 asm(" r12e = r13 ") ; | |
134 | |
135 asm(" a1 = a2 + a2 ") ; | |
136 | |
137 asm("*r12 = a0 = *r6++ ") ; | |
138 | |
139 asm(" a0 = a0 - *r12++ * a2 ") ; /* xn-1 */ | |
140 asm(" a0 = a0 + ( *r11 = *r12 ) * a1 ") ; /* yn-1 */ | |
141 asm("*r12 = a0 = a0 - *r11++ * a3 ") ; /* yn-2 */ | |
142 | |
143 asm(" a0 = a0 - *r12++ * a2 ") ; /* xn-1 */ | |
144 asm(" a0 = a0 + ( *r11 = *r12 ) * a1 ") ; /* yn-1 */ | |
145 asm("*r12 = a0 = a0 - *r11++ * a3 ") ; /* yn-2 */ | |
146 | |
147 asm(" a0 = a0 - *r12++ * a2 ") ; /* xn-1 */ | |
148 asm(" a0 = a0 + ( *r11 = *r12 ) * a1 ") ; /* yn-1 */ | |
149 asm("*r12 = a0 = a0 - *r11++ * a3 ") ; /* yn-2 */ | |
150 | |
151 asm(" a0 = a0 - *r12++ * a2 ") ; /* xn-1 */ | |
152 asm(" a0 = a0 + ( *r11 = *r12 ) * a1 ") ; /* yn-1 */ | |
153 asm("*r12 = a0 = a0 - *r11++ * a3 ") ; /* yn-2 */ | |
154 | |
155 asm("*r8 = a0 = *r12++ * *r10") ; | |
156 #else | |
157 xpt = start ; | |
158 | |
159 del1 = a0 = *input_ptr++ ; | |
160 | |
161 a0 = a0 - *xpt++ * a2 ; /* xn-1 */ xpt[-1] = del1 ; | |
162 a0 = a0 + ( del2 = *xpt ) * a1 ; /* yn-1 */ | |
163 del1 = a0 = a0 - *ypt++ * a3 ; /* yn-2 */ ypt[-1] = del2 ; | |
164 | |
165 a0 = a0 - *xpt++ * a2 ; /* xn-1 */ xpt[-1] = del1 ; | |
166 a0 = a0 + ( del2 = *xpt ) * a1 ; /* yn-1 */ | |
167 del1 = a0 = a0 - *ypt++ * a3 ; /* yn-2 */ ypt[-1] = del2 ; | |
168 | |
169 a0 = a0 - *xpt++ * a2 ; /* xn-1 */ xpt[-1] = del1 ; | |
170 a0 = a0 + ( del2 = *xpt ) * a1 ; /* yn-1 */ | |
171 del1 = a0 = a0 - *ypt++ * a3 ; /* yn-2 */ ypt[-1] = del2 ; | |
172 | |
173 a0 = a0 - *xpt++ * a2 ; /* xn-1 */ xpt[-1] = del1 ; | |
174 a0 = a0 + ( del2 = *xpt ) * a1 ; /* yn-1 */ | |
175 del1 = a0 = a0 - *ypt++ * a3 ; /* yn-2 */ ypt[-1] = del2 ; | |
176 | |
177 *output_ptr = *gpt * a0 ; *xpt++ = del1 ; | |
178 #endif | |
179 ypt = xpt ; | |
180 } | |
181 } | |
182 | |
183 return( sizeof ( OUTPUT_TYPE ) ) ; | |
184 } | |
185 | |
186 /* for compatability */ | |
187 | |
188 PointCount FILTER_NAME( compensator_state, input_array, output_array, npoints ) | |
189 FilterChannelInfo *compensator_state ; | |
190 INPUT_TYPE *input_array ; | |
191 OUTPUT_TYPE *output_array ; | |
192 PointCount npoints ; | |
193 { | |
194 ( ( PhaseCompensatorState * ) compensator_state )->filter_module = MODULE_NAME ; | |
195 | |
196 return( PhaseCompensateFilter( ( PhaseCompensatorState * ) compensator_state, ( Pointer ) input_array, ( Pointer ) output_array, npoints ) ) ; | |
197 } | |
198 | |
199 | |
200 /* tidy up defines for redefinition */ | |
201 | |
202 #undef STATE_TYPE | |
203 #undef INPUT_TYPE | |
204 #undef OUTPUT_TYPE | |
205 #undef FILTER_NAME | |
206 #undef MODULE_NAME | |
207 #undef I_SHIFT | |
208 #undef K_SHIFT | |
209 #undef S_SHIFT | |
210 | |
211 #undef SIN | |
212 #undef COS | |
213 | |
214 #ifdef FLOAT | |
215 #undef FLOAT | |
216 #endif | |
217 | |
218 #ifdef COMPLEX | |
219 #undef COMPLEX | |
220 #endif |