Download presentation
Presentation is loading. Please wait.
Published byReynold Higgins Modified over 9 years ago
1
Creative Commons Attribution Non-Commercial Share Alike License http://creativecommons.org/licenses/by-nc- sa/3.0/http://creativecommons.org/licenses/by-nc- sa/3.0/ Original Developer: Beth Simon, 2009 bsimon@cs.ucsd.edu
2
CSE8A Lecture 21 Read next class: read pg 300-308 and 312-321 Freshman seminar: Peer Instruction Research CSE 8A Art Show! Sat Nov 14 10:30-12 noon –Print out your code! –Show up at 10am to tape up your poster and code! –What do we have on chromakey? (check out wiki) Help future 8A students! –Wiki of CSE terminology (demo) Solutions to midterm posted on moodle –Pick up midterms today (solutions don’t have problems listed)
3
Picking up midterm after class (I’ll bring leftovers up to discussion and to class on Monday)
4
By the end of today’s class you should be able to… LG41: Read, trace, and write code to change the volume of a Sound object (using for each, while and for loops) LG42: Compare and contrast the difference between changing the Color of Pixels in a Picture to changing the volume of SoundSamples in a Sound. LG43: Trace execution of sound code using multiple loops and if statements. LG44: Be able to use either array-based or method-based (API) access for (getting/reading, setting/writing) sound File. LG45: Be able to explain in plain English what code modifying Sounds does. LG46: Trace indexing patterns in code to perform Sound manipulations (e.g., reversing a sound).
5
Lab Note: More than one way to modify Sounds SoundSample[] noiseArray = noise.getSamples(); for (int i = 0; i < noiseArray.length; i++) { SoundSample sample = noiseArray[i]; int foo = sample.getValue(); sample.setValue(foo/2); } int foo = noise.getSampleValueAt(); noise.setSampleValueAt(foo/2); int foo = noise.getSampleValueAt(i); noise.setSampleValueAt(foo/2); int foo = noise.getSampleValueAt(i); noise.setSampleValueAt(i,foo/2); int foo = this.getSampleValueAt(); this.setSampleValueAt(foo/2); int foo = this.getSampleValueAt(i); this.setSampleValueAt(i,foo/2);
6
Conceptual Highlight Get/Read Value Pixel[] foo = xxx.getPixels(); Color c = foo[i].getColor(); Pixel bar = xxx.getPixel(x,y); Color c = bar.getColor(); SoundSample[] foo = xxx.getSamples(); int value = foo[i].getValue(); int value = xxx.getSampleValueAt(i); Set/Modify Value foo[i].setColor(modC); Pixel bar = xxx.getPixel(x,y); bar.setColor(modC); foo[i].setValue(modValue); xxx.setSampleValueAt(i,modValue);
7
For you to practice Write that code using a –While loop Write a code that reduces the volume of every other SoundSample. What does that really sound like?
8
Lab Review: What does this code do? 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 public void lab7Quiz3(Sound mySound) { Sound[] source = this.getSamples(); Sound[] result = mySound.getSamples(); for (int i = source.length/2; i < source.length; i++) { int value = source[i].getValue(); result[i].setValue(value); }
9
What’s printed by this code? (assume calling object ( this ) as shown) A.0,9 B.60,0 C.90,5 D.100,4 E.None of the above public void guess() { SoundSample[] noiseArray = this.getSamples(); int a, b = 0; for (int i=0;i<noiseArray.length; i++) { SoundSample sample = noiseArray[i]; int foo = sample.getValue(); if (foo > a) { a = foo; b = i; } S.o.pln(a + “,”+b); }
10
What’s printed by this code? (assume calling object ( this ) as shown) A.0,9 B.0,6 C.90,5 D.32767, 0 E.None of the above public void guess() { SoundSample[] noiseArray = this.getSamples(); int a = 32767; int b = 0; for (int i=0;i<noiseArray.length; i++) { SoundSample sample = noiseArray[i]; int foo = sample.getValue(); if (foo < a) { a = foo; b = i; } S.o.pln(a + “,”+b); }
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.