qm-dsp
1.8
|
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ 00002 00003 /* 00004 QM DSP Library 00005 00006 Centre for Digital Music, Queen Mary, University of London. 00007 This file copyright 2008 Kurt Jacobson and QMUL. 00008 00009 This program is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU General Public License as 00011 published by the Free Software Foundation; either version 2 of the 00012 License, or (at your option) any later version. See the file 00013 COPYING included with this distribution for more information. 00014 */ 00015 00016 #include "BeatSpectrum.h" 00017 00018 #include "maths/CosineDistance.h" 00019 00020 using std::vector; 00021 00022 vector<double> BeatSpectrum::process(const vector<vector<double> > &m) 00023 { 00024 int origin = 0; 00025 int sz = m.size()/2; 00026 00027 int i, j, k; 00028 00029 vector<double> v(sz); 00030 for (i = 0; i < sz; ++i) v[i] = 0.0; 00031 00032 CosineDistance cd; 00033 00034 for (i = origin; i < origin + sz; ++i) { 00035 00036 k = 0; 00037 00038 for (j = i + 1; j < i + sz + 1; ++j) { 00039 00040 v[k++] += cd.distance(m[i], m[j]); 00041 } 00042 } 00043 00044 // normalize 00045 00046 double max = 0.0; 00047 00048 for (i = 0; i < sz; ++i) { 00049 if (v[i] > max) max = v[i]; 00050 } 00051 00052 if (max > 0.0) { 00053 for (i = 0; i < sz; ++i) { 00054 v[i] /= max; 00055 } 00056 } 00057 00058 return v; 00059 } 00060