CLAM-Development  1.4.0
OverlapAdd.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 "OverlapAdd.hxx"
23 #include "ProcessingFactory.hxx"
24 
25 namespace CLAM
26 {
27 
28 namespace Hidden
29 {
30  static const char * metadata[] = {
31  "key", "OverlapAdd",
32  "category", "Synthesis",
33  "description", "OverlapAdd",
34  0
35  };
36  static FactoryRegistrator<ProcessingFactory, OverlapAdd> reg = metadata;
37 }
38 
39 /* processing object method implementations */
40 
42  : mInput( "Audio Input", this ),
43  mOutput( "Audio Output", this )
44 {
45  Configure(c);
46 }
47 
49 {
50 }
51 
52 
53 /* configure the processing object according to the config object */
54 
55 bool OverlapAdd::ConcreteConfigure(const ProcessingConfig& c)
56 {
58 
59 
60  int frameSize=mConfig.GetFrameSize();
61 
62  mInput.SetSize( frameSize*2 );
63  mInput.SetHop( frameSize*2 );
64 
65  mOutput.SetSize( frameSize );
66  mOutput.SetHop( frameSize );
67 
68  mTmp.SetSize( frameSize*2 +1 );
69 
70  for(int i=0;i<mTmp.GetSize();i++)
71  mTmp.GetBuffer()[i]=0.0f;
72 
73  return true;
74 }
75 
76 /* the supervised Do() function */
77 
78 bool OverlapAdd::Do(void)
79 {
80  bool result = Do( mInput.GetAudio(), mOutput.GetAudio() );
81  mInput.Consume();
82  mOutput.Produce();
83  return result;
84 }
85 
86 bool OverlapAdd::Do( const Audio &in, Audio & out)
87 {
88  //xamat: testing
89  /* std::cout<<"***OverlapAdd Configuration: "<<std::endl;
90  std::cout<<"FrameSize: "<<mConfig.GetFrameSize()<<std::endl;
91  std::cout<<"Input Audio Size: "<<in.GetSize()<<std::endl;
92  std::cout<<"Output Audio Size: "<<out.GetSize()<<std::endl;
93  */
94  // TODO: refactor
95  int halfSize = in.GetSize()/2;
96  CLAM_DEBUG_ASSERT( out.GetSize() == halfSize, "OverlapAdd::Do - Audio Out size must be half the input size" );
97  CLAM_DEBUG_ASSERT( mConfig.GetFrameSize() == halfSize, "OverlapAdd::Do - Config FrameSize must be half the input size" );
98 
99  CLAM::DataArray & inBuffer = in.GetBuffer();
100  CLAM::DataArray & outBuffer = out.GetBuffer();
101  CLAM::DataArray & tmpBuffer = mTmp.GetBuffer();
102  const TSize outSize = out.GetSize();
103  const TSize inSize = in.GetSize();
104 
105 
106  for( int i=0;i<halfSize;i++)
107  {
108  tmpBuffer[i] = tmpBuffer[i+halfSize] + inBuffer[i];
109  }
110 
111  for( int i=halfSize;i<inSize;i++)
112  {
113  tmpBuffer[i] = inBuffer[i];
114  }
115 
116  for( int i=0;i<outSize;i++)
117  {
118  outBuffer[i] = tmpBuffer[i];
119  }
120 
121  return true;
122 }
123 
124 
125 } // namespace CLAM
126