Problems


[Page 340 (continued)]

10.1

What are each of the following:

  • MIDI

  • MP3

  • A class method

  • Sound pitch


  • [Page 341]
  • A static method

  • Private visibility

10.2

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?

10.3

When should you make a method static? Can static methods access object data?

10.4

Write a method to triple the frequency of a sound. Use Program 83 (page 319) as a starting point.

10.5

Write a method to quadruple the frequency of a sound. Use Program 83 (page 319) as a starting point.

10.6

Write a method to play a sound with the frequency changed 10 times. Use Program 87 (page 324) as a starting point.

10.7

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.

10.8

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.

10.9

Create a method that will create a pyramid shaped sound wave. Use Program 91 (page 332) as a starting point.

10.10

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.

10.11

How long is a sound compared to the original when it's been frequency doubled (Program 83 (page 319))?

10.12

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)?

10.13

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.)

10.14

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?

10.15

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.


[Page 342]
10.16

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.

10.17

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.

10.18

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.

10.19

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.

10.20

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?



Introduction to Computing & Programming Algebra in Java(c) A Multimedia Approach
Introduction to Computing & Programming Algebra in Java(c) A Multimedia Approach
ISBN: N/A
EAN: N/A
Year: 2007
Pages: 191

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net