2
* interpolation.h - fast implementations of several interpolation-algorithms
4
* Linux MultiMedia Studio
5
* Copyright (c) 2004-2005 Tobias Doerffel <tobydox@users.sourceforge.net>
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public
9
* License as published by the Free Software Foundation; either
10
* version 2 of the License, or (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* General Public License for more details.
17
* You should have received a copy of the GNU General Public
18
* License along with this program (see COPYING); if not, write to the
19
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20
* Boston, MA 02111-1307, USA.
25
#ifndef _INTERPOLATION_H
26
#define _INTERPOLATION_H
35
inline float hermiteInterpolate( float x0, float x1, float x2, float x3,
38
const float frsq = frac_pos*frac_pos;
39
const float frsq2 = 2*frsq;
40
return( ( (x2-x0) *0.5f ) * ( frac_pos * (frsq+1) -frsq2 ) +
41
( frsq2*frac_pos - 3*frsq ) * ( x1-x2 ) +
42
frsq2 * (frac_pos-1) * ( ( x3-x1 ) * 0.25f ) + x1 );
45
const float frsq = frac_pos*frac_pos;
46
//const float frsq2 = 2*frsq;
48
const float frcu = frsq*frac_pos;
51
(frcu - frsq + frac_pos) * ((x2 - x0)) +
53
(4*frcu - 3*frsq) * (x1 - x2)
54
//frsq*(2*frac_pos-3) * (x1 - x2)
56
+ (frcu - 0.5*frsq)*((x3 - x1))
66
inline float cubicInterpolate( float v0, float v1, float v2, float v3, float x )
72
return( v1 + 0.5f * frcu + x * ( v2 - frcu * ( 1.0f/6.0f ) -
73
t1 * ( 1.0f/6.0f ) - v0 / 3.0f ) + frsq * x * ( t1 *
74
( 1.0f/6.0f ) - 0.5f * v2 ) + frsq * ( 0.5f * v2 - v1 ) );
79
inline float cosinusInterpolate( float v0, float v1, float x )
81
float f = cosf( x * ( M_PI*0.5f ) );
82
return( v0*f + v1*( 1.0f-f ) );
87
inline float linearInterpolate( float v0, float v1, float x )
89
return( v0*( 1.0f-x ) + v1*x );
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., 59 Temple Place - Suite 330,
21
* Boston, MA 02111-1307, USA.
26
#ifndef _INTERPOLATION_H
27
#define _INTERPOLATION_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 * ( M_PI*0.5f ) );
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 );