liveBook · Manning

Tone

As explained in Learn Haskell by Example

A tone is a sustained musical sound characterized by a particular frequency and waveform.

A tone is generated by repeating waveform samples at a chosen frequency until a requested duration is filled. Different waveforms change the sound’s timbre. section 10.1.2

Build a tone from these practical pieces:

  • Represent a waveform as a function from a position between 0 and 1 to a sample value. section 10.1.2
  • Compute the samples in one period from the frequency, then repeat their positions across the requested duration. section 10.1.2
  • Use sine, square, sawtooth, or triangle waveforms to produce different signal shapes. section 10.1.2
  • Clamp signal values before converting them to audio samples and writing a WAV file. section 10.1.2

Exporting four tones

Generate four five-second tones at 220 Hz by mapping `tone` over the sine, triangle, sawtooth, and square waves, concatenating the signals, and passing them to `writeWav`. section 10.1.2

Figure 10.2 Four standard waveforms
figure

Compare the four standard waveform shapes to see how changing the signal function changes the generated tone. section 10.1.2

Abruptly stopping a tone can create an audible click because the waveform is cut off; contouring the signal, especially its ending, addresses this problem. section 10.2

Multiple tones become music when events specify each tone’s pitch, duration, and start time alongside periods of silence. section 10.3 section 10.3.1

How Learn Haskell by Example covers it

How deep it goes
Explains waveform functions, period sampling, WAV conversion, clipping, and abrupt-stop artifacts, while deferring deeper timbre modulation.
Examples
Uses sine, square, sawtooth, and triangle waves, then exports four concatenated 220 Hz WAV segments.
What it assumes
Assumes familiarity with numeric type classes and introduces sound generation through waveform functions and sampled signals.
What you can do after
Build it from scratch in Haskell by defining waveforms, generating sampled tones, limiting signals, and exporting WAV files.
How it connects
Connects tone to waveforms, frequency, timbre, signals, silence, and event scheduling.

Also explained in

Compare how 4 books explain tone →

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.