Lab 2:   Arithmetic of sounds
1 Getting RSound installed
1.1 NOTE FOR WINDOWS USERS
2 Playing sounds
3 File Systems
6.11.0.2

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 Getting RSound installed

Next, in order to use sound in DrRacket, you’ll need to have the "RSound" package installed.

First, choose File|Install Package..., and enter "rsound" in the resulting dialog. Click Okay, and wait for it to finish (this should take less than 3 minutes). NB: The installation is finished when the "Close" button is enabled.

Quit and restart DrRacket (this is needed to allow the creation of the preference pane for Windows users).

Finally, to check whether the installation finished correctly, enter this program into the top ("definitions") window of DrRacket:

(require rsound)
 
(play ding)

Then, type CMD-R or click the "Run" button to run the program. After about ten seconds, you should hear a ding.

1.1 NOTE FOR WINDOWS USERS

Try these instructions. If you get an error message indicating "device not available", then you probably need to change the default frame rate from 44100 Hz to 48000 Hz. To do this, go to the Preferences menu, click on the RSound tab, and make the change.

Why is this necessary? Windows machines have a variety of different sound cards, and they support different frame rates.

2 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 17.

  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 17, 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 18.

  10. Define the function string-stutter, that accepts a string of length greater than two and returns the string formed by repeating the first two characters of the string four times.

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

    Note: like the last function, this function will have to work for any sound that you call it with.

  12. Do HtDP 2e Exercise 23.

  13. Do HtDP 2e Exercise 27.

  14. Do HtDP 2e Exercise 28.

3 File Systems

Stop me if you’ve heard this one:

Super-high-level intro to file systems:

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.