Introduction to Processing Digital Sounds part 2

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming Lecture 5 Array and Collections.
Advertisements

Georgia Institute of Technology Introduction to Processing Digital Sounds.
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.
Loops – While, Do, For Repetition Statements Introduction to Arrays
1 Lecture Today’s topic Arrays Reading for this Lecture: –Chaper 11.
1 Recitation 7. Developing loops Introduction. This recitation concerns developing loops using their invariants and bound functions. Your recitation instructor.
Intro-Sound-part21 Introduction to Processing Digital Sounds part 2 Barb Ericson Georgia Institute of Technology Oct 2009.
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
Georgia Institute of Technology Introduction to Processing Digital Sounds part 1 Barb Ericson Georgia Institute of Technology Sept 2005.
New Tools And Workshop Mod & For Loops. Modulo Calculates the remainder (remember long division?) % Examples: 7 % 3 10 % 2 2 % 3 evaluates to 1 evaluates.
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.
6.2 For…Next Loops General Form of a For…Next Loop
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.
Intro-Sound-part1 Introduction to Processing Digital Sounds part 1 Barb Ericson Georgia Institute of Technology Oct 2009.
Georgia Institute of Technology Creating Classes part 2 Barb Ericson Georgia Institute of Technology June 2006.
Georgia Institute of Technology Speed part 4 Barb Ericson Georgia Institute of Technology May 2006.
Georgia Institute of Technology What is new in Java 5.0 (1.5)? Barb Ericson Georgia Institute of Technology June 2006.
Intro-Sound-Mod10-part31 Introduction to Processing Digital Sounds part 3 while loop, tracing, for loop, parameters Barb Ericson Georgia Institute of Technology.
ManipulatingPictures-part31 Manipulating Pictures, Arrays, and Loops part 3 Barb Ericson Georgia Institute of Technology Nov 2009.
Comp 248 Introduction to Programming Chapter 6 Arrays Part A Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia University,
04-ManipulatingPictures-part21 Manipulating Pictures, Arrays, and Loops part 2 Barb Ericson Georgia Institute of Technology June 2008.
Arrays. What is an array? An array is a collection of data types. For example, what if I wanted to 10 different integers? int num1; int num2; int num3;
Introduction to programming in java Lecture 21 Arrays – Part 1.
Comp1004: Loops and Arrays I Whiles, For and Arrays[]
Barbara Ericson Georgia Tech Sept 2005
Sections 10.1 – 10.4 Introduction to Arrays
Some Assignments  Write a program which prints the following information about at least 5 persons: NAME MAIL-ID EMPLOYEE-CODE PHONE Eg. Umesh
Manipulating Pictures, Arrays, and Loops part 2
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
Barb Ericson Georgia Institute of Technology Dec 2009
Manipulating Pictures, Arrays, and Loops part 2
Manipulating Pictures, Arrays, and Loops part 2
Arrays, For loop While loop Do while loop
Manipulating Pictures, Arrays, and Loops
Manipulating Pictures, Arrays, and Loops part 5
Arrays versus ArrayList
Java Programming Loops
Processing Sound Ranges part 1
Manipulating Pictures, Arrays, and Loops part 3
Barb Ericson Georgia Institute of Technology June 2006
Topics discussed in this section:
Introduction to Processing Digital Sounds part 3
CS2011 Introduction to Programming I Arrays (I)
Barb Ericson Georgia Institute of Technology Oct 2005
Workshop for Programming And Systems Management Teachers
Manipulating Pictures, Arrays, and Loops
Manipulating Pictures, Arrays, and Loops
Arrays.
Manipulating Pictures, Arrays, and Loops
Introduction to Processing Digital Sounds
Processing Sound Ranges part 2
Manipulating Pictures, Arrays, and Loops part 6
Processing Sound Ranges
Manipulating Pictures, Arrays, and Loops
Processing Sound Ranges part 3
Introduction to Computer Science
Creating and Modifying Text part 3
Barb Ericson Georgia Institute of Technology Oct 2005
CSC1401 Manipulating Pictures 2
Manipulating Pictures, Arrays, and Loops part 6
Week 7 - Monday CS 121.
Arrays: Iteration Working through an array algorithmically.
Presentation transcript:

