Pitch describes the highness or lowness of a musical sound. In a synthesizer, it must become a frequency so an oscillator can generate the intended tone. section 10.3 section 10.4.1
A Haskell type class separates musical pitch representations from the conversion needed by sound generation. Pitchable values provide toFrequency; Hz already satisfies the class through the identity function. section 10.4.1
Useful representations build from frequency toward musical notation:
- Hz represents an already known frequency. section 10.4.1
- A Semitone is an Integer distance from concert A, where A equals 440 Hz; twelve semitones double or halve the frequency. section 10.4.1
- Chromatic combines a note name such as A, Cs, or C with an octave, then maps through semitones to frequency. section 10.4.1
- Pitch can wrap any Pitchable value, allowing Hz, semitones, and chromatic notes to coexist in one heterogeneous list. section 11.1.2
Convert notes into a melody
A melody can map toFrequency over [c 4, e 4, g 4, d 5, c 5], turn each frequency into a Tone, concatenate the events, and write melody.wav. section 10.4.1
Listing 11.1 A data type for structuring notes
data Pitch = forall a. (Pitchable a, Show a) => Pitch a #1 deriving instance Show Pitch #2 instance Pitchable Pitch where toFrequency (Pitch p) = toFrequency p #3
Inspect the existential Pitch definition and its Pitchable instance, which preserve a common conversion interface across different pitch representations. section 11.1.2

