CS 101 - Introduction to Computing, Spring 2007

Lab 10

Reminder

The program Jython Environment for Students (or JES) is the development environment that we will use for this lab.

In the ACCC Labs that have JES, it can be found by:

  1. Clicking on Start
  2. Then click on All Programs
  3. Then click on Class Applications
  4. Then click on Engineering
  5. Finally click on Jython Environment for Students

Converting from Seconds to Sample Index

This lab assignment will have you write a function that will play a portion of a sound file. The JES function playInRange() will be the basis of our new function. However, we want to specify the portion using seconds and playInRange() uses index position to specify the starting and stopping locations of the sound. Thus we will need to convert from a position in seconds to a position index.

The JES function getSamplingRate () will allow us to convert from index to seconds and seconds to index. This function returns the number of samples in each second. Thus if we know the total number of samples in a sound (this can be gotten from getLength()), we can determine the length in seconds by dividing by the sampling rate. However, if we know a position in seconds, we can determine the sample index by multiplying by the sampling rate.

The following functions will be useful with this assignment.

getLength
getLength(sound):
sound: the sound you want to find the length of.
returns: the number of samples in sound.
Takes a sound as input and returns the number of samples in that sound.
getSamplingRate
getSamplingRate(sound):
sound: A Sound, the sound you want to get the sampling rate from.
returns: An Integer representing the number of samples per second.
Takes a sound as input and returns the number representing the number of samples in each second for the sound
playInRange playInRange(sound, start, stop):
sound: A Sound, the sound you want to play a piece of.
start: A Number, the index of the sound you want the playback to start.
stop: A Number, the index of the sound you want the playback to stop.
Take a sound, a start index, and a stop index and plays a selection of the sound defined by the start and stop indexes.

Lab Assignment 10

Due: Tuesday 4/3/2007 by 11:59 pm

Create a file using JES that will:

  1. Contain a comment indicating

  2. Contain a JES function called playSoundBetween () that will If one of the verification checks fail, print out a descriptive error message and return from the function without playing the sound. The time in seconds can be given as a floating point number (with a decimal point). So you can play from 2.25 seconds to 4.875 seconds.

    Note: The time of the beginning of a sample is 0 seconds. However, the first sample has index of 1. Because of this, you may need to add 1 to the result of the sound to index conversion.

  3. Contain a JES driver function that will:
These functions may call other functions that are built-in to JES or that you have written.

Here are some example sound files you can use with this assignment.

Submittal of the Lab Assignment

Comments on the ACCC Labs

On the computers in the ACCC Labs there should an H: drive. This drive is actually a networked connection to your own file space maintained by the ACCC. No matter what machine you use or what lab you are in, the H: drive will access the same file space. This means that you can save a file on the H: drive on a computer in one lab and access that same file on a computer in another lab. This can be very helpful. It is suggested that you store your python program files on your H: drive.