CLAM-Development  1.4.0
SegmentSMSTimeStretch.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 
23 #include "ProcessingFactory.hxx"
24 
25 
26 
27 namespace CLAM
28 {
29 
30 namespace Hidden
31 {
32  static const char * metadata[] = {
33  "key", "SegmentSMSTimeStretch",
34 // "category", "SMS Transformations",
35  "description", "SegmentSMSTimeStretch",
36  0
37  };
38  static FactoryRegistrator<ProcessingFactory, SegmentSMSTimeStretch> reg = metadata;
39 }
40 
42 {
44  mAnalysisTime=0;
47 }
48 
50 {
52  mAnalysisTime=0;
54  Configure(c);
55 }
56 
58 {
60  mUseTemporalBPF=false;
61  if(mConcreteConfig.HasAmount())
62  mAmount.DoControl(mConcreteConfig.GetAmount());
63  else if(mConcreteConfig.HasBPFAmount()){
64  mAmount.DoControl(mConcreteConfig.GetBPFAmount().GetValue(0));
65  mUseTemporalBPF=true;}
66  else
67  mAmount.DoControl(0);
68 
69  FrameInterpConfig tmpCfg;
70  tmpCfg.SetHarmonic(mConcreteConfig.GetHarmonic());
72 
74 
75  return true;
76 }
77 
79 {
81  return true;
82 }
83 
85 {
87  mAnalysisTime=0;
91  mLeftFrame.SetCenterTime(-1);
92  return true;
93 }
94 
96 bool SegmentSMSTimeStretch::Do(const Frame& in, Frame& out)
97 {
98  TData interpFactor= (mAnalysisTime-mLeftFrame.GetCenterTime())/(mConcreteConfig.GetHopSize()/mConcreteConfig.GetSamplingRate());
99  out.SetCenterTime(mSynthesisTime);
100  mSynthesisTime+=(TData)mConcreteConfig.GetHopSize()/mConcreteConfig.GetSamplingRate();
102  if(interpFactor>1)
103  {
104  TData tmpCenterTime=out.GetCenterTime();
105  out=mLeftFrame;
106  out.SetCenterTime(tmpCenterTime);
107  return true;
108  }
109  if (interpFactor<0)
110  {
111  TData tmpCenterTime=out.GetCenterTime();
112  out=in;
113  out.SetCenterTime(tmpCenterTime);
114  return true;
115  }
116 
118  mLeftFrame.GetSpectralPeakArray().SetIsIndexUpToDate(true);
120 
121  return true;
122 }
123 
124 
126 {
127  //Unused var: char test;
128  if(mCurrentInputFrame>-1)
129  {
131  {
132  if(mConcreteConfig.GetUseBPF())
133  {
135  }
136  TData previousAnalysisTime=mAnalysisTime;
137  UpdateTimeAndIndex(in);
139  {
141  mCurrentInputFrame=in.mCurrentFrameIndex-2;
142  if(mCurrentInputFrame<0) mCurrentInputFrame=0;//I don't know why but this happens sometimes
143  mLeftFrame=in.GetFrame(mCurrentInputFrame);
144  mAnalysisTime=previousAnalysisTime;
145  return true;
146  }
149  out.mCurrentFrameIndex++;
150  }
151  }
152  else mCurrentInputFrame++;
153  return true;
154 }
155 
157 {
158  mAnalysisTime+=(TData)mConcreteConfig.GetHopSize()*mAmount.GetLastValue()/mConcreteConfig.GetSamplingRate();
159  while(mAnalysisTime>mLeftFrame.GetCenterTime()+mConcreteConfig.GetHopSize()/mConcreteConfig.GetSamplingRate()&&mCurrentInputFrame<=in.GetnFrames())
160  {
163  }
164 }
165 
167 {
168  return in.GetFrame(mCurrentInputFrame);
169 }
170 
171 
173 {
174  if(mnSynthesisFrames==out.GetnFrames())
175  out.AddFrame(out.GetFrame(out.GetnFrames()-1));
176  return out.GetFrame(mnSynthesisFrames);
177 }
178 
179 
181 {
183 }
184 
186 {
187  bool isLast=HaveFinished();
188  if(isLast)
189  {
191  {
193  }
194  }
195  return isLast;
196 }
197 
198 
199 }
200