Lessons 24 · 1 lessons · N. I. Taylaqov (general editor), A. B. Akhmedov, M. D. Pardayeva, A. A. Abdug‘aniyev, U. M. Mirsanov. Informatics and Information Technologies, Grade 11, 1st edition. “Extremum-press”, Tashkent, 2018
24
Sound data and working with it
Textbook: pp. 85–87
GoalExplains digital sound (sampling rate, bit depth, channel), calculates sound size, tells audio and video formats apart and correctly places the <audio> and <video> elements on a web page.
New words
sampling rate: how many times per second the sound level is measured, in hertz (Hz) · diskretlash chastotasibit depth: the number of bits used to store one measurement of the sound · razryad (bit chuqurligi)lossy compression: making a file smaller by permanently removing details that are hard to notice (MP3, AAC) · yo‘qotishli siqishcaptions: the text of speech and sounds shown with a video, helpful for people who cannot hear it · subtitr
Explanation
Sound is vibration of the air. The computer turns it into an electrical signal with a microphone, measures it many times per second and stores each measurement as a number; this is called sampling. The number of measurements per second is the sampling rate (for example 44100 Hz on an audio CD), and the number of bits for one measurement is the bit depth (16 bits). Stereo sound has two channels (left and right), so the size is twice as big. Uncompressed size = rate × bit depth × channels × seconds (in bits); divide by 8 to get bytes. For example, 16 bits = 2 bytes, so a 10-second stereo recording is 44100·2·2·10 = 1764000 bytes. Files: WAV is usually uncompressed and large; FLAC reduces the size but loses nothing; MP3 and AAC use lossy compression and are about 8–10 times smaller. Video is quickly changing pictures plus sound; MP4 (H.264) and WebM are widely used. HTML5 has the <audio> and <video> elements: the controls attribute shows the control buttons, <source> offers several formats (the browser picks one), <track> adds captions, and poster is a picture shown before the video starts. So as not to annoy the user, sound should not start by itself (do not use autoplay), and captions should be given. Changing a file extension does not change the format: renaming .avi to .mp4 does not convert it; a special program is needed. Other people's music and video are protected by copyright; place only files you recorded yourself or ones with a free licence.
Worked examples
Page code: <!DOCTYPE html> ⏎ <html lang="uz"> ⏎ <head> ⏎ <meta charset="utf-8"> ⏎ <title>Ovoz va video</title> ⏎ </head> ⏎ <body> ⏎ <h1>Maktab radiosi</h1> ⏎ <audio controls src="salom.mp3">Brauzer audio elementini qo‘llamaydi.</audio> ⏎ <video controls width="320" poster="muqova.jpg"> ⏎ <source src="lavha.mp4" type="video/mp4"> ⏎ <source src="lavha.webm" type="video/webm"> ⏎ <track kind="captions" src="lavha.vtt" srclang="uz" label="O‘zbekcha"> ⏎ Brauzer video elementini qo‘llamaydi. ⏎ </video> ⏎ </body> ⏎ </html> The browser picks the first format it can play (mp4 or webm); if it supports neither, the text inside the element is shown.
Size: one minute of 128 kbit/s MP3 is 128000·60/8 = 960000 bytes, about 1 MB. Uncompressed CD quality: 44100·16·2 = 1411200 bits/s, so one minute is 1411200·60/8 = 10584000 bytes, about 10.6 MB – that is 11 times more than the MP3.
Class activity
Record 10 seconds of sound with your phone, save it in two formats (for example WAV and MP3) and compare the sizes. Compare the difference with your own calculation.
Practice
1
A mono recording, 8000 Hz, 8 bits, 20 seconds long: how many bytes is it?
160000
2
Write the line that places the file qoshiq.mp3 on the page with control buttons.
<audio controls src="qoshiq.mp3"></audio>
3
A file was renamed from film.avi to film.mp4. Did the video format change? Why?
No: only the name changed, the data inside stayed the same; a conversion program is needed.
4
Why is adding captions (track) to a video useful? Give two reasons.
People who cannot hear well understand it; it can also be watched without sound (in a quiet room or in noise).