source: roaraudio/libroardsp/poly.c @ 4708:c9d40761088a

Last change on this file since 4708:c9d40761088a was 4708:c9d40761088a, checked in by phi, 13 years ago

updated copyright statements

File size: 3.2 KB
Line 
1//poly.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2011
5 *
6 *  This file is part of libroar a part of RoarAudio,
7 *  a cross-platform sound system for both, home and professional use.
8 *  See README for details.
9 *
10 *  This file is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License version 3
12 *  as published by the Free Software Foundation.
13 *
14 *  libroar is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU General Public License for more details.
18 *
19 *  You should have received a copy of the GNU General Public License
20 *  along with this software; see the file COPYING.  If not, write to
21 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
23 *
24 *  NOTE for everyone want's to change something and send patches:
25 *  read README and HACKING! There a addition information on
26 *  the license of this document you need to read before you send
27 *  any patches.
28 *
29 *  NOTE for uses of non-GPL (LGPL,...) software using libesd, libartsc
30 *  or libpulse*:
31 *  The libs libroaresd, libroararts and libroarpulse link this lib
32 *  and are therefore GPL. Because of this it may be illigal to use
33 *  them with any software that uses libesd, libartsc or libpulse*.
34 */
35
36#include "libroardsp.h"
37
38int roar_math_mkpoly (float * poly, float * data, int len) {
39 if ( len == 2 )
40  return roar_math_mkpoly_2x2(poly, data);
41 if ( len == 3 )
42  return roar_math_mkpoly_3x3(poly, data);
43 if ( len == 4 )
44  return roar_math_mkpoly_4x4(poly, data);
45 if ( len == 5 )
46  return roar_math_mkpoly_5x5(poly, data);
47
48 return -1;
49}
50
51int roar_math_mkpoly_2x2 (float * poly, float * data) {
52/*
53 A B
54 0 1 x
55 1 1 y
56
57B = x
58A = y - x
59*/
60
61 poly[0] =           data[0];
62 poly[1] = data[1] - data[0];
63
64 return 0;
65}
66
67int roar_math_mkpoly_3x3 (float * poly, float * data) {
68/*
69 A B C
70 0 0 1 x
71 1 1 1 y
72 4 2 1 z
73*/
74
75 poly[0] = data[0];
76 poly[1] = 2*data[1] - 2*data[0] - (data[2]-data[0])/2;
77 poly[2] = (data[2]-data[0])/2 - data[1] + data[0];
78
79
80 return 0;
81}
82
83int roar_math_mkpoly_4x4 (float * poly, float * data) {
84/*
85   a    b    c    d
86   0    0    0    1  A X 0
87   1    1    1    1  B Y 1
88   8    4    2    1  C Z 2
89  27    9    3    1  D Q 3
90*/
91
92
93// { a = -(3z-3y+x-q)/6, b = (4z-5y+2x-q)/2, c = -(9z-18y+11x-2q)/6, d = x }.
94
95 poly[0] =      data[0];
96 poly[1] = -(11*data[0] - 18*data[1] + 9*data[2] - 2*data[3])/6;
97 poly[2] =  (2 *data[0] -  5*data[1] + 4*data[2] -   data[3])/2;
98 poly[3] = -(   data[0] -  3*data[1] + 3*data[2] -   data[3])/6;
99
100 return 0;
101}
102
103int roar_math_mkpoly_5x5 (float * poly, float * data) {
104 return -1;
105}
106
107
108float roar_math_cvpoly     (float * poly, float t, int len) {
109 float ret = 0;
110 float ct  = 1;
111 int i;
112
113 if ( poly == NULL )
114  return 0;
115
116 switch (len) {
117  case 4: return roar_math_cvpoly_4x4(poly, t);
118 }
119
120 for (i = 0; i < len; i++) {
121  ret += poly[i] * ct;
122  ct  *= t;
123 }
124
125 return ret;
126}
127
128float roar_math_cvpoly_4x4 (float * poly, float t) {
129 float ret = poly[0];
130 float ct  = t;
131
132 ret += poly[1] * ct;
133 ct  *= t;
134 ret += poly[2] * ct;
135 ct  *= t;
136 ret += poly[3] * ct;
137
138// printf("ret=%f\n", ret);
139
140 return ret;
141}
142
143//ll
Note: See TracBrowser for help on using the repository browser.