Revision 22:6afcb5edd7ab
| Agent.h | ||
|---|---|---|
| 182 | 182 |
*/ |
| 183 | 183 |
void fillBeats(double start); |
| 184 | 184 |
|
| 185 |
// for sorting AgentList |
|
| 186 |
bool operator<(const Agent &a) const {
|
|
| 187 |
return beatInterval < a.beatInterval; |
|
| 188 |
} |
|
| 189 |
|
|
| 190 | 185 |
}; // class Agent |
| 191 | 186 |
|
| 192 | 187 |
#endif |
| AgentList.cpp | ||
|---|---|---|
| 23 | 23 |
{
|
| 24 | 24 |
sort(); |
| 25 | 25 |
for (iterator itr = begin(); itr != end(); ++itr) {
|
| 26 |
#ifdef DEBUG_BEATROOT |
|
| 27 |
std::cerr << "removeDuplicates: considering agent " << (*itr)->idNumber << std::endl; |
|
| 28 |
#endif |
|
| 26 | 29 |
if ((*itr)->phaseScore < 0.0) // already flagged for deletion |
| 27 | 30 |
continue; |
| 28 | 31 |
iterator itr2 = itr; |
| ... | ... | |
| 32 | 35 |
if (fabs((*itr)->beatTime - (*itr2)->beatTime) > DEFAULT_BT) |
| 33 | 36 |
continue; |
| 34 | 37 |
if ((*itr)->phaseScore < (*itr2)->phaseScore) {
|
| 38 |
#ifdef DEBUG_BEATROOT |
|
| 39 |
std::cerr << "agent " << (*itr)->idNumber << " is similar to but lower-scoring than agent " << (*itr2)->idNumber << ", marking for deletion" << std::endl; |
|
| 40 |
#endif |
|
| 35 | 41 |
(*itr)->phaseScore = -1.0; // flag for deletion |
| 36 | 42 |
if ((*itr2)->topScoreTime < (*itr)->topScoreTime) |
| 37 | 43 |
(*itr2)->topScoreTime = (*itr)->topScoreTime; |
| 38 | 44 |
break; |
| 39 | 45 |
} else {
|
| 46 |
#ifdef DEBUG_BEATROOT |
|
| 47 |
std::cerr << "agent " << (*itr2)->idNumber << " is similar to but lower-scoring than agent " << (*itr)->idNumber << ", marking for deletion" << std::endl; |
|
| 48 |
#endif |
|
| 40 | 49 |
(*itr2)->phaseScore = -1.0; // flag for deletion |
| 41 | 50 |
if ((*itr)->topScoreTime < (*itr2)->topScoreTime) |
| 42 | 51 |
(*itr)->topScoreTime = (*itr2)->topScoreTime; |
| ... | ... | |
| 115 | 124 |
Agent *bestAg = 0; |
| 116 | 125 |
for (iterator itr = begin(); itr != end(); ++itr) {
|
| 117 | 126 |
if ((*itr)->events.empty()) continue; |
| 118 |
double startTime = (*itr)->events.begin()->time; |
|
| 119 | 127 |
double conf = ((*itr)->phaseScore + (*itr)->tempoScore) / |
| 120 | 128 |
(useAverageSalience? (double)(*itr)->beatCount: 1.0); |
| 121 | 129 |
if (conf > best) {
|
| BeatRootProcessor.cpp | ||
|---|---|---|
| 49 | 49 |
vector<int>::iterator it = peaks.begin(); |
| 50 | 50 |
onsetList.clear(); |
| 51 | 51 |
double minSalience = Peaks::min(spectralFlux); |
| 52 |
for (int i = 0; i < onsets.size(); i++) {
|
|
| 52 |
for (int i = 0; i < (int)onsets.size(); i++) {
|
|
| 53 | 53 |
int index = *it; |
| 54 | 54 |
++it; |
| 55 | 55 |
onsets[i] = index * hop; |
| BeatRootProcessor.h | ||
|---|---|---|
| 117 | 117 |
protected: |
| 118 | 118 |
/** Allocates memory for arrays, based on parameter settings */ |
| 119 | 119 |
void init() {
|
| 120 |
#ifdef DEBUG_BEATROOT |
|
| 121 |
std::cerr << "BeatRootProcessor::init()" << std::endl; |
|
| 122 |
#endif |
|
| 120 | 123 |
makeFreqMap(fftSize, sampleRate); |
| 121 | 124 |
prevFrame.clear(); |
| 122 | 125 |
for (int i = 0; i <= fftSize/2; i++) prevFrame.push_back(0); |
| 123 | 126 |
spectralFlux.clear(); |
| 127 |
onsets.clear(); |
|
| 128 |
onsetList.clear(); |
|
| 124 | 129 |
} // init() |
| 125 | 130 |
|
| 126 | 131 |
/** Creates a map of FFT frequency bins to comparison bins. |
| ... | ... | |
| 137 | 142 |
int crossoverMidi = (int)lrint(log(crossoverBin*binWidth/440)/ |
| 138 | 143 |
log(2) * 12 + 69); |
| 139 | 144 |
int i = 0; |
| 140 |
while (i <= crossoverBin && i <= fftSize/2) |
|
| 141 |
freqMap[i++] = i; |
|
| 145 |
while (i <= crossoverBin && i <= fftSize/2) {
|
|
| 146 |
freqMap[i] = i; |
|
| 147 |
++i; |
|
| 148 |
} |
|
| 142 | 149 |
while (i <= fftSize/2) {
|
| 143 | 150 |
double midi = log(i*binWidth/440) / log(2) * 12 + 69; |
| 144 | 151 |
if (midi > 127) |
| 145 | 152 |
midi = 127; |
| 146 |
freqMap[i++] = crossoverBin + (int)lrint(midi) - crossoverMidi; |
|
| 153 |
freqMap[i] = crossoverBin + (int)lrint(midi) - crossoverMidi; |
|
| 154 |
++i; |
|
| 147 | 155 |
} |
| 148 | 156 |
freqMapSize = freqMap[i-1] + 1; |
| 149 | 157 |
} // makeFreqMap() |
| BeatRootVampPlugin.cpp | ||
|---|---|---|
| 209 | 209 |
BeatRootVampPlugin::getRemainingFeatures() |
| 210 | 210 |
{
|
| 211 | 211 |
EventList el = m_processor->beatTrack(); |
| 212 |
|
|
| 212 |
|
|
| 213 | 213 |
Feature f; |
| 214 | 214 |
f.hasTimestamp = true; |
| 215 | 215 |
f.hasDuration = false; |
| Peaks.cpp | ||
|---|---|---|
| 29 | 29 |
if (i < 0) |
| 30 | 30 |
i = 0; |
| 31 | 31 |
int stop = mid + width + 1; |
| 32 |
if (stop > data.size()) |
|
| 32 |
if (stop > (int)data.size())
|
|
| 33 | 33 |
stop = data.size(); |
| 34 | 34 |
maxp = i; |
| 35 | 35 |
for (i++; i < stop; i++) |
| ... | ... | |
| 40 | 40 |
for (j = peakCount; j > 0; j--) {
|
| 41 | 41 |
if (data[maxp] <= data[peaks[j-1]]) |
| 42 | 42 |
break; |
| 43 |
else if (j < peaks.size()) |
|
| 43 |
else if (j < (int)peaks.size())
|
|
| 44 | 44 |
peaks[j] = peaks[j-1]; |
| 45 | 45 |
} |
| 46 |
if (j != peaks.size()) |
|
| 46 |
if (j != (int)peaks.size())
|
|
| 47 | 47 |
peaks[j] = maxp; |
| 48 |
if (peakCount != peaks.size()) |
|
| 48 |
if (peakCount != (int)peaks.size())
|
|
| 49 | 49 |
peakCount++; |
| 50 | 50 |
} |
| 51 | 51 |
mid++; |
| ... | ... | |
| 69 | 69 |
if (i < 0) |
| 70 | 70 |
i = 0; |
| 71 | 71 |
int stop = mid + width + 1; |
| 72 |
if (stop > data.size()) |
|
| 72 |
if (stop > (int)data.size())
|
|
| 73 | 73 |
stop = data.size(); |
| 74 | 74 |
maxp = i; |
| 75 | 75 |
for (i++; i < stop; i++) |
| ... | ... | |
| 106 | 106 |
if (iStart < 0) |
| 107 | 107 |
iStart = 0; |
| 108 | 108 |
int iStop = index + post * width; |
| 109 |
if (iStop > data.size()) |
|
| 109 |
if (iStop > (int)data.size())
|
|
| 110 | 110 |
iStop = data.size(); |
| 111 | 111 |
double sum = 0; |
| 112 | 112 |
int count = iStop - iStart; |
| ... | ... | |
| 120 | 120 |
void Peaks::normalise(vector<double> &data) {
|
| 121 | 121 |
double sx = 0; |
| 122 | 122 |
double sxx = 0; |
| 123 |
for (int i = 0; i < data.size(); i++) {
|
|
| 123 |
for (int i = 0; i < (int)data.size(); i++) {
|
|
| 124 | 124 |
sx += data[i]; |
| 125 | 125 |
sxx += data[i] * data[i]; |
| 126 | 126 |
} |
| ... | ... | |
| 128 | 128 |
double sd = sqrt((sxx - sx * mean) / data.size()); |
| 129 | 129 |
if (sd == 0) |
| 130 | 130 |
sd = 1; // all data[i] == mean -> 0; avoids div by 0 |
| 131 |
for (int i = 0; i < data.size(); i++) {
|
|
| 131 |
for (int i = 0; i < (int)data.size(); i++) {
|
|
| 132 | 132 |
data[i] = (data[i] - mean) / sd; |
| 133 | 133 |
} |
| 134 | 134 |
} // normalise() |
| ... | ... | |
| 154 | 154 |
double delta = n * sxx - sx * sx; |
| 155 | 155 |
for ( ; j < n / 2; j++) |
| 156 | 156 |
slope[j] = (n * sxy - sx * sy) / delta; |
| 157 |
for ( ; j < data.size() - (n + 1) / 2; j++, i++) {
|
|
| 157 |
for ( ; j < (int)data.size() - (n + 1) / 2; j++, i++) {
|
|
| 158 | 158 |
slope[j] = (n * sxy - sx * sy) / delta; |
| 159 | 159 |
sy += data[i] - data[i - n]; |
| 160 | 160 |
sxy += hop * (n * data[i] - sy); |
| 161 | 161 |
} |
| 162 |
for ( ; j < data.size(); j++) |
|
| 162 |
for ( ; j < (int)data.size(); j++)
|
|
| 163 | 163 |
slope[j] = (n * sxy - sx * sy) / delta; |
| 164 | 164 |
} // getSlope() |
| 165 | 165 |
|
| 166 | 166 |
int Peaks::imin(const vector<double> &arr) {
|
| 167 | 167 |
int i = 0; |
| 168 |
for (int j = 1; j < arr.size(); j++) |
|
| 168 |
for (int j = 1; j < (int)arr.size(); j++)
|
|
| 169 | 169 |
if (arr[j] < arr[i]) |
| 170 | 170 |
i = j; |
| 171 | 171 |
return i; |
| ... | ... | |
| 173 | 173 |
|
| 174 | 174 |
int Peaks::imax(const vector<double> &arr) {
|
| 175 | 175 |
int i = 0; |
| 176 |
for (int j = 1; j < arr.size(); j++) |
|
| 176 |
for (int j = 1; j < (int)arr.size(); j++)
|
|
| 177 | 177 |
if (arr[j] > arr[i]) |
| 178 | 178 |
i = j; |
| 179 | 179 |
return i; |
Also available in: Unified diff