-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cpp
95 lines (81 loc) · 2.29 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
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 "Common.h"
#include "Pool.h"
#include "AlsaReader.h"
#include "Reader.h"
#include "AlsaWriter.h"
#include "FileWriter.h"
#include "Detector.h"
#include <stdlib.h>
#include <string>
#include <iostream>
#define OPTS "i:o:f:n:"
using namespace std;
int main(int argc, char ** argv)
{
int n = 16;
char c;
Common::init();
//Common::log();
ModuleBase *producer = NULL;
ModuleBase *consumer = NULL;
Pool<short*> pool;
/*options:
-i select input mode: (default is Reader)
a -> AlsaReader
r -> Reader
-o select output mode: (default is Detector)
a -> AlsaWriter
d -> Detector
f -> FileWriter
-n specify number of items to process (default is 16)
-f specify file name (for fileWriter, not implemented yet)
*/
while((c = getopt(argc,argv,OPTS)) != -1){
switch(c){
case 'i':
if(!strcmp(optarg,"a")){
producer = new AlsaReader(&pool,"Alsa Reader");
}else if(!strcmp(optarg,"r")){
producer = new Reader(&pool,"Reader");
}else{
fprintf(stderr,"bad input option argument: %s\n",optarg);
exit(EXIT_FAILURE);
}
break;
case 'o':
if(!strcmp(optarg,"a")){
consumer = new AlsaWriter(&pool,"Alsa Writer");
}else if(!strcmp(optarg,"d")){
consumer = new Detector(&pool,"Freq Detector");
}else if(!strcmp(optarg,"f")){
consumer = new FileWriter(&pool,"File Writer", "data.raw");
}else{
fprintf(stderr,"invalid output option argument: %s\n",optarg);
exit(EXIT_FAILURE);
}
break;
case 'n':
n = atoi(optarg);
break;
case 'f':
break;
}
}
if(producer == NULL) producer = new Reader(&pool,"Default Reader");
if(consumer == NULL) consumer = new Detector(&pool,"Detector");
//Reader prod(&pool, "Alsa Reader 1");
//AlsaReader prod1(&pool, "Alsa reader 2");
//Detector cons0(&pool, "Freq Detector 0");
//AlsaWriter cons1(&pool, "Alsa Writer 0");
producer->execute(n);
consumer->execute(n);
//cons0.detect(55);
//cons1.execute(16);
//prod.execute(16);
//prod.join();
//cons0.join();
//cons1.join();
producer->join();
consumer->join();
return 0;
}