Sound, pictures and video as numbers
Sound is a wave. To store it, a computer samples the wave: it measures the height at regular times. Each measure is rounded to a whole number (quantization) and written as bits (encoding). More samples per second and more bits per sample copy the sound more closely, but the file is bigger. The size is: samples per second × bits per sample × seconds × channels, in bits; divide by 8 for bytes. In this lesson 1 KB = 1,000 bytes and 1 MB = 1,000,000 bytes. For 8,000 samples per second, 8 bits, 10 seconds, one channel: 8,000 × 8 × 10 = 640,000 bits = 80,000 bytes = 80 KB. A picture is a grid of pixels. The resolution is the number of pixels wide × the number high. The colour depth is the number of bits per pixel: 1 bit gives 2 colours, 8 bits give 256, and 24 bits give 16,777,216 (about 16.7 million). On a screen, red, green and blue light add up to white; in printing, cyan, magenta and yellow inks subtract light. Size in bytes = pixels × bits per pixel ÷ 8. A 100 × 50 picture with 8 bits is 5,000 × 8 ÷ 8 = 5,000 bytes = 5 KB. Raster pictures are pixels and blur when enlarged; vector pictures are shapes described by formulas and stay sharp. A video is many pictures, called frames, shown quickly: its size is one image × frames per second × seconds, which is huge, so we compress. Lossless compression can restore the file exactly; lossy compression drops details people hardly notice, and cannot be undone.
Work out on paper, stating the unit rule (1 KB = 1,000 bytes): the size of a 5-second recording with 4,000 samples per second, 8 bits and one channel. Then the size of a 40 × 25 picture with 8 bits per pixel.