Mercurial > hg > match-vamp
diff src/FeatureConditioner.cpp @ 103:593054bf6476 feature_conditioner
Pull out normalisation and specdiff stuff into FeatureConditioner
author | Chris Cannam |
---|---|
date | Thu, 04 Dec 2014 13:05:16 +0000 |
parents | |
children | eed5f9594268 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/FeatureConditioner.cpp Thu Dec 04 13:05:16 2014 +0000 @@ -0,0 +1,80 @@ +/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ + +/* + Vamp feature extraction plugin using the MATCH audio alignment + algorithm. + + Centre for Digital Music, Queen Mary, University of London. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. See the file + COPYING included with this distribution for more information. +*/ + +#include "FeatureConditioner.h" + +#include <iostream> + +using namespace std; + +vector<double> +FeatureConditioner::process(const vector<double> &feature) +{ + if (m_prev.empty()) { + m_prev.resize(feature.size(), 0.0); + } + if (m_prev.size() != feature.size()) { + cerr << "ERROR: FeatureConditioner::process: feature size " + << feature.size() << " differs from previous feature size " + << m_prev.size() << endl; + return feature; + } + + int size = feature.size(); + + vector<double> out(size, 0.0); + + double totalEnergy = 0; + if (m_params.order == OutputRectifiedDerivative) { + for (int i = 0; i < size; i++) { + totalEnergy += feature[i]; + if (feature[i] > m_prev[i]) { + out[i] = feature[i] - m_prev[i]; + } else { + out[i] = 0; + } + } + } else { + for (int i = 0; i < size; i++) { + out[i] = feature[i]; + totalEnergy += out[i]; + } + } + + if (m_ltAverage == 0) { + m_ltAverage = totalEnergy; + } else { + double decay = m_params.decay; + m_ltAverage = m_ltAverage * decay + totalEnergy * (1.0 - decay); + } + + if (totalEnergy <= m_params.silenceThreshold) { + for (int i = 0; i < size; i++) { + out[i] = 0; + } + } else if (m_params.norm == NormaliseToSum1) { + for (int i = 0; i < size; i++) { + out[i] /= totalEnergy; + } + } else if (m_params.norm == NormaliseToLTAverage) { + for (int i = 0; i < size; i++) { + out[i] /= m_ltAverage; + } + } + + m_prev = feature; + return out; +} +