2 * interpolation.h - fast implementations of several interpolation-algorithms
4 * Copyright (c) 2004-2005 Tobias Doerffel <tobydox/at/users.sourceforge.net>
6 * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public
19 * License along with this program (see COPYING); if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301 USA.
26 #ifndef _INTERPOLATION_H
27 #define _INTERPOLATION_H
34 #include "lmms_constants.h"
36 inline float hermiteInterpolate( float x0
, float x1
, float x2
, float x3
,
39 const float frsq
= frac_pos
*frac_pos
;
40 const float frsq2
= 2*frsq
;
41 return( ( (x2
-x0
) *0.5f
) * ( frac_pos
* (frsq
+1) -frsq2
) +
42 ( frsq2
*frac_pos
- 3*frsq
) * ( x1
-x2
) +
43 frsq2
* (frac_pos
-1) * ( ( x3
-x1
) * 0.25f
) + x1
);
46 const float frsq = frac_pos*frac_pos;
47 //const float frsq2 = 2*frsq;
49 const float frcu = frsq*frac_pos;
52 (frcu - frsq + frac_pos) * ((x2 - x0)) +
54 (4*frcu - 3*frsq) * (x1 - x2)
55 //frsq*(2*frac_pos-3) * (x1 - x2)
57 + (frcu - 0.5*frsq)*((x3 - x1))
67 inline float cubicInterpolate( float v0
, float v1
, float v2
, float v3
, float x
)
73 return( v1
+ 0.5f
* frcu
+ x
* ( v2
- frcu
* ( 1.0f
/6.0f
) -
74 t1
* ( 1.0f
/6.0f
) - v0
/ 3.0f
) + frsq
* x
* ( t1
*
75 ( 1.0f
/6.0f
) - 0.5f
* v2
) + frsq
* ( 0.5f
* v2
- v1
) );
80 inline float cosinusInterpolate( float v0
, float v1
, float x
)
82 float f
= cosf( x
* ( F_PI_2
) );
83 return( v0
*f
+ v1
*( 1.0f
-f
) );
88 inline float linearInterpolate( float v0
, float v1
, float x
)
90 return( v0
*( 1.0f
-x
) + v1
*x
);