CircularShift.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 "Audio.hxx"
00023 #include "Spectrum.hxx"
00024 #include "Complex.hxx"
00025 #include "CircularShift.hxx"
00026
00027 namespace CLAM {
00028
00029
00030
00031 CircularShift::CircularShift()
00032 : mInput( "Input samples", this ),
00033 mOutput( "Shifted samples", this ),
00034 mSteps( "Shift Steps", this )
00035 {
00036 Configure(CircularShiftConfig());
00037 }
00038
00039 CircularShift::CircularShift(const CircularShiftConfig &c)
00040 : mInput( "Input samples", this ),
00041 mOutput( "Shifted samples", this ),
00042 mSteps("Shift Steps",this)
00043 {
00044 Configure(c);
00045 }
00046
00047 CircularShift::~CircularShift()
00048 {}
00049
00050
00051
00052
00053 bool CircularShift::ConcreteConfigure(const ProcessingConfig& c)
00054 {
00055 CopyAsConcreteConfig(mConfig, c);
00056 mSteps.DoControl(TData(mConfig.GetAmount()));
00057
00058 return true;
00059 }
00060
00061
00062
00063 bool CircularShift::SetPrototypes(Spectrum& inputs,const Spectrum& out)
00064 {
00065 return false;
00066 }
00067
00068 bool CircularShift::SetPrototypes()
00069 {
00070 return false;
00071 }
00072
00073 bool CircularShift::UnsetPrototypes()
00074 {
00075 return false;
00076 }
00077
00078
00079
00080 bool CircularShift::Do(void)
00081 {
00082 return Do( mInput.GetAudio(), mOutput.GetAudio() );
00083 mInput.Consume();
00084 mOutput.Produce();
00085
00086 }
00087
00088
00089
00090 bool CircularShift::Do( const DataArray& in, DataArray& out)
00091 {
00092
00093 int i;
00094 TData amount = mSteps.GetLastValue();
00095 int size = in.Size();
00096 const TData* inp = in.GetPtr();
00097 TData* outp = out.GetPtr();
00098 TData* tmp;
00099
00100 CLAM_ASSERT(size == out.Size(),
00101 "CircularShift::Do(): input and output vectors do not match");
00102
00103 if (amount > 0) {
00104 int ia = (int)amount;
00105 tmp = new TData[ia];
00106 for (i=0;i<ia;i++)
00107 tmp[i] = inp[size - ia + i];
00108 for (i=size-ia-1;i>= 0;i--)
00109 outp[i + ia] = inp[i];
00110 for (i=0;i< ia;i++)
00111 outp[i] = tmp[i];
00112 }
00113 else {
00114 int ia = (int)-amount;
00115 tmp = new TData[ia];
00116 for (i=0;i<ia;i++)
00117 tmp[i] = inp[i];
00118 for (i=0;i< (size - ia);i++)
00119 outp[i] = inp[i+ia];
00120 for (i=0;i< ia;i++)
00121 outp[i+size-ia] = tmp[i];
00122 }
00123 delete[] tmp;
00124 return true;
00125 }
00126
00127 bool CircularShift::Do(Spectrum& in, Spectrum& out)
00128 {
00129 CLAM_ASSERT(!in.HasMagBuffer(),
00130 "CircularShift::Do(): only implemented for Spectrums with MagBuffer");
00131
00132 return Do(in.GetMagBuffer(),out.GetMagBuffer());
00133 }
00134
00135 bool CircularShift::Do( const Audio& in, Audio& out)
00136 {
00137 Do(in.GetBuffer(),out.GetBuffer());
00138 return true;
00139 }
00140
00141
00142 }
00143