-
Notifications
You must be signed in to change notification settings - Fork 3
/
recorder.cpp
124 lines (108 loc) · 2.84 KB
/
recorder.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
* Copyright 2009 by Idiap Research Institute, http://www.idiap.ch
*
* See the file COPYING for the licence associated with this software.
*/
#include <tracter/Source.h>
#include <tracter/SndFileSink.h>
#include <tracter/ASRFactory.h>
#include <tracter/Frame.h>
#include <tracter/Unframe.h>
#include <tracter/Energy.h>
#include <tracter/Modulation.h>
#include <tracter/NoiseVAD.h>
#include <tracter/VADGate.h>
#include <tracter/Mean.h>
#include <tracter/Variance.h>
#include <tracter/Subtract.h>
#include <tracter/Divide.h>
#include <tracter/Select.h>
#include <tracter/Minima.h>
#include <tracter/Comparator.h>
#include <tracter/TimedLatch.h>
#include <tracter/Gate.h>
using namespace Tracter;
class Record : public Tracter::Object
{
public:
Record()
{
objectName("Record");
ASRFactory fac;
Component<float>* p = 0;
VADStateMachine* sm = 0;
// Choose a VAD
enum {
MODULATION,
NEW_MODULATION
};
const StringEnum cVAD[] = {
{"Modulation", MODULATION},
{"NewModulation", NEW_MODULATION},
{0, -1}
};
int vad = config(cVAD, -1);
// Source
p = fac.createSource(mSource);
switch (vad)
{
// Modulation VAD
case MODULATION:
{
Component<float>* v = p;
v = new Frame(v);
v = new Energy(v);
Modulation* m = new Modulation(v);
sm = new NoiseVAD(m, v);
p = new Frame(p);
p = new VADGate(p, sm);
p = new Unframe(p);
break;
}
// New Modulation VAD
case NEW_MODULATION:
{
Component<float>* v = p;
v = new Frame(v);
v = new Energy(v);
Modulation* m = new Modulation(v);
Component<float>* n = new Minima(v);
Component<BoolType>* b = new Comparator(m, n);
b = new TimedLatch(b);
p = new Frame(p);
p = new Gate(p, b);
p = new Unframe(p);
break;
}
default:
verbose(1, "No VAD, or not compiled in\n");
}
// Sink
mSink = new SndFileSink(p);
}
virtual ~Record() throw ()
{
// Delete the sink
delete mSink;
}
void All(int argc, char* argv[])
{
if (argc != 3)
throw Exception(
"argc != 3\n"
"usage: recorder <insource> <outsink>\n"
"(and don't forget to set your environment variables!)\n"
);
verbose(1, "%s -> %s\n", argv[1], argv[2]);
mSource->open(argv[1]);
mSink->open(argv[2]);
}
private:
ISource* mSource;
SndFileSink* mSink;
};
int main(int argc, char* argv[])
{
Record r;
r.All(argc, argv);
}