Creative Commons Attribution NonCommercial Share Alike License http
Creative Commons Attribution Non-Commercial Share Alike License • http: //creativecommons. org/licenses/by-ncsa/3. 0/ • Original Developer: Beth Simon, 2009 bsimon@cs. ucsd. edu
CSE 8 A Lecture 21 • Read next class: read pg 300 -308 and 312 -321 • Freshman seminar: Peer Instruction Research • CSE 8 A Art Show! Sat Nov 14 10: 30 -12 noon – Print out your code! – Show up at 10 am to tape up your poster and code! – What do we have on chromakey? (check out wiki) • Help future 8 A students! – Wiki of CSE terminology (demo) • Solutions to midterm posted on moodle – Pick up midterms today (solutions don’t have problems listed)
Picking up midterm after class (I’ll bring leftovers up to discussion and to class on Monday)
By the end of today’s class you should be able to… • LG 41: Read, trace, and write code to change the volume of a Sound object (using for each, while and for loops) • LG 42: Compare and contrast the difference between changing the Color of Pixels in a Picture to changing the volume of Sound. Samples in a Sound. • LG 43: Trace execution of sound code using multiple loops and if statements. • LG 44: Be able to use either array-based or method-based (API) access for (getting/reading, setting/writing) sound File. • LG 45: Be able to explain in plain English what code modifying Sounds does. • LG 46: Trace indexing patterns in code to perform Sound manipulations (e. g. , reversing a sound).
Lab Note: More than one way to modify Sounds Sound. Sample[] noise. Array = noise. get. Samples(); for (int i = 0; i < noise. Array. length; i++) { Sound. Sample sample = noise. Array[i]; int foo = sample. get. Value(); sample. set. Value(foo/2); } int foo = noise. get. Sample. Value. At(); noise. set. Sample. Value. At(foo/2); int foo = this. get. Sample. Value. At(); this. set. Sample. Value. At(foo/2); int foo = noise. get. Sample. Value. At(i); noise. set. Sample. Value. At(i, foo/2); int foo = this. get. Sample. Value. At(i); this. set. Sample. Value. At(i, foo/2);
Conceptual Highlight Get/Read Value • • Pixel[] foo = xxx. get. Pixels(); Color c = foo[i]. get. Color(); Pixel bar = xxx. get. Pixel(x, y); Color c = bar. get. Color(); Sound. Sample[] foo = xxx. get. Samples(); int value = foo[i]. get. Value(); int value = xxx. get. Sample. Value. At(i); Set/Modify Value • foo[i]. set. Color(mod. C); • Pixel bar = xxx. get. Pixel(x, y); bar. set. Color(mod. C); • foo[i]. set. Value(mod. Value); • xxx. set. Sample. Value. At(i, mod. Value);
For you to practice • Write that code using a – While loop • Write a code that reduces the volume of every other Sound. Sample. What does that really sound like?
Lab Review: What does this code do? public void lab 7 Quiz 3(Sound my. Sound) { Sound[] source = this. get. Samples(); Sound[] result = my. Sound. get. Samples(); for (int i = source. length/2; i < source. length; i++) { int value = source[i]. get. Value(); result[i]. set. Value(value); } } A. Erases half of the sound B. Changes the result sound based on the this sound C. Replaces the parameter sound with the calling object sound D. Puts the last half of the calling object sound into the parameter sound E. Replaces the last half of the parameter sound with the last half of the result sound
What’s printed by this code? (assume calling object (this) as shown) public void guess() { Sound. Sample[] noise. Array = this. get. Samples(); int a, b = 0; for (int i=0; i<noise. Array. length; i++) { Sound. Sample sample = noise. Array[i]; int foo = sample. get. Value(); if (foo > a) { a = foo; b = i; } } S. o. pln(a + “, ”+b); } A. 0, 9 B. 60, 0 C. 90, 5 D. 100, 4 E. None of the above
What’s printed by this code? (assume calling object (this) as shown) public void guess() { Sound. Sample[] noise. Array = this. get. Samples(); int a = 32767; int b = 0; for (int i=0; i<noise. Array. length; i++) { Sound. Sample sample = noise. Array[i]; int foo = sample. get. Value(); if (foo < a) { a = foo; b = i; } } S. o. pln(a + “, ”+b); } A. 0, 9 B. 0, 6 C. 90, 5 D. 32767, 0 E. None of the above
- Slides: 10