========================= SET UP: prepare for media files > FileChooser.setMediaPath( "/Users/wallingf/home/teaching/cs1-media/intro-prog-java/mediaSources/" ) ========================= QUICK EXERCISE: find max sample difference > Sound voice = new Sound( FileChooser.getMediaPath("ew/the-voice-raw.aiff") ); > voice.maximumDifferenceV1() 15202 ----- But we'll need the *location*, so... > voice = new Sound( FileChooser.getMediaPath("ew/the-voice-raw.aiff") ); > voice. maximumDifference() 70805 > voice.getSampleValueAt( 70805 ) 13165 > voice.getSampleValueAt( 70806 ) -2037 > voice.explore(); > Math.abs( voice.getSampleValueAt(70805) - voice.getSampleValueAt(70806) ) 15202 > Sound sweetDreams = new Sound( FileChooser.getMediaPath("ew/SweetDreams.aiff") ); > sweetDreams. maximumDifference() 8088407 > sweetDreams.getSampleValueAt( 8088407 ) -19225 > sweetDreams.getSampleValueAt( 8088408 ) -2241 > Math.abs( sweetDreams.getSampleValueAt(8088407) - sweetDreams.getSampleValueAt(8088408) ) 16984 ========================= IDEA: changing a sound's frequency > voice = new Sound( FileChooser.getMediaPath("ew/the-voice-clipped-and-pitched.aiff") ); > voice.changeFrequency( 22050.0 / 16000.0 ); // OOPS! wrong way > voice.play(); > voice = new Sound( FileChooser.getMediaPath("ew/the-voice-clipped-and-pitched.aiff") ); > voice.changeFrequency( 16000.0 / 22050.0 ); > voice.play(); ----- The frequency seems right now! ----- ... but the result sound is too short. ----- What can we do? ========================= IDEA: data compression // show compression and decompression of And So It Goes // the file gets larger! // is the wave the same? ========================= EXERCISE: data compression > Sound voice = new Sound( FileChooser.getMediaPath("ew/the-voice-raw.aiff") ); > voice.displayDifferences( voice.arrayOfDifferencesV1(), 1000, 1050 ); 43 84 102 90 61 24 ... ----- But this uses ints -- same space! ----- Try a ** byte ** instead. > voice.displayDifferences( voice.arrayOfDifferences(), 1000, 1050 ); 43 84 102 90 61 24 ... ----- This encoding requires us to ----- manipulate byte arrays. But ----- this is really a new ----- *kind of object* ========================= IDEA: make a DiffSound class for compressed sound > 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 ...