CLAM-Development
1.1
|
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 "SDIFIn.hxx" 00023 #include "SpectrumConfig.hxx" 00024 #include "ErrOpenFile.hxx" 00025 #include "Frame.hxx" 00026 #include "Segment.hxx" 00027 #include "SpectralPeakArray.hxx" 00028 #include "Fundamental.hxx" 00029 #include "SDIFFile.hxx" 00030 #include "SDIFFrame.hxx" 00031 #include "SDIFMatrix.hxx" 00032 #include "Fundamental.hxx" 00033 #include "Spectrum.hxx" 00034 #include "SpectralPeakArray.hxx" 00035 00036 using std::iterator; 00037 00038 namespace CLAM 00039 { 00040 00041 SDIFIn::SDIFIn(): 00042 mOutput("Output",this), 00043 mSDIFReader(), 00044 mPrevIndexArray(0) 00045 { 00046 mLastCenterTime=-1; 00047 00048 Configure(SDIFInConfig()); 00049 } 00050 00051 SDIFIn::SDIFIn(const SDIFInConfig& c): 00052 mOutput("Output",this), 00053 mSDIFReader(c), 00054 mPrevIndexArray(0) 00055 { 00056 mLastCenterTime=-1; 00057 00058 Configure(c); 00059 } 00060 00061 SDIFIn::~SDIFIn() 00062 { 00063 } 00064 00065 bool SDIFIn::ConcreteConfigure(const ProcessingConfig& c) 00066 { 00067 CopyAsConcreteConfig(mConfig, c); 00068 00069 mSDIFReader.Configure(mConfig); 00070 00071 return true; 00072 } 00073 00074 bool SDIFIn::ConcreteStart() 00075 { 00076 return true; 00077 } 00078 00079 bool SDIFIn::ConcreteStop() 00080 { 00081 return true; 00082 } 00083 00084 const ProcessingConfig& SDIFIn::GetConfig() const 00085 { 00086 return mConfig; 00087 } 00088 00089 bool SDIFIn::LoadSDIFDataIntoSegment( CLAM::Segment& segment ) 00090 { 00091 00092 // CLAM::Fundamental fundamental; 00093 // CLAM::Spectrum residualSpectrum; 00094 // CLAM::SpectralPeakArray spectralPeaks; 00095 00096 // TODO: should you be recreating these objects every time? what would happen if you 00097 // used a single object? would the data be overwritten in the Reader or would 00098 // the new data be merely appended to the old? 00099 Frame aFrame; 00100 aFrame.AddSpectralPeakArray(); 00101 aFrame.AddResidualSpec(); 00102 aFrame.AddFundamental(); 00103 aFrame.UpdateData(); 00104 TTime frameCenterTime; 00105 00106 // Frame& tmpFrame=segment.GetFrame(segment.GetnFrames()-1); 00107 00108 // although it might be better to do this in a while loop, historically this method 00109 // was called once for each frame of data to be loaded. so, for backwards compatability 00110 // we will continue to do it this way. 00111 bool response = mSDIFReader.ReadFrame( aFrame.GetFundamental(), aFrame.GetSpectralPeakArray(), 00112 aFrame.GetResidualSpec(), frameCenterTime ); 00113 00114 if (response == true) 00115 { 00116 aFrame.SetCenterTime(frameCenterTime); 00117 00118 if ( !segment.HasSamplingRate() ) 00119 { 00120 segment.AddSamplingRate(); 00121 segment.UpdateData(); 00122 } 00123 segment.SetSamplingRate(mSDIFReader.GetSamplingRate()); 00124 00125 segment.AddFrame(aFrame); 00126 } 00127 00128 return response; 00129 } 00130 00131 bool SDIFIn::Do( CLAM::Segment& segment ) 00132 { 00133 //TODO uncomment: bool thereIsMoreData = false; 00134 00135 //TODO while( ( thereIsMoreData = LoadSDIFDataIntoSegment( segment ) ) ); 00136 return LoadSDIFDataIntoSegment( segment ); 00137 00138 return true; 00139 } 00140 00141 bool SDIFIn::Do(void) 00142 { 00143 bool result = LoadSDIFDataIntoSegment( mOutput.GetData() ); 00144 //mOutput.Produce(); 00145 return result; 00146 } 00147 00148 } // namespace CLAM 00149