Lab 2:   Arithmetic of sounds
1 Playing sounds
2 File Systems
6.3.0.7

Lab 2: Arithmetic of sounds

At the end of this lab, you should be able to

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.

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.

Now, do these exercises.

  1. Do HtDP 2e Exercise 2.

  2. Use F1 to read the documentation for rs-overlay. You may have to "clear" the filter in order to show this documentation.

  3. 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.

  4. Do HtDP 2e Exercise 4.

  5. Do HtDP 2e Exercise 10.

  6. Use the record-sound function to record yourself saying the words "Chicken", "Monkey", and "Duck". Use rs-write to save them as WAV files. Use F1 to read the documentation and discover how these functions work. If there’s no microphone on any of the computers you’re using, you can use my recordings from the CS courtyard of illustrious professors and students:

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

  8. 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.

  9. Do HtDP 2e Exercise 16.

  10. 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.

  11. Do HtDP 2e Exercise 23.

  12. Do HtDP 2e Exercise 28.

  13. Using big-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.

  14. 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. Read the documentation for the andplay function, which will be useful here.

2 File Systems

Stop me if you’ve heard this one:

Super-high-level intro to file systems (apologies if you already knew all of this):

All current operating systems (Unix/Linux, Windows, OS X, Android, iOS) store files using a "tree" structure; there are one or more "root"s which are at the the "top level", and then there are "directories" or "folders" below this. Moreover, directories can contain other directories. So, on an OS X machine, my "home" directory is is in the "clements" directory that is in the "Users" directory of the root directory. A "path" is a string that describes a trace of directories to follow to get to a particular directory or file. So, for instance, the string

"cpe123/labs/lab1.rkt"

refers to the lab1.rkt file in the labs subdirectory of the cpe123 subdirectory of the current one. This is called a "relative path" because it starts in some current directory. If you want to describe a top-level directory (that is, to start at the root), you must begin your path with a slash. This is called an "absolute path". It might look like this:

"/Users/clements/cpe123/labs/lab1.rkt"

Note that as a special case of all this, if you use a path like

"awesomeness.wav"

... it will refer to a file in the current directory.

NOTE FOR WINDOWS:

A couple of things are different about windows. First, the root directories are associated with letters. So, you might find your files on the "C drive". A typical location is for program files to occur in

"C:/Program Files/"

Please note: some of you are about to yell at me, because I used *forward slashes* here. It’s true that Windows paths are typically written with backslashes. Unfortunately, in Racket and Java and Python and C and every other darn language, the backslash is used as a special "escaping" character, which means that if you want a backslash in a string, you need to write *two* backslashes in a row. So, a string containing the characters ’C’, colon, backslash, and the letter ’x’ would be written as "C:\\x". That’s a string of length 4. Sigh. Fortunately, Racket allows you to use the path with the forward slashes, instead.