Mercurial > hg > aim92
comparison filter/phase.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 phase.c | |
26 ======= | |
27 | |
28 looks after phase compensation of all filter types | |
29 | |
30 | |
31 */ | |
32 | |
33 #include "stitch.h" | |
34 #include "phase.h" | |
35 | |
36 | |
37 PhaseCompensatorState *NewPhaseCompensator( filter_state, filter_module, sample_delay ) | |
38 FilterState filter_state ; | |
39 FilterModule filter_module ; | |
40 double sample_delay ; | |
41 { | |
42 DeclareNew( PhaseCompensatorState *, compensator_state ) ; | |
43 | |
44 compensator_state->filter_state = filter_state ; | |
45 compensator_state->filter_module = filter_module ; | |
46 compensator_state->sample_delay = sample_delay + 0.5 ; | |
47 | |
48 compensator_state->delay_buffer = ( Pointer ) 0 ; | |
49 | |
50 return( compensator_state ) ; | |
51 } | |
52 | |
53 PointCount PhaseCompensateFilter( compensator_state, input, output, points ) | |
54 PhaseCompensatorState *compensator_state ; | |
55 Pointer input ; | |
56 Pointer output ; | |
57 PointCount points ; | |
58 { | |
59 unsigned output_size ; | |
60 int byte_delay, bytes ; | |
61 PointCount process ; | |
62 Pointer input_ptr ; | |
63 static int zero = 0 ; | |
64 | |
65 /* support for new and old zero point transfers to get any remaining | |
66 data from filters - in short a mess */ | |
67 | |
68 if( compensator_state->sample_delay < 0 && ( input == ( Pointer ) 0 || points == 0 ) ) { | |
69 process = - ( int ) compensator_state->sample_delay ; | |
70 | |
71 if( process > points && points != 0 ) | |
72 process = points ; | |
73 | |
74 compensator_state->sample_delay = ( int ) compensator_state->sample_delay + process ; | |
75 | |
76 input_ptr = ( Pointer ) 0 ; | |
77 } | |
78 else { | |
79 process = points ; | |
80 input_ptr = input ; | |
81 } | |
82 | |
83 /* call filter pod */ | |
84 | |
85 output_size = compensator_state->filter_module( | |
86 &compensator_state->filter_state, | |
87 &zero, | |
88 input_ptr, | |
89 output, | |
90 process, | |
91 1 | |
92 ) ; | |
93 | |
94 byte_delay = ( int ) compensator_state->sample_delay * output_size ; | |
95 bytes = points * output_size ; | |
96 | |
97 if( compensator_state->delay_buffer == ( Pointer ) 0 ) | |
98 if( ( int ) compensator_state->sample_delay < 0 ) { | |
99 stitch_bcopy( output - byte_delay, output, bytes - byte_delay ) ; | |
100 compensator_state->delay_buffer = ( Pointer ) 0 + 1 ; | |
101 | |
102 return( points + ( int ) compensator_state->sample_delay ) ; | |
103 } | |
104 else | |
105 compensator_state->delay_buffer = stitch_calloc( | |
106 ( unsigned ) compensator_state->sample_delay * 2, | |
107 output_size, "phase.c for delay buffer\n" ) ; | |
108 | |
109 if( byte_delay > bytes ) { | |
110 stitch_bcopy( output, compensator_state->delay_buffer + byte_delay, bytes ) ; | |
111 stitch_bcopy( compensator_state->delay_buffer, output, bytes ) ; | |
112 stitch_bcopy( compensator_state->delay_buffer + bytes, compensator_state->delay_buffer, byte_delay ) ; | |
113 } | |
114 else if( byte_delay > 0 ) { | |
115 stitch_bcopy( output + bytes - byte_delay, compensator_state->delay_buffer + byte_delay, byte_delay ) ; | |
116 stitch_bcopy( output, output + byte_delay, bytes - byte_delay ) ; | |
117 stitch_bcopy( compensator_state->delay_buffer, output, byte_delay ) ; | |
118 stitch_bcopy( compensator_state->delay_buffer + byte_delay, compensator_state->delay_buffer, byte_delay ) ; | |
119 } | |
120 | |
121 return( process ) ; | |
122 } | |
123 | |
124 void FreeCompensatedFilter( compensator_state ) | |
125 PhaseCompensatorState *compensator_state ; | |
126 { | |
127 stitch_free( compensator_state->filter_state ) ; | |
128 stitch_free( ( Pointer ) compensator_state ) ; | |
129 | |
130 return ; | |
131 } | |
132 |