Change Contents of the Bubble
Welcome to CS1315. Click on the python to add comments.

Looking for the book? They have it at the Engineer's Bookstore at 748 Marietta St NW. Here is there website: http://www.engrbookstore.com/ - Monica

Hotspots: Slides and CodeTA CornerComments?AnnouncementsFAQStatic Webspace
View this PageEdit this PageUploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Homework 4 Questions- Spring 2008

Questions?

Where can I find more music notes to work with? The only ones in the file are C, E, and G, I believe. Thanks.
Asked and answered down the page. Thanks! Brittany Duncan

Should we call the homework hw4.py? The instructions say hw3.py.
Changing that now. Sorry. Thanks! Brittany Duncan

Are there supposed to be only 14 sound files in the sound folder we had to download? And are we allowed to use the bassoon sound files along with all the other sound files we downloaded in the Media Sources folder we downloaded in the beginning of the semester?
Yes to both. Thanks! Brittany Duncan

Can someone please clarify what the 15 different sounds are? If two sound files are played in a row twice, like s1, s2, s1, s2, does that qualify as four sounds even if they don't overlap?
How about 15 different notes? Basically use 5 different sound files at least 15 times. Thanks! Brittany Duncan

is the TA going to use setMediaPath() before grading? Otherwise I don't know any other way to import the sounds into JES.
Yes they will – just like the other homeworks in which you used getMediaPath. Colin Potts

