[Note: this webpage last modified Friday, 04-Feb-2011 19:44:51 EST]
Adinistrative...
Homework 7.
Final Project.
Homework 8.
Make sure to right-click and choose "Save ... as ..." to save python files off of the website.
Today: adding/blending sounds together
Adding sounds together - make a new sound object and do a for loop that sets each sample value in the new sound to be the sum of the sample values in the other two sounds.
We try it out, and how does it sound? It may sound terrible because of "overflow". We have seen overflow before, it is when we try to set a value that is bigger than is allowed. Using 16-bit samples for each sample value, the largest value that is allowed is 32767. What happens if we try to set the sample value to be larger, like 50000? JES does "wraparound", so it treats 32768 like the most negative possible value (which is -32768), and treats 32769 like -32767, etc. We have seen this before also with setting the red, green, and blue values of pixels. This is a common problem to look out for any time you are using a limited number of bits to store numbers. The same kinds of problems can happen on your calculator.
Blending sounds together - similar to adding the sounds, but now we make the new sample value equal to .5 * sample1 value + .5 * sample2 value. That way, it will never get larger than the largest possible, and we won't have overflow. If we were blending 3 sounds, we would do .33 * sample1 + .33 * sample2 + .33 * sample3.
Note use of min function in the sample code for today. It is just like the max function, but gives you the minimum instead of the maximum.
Next time: creating an echo.
And make sure to take the quiz, and type things into JES to try them out!