comparison src/Support/StrobeList.h @ 0:582cbe817f2c

- Initial add of support code and modules. Not everything is working yet.
author tomwalters
date Fri, 12 Feb 2010 12:31:23 +0000
parents
children 3c782dec2fc0
comparison
equal deleted inserted replaced
-1:000000000000 0:582cbe817f2c
1 // Copyright 2007-2010, Thomas Walters
2 //
3 // AIM-C: A C++ implementation of the Auditory Image Model
4 // http://www.acousticscale.org/AIMC
5 //
6 // This program is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19 /*!
20 * \file
21 * \brief Modifiable List of Strobe Points - helper for SAI generation
22 *
23 * \author Tom Walters <tcw24@cam.ac.uk>
24 * \date created 2007/08/22
25 * \version \$Id: StrobeList.h 1 2010-02-02 11:04:50Z tcw $
26 */
27
28 #ifndef _AIMC_STROBE_LIST_H_
29 #define _AIMC_STROBE_LIST_H_
30
31 #include <math.h>
32
33 #include "Support/util.h"
34
35 typedef struct StrobePoint {
36 int iTime;
37 float fWeight;
38 float fWorkingWeight;
39 StrobePoint() {
40 iTime=0;
41 fWeight=0.0f;
42 fWorkingWeight=0.0f;
43 }
44 };
45
46 class StrobeList;
47 /*!
48 * \class Signal "Support/StrobeList.h"
49 * \brief Modifiable List of Strobe Points, which must be ordered
50 *
51 */
52 class StrobeList {
53 public:
54 /*! \brief Create a new strobe list
55 */
56 inline StrobeList() {
57 m_iStrobeCount = 0;
58 m_iMaxStrobes=0;
59 m_iOffset=0;
60 m_pStrobes = NULL;
61 };
62
63 inline void Create(unsigned int iMaxStrobes) {
64 m_iMaxStrobes = iMaxStrobes;
65 m_pStrobes = new StrobePoint[m_iMaxStrobes+1];
66 }
67
68 inline ~StrobeList() {
69 if (m_pStrobes != NULL)
70 delete [] m_pStrobes;
71 };
72
73 //! \brief Return the strobe time (in samples, can be negative)
74 inline unsigned int getTime(unsigned int iStrobeNumber) {
75 return m_pStrobes[GetBufferNumber(iStrobeNumber)].iTime;
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 };
87
88 //! \brief Set the strobe weight
89 inline void setWeight(unsigned int iStrobeNumber, float fWeight) {
90 m_pStrobes[GetBufferNumber(iStrobeNumber)].fWeight = fWeight;
91 };
92
93 //! \brief Set the strobe's working weight
94 inline void setWorkingWeight(unsigned int iStrobeNumber,
95 float fWorkingWeight) {
96 m_pStrobes[GetBufferNumber(iStrobeNumber)].fWorkingWeight = fWorkingWeight;
97 };
98
99 //! \brief Add a strobe to the list (must be in order)
100 inline void addStrobe(int iTime, float fWeight) {
101 if (m_iStrobeCount + 1 <= m_iMaxStrobes) {
102 m_iStrobeCount++;
103 m_pStrobes[GetBufferNumber(m_iStrobeCount)].iTime=iTime;
104 m_pStrobes[GetBufferNumber(m_iStrobeCount)].fWeight=fWeight;
105 }
106 };
107
108 //! \brief Delete a strobe from the list
109 inline void deleteFirstStrobe() {
110 if (m_iStrobeCount > 0) {
111 m_iOffset = (m_iOffset+1) % m_iMaxStrobes;
112 m_iStrobeCount--;
113 }
114 };
115
116 //! \brief Get the number of strobes
117 inline unsigned int getStrobeCount() {
118 return m_iStrobeCount;
119 };
120
121 //! \brief Shift the position of all strobes by subtracting iOffset from
122 //! the time value of each
123 inline void shiftStrobes(unsigned int iOffset) {
124 for (unsigned int i=1; i<m_iStrobeCount+1; i++)
125 m_pStrobes[GetBufferNumber(i)].iTime-=iOffset;
126 };
127
128 protected:
129
130 private:
131 unsigned int m_iStrobeCount;
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 };
141
142 #endif /* _AIMC_STROBE_LIST_H_ */
143