Skip to content

Commit 61aa313

Browse files
authored
Add frequency in equal temperament (#24)
1 parent e99fdc1 commit 61aa313

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

src/MusicTheory.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ include("scales.jl")
2727
include("chords.jl")
2828
include("triads.jl")
2929
include("notes.jl")
30+
include("equal_temperament.jl")
3031
end

src/equal_temperament.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
abstract type Temperament end
2+
3+
struct EqualTemperament
4+
base_pitch::Pitch
5+
base_frequency::Float64
6+
end
7+
8+
9+
function frequency(temperament::EqualTemperament, pitch::Pitch)
10+
semitone_distance = semitone(pitch) - semitone(temperament.base_pitch)
11+
return 2.0^(semitone_distance // 12) * temperament.base_frequency
12+
end
13+

test/equal_temperament.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@testest "Equal temperament" begin
2+
temperament = EqualTemperament(A[4], 440)
3+
4+
@test frequency(temperament, C[4]) == 261.6255653005986
5+
end

0 commit comments

Comments
 (0)