Lesson 58: Sampling sound
此页面需较新浏览器(支持 SharedArrayBuffer)。请升级 Chrome、Edge、Firefox 或 Safari 至最新版本。
English
From sound wave to numbers
- Sound is a wave: the voltage from a microphone goes up and down smoothly.
- A computer cannot store a smooth wave. It samples it: it measures the height again and again, at fixed times.
- Each measurement is stored as a binary number.
Words for this lesson
| Word | Meaning |
|---|---|
| sample | one measurement of the wave's height |
| sample rate | how many samples are taken each second (Hz) |
| sample resolution | how many bits each sample has |
English
More or fewer bits?
| Resolution | Values | Result |
|---|---|---|
| 10 bits | 0 to 1023 | close to the real sound, bigger file |
| 2 bits | 0 to 3 | very rough sound, tiny file |
English
In the exam
- 0478/11/M/J/23 Q2(a): state what is meant by sample rate and sample resolution. Mark scheme: the sample rate is the number of samples taken in a second; the sample resolution is the number of bits per sample.
- 0478/12/O/N/23 Q5: a band records a song. (a) A benefit of a higher sample rate: the recording is more accurate, closer to the original. (b) A drawback: the file size increases. (c) Sample resolution: the number of bits per sample, which sets how many different amplitudes can be stored.
难度 3/5 · 今日首次完成可获 200 金币及少量额外奖励
A microphone turns sound into a voltage that goes up and down. Recording sound means sampling: measuring the voltage again and again at fixed times. Take 8 samples, one every 100 ms: wait 100 ms, then store analogRead(A0) 入 samples[i]. The program prints them.
点击“运行”查看此处输出。
难度 4/5 · 今日首次完成可获 280 金币及少量额外奖励
Now store the same sound with a sample resolution of 2 bits. samples[i] >> 8 shifts the 10 bits right by 8, so only the top 2 bits are left: a value from 0 to 3. Print 2-bit: and the 8 small values, like the first line.
点击“运行”查看此处输出。