BinaryAudioOp.hxx
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 #ifndef _BINARY_AUDIO_OP_H_
00023 #define _BINARY_AUDIO_OP_H_
00024
00025 #include "Processing.hxx"
00026 #include "DynamicType.hxx"
00027 #include "Audio.hxx"
00028 #include <typeinfo>
00029 #include "AudioInPort.hxx"
00030 #include "AudioOutPort.hxx"
00031
00032 #include <iostream>
00033
00034 namespace CLAM
00035 {
00036
00037 class BinaryAudioOpConfig: public ProcessingConfig
00038 {
00039 public:
00040 DYNAMIC_TYPE_USING_INTERFACE (BinaryAudioOpConfig, 0, ProcessingConfig);
00041 };
00042
00043 template < typename BinOp >
00044 class BinaryAudioOp
00045 : public Processing
00046 {
00047 BinaryAudioOpConfig mConfig;
00048 BinOp mOperation;
00049
00053 bool ConcreteConfigure(const ProcessingConfig& c)
00054 {
00055 try {
00056 mConfig = dynamic_cast<const BinaryAudioOpConfig&>(c);
00057 }
00058 catch (std::bad_cast)
00059 {
00060 CLAM_ASSERT(false,"Config should be a BynariaAudioOpConfig");
00061 }
00062 return true;
00063
00064 }
00065
00066 AudioInPort mFirstInput;
00067 AudioInPort mSecondInput;
00068 AudioOutPort mOutput;
00069
00070
00071 public:
00072
00073 BinaryAudioOp()
00074 :mFirstInput("First Audio Input",this),
00075 mSecondInput("Second Audio Input",this),
00076 mOutput("Audio Output",this)
00077 {
00078 Configure( BinaryAudioOpConfig() );
00079 }
00080
00081 BinaryAudioOp(const BinaryAudioOpConfig &c)
00082 :mFirstInput("First Audio Input",this),
00083 mSecondInput("Second Audio Input",this),
00084 mOutput("Audio Output",this)
00085
00086 {
00087 Configure( c );
00088 }
00089
00090 ~BinaryAudioOp()
00091 {
00092 }
00093
00094 const ProcessingConfig &GetConfig() const { return mConfig;}
00095
00096 const char *GetClassName() const {return "BinaryAudioOperation";}
00097 void Check(const Audio& in1, const Audio& in2, const Audio& out)
00098 {
00099 CLAM_ASSERT(in1.GetSize() <= in2.GetSize(),
00100 "BinaryAudioOperation::Do(): Incompatible Input Audio Data Sizes");
00101 CLAM_ASSERT(in1.GetSize() <= out.GetSize(),
00102 "BinaryAudioOperation::Do(): Incompatible Output Audio Data Size");
00103
00104 }
00105
00106 bool Do(void)
00107 {
00108 bool res = Do(mFirstInput.GetAudio(),
00109 mSecondInput.GetAudio(),
00110 mOutput.GetAudio());
00111 mFirstInput.Consume();
00112 mSecondInput.Consume();
00113 mOutput.Produce();
00114 return res;
00115 }
00116
00117 bool Do(const Audio& in1, const Audio& in2, Audio& out)
00118 {
00119
00120
00121 int size = in1.GetSize();
00122 int i;
00123
00124 Check(in1,in2,out);
00125
00126 TData* inb1 = in1.GetBuffer().GetPtr();
00127 TData* inb2 = in2.GetBuffer().GetPtr();
00128 TData* outb = out.GetBuffer().GetPtr();
00129
00130 for (i=0;i<size;i++)
00131 {
00132 *outb++ = mOperation( *inb1++ , *inb2++ );
00133 }
00134
00135 return true;
00136 }
00137
00138
00139
00140 bool SetPrototypes(const Audio& in1, const Audio& in2, const Audio& out)
00141 {
00142 return false;
00143 }
00144
00145 bool SetPrototypes()
00146 {
00147 return false;
00148 }
00149
00150 bool UnsetPrototypes()
00151 {
00152 return true;
00153 }
00154
00155 bool MayDisableExecution() const {return true;}
00156
00157 private:
00158 };
00159
00160 }
00161
00162 #endif // _BINARY_AUDIO_OP_H_
00163