========================= SET UP: prepare for media files > FileChooser.setMediaPath( "/Users/wallingf/home/teaching/cs1-media/intro-prog-java/mediaSources/" ) ========================= OPENING EXERCISE: encoding 3 ints -> int ... Pixels! > Picture p = new Picture( FileChooser.getMediaPath("ew/wallingf-problemFived.jpg") ); > p.explore(); > Pixel pixel = p.getPixel( 166, 258 ); > pixel.getColor() java.awt.Color[r=236,g=0,b=154] > pixel.encode() 15466650 > Pixel other = p.getPixel( 237, 137 ); > other.getColor() java.awt.Color[r=255,g=251,b=2] > other.encode() 16775938 ========================= EXERCISE #2: decoding int -> 3 ints -> Pixel color! > Picture p = new Picture( FileChooser.getMediaPath("ew/wallingf-problemFived.jpg") ); > Pixel pixel = p.getPixel( 166, 258 ); > Pixel other = p.getPixel( 237, 137 ); > int pixelCode = pixel.encode(); > int otherCode = other.encode(); > pixel.setColorFrom( otherCode ); > other.setColorFrom( pixelCode ); > p.repaint(); > p.explore(); > pixel Pixel red=255 green=251 blue=2 > other Pixel red=236 green=0 blue=154 ========================= REVIEW: data compression, sounds as sample diffs > Sound voice = new Sound( FileChooser.getMediaPath("ew/the-voice-raw.aiff") ); > DiffSound compressedVoice = voice.compress(); > compressedVoice.displayDifferences( 1000, 1050 ); -43 -84 -102 -90 -61 -24 11 44 77 ... ----- Look at the class: ----- class declaration ----- instance variables ----- constructor ----- method ========================= EXERCISE #3: decompressing a DiffSound > Sound voice = new Sound( FileChooser.getMediaPath("ew/the-voice-raw.aiff") ); > DiffSound compressedVoice = voice.compress(); > Sound voiceDecompressed = compressedVoice.decompress(); > voiceDecompressed.play(); ----- What went wrong? > voiceDecompressed.explore(); ----- ... Casting to byte is wrong! ----- ... Remember what happens with value too big. ----- ... Let's "truncate" differences. > Sound voice = new Sound( FileChooser.getMediaPath("ew/the-voice-raw.aiff") ); > DiffSound compressedVoice = voice.compress(); > Sound voiceDecompressed = compressedVoice.decompress(); > voiceDecompressed.explore(); > voiceDecompressed.play(); ----- The voice is in there! ----- But our compression is *lossy*. ----- Some |difference|s > 127. ----- Why does the voice sound as if it is ----- at a higher frequency?? ----- Recorded at 1/16000; returned at 1/22050. ----- Let's try another example -- ----- recorded at 1/22050. > Sound preamble = new Sound( FileChooser.getMediaPath("preamble.wav") ); > preamble.play(); > DiffSound compressedPreamble = preamble.compress(); > Sound preambleDecompressed = compressedPreamble.decompress(); > preambleDecompressed.play(); > preambleDecompressed.explore(); ----- Lossy -- but not too bad! ========================= IDEA: using javadoc to generate web doc for classes mac os x > cd /Users/wallingf/home/teaching/cs1/sessions/session20 mac os x > mkdir javadoc-example/ mac os x > cp DiffSound.java Sound.java javadoc-example/ mac os x > cd javadoc-example/ mac os x > javadoc *.java ----- Sound.java:9: cannot find symbol ----- symbol: class SimpleSound ----- ----- DiffSound.java:9: warning - @date is an unknown tag. mac os x > open index.html