-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAudioWindow.cpp
71 lines (58 loc) · 1.39 KB
/
AudioWindow.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
//
// AudioWindow.cpp
// AudioComponents
//
// Created by Aaron Dawson on 9/19/16.
//
//
#include "AudioWindow.hpp"
double* AudioWindow::blackman(unsigned long length)
{
double* window = new double[length];
unsigned long i;
double pi, phase = 0, delta;
pi = 4.*atan(1.0);
delta = 2 * pi / (double) length;
for( i = 0; i < length; i++ )
{
window[i] = (float)(0.42 - .5*cos(phase) + .08*cos(2*phase));
phase += delta;
}
return window;
}
double* AudioWindow::hamming(unsigned long length)
{
double* window = new double[length];
unsigned long i;
double pi, phase = 0, delta;
pi = 4.*atan(1.0);
delta = 2 * pi / (double) length;
for( i = 0; i < length; i++ )
{
window[i] = (float)(0.54 - .46*cos(phase));
phase += delta;
}
return window;
}
double* AudioWindow::hanning(unsigned long length)
{
double* window = new double[length];
unsigned long i;
double pi, phase = 0, delta;
pi = 4.*atan(1.0);
delta = 2 * pi / (double) length;
for( i = 0; i < length; i++ )
{
window[i] = (float)(0.5 * (1.0 - cos(phase)));
phase += delta;
}
return window;
}
double* AudioWindow::rectangular(unsigned long length)
{
double* window = new double[length];
for (int i=0; i<length; i++) {
window[i] = 1.0;
}
return window;
}