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 interp.c
|
tomwalters@0
|
26 ========
|
tomwalters@0
|
27
|
tomwalters@0
|
28 Some types of interpolation of short arrays for multiplexed filters
|
tomwalters@0
|
29
|
tomwalters@0
|
30 linterp() performs fast linear interpolations from n points to n*2-1
|
tomwalters@0
|
31 points repeatedly till the number of points required is reached.
|
tomwalters@0
|
32
|
tomwalters@0
|
33 interp() performs a slower but hopefully smoother (in the first differential)
|
tomwalters@0
|
34 interpolation from n points to n*2-1 points.
|
tomwalters@0
|
35
|
tomwalters@0
|
36 Author : John Holdsworth
|
tomwalters@0
|
37 Written : 11th March, 1989.
|
tomwalters@0
|
38
|
tomwalters@0
|
39 Edited :
|
tomwalters@0
|
40
|
tomwalters@0
|
41
|
tomwalters@0
|
42
|
tomwalters@0
|
43
|
tomwalters@0
|
44 */
|
tomwalters@0
|
45
|
tomwalters@0
|
46
|
tomwalters@0
|
47 #ifndef lint
|
tomwalters@0
|
48 static char *sccs_id = "@(#)interp.c 1.4 J. Holdsworth (MRC-APU) 11/21/89" ;
|
tomwalters@0
|
49 #endif
|
tomwalters@0
|
50
|
tomwalters@0
|
51
|
tomwalters@0
|
52 /* linear interpolation */
|
tomwalters@0
|
53
|
tomwalters@0
|
54 int linterp( input, output, points, newpoints )
|
tomwalters@0
|
55 short *input, *output ;
|
tomwalters@0
|
56 int points, newpoints ;
|
tomwalters@0
|
57 {
|
tomwalters@0
|
58 register int store ;
|
tomwalters@0
|
59 register short *optr, *end, *iptr ;
|
tomwalters@0
|
60 register int nextpoints ;
|
tomwalters@0
|
61
|
tomwalters@0
|
62 nextpoints = points ;
|
tomwalters@0
|
63 end = input + 1 ;
|
tomwalters@0
|
64
|
tomwalters@0
|
65 do {
|
tomwalters@0
|
66
|
tomwalters@0
|
67 iptr = end - 1 + nextpoints - 1 ;
|
tomwalters@0
|
68
|
tomwalters@0
|
69 nextpoints = nextpoints * 2 - 1 ;
|
tomwalters@0
|
70
|
tomwalters@0
|
71 optr = output + nextpoints ;
|
tomwalters@0
|
72 end = output + 1 ;
|
tomwalters@0
|
73
|
tomwalters@0
|
74 do {
|
tomwalters@0
|
75 *--optr = store = * iptr ;
|
tomwalters@0
|
76 *--optr = store + *--iptr >> 1 ;
|
tomwalters@0
|
77 } while( optr > end ) ;
|
tomwalters@0
|
78
|
tomwalters@0
|
79 } while ( nextpoints < newpoints ) ;
|
tomwalters@0
|
80
|
tomwalters@0
|
81 *--optr = *iptr ;
|
tomwalters@0
|
82
|
tomwalters@0
|
83 return ;
|
tomwalters@0
|
84 }
|
tomwalters@0
|
85
|
tomwalters@0
|
86 /* simple 2nd orderish interpolation - preserves slopes */
|
tomwalters@0
|
87
|
tomwalters@0
|
88 int interp( input, output, points, newpoints )
|
tomwalters@0
|
89 short *input, *output ;
|
tomwalters@0
|
90 int points, newpoints ;
|
tomwalters@0
|
91 {
|
tomwalters@0
|
92 register short *optr, *end, *iptr ;
|
tomwalters@0
|
93 register int nextnum, bignum, oldbignum, oldput ;
|
tomwalters@0
|
94
|
tomwalters@0
|
95 iptr = input ;
|
tomwalters@0
|
96 optr = output ;
|
tomwalters@0
|
97 end = output + newpoints ;
|
tomwalters@0
|
98
|
tomwalters@0
|
99 #ifdef lint
|
tomwalters@0
|
100 points ;
|
tomwalters@0
|
101 #endif
|
tomwalters@0
|
102
|
tomwalters@0
|
103 nextnum = *(iptr+1) ;
|
tomwalters@0
|
104 oldbignum = ( *iptr << 2 ) + *iptr ;
|
tomwalters@0
|
105 oldput = ( *iptr << 1 ) - nextnum ;
|
tomwalters@0
|
106
|
tomwalters@0
|
107 while( optr < end ) {
|
tomwalters@0
|
108 *optr++ = *iptr++ ;
|
tomwalters@0
|
109 if( optr < end ) {
|
tomwalters@0
|
110 bignum = ( nextnum << 2 ) + nextnum ;
|
tomwalters@0
|
111 if( optr < end - 2 )
|
tomwalters@0
|
112 nextnum = *(iptr+1) ;
|
tomwalters@0
|
113 else
|
tomwalters@0
|
114 nextnum = ( *iptr << 1 ) - *(iptr-1) ;
|
tomwalters@0
|
115 *optr++ = ( oldbignum + bignum - oldput - nextnum + 4 ) >> 3 ;
|
tomwalters@0
|
116 oldbignum = bignum ;
|
tomwalters@0
|
117 oldput = *(iptr-1) ;
|
tomwalters@0
|
118 }
|
tomwalters@0
|
119 }
|
tomwalters@0
|
120
|
tomwalters@0
|
121 return ;
|
tomwalters@0
|
122 }
|
tomwalters@0
|
123
|