CSCI 1101A Sound Ch. 6, 7, 8 [MultimediaGuzdial] Mohammad T . - - PDF document

csci 1101a
SMART_READER_LITE
LIVE PREVIEW

CSCI 1101A Sound Ch. 6, 7, 8 [MultimediaGuzdial] Mohammad T . - - PDF document

3/25/15 CSCI 1101A Sound Ch. 6, 7, 8 [MultimediaGuzdial] 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


slide-1
SLIDE 1

3/25/15 ¡ 1 ¡

CSCI 1101A

Sound

  • Ch. 6, 7, 8

[Multimedia—Guzdial] Mohammad T . Irfan

Physics of sound à computation

slide-2
SLIDE 2

3/25/15 ¡ 2 ¡

Physics of sound

u Sound: waves of air

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

Compression Rarefaction

Volume ¡

u How loud is a sound?

u Related to amplitude (logarithmically) u Difference in volumes of two sounds, with

amplitudes A1 and A2, is measured in decibels (dB)

u Difference in volumes = 20 log10(A1/A2) dB

u If the amplitude doubles (A1 = 2*A2), volume

difference is 6 dB

slide-3
SLIDE 3

3/25/15 ¡ 3 ¡

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

slide-4
SLIDE 4

3/25/15 ¡ 4 ¡

  • 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

slide-5
SLIDE 5

3/25/15 ¡ 5 ¡

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 216 = 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è 215 = 32,768 u Range of 16-bit numbers: –32,768 to +32,767

slide-6
SLIDE 6

3/25/15 ¡ 6 ¡

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

slide-7
SLIDE 7

3/25/15 ¡ 7 ¡

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

slide-8
SLIDE 8

3/25/15 ¡ 8 ¡

Basic sound functions (vs. picture functions)

u makeSound(f) u getSamples(sndObj) u getSampleObjectAt(sndObj, idx) u getLength(sObject) u getSampleValue(sample) u getSampleValueAt(sndObj, idx) u setSampleValue(sample, val) u setSampleValueAt(sndObj, idx,

val)

u makePicture(f) u getPixels(picObject) u getPixel(picObject, x, y) u getWidth(picObject), getHeight(…) u getColor(px) u (no direct function) u setColor(px, color) u (no direct function)

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)

slide-9
SLIDE 9

3/25/15 ¡ 9 ¡

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

  • ccurred

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

slide-10
SLIDE 10

3/25/15 ¡ 10 ¡

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?

slide-11
SLIDE 11

3/25/15 ¡ 11 ¡

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

slide-12
SLIDE 12

3/25/15 ¡ 12 ¡

Code: Step 1

More general!

Code: Step 2

slide-13
SLIDE 13

3/25/15 ¡ 13 ¡

Useful function: clip

u Make a new sound object with only part of a

give sound object

Code

slide-14
SLIDE 14

3/25/15 ¡ 14 ¡

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

slide-15
SLIDE 15

3/25/15 ¡ 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

slide-16
SLIDE 16

3/25/15 ¡ 16 ¡

Code

  • Misc. Topics (Ch 8)

u Blending sounds (Section 8.2) u Playing MIDI (Section 8.6)

u playNote(noteFrequency, duration [, intensity])