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.

Slides:



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

Control Structures Any mechanism that departs from straight-line execution: –Selection: if-statements –Multiway-selection: case statements –Unbounded iteration:
Intro-Sound-part31 Introduction to Processing Digital Sounds part 3 Barb Ericson Georgia Institute of Technology Oct 2009.
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 6 Functions.
Standing Waves Physics 202 Professor Vogel (Professor Carkner’s notes, ed) Lecture 5.
CS 106 Introduction to Computer Science I 02 / 12 / 2007 Instructor: Michael Eckmann.
School of Computing Science CMT1000 © Ed Currie Middlesex University Lecture 10: 1 TEST!!
Introduction to Computers and Programming Lecture 5 Boolean type; if statement Professor: Evan Korth New York University.
1 Lecture 7:Control Structures I (Selection) Introduction to Computer Science Spring 2006.
Chapter 6: User-Defined Functions I
Slides prepared by Rose Williams, Binghamton University Chapter 6 Arrays.
CS241 PASCAL I - Control Structures1 PASCAL I - Control Structures Philip Fees CS241.
Sorting and Searching Arrays CSC 1401: Introduction to Programming with Java Week 12 – Lectures 1 & 2 Wanda M. Kunkle.
C++ Functions. 2 Agenda What is a function? What is a function? Types of C++ functions: Types of C++ functions: Standard functions Standard functions.
JS Arrays, Functions, Events Week 5 INFM 603. Agenda Arrays Functions Event-Driven Programming.
Problem Solving with Data Structures using Java: A Multimedia Approach Chapter 5: Arrays: A Static Data Structure for Sounds.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Recursion Review.
Basics of Digital Audio Outline  Introduction  Digitization of Sound  MIDI: Musical Instrument Digital Interface.
Chapter 11Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 11 l Basics of Recursion l Programming with Recursion Recursion.
COSC 1P02 Introduction to Computer Science 3.1 Cosc 1P02 Week 3 Lecture slides Birthdays are good for you. Statistics show that the people who have the.
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.
1 Programming with Recursion. 2 Recursive Function Call A recursive call is a function call in which the called function is the same as the one making.
Lecturer: Dr. AJ Bieszczad Chapter 11 COMP 150: Introduction to Object-Oriented Programming 11-1 l Basics of Recursion l Programming with Recursion Recursion.
Chapter 6: Functions Starting Out with C++ Early Objects
CPS120: Introduction to Computer Science Decision Making in Programs.
Georgia Institute of Technology Processing Sound Ranges Barb Ericson Georgia Institute of Technology July 2005.
CPS120: Introduction to Computer Science Functions.
USER-DEFINED FUNCTIONS. STANDARD (PREDEFINED) FUNCTIONS  In college algebra a function is defined as a rule or correspondence between values called the.
CPS120: Introduction to Computer Science Lecture 14 Functions.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
CSC 107 – Programming For Science. Today’s Goal  Discuss writing functions that return values  return statement’s meaning and how it works  When and.
1 CS161 Introduction to Computer Science Topic #9.
AP Computer Science edition Review 1 ArrayListsWhile loopsString MethodsMethodsErrors
Encoding and Simple Manipulation
CPSC1301 Computer Science 1 Chapter 8 Introduction to Processing Digital Sounds part 3.
Python 101 Dr. Bernard Chen University of Central Arkansas PyArkansas.
Starting Out with C++ Early Objects ~~ 7 th Edition by Tony Gaddis, Judy Walters, Godfrey Muganda Modified for CMPS 1044 Midwestern State University 6-1.
Chapter 11Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 11 l Basics of Recursion l Programming with Recursion Recursion.
CS241 PASCAL I - Control Structures1 PASCAL Control Structures Modified Slides of Philip Fees.
CSE 110 Review Session Hans Hovanitz, Kate Kincade, and Ian Nall.
Copyright © 2000, Department of Systems and Computer Engineering, Carleton University 1 Introduction An array is a collection of identical boxes.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
CS 46B: Introduction to Data Structures June 30 Class Meeting Department of Computer Science San Jose State University Summer 2015 Instructor: Ron Mak.
Searching CSE 103 Lecture 20 Wednesday, October 16, 2002 prepared by Doug Hogan.
CS 115 OBJECT ORIENTED PROGRAMMING I LECTURE 12 GEORGE KOUTSOGIANNAKIS 1 Copyright: 2015 Illinois Institute of Technology_ George Koutsogiannakis.
Lecture 4 – Function (Part 1) FTMK, UTeM – Sem /2014.
Midterm Review Tami Meredith. Primitive Data Types byte, short, int, long Values without a decimal point,..., -1, 0, 1, 2,... float, double Values with.
Intro-Sound-Mod10-part31 Introduction to Processing Digital Sounds part 3 while loop, tracing, for loop, parameters Barb Ericson Georgia Institute of Technology.
COP 2220 Computer Science I Topics –Breaking Problems Down –Functions –User-defined Functions –Calling Functions –Variable Scope Lecture 4.
1 CS 177 Week 7 Recitation Slides Modifying Sounds using Loops + Discussion of some Exam Questions.
Functions and Program Structure Chapter 4. Introduction Functions break large computing tasks into smaller ones Appropriate functions hide details of.
CONDITIONALS CITS1001. Scope of this lecture if statements switch statements Source ppts: Objects First with Java - A Practical Introduction using BlueJ,
Information and Computer Sciences University of Hawaii, Manoa
Chapter 9: Value-Returning Functions
User-Written Functions
Arrays 2/4 By Pius Nyaanga.
Georgia Institute of Technology
Programmazione I a.a. 2017/2018.
CHAPTER FOUR Functions.
Arrays, For loop While loop Do while loop
Winter 2018 CISC101 12/2/2018 CISC101 Reminders
Introduction to Computer Programming
Introduction to Processing Digital Sounds
Processing Sound Ranges
Based on slides created by Bjarne Stroustrup & Tony Gaddis
Introduction to Programming
CS1315: Introduction to Media Computation
Arrays Introduction to Arrays Reading for this Lecture:
Corresponds with Chapter 5
Creating Sounds and MIDI
Presentation transcript:

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 pay my bill is certainly not a failure."

