[Clam-devel] TokenDelay patch

Pau Arumi parumi at iua.upf.edu
Fri Apr 20 10:51:05 PDT 2007


This can't break anything, ho ahead, commit it. We can improve it 
later. Like leaving only one representation and get rid of
#ifdefs

However, I don't see what operations are more efficient using a
vector. Can you explain?
As I see it, when you copy, say, an spectrum its buffers are
copied in both cases.

pau

En/na Xavier Amatriain ha escrit:
> Find attached patch for TokenDelay, improving general design and
> efficiency. As of now the optimizations are only implemented as an
> extension when CLAM_OPTIMIZE is defined but I really see no reason to
> keep the queue implementation.
> 
> Also I did some tests implementing specialized functions for basic types
> but found no real improvements so this version is general-purpose
> enough.
> 
> 
> 
> 
> ------------------------------------------------------------------------
> 
> Index: TokenDelay.hxx
> ===================================================================
> --- TokenDelay.hxx	(revision 10015)
> +++ TokenDelay.hxx	(working copy)
> @@ -35,6 +35,8 @@
>  
>  using std::string;
>  
> +#include "Array.hxx"
> +
>  namespace CLAM  
>  {
>  
> @@ -174,11 +176,17 @@
>  	 * delay.
>  	 */
>  	void UpdateBuffersToDelay();
> -
> -
> +	void WriteNewSample(const T& in);
> +	void ReadCurrentSample(T& out);
> +	
>  // Implementation Details:
> -
> +#ifdef CLAM_OPTIMIZE
> +	std::vector<T> mTokenQueue;
> +	unsigned mReadPointer;
> +	unsigned mWritePointer;
> +#else
>  	std::deque<T> mTokenQueue;
> +#endif
>  	/** The maximun number of elements in the queue. */
>  	unsigned mCapacity;
>  	/** The control value read on the last started Do */
> @@ -209,6 +217,11 @@
>  	mCapacity = mConfig.GetMaxDelay();
>  	mDelayControl.DoControl(TControlData(mConfig.GetDelay()));
>  	mGivenDelay = CastDelayControlValue(mDelayControl.GetLastValue());
> +#ifdef CLAM_OPTIMIZE	
> +	mTokenQueue.resize(mCapacity);
> +	mWritePointer = 0;
> +	mReadPointer = -mGivenDelay;
> +#endif
>  	return true;
>  }
>  
> @@ -237,25 +250,56 @@
>  	// If the value is different make the difference efective
>  	if (mLastDelay != mGivenDelay)
>  		UpdateBuffersToDelay();
> -	
> +	WriteNewSample(in);
> +	ReadCurrentSample(out);
> +	return true;
> +
> +}
> +
> +template <class T> 
> +void TokenDelay<T>::WriteNewSample(const T& in)
> +{
> +#ifdef CLAM_OPTIMIZE
> +	mTokenQueue[mWritePointer] = in;
> +	mWritePointer++;
> +	if(mWritePointer==mCapacity) mWritePointer=0;
> +#else
>  	mTokenQueue.push_back(in);
> -	out=mTokenQueue.front();
> +#endif
> +
> +}
> +
> +
> +template <class T>
> +void TokenDelay<T>::ReadCurrentSample(T& out)
> +{
> +#ifdef CLAM_OPTIMIZE
> +	CLAM_DEBUG_ASSERT(mReadPointer>0, "Trying to read outside buffer");
> +	int oldReadPointer = mReadPointer;
> +	mReadPointer++;
> +	if(mReadPointer==mCapacity) mReadPointer=0;
> +	out = mTokenQueue[oldReadPointer];
> +#else
> +	out = mTokenQueue.front();
>  	if (mTokenQueue.size()>mGivenDelay)
>  		mTokenQueue.pop_front();
> -	return true;
> -
> +#endif
>  }
>  
>  
> +
>  // Delay change
>  template <class T> 
>  void TokenDelay<T>::UpdateBuffersToDelay()
>  {
> +#ifdef CLAM_OPTIMIZE
> +	mWritePointer =  mReadPointer + CastDelayControlValue(mGivenDelay);
> +	if(mWritePointer>=mCapacity) mWritePointer-=mCapacity;
> +#else
>  	while (mTokenQueue.size()>mGivenDelay) {
> -		//T* toDelete=mTokenQueue.front();
>  		mTokenQueue.pop_front();
> -		//this->Discard(toDelete);
>  	}
> +#endif
>  	return;
>  }
>  
> @@ -326,4 +370,3 @@
>  
>  
>  #endif //_TokenDelay_
> -
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Clam-devel mailing list
> Clam-devel at llistes.projectes.lafarga.org
> https://llistes.projectes.lafarga.org/cgi-bin/mailman/listinfo/clam-devel





More information about the clam-devel mailing list