2 * LAME tools library include file
3 * Simple context free functions
4 * - no references to gfc, to gfp, or to any other function not defined
7 * Copyright (c) 2000 Frank Klemm
8 * Copyright (c) 2001 John Dahlstrom
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Library General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Library General Public License for more details.
20 * You should have received a copy of the GNU Library General Public
21 * License along with this library; if not, write to the
22 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 * Boston, MA 02111-1307, USA.
26 /* $Id: tools.h,v 1.1 2002/04/28 17:30:30 kramm Exp $ */
35 /***********************************************************************
36 * Function Prototype Declarations
37 ***********************************************************************/
39 static inline void qinterp_cf_42( const FLOAT y[4], FLOAT c[3] );
40 static inline void qinterp_cf_3( const FLOAT y[3], FLOAT c[3] );
41 static inline FLOAT qinterp_eval( const FLOAT c[3], FLOAT x,
42 FLOAT xtrans, FLOAT xratio );
46 /***********************************************************************
47 * Macros and Static Inline Function Definitions
48 ***********************************************************************/
50 /* qinterp_cf_42 - Given 4 points, find the coefficients for a quadratic
51 that connects the 2 center points. -jd
52 in: y coordinate values, paired with constant x coordinates, -1, 0, 1, 2
53 out: c coefficients ordered for quadratic, (c[2] * x*x + c[1] * x + c[0])
55 Utilize the inverse of two constant 3x3 matrices to compute two quadratics,
56 one from the points at (-1,0,1), and the other from the points at (0,1,2).
57 The mean of the two yields a quadratic between the points at 0 and 1.
60 qinterp_cf_42( const FLOAT y[4], FLOAT c[3] )
62 c[2] = ( y[0] - y[1] - y[2] + y[3]) * 0.25; /* ([1 -1 -1 1] .* Y) * 0.25 */
63 c[1] = y[2] - y[1] - c[2]; /* ([-1 -3 5 -1] .* Y) * 0.25 */
67 /* qinterp_cf_3 - Given 3 points, find the coefficients for a quadratic
68 that connects the 3 points. -jd
69 in: y coordinate values, paired with constant x coordinates, 0, 1, 2
70 out: c coefficients ordered for quadratic, (c[2] * x*x + c[1] * x + c[0])
73 qinterp_cf_3( const FLOAT y[3], FLOAT c[3] )
75 c[2] = ( y[0] + y[2]) * 0.5 - y[1]; /* ([1 -2 1] .* Y) * 0.5 */
76 c[1] = y[1] - y[0] - c[2]; /* ([-3 4 -1] .* Y) * 0.5 */
82 /* qinterp_eval - Evaluate a quadratic at a point, given polynomial
83 coefficients, and an x coordinate with translation and scale
84 ratio values. This function evaluates the quadratic at the
85 transformed x coordinate ((x - xtrans) * xratio)). -jd
86 in: c quadratic coefficients, for (c[2] * x * x + c[1] * x + c[0])
90 returns: y coordinate (the quadratic evaluated)
93 qinterp_eval( const FLOAT c[3], FLOAT x, FLOAT xtrans, FLOAT xratio )
95 x = (x - xtrans) * xratio;
96 return( (c[2] * x + c[1]) * x + c[0] );
101 #endif /* LAME_TOOLS_H */