CLAM-Development
1.4.0
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
src
Processing
Transformations
SMS
SMSTimeStretch.cxx
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2001-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 "
SMSTimeStretch.hxx
"
23
#include "
ProcessingFactory.hxx
"
24
25
namespace
CLAM
26
{
27
28
namespace
Hidden
29
{
30
static
const
char
*
metadata
[] = {
31
"key"
,
"SMSTimeStretch"
,
32
"category"
,
"SMS Transformations"
,
33
"description"
,
"SMSTimeStretch"
,
34
0
35
};
36
37
// static FactoryRegistrator<ProcessingFactory, SMSTimeStretch> reg = metadata;
38
}
39
40
bool
SMSTimeStretch::Do
(
const
Frame
& in,
Frame
& out)
41
{
42
return
Do
( in.GetSpectralPeakArray(),
43
in.GetFundamental(),
44
in.GetResidualSpec(),
45
46
out.GetSpectralPeakArray(),
47
out.GetFundamental(),
48
out.GetResidualSpec()
49
);
50
}
51
52
// bool SMSTimeStretch::Do(const Segment& in, Segment& out)
53
// {
54
// //Unused var: char test;
55
// if(mCurrentInputFrame>-1)
56
// {
57
// while(mCurrentInputFrame<in.mCurrentFrameIndex&&!HaveFinished())
58
// {
59
// if(mConcreteConfig.GetUseBPF())
60
// {
61
// UpdateControlValueFromBPF(((TData)mCurrentInputFrame)/in.GetnFrames());
62
// }
63
// TData previousAnalysisTime=mAnalysisTime;
64
// UpdateTimeAndIndex(in);
65
// if(mCurrentInputFrame>=in.mCurrentFrameIndex)
66
// {
67
// UpdateControlValueFromBPF(((TData)mCurrentInputFrame)/in.GetnFrames());
68
// mCurrentInputFrame=in.mCurrentFrameIndex-2;
69
// if(mCurrentInputFrame<0) mCurrentInputFrame=0;//I don't know why but this happens sometimes
70
// mLeftFrame=in.GetFrame(mCurrentInputFrame);
71
// mAnalysisTime=previousAnalysisTime;
72
// return true;
73
// }
74
// Do(GetCurrentFrame(in),GetCurrentFrame(out));
75
// CLAM_DEBUG_ASSERT(mCurrentInputFrame<in.mCurrentFrameIndex,"Error");
76
// out.mCurrentFrameIndex++;
77
// }
78
// }
79
// else mCurrentInputFrame++;
80
// return true;
81
// }
82
bool
SMSTimeStretch::Do
(
const
SpectralPeakArray
& inPeaks,
83
const
Fundamental
& inFund,
84
const
Spectrum
& inSpectrum,
85
SpectralPeakArray
& outPeaks,
86
Fundamental
& outFund,
87
Spectrum
& outSpectrum
88
)
89
{
90
// /**TODO: This method does not work if called directly! it must be called from the Segment overload*/
91
// bool SMSTimeStretch::Do(const Frame& in, Frame& out)
92
93
94
//FIXME
95
TData
interpFactor;
// = (mAnalysisTime-mLeftFrame.GetCenterTime()) / (mConfig.GetHopSize()/mConfig.GetSamplingRate());
96
// out.SetCenterTime(mSynthesisTime);
97
98
mSynthesisTime
+= (
TData
)mConfig.GetHopSize() / mConfig.GetSamplingRate();
99
100
mnSynthesisFrames
++;
101
102
// if (interpFactor>1)
103
// {
104
// TData tmpCenterTime = out.GetCenterTime();
105
// out = mLeftFrame;
106
// out.SetCenterTime( tmpCenterTime );
107
// return true;
108
// }
109
110
// if (interpFactor<0)
111
// {
112
// TData tmpCenterTime=out.GetCenterTime();
113
// out=in;
114
// out.SetCenterTime(tmpCenterTime);
115
// return true;
116
// }
117
118
// mFrameInterpolator.mFrameInterpolationFactorCtl.DoControl( interpFactor );
119
// mLeftFrame.GetSpectralPeakArray().SetIsIndexUpToDate(true);
120
// mFrameInterpolator.Do( in, mLeftFrame, out );
121
//TODO check morph interpolation
122
// TData newPitch = (1. - interpFactor)*inFund1.GetFreq() + interpFactor*inFund2.GetFreq();
123
// if( Harmonic ) newPitch=0;
124
// //Sets new fund freq
125
// if (outFund.GetnCandidates()==0)
126
// outFund.AddElem(newPitch,0);
127
// else
128
// outFund.SetFreq(0,newPitch);
129
// outFund.SetnCandidates(1);
130
131
// mPeaksInterpolator.GetInControl("MagInterpolationFactor").DoControl(interpFactor);
132
// mPeaksInterpolator.GetInControl("FreqInterpolationFactor").DoControl(alpha);
133
// mPeaksInterpolator.GetInControl("PitchInterpolationFactor").DoControl(alpha);
134
// mPeaksInterpolator.Do(inPeaks, inPeaks, outPeaks);
135
136
137
//TODO separate alpha/interpolation value for peaks and residual????
138
139
// outSpectrum = inSpectrum1; //FIXME asserts without this...
140
// CLAM_DEBUG_ASSERT( inSpectrum1.GetSize()==inSpectrum2.GetSize(), "Expected two spectrums of the same size");
141
// mSpectrumInterpolator.GetInControl("InterpolationFactor").DoControl(alpha);
142
143
// TODO fix (and check SpectrumInterpolator bug... (add/fix const inputs) mSpectrumInterpolator.Do(inSpectrum1, inSpectrum2, outSpectrum);)
144
// mSpectrumInterpolator.Do(const_cast<Spectrum&>(inSpectrum1), const_cast<Spectrum&>(inSpectrum2), outSpectrum);
145
146
return
true
;
147
}
148
149
150
// SMSTimeStretch::SMSTimeStretch()
151
// :mFactor("Stretch Factor", this)
152
// {
153
// mSynthesisTime=0;
154
// mAnalysisTime=0;
155
// mCurrentInputFrame=-1;
156
// Configure(SMSTimeStretchConfig());
157
// }
158
159
// SMSTimeStretch::SMSTimeStretch(const SegmentTransformationConfig &c)
160
// : SegmentTransformation(c),
161
// mFactor("Stretch Factor", this)
162
// {
163
// mSynthesisTime=0;
164
// mAnalysisTime=0;
165
// mCurrentInputFrame=-1;
166
// Configure(c);
167
// }
168
169
bool
SMSTimeStretch::ConcreteConfigure
(
const
ProcessingConfig
& config)
170
{
171
CopyAsConcreteConfig
( mConfig, config );
172
173
// mUseTemporalBPF=false;
174
// if(mConcreteConfig.HasAmount())
175
// mFactor.DoControl(mConcreteConfig.GetAmount());
176
// else if(mConcreteConfig.HasBPFAmount()){
177
// mFactor.DoControl(mConcreteConfig.GetBPFAmount().GetValue(0));
178
// mUseTemporalBPF=true;}
179
// else
180
// mAmount.DoControl(0);
181
182
// FrameInterpConfig tmpCfg;
183
// tmpCfg.SetHarmonic(mConfig.GetHarmonic());
184
// mFrameInterpolator.Configure(tmpCfg);
185
// mFrameInterpolator.Configure(FrameInterpConfig());
186
187
return
true
;
188
}
189
190
//FIXME
191
bool
SMSTimeStretch::ConcreteStop
()
192
{
193
// mFrameInterpolator.Stop();
194
return
true
;
195
}
196
197
//FIXME
198
bool
SMSTimeStretch::ConcreteStart
()
199
{
200
mSynthesisTime
=0;
201
mAnalysisTime
=0;
202
// mCurrentInputFrame=-1;
203
mnSynthesisFrames
=0;
204
// mFrameInterpolator.Start();
205
mLeftFrame
.SetCenterTime(-1);
206
return
true
;
207
}
208
209
// void SMSTimeStretch::UpdateTimeAndIndex(const Segment& in)
210
// {
211
// mAnalysisTime+=(TData)mConcreteConfig.GetHopSize()*mFactor.GetLastValue()/mConcreteConfig.GetSamplingRate();
212
// while(mAnalysisTime>mLeftFrame.GetCenterTime()+mConcreteConfig.GetHopSize()/mConcreteConfig.GetSamplingRate()&&mCurrentInputFrame<=in.GetnFrames())
213
// {
214
// mLeftFrame=in.GetFrame(mCurrentInputFrame);
215
// mCurrentInputFrame++;
216
// }
217
// }
218
//
219
// const Frame& SMSTimeStretch::GetCurrentFrame(const Segment& in)
220
// {
221
// return in.GetFrame(mCurrentInputFrame);
222
// }
223
//
224
//
225
// Frame& SMSTimeStretch::GetCurrentFrame(Segment& out)
226
// {
227
// if(mnSynthesisFrames==out.GetnFrames())
228
// out.AddFrame(out.GetFrame(out.GetnFrames()-1));
229
// return out.GetFrame(mnSynthesisFrames);
230
// }
231
//
232
//
233
// bool SMSTimeStretch::HaveFinished()
234
// {
235
// return mCurrentInputFrame>mInput->GetnFrames();
236
// }
237
//
238
// bool SMSTimeStretch::IsLastFrame()
239
// {
240
// bool isLast=HaveFinished();
241
// if(isLast)
242
// {
243
// while(mOutput->GetnFrames()>mnSynthesisFrames-1)
244
// {
245
// mOutput->DeleteFrame(mOutput->GetnFrames()-1);
246
// }
247
// }
248
// return isLast;
249
// }
250
251
252
}
253
Generated by
1.8.1