Lab 2:   Arithmetic of sounds
1 Playing sounds

Lab 2: Arithmetic of sounds

At the end of this lab, you should be able to - play sounds - manipulate sounds using simple operators - define simple functions on sounds - design and build simple interactive programs using the "world" model

As before, do all of your work in a single definitions window. When an exercise asks you to answer a question rather than develop a program (or in addition), use a comment to record your answer.

It appears that a bunch of people’s DrRacket installations aren’t indexing the RSound documentation, so I’m providing a static link to the RSound documentation.

1 Playing sounds

Beside ding, there are a number of other drum sounds that are built into the sound library:

Try playing some of these, using play.
  • Do HtDP 2e Exercise 2.

  • Use define and rs-overlay to define claps to be the sound that has clap-1 and clap-2 on top of each other. Then, use rs-append and silence to play the claps noise twice, separated by one second of silence. Note that you need a lot of silence–there are 44,100 frames in each second.

  • Do HtDP 2e Exercise 4.

  • Do HtDP 2e Exercise 10.

  • Use an application such as Audacity to record yourself saying the words "Chicken", "Monkey", and "Duck". Trim and cut to separate this into three separate audio samples, and then export them as WAV files.

  • Use rs-read and play to play your three sounds individually.

  • Building on Exercise 10, create an expression that says "Chicken" if the image is tall, "Monkey" if it is square, and "Duck" if it is wide.

  • Do HtDP 2e Exercise 16.

  • Define the function stutter, that extracts the first quarter of a sound and appends it to itself four times. You’ll need to use clip, rs-frames, and rs-append to make this work.

  • Do HtDP 2e Exercise 24.

  • Do HtDP 2e Exercise 28

  • Using bing-bang, develop a program whose "state" is the string "blue" or "red". It should display a rectangle of the color matching the state. When the user presses the space bar, it should toggle the world state between "blue" and "red". When the user presses another key, nothing should happen.

  • Using big-bang, develop a program whose "state" is the time elapsed since the beginning of the program, which plays the kick noise every second, and the c-hi-hat-1 sound every time the user presses a key.