Is it possible to manipulate the sound files you gave us to make them sharper or flatter? Ex: manipulating a sound file that plays the note F to sound like F#
This is really difficult. You can fairly easily go up an octave by doubling frequency just by copying every other sample. Code for that will be available on the Coweb shortly. I think that a fifth is 1.5 times the frequency, and if so, you could transform a C into a G, for example (if you didn't already have the sound) by copying two out of every three samples. But changing by just a semitone would require you to know the exact ratio of the frequencies of an F and F sharp. If you take CS 1316, you can do stuff like this in Java, but for now I recommend sticking to C major. Colin Potts

Would it be possible to move the due date of the homework maybe to Wednesday, March 12th at 11:55 P.M.? Especially since we were informed in class today that a concept that would be useful to use in the hw would be gone over on Friday. This way we would be able to have more time to go to office hours to get help. Thanks!
Sure. No problem. Colin Potts

can you post the assignment on t-square?
Up now. Thanks! Brittany Duncan

So is this homework really due monday or wednesday?
Definitely NOT Monday. It seems that the week before Spring Break is an assignment and test magnet for many classes, so having some extra time is reasonable. We will post an official announcement soon and change the homework assignment page to reflect that. Colin Potts

what do the instructions mean when they say "at least two functions must return a value"? What is returning a value?
This is what happens when you miss class. You're asking about a concept that has been discussed on several occasions and is illustrated in many examples posted to the slides/code page. You can also catch up by reading the textbook. (Start with the index.) Colin Potts

When you say that "For at least three of your sounds, you must let them overlap on the canvas" do you mean that we must blend 3 sounds together throughout the entire audio clip, or that we have to blend 3 sounds together at once at a certain point during the clip, or that at least three separate sounds must be blended with some other sound on three separate occasions?
A minimum of 2 sounds must be blended on at least 3 occasions throughout the clip. Thanks! Brittany Duncan

Are comments within our code counted towards the number of lines in a function? I need to know so my functions will be under the limit allowed by the homework guide lines. Thanks.
No. This makes life more difficult for us, but easier for you. Colin Potts

Is there a way to shorten the time gap between sounds when using blendCopy more than once? When I play individual sounds by themselves they play one right after the other but when blended there is a slight delay between the next set of blended notes making my song sound awkward.
That is because blendCopy makes an empty sound that is longer than the longer of the two sounds it is given. So if you use it repeatedly and then add the resulting sound, you will have gaps. You would be better off starting with addInto, wouldn't you? Unlike blendCopy, addInto takes a sound (possibly silence, possibly already copied into) and adds another sound into it. You already should have created a long sound that you are going to add into. You will have to supply another argument to say where you want the added sound to go, since the published function only adds at the very beginning. Colin Potts

What are some examples of functions that we could use to meet the 4 function quota on our homework? I know that overlaying multiple sounds could be one, and also making a sound longer, but what other functions could we use?
Think about what your program is doing by describing it in English. Every time you use the words "and" or "next", you've probably finished describing one possible function and are about to describe the next one. It's really up to you: any more advice is giving this to you on a plate. Colin Potts

What is the difference between getSampleValueAt, getSampleObjectAt, and getSample?
getSampleValueAt takes a sample number and gives you the value of the sample at that position. So if you have 22,050 samples per second, and say x=getSampleValueAt(22050) you will get the value of the sample at the end of the first second (i.e. a number between -32k and +32k). If you do s=getSampleObjectAt(22050) you will get a sample at that position. This is very like p=getPixel(x, y) for pictures. A "sample object", like s in this case, is a sample (i.e. the smallest element of a sound), not a number. Finally, having got your sample, s, you can type x = getSample(s). This is confusing, but that's just the way things are... give getSample() a sample object and it will give you NOT a sample as the name would suggest, but that sample's value (a number). Experiment in the command area by making a sound and then trying these functions out. Colin Potts
I strongly, STRONGLY recommend using getSampleValueAt() primarily. Every sort of manipulation we'd ask you to do can be done with it, in a fairly straightforward way; the others are, as Colin said, a bit confusing. getSampleValueAt() allows for a comparatively easier way to manipulate just portions of a song, as well. Chris Phillips

def makeMusic():
  sound1 = nearlyScale(dir, str(string))
  sound2 = nearlyScale(dir, str(bassoon))
  blendCopy(sound1, sound2)


I have this and it's saying that string and bassoon are variables that are not found locally or globally. I need to define them somehow, but I'm not sure what to do. I just need the word "string" and the word "bassoon" in order to insert them into a filename, so I don't see why I should have to define random input variables...
You aren't really understanding the concept of casting variables as strings. You are trying to make the string variable a string. Instead, you just need to tell JES that string is a word when you create it, by saying "string". If you still don't understand, please see a TA at office hours or read in the book about filenames. Thanks! Brittany Duncan

I thought that if you return a variable that is changed by a function, you can use the changed version of the variable anywhere else in the code after you run the first function. For some reason, it doesn't work for me.
The returned value is available in the function that made the call, not in any function. By analogy, if a manager (function1) asks a subordinate (function2) to generate a report (the returned value), the manager can use the report. But other employees (including the manager's own manager) cannot unless the manager gives it to them. Colin Potts

fileName = str(dir) + os.sep + "string-" + note + "4.wav"
      sound = makeSound(fileName)

JES keeps giving me an error on the second line of this code saying that there is no file at C:\Documents and Settings\Me\My Documents\musicSounds\None\string-e4.wav . The problem is, I have no idea where "\None" is coming from in that directory. When I setMediaPath for the directory, I set it to C:\\Documents and Settings\Me\My Documents\musicSounds , so I don't know how the "\None" came to be.
If you are using setMediaPath(), then try using this line instead -

fileName=getMediaPath("string-"+note+"4.wav") Chris Phillips

What does this mean?

the code the error is for is
 setSampleValueAt(canvas, position+start-1, value)


makeMusic()
The error was: That index 13230600, does not exist. The last valid index is 13229999
I wasn't able to do what you wanted.
The error SoundException has occured
SoundException: That index 13230600, does not exist. The last valid index is 13229999
Please check line 44 of C:\Documents and Settings\Ryan\My Documents\HW4.py
You're falling off the end of your sound canvas. Either you didn't make it long enough to accommodate all the samples you are copying or the value position+start+1 is wrong and you really should be copying to a lower sample number. Colin Potts

In regards to the above question about the return function: If I have a function call another function that returns a variable, am I supposed to be able to use the variable in the first function after it calls the second function?

(example)
def mainFunction():
   def subFunction(variable):
      return variable

Your example doesn't illustrate your question. In answer to your question: No. With regard to your illustration: (a) Don't forget to add code tags on so that your code is readable on the Coweb. (I have done this for you). (b) You are trying to DEFINE (not use) one function inside the definition of another. (c) It's not a good idea to return a variable that was passed in as a parameter (the variable named "variable" in your case). It's better to create a variable inside your function that you will return. Colin Potts

My program works, it returns a somewhat recognizable tune, however, it takes about 5 minutes to do this and it copies not only the 24 notes that I want to play, but also about 8 minutes of blank sound after that. What do I do to decrease the time it takes to run the program and get rid of the blank space?
You possibly copied the code that I posted intitially. I corrected it last week. The error is in the line of code that creates the blank canvas. (Well, that's obvious, isn't it?) And it must be making a canvas that is many times (hint, hint) too long. I don't know whether this will shorten the execution time. That could be a sign that you have also nested your loops incorrectly. Colin Potts

If I create a variable inside a function and then return it, it will not let me use it in the main function. (The main function calls the subfunction which returns the variable.) It says "Name not found globally" "You need to define a function or variable before using." The only way I can use a returned variable outside a function is if I pass it through as a parameter. Am I doing something wrong?
Are you storing it in a variable when it is returned? For example: "value = subfunction(foo, bar)" Thanks! Brittany Duncan

so a blend function with 3 sounds only produces 1 note? if i have 12 functions, and each one takes in 1 sound, then i only have 12 notes? i can't add any more functions because if i do, i go over 30 lines for my makeMusic function. how is this possible?
That would only produce one note, but why are you having 12 functions take in 1 sound? Why don't you just create 5 sounds and use those? This is very possible. If you are still confused, please see a TA at office hours or speak to someone on AIM. Thanks! Brittany Duncan

the assignment states that we should save the file as hw4.py. do we have to add the ".py" or is that added by JES when we save it?
You have to add it. Chris Phillips



Link to this Page