annotate trunk/src/Support/StrobeList.h @ 268:e14c70d1b171

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