Slides

What is Sound?
1
Changes in air pressure detected by our ears
Figure from http://www.mediacollege.com/audio/01/sound-waves.html
Wave Terminology
2
Figure from Guzdial and Ericson, Introduction to Computing and Programming in Python,
3rd edition, page 146
3
Sound Waves
Amplitude determines
volume
Frequency determines
pitch
Figure from http://physics.tutorvista.com/waves/amplitude-of-a-wave.html
Slides18-SoundIntro.key - November 24, 2015
Frequency
440 Hertz
A above middle C
4
261.6 Hertz
Middle C
Frequency is the number of cycles per second
1 Hertz = 1 cycle per second
Human hearing range is 2 - 20,000 Hertz
A above middle C is 440 Hertz.
Double the Hertz to go up 1 octave, so the next A is at
880 Hertz.
Review: Digitizing Images
Pixels: Sample a scene by
recording colors at distinct
points
5
RGB: Encode a visual
color in numbers
6
Digitizing Sound
Need a sampling technique (like pixels are for
images)
Need to convert sound samples to numbers (like
RGB does for colors)
Slides18-SoundIntro.key - November 24, 2015
Encoding Sound Digitally
7
Need to turn sound into numbers,
like we turned color into numbers
Technique: sampling - record the
air pressure at fixed intervals of
time
Curve in the diagram
is the sound wave.
The dots on the
curve are sampled
values.
Frequent sampling
gives a good
approximation of the
original curve.
Sampling and Sound Quality
8
More frequent
sampling ->
better
approximation of
original sound
wave
Figure from http://www.karbosguide.com/books/videosound/chapter05.htm
Sampling and Sound Quality
9
Human voice <
4000 Hertz
Phone quality =
8000 Hertz
CD quality =
44,100 Hertz
Figure from http://www.karbosguide.com/books/videosound/chapter05.htm
Slides18-SoundIntro.key - November 24, 2015
Playing Sound with Python
10
makeSound ( <filename> ) - returns a Sound object
explore ( <sound> ) - opens a window showing the sound
wave
blockingPlay ( <sound> ) - plays the sound
def playAah () :
aah = makeSound ("/Users/blerner/Documents/cs100/mediasources/aah.wav")
explore(aah)
blockingPlay (aah)
11
Manipulating Sound
getSamples ( <sound> ) - returns an array of
the samples in a sound
getSampleValue ( <sample> ) - returns the value
of the sample (a 16-bit number)
setSampleValue ( <sample> , <integer> ) changes the value of a sample
The value of the sample is the y-value. How can we use
these functions to increase the volume of a sound?
Amplifying Sound
12
Increasing the amplitude can result in distorted
sound.
Original:
Amplitude * 10
Or is it?
Slides18-SoundIntro.key - November 24, 2015
Normalizing Sound
13
Goal: Scale the sound so the largest amplitude is full
amplitude.
Amplitude value is 16 bits
1 bit is used to remember if the number is positive or
negative, 15 bits left for the value
215 = 32,768
How do we scale the sound so that the maximum amplitude
is 32,768?
Original
Normalized
14
Summary
Sound is digitized by sampling
Need 44,100 samples / second to get CD quality
recordings
Analogous Image / Sound Functions
Images
Sound
makePicture (<filename>)
makeSound (<filename>)
explore (<picture>)
explore (<sound>)
show (<picture>)
blockingPlay (<sound>)
getPixels (<picture>)
getSamples (<sound>)
getRed (<pixel>)
getSampleValue (<sample>)
setRed (<pixel>, <integer>)
setSampleValue (<sample>,
<integer>)
15
Slides18-SoundIntro.key - November 24, 2015