c@256: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ c@256: c@256: /* c@256: QM DSP Library c@256: c@256: Centre for Digital Music, Queen Mary, University of London. c@256: This file copyright 2008 Kurt Jacobson and QMUL. c@309: c@309: This program is free software; you can redistribute it and/or c@309: modify it under the terms of the GNU General Public License as c@309: published by the Free Software Foundation; either version 2 of the c@309: License, or (at your option) any later version. See the file c@309: COPYING included with this distribution for more information. c@256: */ c@256: c@256: #include "BeatSpectrum.h" c@256: c@256: #include "maths/CosineDistance.h" c@256: c@256: using std::vector; c@256: c@256: vector BeatSpectrum::process(const vector > &m) c@256: { c@256: int origin = 0; c@256: int sz = m.size()/2; c@256: c@256: int i, j, k; c@256: c@256: vector v(sz); c@256: for (i = 0; i < sz; ++i) v[i] = 0.0; c@256: c@256: CosineDistance cd; c@256: c@256: for (i = origin; i < origin + sz; ++i) { c@256: c@256: k = 0; c@256: c@256: for (j = i + 1; j < i + sz + 1; ++j) { c@256: c@256: v[k++] += cd.distance(m[i], m[j]); c@256: } c@256: } c@256: c@256: // normalize c@256: c@256: double max = 0.0; c@256: c@256: for (i = 0; i < sz; ++i) { c@256: if (v[i] > max) max = v[i]; c@256: } c@256: c@256: if (max > 0.0) { c@256: for (i = 0; i < sz; ++i) { c@256: v[i] /= max; c@256: } c@256: } c@256: c@256: return v; c@256: } c@256: