Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE 8A Lecture 13 Reading for next class: Chapter 9 Today’s topics: –Sounds! Finish PSA 6: Chromakey! DUE TUESDAY Interm exam 3 next Thursday.

Similar presentations


Presentation on theme: "CSE 8A Lecture 13 Reading for next class: Chapter 9 Today’s topics: –Sounds! Finish PSA 6: Chromakey! DUE TUESDAY Interm exam 3 next Thursday."— Presentation transcript:

1 CSE 8A Lecture 13 Reading for next class: Chapter 9 Today’s topics: –Sounds! Finish PSA 6: Chromakey! DUE TUESDAY Interm exam 3 next Thursday

2 if ( absValZ < 2.0 ) { return true; } else { return false; } Which of the following is equivalent to the above code? A.return absValZ; B.return absValZ < 2.0; C.return absValZ >= 2.0; D.None of these CS Concept: Booleans are values

3 public static boolean inMset( double real, double imag ) { double zReal = 0; double zImag = 0; double realUpdate; int numIter = 0; double absValZ = Math.sqrt(zReal*zReal + zImag*zImag); while ( absValZ < 2.0 && numIter < 25 ) { realUpdate = zReal*zReal-zImag*zImag + real; zImag = zReal*zImag*2+ imag; zReal = realUpdate; absValZ = Math.sqrt(zReal*zReal + zImag*zImag); numIter++; } if ( absValZ < 2.0 ) { return true; } else { return false; } Magic Numbers!! (BAD)

4 public static boolean inMset( double real, double imag ) { final double zLimit = 2.0; final int maxIter = 25; double zReal, zImag, realUpdate; zReal = zImag = 0; int numIter = 0; double absValZ = Math.sqrt(zReal*zReal + zImag*zImag); while ( absValZ < zLimit && numIter < maxIter ) { realUpdate = zReal*zReal-zImag*zImag + real; zImag = zReal*zImag*2+ imag; zReal = realUpdate; absValZ = Math.sqrt(zReal*zReal + zImag*zImag); numIter++; } return ( absValZ < zLimit ); } final ly, no Magic Numbers Variables declared with the keyword final are constant. i.e. they can’t be modified once they are set.

5 Chromakey: Visit strange new places 1)Solo: (30 sec) 2)Discuss: (2 min) 3)Group: (20 sec) background person (before) person (after) In order to create modify the person picture so that it looks like the after picture, from which pictures to you take the pixels in the boxes? A.Box 1 (yellow) from background, box 2 (green) from person B.Box 1 from background, box 2 from background C.Box 1 from person, box 2 from person D.Box 1 from person, box 2 from background E.None of the above 1 2

6 How will you know which part (yellow box or green) you are in? A.Condition on the Pixel coordinates (not the color) B.Condition on the Pixel colors in background C.Depends on the Pixel colors in person D.Depends on the Pixel colors in background, compared to those at the same coordinates in person 1)Solo: (30 sec) 2)Discuss: (30 sec) 3)Group: (20 sec) 1 2 background person (before)

