3/25/15 ¡ CSCI 1101A Sound Ch. 6, 7, 8 [Multimedia—Guzdial] Mohammad T . Irfan Physics of sound à computation 1 ¡
3/25/15 ¡ Physics of sound u Sound: waves of air Compression Rarefaction pressure u Waves come in cycles u The frequency of a wave is the number of cycles per second (cps) or Hertz u Complex sounds have more than one frequencies. u The amplitude is the maximum height of the wave Volume ¡ u How loud is a sound? u Related to amplitude (logarithmically) u Difference in volumes of two sounds, with amplitudes A 1 and A 2 , is measured in decibels (dB) u Difference in volumes = 20 log 10 (A 1 /A 2 ) dB u If the amplitude doubles (A 1 = 2*A 2 ), volume difference is 6 dB 2 ¡
3/25/15 ¡ Pitch u What sounds are audible? u Human hearing range: 20 Hz to 22,000 Hz (22 kHz) u Pitch u Our perception of pitch is related (logarithmically) to changes in frequency– e.g., piano keys u Higher frequencies are perceived as higher pitches u A above middle C is 440 Hz Storing sound in a computer u Analog vs. digital u Technique u Divide the wave into MANY segments and store information about each segment u Analog-to-digital conversion (ADC) is used for this 3 ¡
3/25/15 ¡ 1. Each rectangle is a sample. 2. Height of a rectangle: Its sample value. Questions u Q1: How many samples do we need? u Nyquist-Shannon Theorem u Q2: What should be the max sample value? u Depends on memory space allocation for storing sound 4 ¡
3/25/15 ¡ Nyquist-Shannon Theorem u Need twice as many samples/sec as the maximum frequency in order to represent (and recreate later) the original sound. u The number of samples recorded per second is the sampling rate u If we capture 8000 samples per second, the highest frequency we can capture is 4000 Hz u That ʼ‚ s how phones work u If we capture more than 44,000 samples per second, we capture everything that we can hear (max 22,000 Hz) u CD quality is 44,100 samples per second Digitizing sound in the computer u Each sample is stored as a number u What’s the maximum number? u Equivalently, how many bits are allocated per number? u Let’s work with 16 bits u What ʼ‚ s the range of available patterns? u 2 16 = 65,536 u But we want both positive and negative values u To represent compressions and rarefactions u Two’s complement system u Use the leftmost bit to indicate positive or negative number. This bit is called sign bit u Sign bit = 0 è non-negative number, 1 è negative number u That leaves us with 15 bits u 15 bits è 2 15 = 32,768 u Range of 16-bit numbers: –32,768 to +32,767 5 ¡
3/25/15 ¡ More on binary numbers & two’s complement system 1. Deciphering (+ve) binary numbers Getting the decimal equivalent of a +ve binary number • 2. Converting (+ve) decimal to binary 3. Two’s complement system Positive & • Negative binary numbers • Exam 3 (30 minutes) u Next Wednesday (a week from today) u Topics u Images u Ch 5 (Sections 5.1, 5.2, 5.3, 5.6) u Edge detection lab (including drawing lines, rectangle, etc.) u Exercise problems on drawing: 5.16, 5.18, 5.25 u Sound u Ch 6 and 7 (partial, up to Monday’s class) u Exercise problems: 6.7, 6.9, 6.12 (We’ll do 6.12 in class) u 1 point: Printout of practice problems u 1 point: Two’s complement system u 8 points: problems on images and sound 6 ¡
3/25/15 ¡ Summary u Each rectangle is a sample and has a sample value between -32767 and +32768 u Sampling rate: # of rectangles/sec. Sound ¡stored ¡in ¡a ¡list ¡ u Samples are stored one after another consecutively in a list Sample with sample value 39 7 ¡
3/25/15 ¡ Basic sound functions (vs. picture functions) u makeSound(f) u makePicture(f) u getSamples(sndObj) u getPixels(picObject) u getSampleObjectAt(sndObj, idx) u getPixel(picObject, x, y) u getLength(sObject) u getWidth(picObject), getHeight(…) u getSampleValue(sample) u getColor(px) u getSampleValueAt(sndObj, idx) u (no direct function) u setSampleValue(sample, val) u setColor(px, color) u setSampleValueAt(sndObj, idx, u (no direct function) val) Demo of sound using JES >>> filename=pickAFile() >>> sound=makeSound(filename) >>> print sound Sound of length 421109 >>> samples=getSamples(sound) >>> print samples Samples, length 421109 >>> print getSampleValueAt(sound,1) 36 >>> print getSampleValueAt(sound,2) 29 >>> explore(sound) 8 ¡
3/25/15 ¡ Demo (continued) >>> print getLength(sound) 220568 >>> print getSamplingRate(sound) 22050.0 >>> print getSampleValueAt(sound,220568) 68 >>> print getSampleValueAt(sound,220570) I wasn't able to do what you wanted. The error java.lang.ArrayIndexOutOfBoundsException has occurred Please check line 0 of >>> print getSampleValueAt(sound,1) 36 >>> setSampleValueAt(sound,1,12) >>> print getSampleValueAt(sound,1) 12 Problem: Increase volume u volume => height of wave => sample values u Make the volume 5 times the original volume => u Make each sample value 5 times the original 9 ¡
3/25/15 ¡ Code Problem: Make the first quarter louder, the rest quieter u Different operations on different parts of sound u Can we use indexing to access specific samples? 10 ¡
3/25/15 ¡ Code Problem: Normalize sound u Want max sample value to be (+/-)32767 u Other sample values to be changed accordingly u Algorithm u Step 1: Find max abs(sample value) u Step 2: Multiply each sample value by 32767.0/ max 11 ¡
3/25/15 ¡ Code: Step 1 More general! Code: Step 2 12 ¡
3/25/15 ¡ Useful function: clip u Make a new sound object with only part of a give sound object Code 13 ¡
3/25/15 ¡ Useful function: copy u Copy source sound to target sound beginning at a desired target index u Target sound object must be big enough to hold the source Code 14 ¡
3/25/15 ¡ Problem: Insert another sound into a given sound object (splicing) u Have (preamble10.wav): “We the people of the United States” u Want: “We the united people of the United States” u Algorithm u Clip “united” and save it as a new sound object u Make a big enough target sound object u Copy “We the” to target u Copy “united” to target u Copy “people of the United States” to target preamble10.wav preamble10.wav 15 ¡
3/25/15 ¡ Code Misc. Topics (Ch 8) u Blending sounds (Section 8.2) u Playing MIDI (Section 8.6) u playNote(noteFrequency, duration [, intensity]) 16 ¡
Recommend
More recommend