Sampling sound, calculating sound file sizes, lossy and lossless compression, run length encoding and Huffman coding.
What you will learn
- Calculate sound file size from sample rate, bit depth and length
- Choose lossy or lossless compression
- Encode and decode run length encoding
- Use a Huffman code table
Sampling sound
Sound is an analogue wave.
To store it, the computer measures its height many times a second; each measurement is a sample.
- Sample rate: samples per second, in hertz (44 100 Hz for CD audio).
- Bit depth: bits per sample. More bits record each height more precisely.
- A higher sample rate or bit depth sounds closer to the original but makes a bigger file.
file size in bits = sample rate × bit depth × length in seconds
(Multiply by 2 for stereo.) For example, 10 seconds at 20 000 Hz and 16 bits: 20 000 × 16 × 10 = 3 200 000 bits = 400 000 bytes = 400 kB.
Working backwards, length in seconds = bits ÷ (sample rate × bit depth): a 400 000 byte file is 3 200 000 bits, and 3 200 000 ÷ (20 000 × 16) = 10 seconds.
The sample interval is the time between samples: 1 ÷ sample rate. At 50 000 Hz it is 1 ÷ 50 000 s = 20 microseconds.
The rest of this lesson and its 8 practice questions are locked.
In this lesson
- Sampling sound
- Compression
- Try it: A sound file
8 practice questions, marked as you go; about 25 minutes in all.
Key terms
Sample, Sample interval, Lossy, Lossless, Run length encoding, Huffman coding, Run
In this unit: Data representation
Binary, denary and hexadecimal, binary addition and shifts, two's complement, and how characters, images and sound are stored and compressed.