CS 107: Pictures and Sounds: Programming with Multimedia

Kalamazoo College

Spring 2008

Mini-Lab: Cropping Sounds

 


Introduction

The objective of this mini-lab is to practice working with sound in JES.


More work with copyInto + Cropping

  1. If you didn't have the opportunity in Lab, write a new version of your copySoundInto function, copySoundIntoAtSec, that takes as a parameter the number of seconds into the tape to start copying, instead of the number of samples. You can accomplish this by converting the desired number of seconds to the corresponding number of samples, and then making a call to copySoundInto. The function getSamplingRate will be helpful for making the conversion. Keep in mind that getSamplingRate returns a real number, not an integer. That means that any value derived from the sampling rate will need to be converted to an integer using the int function before it can be used as an index value.
  2. Earlier in the course, we looked at cropping images. We can do something similar with sounds. Write a function called cropSound which crops a section of a sound and returns just the cropped piece. Your function should take as parameters the sound, the index to start cropping, and the number of samples to include in the cropped sound.
    Design Questions: How big do we want the resulting sound to be? Does it depend on how long the original sound is? How do we know how long the original sound is?

  3. If you have time, write a new function, cropSoundByTime that takes three parameters: the sound, the number of seconds into the sound to start cropping, and the number of seconds to include in the resulting sound. You should be able to accomplish this by making a call to the cropSound function. The resulting function should only be 2-3 lines long.

Print your results

  1. Print the completed functions and hand them in.