Week 9 – Audio Processing

Slides:



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

ITEC 109 Lecture 25 Sound.
From Sound to Music CSC 161: The Art of Programming Prof. Henry Kautz 11/16/2009.
Week 7 - Friday.  What did we talk about last time?  Array examples.
CS 177 Recitation Week 8 – Methods. Questions? Announcements  Project 3 milestone due next Thursday 10/22 9pm  Turn in with: turnin –c cs177=xxxx –p.
1 CS 177 Week 4 Recitation Slides Conditionals. 2 Announcements Project 1 is due on Feb. 7th 9pm (extended) Project 2 will be posted today (Feb. 5th)
Spring 2002EECS150 - Lec13-proj Page 1 EECS150 - Digital Design Lecture 13 - Final Project Description March 7, 2002 John Wawrzynek.
Classes, methods, and conditional statements We’re past the basics. These are the roots.
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.
CS102--Object Oriented Programming Lecture 6: – The Arrays class – Multi-dimensional arrays Copyright © 2008 Xiaoyan Li.
Week 8: Audio Processing 1.  Light and sound are both transmitted in waves 2.
© 2010 Pearson Education, Inc. Conceptual Physics 11 th Edition Chapter 21: MUSICAL SOUNDS Noise and Music Musical Sounds Pitch Sound Intensity and Loudness.
School of Informatics CG087 Time-based Multimedia Assets Sampling & SequencingDr Paul Vickers1 Sampling & Sequencing Combining MIDI and audio.
Week 7 - Wednesday.  What did we talk about last time?  Introduction to arrays  Lab 6.
Problem Solving with Data Structures using Java: A Multimedia Approach Chapter 5: Arrays: A Static Data Structure for Sounds.
 The pool rack example could be implemented using a for loop.  It is also possible to write recursive methods that accomplish things that you might.
2.1 Functions. f x y z f (x, y, z) 3 Functions (Static Methods) Java function. n Takes zero or more input arguments. n Returns one output value. Applications.
2.1 Functions Introduction to Programming in Java: An Interdisciplinary Approach · Robert Sedgewick and Kevin Wayne · Copyright © 2008 · October 21, 2015.
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.
CS177 RECITATION WEEK 7 Input and Output (Text & Graphical)
2.1 Functions Introduction to Programming in Java: An Interdisciplinary Approach · Robert Sedgewick and Kevin Wayne · Copyright © 2008 · 9/10/08 9/10/08.
1 CSC 201: Computer Programming I Lecture 2 B. S. Afolabi.
Copyright 2004 Ken Greenebaum Introduction to Interactive Sound Synthesis Lecture 18:Noise Ken Greenebaum.
CS 102 Computers In Context (Multimedia)‏ 03 / 30 / 2009 Instructor: Michael Eckmann.
Intro-Sound-part1 Introduction to Processing Digital Sounds part 1 Barb Ericson Georgia Institute of Technology Oct 2009.
CMSC 202 Arrays 2 nd Lecture. Aug 6, Array Parameters Both array indexed variables and entire arrays can be used as arguments to methods –An indexed.
Week 7 - Friday.  What did we talk about last time?  Array examples  Sound.
Introduction to array: why use arrays ?. Motivational example Problem: Write a program that reads in and stores away 5 double numbers After reading in.
Week 7 - Wednesday.  What did we talk about last time?  Introduction to arrays  Lab 6.
Week 10 - Friday.  What did we talk about last time?  References and primitive types  Started review.
int [] scores = new int [10];
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.
1 CS 177 Week 7 Recitation Slides Modifying Sounds using Loops + Discussion of some Exam Questions.
NXC: Making Music BricxCC has a built-in utility to convert .wav files into .rso files accessible via menu Tools, Sound conversion. Then you can store.
CS 112 Introduction to Programming Digital Audio; User-Defined Data Types (struct) Yang (Richard) Yang Computer Science Department Yale University 208A.
1 Section 5.4 Digital Sound Processing Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Section Vocabulary  Pitch- the highness or lowness of sound  Hertz- unit used to measure the frequency of a sound wave  Octave- A series of 8 notes.
CS 591 S1 – Computational Audio -- Spring, 2017
8th Grade Physical Science
CS 591 S1 – Computational Audio -- Spring, 2017
Bit-Depth Tonal-Range Sample-Rate Clarity Timbre Pitch
Arrays in Classes and Methods
Arrays 3/4 By Pius Nyaanga.
Week 7 - Friday CS 121.
Building Java Programs
CS 591 S1 – Computational Audio -- Spring, 2017
Foundations of Programming: Arrays
Week 7 - Wednesday CS 121.
Functions that Deal with Arrays CS 1111 Ryan Layer Feb 23, 2010
CS/COE 0449 (term 2174) Jarrett Billingsley
Processing Sound Ranges part 3
Lecture 28 Closing it Out.
Designing a Music Scripting Language Casey Mihaloew
CS 177 Week 15 Recitation Slides
CS 177 Week 4 Recitation Slides
How is Music Related to Math?
Processing Sound Ranges part 1
How sound works: Acoustics, the physics of sound
CS2011 Introduction to Programming I Arrays (II)
int [] scores = new int [10];
Sound Sound is a type of energy made by vibrations. When any object vibrates, it causes movement in the air particles. These particles bump into the particles.
Introduction to Processing Digital Sounds
Processing Sound Ranges
Processing Sound Ranges part 3
CS1315: Introduction to Media Computation
Arrays 3/4 June 3, 2019 ICS102: The course.
Chapter 6 Arrays.
Creating Sounds and MIDI
Presentation transcript:

