annotate 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
rev   line source
tomwalters@0 1 /*
tomwalters@0 2 Copyright (c) Applied Psychology Unit, Medical Research Council. 1988, 1989
tomwalters@0 3 ===========================================================================
tomwalters@0 4
tomwalters@0 5 Permission to use, copy, modify, and distribute this software without fee
tomwalters@0 6 is hereby granted for research purposes, provided that this copyright
tomwalters@0 7 notice appears in all copies and in all supporting documentation, and that
tomwalters@0 8 the software is not redistributed for any fee (except for a nominal shipping
tomwalters@0 9 charge). Anyone wanting to incorporate all or part of this software in a
tomwalters@0 10 commercial product must obtain a license from the Medical Research Council.
tomwalters@0 11
tomwalters@0 12 The MRC makes no representations about the suitability of this
tomwalters@0 13 software for any purpose. It is provided "as is" without express or implied
tomwalters@0 14 warranty.
tomwalters@0 15
tomwalters@0 16 THE MRC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
tomwalters@0 17 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL THE
tomwalters@0 18 A.P.U. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
tomwalters@0 19 DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
tomwalters@0 20 AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
tomwalters@0 21 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
tomwalters@0 22 */
tomwalters@0 23
tomwalters@0 24 /*
tomwalters@0 25 ===================================================
tomwalters@0 26 new.c generic C code for recursive filter section.
tomwalters@0 27 ===================================================
tomwalters@0 28
tomwalters@0 29
tomwalters@0 30 J. Holdsworth - 23rd February 1988.
tomwalters@0 31
tomwalters@0 32
tomwalters@0 33 Copywright (c) Applied Psychology Unit, Medical Research Council. 1988.
tomwalters@0 34 =======================================================================
tomwalters@0 35
tomwalters@0 36
tomwalters@0 37 Release 2: 5th July 1988.
tomwalters@0 38 Rewrite : 21st Jan 1989.
tomwalters@0 39
tomwalters@0 40 */
tomwalters@0 41
tomwalters@0 42 #include "stitch.h"
tomwalters@0 43 #include "recurse.h"
tomwalters@0 44 #include "phase.h"
tomwalters@0 45 #include "gamma_tone.h"
tomwalters@0 46 #include "calc.h"
tomwalters@0 47
tomwalters@0 48 #ifdef DSP32
tomwalters@0 49 #define ASM
tomwalters@0 50 #endif
tomwalters@0 51
tomwalters@0 52 #define STATE_TYPE float
tomwalters@0 53
tomwalters@0 54 #ifndef INPUT_TYPE
tomwalters@0 55 #define INPUT_TYPE DataType
tomwalters@0 56 #endif
tomwalters@0 57
tomwalters@0 58 #ifndef OUTPUT_TYPE
tomwalters@0 59 #define OUTPUT_TYPE INPUT_TYPE
tomwalters@0 60 #endif
tomwalters@0 61
tomwalters@0 62 #ifndef MODULE_NAME
tomwalters@0 63 #define MODULE_NAME DoNewFilterDataArray
tomwalters@0 64 #define FILTER_NAME NewFilterDataArray
tomwalters@0 65 #endif
tomwalters@0 66
tomwalters@0 67 /* Code that performs the actual filtering */
tomwalters@0 68
tomwalters@0 69 PointCount MODULE_NAME( filter_states, delays, input, output, points, channels )
tomwalters@0 70 RecursiveFilterState **filter_states ;
tomwalters@0 71 int *delays ;
tomwalters@0 72 INPUT_TYPE *input ;
tomwalters@0 73 OUTPUT_TYPE *output ;
tomwalters@0 74 int points, channels ;
tomwalters@0 75 {
tomwalters@0 76 register STATE_TYPE *start, *xpt, *ypt, *gpt ;
tomwalters@0 77 #ifndef ASM
tomwalters@0 78 register double a0, a1, del1, del2 ;
tomwalters@0 79 #endif
tomwalters@0 80 register RecursiveFilterState *filter_state ;
tomwalters@0 81 register OUTPUT_TYPE *output_ptr, *end ;
tomwalters@0 82 register INPUT_TYPE *input_ptr ;
tomwalters@0 83 register STATE_TYPE a3, a2 ;
tomwalters@0 84 int channel ;
tomwalters@0 85
tomwalters@0 86 /* set up register pointers for speed of inner loop */
tomwalters@0 87
tomwalters@0 88 end = output + points * channels ;
tomwalters@0 89
tomwalters@0 90 /* for all channels */
tomwalters@0 91
tomwalters@0 92 for( channel=0 ; channel < channels ; channel++ ) {
tomwalters@0 93
tomwalters@0 94 filter_state = filter_states[ channel ] ;
tomwalters@0 95
tomwalters@0 96 /* if first time then perform implementation specific initialisation */
tomwalters@0 97
tomwalters@0 98 if( filter_state->states == ( Pointer ) 0 ) {
tomwalters@0 99
tomwalters@0 100 filter_state->states = stitch_ralloc( ( unsigned ) ( filter_state->order + 1 ) * 2 * sizeof ( STATE_TYPE ), "generic.c for filter states\n" ) ;
tomwalters@0 101 /* filter state stored in form of complex phasor for each cascade of filter */
tomwalters@0 102 /* real and imaginary state values interleaved in state array */
tomwalters@0 103
tomwalters@0 104 filter_state->states_end = ( Pointer ) ( ( STATE_TYPE * ) filter_state->states + ( filter_state->order + 1 ) * 2 ) ;
tomwalters@0 105
tomwalters@0 106 stitch_bzero( filter_state->states, filter_state->states_end - filter_state->states ) ;
tomwalters@0 107
tomwalters@0 108 }
tomwalters@0 109
tomwalters@0 110 if( input == ( INPUT_TYPE * ) 0 ) {
tomwalters@0 111 input_ptr = ( INPUT_TYPE * ) output ;
tomwalters@0 112
tomwalters@0 113 stitch_bzero( input_ptr, ( end - output ) / channels * sizeof ( *input_ptr ) ) ;
tomwalters@0 114 }
tomwalters@0 115 else
tomwalters@0 116 input_ptr = input - delays[ channel ] ;
tomwalters@0 117
tomwalters@0 118 start = ( STATE_TYPE * ) filter_state->states ;
tomwalters@0 119
tomwalters@0 120 a2 = filter_state->k1 ;
tomwalters@0 121 #ifndef ASM
tomwalters@0 122 a1 = a2 * 2 ;
tomwalters@0 123 #endif
tomwalters@0 124 a3 = filter_state->k2 ;
tomwalters@0 125
tomwalters@0 126 ypt = start + filter_state->order + 1 ;
tomwalters@0 127
tomwalters@0 128 gpt = &filter_state->gain ;
tomwalters@0 129
tomwalters@0 130 for( output_ptr = output + channel ; output_ptr < end ; output_ptr += channels ) {
tomwalters@0 131
tomwalters@0 132 #ifdef ASM
tomwalters@0 133 asm(" r12e = r13 ") ;
tomwalters@0 134
tomwalters@0 135 asm(" a1 = a2 + a2 ") ;
tomwalters@0 136
tomwalters@0 137 asm("*r12 = a0 = *r6++ ") ;
tomwalters@0 138
tomwalters@0 139 asm(" a0 = a0 - *r12++ * a2 ") ; /* xn-1 */
tomwalters@0 140 asm(" a0 = a0 + ( *r11 = *r12 ) * a1 ") ; /* yn-1 */
tomwalters@0 141 asm("*r12 = a0 = a0 - *r11++ * a3 ") ; /* yn-2 */
tomwalters@0 142
tomwalters@0 143 asm(" a0 = a0 - *r12++ * a2 ") ; /* xn-1 */
tomwalters@0 144 asm(" a0 = a0 + ( *r11 = *r12 ) * a1 ") ; /* yn-1 */
tomwalters@0 145 asm("*r12 = a0 = a0 - *r11++ * a3 ") ; /* yn-2 */
tomwalters@0 146
tomwalters@0 147 asm(" a0 = a0 - *r12++ * a2 ") ; /* xn-1 */
tomwalters@0 148 asm(" a0 = a0 + ( *r11 = *r12 ) * a1 ") ; /* yn-1 */
tomwalters@0 149 asm("*r12 = a0 = a0 - *r11++ * a3 ") ; /* yn-2 */
tomwalters@0 150
tomwalters@0 151 asm(" a0 = a0 - *r12++ * a2 ") ; /* xn-1 */
tomwalters@0 152 asm(" a0 = a0 + ( *r11 = *r12 ) * a1 ") ; /* yn-1 */
tomwalters@0 153 asm("*r12 = a0 = a0 - *r11++ * a3 ") ; /* yn-2 */
tomwalters@0 154
tomwalters@0 155 asm("*r8 = a0 = *r12++ * *r10") ;
tomwalters@0 156 #else
tomwalters@0 157 xpt = start ;
tomwalters@0 158
tomwalters@0 159 del1 = a0 = *input_ptr++ ;
tomwalters@0 160
tomwalters@0 161 a0 = a0 - *xpt++ * a2 ; /* xn-1 */ xpt[-1] = del1 ;
tomwalters@0 162 a0 = a0 + ( del2 = *xpt ) * a1 ; /* yn-1 */
tomwalters@0 163 del1 = a0 = a0 - *ypt++ * a3 ; /* yn-2 */ ypt[-1] = del2 ;
tomwalters@0 164
tomwalters@0 165 a0 = a0 - *xpt++ * a2 ; /* xn-1 */ xpt[-1] = del1 ;
tomwalters@0 166 a0 = a0 + ( del2 = *xpt ) * a1 ; /* yn-1 */
tomwalters@0 167 del1 = a0 = a0 - *ypt++ * a3 ; /* yn-2 */ ypt[-1] = del2 ;
tomwalters@0 168
tomwalters@0 169 a0 = a0 - *xpt++ * a2 ; /* xn-1 */ xpt[-1] = del1 ;
tomwalters@0 170 a0 = a0 + ( del2 = *xpt ) * a1 ; /* yn-1 */
tomwalters@0 171 del1 = a0 = a0 - *ypt++ * a3 ; /* yn-2 */ ypt[-1] = del2 ;
tomwalters@0 172
tomwalters@0 173 a0 = a0 - *xpt++ * a2 ; /* xn-1 */ xpt[-1] = del1 ;
tomwalters@0 174 a0 = a0 + ( del2 = *xpt ) * a1 ; /* yn-1 */
tomwalters@0 175 del1 = a0 = a0 - *ypt++ * a3 ; /* yn-2 */ ypt[-1] = del2 ;
tomwalters@0 176
tomwalters@0 177 *output_ptr = *gpt * a0 ; *xpt++ = del1 ;
tomwalters@0 178 #endif
tomwalters@0 179 ypt = xpt ;
tomwalters@0 180 }
tomwalters@0 181 }
tomwalters@0 182
tomwalters@0 183 return( sizeof ( OUTPUT_TYPE ) ) ;
tomwalters@0 184 }
tomwalters@0 185
tomwalters@0 186 /* for compatability */
tomwalters@0 187
tomwalters@0 188 PointCount FILTER_NAME( compensator_state, input_array, output_array, npoints )
tomwalters@0 189 FilterChannelInfo *compensator_state ;
tomwalters@0 190 INPUT_TYPE *input_array ;
tomwalters@0 191 OUTPUT_TYPE *output_array ;
tomwalters@0 192 PointCount npoints ;
tomwalters@0 193 {
tomwalters@0 194 ( ( PhaseCompensatorState * ) compensator_state )->filter_module = MODULE_NAME ;
tomwalters@0 195
tomwalters@0 196 return( PhaseCompensateFilter( ( PhaseCompensatorState * ) compensator_state, ( Pointer ) input_array, ( Pointer ) output_array, npoints ) ) ;
tomwalters@0 197 }
tomwalters@0 198
tomwalters@0 199
tomwalters@0 200 /* tidy up defines for redefinition */
tomwalters@0 201
tomwalters@0 202 #undef STATE_TYPE
tomwalters@0 203 #undef INPUT_TYPE
tomwalters@0 204 #undef OUTPUT_TYPE
tomwalters@0 205 #undef FILTER_NAME
tomwalters@0 206 #undef MODULE_NAME
tomwalters@0 207 #undef I_SHIFT
tomwalters@0 208 #undef K_SHIFT
tomwalters@0 209 #undef S_SHIFT
tomwalters@0 210
tomwalters@0 211 #undef SIN
tomwalters@0 212 #undef COS
tomwalters@0 213
tomwalters@0 214 #ifdef FLOAT
tomwalters@0 215 #undef FLOAT
tomwalters@0 216 #endif
tomwalters@0 217
tomwalters@0 218 #ifdef COMPLEX
tomwalters@0 219 #undef COMPLEX
tomwalters@0 220 #endif