Processing Sound Ranges part 3

Slides:



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

Week 7 - Friday.  What did we talk about last time?  Array examples.
Computer Science 101 Introduction to Programming with Sounds.
Intro-Sound-part21 Introduction to Processing Digital Sounds part 2 Barb Ericson Georgia Institute of Technology Oct 2009.
Georgia Institute of Technology Two-Dimensional Arrays and Nested Loops – part 6 Barb Ericson Georgia Institute of Technology August 2005.
NestedLoops-part31 Nested Loops – part 3 Barb Ericson Georgia Institute of Technology Nov 2009.
Introduction to Computing and Programming in Python: A Multimedia Approach Chapter 7: Modifying Samples in a Range.
Problem Solving with Data Structures using Java: A Multimedia Approach Chapter 5: Arrays: A Static Data Structure for Sounds.
Computing with Digital Media: A Study of Humans and Technology Mark Guzdial, School of Interactive Computing.
NestedLoops-part11 Nested Loops – part 1 Barb Ericson Georgia Institute of Technology Nov 2009.
COSC 1P02 Introduction to Computer Science 4.1 Cosc 1P02 Week 4 Lecture slides “Programs are meant to be read by humans and only incidentally for computers.
Georgia Institute of Technology Introduction to Processing Digital Sounds part 1 Barb Ericson Georgia Institute of Technology Sept 2005.
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.
NestedLoops-Mod7-part31 Two-Dimensional Arrays and Nested Loops – part 3 Bugs in the garden Originally by Barb Ericson Georgia Institute of Technology.
CreatingSubclasses1 Barb Ericson Georgia Institute of Technology Dec 2009.
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.
Georgia Institute of Technology Creating Classes part 4 Barb Ericson Georgia Institute of Technology May 2006.
Georgia Institute of Technology Movies part 4 Barb Ericson Georgia Institute of Technology April 2006.
Intro-Sound-part1 Introduction to Processing Digital Sounds part 1 Barb Ericson Georgia Institute of Technology Oct 2009.
Binary! Objectives How sound is stored in digital format What is meant by “sample interval” and how it affects quality The trade off between file size.
Georgia Institute of Technology Speed part 4 Barb Ericson Georgia Institute of Technology May 2006.
Sound “A sound man…”. Frequency The frequency of a sound wave is perceived as the pitch (note) –High frequency → high pitch → high note –“Middle C” has.
Chapter 8: Modifying Samples in a Range. Chapter Objectives.
Session 18 The physics of sound and the manipulation of digital sounds.
Intro-Sound-Mod10-part31 Introduction to Processing Digital Sounds part 3 while loop, tracing, for loop, parameters Barb Ericson Georgia Institute of Technology.
1 CS 177 Week 7 Recitation Slides Modifying Sounds using Loops + Discussion of some Exam Questions.
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 Two-Dimensional Arrays and Nested Loops – part 2 Barb Ericson Georgia Institute of Technology August 2005.
NestedLoops-Mod7-part61 Two-Dimensional Arrays and Nested Loops – part 6 Enlarge Barb Ericson Georgia Institute of Technology August 2005.
Georgia Institute of Technology More on Creating Classes Barb Ericson Georgia Institute of Technology June 2006.
Manipulating Pictures, Arrays, and Loops part 2
Week 7 - Wednesday CS 121.
Chapter 8: Making Sounds by Combining Pieces
Georgia Institute of Technology
Processing Sound Ranges part 1
Processing Sound Ranges part 3
Barb Ericson Georgia Institute of Technology Dec 2009
Pitch.
Manipulating Pictures, Arrays, and Loops part 2
Manipulating Pictures, Arrays, and Loops
Chapter 7: Modifying Samples in a Range
Hearing and Mechanoreceptors
Barb Ericson Georgia Institute of Technology August 2005
Introduction to Processing Digital Sounds part 2
Manipulating Pictures, Arrays, and Loops part 5
Arrays versus ArrayList
Processing Sound Ranges part 1
Remember me? The number of times this happens in 1 second determines the frequency of the sound wave.
How sound works: Acoustics, the physics of sound
Chapter 7: Modifying Samples in a Range
Introduction to Processing Digital Sounds part 3
Two-Dimensional Arrays and Nested Loops – part 2
Manipulating Pictures, Arrays, and Loops
Two-Dimensional Arrays and Nested Loops – part 6
Manipulating Pictures, Arrays, and Loops
Introduction to Processing Digital Sounds
Processing Sound Ranges part 2
Processing Sound Ranges
Two-Dimensional Arrays and Nested Loops – part 6
CS 177 Week 9 Recitation Slides
Cornell Notes Sound Waves
More on Creating Classes
Manipulating Pictures, Arrays, and Loops
CS1315: Introduction to Media Computation
Manipulating Pictures, Arrays, and Loops part 6
Creating Sounds and MIDI
Presentation transcript:

