CLAM-Development
1.4.0
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
src
Processing
Transformations
SMS
SegmentTransformation.cxx
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2004 MUSIC TECHNOLOGY GROUP (MTG)
3
* UNIVERSITAT POMPEU FABRA
4
*
5
*
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
*
20
*/
21
22
#include "
SegmentTransformation.hxx
"
23
24
namespace
CLAM
25
{
26
void
SegmentTransformation::WrapFrameTransformation
(
FrameTransformation
* trans)
27
{
28
CLAM_ASSERT
( !mFrameTransformation,
"SegmentTransformation::Wrapp object shoudn't have wrapped transformation"
);
29
mFrameTransformation = trans;
30
}
31
32
SegmentTransformation::SegmentTransformation
()
33
: mOnCtrl(
"On"
,this)
34
, mAmountCtrl(
"Amount"
,this)
35
{
36
mInput
= 0;
37
mOutput
= 0;
38
mUseTemporalBPF
= 0;
39
mCurrentInputFrame
= 0;
40
mFrameTransformation = 0;
41
}
42
43
SegmentTransformation::SegmentTransformation
(
const
SegmentTransformationConfig
& c)
44
: mOnCtrl(
"On"
,this)
45
, mAmountCtrl(
"Amount"
,this)
46
{
47
mInput
= 0;
48
mOutput
= 0;
49
mUseTemporalBPF
= 0;
50
mCurrentInputFrame
= 0;
51
Configure
(c);
52
mFrameTransformation = 0;
53
}
54
55
SegmentTransformation::~SegmentTransformation
()
56
{
57
if
(mFrameTransformation)
58
delete
mFrameTransformation;
59
};
60
61
bool
SegmentTransformation::Do
(
const
Segment
& in,
Segment
& out)
62
{
63
CLAM_ASSERT
(
mInput
==&in,
"sms transformation chain needs input segment"
);
64
//TODO find out why this finalization condition (and not just using size)
65
while
(
mCurrentInputFrame
<in.
mCurrentFrameIndex
)
66
{
67
if
(
mUseTemporalBPF
)
68
UpdateControlValueFromBPF
(((
TData
)in.
mCurrentFrameIndex
)/in.
GetnFrames
());
69
70
AddFramesToOutputIfInputIsLonger
(
mCurrentInputFrame
, in, out);
71
72
const
Frame
& inframe = in.
GetFrame
(
mCurrentInputFrame
);
73
Frame
& outframe = out.
GetFrame
(
mCurrentInputFrame
);
74
75
if
(mFrameTransformation)
76
{
77
mFrameTransformation->
Do
(inframe, outframe);
78
}
79
else
//TODO remove when refactoring is done
80
{
81
Do
( inframe, outframe );
82
}
83
84
85
86
if
(&in!=&out)
87
out.
mCurrentFrameIndex
++;
88
89
mCurrentInputFrame
++;
90
}
91
return
true
;
92
}
93
94
bool
SegmentTransformation::ConcreteConfigure
(
const
ProcessingConfig
& c)
95
{
96
CopyAsConcreteConfig
(
mConfig
, c);
97
mUseTemporalBPF
=
false
;
98
if
(
mConfig
.HasAmount())
99
{
100
mAmountCtrl
.
DoControl
(
mConfig
.GetAmount());
101
}
102
else
if
(
mConfig
.HasBPFAmount()){
103
mAmountCtrl
.
DoControl
(
mConfig
.GetBPFAmount().GetValue(0));
104
mUseTemporalBPF
=
true
;
105
}
106
else
107
{
108
mAmountCtrl
.
DoControl
(0);
109
}
110
111
return
true
;
112
}
113
114
bool
SegmentTransformation::UpdateControlValueFromBPF
(
TData
pos)
115
{
116
if
(
mConfig
.HasBPFAmount())
117
{
118
TControlData
amount =
mConfig
.GetBPFAmount().GetValue(pos);
119
mAmountCtrl
.
DoControl
(amount);
120
return
true
;
121
}
122
else
return
false
;
123
}
124
125
bool
SegmentTransformation::IsLastFrame
()
126
{
127
bool
isLast=
mInput
->
mCurrentFrameIndex
>=
mInput
->
GetnFrames
();
128
129
if
(isLast)
130
{
131
while
(
mOutput
->
GetnFrames
()>=
mOutput
->
mCurrentFrameIndex
)
132
{
133
mOutput
->
DeleteFrame
(
mOutput
->
GetnFrames
()-1);
134
}
135
}
136
return
isLast;
137
}
138
139
bool
SegmentTransformation::ConcreteStart
()
140
{
141
return
true
;
142
}
143
144
145
146
}
147
Generated by
1.8.1