Spring 2007 Homework 4 Questions
Questions?
I'm working along with the book and tried this code(pg154):
def increaseVolume(sound):
for sample in getSamples(sound):
value= getSample(sample)
setSample(sample,value 2)
but when i try to run the code i get this error:
>>> increaseVolume(s)
The error was: You are trying to access the sample at index: 220568, but the last valid index is at 220567
I wasn't able to do what you wanted.
The error SoundException has occured
SoundException: You are trying to access the sample at index: 220568, but the last valid index is at 220567
Please check line 3 of C:\Documents and Settings\Me\My Documents\Code\Practice\increaseVolume
what's wrong???
on the hw4. How the TA will grade area which is very bottom of the hw4 page.
Number 7 - type play(makeMusic()) into the command area means play(makeMelody()) instead?
| Its supposed to be makeMelody(). I changed it now. - Bobby Mathew |
Prof. Stallworth said today that he wouldn't post what functions he used in class on the website. Those functions always help me understand how things such as makeSound, getSampleValueAt, setSampleValueAt, etc. work... in PROPERLY working code. Without them, I'm left with just the book, which quickly overviews the functions and moves right on. There's nowhere else other than GT to get help with JES, and I'm getting frustrated with the level of support here.
| You can also check the code that I posted to the website. I think that Cedric meant that he wasn't going to post code that duplicated mine and that was too close to homework solutions. You will see in my code that there are gaps that you have to fill in for yourself. Regarding office hours, I saw TWO students during my Monday office hours last week and ZERO the week before. By all means come and see me if you need help. Colin Potts |
I understand you don't want students using it as a crutch, but come on. If the professor hides half of the code during the lecture, people copy that part down, and now we're all left with code that doesn't work at all, and no way to intuitively figure it out. Sorry if this sounds whiny, but I'd rather not go to recitation if everyone just mobs the T.A. for individual help because none of us know what's going on, and we don't have any framework for our homework.
| Try going to recitation, where the TAs lead a class and show you how to write code in that works properly. After that lecture (if that's what you want to call it) the TA's will help with extra work, but I've yet to be bombarded with students after class wanting help. Amanda Bennett |
I can't get my makeBlank sound function work. I think I am putting in something wrong in the part writeSoundTo(song,'something.wav'). (for example)
my code looks like this
def makeBlank():
song = makeEmptySound(10)
# This is where you need to put your splicing code so that you are writing out the final song in the next line not the blank sound. (Colin Potts)
writeSoundTo(song,'myname.wave') # I'm not sure whether ".wave" will play. It should be ".wav". Of course you won't hear anything in any case.
How do I get this to create the blank sound for my melody??? If I got this right then I could really get started on the rest of the functions!
I did indent in my code above, but the post screwed it up.
| You're on the right track. What you're doing is writing out the blank 10-second sound, but there is no need to do this. See the comment I inserted in your code above. I also put code tags round your code. This preserves your indentation. Click on the edit button above to see the tags. Colin Potts |
Just wondering – I deleted the old JES and then downloaded the new JES from coweb. The zipped file JES 3.0.3 downloads without a problem, but when I run JES and open up the Help tab and then "About JES" it tells me I am running version 3.0.1. I have deleted and re-downloaded the new JES twice thinking I could have somehow made a mistake, but the same information is displayed. Have I done something wrong, or is this indeed the correct version?
Teacher told me that's right version if you downloaded new version of it
| The help page has not been updated on the PC version, but it really is version 3.0.3. so don't worry about that. Colin Potts |
I had the same problem. I deleted the older version of JES twice and downloaded the newer version from the website. When I click on "About JES" I also still get version 3.0.1. Also, I tried the doubleFrequency function from lecture but when I run the function, it doesn't stop and I suspect it is because I am not able to get the 3.0.3 version.
| This should not be a problem with the version of JES (see my other responses). I tried the posted code, and it works. In fact, on the Macintosh it stops quite quickly when given one of the music sound files (about 1-2seconds for a 1-second music file). Are you using a very long duration sound file? Is anyone else reporting this problem of doubleFrequency hanging? Colin Potts |
I had the same problem as the other two. I re-downloaded it a bunch of times, but it's 3.0.1, not 3.0.3
| The help page has not been updated on the PC version, but it really is version 3.0.3. so don't worry about that. Colin Potts |
for my line:
getSampleValueAt (target, target_index, value)
it gave me an error:
The error was:getSampleValueAt() too many arguments; expected 2 got 3
Inappropriate argument type.
An attempt was made to call a function with a parameter of an invalid type. This means that you did something such as trying to pass a string to a
method that is expecting an integer.
but that was the code we were shown to use in class. whats wrong?
| I think you are confusing the functions to get and set sample values. If you are getting a sample value, why are you giving it a value? The error message is right: you only need to provide two arguments. BTW, this is an excellently worded question, because you give enough details to diagnose the problem instead of simply saying, as some students would, "help: getSampleValueAt doeesn't work. What did I do wrong?" So, thanks. Colin Potts |
Was the homework changed ? I don't see the getMediaPath that used to be in the homework
The songs I downloaded didn't sound like they included all notes in a scale. I wonder if I am missing any? Are all the notes within the same octave?
| You have to play them in ascending order CDEFGAB. It isn't an entire octave, because there are only seven notes provided, but you can create other notes by doubling or halving frequencies of the provided notes. Colin Potts |
For hw4, do we have to come up with a completely original piece of music? Or are we allowed to try to reproduce a tune we like?
my computer wont ever finsh downloading the new version of JES. its gets almost through extracting then says the zipped file is empty w/ no more to extract. what should i do?
| This is weird. I tested this on my home PC this morning and downloaded JES without problems. This is probably a browser/network/unzip problem. If you have a laptop, you could go over this with a TA. If you have a desktop machine, it will take longer for us to diagnose. In the meantime, you could try downloading version 2 from the archive website (there is a link on the software page for older versions) or install version 2 from the CD-ROM. If downloading the older version also gives the same problem, you definitely have a software problem on your PC. If not, go with the older version for the homework. You won't be at any disadvantage, but we do need to work out what is wrong before we get to turtles later in the semester, as they are new in Version 3. (BTW, the only older version you should download is version 2. In the earlier 3.0.x. versions, sound does not work properly.) Colin Potts |
also, how do i completely erase all of the old JES stuff? (i know that just sending it to the recycle bin doesnt do it). thanks!
| Sending it to the recycle bin and then emptying it will do it. JES is a stand-alone program and set of files. It doesn't change your registry or add anything to your system folders. But until you sort this problem out, unless you are really short of diskspace you should probably keep your old version in a backup folder. You can keep multiple versions without any problems as long as you remember which one to run. They won't interfere. Colin Potts |
I am writing this into JES:
sound = makeEmptySound(7)
but it only gives me 7 samples to write using the setSampleValueAt(target, index, value). But if I only write 7 samples, it does not play anything when I play(sound). How can I get more samples to write with the makeEmptySound(7)?
| Seven samples is such a short sound, that you probably won't hear anything other than a click, if that. The argument to makeEmptySound is in seconds, not samples. If you type getLength(sound) you will see just how many samples that is. (All the other samples after the first seven will be zero.) You can only write that number of samples practically by copying them from other sounds using a for loop. Colin Potts |
This is what I have to show that makeEmptySound(7) only has 7 samples:
def makeMelody():
target = makeEmptySound(7)
brassB = makeSound("brass-b4.wav")
print getSamplingRate(target)
print getLength(target)
print getSamplingRate(brassB)
print getLength(brassB)
but the result gives me:
>>makeMelody()
22050.0
7
22050.0
22050
The problem is that when I set the sample by setSampleValueAt(target, index, value) and the index is greater than 7, JES gives me an error. How do I solve this?
| That's an odd problem. What version of JES are you using? I just tried to reproduce your problem, and I couldn't. Amanda Bennett |
| You're definitely using the previous, incorrect version of JES. Colin Potts |
I am trying to use the insertNote function from class on Wednesday but it keeps giving me an error. the code im using is:
def insertNote(target,target_index,note,duration):
for index in range (1,int(getSamplingRate(note)(duration))):
value = getSampleValueAt(note, index)
setSampleValueAt(target,target_index,value)
target_index = target_index+1
It says that there is an error with setSampleValueAt(target,target_index,value)
and that the error is The error was:__sub__ nor __rsub__ defined for these operands
Inappropriate argument type.
An attempt was made to call a function with a parameter of an invalid type. This means that you did something such as trying to pass a string to a method that is expecting an integer.
What is the problem? Did I leave off part of the code when I wrote it in class or is there another problem?
About JES says that I am using the new JES, JES- Jython Environment for Students version 3.0.1, it's the new one I downloaded. Should I use version 2.0 instead?
| The code posted above contains a syntax error and gives a different error from the one you are reporting. The error is in the range, not setSampleValueAt. You need to multiply the sampling rate by the duration using the * operator. If you fix this and make sure that you provide a valid value for duration (not too long), the function works. Actually, you don't need to go to all this trouble, since all the notes you are using have the same sampling rate. You could simply use a range from 1 to getLength(note). If you get the error you are reporting, you are not using the latest version of JES. There is no need to go back to version 2: just download updated version that was posted this week. Colin Potts |
Maybe this is obvious and I am just missing it, but where is "the code posted to the website" ?
| A page linked from the Syllabus has links to Powerpoint slides and code shown in class (from the beginning of the semester actually ;) ). Colin Potts |
Is our code supposed to say play(canvas) or is it not? Because number eleven in the instructions says "makeMelody will return the sound when it is done, but it must not play the sound." Does this mean I just need return canvas in stead of play(canvas)? Thanks so much!
| That's right. Just return the sound, don't play it. The TA will play the returned sound when testing your code. Colin Potts |
Is there any way to incorporate the slice code and the halve frequency doe together so that if we want to lower a not we don't rewrite the initial sound given to us so that we can use it later on? I tried a haphazard way of putting them together (poor attempts with my low level of computer knowledge!), but my sound just ends up not transferring to the canvas. Here was a guess that obviously doesn't work!
def spliceAndLowerPitch(sourceSound, n, destSound, location):
lastSample = (getLength(sourceSound))/n
for fromSample in range(1, lastSample):
srcIndex = 1
for destIndex in range(1, (getLength(destSound))/n):
sample = getSampleValueAt(sourceSound, int(srcIndex) )
setSampleValueAt(destSound, destIndex, sample)
srcIndex = srcIndex + 0.5
return destSound
sourceValue = getSampleValueAt(sourceSound, fromSample)
destValue = getSampleValueAt(destSound, location)
setSampleValueAt(destSound, location, 0.5*sourceValue + 0.5*destValue)
location = location + 1
return location
Thanks so much!
My indentations just didn't hold over, so here are the line indentation groupings:
lines 2,3,and14 go together, lines 4,5,9-13 go together, and lines6-8 go together.(sorry this is so crazy!)
| If you edit the page, rather than using the box at the bottom, and surround your code with code tags, indentation is preserved. Check it out. Colin Potts |
The function works by itself, but not when called upon in the make melody function. this is the error I get
The error was: You are trying to access the sample at index: 22050, but the last valid index is at 22049
I wasn't able to do what you wanted.
The error SoundException has occured
SoundException: You are trying to access the sample at index: 22050, but the last valid index is at 22049
Please check line 53 of C:\Documents and Settings\Ashley\My Documents\hw4.py
Again, thanks!
Is it ok if we try to make a reggae melody ?
| It doesn't work, because your blank canvas is not long enough. It is trying to write a sample to a space that doesn't exist. Your melody can sound however you would like. -Brittany Duncan |
Is there any way to make sharps?
I downloaded the new JES 3.03, but I can't open it. I tried updating java and restarting but I still can't open it.
help!
When I did writeSoundTo and saved it to my computer it worked fine. But then when I tried to play it back, there was no sound. Am I doing something wrong?
oh actually I downloaded 3.04..
I am having trouble making notes flat. I would assume that, similarly to process for doubling or halving the frequency, I would need to decrease the frequency by some value between 0.5 and 1, correct? Thanks.
After I added the mirrorSound() function, my melody started playing raspy sounds towards the second half. Should it sound like that or is there something wrong with my code? In addition to the mirrorSound function, I have the increaseAndDecrease() function, which increases the volume and then decreases the volume. Could the combination of these two codes be the cause of the raspy noises?
| I would guess that when you increase the values, you are trying to increase beyond the maximum value. That will create the rasping noise. Decreasing the values afterward will only make the raspiness quieter; it won't make it go away. Either try decreasing first or normalizing. (BTW, why are you mirroring anyway?) Colin Potts |
when i type play(makeMelody()) in the command area it gives me an error even though my function is named makeMelody() and it plays in the sound tool. play(sound): Input is not a sound.The error was:
Inappropriate argument value (of correct type).
An error occurred attempting to pass an argument to a function.
| Does your function makeMelody() return the sound canvas that you are adding the notes to? It should contain a return command at the end. Colin Potts |
Is there a way to see the notes for these as sheet music or on tabs ? If not then I'd just like some clarification on what the notes are, is brass c4 the 4th string c or ... ?
| The number in an note like D4 is the number of the octave. The C is the lowest note; the B is the highest note. If you halve the frequency of C4 [oops. I mean "double the frequency"], the resulting note should be C5, which should be the final tone in the scale after B4. Colin Potts |
does a chord with 3 notes count as 3 notes towards the required 10 or just 1?
When I type in play(makeMelody()) I get an error that says:
Inappropriate argument value (of correct type).
An error occurred attempting to pass an argument to a function.
It still returns my sound tool, but it gives me that error.
any advice on this?
| In your function makeMelody() do you return the sound? Colin Potts |
I have my code where it should create a melody, however when I run my function (which at the end opens the sound tool), the sound tool is blank. I have put in return (note), but still nothing shows up. What could I be missing??
| You could be returning the empty sound that you create as your sound canvas. In between you should be writing sample values into it, but there must be something wrong with where you are writing. Maybe you are writing the same sample over and over again (indentation error). Show your code to a TA. It could be a really simple fix. Colin Potts |
what would be an algorithms to get a sharp or flat all i seem to be able to do is make it go up an octave but would a sharp be a 1/12 step up? so how would i increase it by 1/12 if JES does not understand anything less than an integer?
I'm working along with the book to try to teach myself how to do the homework and I'm running into an extreme problem. I can't make the getSamples command to work. It's not doing what the book says it will. Instead, it starts running and then JES freezes every time. I updated JES before tryin all of this too. What's the problem. Here's what i'm putting into the command line.
>>> file = pickAFile()
>>> sound = makeSound(file)
>>> samples = getSamples(sound)
>>> print samples
| getSamples() doesn't work correctly in JES 3. I announced this in class, and for the homework you only should be using getSampleValueAt() anyway. In the example above, if you try to print samples - even if it did work - you would get a HUGE list of sample details. Think about doing the analogous thing with makePicture() and getPixels() and then print pixels! Definitely not something you want to do. Colin Potts |
| Here's another try at doing the code correctly. Thanks! |
def spliceAndLowerPitch(sourceSound, n, destSound, location):
lastSample = (getLength(sourceSound))/n
for fromSample in range(1, lastSample):
srcIndex = 1
for destIndex in range(1, (getLength(destSound))/n):
sample = getSampleValueAt(sourceSound, int(srcIndex) )
setSampleValueAt(destSound, destIndex, sample)
srcIndex = srcIndex + 0.5
return destSound
sourceValue = getSampleValueAt(sourceSound, fromSample)
destValue = getSampleValueAt(destSound, location)
setSampleValueAt(destSound, location, 0.5*sourceValue + 0.5*destValue)
location = location + 1
return location
I hope this works and shows correctly now!|
When i put, play(canvas) in my code, the notes play fine, but when I take that out of my code, and put play(makeMelody()) in the command area, which is what the TA's will write, it says that makeMelody is not a sound. How can I fix this?
| If it says that it is not a sound, then you are not returning a sound. Colin Potts |
are we required to have at least 3 defined functions (def .....) or do you mean JES functions like get(),set(), for loops, etc..?
my function works when i play it in JES, but when I return it and write it to my folder, it plays for the right amount of seconds, but no sound is produced. what am i doing wrong?
how many points are deducted if i dont use 3 defined functions? i cant find anyway to split my code up into 3 functions and get it working properly
can you explain how to do the writeSoundTo function? I already got the hw and posted it to sakai but this step is confusing me. thx
how do we upload our "music" to the sound collage page? I have the file on my desktop.
I keep getting an error at setSampleValueAt(canvas,index,value). How can I correct this error?
WHAT IS THE LOCK PASSWORD??!!!
So what should we do if when we try to upload to the sound collage page and when we view the page it says Missing File (/cs1315/uploads/gtg337x.wav)??
I keep getting Missing File too. How exactly should we save our sound and then type it into the sound collage page so that it works correctly??
is hw4 late if we submit b4 11:45 and after 6:45 2day cuz on sakai it says due at 6:45 and it said mine was late?????????
Nevermind...I figured the posting thing out. For the person who posted under me, go to the sound collage page and click the attach button, not the edit button. From there you will be able to browse your computer to upload the file.
what if my attachment shows up on the attachment page but not on the main sound collage page?
I have just uploaded my song to the sound collage page, but when I open the file, a questionmark appears on my screen. Any idea of what I am doin wrong?
I posted my sound file to the collage page last night and then checked to see if it worked, and it did. I am now on another computer and cannot find my file on the same page. Why would this be happening?
Link to this Page