SegmentTransformation.cxx

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2004 MUSIC TECHNOLOGY GROUP (MTG)
00003  *                         UNIVERSITAT POMPEU FABRA
00004  *
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 
00022 #include "SegmentTransformation.hxx"
00023 
00024 namespace CLAM
00025 {
00026         void SegmentTransformation::WrapFrameTransformation( FrameTransformation* trans)
00027         {
00028                 CLAM_ASSERT( !mFrameTransformation, "SegmentTransformation::Wrapp object shoudn't have wrapped transformation");
00029                 mFrameTransformation = trans;
00030         }
00031         
00032         SegmentTransformation::SegmentTransformation()
00033                 : mOnCtrl("On",this)
00034                 , mAmountCtrl("Amount",this)
00035         {
00036                 mInput = 0;
00037                 mOutput = 0;
00038                 mUseTemporalBPF = 0;
00039                 mCurrentInputFrame = 0;
00040                 mFrameTransformation = 0;
00041         }
00042 
00043         SegmentTransformation::SegmentTransformation(const SegmentTransformationConfig& c) 
00044                 : mOnCtrl("On",this)
00045                 , mAmountCtrl("Amount",this)
00046         {
00047                 mInput = 0;
00048                 mOutput = 0;
00049                 mUseTemporalBPF = 0;
00050                 mCurrentInputFrame = 0;
00051                 Configure(c);
00052                 mFrameTransformation = 0;
00053         }
00054 
00055         SegmentTransformation::~SegmentTransformation()
00056         {
00057                 if (mFrameTransformation)
00058                         delete mFrameTransformation;
00059         };
00060         
00061         bool SegmentTransformation::Do(const Segment& in, Segment& out)
00062         {
00063                 CLAM_ASSERT(mInput==&in, "sms transformation chain needs input segment");
00064                 //TODO find out why this finalization condition (and not just using size)
00065                 while( mCurrentInputFrame<in.mCurrentFrameIndex)
00066                 {
00067                         if(mUseTemporalBPF)
00068                                 UpdateControlValueFromBPF(((TData)in.mCurrentFrameIndex)/in.GetnFrames());
00069                         
00070                         AddFramesToOutputIfInputIsLonger(mCurrentInputFrame, in, out);
00071                         
00072                         const Frame & inframe = in.GetFrame(mCurrentInputFrame);
00073                         Frame & outframe = out.GetFrame(mCurrentInputFrame);
00074 
00075                         if (mFrameTransformation)
00076                         {
00077                                 mFrameTransformation->Do(inframe, outframe);
00078                         }
00079                         else //TODO remove when refactoring is done 
00080                         {
00081                                 Do( inframe, outframe );
00082                         }
00083                         
00084 
00085                         
00086                         if(&in!=&out)
00087                                 out.mCurrentFrameIndex++;
00088                         
00089                         mCurrentInputFrame++;
00090                 }
00091                 return true;
00092         }
00093 
00094         bool SegmentTransformation::ConcreteConfigure(const ProcessingConfig& c)
00095         {
00096                 CopyAsConcreteConfig(mConfig, c);
00097                 mUseTemporalBPF=false;
00098                 if(mConfig.HasAmount())
00099                 {
00100                         mAmountCtrl.DoControl(mConfig.GetAmount());                                                             
00101                 }
00102                 else if(mConfig.HasBPFAmount()){
00103                         mAmountCtrl.DoControl(mConfig.GetBPFAmount().GetValue(0));              
00104                         mUseTemporalBPF=true;
00105                 }
00106                 else
00107                 {
00108                         mAmountCtrl.DoControl(0);                                                                               
00109                 }
00110 
00111                 return true;
00112         }       
00113 
00114         bool SegmentTransformation::UpdateControlValueFromBPF(TData pos)
00115         {
00116                 if(mConfig.HasBPFAmount())
00117                 {
00118                         TControlData amount = mConfig.GetBPFAmount().GetValue(pos);
00119                         mAmountCtrl.DoControl(amount);
00120                         return true;
00121                 }
00122                 else return false;
00123         }
00124 
00125         bool SegmentTransformation::IsLastFrame()
00126         {
00127                 bool isLast=mInput->mCurrentFrameIndex >= mInput->GetnFrames();
00128                 
00129                 if(isLast)
00130                 {
00131                         while(mOutput->GetnFrames()>=mOutput->mCurrentFrameIndex)
00132                         {
00133                                 mOutput->DeleteFrame(mOutput->GetnFrames()-1);
00134                         }
00135                 }
00136                 return isLast;
00137         }
00138 
00139         bool SegmentTransformation::ConcreteStart()
00140         {
00141                 return true;
00142         }
00143 
00144 
00145 
00146 }
00147 
Generated by  doxygen 1.6.3