-
-
Notifications
You must be signed in to change notification settings - Fork 143
/
Copy pathchroma_filter.cpp
52 lines (45 loc) · 1.11 KB
/
chroma_filter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright (C) 2010-2016 Lukas Lalinsky
// Distributed under the MIT license, see the LICENSE file for details.
#include <limits>
#include <assert.h>
#include <math.h>
#include "chroma_filter.h"
#include "utils.h"
namespace chromaprint {
ChromaFilter::ChromaFilter(const double *coefficients, int length, FeatureVectorConsumer *consumer)
: m_coefficients(coefficients),
m_length(length),
m_buffer(8),
m_result(12),
m_buffer_offset(0),
m_buffer_size(1),
m_consumer(consumer)
{
}
ChromaFilter::~ChromaFilter()
{
}
void ChromaFilter::Reset()
{
m_buffer_size = 1;
m_buffer_offset = 0;
}
void ChromaFilter::Consume(std::vector<double> &features)
{
m_buffer[m_buffer_offset] = features;
m_buffer_offset = (m_buffer_offset + 1) % 8;
if (m_buffer_size >= m_length) {
int offset = (m_buffer_offset + 8 - m_length) % 8;
fill(m_result.begin(), m_result.end(), 0.0);
for (int i = 0; i < 12; i++) {
for (int j = 0; j < m_length; j++) {
m_result[i] += m_buffer[(offset + j) % 8][i] * m_coefficients[j];
}
}
m_consumer->Consume(m_result);
}
else {
m_buffer_size++;
}
}
}; // namespace chromaprint