Presentation is loading. Please wait.

Presentation is loading. Please wait.

Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/http://creativecommons.org/licenses/by-nc-

Similar presentations


Presentation on theme: "Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/http://creativecommons.org/licenses/by-nc-"— Presentation transcript:

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 22 Read next class: REPEAT read 312-321 Freshman seminar: Peer Instruction Research CSE 8A Art Show! ROCKED! Help future 8A students!: terminology wiki Solutions to midterm posted on moodle Advising on your next courses (next)

3 Majors: What courses to take next term (cape.ucsd.edu) CSE8B –(10 hours a week), 5 programs, 5 quizzes, 1 MT CSE15L (highly recommended before 12) –(2-4 hours a week) Maybe CSE20 (no programming) –(4-6 hours a week) –CSE 20 and 21 are computing “math classes” –Pre-req for 30 (and 21) –CSE21 pre-req for 100 (maybe you’ll take this in fall 2010…) if so you want to take 20 next term

4 Non-majors If you have/plan to take 8B, take it NEXT TERM –Hard to get “back” into programming ICAM – 8B required Hey? Interested in majoring? –WE WANT YOU! –Well paying (and cool) jobs are available in CSE! –Feel good that you “make things” other people use! –Changes likely…

5 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).

6 What does this code do? A.Sets the end of the array to 0s. B.Finds the first value C.Finds the minimum (and its location) D.Finds the maximum (and its location) E.Finds the last value …for (int i=0;i<noiseArray.length; i++) { SoundSample sample = noiseArray[i]; int foo = sample.getValue(); if (foo > a) { a = foo; b = i; }

7 Why would we do that?: Normalizing 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; } double factor = 32767 / a; for (int i = 0; i < noiseArray.length; i++) { SoundSample sample = noiseArray[i]; sample.setValue((int) sample.getValue() * factor)); }

8 How does my SoundSample[] change? public void funky() { SoundSample[] noiseArray = this.getSamples(); int zzz = 0; for (int i=0;i<noiseArray.length; i++) { SoundSample sample = noiseArray[i]; int foo = sample.getValue(); zzz += foo; } int yyy = zzz / noiseArray.length; for (int i = 0; i < noiseArray.length; i++) { SoundSample sample = noiseArray[i]; sample.setValue(yyy); }

9 SPEEDY: What does that code do? A.Makes it higher pitched B.Makes it louder C.Makes if lower pitched D.Makes it quieter E.Makes a silent sound public void funky() { SoundSample[] noiseArray = this.getSamples(); int zzz = 0; for (int i=0;i<noiseArray.length) { SoundSample sample = noiseArray[i]; int foo = sample.getValue(); zzz += foo; } int yyy = zzz / noiseArray.length; for (int i = 0; i < noiseArray.length; i++) { SoundSample sample = noiseArray[i]; sample.setValue(yyy); }

10 “Clipping” or Force to Extremes: What would happen to the array “What if all positive values (including zero) were (set to) the maximum value (32,767) and all negative values were set to the minimum value (-32,768)?

11 “Clipping” or Force to Extremes: What would happen to the array “ What if all positive values (including zero) were (set to) the maximum value (32,767) and all negative values were set to the minimum value (-32,768)? if (foo[i].getValue() >= 0)if (i >= 0) if (foo[i].getValue() < 0) if (i < 0) SoundSample[] foo = this.getSamples(); for (int i = 0; i < foo.length; i++) { > foo[i].setValue(32767); else foo[i].setValue(-32768);

12 Speaking backwards… But creating NEW Sound We want to do this: What should be the indices (indexes) we use for: sourceIndex targetIndex

13 Write the code… (on your own… type it in to see if it works) SoundSample[] sourceAr = source.getSamples(); SoundSample[] targetAr = target.getSamples() for ( { int value = sourceAr[sourceIndex].getValue(); targetAr[targetIndex].setValue(value); }


Download ppt "Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/http://creativecommons.org/licenses/by-nc-"

Similar presentations


Ads by Google