-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOLA.cpp
More file actions
70 lines (59 loc) · 1.31 KB
/
OLA.cpp
File metadata and controls
70 lines (59 loc) · 1.31 KB
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
#include <stdio.h>
#include <math.h>
#include <iostream>
using namespace std;
#define PI 3.1416
#define CHUNK 4096
inline double* han2()
{
double *w = new double[CHUNK];
for(int i =0;i<CHUNK;i++)
w[i] = pow(sin(PI*(i/float(CHUNK))),2);
return w;
}
//cache hann window
const double *han_buf = han2();
double frame1[CHUNK]={0};
double prev_x[CHUNK/2]={0};
double prev_han[CHUNK/2]={0};
// =======================
// x-1 x
// .....|.....|
// ^-----^
// frame1
// ^-----^
// out
// ^-----^
// current frame
// ^--^
// prev_x
// ^--^
// prev_han = han(x)[CHUNK/2:end]
//
//=======================
extern "C" void ola(double x[],double *out)
{
//prepare two frames for processing
for(int i =0;i<CHUNK/2;i++)
{
frame1[i] = prev_x[i];
prev_x[i] = x[i+CHUNK/2];
}
for(int i =CHUNK/2;i<CHUNK;i++)
frame1[i] = x[i-CHUNK/2];
//Start frame1,x process
//END frame1,x process
for(int i =0;i<CHUNK;i++)
frame1[i] *= han_buf[i];
//OLA
for(int i =0;i<CHUNK/2;i++)
{
out[i] = frame1[i]+prev_han[i];
}
for(int i =0;i<CHUNK;i++)
x[i] *= han_buf[i];
for(int i =CHUNK/2;i<CHUNK;i++)
out[i] =frame1[i]+x[i-CHUNK/2];
for(int i =0;i<CHUNK/2;i++)
prev_han[i] = x[i+CHUNK/2];
}