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