Intro-Sound-Mod10-part31 Introduction to Processing Digital Sounds part 3 while loop, tracing, for loop, parameters Barb Ericson Georgia Institute of Technology.

Slides:



Advertisements
Similar presentations
Georgia Institute of Technology Introduction to Processing Digital Sounds.
Advertisements

ManipulatingPictures-Mod6-part21 Manipulating Pictures, Arrays, and Loops part 2 Barb Ericson Georgia Institute of Technology.
Intro-Sound-part31 Introduction to Processing Digital Sounds part 3 Barb Ericson Georgia Institute of Technology Oct 2009.
Animation Mrs. C. Furman. Animation  We can animate our crab by switching the image between two pictures.  crab.png and crab2.png.
Computer Science 1620 Loops.
Loops – While, Do, For Repetition Statements Introduction to Arrays
1 CS 177 Week 15 Recitation Slides Review. Announcements Final Exam on Sat. May 8th  PHY 112 from 8-10 AM Complete your online review of your classes.
Conditionals-part11 Barb Ericson Georgia Institute of Technology Nov 2009.
Intro-Sound-part21 Introduction to Processing Digital Sounds part 2 Barb Ericson Georgia Institute of Technology Oct 2009.
C++ / G4MICE Course Session 3 Introduction to Classes Pointers and References Makefiles Standard Template Library.
01- Intro-Java-part1 1 Introduction to Java, and DrJava Barb Ericson Georgia Institute of Technology June 2008.
Georgia Institute of Technology Introduction to Java, and DrJava Barb Ericson Georgia Institute of Technology Aug 2005.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
CreatingClasses-part11 Creating Classes part 1 Barb Ericson Georgia Institute of Technology Dec 2009.
Georgia Institute of Technology Creating Classes part 1 Barb Ericson Georgia Institute of Technology Oct 2005.
Georgia Institute of Technology Movies part 5 Barb Ericson Georgia Institute of Technology April 2006.
Georgia Institute of Technology Processing Sound Ranges Barb Ericson Georgia Institute of Technology July 2005.
UsingSoundRanges-part21 Processing Sound Ranges part 2 Barb Ericson Georgia Institute of Technology Oct 2009.
Georgia Institute of Technology Manipulating Pictures, Arrays, and Loops Barb Ericson Georgia Institute of Technology August 2005.
TOPIC 6 MODIFYING PICTURES USING LOOPS 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
Introduction to Java Java Translation Program Structure
CSC1401 Classes - 2. Learning Goals Computing concepts Adding a method To show the pictures in the slide show Creating accessors and modifiers That protect.
ManipulatingPictures-Mod6-part61 Manipulating Pictures, Arrays, and Loops: Eliminating color, Inversion, grey scale and adjusting for luminance Barb Ericson.
Georgia Institute of Technology More on Creating Classes part 2 Barb Ericson Georgia Institute of Technology Oct 2005.
AP Computer Science edition Review 1 ArrayListsWhile loopsString MethodsMethodsErrors
CPSC1301 Computer Science 1 Chapter 8 Introduction to Processing Digital Sounds part 3.
CPSC1301 Computer Science 1 Chapter 4 Manipulating Pictures, Arrays, and Loops part 5.
Conditionals-part21 Conditionals – part 2 Barb Ericson Georgia Institute of Technology Nov 2009.
Intro-Sound-part1 Introduction to Processing Digital Sounds part 1 Barb Ericson Georgia Institute of Technology Oct 2009.
CreatingClasses-SlideShow-part31 Creating Classes part 3 Barb Ericson Georgia Institute of Technology Dec 2009.
Georgia Institute of Technology Creating Classes part 2 Barb Ericson Georgia Institute of Technology June 2006.
Georgia Institute of Technology What is new in Java 5.0 (1.5)? Barb Ericson Georgia Institute of Technology June 2006.
Repetition Statements (Loops). 2 Introduction to Loops We all know that much of the work a computer does is repeated many times. When a program repeats.
ManipulatingPictures-part31 Manipulating Pictures, Arrays, and Loops part 3 Barb Ericson Georgia Institute of Technology Nov 2009.
04-ManipulatingPictures-part21 Manipulating Pictures, Arrays, and Loops part 2 Barb Ericson Georgia Institute of Technology June 2008.
Georgia Institute of Technology Introduction to Java, and DrJava part 1 Dr Usman Saeed Assistant Professor Faculty of Computing and Information Technology.
Georgia Institute of Technology More on Creating Classes Barb Ericson Georgia Institute of Technology June 2006.
Barbara Ericson Georgia Tech Sept 2005
Manipulating Pictures, Arrays, and Loops part 2
Manipulating Pictures, Arrays, and Loops part 3
Georgia Institute of Technology
Processing Sound Ranges part 1
Processing Sound Ranges part 3
Manipulating Pictures, Arrays, and Loops part 2
CS 177 Week 15 Recitation Slides
Georgia Institute of Technology
Manipulating Pictures, Arrays, and Loops
Barb Ericson Georgia Institute of Technology August 2005
Introduction to Processing Digital Sounds part 2
Manipulating Pictures, Arrays, and Loops part 5
An Introduction to Java – Part I, language basics
Arrays versus ArrayList
<INSERT_WITTY_QUOTE_HERE>
Processing Sound Ranges part 1
Manipulating Pictures, Arrays, and Loops part 3
Barb Ericson Georgia Institute of Technology June 2006
Introduction to Processing Digital Sounds part 3
Manipulating Pictures, Arrays, and Loops
Manipulating Pictures, Arrays, and Loops
Introduction to Processing Digital Sounds
Processing Sound Ranges part 2
Processing Sound Ranges
Barb Ericson Georgia Institute of Technology June 2005
Barb Ericson Georgia Institute of Technology May 2006
More on Creating Classes
Manipulating Pictures, Arrays, and Loops
Processing Sound Ranges part 3
Barb Ericson Georgia Institute of Technology Oct 2005
Creating Sounds and MIDI
Presentation transcript:

