JES functions/commands for files and pictures

 

 

JES functions/commands for sounds

 

 

 

Other JES functions

 

Python builtin functions

 

Python keywords

 

Very often used lines of code

 

 

Special characters in Python

General programming concepts

 

 

Picture concepts

 

 

Sound concepts

·      What is sound.  Sound is just variations in pressure in air (or water if you happen to be underwater).  The parts of our ear responsible for sound are sensitive to these changes in pressure and will vibrate accordingly.  The brain takes this information and we “hear” sound.  At any given point (like the tip of a microphone), we can look at how the pressure is varying over time.  It will get larger, smaller, etc. as the sound travels through the air.  We can then graph this value to get a curve.  The curve might look something like a sine curve. 

·      What is a speaker/microphone.  A speaker wants to “make sound”.  Since sound is just variations in pressure, the speaker pushes on the air to create the variation in pressure.  A microphone is just a speaker in reverse.  It is like a little speaker that will get pushed in and out with variations in pressure, and this creates a difference in voltage or current that can then be recorded by the computer.

·      How is sound stored on the computer.  To store sound on the computer, we just take the “pressure reading” at regular intervals.  We use really small intervals, short enough that our ears won’t know the difference when we recreate the sound based off of the pressure readings at these short intervals.  Each pressure reading is called a sample.  One way to view this is that a sound file on the computer is regular-spaced points on the sound curve.  A sound file is made up of: what is the sampling rate, and what are the sample values (the regularly-space points on the curve).

·      Parts of the curve, sound lingo.  The frequency of something is just how often it happens, normally per second.  Frequency is measured in hertz.  100 hertz would mean 100 times per second.  The frequency of sampling is just the number of samples per second.  The frequency of a sound wave is the number of times it repeats per second.  So 400 hertz would mean it repeats 400 times per second.  That would mean the part that is repeating is 1/400 of a second long.  This is called the period or cycle length. 

·      The amplitude of a sound wave is just the maximum distance the curve gets away from the baseline.  We hear higher amplitude curves as being louder – there is a greater difference in pressure, so that makes sense. 

·      We hear higher frequency sounds as having a higher pitch, and lower frequency sounds as having a lower pitch. 

·      An octave is a range of sound frequencies from some value to double that value.  So the sound frequencies between 200 and 400 hertz is an octave.  The reason we split it up like this is because doubling or halving a sound frequency makes it still sound like the same note to us (a C note, maybe).

·      Splicing sounds.  If we have two different sound objects, we can make a third object that has the first one followed by the second one.  The third one would have to be as long as the other two combined, and we could use for loops to copy the values.

·      Blending/adding sounds.  If we want to put two sounds together so we hear both at the same time, we can create a third sound where the sample values just come from adding the sample values of the two sounds.  This could result in “overflow”, so we can get around that by blending the two sounds instead of adding (add them up and divide by two).

·      Clipping (or selecting part of a sound).  We could copy just part of a sound into another sound by changing what the ranges are on the for loop.

·      Normalizing sound.  This is multiplying all sample values in a sound by some value so that the maximum sample value is the maximum value allowed (32767 for 16-bit samples).

·      Stereo versus mono sound.  Stereo sound is actually made up of two different sound objects, one for the left speaker and one for the right speaker.  In JES, we are using mono sounds – just a single sound wave that goes to both speakers.

 

Common mistakes/advice

 

Advice on steps to write a program/function

(1)  Understand exactly what it is supposed to do, e.g., what would a picture look like after running the function on it.

(2)  Write down a way that you would do this - the basic idea, a few sentences (e.g., for red eye removal, change any pixel that is close to red to black).

(3)  Write down "pseudocode" - the basic outline of what your program will look like to achieve what you want to do. For example, with red eye removal it could be something like

a.     function definition line, take a picture as input.

b.     for each pixel in the picture do the following.

c.     if the pixel's red value is above 200, then change the pixel's color to be black.

(4)  Take your pseudocode and write your function.

(5)   Debug/test your function.  If you do the other steps right and take your time with them, this step won’t be too bad.  If you don’t do the other steps, this step can take FOREVER.

 

Each step along the way you are getting more and more precise about how exactly you are going to solve the problem. If you take your time and think things out, you will get to the final solution much faster!  DO NOT JUST START TYPING without understanding the problem or what you are typing.  If you do not understand what you have typed, then it almost certainly will not work!!

 

 

Debugging techniques