1 Setup
2 Design Recipe
3 Attenuation
4 Interference
5 Compound Data
6 Using Compound Data
7 Compound Data
8 Mixed Data

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" 1 3)))
  (require (planet "draw.rkt" ("clements" "rsound.plt" 1 3)))

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 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 Compound Data

In the rest of this lab, we’re going to be working with compound data. Here’s a silly example, the data definition for a sheep that has a weight and a name:

  ; a sheep is (make-sheep number string)
  (define-struct sheep weight name)

Your data definitions should look like this. A comment, followed (if necessary) by any structure definitions.

6 Using Compound Data

  1. Develop the function rsound-duration, that consumes an rsound and returns the duration of the rsound in seconds. Remember that each rsound has its own sample-rate.

7 Compound Data

  1. Develop the rsound2 structure that contains two rsounds, named treble and bass. Write the data definition and three examples of rsound2s.

  2. Write down three examples of rsound2s.

  3. Develop the check-rsound2 function, that accepts an rsound2 and returns true when the two rsounds are of the same length, and have the same sample-rate.

  4. Develop the function stagger, that consumes an rsound2 and produces an rsound containing the treble and bass rsounds overlaid, where the treble is delayed by half the length of the sound.

8 Mixed Data

Here’s a data definition for something that’s either sound or silence:

  ; an event is either
  ; - a number, representing a number of seconds of silence, or
  ; - an rsound

Note that no structure definitions are necessary for this data definitions, because numbers and rsounds are already defined.

  1. Develop the function event->rsound, that accepts an event and produces an rsound. If the input is a number, the result should be a silent rsound of the given length. If the input is an rsound, the result should simply be that rsound. You may assume that the sample rate is fixed at 44100.

  2. Develop the function events->rsound, that accepts a list of events and uses map and rsound-append* to construct a single rsound containing all of the events.