Processing Sound Ranges part 3

Slides:



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

Sound, Part 3. Multiple Echoes Here is a recipe to create multiple echoes: def echoes(sndfile, delay, num): s1 = makeSound(sndfile) ends1 = getLength(s1)
Chapter 8: Making Sounds by Combining Pieces. Chapter Objectives.
Introduction to Computing and Programming in Python: A Multimedia Approach Chapter 8: Making Sounds by Combining Pieces.
Week 7 - Friday.  What did we talk about last time?  Array examples.
Intro-Sound-part31 Introduction to Processing Digital Sounds part 3 Barb Ericson Georgia Institute of Technology Oct 2009.
Sound, Part 2 Using range to manipulate samples by index number.
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.
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.
Basics of Digital Audio Outline  Introduction  Digitization of Sound  MIDI: Musical Instrument Digital Interface.
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.
Introduction to Computing and Programming in Python: A Multimedia Approach Chapter 8: Making Sounds by Combining Pieces.
Physics of Sound Part 1 Sound waves How they are generated and travel.
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.
Introduction to Computing and Programming in Python: A Multimedia Approach Chapter 7: Modifying Samples in a Range.
Georgia Institute of Technology Manipulating Pictures, Arrays, and Loops Barb Ericson Georgia Institute of Technology August 2005.
ManipulatingPictures-Mod6-part61 Manipulating Pictures, Arrays, and Loops: Eliminating color, Inversion, grey scale and adjusting for luminance Barb Ericson.
CPSC1301 Computer Science 1 Chapter 8 Introduction to Processing Digital Sounds part 3.
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.
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.
CSE 8A Lecture 14 Reading for next class: None (INTERM EXAM #3) Today’s topics: –More Sounds! PSA 6 due tonight PSA 7 (sounds) due next Monday (11/19)
Session 18 The physics of sound and the manipulation of digital sounds.
COSC 1P02 Introduction to Computer Science 5.1 Cosc 1P02 Week 5 Lecture slides Psychiatrist to patient "You have nothing to worry about - anyone who can.
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.
12-3 Harmonics.
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.
Working with Sounds Barb Ericson College of Computing Georgia Institute of Technology
Frequency determines pitch
Week 7 - Wednesday CS 121.
Chapter 8: Making Sounds by Combining Pieces
Georgia Institute of Technology
Processing Sound Ranges part 1
Pitch.
Manipulating Pictures, Arrays, and Loops
Chapter 7: Modifying Samples in a Range
Translating to Algebraic Expressions
Introduction to Processing Digital Sounds part 2
Arrays versus ArrayList
Chapter 8: Making Sounds by Combining Pieces
Processing Sound Ranges part 1
How sound works: Acoustics, the physics of sound
Chapter 7: Modifying Samples in a Range
Week 9 – Audio Processing
Introduction to Processing Digital Sounds part 3
Two-Dimensional Arrays and Nested Loops – part 2
Copyright © 2017, 2013, 2009 Pearson Education, Inc.
Manipulating Pictures, Arrays, and Loops
Manipulating Pictures, Arrays, and Loops
Two-Dimensional Arrays and Nested Loops – part 6
Introduction to Processing Digital Sounds
Processing Sound Ranges part 2
Processing Sound Ranges
Two-Dimensional Arrays and Nested Loops – part 6
Cornell Notes Sound Waves
EXPRESSIONS, PAUSES AND SOUNDS
Processing Sound Ranges part 3
CS1315: Introduction to Media Computation
Creating Sounds and MIDI
Presentation transcript:

Processing Sound Ranges part 3 Barb Ericson Georgia Institute of Technology Oct 2009 UsingSoundRanges-part3

UsingSoundRanges-part3 Learning Goals Processing ranges of Sound values Creating echoes Changing the sound frequency Computing concepts Changing a for loop to increment by a value other than 1 Modifying a method to be more general UsingSoundRanges-part3

UsingSoundRanges-part3 Echo By blending a sound with itself we can make an echo Add the sound values to the same sound but after some delay UsingSoundRanges-part3

UsingSoundRanges-part3 Method echo public void echo(int delay) { // make a copy of the original sound Sound s = new Sound(this.getFileName()); int value = 0; // loop from delay to end of sound for (int i = delay; i < this.getLength(); i++) UsingSoundRanges-part3

UsingSoundRanges-part3 Method echo continued /* get the value back by delay samples from the * copy of the sound and make it fainter */ value = (int) (s.getSampleValueAt(i-delay) * 0.6);   /* set the value at the current index to the sum * of the current value and the echo */ this.setSampleValueAt(i, this.getSampleValueAt(i) + value); } UsingSoundRanges-part3

UsingSoundRanges-part3 Test the echo method String fileName = FileChooser.getMediaPath( "thisisatest.wav"); Sound sound = new Sound(fileName); sound.explore(); sound.echo(20000); UsingSoundRanges-part3

UsingSoundRanges-part3 How does that work? The echo method takes an integer delay The number of samples to wait before starting the echo It makes a copy of the current sound So that we copy without the echo Loop starting from delay to the end of the sound Get the value at i-delay and multiply it by 0.6 to make it quieter Set the current sound value at i to the current value at i plus the calculated value UsingSoundRanges-part3

Creating Multiple Echoes You can use a nested loop to create multiple echoes Here is an example nested loop in Alice UsingSoundRanges-part3

Creating Multiple Echoes Method public Sound echo(int delay, int numEchoes) { int soundLength = this.getLength(); Sound echoSound = new Sound(numEchoes * delay + soundLength); int value = 0; int echoIndex = 0; int echoValue = 0; double echoAmplitude = 1; // to start // copy the original sound echoSound.splice(this,0,soundLength,0); /* loop starting with 1 to create the first echo at the * right place and end when = the number of echoes */ UsingSoundRanges-part3

Multiple Echoes - continued for (int echoCount = 1; echoCount <= numEchoes; echoCount++) { // decrease the volume (amplitude) of the echo echoAmplitude = echoAmplitude * 0.6; // echo the whole sound for (int i = 0; i < soundLength; i++) echoIndex = i + (delay * echoCount); echoValue = (int) (this.getSampleValueAt(i) * echoAmplitude); echoSound.setSampleValueAt(echoIndex,echoValue + echoSound.getSampleValueAt(echoIndex)); } return echoSound; UsingSoundRanges-part3

UsingSoundRanges-part3 Try Multiple Echoes Sound s = new Sound( FileChooser.getMediaPath("croak.wav")); Sound e = s.echo(8000,5); e.play(); UsingSoundRanges-part3

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 UsingSoundRanges-part3

UsingSoundRanges-part3 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 UsingSoundRanges-part3

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 */ UsingSoundRanges-part3

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); } UsingSoundRanges-part3

UsingSoundRanges-part3 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. UsingSoundRanges-part3

UsingSoundRanges-part3 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? UsingSoundRanges-part3

UsingSoundRanges-part3 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 100 | 200 | 300 | 400 | 500 100 | 100 | 200 | 200 | 300 UsingSoundRanges-part3

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)); } UsingSoundRanges-part3

Testing Halve Frequency Sound s = new Sound(FileChooser.getMediaPath( "c4.wav")); s.explore(); s.halveFreq(); UsingSoundRanges-part3

UsingSoundRanges-part3 Challenge 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. UsingSoundRanges-part3

UsingSoundRanges-part3 Summary You can increment or decrement loop variables by numbers other than 1 You can make methods more general By passing in parameters UsingSoundRanges-part3