CS
110 Spring 2012
Homework07: A Sound Editor
Part I Due: Monday, April 9th at 11pm
In Homework 07, you will create a GUI-based sound editor. In the description that follows, we will outline a basic set of required elements, but you are encouraged to be creative and to define other manipulations to make the program more complete and more interesting.
Part I: The Manipulation of Sounds
As we have learned in class, the Sound objects that we create in our programs are complex, aggregate objects that have, as part of their makeup, a large number of Sample objects in an ordered collection, and that these sample objects are themselves aggregate, and composed of sample values, including left and right stereo channels, as well as information that ties the sample back to the sound.
In the abstract, we can think of sounds as a list of integer samples, and it is easier to manipulate lists of integers. So to make the Sound Editor project more manageable, we break the problem into two parts:
- Functions to translate back and forth between the two representations -- taking a sound and creating the corresponding list of integers, and taking a list of integers and creating the corresponding sound.
- Functions for manipulating lists of integers that correspond to the set of operations we wish to perform on sounds.
Part I of this assignment separates the function types described above from the graphical user interface that presents the sound editor to the user. The deliverable for Part I is a main() function along with definitions of all of the functions described below. The main() function will interact with the user to get the information need to drive the testing of the sound manipulations and demonstrate their correct operation. You will be graded on both the manipulation functions and on the devising of your main() function and how well it demonstrates your work.
I-A: Converting between Representations
We require two conversion functions. One to go from a Sound object to a list of integers, and the other to go from a list of integers to a (newly created) Sound object.- vlist = getValueList(sound): where parameter argument, sound, is a reference to an existing (already created) sound object. This function should create and return a list of integers representing the set of sample values from the given sound. The length of the returned list should be exactly the same as the number of samples in the given sound.
- newsound = soundFromValues(vlist): where parameter argument, vlist, is a reference to an existing list of integers. This function creates a brand new empty sound with a number of samples equal to the length of the integer list and then populates the samples of that sound with the values in vlist.
I-B: Sound-motivated functions to manipulate lists of integer samples
The following list documents the set of required functions for the manipulation of the lists of integers for use as building blocks in our sound editor.- vlist = sublist(listin, start, end): where parameter argument, listin, is a reference to an existing list of integer samples, and start and end are indices between 0 and len(listin) - 1. This function should create and return a list of integers containing the values from listin between (and including) index start to index end.
- vlist = backwards(listin): where parameter argument, listin, is a reference to an existing list of integer samples. This function should create and return a list of integers containing the values from listin, but in reverse order.
- vlist = splice(first, second): where parameter arguments, first and second, are references to existing lists of integer samples. This function should create and return a list of integers containing the values from first followed by the values from second.
- vlist = merge(listin1, listin2): where parameter arguments, listin1 and listin2, are references to existing lists of integer samples. This function should create and return a list of integers obtained by adding the values from the two lists for all the indices in common. If one list is longer than the other, then the newly created list should also include these remaining suffix values.
- vlist = merge(listin1, listin2, offset): where parameter arguments, listin1 and listin2, are references to existing lists of integer samples. As above, this function should create and return a list of integers obtained by adding the values from the two lists, but this time, the prefix in listin1 from 0 up to, but not including offset should be copied to the new list, and then we add together values from the two lists where offset in listin1 aligns with 0 in listin2, and so forth. If one list is longer than the other, then the newly created list should also include these remaining suffix values. This function should be considered extra credit.
- vlist = scale(listin, factor): where parameter arguments, listin is a reference to an existing lists of integer samples, and factor is a real valued number. This function should create and return a list of integers obtained by, for each element of listin, multiplying the element value by factor, and then creating the integer value of the result.
- vlist = fade(listin): where parameter argument listin is a reference to an existing lists of integer samples. This function should create and return a list of integers obtained by traversing the original list and decreasing the amplitude of subsequent samples by ever increasing amounts so that the result is a smooth scale factor progression from 1.0 down to 0.0.
- vlist = freqscaleup(listin, rate): where parameter argument listin is a reference to an existing lists of integer samples. This function should create and return a list of integers obtained by traversing the original list and undersampling by rate. So if rate were 3, the resultant list would take every third sample from the original list. This function should, in essence, compress the original list by a factor given by rate.
- vlist = freqscaledown(listin, rate): where parameter argument listin is a reference to an existing lists of integer samples. This function should create and return a list of integers obtained by traversing the original list and oversampling by rate. So if rate were 4, the resultant list would repeat every sample from the original list 4 times. This function should, in essence, expand the original list by a factor given by rate.
- As another extra credit possiblity, you should combine the freqscale up and down into a single function whose rate is a real value. Values greater than 1 are scaling up, while fractions less than 1 are scaling down with 1/rate giving the amount to scale. This extra credit function should process the list properly when fractional rates are used. So a scale by 1.5 should properly expand the list by one and a half times, and so the algorithm becomes more involved than just taking every nth value.
I-C: Driving the functions through their paces
Part of your grade for the Sound Lab Part I will be the demonstration of your functions. You should write a main() function that goes through and thoroughly demonstrates the correct operation of all of your sound functions, with multiple test cases for each function. Be sure to to test, for example, a merge where the first sound is shorter and a merge where the second sound is shorter.If your main() function execution sequence depends on particular sounds in order to test correctly, you should inlcude a README file (simply a text file) with instructions on the appropriate way to run your main() function.
Submitting your lab
Please make sure that your lab07 directory has the following file:- soundeditor.py
- README (if needed)