tomwalters@0: /* tomwalters@0: Copyright (c) Applied Psychology Unit, Medical Research Council. 1988, 1989 tomwalters@0: =========================================================================== tomwalters@0: tomwalters@0: Permission to use, copy, modify, and distribute this software without fee tomwalters@0: is hereby granted for research purposes, provided that this copyright tomwalters@0: notice appears in all copies and in all supporting documentation, and that tomwalters@0: the software is not redistributed for any fee (except for a nominal shipping tomwalters@0: charge). Anyone wanting to incorporate all or part of this software in a tomwalters@0: commercial product must obtain a license from the Medical Research Council. tomwalters@0: tomwalters@0: The MRC makes no representations about the suitability of this tomwalters@0: software for any purpose. It is provided "as is" without express or implied tomwalters@0: warranty. tomwalters@0: tomwalters@0: THE MRC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING tomwalters@0: ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL THE tomwalters@0: A.P.U. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY tomwalters@0: DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN tomwalters@0: AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF tomwalters@0: OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. tomwalters@0: */ tomwalters@0: tomwalters@0: /* tomwalters@0: interp.c tomwalters@0: ======== tomwalters@0: tomwalters@0: Some types of interpolation of short arrays for multiplexed filters tomwalters@0: tomwalters@0: linterp() performs fast linear interpolations from n points to n*2-1 tomwalters@0: points repeatedly till the number of points required is reached. tomwalters@0: tomwalters@0: interp() performs a slower but hopefully smoother (in the first differential) tomwalters@0: interpolation from n points to n*2-1 points. tomwalters@0: tomwalters@0: Author : John Holdsworth tomwalters@0: Written : 11th March, 1989. tomwalters@0: tomwalters@0: Edited : tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: */ tomwalters@0: tomwalters@0: tomwalters@0: #ifndef lint tomwalters@0: static char *sccs_id = "@(#)interp.c 1.4 J. Holdsworth (MRC-APU) 11/21/89" ; tomwalters@0: #endif tomwalters@0: tomwalters@0: tomwalters@0: /* linear interpolation */ tomwalters@0: tomwalters@0: int linterp( input, output, points, newpoints ) tomwalters@0: short *input, *output ; tomwalters@0: int points, newpoints ; tomwalters@0: { tomwalters@0: register int store ; tomwalters@0: register short *optr, *end, *iptr ; tomwalters@0: register int nextpoints ; tomwalters@0: tomwalters@0: nextpoints = points ; tomwalters@0: end = input + 1 ; tomwalters@0: tomwalters@0: do { tomwalters@0: tomwalters@0: iptr = end - 1 + nextpoints - 1 ; tomwalters@0: tomwalters@0: nextpoints = nextpoints * 2 - 1 ; tomwalters@0: tomwalters@0: optr = output + nextpoints ; tomwalters@0: end = output + 1 ; tomwalters@0: tomwalters@0: do { tomwalters@0: *--optr = store = * iptr ; tomwalters@0: *--optr = store + *--iptr >> 1 ; tomwalters@0: } while( optr > end ) ; tomwalters@0: tomwalters@0: } while ( nextpoints < newpoints ) ; tomwalters@0: tomwalters@0: *--optr = *iptr ; tomwalters@0: tomwalters@0: return ; tomwalters@0: } tomwalters@0: tomwalters@0: /* simple 2nd orderish interpolation - preserves slopes */ tomwalters@0: tomwalters@0: int interp( input, output, points, newpoints ) tomwalters@0: short *input, *output ; tomwalters@0: int points, newpoints ; tomwalters@0: { tomwalters@0: register short *optr, *end, *iptr ; tomwalters@0: register int nextnum, bignum, oldbignum, oldput ; tomwalters@0: tomwalters@0: iptr = input ; tomwalters@0: optr = output ; tomwalters@0: end = output + newpoints ; tomwalters@0: tomwalters@0: #ifdef lint tomwalters@0: points ; tomwalters@0: #endif tomwalters@0: tomwalters@0: nextnum = *(iptr+1) ; tomwalters@0: oldbignum = ( *iptr << 2 ) + *iptr ; tomwalters@0: oldput = ( *iptr << 1 ) - nextnum ; tomwalters@0: tomwalters@0: while( optr < end ) { tomwalters@0: *optr++ = *iptr++ ; tomwalters@0: if( optr < end ) { tomwalters@0: bignum = ( nextnum << 2 ) + nextnum ; tomwalters@0: if( optr < end - 2 ) tomwalters@0: nextnum = *(iptr+1) ; tomwalters@0: else tomwalters@0: nextnum = ( *iptr << 1 ) - *(iptr-1) ; tomwalters@0: *optr++ = ( oldbignum + bignum - oldput - nextnum + 4 ) >> 3 ; tomwalters@0: oldbignum = bignum ; tomwalters@0: oldput = *(iptr-1) ; tomwalters@0: } tomwalters@0: } tomwalters@0: tomwalters@0: return ; tomwalters@0: } tomwalters@0: