CLAM-Development  1.4.0
SDIFIn.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 "SDIFIn.hxx"
23 #include "SpectrumConfig.hxx"
24 #include "ErrOpenFile.hxx"
25 #include "Frame.hxx"
26 #include "Segment.hxx"
27 #include "SpectralPeakArray.hxx"
28 #include "Fundamental.hxx"
29 #include "SDIFFile.hxx"
30 #include "SDIFFrame.hxx"
31 #include "SDIFMatrix.hxx"
32 #include "Fundamental.hxx"
33 #include "Spectrum.hxx"
34 #include "SpectralPeakArray.hxx"
35 
36 using std::iterator;
37 
38 namespace CLAM
39 {
40 
42  mOutput("Output",this),
43  mSDIFReader(),
44  mPrevIndexArray(0)
45 {
46  mLastCenterTime=-1;
47 
49 }
50 
52  mOutput("Output",this),
53  mSDIFReader(c),
54  mPrevIndexArray(0)
55 {
56  mLastCenterTime=-1;
57 
58  Configure(c);
59 }
60 
62 {
63 }
64 
65 bool SDIFIn::ConcreteConfigure(const ProcessingConfig& c)
66 {
67  CopyAsConcreteConfig(mConfig, c);
68 
69  mSDIFReader.Configure(mConfig);
70 
71  return true;
72 }
73 
75 {
76  return true;
77 }
78 
80 {
81  return true;
82 }
83 
85 {
86  return mConfig;
87 }
88 
90 {
91 
92 // CLAM::Fundamental fundamental;
93 // CLAM::Spectrum residualSpectrum;
94 // CLAM::SpectralPeakArray spectralPeaks;
95 
96  // TODO: should you be recreating these objects every time? what would happen if you
97  // used a single object? would the data be overwritten in the Reader or would
98  // the new data be merely appended to the old?
99  Frame aFrame;
100  aFrame.AddSpectralPeakArray();
101  aFrame.AddResidualSpec();
102  aFrame.AddFundamental();
103  aFrame.UpdateData();
104  TTime frameCenterTime;
105 
106 // Frame& tmpFrame=segment.GetFrame(segment.GetnFrames()-1);
107 
108  // although it might be better to do this in a while loop, historically this method
109  // was called once for each frame of data to be loaded. so, for backwards compatability
110  // we will continue to do it this way.
111  bool response = mSDIFReader.ReadFrame( aFrame.GetFundamental(), aFrame.GetSpectralPeakArray(),
112  aFrame.GetResidualSpec(), frameCenterTime );
113 
114  if (response == true)
115  {
116  aFrame.SetCenterTime(frameCenterTime);
117 
118  if ( !segment.HasSamplingRate() )
119  {
120  segment.AddSamplingRate();
121  segment.UpdateData();
122  }
123  segment.SetSamplingRate(mSDIFReader.GetSamplingRate());
124 
125  segment.AddFrame(aFrame);
126  }
127 
128  return response;
129 }
130 
131 bool SDIFIn::Do( CLAM::Segment& segment )
132 {
133  //TODO uncomment: bool thereIsMoreData = false;
134 
135 //TODO while( ( thereIsMoreData = LoadSDIFDataIntoSegment( segment ) ) );
136  return LoadSDIFDataIntoSegment( segment );
137 
138  return true;
139 }
140 
141 bool SDIFIn::Do(void)
142 {
143  bool result = LoadSDIFDataIntoSegment( mOutput.GetData() );
144  //mOutput.Produce();
145  return result;
146 }
147 
148 } // namespace CLAM
149