1 Test Cases for inexact numbers
2 Functions that generate samples

Lab 8

THIS LAB IS DUE ON MONDAY, OCTOBER 17.

In this lab, I’d like you to create one test case for each function *before* you develop the function itself. Use check-expect for this.

Use the "Intermediate Student" language for this lab.

Also, to activate the drawing library, use these require lines:

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

1 Test Cases for inexact numbers

Inexact numbers can’t be tested for equality directly. That’s because... well, they’re inexact. Instead, you’ll need to use a different test case form, check-within. You can check out the documentation, but the gist of it is that you need to provide an extra argument, specifying an "epsilon" which indicates how close the two answers must be.

For instance, I might write

(check-within pi 3.14 0.01)

... and this test would pass, but the test

(check-within pi 3.14 0.001)

would not, because pi is not within one thousandth of 3.14.

2 Functions that generate samples

  1. Develop the function t, that accepts an integer n and returns the cosine of 2π*400*n/44100. Please include at least one test case.

  2. Use the function mono-signal->rsound to generate a sound using this function. Read the documentation for mono-signal->rsound to see how. Play the sound.

  3. Use the function rsound-draw to draw the sound that you generated. Zoom in by clicking on the waveform.

  4. Develop a new function sum-t that is like t but instead produces the sum of three waves of different frequencies, scaled so that the values are no larger than 1.0.

  5. Again, use mono-signal->rsound to generate a sound, play to play it, and rsound-draw to draw it.

  6. Find a piece of music online. Using rs-read/clip or clip, define a sound that is no more than 400 samples.

  7. Play the fragment. How long is the fragment?

  8. Play 100 copies of the fragment, using the times function.

  9. Draw the fragment, using rsound-draw.

  10. EXTRA CREDIT: Based on the drawing, develop a function my-t that produces a new waveform that is similar to the one you downloaded. Can you make them look and sound the same?