/
main.cpp
63 lines (52 loc) · 1.46 KB
/
main.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
#include <cmath>
#include <cstdlib>
#include "ODF/ODF.h"
#include "portaudio/audio_io.h"
#define SAMPLERATE 44100
#define CHANNELS 1
#define FRAMES 65536
#define ARGCOUNT 3
int findNotZeros(float* x, unsigned long N, unsigned long offset) {
int count = 0;
for(unsigned long n=0; n<N; ++n) {
if(x[n] > 0) {
std::cout << "onset: " << N+(offset*N) << std::endl;
count++;
};
};
return count;
};
int main(int argc, char** argv) {
if(argc < ARGCOUNT) {
std::cout << "usage: ....\n";
return -1;
}
unsigned long N = atoi(argv[1]);
// open audiostream:
Audio_IO audioStream(SAMPLERATE, 1);
float* buffer = new float[N];
static int input_device;
audioStream.set_mode(AUDIO_IO_READONLY);
audioStream.set_framesperbuffer(N);
audioStream.initialise();
audioStream.list_devices();
std::cout << "\nGive input device number: ";
std::cin >> input_device;
audioStream.set_input_device(input_device);
audioStream.start_server();
// init ODF:
float th = atof(argv[2]);
float binTh = atof(argv[3]);
int rechargeN = atoi(argv[4]);
ODF* odf = new ODF(N, 512, 1024, 128, th, binTh, rechargeN);
float* onsets;
unsigned long frame = 0;
while (true) {
audioStream.read(buffer);
onsets = odf->phaseFlux(buffer, N);
findNotZeros(onsets, N, frame);
frame++;
}
delete[] buffer;
return 0;
}