Example #1
0
void Chroma::Consume(const FFTFrame &frame)
{
	fill(m_features.begin(), m_features.end(), 0.0);
	for (int i = m_min_index; i < m_max_index; i++) {
		int note = m_notes[i];
		double energy = frame.Energy(i);
		if (m_interpolate) {
			int note2 = note;
			double a = 1.0;
			if (m_notes_frac[i] < 0.5) {
				note2 = (note + NUM_BANDS - 1) % NUM_BANDS;
				a = 0.5 + m_notes_frac[i];
			}
			if (m_notes_frac[i] > 0.5) {
				note2 = (note + 1) % NUM_BANDS;
				a = 1.5 - m_notes_frac[i];
			}
			m_features[note] += energy * a; 
			m_features[note2] += energy * (1.0 - a); 
		}
		else {
			m_features[note] += energy; 
		}
	}
	m_consumer->Consume(m_features);
}