Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 63 lines (55 sloc) 1.622 kb
bbc0f63 @lalinsky Import from my private branch
authored
1 /*
2 * Chromaprint -- Audio fingerprinting toolkit
3 * Copyright (C) 2010 Lukas Lalinsky <lalinsky@gmail.com>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 * USA
19 */
20
21 #include <limits>
22 #include <assert.h>
23 #include <math.h>
24 #include "chroma_resampler.h"
25 #include "utils.h"
26
27 using namespace std;
28 using namespace Chromaprint;
29
30 ChromaResampler::ChromaResampler(int factor, FeatureVectorConsumer *consumer)
31 : m_result(12, 0.0),
32 m_iteration(0),
33 m_factor(factor),
34 m_consumer(consumer)
35 {
36 }
37
38 ChromaResampler::~ChromaResampler()
39 {
40 }
41
42 void ChromaResampler::Reset()
43 {
44 m_iteration = 0;
45 fill(m_result.begin(), m_result.end(), 0.0);
46 }
47
48 void ChromaResampler::Consume(std::vector<double> &features)
49 {
50 for (int i = 0; i < 12; i++) {
51 m_result[i] += features[i];
52 }
53 m_iteration += 1;
54 if (m_iteration == m_factor) {
55 for (int i = 0; i < 12; i++) {
56 m_result[i] /= m_factor;
57 }
58 m_consumer->Consume(m_result);
59 Reset();
60 }
61 }
62
Something went wrong with that request. Please try again.