File: comp_chroma.cpp

package info (click to toggle)
audacity 3.2.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 106,704 kB
  • sloc: cpp: 277,038; ansic: 73,623; lisp: 7,761; python: 3,305; sh: 2,715; perl: 821; xml: 275; makefile: 119
file content (49 lines) | stat: -rw-r--r-- 1,233 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* comp_chroma.cpp -- compute chroma distance
 *
 * 2008 RBD
 */

#include <string.h>
#include <math.h>
#include <fstream>
#include <algorithm>
#include "allegro.h"
#include "audioreader.h"
#include "scorealign.h"
#include "gen_chroma.h"
#include  "comp_chroma.h"
using namespace std;

#ifdef min
#undef min
#endif
#define min(x,y) ((x)<(y)?(x):(y))

#define SILENCE_DISTANCE 16.0

/*				GEN_DIST
 *
 * This function generates the Euclidean distance for points i
 * and j in two chroma vectors for use with dynamic time warping of 
 * the chroma vectors.
 */
float Scorealign::gen_dist(int i, int j) 
{
    const float MAX = 12.0;
    assert(i < file0_frames);
    assert(j < file1_frames);
    float *cv0 = AREF1(chrom_energy0, i);
    float *cv1 = AREF1(chrom_energy1, j);
    if (cv0[CHROMA_BIN_COUNT] != cv1[CHROMA_BIN_COUNT]) {
        // silent frames are a (large) constant distance from non-silent frames
        return SILENCE_DISTANCE;
    }
    /* calculate the Euclidean distance between these vectors */
    float sum = 0;
    for (int k = 0; k < CHROMA_BIN_COUNT; k++) {
        float diff = cv0[k] - cv1[k];
        sum += diff * diff ;
    }
    // place a ceiling (MAX) on distance
    return min(sqrt(sum), MAX);
}