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:
- Clicking on Start
- Then click on All Programs
- Then click on Class Applications
- Then click on Engineering
- 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:
- Contain a comment indicating
- your Name,
- Net-ID,
- Course Name,
- Assignment Name and
- a short description of
the assignment
- Contain a JES function called playSoundBetween () that will
- take 3 parameter values:
- a sound object
- a number specifying where you want the playback to start in seconds
- a number specifying where you want the playback to stop in seconds
- verify that the start value is less than the stop value.
- convert the second values to index positions
- verify that the start and stop indexes are within the range of
valid sample indexes for the sound
- play the sound with in the specified range.
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.
- Contain a JES driver function that will:
- prompt the user to open a sound file using pickAFile()
- create a sound abject from the file
- call the function playSoundBetween() with this sound value.
The values for the time in seconds can be "hardcoded" in your code.
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
- You are submit your program electronically by placing it in the
digital drop box in blackboard.
- Programs that are correct and
submitted by noon on the Wednesday
the lab assignment is discussed will receive an extra 10% on the
score of the lab.
- When saving your program, use a meaningful name like lab10.py.
- When submitting your lab assignment, place all of the needed files it in a
zippped folder (even if you are only submitting one file) with the name
of yournetid_labNum and submit that zipped folder to the digital
drop box. For instance, if your net id is
abc32 then the folder name should be abc32_lab10.
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.