Lab 4
In this lab, use make-pstream and pstream-queue and pstream-current-frame to trigger your sounds, so they don’t wind up on top of each other. To find out more about these three functions, use help desk.
No design recipe steps are required unless the item says "develop", as in "develop a program" or "develop a function".
Also, the rsound library provides several functions like sine-wave and sawtooth-wave that ... are probably not helpful to you. Using these functions will lead you into the world of signals, and we haven’t covered that in lecture at all, at this point. I would advise you instead just to use the same setup in the lab that we did in Monday’s lecture (the code for this lecture appears online, on Piazza).
Using rs-read/clip, extract a sample from a song of about ten seconds.
Using functions you know, add that sound to itself, delayed by 10000 frames, and play the result. Use rs-scale to lower the volume to 0.5, so that it doesn’t distort.
Once again, add that sound to itself, delayed by only 10 frames. How does it sound? Try it with 10, 5, and 2 frames. Write a comment describing how they sound.
Change your language level to "Intermediate". Yay!
Next, we want to reverse this ten-second sound. In order to do this, we need a function that describes what samples are in the new sound. More specifically, we need a function that maps frame number to sample. (Note: we’re going to ignore the right channel, and use only the left channel, for now.) As a warmup, use a comment to write down what the first four samples of the new (reversed) sound should be. In order to figure it out, use rs-ith/left on the old sound.
Next, develop a function called revsnd that accepts a frame index (natural number) and returns the correct sample for the reversed sound. Be sure to follow the steps of the design recipe.
Using indexed-signal and signal->rsound and the function you just wrote to reverse the sound. Play it, and make sure it’s backward.
Following a similar set of steps, develop a stretchsnd function to stretch the sound out by a factor of 2, duplicating each sample twice. How does it sound? Write your answer in the form of a comment.
Following a similar set of steps, develop a sinesnd function that produces a sine wave of 440 Hz. Play it.
The following five steps are awesome, but optional. Please note that the final big-bang program at the bottom is *not* optional, so you should probably do that one first.
OPTIONAL: Next, multiply the sampled sound by that sine wave of 440 Hz.
OPTIONAL: Construct a sawtooth wave. This is a wave that goes from zero up to 1.0 in a smooth sloped line and then jumps back to zero again. Your wave should have frequency 300 Hz. That is, it should jump back to zero 300 times per second.
OPTIONAL: multiply your sampled sound by a sawtooth wave.
OPTIONAL: construct a square wave. This should be 1.0 for a period of time, and then 0.0 for the same period of time, then continue to alternate between 1.0 and 0.0. It should complete a single cycle of high/low 250 times per second, making a wave of 250 Hz.
OPTIONAL: multiply the sampled sound by the square wave.
1 Project 2 warmup
As a warmup for project 2, develop a program that shows a set of four empty circles. Hitting the "1" key toggles the first circle from empty to blue and back again. Hitting the "2" key toggles the second circle from empty to red and back again. Continue with the third and fourth circles mapping to the "3" and "4", keys, with the colors purple and green. Hitting any keys in any order should toggle the appropriate circles. So, for instance, if I start the program and hit keys 4, 2, and 4, then the second circle should be red, and the others should all be empty.
Think carefully about the world state for this program, and how you’re going to represent it.