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 23 • Read next class: read 321 -325, Chapter 11: 343 -366 • Thanks! terminology wiki – Add your thoughts or modify those of others… • What’s happening the rest of the term – Finish Chapter 10 (Sound) – Chapter 11 (Creating your own classes) – Arrays – not just for Sounds and Pictures anymore… – Week 9 (Tgiving) • Beth in Europe, Leo Lectures Monday • No class, No lab Wed • PSA 8 due Tues 11: 59 (individual – Sound collage) – Week 10 • PSA 9 due WED 11: 59 pm (pair – Make a class) • Lecture all week, Exam Wed of finals week 3 -6 pm
Are you planning to enroll in 8 B? A. Yes B. No C. Maybe in Spring D. Not sure
By the end of today’s class you should be able to… • 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, create echos). • LG 47: Identify scenarios where object transformations lead to objects of different “sizes”. • LG 48: Create a Sound of a specific “length” or duration using new • LG 48: Read, trace, and write methods which creates and returns new objects (rather than modifying calling objects). • LG 49: Identify issues with overwriting arrays when trying to “modify in place”.
Trace this code: where foo is 5 public Sound funky 2(int foo) { Sound s = new Sound(this. get. File. Name()); int value = 0; for (int i = foo; i < this. get. Length(); i++) { value = (int) s. get. Sample. Value. At(i) *. 1; this. set. Sample. Value. At(i-foo, value + this. get. Sample. Value. At(i-foo)); } }
Understanding the impact of changing pitch • Play a recording of someone reading a sentence • Play it so that it sounds “high pitched” – How long does it take to play the sound high pitched? – What is it was a “lower” pitch? How long?
Raise the pitch of a Sound • Take every nth sample
Draw the resulting wave
Options to raise. Pitch • Create new Sound – V 1) Of same length as original with “silence” at end – V 2) Of exact length needed for higher pitched sound • Modify existing Sound – V 3) Will be of same length with “silence” at end
V 1: Create new sound of same length with 0 at end • Common technique: object (Sound) that is the “base” is the calling object. – If extra information is needed we pass it in as parameter – If creating something “new” we return it <<<INSERT METHOD HEADER HERE>>> Sound high. P = ZZZZZZ; Sound. Sample[] original = XXXX. get. Samples(); Sound. Sample[] higher = high. P. get. Samples(); <<SOME LOOP HERE TO COPY ORIGINAL INTO HIGHER>> public void raise. P(Sound s) new Sound(s); s. get. Samples(); public void raise. P(Sound s) s. get. Samples(); this. get. Samples(); public Sound raise. P() new Sound(this); this. get. Samples();
Options to raise. Pitch • Create new Sound – V 1) Of same length as original with “silence” at end – V 2) Of exact length needed for higher pitched sound • Modify existing Sound – V 3) Will be of same length with “silence” at end
V 2: Create new sound of CORRECT length (1/2) <<<INSERT METHOD HEADER HERE>>> { Sound high. P = <<<XXXX>>> Sound. Sample[] original =<<<XXXX>>> Sound. Sample[] higher = high. P. get. Samples(); <<SOME LOOP HERE TO COPY ORIGINAL INTO HIGHER>> } public void raise. P() this; this. get. Samples(); public Sound raise. P() new Sound(this); this. get. Samples(); public void raise. P() this. get. Length()/2; this. get. Samples(); public Sound raise. P() new Sound(this. get. Length()/2); this. get. Samples();
V 2: Create new sound of CORRECT length (1/2) public Sound raise. P() { Sound high. P = Sound. Sample[] original = Sound. Sample[] higher = high. P. get. Samples(); int new. Place = 0; for (int orig. I = 0; orig. I < original. length; orig. I+=2) { <<LINES GO HERE>> higher[new. Place]. set. Value( original[orig. I]. get. Value()); new. Place = orig. I; } } higher[new. Place]. set. Value( original[orig. I]. get. Value()); new. Place++; original[orig. I]. get. Value( higher[new. Place]. set. Value()); new. Place = orig. I; original[orig. I]. get. Value( higher[new. Place]. set. Value()); new. Place++;
- Slides: 14