Mercurial > hg > qm-dsp
comparison dsp/rhythm/BeatSpectrum.cpp @ 31:dfe38135e4c7
* Add cosine distance and the self-similarity matrix used for SB rhythmic
similarity
* Pull out SB timbral similarity KL divergence into its own file
author | cannam |
---|---|
date | Fri, 18 Jan 2008 14:40:20 +0000 |
parents | |
children | e5907ae6de17 |
comparison
equal
deleted
inserted
replaced
30:a251fb0de594 | 31:dfe38135e4c7 |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 QM DSP Library | |
5 | |
6 Centre for Digital Music, Queen Mary, University of London. | |
7 This file copyright 2008 Kurt Jacobson and QMUL. | |
8 All rights reserved. | |
9 */ | |
10 | |
11 #include "BeatSpectrum.h" | |
12 | |
13 #include "maths/CosineDistance.h" | |
14 | |
15 using std::vector; | |
16 | |
17 vector<double> BeatSpectrum::process(const vector<vector<double> > &m) | |
18 { | |
19 int origin = 0; | |
20 int sz = m.size()/2; | |
21 | |
22 int i, j, k; | |
23 | |
24 vector<double> v(sz); | |
25 for (i = 0; i < sz; ++i) v[i] = 0.0; | |
26 | |
27 CosineDistance cd; | |
28 | |
29 for (i = origin; i < origin + sz; ++i) { | |
30 | |
31 k = 0; | |
32 | |
33 for (j = i + 1; j < i + sz + 1; ++j) { | |
34 | |
35 v[k++] += cd.distance(m[i], m[j]); | |
36 } | |
37 } | |
38 | |
39 // normalize | |
40 | |
41 double max = 0.0; | |
42 | |
43 for (i = 0; i < sz; ++i) { | |
44 if (v[i] > max) max = v[i]; | |
45 } | |
46 | |
47 if (max > 0.0) { | |
48 for (i = 0; i < sz; ++i) { | |
49 v[i] /= max; | |
50 } | |
51 } | |
52 | |
53 return v; | |
54 } | |
55 |