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