Intro-Sound-Mod10-part31 Introduction to Processing Digital Sounds part 3 while loop, tracing, for loop, parameters Barb Ericson Georgia Institute of Technology

Intro-Sound-Mod10-part32 Learning Goals Review the while loop Increase and decrease the volume of a sound Trace a method Review the for loop Make a method more reusable by passing in a parameter

Intro-Sound-Mod10-part33 While Loop Loops while a boolean (true or false) test is true –When the test is false execution continues with the first statement after the loop while(test) { // statements to be done while the test is true } –To use a while loop you may need to declare variables before the loop and change them in the loop

Intro-Sound-Mod10-part34 While Loop to Double volume

Intro-Sound-Mod10-part35 Increase Volume with While Loop

Intro-Sound-Mod10-part36 Testing increaseVolume String file = "gettysburg10.wav"; Sound soundObj = new Sound(file); soundObj.play(); soundObj.explore(); soundObj.doubleVolume(); soundObj.play(); soundObj.explore();

Intro-Sound-Mod10-part37 Tracing Execution The index is set to 0 The value is set to the value in the array at that index (59) The sample value at the current index is set to 2 * value The index changes to the next index (1) We check if the index is less than the length of the array and –If so do the loop again –Else jump to the first statement after the loop

Intro-Sound-Mod10-part38 Memory versus Disk When we read from a file we read from disk into memory –Computers only do calculations on memory We change the values in memory The file on the disk hasn’t changed To save our new sound we need to write a file to the disk –soundObj.write(fileName);

Intro-Sound-Mod10-part39 Decrease Volume Exercise Write a method to decrease the volume of the sound –decreaseVolume() –Multiply each value by 0.5 What parts need to change from the last method? –Only the calculation of the new value Try it: Sound s = new Sound("gettysburg10.wav"); s.explore(); s.decreaseVolulme(); s.explore();

Intro-Sound-Mod10-part310 While Loop versus For Loop It is easy to make mistakes when you use a while loop for looping a set number of times –Forget to declare variables before the loop –Forget to increment the variables in the loop before the next test Programmers use a For loop when the number of times to loop is known –And a while loop when you don’t know

Intro-Sound-Mod10-part311 For Loop A for loop allows you to declare and initialize variables, specify the test, and specify the way the variables change –All in one place –But, they still happen in the usual place for(int index = 0; index < sampleArray.length; index++) { }

Intro-Sound-Mod10-part312 Double Volume with a For Loop public void doubleVolume() { SoundSample[] sampleArray = this.getSamples(); SoundSample s = null; int val = 0; // loop through all the samples in the array for (int index = 0; index < sampleArray.length; index++) { s = sampleArray[index]; val = s.getValue(); s.setValue(val * 2); }

Intro-Sound-Mod10-part313 Modify decreaseVolume Exercise Change decreaseVolume to use a for loop –Comment out declaration of the index –Comment out the increment of the index at the end of the loop –Comment out the while and put in a for loop Test it to make sure it still works –String file = “gettysburg10.wav“; –Sound soundObj = new Sound(file); –soundObj.explore(); –soundObj.decreaseVolume(); –soundObj.explore();

Intro-Sound-Mod10-part314 General Change Volume Method The methods increaseVolume and decreaseVolume are very similar –They multiply the current sound values by a given amount To change this you would need to modify the method and compile –The methods would be more reusable if we pass in the amount to multiply the current sound values by As a parameter to the method

Intro-Sound-Mod10-part315 change Volume with a For Loop What is different??

Intro-Sound-Mod10-part316 General changeVolume method Can this factor be an int? You could only increase volume if it is. setValue( ) must be an int value

Intro-Sound-Mod10-part317 Summary Use a while loop to execute a statement or block of statements while a boolean test is true –Often declare and initialize variables before the loop –And modify variables in the loop Use a for loop to execute a statement or block of statements while a boolean test is true –And specify how to initialize loop variables and change them after each loop in one place Use parameters to make methods more reusable