right now i have this in my code
def makeMusic():
canvas = makeEmptySound(7)
bc = makeSound(getMediaPath("bassoon-c4.wav"))
be = makeSound(getMediaPath("bassoon-e4.wav"))
bg = makeSound(getMediaPath("bassoon-g4.wav"))
sc = makeSound(getMediaPath("string-c4.wav"))
se = makeSound(getMediaPath("string-e4.wav"))
sg = makeSound(getMediaPath("string-g4.wav"))
#Adding Sounds
for srcSample in range(1, getLength(bc)+1):
destValue = getSampleValueAt(bc, srcSample)
srcValue = getSampleValueAt(be, srcSample)
setSampleValueAt(bc, srcSample, srcValue+destValue)
Everytime i put -return canvas- at the end of the function, the program runs but nothing plays. If i put -return bc- at the end of the function the chord I want will play. Why won't it play with -return canvas-??
| This is because you are using the sound 'bc' as the changed value in the setSampleValueAt function. If you want to have the canvas to have the sound, you need to use canvas as the first input to the function. Amanda Bennett |
if i double or half the frequency in the middle of my function, will it remain changed for the remainder of my function?
| Yes. It is just like pictures. You can change this by making a copy of the specific sound and then changing the frequency, or making the original sound again. Amanda Bennett |
I finished my project and used the writeSoundTo and then took removed it from the file... I can use quicktime to listen to the wav file i produced but I get an error in JES... this is what I get:
>>> setMediaPath()
New media folder: C:\cs 1315\LABS\HM3sounds\
>>> play(makeMusic())
play(sound): Input is not a sound.
An error occurred attempting to pass an argument to a function.
Please tell me what I am doing wrong... I think I had a similar problem with homework 2. thanks.
| Are you returning your sound at the end of your code? Toni Walden |
yes I am returning:
def makeMusic():
seven()
shiftFreqString()
spliceBass()
echoString()
then I define each function and used return at the end of the funcitons
example:
def seven():
background= makeEmptySound(7)
return background
I do the same for the other 3 functions...
| But you arent returning anything from your main makeMusic() function. For play(makeMusic()) to work, there has to be a sound being saved within that function. Is this making sense?? Liz Helms |
Below is my code. I have come to the point in the HW where I am trying to cut the frequency in half. when I run the code, (dest = target) becomes highlighted and it states: A local or global name could not be found. You need to define the function or variable before you try to use it in any way.
Please check line 67 of \\smb.prism.gatech.edu\gtg469v\COA-MyDocuments\hw3.py
Why does it not like the dest being set as target?
| This is because you haven't defined target in your half(C) code. I deleted your posted code so people do not take it and use it as their own. In the future, please only post the specific function/area of code that you are having problems with (but thanks for giving us enough to see where the problem would be). Amanda Bennett |
I was wondering for the splicing part do you want was to leave the empty sound or do you want us to overlap it with another sound so that there is not a gap in the sound?
What sound files will the TAs be using? Every file that is in the Media Sources file and the musicsounds.zip or will it just be the music sounds from the two folders...i.e. will the voice files not be included?
Reason, I would like to use some of the voice files in my program.
| Voices are sounds. We'll simply be combining the musicFiles and MediaSources folders to grade. Amanda Bennett |
What do you mean by using 5 sound files for 10 sounds? Do we use two sounds and put them together to make one sound? Is that what you mean? I do not understand how the sounds are suppose to sound?
| There's an example to help explain in the homework. "if you combined bassoon-c4.wav plus bassoon-e4.wav plus bassoon-c4.wav plus bassoon-e4.wav, you will have used 2 different sound files for 4 different sounds." So, basically you need to use at least 5 sound FILES, and concatenate these in some way to create 10 different sounds in your function. Amanda Bennett |
For the splicing, do you want us to cut a sound so that it is shorter and can be used in our new sound? For example, say I have a 10 second sound, but I only want to use 5 seconds in my new sound. I can cut 2 seconds from the front and 3 from the back and use the remaining sounds as part of my new sound?
I'm trying to put in my secondary function into my main fucntion. When I comment out the second function within my main one, everything runs fine. As soon as I try to run the full program I get the error play(sound): Input is not a sound.
An error occurred attempting to pass an argument to a function.
What's going wrong? At the end of the function I have return canvas..... should i have something else?
NEVERMIND! i figured it out... but you can answer it anyway for others who may need it
I'm having trouble trying to figure out how to save my sounds into the main makeMusic() function and returning it.
| Could you be more specific when you say saving your sounds, do you mean you are having trouble creating sounds using makeSound(file) or that you are having trouble saving it to your computer using writeSoundTo(sound, computer path)? Liz Helms |
| I've seen several students doing something that is causing this same problem. Be sure to use the SAME canvas for all of your functions! So, maybe in your subfunctions where you've had your sound spliced and frequencies changed, instead of making a new canvas each time, passing in a canvas as an input. This canvas can be the same one for all of the functions then. If this isn't what you're asking at all, I apologize, but maybe it will help someone else. Amanda Bennett |
def makeMusic():
canvas = makeEmptySound(7)
bc = makeSound(getMediaPath("bassoon-c4.wav"))
be = makeSound(getMediaPath("bassoon-e4.wav"))
bg = makeSound(getMediaPath("bassoon-g4.wav"))
sc = makeSound(getMediaPath("string-c4.wav"))
se = makeSound(getMediaPath("string-e4.wav"))
sg = makeSound(getMediaPath("string-g4.wav"))
## Splicing
targetIndex = 1
#sg and se chord
for sourceIndex in range(1, getLength(sg)):
value8 = getSampleValueAt(sg, sourceIndex)
value9 = getSampleValueAt(se, sourceIndex)
setSampleValueAt(canvas, targetIndex, (value8+value9)/2)
targetIndex = targetIndex + 1
return canvas
when i run this function, nothing happens. This is only a part of my function but it seems as though it's written just like the others. There are no errors and program doesn't stop, it just doesn't play anything. Why?
| Check out the indentation of your return statement, and remember what happens as soon as the program "sees" return. Amanda Bennett |
# Second function - Doubling frequency
def doubleFrequency(aSound):
source = makeSound(aSound)
target = makeSound(aSound)
targetIndex = 1
for srcIndex in range(1, getLength(source)+1, 2):
setSampleValueAt(target, targetIndex, getSampleValueAt(source, srcIndex))
targetIndex = targetIndex + 1
#clearing out the second half
for secondHalf in range(getLength(target)/2, getLength(target)):
setSampleValueAt(target, targetIndex, 0)
targetIndex = targetIndex + 1
return aSound
Now I'm having trouble with my second function. I get an error on the 11th line (setSampleValueAt...). It tells me: JavaSoundException: That index 55126, does not exist. There are only 55125 frames in the entire sound. I didn't get this error before when my code was shorter. Do I have to change index or value as my function grows?
| Print the value of targetIndex between the two loops and see whether it is what you expect it to be. And what is the purpose of the second loop index 'secondHalf'? Colin Potts |
My program allows me to perform the following requirements of the hw3 in my program w/o SPLICING or using the frequency code in the slides:
For at least four of your sounds, you must shift the frequency the basic sound (up or down) that you are including.
For at least five of your sounds, do not include the whole sound–splice out (copy over) only part of it, so that you control the duration.
Will I still get full credit?
I can control (shorten) the lengths of my sound and control frequency.
| As long as your program does what we ask, you will not lose credit. Amanda Bennett |
I have a working double frequency function. However, when I play the sound after it has run through the function, it sounds like two different sounds. Is this normal?
| What does changing the frequency do to the sound? This will help you answer your question. Other students, feel free to answer! Amanda Bennett |
def doubleFrequency(filename):
source = makeSound(filename)
target = makeSound(filename)
targetIndex = 1
for sourceIndex in range(1, getLength(source) + 1, 2):
value = getSampleValueAt(source, sourceIndex)
setSampleValueAt(target, targetIndex, value)
targetIndex = targetIndex + 1
for secondHalf in range(getLength(target)/2, getLength(target)):
setSampleValueAt(target, targetIndex, 0)
targetIndex = targetIndex + 1
return target
Whats wrong with this?! i'm getting an error on line 10 and it tells me "JavaSoundException: That index 55126, does not exist. There are only 55125 frames in the entire sound". Ahh! It's starting to make me angry
| Look up, Colin answered almost the exact same question already |
And that still doesn't answer my question
Why does this make my sound blank?
def half(sourceSound):
source = sourceSound
dest = sourceSound
srcIndex = 1
for destIndex in range(1, getLength(source)+1):
value = getSampleValueAt(source, int(srcIndex))
setSampleValueAt(dest, destIndex, value)
srcIndex = srcIndex + 0.5
return dest
| ...I dont see anything wrong with this, are you sure you are passing in a working sound? Liz Helms |
destSample=97000
for srcSample in range(1, getLength(bassoona)+1,2):
setSampleValueAt(empty, destSample,getSampleValueAt(bassoona,srcSample))
destSample = destSample + 1
^ why does that play the higher frequency and then the low frequency in the same sound?
| Take a look at the slides on this subject, note the importance of silencing the second half of your doubled sound and think about what exactly is going, yes, you are copying the doubled samples to this new sound, but what is happening to the second half of the sound? Nothing. So it will play as normal. Thus, the need to silence it. Liz Helms |
>>> play(makeMusic())
Trouble accessing the sound device.
Trouble accessing the sound device.
what does that mean?
| It sounds as though one of the other applications you are running on your computer is already using sound. Try closing all applications before running this again. If that doesn't work, maybe a program was using sound and didn't close properly. Reboot your computer and try again. If that still doesn't work, try running a sound application (anything that plays music, say) to check that your computer is ok. Colin Potts |
def doubleFreq(filename):
source=makeSound(filename)
target=makeSound(filename)
targetIndex=1
for sourceIndex in range(1,getLength(source)+1,2):
value = getSampleValueAt(source, srcIndex)
setSampleValueAt(target, targetIndex, value)
targetIndex = targetIndex + 1
for secondHalf in range(getLength(target)/2, getLength(target)):
setSampleValueAt(target,targetIndex,0)
targetIndex=targetIndex+1
return target
It keeps saying "An attempt was made to call a function with a parameter of an invalid type." and it says to check line 2...what is wrong with this?
| My guess would be that when you are calling this function, you are inputting a sound that has already been made instead of a filename. Liz Helms |
JES says to check "source=makeSound(filename)"...
whats the difference between return canvas and play canvas?
| Its the same difference as show(pic) and return(pic)... play will only play the sound for you to hear, but return will save it for later reference. Liz Helms |
my function plays me music with "play" and no "return"
does blending one sound with another count as one of the "changing frequency" requirements for HW3?
| Think about what exactly the frequency is and how to alter it, does adding two sounds together in a blend seem to deal with frequency in this manner? Liz Helms |
def doubleFrequency(filename):
source = makeSound(filename)
target = makeSound(filename)
targetIndex = 1
for sourceIndex in range(1, getLength(source)+1, 2):
setSampleValueAt(target, targetIndex, getSampleValueAt(source, sourceIndex))
targetIndex = targetIndex + 1
return filename
I get an error saying: 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 does this mean? I tried to change the name of 'source' and the name of 'filename' but it still comes up with this message.
| You need to return a sound so that you can play it, not a filename. Try returning target. Colin Potts |
I tried playing the bassoon sounds but with windows media but it tells me there is an error "An audio codec is needed to play this file. To determine if this codec is available to download from the Web, click Web Help." but when you go to web help there is nothing to download to make it work. it says i am to use the bassoon sounds to make my code but i cant check my code if the sound doesnt work. what should i do?
what can I do about my jes going crazy? It keeps showing multiple mouse points, and my type blends together and looks crazy.... I'm scared for my homeworks life.
i had the same problem with the doubleFrequency...what you need to do for your source is:
source = filename
target = filename
doing that and returning the target worked for me.
On the assignment it says to use at least 2 functions, does this mean to use two type of functions in your "def" code or to use two "def" codes that work together? Because I noticed on hw2 that it stated that we should have 2 functions but I only used one "def" function with multiple functions within it and my TA had no problem with it.
| Just 2 functions. You need to have 2 "def" statements in the file you turn in. Amanda Bennett |
When I change the frequency of a sound, should I be able to noticeably hear a difference?
I put my canvas as an input for my 2 functions and I returned it to the def makeMusic(): but it only plays the first function and not the other. when I # out the first function, the second function plays. when the second functions plays it pauses for about 4 seconds which is how long my first function last then it plays the second function. I can't figure out how to play one function after the other.
| It's really hard to work out what you are doing and what is going wrong because you're not being very exact in your wording. (E.g. you can't play a function!) Please try to be more careful when you post questions in future so that we can help you. In the meantime, email your code to me or your TA or take your code to a TA tomorrow and talk to him or her in person. Colin Potts |
I have my code for adding two sounds but I don't know what to return at the end of the code to give me the new combined sound. I had return(s1) but that only returned the first inputed sound unaltered. This is my code:
def add(s1,s2):
for x in range (1, getLength(s1)+1):
sample1=getSampleValueAt(s1,x)
sample2=getSampleValueAt(s2,x)
setSampleValueAt(s2,x,sample1+sample2)
Help me.
| Your code is modifying the sound s2, so if anything, it should return s2. However, as you are passing in s2 as an argument and modifying it inside the function you don't really need to return anything. s2 will have been changed by the function. Colin Potts |
Ok I have this,
def makeMusic():
#Creating Variables
canvas = makeEmptySound(20)
Elliot = makeSound(getMediaPath("Elliot-hello.wav"))
bc = makeSound(getMediaPath("bassoon-c4.wav"))
be = makeSound(getMediaPath("bassoon-e4.wav"))
bg = makeSound(getMediaPath("bassoon-g4.wav"))
son = makeSound(getMediaPath("sun.wav"))
of = makeSound(getMediaPath("of.wav"))
a = makeSound(getMediaPath("a.wav"))
bleep = makeSound(getMediaPath("nu-f440"))
that = makeSound(getMediaPath("that.wav"))
scream = makeSound("aah.wav"))
#Creating The Song
for srcSample in range(1,getLength(Elliot)-16592):
destValue = getSampleValueAt(Elliot,srcSample)
srcValue = getSampleValueAt(Elliot,srcSample)
setSampleValueAt(canvas,srcSample,srcValue+destValue)
#Playing final product
play(canvas)
return canvas
And I keep getting the error;
>>> There was a spacing error in the program.
It might be from a previous line, but I think the error is in line 16
But I can't figure it out.
| One of your lines has more closing parentheses than opening parentheses. Delete the extra ')' and the error will go away. I didn't count the lines, but usually if this happens, an error reported on line 16 means that the mistake is actually on line 15. Colin Potts |
do we have to have both "return" and "play" at the end of the function?
by having return, what use would this be... i know return saves it for later use but why would you want to save it?
you shouldn't need play at the end of the function. The assignment says that your TA will type in "play(makeMusic())"
I keep getting the error <media.Sound instance at ########> (random number there) and nothing plays even though there seems to be nothing wrong with my function. I transfered the file to my friend and she says my program works perfectly on her computer! Help?!
<media.Sound instance at ########> is not an error message. It is JES's attempt to print the value that your function returns. Instead of typing makeMusic() in the command area (or print makeMusic(), which would give you the same output), try typing play(makeMusic()) I bet that is what your friend was doing! Colin Potts |
Is there a maximum # of sound files we can use?
How do you find out how long (in seconds) each sound is?
| getLength() tells you how many samples there are in the sound, and getSamplingRate() tells you how many samples there are per second, so you can easily compute the duration. Remember though that if you divide an integer by an integer, you will get only the integer part of the answer. To get a floating point (real) number with a fractional part you need to convert either the numerator or denominator to a real by saying (for example) numberOfSamples = float(getLength()) Colin Potts |
My sounds keep overlapping though I am using getLength(previousSound)+1 Why is this? And no matter how many sounds I plug in I can only get about 5 to actually play. Thanks.
| It's impossible to say what is happening here without seeing your code. Consult a TA tomorrow or email your code. My guess is that you are setting the values of the wrong samples because you are getting the source and destination indices mixed up at some point. Colin Potts |
When splicing the sounds, is it ok to overlap the sounds so that the entire sounds don't play or are you looking for us to actually cut out a segment of the sound without just overlapping them so it appears to be shorter. Or is this the same thing?
| You should cut them out for it to be officially splicing. Otherwise you're just copying one sound over another. But do whatever you can get to work. Amanda Bennett |
hey so how do you writeSoundTo again? in the command or in the function after play(sound)...?
| Use writeSoundTo() and play() in the command area to test your function and to save the sound it creates for uploading to the gallery. Don't call either of these functions in your function. It should just return a sound. Colin Potts |
Is it considered splicing to simply "copy" half of your sound to the canvas? For example:
for sourceIndex in range(1,getLength(sound)/2):
the int() function doesnt seem to be having any effect in my code, causing 'invalid parameter type' error messages to come up
when i type int(variable) there is no coloration of the function that shows its even being recognized. Should there be?
I can't seem to get "writeSoundTo" to work for me. It's not generating a saved file at all.
return canvas
writeSoundTo(canvas, "C:\Documents and Settings\what\My Documents\adenoble3.wav")
Those are the last two lines of my code. Could be wrong because I couldn't find an exact syntax for it, was just going off of "writePictureTo".
| Anything you want your code to run should come before your return statement. Amanda Bennett |
my function works jsut fine, i have a song that plays when i type makeMusic() in the command prompt
but when i try to type play(song) in the command prompt it says: a local or global name could not be found.
| Do you have the variable song defined before you call play? prehaps you should say play(makeMusic()) or song=makeMusic() then play(song) Amanda Bennett |
How do you find out how long (in seconds)each sound is?
I keep getting a spacing problem out of nowhere when I never had one before. It's driving me crazy. If it's not "for srcIndex in range(1, getLength(be)):", it'll be "return canvas." It says it every time I click LOAD.
| Try the line right above your for loop. Sometimes if you forget something on a line, it will continue to the next line. -poof #10 |
do we HAVE to use one of the bassoon files?
I am attempting to use the writeSoundTo function, but it doesnt work.
Is it writeSoundTo(canvas, "C:\\soundfile.wav")
| Try putting a lowercase r at the beginning like so r"C:\\soundfile.wav" -poof #10 |
| No, you don't have to use a bassoon file. You can use any of the instruments you want. Mark Guzdial |
Im trying to run my function and I get this error message...
The error JavaSoundException has occured
JavaSoundException: That index 3528064, does not exist. There are only 2205000 frames in the entire sound
this may be too late, but I can't get the writeSoundTo function to work and I've tried everything above. I've tried it both within the code and in the command area (black)
Link to this Page