1 Setup
2 Design Recipe
3 Attenuation
4 Interference
5 sequencing
6 Making a song

Lab 9

1 Setup

For this lab, you should be in the Intermediate Student language. Begin your programs with

(require (planet "main.rkt" ("clements" "rsound.plt" 2 5)))
(require (planet "draw.rkt" ("clements" "rsound.plt" 2 5)))

2 Design Recipe

In this lab, you need to follow the design recipe explicitly when developing functions. For now, this means:
  1. Write a purpose statement and contract and header for your function

  2. Write a test case using check-expect.

  3. Develop the function body

  4. Run the test cases, correct any problems.

3 Attenuation

Develop the function ring, that accepts a frequency f and a time t and produces an rsound representing a sine wave tone at that frequency that lasts for 4t seconds. At time 0, it should have amplitude 1.0. At time t, it should have amplitude 0.5. At time 2t, it should have amplitude 0.25, and so on. Assume a sample rate of 44100.

4 Interference

Develop the function beat, that accepts a frequency f and a beat-time t and produces an rsound of duration 4t that contains two sine waves one of frequency f and one of a frequency that’s slightly higher, chosen so that they "beat" with period t. Assume a sample rate of 44100.

5 sequencing

Develop the function note, that accepts either a MIDI note number or the value false, and produces a tone of duration 1/4 second at the given pitch, or 1/4 second of silence if called with false.

For this next function and the remainder of the lab, you should use the "Use language declared in source" language level and a "#lang racket" declaration. Open a new file for this part of the lab, since your check-expects won’t work in the full language.

Next, develop the function notes->song, that consumes a list of note numbers and falses and uses rs-append* and a for/list loop and the prior note function to produce a single song.

6 Making a song

Using the notes->song function, create the first ten seconds of one of the following songs:
  • Happy Birthday

  • Axel F

  • Bach’s Invention No. 1 (treble clef only)

  • In a Sentimental Mood

  • ... or something else that’s easily recognizable.