CS101 Lecture 18: Audio Encoding Sampling Quantizing Aaron Stevens (azs@bu.edu) with special guest Wayne Snyder (snyder@bu.edu) 16 October 2012 What You ll Learn Today How do we hear sounds? How can audio information (sounds) be stored on a computer? How to reproduce the sounds from the binary data? 2 1
Hearing We hear sound when a series of air compressions vibrate a membrane in our ear. The inner ear sends signals to our brain. The rate of this vibration is measured in Hertz, and the human ear can hear sounds in the range of roughly 20Hz - 20KHz. 3 Sound Wave Properties Wavelength: distance between waves (affects pitch -- high or low sounds) Amplitude: strength of power of waves (volume) Frequency: the number of times a wave occurs in a second measured in Hertz. 4 2
Music Concepts Pitch is the human perception of sounds as musical notes Microphones and Speakers Microphones convert acoustical energy (sound waves) into electrical energy (the audio signal). Speakers do the same thing in reverse: convert electrical energy into acoustical energy. 6 3
Audio Playback A stereo sends an electrical signal to a speaker to produce sound. This signal is an analog representation of the sound wave. The voltage in the signal varies in direct proportion to the sound wave. 7 Important Note about Electronic Signals An analog signal continually fluctuates in voltage up and down. A digital signal has only a high or low state, which we model as binary digits. 8 4
Recall: Digitizing an Image Sampling: Taking measurements (of color) at discrete locations within the image. Sampling rate: 16 samples per inch (in each direction) Recall: Digitizing an Image Sampling: Measure the color for each pixel, and record that color. 16 pixels per inch Quantization: determine a discrete value for each pixel. 5
Digitizing Audio Information How can we store this continuous information in a finite machine? Digitize the signal by sampling: periodically measure the voltage record the numeric value 11 Sampling Audio Information Sampling: periodically measure the voltage and record the numeric value. Some data is lost, but a reasonable sound is reproduced. 12 6
From Sound Wave to Sample In this case, we are measuring the amplitude of the sound wave with 3 bits of precision (8 possible values, Y axis), at a sampling rate determined along the X axis. We record the values for each sample. 13 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). 14 7
10/12/12 From Sample to Sound Wave Using the recorded information, the computer must re-recreate the sound wave. Some of the original information was lost by the sampling process! 15 Increasing Quality To increate the quality of the recording, we can change 2 dimensions (independently): 1 - increase the sample rate (more points of measurement on X/time axis) 16 2 - increase the bit depth (more discrete levels of measurement on Y/amplitude axis). 8
How Good is Good Enough? How would you determine the required: Sampling rate Bit depth (quantization of sound wave) to recreate the best sensory audio experience? Choosing a Sampling Rate Consider this waveform. What sampling rate should we choose? 9
Choosing a Sampling Rate How about this sampling rate? (6 samples) Choosing a Sampling Rate How about this sampling rate? (11 samples) 10
Choosing a Sampling Rate How about this sampling rate? (21 samples) Choosing a Sampling Rate Consider this waveform, and these two sampling strategies. What s going on here? A. B. 11
Nyquist Theorem The Nyquist Theorem states that the sampling rate must be greater than twice the value of the highest frequency component of the analog signal. Consider this waveform and sampling rate: 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 uncompressed format? What are the drawbacks? 12
Recording a.wav file. Example: using Audacity to record a.wav file. Recall: a speaker has an electromagnet, just like a microphone Representing Audio Information Compact Disc audio is encoded by sampling: 44,100 samples per second 16 bits per sample per channel (2 channels) thus: 44,100 * 16 * 2 = 1,411,200 bps Or about 10,600,000 bytes per minute CD Audio uses about 10 megabytes of data per minute of audio. 26 13
What You Learned Today Hearing Sound waves Sampling, Sampling Rates Quantizing, Bit Depth Data storage requirements 27 Announcements and To Do Readings: Wong ch 4, pp 102-117 (this week) YouTube: History of Sony music technology http://www.youtube.com/watch?v=v5i41pdak0y (6 minutes) Homework 6 due Tuesday 10/16 28 14