Week 9 – Audio Processing CS 177 Recitation Week 9 – Audio Processing

Announcements Project 3 (final version) is due on Thursday (Oct 29) Any questions about the project?

Questions?

Sound Like light, sound is a wave We can’t record an (analog) wave directly on a (digital) computer, so we have to do sampling Sampling converts the analog wave into a digital approximation Break the wave down into a lot of samples (44,100 samples per second = 44,100 Hz) Each sample is a double value in the range [-1, 1] Each sample records the amplitude of the wave at a certain place In the computer, the sound wave is just an array of doubles

Sound Amplitude of the wave determines the sound’s volume Frequency of the wave determines how high or low the sound is is louder than low-pitched sound high-pitched sound

StdAudio Written by the book’s author, like StdIn and StdDraw As usual, remember to download the file and put it in the same directory if you want to use the StdAudio methods Allows you to manipulate sound as a single array of samples Allows you to read and write WAV files

StdAudio Methods

Simple Audio Example Reads a sound from file and plays it public class PlaySound { public static void main(String[] args){ System.out.print("Enter filename: "); String file = StdIn.readString(); double[] sound = StdAudio.read(file); StdAudio.play(sound); }

Slowing Down a Sound The example in lecture just doubled the length of the sound by using each sample twice Example: slow[0] = sound[0] slow[1] = sound[0] slow[2] = sound[1] slow[3] = sound[1] This works, but doesn’t sound so great Using each sample twice in a row makes the wave kind of blocky instead of

Slow.java To smooth the slowed sound, use the average of adjacent samples instead of copies public class Slow{ public static void main(String[] args){ double[] sound = StdAudio.read("world.wav"); double[] slow = new double[sound.length*2]; for( int i = 0; i < slow.length-1; i++ ) //slow[i] = sound[i/2]; //old way slow[i] = (sound[i/2] + sound[(i+1)/2]) / 2.0; //better way StdAudio.play(slow); }

Adding Noise We can add noise to a sound by adding or subtracting a small random number from each sample For simplicity, we’ll only add Remember, the samples can only be in the range -1 to 1 Whenever you’re changing the samples, be sure that they stay in that range!

AddNoise.java public class AddNoise { public static void main( String [] args ) { String file = “world.wav”; double samples [] = StdAudio.read(file); for ( int i = 0; i < samples.length; i++ ) { double noise = Math.random(); samples[i] += noise; if ( samples[i] > 1 ) samples[i] = 1; } StdAudio.play(samples);

Playing Two Sounds Together Add the samples at each position in the array First sound: .5 .2 -.1 1 … Second sound: .1 -.2 .3 -.6 .2 … Combined sound: .6 -.1 1.3 -.4 .4 … Don’t forget to check for samples that become >1 or <-1!

Playing Two Sounds Together If one sound is longer than the other: mix the two until the end of the shorter sound copy the rest of the longer sound unchanged onto the end of the mixed sound First sound: .5 .2 -.1 1 Second sound: .1 -.2 .3 -.6 .2 … Combined sound: .6 -.1 1.3 -.6 .2 … Mix of both sounds Copy of the longer sound’s data

public class PlayTwo { public static void main( String [] args ) { String file1 = ”world.wav"; String file2 = "breakbeato.wav"; double samples1 [] = StdAudio.read(file1); double samples2 [] = StdAudio.read(file2); int longer = samples1.length; int shorter = samples2.length; if ( samples2.length > longer ) { longer = samples2.length; shorter = samples1.length; } double mix [] = new double[longer]; for ( int i = 0; i < shorter; i++ ) { mix[i] = samples1[i] + samples2[i]; for ( int j = shorter; j < longer; j++ ) { if ( samples1.length > samples2.length ) mix[j] = samples1[j]; else mix[j] = samples2[j]; PlayTwo.java

Improving PlayThatTune.java The book’s PlayThatTune program works fine, but produces vaguely creepy robot music We want to make it a little less creepily robotic Add harmonic tones one octave above and below each note to produce a more realistic sound To run PlayThatTune (has to be done from the command line): java PlayThatTune < elise.txt

Improving PlayThatTune.java Originally the wave for a note looks like: With the harmonics, it looks like:

PlayThatTune2.java public class PlayThatTune2 { public static double[] sum(double[]a, double [] b, double awt, double bwt ) { double [] c = new double[a.length]; for ( int i = 0; i < a.length; i++) c[i] = a[i] * awt + b[i] * bwt; return c; } public static double[] tone(double hz, double t) { int SAMPLE_RATE = 44100; int N = (int) (SAMPLE_RATE * t); double[] a = new double[N+1]; for (int i = 0; i <= N; i++) { a[i] = Math.sin(2 * Math.PI * i * hz / SAMPLE_RATE); return a;

PlayThatTune2.java con. double hz = 440.0 * Math.pow( 2, p / 12.0); public static double[]note ( int p, double t) { double hz = 440.0 * Math.pow( 2, p / 12.0); double[] a = tone( hz, t); double[] hi = tone(2 * hz, t); double[]lo = tone(hz/2, t); double[] h = sum(hi, lo, .5, .5); return sum(a,h,.5,.5); } public static void main(String [] args) { while ( !StdIn.isEmpty()) { int pitch = StdIn.readInt(); double duration = StdIn.readDouble(); double[]a = note(pitch, duration); StdAudio.play(a);