COSC 1P02 Introduction to Computer Science 5.2 Generating Clipping  Clipping occurs when the sample value exceeds the maximum sample size (e.g. greater than 32,767 or less than -32,768 for a 2 byte sample).  sample value when clipped will be the maximum value (32,767 or -32,768)  If keep increasing volume, clipping occurs  What happens if all samples clipped?  Example  program to set all samples to maximum value  What does signal look like?  Note: we can still understand it!  if statement  choice between executing two alternatives  to handle maximum positive and maximum negative

COSC 1P02 Introduction to Computer Science 5.3 If Statement  Syntax  If condition is true, the first set of statements (then part) is executed, otherwise the second set of statements (else part) is executed  Condition  an expression that is either true or false  relational operators  note: also used in for statement (second part)

COSC 1P02 Introduction to Computer Science 5.6 Normalizing a Sound  What if we want to make a sound as loud as we can without causing clipping?  Need to know the largest (absolute value) amplitude (sample)  Can scale each sample by the ratio of this largest value to the maximum sample size ( 32,767 )  Finding maximum  sequence through all samples and if find one that is bigger than the biggest so far, change our guess of what the biggest value is  work with absolute value (i.e. don’t care if positive or negative)  need a starting guess  since looking at absolute value, no sample can be smaller than 0 so 0 can be starting guess  Example  Note: need two loops  one to find maximum  one to scale samples

COSC 1P02 Introduction to Computer Science 5.8 Mirroring A Sound  Mirror around mid-point  odd vs even number of samples  Copying sample values  only half copied  can’t use for-each  Indexing a collection  aSound.getSample(i)  returns Sample at position (index) i in sound  positions start at 0 (last position numSamples-1 )  Example  mid point  uses counting for  from position & to position  for each vs for & indexing

COSC 1P02 Introduction to Computer Science 5.9 Reversing a Sound  Produce a new sound which is the old sound in reverse order  like mirror except all samples reproduced in reverse order  create a new Sound object  Example  Sound objects now declared in method  more than one sound involved  must be passed as parameter (scope)  Creating a new sound with same attributes  Sound constructor  Cascading method calls  aSound.getSample(i) returns a Sample object  this object can perform the getValue() method  saves declaring a variable that isn’t going to be used except to make next call

COSC 1P02 Introduction to Computer Science 5.10 Function Methods  Methods can produce a result  value (e.g. sin() )  object (e.g. getSample() )  Method declaration  void – procedure method  no result  executed for its effect  type – function method  result is of specified type  executed for result  Method call  procedure method  called as a statement (e.g. close() )  function method  called as an expression (e.g. sin() )

COSC 1P02 Introduction to Computer Science 5.11  Method execution  value of argument computed  calling code suspended  value of argument copied to parameter  body of method executed  functions : return “value” computed  calling code continues ( functions : with return “value”)  Return statement  syntax  execution  expression computed  method terminates (returns)

COSC 1P02 Introduction to Computer Science 5.12 Changing the Frequency of a Sound  Change pitch by changing frequency  e.g. A above middle C is 440Hz, next A is 880Hz  To double frequency must halve cycle length  if sampling rate is constant, there will be half as many samples in the higher frequency version of the same sound  Select every other sample to create a new sound  same rough shape but compressed (higher frequency)  new sound will be half as long (half as many samples)  Example  new sound has half the samples  need a value for each sample in result (for-each)  every other sample of old sound  pos has values: 0, 2, 4, …

COSC 1P02 Introduction to Computer Science 5.13

COSC 1P02 Introduction to Computer Science 5.14 Combining Sounds  When two sounds occur together, their sound waves merge  e.g. instruments in an orchestra  merging is just addition of the samples at the same point in time  What if one sound is longer than the other  merging occurs over duration of shorter sound  result has tail end of longer sound  Example  determine longer & shorter sound  result has length of longer sound  merge as many samples as in shorter sound  to maintain volume, use half the amplitude of each sample  copy tail of longer sound  Note: for loop index doesn’t have to start at 0 or 1

COSC 1P02 Introduction to Computer Science 5.15 SoundPlayer Methods

COSC 1P02 Introduction to Computer Science 5.16 Sound Methods

COSC 1P02 Introduction to Computer Science 5.17 Sample Methods

COSC 1P02 Introduction to Computer Science 5.18 The end