Expand All Collapse All


ReverseSoundWave
How do I print the values in an array?
Write a loop and print each element. Remember that, if samples is an array, System.out.println(samples) doesn't print the elements of the array.
Should I debug by printing the arrays?
That's a good idea, but you probably don't want to print the entire array. Remember, each second of digital audio contains 44,100 samples. Instead, consider just printing the first (and/or last) handful of elements.

Another way to debug is to use the reversed files supplied, such as ReverseHelloWorld.wav, as the inputs to your program. When you reverse a reversed audio file, you get back the original.

Why do reverse notes in A.wav and AMajorScale.wav sound like the originals when reversed?
The notes are created using pure sine waves—they oscillates with the same frequency whether played regularly or in reverse.
What happens with stereo audio files?
The method StdAudio.read() first converts the audio to monaural, so you need not worry about that here.
Superpose
How can my program determine the number of command-line arguments?
The variable args is an array of strings. As with any array, you can get its length with args.length.
Can I assume that all of the audio files are of the same length?
Yes. No need to worry about superposing sound waves of different lengths.
What should I do if the sum of the samples is bigger than +1 (or less than –1)?
Don't worry about it on this assignment. When you send the samples to StdAudio, it will clip them (round them to +1 or –1).
I don't hear any sound when I superpose SynthA.wav and InvertedSynthA.wav even though they both make sounds when played individually. What's going on?
These two sound waves are the same except the samples are inverted (the signs of the corresponding samples are flipped). As a result, even though they sound the same when played individually, they interact with other sound waves differently. In particular, when superposed, these two sound waves perfectly cancel each other out. This idea is the foundation of technologies like noise-cancelling headphones.
ChipmunkEffect
PerfectShuffle
How should I store and initialize the deck of m cards?
Use an array of strings. To get started, we recommend creating and initializing an array containing all 52 cards in a manner analogous to the code on p. 96 of the textbook, but (i) using the abbreviated names for the ranks and suits and (ii) ordering them by suit, then rank (instead of by rank, then suit). Then, copy the first m cards into a new array and use this new array for the shuffling.
I can't seem to perform the perfect shuffle without overwriting entries in the array. What should I do?
While it is techincally possible to implement a perfect shuffle in-place, it is much easier to use an extra array. That is, create a new array of length m; put the results of applying the perfect shuffle in that array; then, copy the results back to the original array.
Can I assume that the number of cards m is even?
Yes. You can also assume that \(m \leq 52\) and n > 0.
What if I do a perfect shuffle, but put the first card from the right pile at the top?
That's known as a perfect in-shuffle.
After how many consecutive perfect shuffles will an m-card deck be restored to its original order?
It will be restored after \(k\) perfect out-shuffles if \(2^k – 1\) is a multiple of \(m –\) 1 or after \(k\) perfect in-shuffles if \(2^ – 1\) is a multiple of \(m + 1\). For example, a 52-card is stored to its original order after 8 perfect out-shuffles (because \(2^8 – 1 = 255\) is a multiple of 51) and after 52 perfect in-shuffles (because \(2^52 – 1\) is a multiple of 53).
I've heard that it takes 7 perfect shuffles to mix a deck of cards thorougly. Is this because 8 would bring it back to its original order?
Well, 8 perfect shuffles does bring a deck of 52 cards back to its original order. But, a perfect shuffle is not an accurate model for humans shuffling cards. The Gilbert–Shannon–Reeds model provides a more realistic model. Under this model, it takes 7 ordinary, imperfect shuffles to randomize the deck sufficiently. Fewer is not enough; more does not signficantly help.