source: roaraudio/libroardsp/poly.c @ 383:56f41c54f169

Last change on this file since 383:56f41c54f169 was 383:56f41c54f169, checked in by phi, 16 years ago

added working 16 bit mono resampling code

File size: 1.5 KB
Line 
1//math.c:
2
3#include "libroar.h"
4
5int roar_math_mkpoly (float * poly, float * data, int len) {
6 if ( len == 2 )
7  return roar_math_mkpoly_2x2(poly, data);
8 if ( len == 3 )
9  return roar_math_mkpoly_3x3(poly, data);
10 if ( len == 4 )
11  return roar_math_mkpoly_4x4(poly, data);
12 if ( len == 5 )
13  return roar_math_mkpoly_5x5(poly, data);
14
15 return -1;
16}
17
18int roar_math_mkpoly_2x2 (float * poly, float * data) {
19/*
20 A B
21 0 1 x
22 1 1 y
23
24B = x
25A = y - x
26*/
27
28 poly[0] =           data[0];
29 poly[1] = data[1] - data[0];
30
31 return 0;
32}
33
34int roar_math_mkpoly_3x3 (float * poly, float * data) {
35/*
36 A B C
37 0 0 1 x
38 1 1 1 y
39 4 2 1 z
40*/
41
42 poly[0] = data[0];
43 poly[1] = 2*data[1] - 2*data[0] - (data[2]-data[0])/2;
44 poly[2] = (data[2]-data[0])/2 - data[1] + data[0];
45
46
47 return 0;
48}
49
50int roar_math_mkpoly_4x4 (float * poly, float * data) {
51/*
52   a    b    c    d
53   0    0    0    1  A X 0
54   1    1    1    1  B Y 1
55   8    4    2    1  C Z 2
56  27    9    3    1  D Q 3
57*/
58
59
60// { a = -(3z-3y+x-q)/6, b = (4z-5y+2x-q)/2, c = -(9z-18y+11x-2q)/6, d = x }.
61
62 poly[0] =      data[0];
63 poly[1] = -(11*data[0] - 18*data[1] + 9*data[2] - 2*data[3])/6;
64 poly[2] =  (2 *data[0] -  5*data[1] + 4*data[2] -   data[3])/2;
65 poly[3] = -(   data[0] -  3*data[1] + 3*data[2] -   data[3])/6;
66
67 return 0;
68}
69
70int roar_math_mkpoly_5x5 (float * poly, float * data) {
71 return -1;
72}
73
74
75float roar_math_cvpoly_4x4 (float * poly, float t) {
76 float ret = poly[0];
77 float ct  = t;
78
79 ret += poly[1] * ct;
80 ct  *= t;
81 ret += poly[2] * ct;
82 ct  *= t;
83 ret += poly[3] * ct;
84
85// printf("ret=%f\n", ret);
86
87 return ret;
88}
89
90//ll
Note: See TracBrowser for help on using the repository browser.