90 mOutput (
"Out", this),
91 mDelayControl(
"Delay Control", this),
113 virtual bool Do(
void);
124 virtual bool Do(
const T & in, T& out);
142 return mTokenQueue.size();
151 return CastDelayControlValue(mDelayControl.
GetLastValue());
160 virtual void Discard(T* toDiscard);
165 unsigned CastDelayControlValue(
TControlData readControlValue);
170 void UpdateBuffersToDelay();
171 void WriteNewSample(
const T& in);
172 void ReadCurrentSample(T& out);
176 std::vector<T> mTokenQueue;
177 unsigned mReadPointer;
178 unsigned mWritePointer;
182 unsigned mGivenDelay;
197 void TokenDelay<T>::Discard(T* toDiscard) {
198 CLAM_ASSERT(toDiscard,
"TokenDelay: Discarding a null pointer");
205 CopyAsConcreteConfig(mConfig, c);
207 mCapacity = mConfig.GetMaxDelay();
208 mDelayControl.DoControl(
TControlData(mConfig.GetDelay()));
209 mGivenDelay = CastDelayControlValue(mDelayControl.GetLastValue());
210 mTokenQueue.resize(mCapacity);
212 mReadPointer = -mGivenDelay;
220 Do(mInput.GetData(), mOutput.GetData());
228 if (readControlValue > mCapacity)
return mCapacity;
229 if (readControlValue < 0)
return 0;
238 mLastDelay = mGivenDelay;
239 mGivenDelay = CastDelayControlValue(mDelayControl.GetLastValue());
241 if (mLastDelay != mGivenDelay)
242 UpdateBuffersToDelay();
244 ReadCurrentSample(out);
251 mTokenQueue[mWritePointer++] = in;
252 if(mWritePointer==mCapacity) mWritePointer=0;
258 void TokenDelay<T>::ReadCurrentSample(T& out)
261 out = mTokenQueue[mReadPointer++];
262 if(mReadPointer==mCapacity) mReadPointer=0;
269 void TokenDelay<T>::UpdateBuffersToDelay()
271 mWritePointer = mReadPointer + CastDelayControlValue(mGivenDelay);
272 if(mWritePointer>=mCapacity) mWritePointer-=mCapacity;
310 #endif //_TokenDelay_