Revision 23:633ec097fa56 Agent.h
| Agent.h | ||
|---|---|---|
| 26 | 26 |
|
| 27 | 27 |
class AgentList; |
| 28 | 28 |
|
| 29 |
class AgentParameters |
|
| 30 |
{
|
|
| 31 |
public: |
|
| 32 |
static const double DEFAULT_POST_MARGIN_FACTOR; |
|
| 33 |
static const double DEFAULT_PRE_MARGIN_FACTOR; |
|
| 34 |
static const double DEFAULT_MAX_CHANGE; |
|
| 35 |
static const double DEFAULT_EXPIRY_TIME; |
|
| 36 |
|
|
| 37 |
AgentParameters() : |
|
| 38 |
postMarginFactor(DEFAULT_POST_MARGIN_FACTOR), |
|
| 39 |
preMarginFactor(DEFAULT_PRE_MARGIN_FACTOR), |
|
| 40 |
maxChange(DEFAULT_MAX_CHANGE), |
|
| 41 |
expiryTime(DEFAULT_EXPIRY_TIME) { }
|
|
| 42 |
|
|
| 43 |
/** The maximum amount by which a beat can be later than the |
|
| 44 |
* predicted beat time, expressed as a fraction of the beat |
|
| 45 |
* period. */ |
|
| 46 |
double postMarginFactor; |
|
| 47 |
|
|
| 48 |
/** The maximum amount by which a beat can be earlier than the |
|
| 49 |
* predicted beat time, expressed as a fraction of the beat |
|
| 50 |
* period. */ |
|
| 51 |
double preMarginFactor; |
|
| 52 |
|
|
| 53 |
/** The maximum allowed deviation from the initial tempo, |
|
| 54 |
* expressed as a fraction of the initial beat period. */ |
|
| 55 |
double maxChange; |
|
| 56 |
|
|
| 57 |
/** The default value of expiryTime, which is the time (in |
|
| 58 |
* seconds) after which an Agent that has no Event matching its |
|
| 59 |
* beat predictions will be destroyed. */ |
|
| 60 |
double expiryTime; |
|
| 61 |
}; |
|
| 62 |
|
|
| 29 | 63 |
/** Agent is the central class for beat tracking. |
| 30 | 64 |
* Each Agent object has a tempo hypothesis, a history of tracked beats, and |
| 31 | 65 |
* a score evaluating the continuity, regularity and salience of its beat track. |
| ... | ... | |
| 33 | 67 |
class Agent |
| 34 | 68 |
{
|
| 35 | 69 |
public: |
| 36 |
/** The maximum amount by which a beat can be later than the predicted beat time, |
|
| 37 |
* expressed as a fraction of the beat period. */ |
|
| 38 |
static double POST_MARGIN_FACTOR; |
|
| 39 |
|
|
| 40 |
/** The maximum amount by which a beat can be earlier than the predicted beat time, |
|
| 41 |
* expressed as a fraction of the beat period. */ |
|
| 42 |
static double PRE_MARGIN_FACTOR; |
|
| 43 |
|
|
| 44 |
/** The default value of innerMargin, which is the maximum time (in seconds) that a |
|
| 45 |
* beat can deviate from the predicted beat time without a fork occurring. */ |
|
| 70 |
/** The default value of innerMargin, which is the maximum time |
|
| 71 |
* (in seconds) that a beat can deviate from the predicted beat |
|
| 72 |
* time without a fork occurring. */ |
|
| 46 | 73 |
static const double INNER_MARGIN; |
| 47 | 74 |
|
| 48 |
/** The maximum allowed deviation from the initial tempo, expressed as a fraction of the initial beat period. */ |
|
| 49 |
static double MAX_CHANGE; |
|
| 50 |
|
|
| 51 |
/** The slope of the penalty function for onsets which do not coincide precisely with predicted beat times. */ |
|
| 52 |
static double CONF_FACTOR; |
|
| 75 |
/** The slope of the penalty function for onsets which do not |
|
| 76 |
* coincide precisely with predicted beat times. */ |
|
| 77 |
static const double CONF_FACTOR; |
|
| 53 | 78 |
|
| 54 |
/** The reactiveness/inertia balance, i.e. degree of change in the tempo, is controlled by the correctionFactor |
|
| 55 |
* variable. This constant defines its default value, which currently is not subsequently changed. The |
|
| 56 |
* beat period is updated by the reciprocal of the correctionFactor multiplied by the difference between the |
|
| 57 |
* predicted beat time and matching onset. */ |
|
| 79 |
/** The reactiveness/inertia balance, i.e. degree of change in the |
|
| 80 |
* tempo, is controlled by the correctionFactor variable. This |
|
| 81 |
* constant defines its default value, which currently is not |
|
| 82 |
* subsequently changed. The beat period is updated by the |
|
| 83 |
* reciprocal of the correctionFactor multiplied by the |
|
| 84 |
* difference between the predicted beat time and matching |
|
| 85 |
* onset. */ |
|
| 58 | 86 |
static const double DEFAULT_CORRECTION_FACTOR; |
| 59 | 87 |
|
| 60 |
/** The default value of expiryTime, which is the time (in seconds) after which an Agent that |
|
| 61 |
* has no Event matching its beat predictions will be destroyed. */ |
|
| 62 |
static const double DEFAULT_EXPIRY_TIME; |
|
| 63 |
|
|
| 64 | 88 |
protected: |
| 65 | 89 |
/** The identity number of the next created Agent */ |
| 66 | 90 |
static int idCounter; |
| 67 | 91 |
|
| 68 |
/** The maximum time (in seconds) that a beat can deviate from the predicted beat time |
|
| 69 |
* without a fork occurring (i.e. a 2nd Agent being created). */ |
|
| 70 |
static double innerMargin; |
|
| 92 |
/** The maximum time (in seconds) that a beat can deviate from the |
|
| 93 |
* predicted beat time without a fork occurring (i.e. a 2nd Agent |
|
| 94 |
* being created). */ |
|
| 95 |
double innerMargin; |
|
| 71 | 96 |
|
| 72 |
/** Controls the reactiveness/inertia balance, i.e. degree of change in the tempo. The |
|
| 73 |
* beat period is updated by the reciprocal of the correctionFactor multiplied by the difference between the |
|
| 74 |
* predicted beat time and matching onset. */ |
|
| 75 |
static double correctionFactor; |
|
| 97 |
/** Controls the reactiveness/inertia balance, i.e. degree of |
|
| 98 |
* change in the tempo. The beat period is updated by the |
|
| 99 |
* reciprocal of the correctionFactor multiplied by the |
|
| 100 |
* difference between the predicted beat time and matching |
|
| 101 |
* onset. */ |
|
| 102 |
double correctionFactor; |
|
| 76 | 103 |
|
| 77 |
/** The time (in seconds) after which an Agent that |
|
| 78 |
* has no Event matching its beat predictions will be destroyed. */
|
|
| 79 |
static double expiryTime;
|
|
| 104 |
/** The time (in seconds) after which an Agent that has no Event
|
|
| 105 |
* matching its beat predictions will be destroyed. */ |
|
| 106 |
double expiryTime; |
|
| 80 | 107 |
|
| 81 |
/** For scoring Agents in a (non-existent) real-time version (otherwise not used). */ |
|
| 82 |
static double decayFactor; |
|
| 108 |
/** For scoring Agents in a (non-existent) real-time version |
|
| 109 |
* (otherwise not used). */ |
|
| 110 |
double decayFactor; |
|
| 83 | 111 |
|
| 84 | 112 |
public: |
| 85 | 113 |
/** The size of the outer half-window before the predicted beat time. */ |
| ... | ... | |
| 94 | 122 |
/** To be used in real-time version?? */ |
| 95 | 123 |
double tempoScore; |
| 96 | 124 |
|
| 97 |
/** Sum of salience values of the Events which have been interpreted |
|
| 98 |
* as beats by this Agent, weighted by their nearness to the predicted beat times. */ |
|
| 125 |
/** Sum of salience values of the Events which have been |
|
| 126 |
* interpreted as beats by this Agent, weighted by their nearness |
|
| 127 |
* to the predicted beat times. */ |
|
| 99 | 128 |
double phaseScore; |
| 100 | 129 |
|
| 101 |
/** How long has this agent been the best? For real-time version; otherwise not used. */ |
|
| 130 |
/** How long has this agent been the best? For real-time version; |
|
| 131 |
* otherwise not used. */ |
|
| 102 | 132 |
double topScoreTime; |
| 103 | 133 |
|
| 104 |
/** The number of beats found by this Agent, including interpolated beats. */ |
|
| 134 |
/** The number of beats found by this Agent, including |
|
| 135 |
* interpolated beats. */ |
|
| 105 | 136 |
int beatCount; |
| 106 | 137 |
|
| 107 |
/** The current tempo hypothesis of the Agent, expressed as the beat period in seconds. */ |
|
| 138 |
/** The current tempo hypothesis of the Agent, expressed as the |
|
| 139 |
* beat period in seconds. */ |
|
| 108 | 140 |
double beatInterval; |
| 109 | 141 |
|
| 110 |
/** The initial tempo hypothesis of the Agent, expressed as the beat period in seconds. */ |
|
| 142 |
/** The initial tempo hypothesis of the Agent, expressed as the |
|
| 143 |
* beat period in seconds. */ |
|
| 111 | 144 |
double initialBeatInterval; |
| 112 | 145 |
|
| 113 | 146 |
/** The time of the most recent beat accepted by this Agent. */ |
| 114 | 147 |
double beatTime; |
| 148 |
|
|
| 149 |
/** The maximum allowed deviation from the initial tempo, |
|
| 150 |
* expressed as a fraction of the initial beat period. */ |
|
| 151 |
double maxChange; |
|
| 115 | 152 |
|
| 116 |
/** The list of Events (onsets) accepted by this Agent as beats, plus interpolated beats. */ |
|
| 153 |
/** The list of Events (onsets) accepted by this Agent as beats, |
|
| 154 |
* plus interpolated beats. */ |
|
| 117 | 155 |
EventList events; |
| 118 | 156 |
|
| 119 | 157 |
/** Constructor: the work is performed by init() |
| 120 | 158 |
* @param ibi The beat period (inter-beat interval) of the Agent's tempo hypothesis. |
| 121 | 159 |
*/ |
| 122 |
Agent(double ibi) {
|
|
| 123 |
innerMargin = INNER_MARGIN; |
|
| 124 |
correctionFactor = DEFAULT_CORRECTION_FACTOR; |
|
| 125 |
expiryTime = DEFAULT_EXPIRY_TIME; |
|
| 126 |
decayFactor = 0; |
|
| 127 |
beatInterval = ibi; |
|
| 128 |
initialBeatInterval = ibi; |
|
| 129 |
postMargin = ibi * POST_MARGIN_FACTOR; |
|
| 130 |
preMargin = ibi * PRE_MARGIN_FACTOR; |
|
| 131 |
idNumber = idCounter++; |
|
| 132 |
phaseScore = 0.0; |
|
| 133 |
tempoScore = 0.0; |
|
| 134 |
topScoreTime = 0.0; |
|
| 135 |
beatCount = 0; |
|
| 136 |
beatTime = -1.0; |
|
| 160 |
Agent(AgentParameters params, double ibi) : |
|
| 161 |
innerMargin(INNER_MARGIN), |
|
| 162 |
correctionFactor(DEFAULT_CORRECTION_FACTOR), |
|
| 163 |
expiryTime(params.expiryTime), |
|
| 164 |
decayFactor(0), |
|
| 165 |
preMargin(ibi * params.preMarginFactor), |
|
| 166 |
postMargin(ibi * params.postMarginFactor), |
|
| 167 |
idNumber(idCounter++), |
|
| 168 |
tempoScore(0.0), |
|
| 169 |
phaseScore(0.0), |
|
| 170 |
topScoreTime(0.0), |
|
| 171 |
beatCount(0), |
|
| 172 |
beatInterval(ibi), |
|
| 173 |
initialBeatInterval(ibi), |
|
| 174 |
beatTime(-1.0), |
|
| 175 |
maxChange(params.maxChange) {
|
|
| 137 | 176 |
} // constructor |
| 138 | 177 |
|
| 139 | 178 |
Agent *clone() const {
|
Also available in: Unified diff