type register = int;;
type tone = float;;
let c = 0;;
let d = 2;;
let e = 4;;
let f = 5;;
let g = 7;;
let a = 9;;
let b = 11;;
(* a is 440 Hz. Circle of 5ths gives 3/2 for each 5th above a. So:
*
* c 3^9/2^15 3^9/2^14
* c# 3^4/2^7 3^4/2^6
* d 3^11/2^18 3^11/2^17
* d# 3^6/2^10 3^6/2^9
* e 3/2^2 3/2^1
* f 3^8/2^13 3^8/2^12
* f# 3^3/2^5 3^3/2^4
* g 3^10/2^16
* g# 3^5/2^8
* a 3^0/2^0 (3^12/2^19)
* a# 3^7/2^11
* b 3^2/2^3
*
* HOWEVER, we don't actually use pure tempering anymore, but approximations.
* In fact, we use equal exponential scaling, i.e. a*(s^12) = 2a, or
* s = 2^(1/12). We'll keep a at 440 Hz. So for a given v and reg we have
* 440*2^(1/12*(v-9+12*reg))
*)
let note v reg =
let sfactor = float_of_int (v - 9 + 12 * reg) /. 12. in
440. *. (2. ** sfactor);;