1 1 Aaron Stevens 11, 13 April 2011 CS101 Lecture 28: Python: Computing with Audio Some material copyright Pearson (Guzdial and Ericson) 2 Overview/Questions – Review: audio samples, sampling rate – How can we create/play WAV audio files? – Programming with sound in Python
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
1
1
Aaron Stevens11, 13 April 2011
CS101 Lecture 28:Python: Computing with Audio
Some material copyright Pearson (Guzdial and Ericson)
2
Overview/Questions
– Review: audio samples, sampling rate– How can we create/play WAV audio files?– Programming with sound in Python
2
33
Review: Sound Wave Properties
Wavelength:distance between waves (affectspitch -- high or low sounds)
Amplitude:strength of power of waves (volume)
Frequency:the number of times a wave occursin a second.
4
Thinking in waveforms
– What kind of waveform would a high pitched/lowpitched sound look like?
– What kind of waveform would silence look like?
– How would we combine sounds, e.g. similar to animage overlay?
3
55
Sampling: 3-bit depth
For each sample, we need to select a discrete value for the amplitude.These values are recorded in 3 bits (right hand side).
66
From Sample to Sound Wave
Using the recorded information, the computer must re-recreate thesound wave. Some of the original information was lost by thesampling process!
4
7
Waveform Audio File Format(.WAV Files)These files store a bitstream of the audio
samples:• compatible with Window, MAC, Linux• typically uncompressed
– What are the benefits of an uncompressedformat?
– What are the drawbacks?
8
Recording a .WAV file.Example: using Audacity to record a .WAVfile.
Recall: a speaker has an electromagnet,just like a microphone…
5
9
Reading a WAV File
JES built-in function:
Example:
10
JES Sound Explorer
explore(sound) -- bring up sound explorer
6
11
How Sampling Works:
The sampling rate describes howmany samples per unit of time.For example, 1000 samples persecond.• Each sample has a timestamp and a
value• The value describes the amplitude of the
sound wave at one point in time
12
Programming with Audio
Reading and playing a WAV FileGet/set individual samplesCreate an empty sound fileSaving a WAV file