Processing Sound Ranges part 3 Barb Ericson Georgia Institute of Technology Sept 2005 Georgia Institute of Technology

Georgia Institute of Technology Learning Goals Processing ranges of Sound values Blending pictures Changing the sound frequency Computing concepts Method overloading Changing a for loop to increment by a value other than 1 Modifying a method to be more general Georgia Institute of Technology

Modify Blend Sounds Exercise Create another blendSounds method That takes the file name of the sounds to blend And a value to start the blend at and another to stop the blend at Modify the original blendSounds method to call this one Georgia Institute of Technology

Georgia Institute of Technology Overloading Methods You can have several methods with the same name As long as the parameter list is different In number of parameters And/or types of parameters blendSounds() blendSound(String name1, String name2, int startBlend, int endBlend) The types are the important thing. The compiler will figure out which method you want based on the type. Georgia Institute of Technology

Changing the Sound Frequency The frequency of a wave is the number of cycles per second (cps), or Hertz (Hz) (Complex sounds have more than one frequency in them.) Our perception of pitch is related (logarithmically) to changes in frequency Higher frequencies are perceived as higher pitches We can hear between 5 Hz and 20,000 Hz (20 kHz) A above middle C is 440 Hz Georgia Institute of Technology

Georgia Institute of Technology Double the Frequency If we take every other sample we double the frequency of the sound Completes two cycles instead of one in the same time It will sound higher 100 | 200 | 300 | 400 | 500 100 | 300 | 500 | 0 | 0 Georgia Institute of Technology

Double Frequency Method public void doubleFreq() { // make a copy of the original sound Sound s = new Sound(this.getFileName()); /* loop and increment target index * by one but source index by 2, * and set target value * to the copy of the original sound */ Georgia Institute of Technology

Double Frequency - Continued for (int sourceIndex=0, targetIndex = 0; sourceIndex < this.getLength(); sourceIndex=sourceIndex+2, targetIndex++) this.setSampleValueAt(targetIndex, s.getSampleValueAt(sourceIndex)); // clear out the rest of this sound to silence (0) for (int i = this.getLength() / 2; i < this.getLength(); i++) this.setSampleValueAt(i,0); } Georgia Institute of Technology

Georgia Institute of Technology Test Double Frequency Sound s = new Sound(FileChooser.getMediaPath( "c4.wav")); s.explore(); s.doubleFreq(); The file c4.wav is the note C played on a piano in the fourth octave. Georgia Institute of Technology

Georgia Institute of Technology Challenge Create a method that will take every third sample Will this sound higher or lower? Can you make this method more general? By passing in the amount to add to the source index each time? Georgia Institute of Technology

Georgia Institute of Technology Halving the Frequency We can copy each source value twice to half the frequency Only get through half a cycle in the same time we used to get through a full cycle It will sound lower This is the same algorithm that we used to scale up a picture 100 | 200 | 300 | 400 | 500 100 | 100 | 200 | 200 | 300 Georgia Institute of Technology

Halve Frequency Method public void halveFreq() { // make a copy of the original sound Sound s = new Sound(this.getFileName()); /* loop through the sound and increment target index * by one but source index by 0.5 and set target value * to the copy of the original sound */ for (double sourceIndex=0, targetIndex = 0; targetIndex < this.getLength(); sourceIndex=sourceIndex+0.5, targetIndex++) this.setSampleValueAt((int) targetIndex, s.getSampleValueAt((int) sourceIndex)); } Georgia Institute of Technology

Testing Halve Frequency Sound s = new Sound(FileChooser.getMediaPath( "c4.wav")); s.explore(); s.halveFreq(); Georgia Institute of Technology

Change Frequency Exercise Write a method that will copy each sound value 4 times to the target Will the new sound be higher or lower? Can you make this more general? By passing in the number of times to copy the source value Try it with 3 times and check the index values to make sure that you are doing it right You can add 0.5 and 0.25 and the (int) of that will work fine. But, you can have trouble with things like 1/3 which is .3333333 (and so on). Computers can’t do infinite numbers. So, they have to approximate them. So adding .33 each time will not get over 1 the way it should. Georgia Institute of Technology

Georgia Institute of Technology Summary You can have more than one method with the same name: method overloading As long as the parameter list is different Different number of parameters Different types of parameters You can increment or decrement loop variables by numbers other than 1 You can make methods more general By passing in parameters Some algorithms are the same for pictures and sounds Scaling a picture down and doubling the frequency of a sound Georgia Institute of Technology