7 Your chromakey Call two chromakey methods: –One to replace background –One to replace tShirt –If there 2 or more people in the picture, you can call more methods – one to replace each tShirt with a different background if you like public void chromaKeyBlue(Picture newPicToReplaceBlue, int blueThreshold) for (int x = 0; x < this.getWidth(); x++) for (int y = 0; y < this.getHeight(); y++) { //Do some stuff } OK to edit pictures before the code runs

8 Modified from the lab 5 quiz A.This code changes any pure red pixels in the top-right quarter of the picture to black. B.This code modifies the top-right quarter of the picture. C.This code loops over pixels in the top half of the array and, if the x coordinate is greater than half the width, checks if the red component is 255 and the blue is 0 and the green is 0, and, if so, sets the pixel to black. for (int x = 0; x < getWidth(); x++) { for (int y = 0; y < getHeight() / 2; y++) { Pixel p = getPixel(x, y); if (x > getWidth() / 2) { if (p.getRed() == 255 && p.getBlue() == 0 && p.getGreen() == 0) { p.setColor(Color.BLACK); }

9 What are we doing next? Chapters 8,9,10: Sound! Continue with computational basics from Picture work: –Iteration/looping, if statements, arrays –Emphasis on deeper understanding –Emphasis on Java terminology, features, mental “model” of how code is represented in the execution on the machine When working with Sound/SoundSample, compare and contrast to Picture/Pixel examples.

10 Chapter 8: Sound!

11 Sounds Sound is a quasiperiodic pattern of waves of air pressure –Increase in air pressure is a compression –Decrease in air pressure is a rarefaction The strength of the compression and rarefaction is the amplitude of the sound The number of compression/rarefaction cycles per second is the frequency of the sound

12 Digitizing Sounds To process sounds in a computer, sound must be digitized A microphone converts instantaneous sound pressure level into voltage (+ voltage for compression, - voltage for rarefaction) Then the amplitude of the voltage can be converted to bits (digital integers) with an Analog-to-Digital converter (ADC)

13 Digital Sample Rate versus Sample Size Size determines max (and min) amplitude –CD audio: 16 bits per sample (per stereo channel) –Min: -32,768; Max: 32,767 Rate is “how often we record an amplitude” –CD audio: 44,100 samples per second –A.k.a. 44.1 KHz sample rate

14 If the following sound were modified to be louder it would A.Have lower frequency and stronger compressions/rarefactions B.Have smaller amplitude and stronger compressions/rarefactions C.Have higher frequency and stronger compressions/rarefactions D.Have larger amplitude and stronger compressions/rarefactions E.None of the above 1)Solo: (30 sec) 2)Discuss: (2 min) 3)Group: (20 sec)

15 If higher pitch? 1)Solo: (30 sec) 2)Discuss: (2 min) 3)Group: (20 sec)

16 Making bad music: What’s wrong with these decisions? 1)Discuss: (3 min) I’ve decided that I don’t like the sampling rate and sample size provided by the book authors. Comment on my decision to use… Sampling Rate Sample Size Explanation 5,000Hz4 bits 100,000Hz32 bits

17 Our Representation of Sound String fileName = FileChooser.pickAFile(); Sound noise = new Sound(fileName); SoundSample[] noiseArray = noise.getSamples(); noiseArray[3].setValue(0); int foo = noiseArray[2].getValue(); noiseArray 0123456789 SoundSample objects

18 Our Representation of Sound (Shorthand) String fileName = FileChooser.pickAFile(); Sound noise = new Sound(fileName); SoundSample[] noiseArray = noise.getSamples(); noiseArray[3].setValue(0); int foo = noiseArray[2].getValue(); 0123456789 noiseArray

19 How would we fill in this SampleSound[] 1)Solo: (60 sec) 2)Discuss: (2 min) 3)Group: (20 sec)

20 How would we fill in this SampleSound[] 1)Solo: (60 sec) 2)Discuss: (2 min) 3)Group: (20 sec) 6

21 According to Nyquist’s Theorem what is the minimum sampling rate? 1)Solo: (60 sec) 2)Discuss: (2 min) 3)Group: (20 sec) A.1.5Hz B.3Hz C.6Hz D.10,000Hz E.20,000Hz

22 Write code which makes the following changes Here’s a Sound String fileName = FileChooser.pickAFile(); Sound noise = new Sound(fileName); SoundSample[] noiseArray = noise.getSamples(); >> for (SoundSample sample: noiseArray) { int foo = sample.getValue(); sample.setValue(foo/2); } for (int i = noiseArray.length/2; i < noiseArray.length) { SoundSample sample = noiseArray[i]; int foo = sample.getValue(); sample.setValue(foo/2); } int i = 0; while (i < noiseArray.length) { SoundSample sample = noiseArray[i]; int foo = sample.getValue(); sample.setValue(foo/2); } 1)Solo: 45 sec) 2)Discuss: (2 min) 3)Group: (20 sec)

23 What does that code do A.Makes a lower pitched sound during first half of play B.Makes a quieter sound during first half of play C.Makes a lower pitched sound during second half of play D.Makes a quieter sound during second half of play E.For each SoundSample element in the second half of the array it gets the Value and stores that in an int and then sets the Value with something that is half that

24 For you to practice Write code that reduces the volume of every other SoundSample. –What does that really sound like?

25 Summary of Concepts Digital representations of sounds Manipulating sounds using loops

26 TODO Reading for next class: Chapter 9 –Read more about Sounds. Finish PSA6


Download ppt "CSE 8A Lecture 13 Reading for next class: Chapter 9 Today’s topics: –Sounds! Finish PSA 6: Chromakey! DUE TUESDAY Interm exam 3 next Thursday."

Similar presentations


Ads by Google