-
Notifications
You must be signed in to change notification settings - Fork 48
/
Polyphase.cpp
95 lines (73 loc) · 2.14 KB
/
Polyphase.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "Polyphase.h"
#include <math.h>
#define IS_DENORMAL(x) (fabs(x) < 0.000001f)
CPolyphase::CPolyphase()
{
suspend();
}
CPolyphase::~CPolyphase()
{
}
void CPolyphase::suspend()
{
lout[0] = lout[1] = lout[2] = 0.f;
uout[0] = uout[1] = uout[2] = 0.f;
uin_1[0] = uin_1[1] = uin_1[2] = 0.f;
lin_1[0] = lin_1[1] = lin_1[2] = 0.f;
}
//remember: output has to be twice the size of input!!!
void CPolyphase::Upsample(float *input, float *output, long nSamples)
{
long index = 0;
for(long i=0;i<nSamples;i++)
{
lout[0] = (input[i] - lout[0])*0.039151597734460045f + lin_1[0];
uout[0] = (input[i] - uout[0])*0.147377113601046600f + uin_1[0];
uin_1[0] = lin_1[0] = input[i];
uout[1] = (uout[0] - uout[1])*0.48246854276970014f + uin_1[1];
lout[1] = (lout[0] - lout[1])*0.30264684832849340f + lin_1[1];
lin_1[1] = lout[0];
uin_1[1] = uout[0];
output[index] = lout[2] = (lout[1] - lout[2])*0.6746159185469639f + lin_1[2];
output[index+1] = uout[2] = (uout[1] - uout[2])*0.8830050257693731f + uin_1[2];
uin_1[2] = uout[1];
lin_1[2] = lout[1];
index += 2;
}
}
//remember: input has to be twice the size of output!!!
void CPolyphase::Downsample(float *input, float *output, long nSamples)
{
long index = 0;
for(long i=0;i<nSamples;i++,index+=2)
{
uout[0] = (input[index] - uout[0])*0.1473771136010466f + uin_1[0];
lout[0] = (input[index+1] - lout[0])*0.039151597734460045f + lin_1[0];
lin_1[0] = input[index+1];
uin_1[0] = input[index];
uout[1] = (uout[0] - uout[1])*0.48246854276970014f + uin_1[1];
lout[1] = (lout[0] - lout[1])*0.3026468483284934f + lin_1[1];
lin_1[1] = lout[0];
uin_1[1] = uout[0];
uout[2] = (uout[1] - uout[2])*0.8830050257693731f + uin_1[2];
lout[2] = (lout[1] - lout[2])*0.6746159185469639f + lin_1[2];
lin_1[2] = lout[1];
uin_1[2] = uout[1];
output[i] = (lout[2] + uout[2])*0.5f;
}
}
void CPolyphase::denormalise()
{
if(IS_DENORMAL(lout[0]))
lout[0] = 0.f;
if(IS_DENORMAL(lout[1]))
lout[1] = 0.f;
if(IS_DENORMAL(lout[2]))
lout[2] = 0.f;
if(IS_DENORMAL(uout[0]))
uout[0] = 0.f;
if(IS_DENORMAL(uout[1]))
uout[1] = 0.f;
if(IS_DENORMAL(uout[2]))
uout[2] = 0.f;
}