[CLAM] newbie

Hernán Ordiales h at ordia.com.ar
Sat Apr 19 07:47:48 PDT 2008


On Thu, Apr 17, 2008 at 2:02 PM, Agustin Cortés <agucortes at gmail.com> wrote:
> I've read the tutorial, and i have one question...
>  ----------------------------
>  #ifndef MyProcessing_hxx
>  #define MyProcessing_hxx
>
>  #include <CLAM/InPort.hxx>
>  #include <CLAM/OutPort.hxx>
>  #include <CLAM/Processing.hxx>
>
>  // Those two configuration types could be the ones you choose.
>  // Your own ones or any type already in CLAM.
>  #include "MyInputDataType.hxx"
>  #include "MyOutputDataType.hxx"
>
>  class MyProcessing : public CLAM::Processing
>  {
>         CLAM::InPort<MyInputDataType> mIn;
>         CLAM::OutPort<MyOutputDataType> mOut;
>  public:
>         const char* GetClassName() const { return "MyProcessing"; }
>         MyProcessing(const Config& config = Config())
>                 : mIn("My Input", this)
>                 , mOut("My Output", this)
>         {
>                 Configure( config );
>         }
>
>         bool Do()
>         {
>                 bool result = Do(mIn.GetData(), mOut.GetData());
>                 // Tell the ports this is done
>                 mIn.Consume();
>                 mOut.Produce();
>                 return result;
>         }
>
>         bool Do(const MyInputDataType& in, MyOutputDataType& out)
>         {
>                 // Your implementation
>         }
>  ------------------
>  What kind of Type of Data is "MyInputDataType", i mean, what i read
>  from the audio from a mic, what kind of data is? is Audio? How do i
>  analyze data from that class?
>  Thanks..
>  Agustin

Hi Agustín! (btw, remember to answer to clam at iua.upf.edu not private mails[1])

could be many things, audio, fundamental, peaks, depends on your incontrol types

for audio things take a look at the simple AudioAmplifier processing
(CLAM/src/Processing/ArithOps/AudioAmplifier.hxx)

		/** Ports **/
		AudioInPort mInputAudio;
		AudioOutPort mOutputAudio;
...
		bool Do(const Audio& in, Audio& out)
		{
			int size = in.GetSize();

			TData gain = mInputControl.GetLastValue();

			TData* inb = in.GetBuffer().GetPtr();
			TData* outb = out.GetBuffer().GetPtr();

			for (int i=0;i<size;i++)
			{
				*outb++ = (*inb++)*gain;
			}

			return true;
		}

if you dislike pointers this also works:
		bool Do(const Audio& in, Audio& out)
		{
			int size = in.GetSize();

			TData gain = mInputControl.GetLastValue();

			DataArray& inb = in.GetBuffer();
			DataArray& outb = out.GetBuffer();

			for (int i=0;i<size;i++)
			{
				outb[i] = inb[i]*gain;
			}

			return true;
		}

cheers

[1] Pau or whoever who is the list admin, i think a 'reply-to' to the
list config like we have in clam-devel would be also useful here...
-- 
Hernán
http://h.ordia.com.ar
GnuPG: 0xEE8A3FE9




More information about the clam-users mailing list