OCR Computer Science J277 - Mr Brown
A microphone captures sound as a continuous analogue wave. To store it on a computer, the wave must be sampled โ measured at regular time intervals โ and each measurement stored as a binary number. Explore how sample rate and bit depth affect the quality of the digital recording (and its file size) below!
Drag the slider to change the sample rate, and pick a bit depth to see the effect on quality.
Sample rate: 20 Hz
Click a sample dot (orange) to see its binary code.
Every sample's height (amplitude) is stored as one of these binary codes:
This slider sets the length of the (hypothetical) full recording, used to calculate its file size:
Duration: 3 seconds
Sound file size = sample rate ร bit depth ร duration = 20 Hz ร 2-bit ร 3s = 120 bits
This is uncompressed โ the file size doesn't depend on what the sound actually is, only on these three settings!
| Metadata | Value |
|---|---|
| Sample rate | 20 Hz |
| Bit depth | 2-bit |
| Duration | 3 s |
| File size | 120 bits |
| Date created |
Sound travels as a continuous analogue wave. A microphone converts this into a continuous electrical signal. Because computers can only store and process binary data, this signal must be sampled โ measured at regular time intervals โ and each measurement (the amplitude, or "height", of the wave at that instant) is stored as a binary number.
Sample rate is the number of samples taken per second, measured in Hertz (Hz). A higher sample rate captures the shape of the original wave more accurately, giving higher playback quality โ but produces a bigger file.
| Sample rate | Typical use |
|---|---|
| 8,000 Hz | Telephone-quality speech |
| 44,100 Hz | CD-quality audio |
| 96,000 Hz | Professional studio recording |
Bit depth is the number of bits used to store each sample's amplitude value. With n bits, each sample can be one of 2โฟ possible amplitude levels.
| Bit depth | Levels possible |
|---|---|
| 1-bit | 2 |
| 4-bit | 16 |
| 8-bit | 256 |
| 16-bit | 65,536 (CD quality) |
Higher bit depth means the volume of each sample is measured more precisely, giving smoother, more accurate sound โ but a bigger file. Try it in the Playground and see the difference!
Duration is simply how many seconds of audio the file contains. A longer recording contains more samples, so it produces a bigger file โ but duration has no effect on the quality of the sound itself.
Sound file size = sample rate (Hz) ร bit depth (bits) ร duration (seconds)
This gives the size in bits โ divide by 8 for bytes, and by a further 1000 for KB.
Example: a 10 second recording at 44,100 Hz with a 16-bit depth:
44,100 ร 16 ร 10 = 7,056,000 bits = 882,000 bytes โ 882 KB
Metadata is extra information stored with a sound file, separate from the sample data itself โ for example its sample rate, bit depth, duration and the date it was created. It's what lets software play the recording back correctly.