-
Notifications
You must be signed in to change notification settings - Fork 1
/
hrm.pure
62 lines (43 loc) · 2.3 KB
/
hrm.pure
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
50
51
52
53
54
55
56
57
58
59
60
61
62
/* hrm.q: generic Barlow disharmonicities of rational pitches and intervals */
using factor;
/* The input to all these functions are rational pitches/intervals specified
as (num,denom) pairs. The pv ("prime valuation") function is used to
determine the basic prime indigestibilities. It is expected to take a prime
number as argument, and return the corresponding indigestibility value as
the result. */
/* Some "standard" 12 tone scales to play with. Add others as needed. */
/* The standard "Just" a.k.a. "Didymian" a.k.a. "Ptomelaic" scale. This
gives different keys distinct colors. Remote keys are disharmonious. */
let just = [(1,1), (16,15), (9,8), (6,5), (5,4), (4,3), (45,32),
(3,2), (8,5), (5,3), (16,9), (15,8), (2,1)];
/* The Pythagorean scale. Closer to equal temperament than Didymos' tuning
(major 3rd is sharp). The tuning of the Middle Ages. */
let pyth = [(1,1), (2187,2048), (9,8), (32,27), (81,64), (4,3), (729,512),
(3,2), (6561,4096), (27,16), (16,9), (243,128), (2,1)];
/* A (re)rationalized 1/4 comma meantone scale, a la Barlow. Pythagorean-
based, but the thirds are "just" in the home keys near C major. Breaks
down in remote keys because of the "wolve" interval. */
let mean4 = [(1,1), (25,24), (10,9), (6,5), (5,4), (4,3), (25,18),
(3,2), (25,16), (5,3), (16,9), (15,8), (2,1)];
/* Some "standard" prime valuation functions to play with. Add others as
needed. */
barlow p = 2*(p-1)*(p-1)/p;
euler p = p-1;
// "mod 2" versions (octave is eliminated)
barlow2 p = if p==2 then 0 else barlow p;
euler2 p = if p==2 then 0 else euler p;
/* Harmonicity computation.
- hrm pv (p,q) computes the disharmonicity of the interval p/q using the
prime valuation function pv.
- hrm pv S computes the disharmonicity metric of a scale S, i.e., the
pairwise disharmonicities of all intervals in the scale. The input can be
a list or vector of intervals as (p,q) pairs, the output is the distance
matrix.
- hrm_dist pv (p1,q1) (p2,q2) computes the harmonic distance between two
pitches, i.e., the disharmonicity of the interval between (p1,q1) and
(p2,q2). */
public hrm_dist;
hrm pv (p,q) = foldl (+) 0 [abs k*pv p | (p,k) = factors (p,q)];
hrm pv S = {hrm_dist pv s t | s = S; t = S};
hrm_dist pv (p1,q1) (p2,q2)
= hrm pv (p1*q2,p2*q1);