annotate dsp/rhythm/BeatSpectrum.cpp @ 135:0fdbb93e92b7

Factorial: return double (int not big enough for many popular values)
author Chris Cannam
date Wed, 16 Oct 2013 16:44:14 +0100
parents e5907ae6de17
children
rev   line source
cannam@31 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
cannam@31 2
cannam@31 3 /*
cannam@31 4 QM DSP Library
cannam@31 5
cannam@31 6 Centre for Digital Music, Queen Mary, University of London.
cannam@31 7 This file copyright 2008 Kurt Jacobson and QMUL.
Chris@84 8
Chris@84 9 This program is free software; you can redistribute it and/or
Chris@84 10 modify it under the terms of the GNU General Public License as
Chris@84 11 published by the Free Software Foundation; either version 2 of the
Chris@84 12 License, or (at your option) any later version. See the file
Chris@84 13 COPYING included with this distribution for more information.
cannam@31 14 */
cannam@31 15
cannam@31 16 #include "BeatSpectrum.h"
cannam@31 17
cannam@31 18 #include "maths/CosineDistance.h"
cannam@31 19
cannam@31 20 using std::vector;
cannam@31 21
cannam@31 22 vector<double> BeatSpectrum::process(const vector<vector<double> > &m)
cannam@31 23 {
cannam@31 24 int origin = 0;
cannam@31 25 int sz = m.size()/2;
cannam@31 26
cannam@31 27 int i, j, k;
cannam@31 28
cannam@31 29 vector<double> v(sz);
cannam@31 30 for (i = 0; i < sz; ++i) v[i] = 0.0;
cannam@31 31
cannam@31 32 CosineDistance cd;
cannam@31 33
cannam@31 34 for (i = origin; i < origin + sz; ++i) {
cannam@31 35
cannam@31 36 k = 0;
cannam@31 37
cannam@31 38 for (j = i + 1; j < i + sz + 1; ++j) {
cannam@31 39
cannam@31 40 v[k++] += cd.distance(m[i], m[j]);
cannam@31 41 }
cannam@31 42 }
cannam@31 43
cannam@31 44 // normalize
cannam@31 45
cannam@31 46 double max = 0.0;
cannam@31 47
cannam@31 48 for (i = 0; i < sz; ++i) {
cannam@31 49 if (v[i] > max) max = v[i];
cannam@31 50 }
cannam@31 51
cannam@31 52 if (max > 0.0) {
cannam@31 53 for (i = 0; i < sz; ++i) {
cannam@31 54 v[i] /= max;
cannam@31 55 }
cannam@31 56 }
cannam@31 57
cannam@31 58 return v;
cannam@31 59 }
cannam@31 60