Introduction to Processing Digital Sounds part 2 Barb Ericson Georgia Institute of Technology Sept 2005 Georgia Institute of Technology

Georgia Institute of Technology Learning Goals Introduce Sound manipulation as a way to review Arrays Declaring variables Sending objects messages Iteration (Loops) Writing methods Georgia Institute of Technology

Getting the Sound Sample Values A Sound has many values in it Numbers that represent the sound at that time in the sample You can get an array of SoundSample objects SoundSample[] sampleArray = sound1.getSamples(); An array of objects is an array of object references. The value in the array is a reference to the actual object (a way to calculate where it is). Georgia Institute of Technology

Explore the Sound Sample Values Zoom in to see all the sound values Click here to pick an index See the value Type in an index Click here to go to the next index Georgia Institute of Technology

Print the Sound Sample Value You can get the SoundSample object from the array at an index SoundSample sample = sampleArray[0]; And then get the value from that System.out.println(sample.getValue()); What are the first 10 values of the Sound created from the file croak.wav? Georgia Institute of Technology

Changing the Value of a Sound Sample You can set the value of a SoundSample sample.setValue(value); This will change the value in the Sound object as well So how would you change the value to the original value * 2? SoundSample sample = sampleArray[0]; sample.setValue(sample.getValue() * 2); Georgia Institute of Technology

Doubling all the Sound Values You could change each SoundSample by hand There are 8808 SoundSamples in croak.wav Do you really want to do that? How long would it take you? Let’s let the computer do it in a loop For-each While For Georgia Institute of Technology

Georgia Institute of Technology For-Each Loop (Java 5.0) For each of the elements in a collection of objects do the body of the loop Each time through the loop the variableName will refer to a different object in the collection for (type variableName : collection) { // statement to repeat } Only use this if you are using Java 5.0 (1.5) or greater! It is not part of Java 1.4. Georgia Institute of Technology

For-Each Loop to Process Sound Samples SoundSample[] sampleArray = this.getSamples(); int value = 0; for (SoundSample sample : sampleArray) { value = sample.getValue(); // get the value sample.setValue(value * 2); // set the value } Georgia Institute of Technology

Increase Volume with For-Each Loop public void increaseVolume() { SoundSample[] sampleArray = this.getSamples(); int value = 0; // value at sample // loop through SoundSample objects for (SoundSample sample : sampleArray) value = sample.getValue(); // get the value sample.setValue(value * 2); // set the value } Georgia Institute of Technology

Testing increaseVolume String file = FileChooser.getMediaPath(“gettysburg10.wav“); Sound soundObj = new Sound(file); soundObj.play(); soundObj.explore(); soundObj.increaseVolume(); Georgia Institute of Technology

Decrease Volume Exercise Write a method to decrease the volume of the sound decreaseVolume() Divide each value by 2 What parts need to change from the last method? Only the calculation of the new value Try it: Sound s = new Sound( FileChooser.getMediaPath(“ gettysburg10.wav”)); s.explore(); s.decreaseVolulme(); Georgia Institute of Technology

Georgia Institute of Technology What Does For-Each Do? It needs to use each element in the array one and only one time So it needs to keep track of the current index It needs to check that the current index is less than the length of the array And stop when they are equal It needs to increment the index after the loop body has executed This is explicit in a while loop Georgia Institute of Technology

Georgia Institute of Technology Summary Sound samples are stored in an array SoundSample[] sampleArray = this.getSamples(); You can get the SoundSample from an array SoundSample sample = sampleArray[0]; We can get and set the value of a SoundSample int value = sample.getValue(); sample.setValue(value * 2); For-Each Loop Use a for-each loop to repeat a statement or block of statements for each element in an array Georgia Institute of Technology