What are each of the following:
A class method
A static method
When should you make a method private? Should you ever change a private method to a public method? Should you ever change a public method to a private one?
When should you make a method static? Can static methods access object data?
Write a method to triple the frequency of a sound. Use Program 83 (page 319) as a starting point.
Write a method to quadruple the frequency of a sound. Use Program 83 (page 319) as a starting point.
Write a method to play a sound with the frequency changed 10 times. Use Program 87 (page 324) as a starting point.
Write a method that will play half of one sound, and then the second half of the first sound added to the first half of another sound, and then the last half of the second sound. Use Program 80 (page 314) as a starting point.
Write a method that will blend three sounds. Start with one sound for 20,000 samples, then blend the first and second sounds for 20,000 samples, then the second and third sounds for 20,000 samples, and then the third sound for 20,000 samples. Use Program 80 (page 314) as a starting point.
Create a method that will create a pyramid shaped sound wave. Use Program 91 (page 332) as a starting point.
Rewrite the echo method (Program 81 (page 315)) to generate two echoes back, each delay samples previous. Hint: Start your index loop at 2*delay + 1, then access one echo sample at index-delay and another at index 2*delay.
How long is a sound compared to the original when it's been frequency doubled (Program 83 (page 319))?
How long is a sound compared to the original if you increment the sourceIndex by 3 each time through the loop in Program 83 (page 319)?
Hip-hop DJ's move turntables so that sections of sound are moved forward and backward quickly. Try combining backward play (Program 78 (page 305)) and frequency shifting (Program 83 (page 319)) to get the same effect. Play a second of a sound quickly forward, then quickly backward, two or three times. (You might have to move faster than just double the speed.)
Consider changing the if block in the frequency shift method (Program 86 (page 323)) to sourceIndex = sourceIndex - getLength(source). What's the difference from just setting the sourceIndex to 1? Is this better or worse? Why?
If you use the shifting method (Program 86 (page 323)) with a factor of 2.0 or 3.0, you'll get the sound repeated or even triplicated. Why? Can you fix it? Write shiftDur that takes a number of samples (or even seconds) to play the sound.
Change the shift method in Program 86 (page 323) to shiftFreq which takes a frequency instead of a factor, then plays the given sound at the desired frequency.
Using the sound tools, figure out the characteristic pattern of different instruments. For example, pianos tend to have a pattern the opposite of what we createdthe amplitudes decrease as we get to higher sine waves. Try creating a variety of patterns and see how they sound and how they look.
When musicians work with additive synthesis, they will often wrap envelopes around the sounds, and even around each added sine wave. An envelope changes the amplitude over time: It might start out small, then grow (rapidly or slowly), then hold at a certain value during the sound, and then drop before the sound ends. That kind of pattern is sometimes called the attack-sustain-decay (ASD) envelope. Pianos tend to attack quickly then decay quickly. Flutes tend to attack slowly and sustain as long as you want. Try implementing that for the sine and square wave generators.
Write a method to play a simple song like Jingle Bells. The song should have at least one repeating part. Make sure that you create a private method for the repeating part.
Create a static method of the Picture class which will create and return a Picture object from a passed file name. Is this better or worse than using a constructor that takes a file name?