Skip to content

Commit

Permalink
Add cents table of harmonic serie
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarbin committed Dec 16, 2024
1 parent 9d9e4a2 commit cd67fd4
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions test/test__acoustic_interval.ml
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,57 @@ let%expect_test "harmonic series and cents" =
└──────────┴────────────────────────────┴───────────────────────────────┘ |}]
;;

let%expect_test "harmonic series and cents bis" =
let module Row = struct
type t =
{ harmonic : int
; cents : Cents.t
}
end
in
let columns =
Ascii_table.Column.
[ create_attr "Harmonic" (fun (t : Row.t) -> [], Int.to_string t.harmonic)
; create_attr "Cents" (fun (t : Row.t) -> [], t.cents |> Cents.to_string_nearest)
]
in
let rows =
List.init 16 ~f:(fun i ->
let i = i + 1 in
let cents =
let harmonic =
Acoustic_interval.small_natural_ratio_exn ~numerator:i ~denominator:1
in
Acoustic_interval.to_cents harmonic %. 1200.
in
{ Row.harmonic = i; cents })
in
Ascii_table.to_string columns rows |> print_endline;
[%expect
{|
┌──────────┬───────┐
HarmonicCents
├──────────┼───────┤
10
20
3702
40
5386
6702
7969
80
9204
10386
11551
12702
13841
14969
151088
160
└──────────┴───────┘
|}]
;;

let%expect_test "equal corner cases" =
let base =
Acoustic_interval.equal_division_of_the_octave ~divisor:53 ~number_of_divisions:52
Expand Down

0 comments on commit cd67fd4

Please sign in to comment.