liveBook · Manning

Pitch

As explained in Learn Haskell by Example

Pitch is the perceptual property of a musical sound associated with its perceived highness or lowness and position in the system of musical tones.

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

How Learn Haskell by Example covers it

How deep it goes
Explains type-class conversion, semitone tuning, chromatic notes, heterogeneous storage, and melody rendering.
Examples
Demonstrates concert A, octave doubling, chromatic note constructors, heterogeneous pitch lists, and a rendered melody.
What it assumes
Assumes basic Haskell types and functions while developing music-theory representations from frequency fundamentals.
What you can do after
Build pitch representations, convert them to frequencies, combine them in compositions, and render tones to a WAV file.
How it connects
Connects frequency, semitones, musical notes, oscillators, synthesizers, type classes, and musical composition.

Also explained in

Compare how 2 books explain pitch →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Haskell by Example. The section links point to the parts of the book it draws on.