comparison src/Support/StrobeList.h @ 5:3c782dec2fc0

- Ported over HTK file output - Added some more meat to the Slaney IIR gammatone implementation - Ported over the AIM-MAT sf2003 parabola strobe algorithm - Finished making the SAI implementation compile - Ported over the strobe list class (now uses STL deques internally)
author tomwalters
date Thu, 18 Feb 2010 16:55:40 +0000
parents 582cbe817f2c
children fcbf85ce59fb
comparison
equal deleted inserted replaced
4:eb0449575bb9 5:3c782dec2fc0
23 * \author Tom Walters <tcw24@cam.ac.uk> 23 * \author Tom Walters <tcw24@cam.ac.uk>
24 * \date created 2007/08/22 24 * \date created 2007/08/22
25 * \version \$Id: StrobeList.h 1 2010-02-02 11:04:50Z tcw $ 25 * \version \$Id: StrobeList.h 1 2010-02-02 11:04:50Z tcw $
26 */ 26 */
27 27
28 #ifndef _AIMC_STROBE_LIST_H_ 28 #ifndef _AIMC_SUPPORT_STROBE_LIST_H_
29 #define _AIMC_STROBE_LIST_H_ 29 #define _AIMC_SUPPORT_STROBE_LIST_H_
30 30
31 #include <deque>
31 #include <math.h> 32 #include <math.h>
32 33
33 #include "Support/util.h" 34 namespace aimc {
34 35 using std::deque;
35 typedef struct StrobePoint { 36 struct StrobePoint {
36 int iTime; 37 int time;
37 float fWeight; 38 float weight;
38 float fWorkingWeight; 39 float working_weight;
39 StrobePoint() { 40 StrobePoint() {
40 iTime=0; 41 time = 0;
41 fWeight=0.0f; 42 weight = 0.0f;
42 fWorkingWeight=0.0f; 43 working_weight = 0.0f;
43 } 44 }
44 }; 45 };
45 46
46 class StrobeList;
47 /*! 47 /*!
48 * \class Signal "Support/StrobeList.h" 48 * \class Signal "Support/StrobeList.h"
49 * \brief Modifiable List of Strobe Points, which must be ordered 49 * \brief Modifiable List of Strobe Points, which must be ordered
50 * 50 *
51 */ 51 */
52 class StrobeList { 52 class StrobeList {
53 public: 53 public:
54 /*! \brief Create a new strobe list 54 /*! \brief Create a new strobe list
55 */ 55 */
56 inline StrobeList() { 56 inline StrobeList() {
57 m_iStrobeCount = 0; 57 strobes_.resize(0);
58 m_iMaxStrobes=0;
59 m_iOffset=0;
60 m_pStrobes = NULL;
61 }; 58 };
62 59
63 inline void Create(unsigned int iMaxStrobes) {
64 m_iMaxStrobes = iMaxStrobes;
65 m_pStrobes = new StrobePoint[m_iMaxStrobes+1];
66 }
67
68 inline ~StrobeList() { 60 inline ~StrobeList() {
69 if (m_pStrobes != NULL)
70 delete [] m_pStrobes;
71 }; 61 };
72 62
73 //! \brief Return the strobe time (in samples, can be negative) 63 //! \brief Return the strobe time (in samples, can be negative)
74 inline unsigned int getTime(unsigned int iStrobeNumber) { 64 inline StrobePoint Strobe(int strobe_number) {
75 return m_pStrobes[GetBufferNumber(iStrobeNumber)].iTime; 65 return strobes_.at(strobe_number);
76 };
77
78 //! \brief Return the strobe weight
79 inline float getWeight(unsigned int iStrobeNumber) {
80 return m_pStrobes[GetBufferNumber(iStrobeNumber)].fWeight;
81 };
82
83 //! \brief Return the strobe's working weight
84 inline float getWorkingWeight(unsigned int iStrobeNumber) {
85 return m_pStrobes[GetBufferNumber(iStrobeNumber)].fWorkingWeight;
86 }; 66 };
87 67
88 //! \brief Set the strobe weight 68 //! \brief Set the strobe weight
89 inline void setWeight(unsigned int iStrobeNumber, float fWeight) { 69 inline void SetWeight(int strobe_number, float weight) {
90 m_pStrobes[GetBufferNumber(iStrobeNumber)].fWeight = fWeight; 70 strobes_.at(strobe_number).weight = weight;
91 }; 71 };
92 72
93 //! \brief Set the strobe's working weight 73 //! \brief Set the strobe's working weight
94 inline void setWorkingWeight(unsigned int iStrobeNumber, 74 inline void SetWorkingWeight(int strobe_number, float working_weight) {
95 float fWorkingWeight) { 75 strobes_.at(strobe_number).working_weight = working_weight;
96 m_pStrobes[GetBufferNumber(iStrobeNumber)].fWorkingWeight = fWorkingWeight;
97 }; 76 };
98 77
99 //! \brief Add a strobe to the list (must be in order) 78 //! \brief Add a strobe to the list (must be in order)
100 inline void addStrobe(int iTime, float fWeight) { 79 inline void AddStrobe(int time, float weight) {
101 if (m_iStrobeCount + 1 <= m_iMaxStrobes) { 80 StrobePoint s;
102 m_iStrobeCount++; 81 s.time = time;
103 m_pStrobes[GetBufferNumber(m_iStrobeCount)].iTime=iTime; 82 s.weight = weight;
104 m_pStrobes[GetBufferNumber(m_iStrobeCount)].fWeight=fWeight; 83 strobes_.push_back(s);
105 }
106 }; 84 };
107 85
108 //! \brief Delete a strobe from the list 86 //! \brief Delete a strobe from the list
109 inline void deleteFirstStrobe() { 87 inline void DeleteFirstStrobe() {
110 if (m_iStrobeCount > 0) { 88 strobes_.pop_front();
111 m_iOffset = (m_iOffset+1) % m_iMaxStrobes;
112 m_iStrobeCount--;
113 }
114 }; 89 };
115 90
116 //! \brief Get the number of strobes 91 //! \brief Get the number of strobes
117 inline unsigned int getStrobeCount() { 92 inline int strobe_count() const {
118 return m_iStrobeCount; 93 return strobes_.size();
119 }; 94 };
120 95
121 //! \brief Shift the position of all strobes by subtracting iOffset from 96 //! \brief Shift the position of all strobes by subtracting offset from
122 //! the time value of each 97 //! the time value of each
123 inline void shiftStrobes(unsigned int iOffset) { 98 inline void ShiftStrobes(int offset) {
124 for (unsigned int i=1; i<m_iStrobeCount+1; i++) 99 for (unsigned int i = 0; i < strobes_.size(); ++i)
125 m_pStrobes[GetBufferNumber(i)].iTime-=iOffset; 100 strobes_[i].time -= offset;
126 }; 101 };
127 102
128 protected:
129
130 private: 103 private:
131 unsigned int m_iStrobeCount; 104 deque<StrobePoint> strobes_;
132 unsigned int m_iMaxStrobes;
133 unsigned int m_iOffset;
134 StrobePoint* m_pStrobes;
135
136 inline unsigned int GetBufferNumber(unsigned int iStrobeIndex) {
137 aimASSERT(((iStrobeIndex-1+m_iOffset) % m_iMaxStrobes)<m_iMaxStrobes);
138 return ((iStrobeIndex-1+m_iOffset) % m_iMaxStrobes) ;
139 };
140 }; 105 };
106 } // namespace aimc
141 107
142 #endif /* _AIMC_STROBE_LIST_H_ */ 108 #endif /* _AIMC_STROBE_LIST_H_ */
143 109