AnimatLab  2
Test
DelayLine.cpp
Go to the documentation of this file.
1 
7 #include "StdAfx.h"
8 #include "IMovableItemCallback.h"
9 #include "ISimGUICallback.h"
10 #include "AnimatBase.h"
11 
12 #include "DelayLine.h"
13 
14 namespace AnimatSim
15 {
16 
24 {
25  m_iDelaySize=0;
26  m_iDelayComp=0;
27  m_iSaveIdx=0;
28  m_iReadIdx=0;
29 }
30 
38 {
39 
40 try
41 {
42  m_aryRingBuf.RemoveAll();
43 }
44 catch(...)
45 {Std_TraceMsg(0, "Caught Error in desctructor of DelayLine\r\n", "", -1, false, true);}
46 }
47 
57 void DelayLine::Initialize(float fltDelayTime, float fltTimeStep)
58 {
59  m_iDelaySize = fltDelayTime/fltTimeStep;
60 
61  if(m_iDelaySize <= 0)
62  m_iDelaySize = 1;
63 
65 
66  m_aryRingBuf.SetSize(m_iDelaySize);
67  for(int iIdx=0; iIdx<m_iDelaySize; iIdx++)
68  m_aryRingBuf[iIdx] = 0;
69 
70  m_iSaveIdx = 0;
72 }
73 
84 void DelayLine::AddValue(float fltVal)
85 {
86  m_aryRingBuf[m_iSaveIdx] = fltVal;
87 
89  m_iSaveIdx=0;
90  else
91  m_iSaveIdx++;
92 
94  m_iReadIdx=0;
95  else
96  m_iReadIdx++;
97 }
98 
108 {return m_aryRingBuf[m_iReadIdx];}
109 
110 } //AnimatSim
DelayLine()
Default constructor.
Definition: DelayLine.cpp:23
Base class file for all Animat simulation objects.
Root namespace for the base simulation library for AnimatLab.
CStdArray< float > m_aryRingBuf
Ring buffer of float values.
Definition: DelayLine.h:26
void AddValue(float fltVal)
Adds a value to the begining of the line.
Definition: DelayLine.cpp:84
int m_iDelayComp
Size of the ring buffer-1.
Definition: DelayLine.h:32
Declares the delay line class.
int m_iSaveIdx
The index where the next new value will be saved in the ring.
Definition: DelayLine.h:35
void Initialize(float fltDelayTime, float fltTimeStep)
Initializes the Delay line.
Definition: DelayLine.cpp:57
float ReadValue()
Reads the current value at the end of the delay line.
Definition: DelayLine.cpp:107
void Std_TraceMsg(const int iLevel, std::string strMessage, std::string strSourceFile, int iSourceLine, bool bLogToFile, bool bPrintHeader)
Traces a message to the debugger window.
virtual ~DelayLine()
Destructor.
Definition: DelayLine.cpp:37
int m_iReadIdx
The index where we read the current top value off the ring.
Definition: DelayLine.h:38
int m_iDelaySize
Size of the ring buffer.
Definition: DelayLine.h:29