Frequencies and Ratios
Overview
Pitches and intervals can also be expressed as physical frequencies and freqency ratios, respectively. We provide wrappers around Float64
that represent log frequencies and log freqency ratios, and perform arithmetic with and without octave equivalence. There are two versions of each constructor depending on whether you provide log or non-log values. All values are printed as non-log. Pitch and interval classes are printed in brackets to indicate that they are representatives of an equivalence class.
julia> freqi(3/2)
fr1.5
julia> logfreqi(log(3/2))
fr1.5
julia> freqic(3/2)
fr[1.5]
julia> freqp(441)
441.0Hz
julia> freqpc(441)
[1.7226562500000004]Hz
Because of the use of floats, rounding errors can occur:
julia> freqp(440)
439.99999999999983Hz
You can use Julia's builtin method isapprox
/≈
to test for approximate equality:
julia> freqp(220) + freqi(2) ≈ freqp(440)
true
Reference
Types
Pitches.FreqInterval
— TypeFreqInterval <: Interval
A frequency ratio interval. Is internally represented by the logarithm of the frequency ratio, so conversion to Float64 will return a log-frequency ratio!
Pitches.FreqIC
— TypeFreqIC <: Interval
A frequency ratio interval class. Is internally represented by the logarithm of the frequency ratio, so conversion to Float64 will return a log-frequency ratio! Maintains octave equivalence.
Constructors
octave equivalent | takes log | interval | pitch |
---|---|---|---|
no | no | freqi | freqp |
yes | logfreqi | logfreqp | |
yes | no | freqic | freqpc |
yes | logfreqic | logfreqpc |
Pitches.freqi
— Functionfreqi(ratio)
Creates a frequency ratio interval from a frequency ratio.
Pitches.freqic
— Functionfreqic(ratio)
Creates a frequency ratio interval class from a frequency ratio.
Pitches.freqp
— Functionfreqp(frequency)
Creates a frequency pitch from a frequency.
Pitches.freqpc
— Functionfreqpc(frequency)
Creates a frequency pitch class from a frequency.
Pitches.logfreqi
— Functionlogfreqi(logratio)
Creates a frequency ratio interval from a log-ratio.
Pitches.logfreqp
— Functionlogfreqp(logfrequency)
Creates a frequency pitch from a log-frequency.
Pitches.logfreqic
— Functionlogfreqic(logratio)
Creates a frequency ratio interval class from a log-ratio.
Pitches.logfreqpc
— Functionlogfreqpc(logfrequency)
Creates a frequency pitch class from a log-frequency.