OverlapAdd.cxx
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "OverlapAdd.hxx"
00023 #include "ProcessingFactory.hxx"
00024
00025 namespace CLAM
00026 {
00027
00028 namespace Hidden
00029 {
00030 static const char * metadata[] = {
00031 "key", "OverlapAdd",
00032 "category", "Synthesis",
00033 "description", "OverlapAdd",
00034 0
00035 };
00036 static FactoryRegistrator<ProcessingFactory, OverlapAdd> reg = metadata;
00037 }
00038
00039
00040
00041 OverlapAdd::OverlapAdd(const OverlapAddConfig &c)
00042 : mInput( "Audio Input", this ),
00043 mOutput( "Audio Output", this )
00044 {
00045 Configure(c);
00046 }
00047
00048 OverlapAdd::~OverlapAdd()
00049 {
00050 }
00051
00052
00053
00054
00055 bool OverlapAdd::ConcreteConfigure(const ProcessingConfig& c)
00056 {
00057 CopyAsConcreteConfig(mConfig, c);
00058
00059
00060 int frameSize=mConfig.GetFrameSize();
00061
00062 mInput.SetSize( frameSize*2 );
00063 mInput.SetHop( frameSize*2 );
00064
00065 mOutput.SetSize( frameSize );
00066 mOutput.SetHop( frameSize );
00067
00068 mTmp.SetSize( frameSize*2 +1 );
00069
00070 for(int i=0;i<mTmp.GetSize();i++)
00071 mTmp.GetBuffer()[i]=0.0f;
00072
00073 return true;
00074 }
00075
00076
00077
00078 bool OverlapAdd::Do(void)
00079 {
00080 bool result = Do( mInput.GetAudio(), mOutput.GetAudio() );
00081 mInput.Consume();
00082 mOutput.Produce();
00083 return result;
00084 }
00085
00086 bool OverlapAdd::Do( const Audio &in, Audio & out)
00087 {
00088
00089
00090
00091
00092
00093
00094
00095 int halfSize = in.GetSize()/2;
00096 CLAM_DEBUG_ASSERT( out.GetSize() == halfSize, "OverlapAdd::Do - Audio Out size must be half the input size" );
00097 CLAM_DEBUG_ASSERT( mConfig.GetFrameSize() == halfSize, "OverlapAdd::Do - Config FrameSize must be half the input size" );
00098
00099 CLAM::DataArray & inBuffer = in.GetBuffer();
00100 CLAM::DataArray & outBuffer = out.GetBuffer();
00101 CLAM::DataArray & tmpBuffer = mTmp.GetBuffer();
00102 const TSize outSize = out.GetSize();
00103 const TSize inSize = in.GetSize();
00104
00105
00106 for( int i=0;i<halfSize;i++)
00107 {
00108 tmpBuffer[i] = tmpBuffer[i+halfSize] + inBuffer[i];
00109 }
00110
00111 for( int i=halfSize;i<inSize;i++)
00112 {
00113 tmpBuffer[i] = inBuffer[i];
00114 }
00115
00116 for( int i=0;i<outSize;i++)
00117 {
00118 outBuffer[i] = tmpBuffer[i];
00119 }
00120
00121 return true;
00122 }
00123
00124
00125 }
00126