2 people like it.

Musical Note Frequencies

With the usual Western music it is common to use the Equal temperament: http://en.wikipedia.org/wiki/Equal_temperament http://hyperphysics.phy-astr.gsu.edu/hbase/music/et.html Then the note frequencies are calculated by this formula. For more information: http://en.wikipedia.org/wiki/Pitch_(music) http://en.wikipedia.org/wiki/Musical_tuning#Tuning_systems

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
/// (Infinite) list of note-frequency -pairs
let tones = 
    let bass = 55.0 
    let octave = ["A"; "A#"; "B"; "C"; "C#"; "D"; "D#"; "E"; "F"; "F#"; "G"; "G#"]
    let notes = seq { while true do yield! octave }
    let frequency = bass |> Seq.unfold (fun x -> Some (x, x*System.Math.Pow(2.0, 1.0 / 12.0)))
    Seq.zip notes frequency

//let ``guitar open A`` = tones |> Seq.nth 24 // val it : float * string = (220.0, "A")

//let ``A to F#`` = tones |> Seq.skip 36 |> Seq.take 10 |> Seq.toArray
//  [|("A", 440.0); ("A#", 466.1637615); ("B", 493.8833013); ("C", 523.2511306);
//    ("C#", 554.365262); ("D", 587.3295358); ("D#", 622.2539674);
//    ("E", 659.2551138); ("F", 698.4564629); ("F#", 739.9888454)|]
val tones : seq<string * float>

Full name: Script.tones


 (Infinite) list of note-frequency -pairs
val bass : float
val octave : string list
val notes : seq<string>
Multiple items
val seq : sequence:seq<'T> -> seq<'T>

Full name: Microsoft.FSharp.Core.Operators.seq

--------------------
type seq<'T> = System.Collections.Generic.IEnumerable<'T>

Full name: Microsoft.FSharp.Collections.seq<_>
val frequency : seq<float>
module Seq

from Microsoft.FSharp.Collections
val unfold : generator:('State -> ('T * 'State) option) -> state:'State -> seq<'T>

Full name: Microsoft.FSharp.Collections.Seq.unfold
val x : float
union case Option.Some: Value: 'T -> Option<'T>
namespace System
type Math =
  static val PI : float
  static val E : float
  static member Abs : value:sbyte -> sbyte + 6 overloads
  static member Acos : d:float -> float
  static member Asin : d:float -> float
  static member Atan : d:float -> float
  static member Atan2 : y:float * x:float -> float
  static member BigMul : a:int * b:int -> int64
  static member Ceiling : d:decimal -> decimal + 1 overload
  static member Cos : d:float -> float
  ...

Full name: System.Math
System.Math.Pow(x: float, y: float) : float
val zip : source1:seq<'T1> -> source2:seq<'T2> -> seq<'T1 * 'T2>

Full name: Microsoft.FSharp.Collections.Seq.zip

More information

Link:http://fssnip.net/oX
Posted:9 years ago
Author:Tuomas Hietanen
Tags: music , frequency table