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