3/25/15 ¡ 1 ¡
CSCI 1101A
Sound
- Ch. 6, 7, 8
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
3/25/15 ¡ 1 ¡
3/25/15 ¡ 2 ¡
u Sound: waves of air
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
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
3/25/15 ¡ 3 ¡
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
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/25/15 ¡ 4 ¡
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
3/25/15 ¡ 5 ¡
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
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
3/25/15 ¡ 6 ¡
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
3/25/15 ¡ 7 ¡
u Each rectangle is a sample and has a sample
value between -32767 and +32768
u Sampling rate: # of rectangles/sec.
u Samples are stored one after another
consecutively in a list
Sample with sample value 39
3/25/15 ¡ 8 ¡
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)
>>> 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)
3/25/15 ¡ 9 ¡
>>> 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
Please check line 0 of >>> print getSampleValueAt(sound,1) 36 >>> setSampleValueAt(sound,1,12) >>> print getSampleValueAt(sound,1) 12
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
3/25/15 ¡ 10 ¡
u Different operations on different parts of
sound
u Can we use indexing to access specific
samples?
3/25/15 ¡ 11 ¡
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
3/25/15 ¡ 12 ¡
More general!
3/25/15 ¡ 13 ¡
u Make a new sound object with only part of a
give sound object
3/25/15 ¡ 14 ¡
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
3/25/15 ¡ 15 ¡
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
3/25/15 ¡ 16 ¡
u Blending sounds (Section 8.2) u Playing MIDI (Section 8.6)
u playNote(noteFrequency, duration [, intensity])