You are on page 1of 33

Teach Computer Science

A-Level

Sound

teachcomputerscience.com
2

Lesson Objectives

Students will learn about:


▪ Storing sound on a computer
▪ Sampling and Nyquist’s theorem
▪ Factors that affect the audio quality of audio files in detail
▪ Musical instrument digital interface (MIDI) files
▪ How to calculate the size of an audio file

teachcomputerscience.com
1.
Content

teachcomputerscience.com
4

Introduction
▪ Sound is another form of data that is stored on a computer.
▪ Similar to other types of information such as numbers, text, and
images, the sound is also stored in digital form.
▪ But, sound, when produced, is in analogue form, that is,
continuous varying data.
▪ To store sound in the computer, it is sampled to obtain thousands
of samples per second where each sample corresponds to a binary
value.
teachcomputerscience.com
5

Sampling
▪ Sampling is the process that
converts analogue sound
into discrete digital data that
can be stored on a
computer.
▪ An analogue sound signal is
shown.
▪ This sound is sampled every
two seconds to obtain
discrete digital sound.
teachcomputerscience.com
6

Sampling
▪ We can see that the shape of
digital sound is quite similar
to analogue sound, but the
curves are not smooth.
▪ A listener will feel that the
digital sound is the same as
the analogue sound but with
a reduced quality.

teachcomputerscience.com
7

Factors affecting audio quality

Factor Definition
Sampling
Number of samples per second
rate
Number of bits used to represent
Bit depth
each clip
Number of bits used per second of
Bit rate
audio

teachcomputerscience.com
8

Sampling rate
▪ The sampling rate is the number of samples taken per second.
▪ The higher the sampling rate, the higher the sound detail. The ups
and downs of the sound wave can be recorded more clearly.
▪ The unit for sampling rate is also represented in Hertz (Hz).
▪ Each sample represents the amplitude of the wave at a certain point
in time.

teachcomputerscience.com
9

Sampling rate

teachcomputerscience.com
10

Sampling rate
▪ The most common sampling rate for music is 44,100 samples per
second, which is 44,100 Hz (=44.1 kHz).
▪ A voice-over-Internet protocol (VOIP) has a sampling rate of 8 kHz,
which is enough for the human voice to be heard clearly, but the
quality is reduced to a certain extent.

teachcomputerscience.com
11

Frequency
▪ The number of
oscillations per second
is called frequency.
▪ It is measured in Hertz
(Hz) and controls the
pitch of the sound.
▪ Sound waves with
different frequencies are
given.

teachcomputerscience.com
12

Nyquist’s theorem
▪ Nyquist’s theorem states that for accurate sampling, the sampling
rate must be at least twice the frequency of the highest frequency in
the original sound signal.
▪ When the sampling rate is less than the frequency suggested by
Nyquist’s theorem, the recording will not be accurate to the original
sound.

teachcomputerscience.com
13

Bit depth
▪ Bit depth is the number of bits available for each sample.
▪ The higher the bit depth, the higher the quality the audio will
be.
▪ A CD has a bit depth of 16 bits, and a DVD has a bit depth of 24
bits.
▪ An n bit system can have 2n different values. Hence, a CD can
represent values from 0 to 65535(216 -1).

teachcomputerscience.com
14

Bit depth
▪ High-quality audio files are created as pulse-code modulation
(PCM).
▪ PCM is the process for digitising a sound file and creating an
uncompressed file.
▪ WAV and AIFF are a few examples of uncompressed audio file
formats.

teachcomputerscience.com
15

Bit rate

▪ Bit rate is the number of bits of data used to store data


sampled every second. The unit for bit rate is kilobits per
second (kbps).
Bit rate=Sampling rate × bit depth × channels
▪ An audio file has 44,100 samples per second, a bit depth of 16-
bits and 2 channels (stereo audio). A bit rate of this file can be
calculated as:
Bit rate=44100×16×2=1,411,200 bits per second=1411.2 kbps
teachcomputerscience.com
16

Bit rate & audio quality

▪ A reasonable music audio must have a minimum bit rate of


128 kbps.
▪ The more the bit rate, the better the quality.
▪ This is the reason why the audio quality of a music CD is better
than downloading from the internet.

teachcomputerscience.com
17

Bit rate & file size

▪ A three-minute audio file with a sampling rate of 44,100 samples


per second, bit depth 16 bits and 2 channels, has a bit rate of
1411.2 kbps per second.
▪ For 3 minutes, the number of bits required is,
1,411,200×180=254,016,000 bits.
▪ This value is equal to 254016000 ÷ 8 = 31752000 bytes = 31.75
megabytes (MB). This is the file size of a three-minute audio file.

teachcomputerscience.com
18

Musical instrument digital


interface (MIDI)
▪ A communication protocol that enables electronic musical
instruments to interact with each other using information and
control signals.
▪ Asynchronous serial 8-bit transmission
▪ MIDI file instructs a device on how to produce a musical note using
several commands.
▪ A command is identified by its specific sequence of bytes.
teachcomputerscience.com
19

MIDI: types of bytes


Status bytes Data bytes
▪ Indicate instruments about the ▪ Information to status byte
type of action to be performed ▪ Pitch byte: denotes note to be
▪ The action of 16 channels are played
represented in this byte ▪ Velocity byte: denotes the
▪ Ex: notes on/off, polyphonic key loudness of the note.
pressure, pitch bend, etc.
▪ Key pressure: how hard a key is
pressed (loudness)
teachcomputerscience.com
20

MIDI files (.mid)


▪ Developed when sound from an instrument is recorded.
▪ Using a MIDI file, music identical to original can be played every time.
▪ Enables us to play the same music through different instruments.
▪ A sequence software is required so that the commands in MIDI files
are recognised.

teachcomputerscience.com
21

MIDI files (.mid)


▪ As these protocols allow the usage of 16 channels, 16 different
instruments can be instructed at the same time.
▪ An electronic orchestra can be created by giving input to each
instrument through a sequencing software.
▪ MIDI files are widely used in recording studios, orchestras and
musical scores in films.

teachcomputerscience.com
22

MIDI files (.mid)


▪ Smaller in size compared to MP3.
▪ Because MIDI file does not contain any audio track.
▪ Used in web pages.
▪ Used in mobile phones to store ringtones.

teachcomputerscience.com
23

Analogue to digital
conversion
▪ An analogue signal is a continuous signal which represents physical
measurements.
▪ A signal from a microphone is an example of an analogue signal.
▪ Sound signals in analogue form can be recorded in tape.
▪ The signals are amplified and played via a speaker.

teachcomputerscience.com
24

Analogue to digital
conversion
▪ Whereas digital signal is a discrete signal that uses discontinuous
values to represent information.
▪ For example, information stored in compact disc, computer, digital
watch.
▪ An analogue signal is sampled at intervals to convert it to digital
values which are then stored in devices such as compact disc and
DVDs.

teachcomputerscience.com
25

Analogue to digital
conversion
▪ A microphone converts sound energy to electrical energy.
▪ In this process, sound in analogue form is converted to digital form
by sampling the analogue signal at intervals.
▪ The amplitude at the intervals is measured and converted to binary
value based on the bit depth.
▪ Digital values are converted to analogue signals by a digital to
analogue converter (DAC). The signal is amplified and sent to a
speaker.
teachcomputerscience.com
26

Analogue to digital
conversion

teachcomputerscience.com
27

Let’s review some concepts

Sampling Factors affecting audio Sampling rate


quality
Sampling is the process that A number of samples per
converts analogue sound into Sampling rate second. Usually represented in
discrete digital data that can be Hertz.
Bit depth
stored in a computer.
Nyquist’s theorem states that for
Bit rate
accurate sampling, the sampling
Bit depth rate must be at least twice the
frequency of the highest
The number of bits used to Musical instrument digital
frequency in the original sound
represent each clip. An n-bit interface (MIDI)
signal.
system can represent 2n different A communication protocol that
values. Calculating file size
enables electronic musical
Bit rate instruments to interact with each File size (bits)= bit rate × number
Number of bits used per second other using information and of seconds
of audio. Bit rate=Sampling rate × control signals.
bit depth × channels
teachcomputerscience.com
2.
Activity

teachcomputerscience.com
29

Activity-1
Duration: 10 minutes

1. A system has a bit depth of 8 bits. What range of values can it


represent? Show your working.
2. Calculate the bit rate of a 32-bit depth system with sampling rate
44,100 samples per second and 2 channels.
3. What is the file size of a 4-minute song with bit rate found in
question 2?
4. What happens to the file size and sound quality if the sampling
rate is increased?
teachcomputerscience.com
3.
End of topic questions

teachcomputerscience.com
31

End of topic questions


1. How is an analogue sound converted to digital form?
2. How is a sound file downloaded from the internet different
from a sound file in CD?
3. What happens to a sound file if its bit depth is increased?
4. Why is the sampling rate of sound in VoIP just 8 kHz?
5. What are the factors by which the audio quality of a digital
sound is affected?

teachcomputerscience.com
32

End of topic questions


6. This question is about the waveform given.

i. What is the frequency of this signal?


ii. What is the minimum sampling frequency required to sample this signal so
that an accurate recording can be made?
teachcomputerscience.com
33

End of topic questions


7. What are the advantages of using a MIDI file? State examples of
data stored about a musical note in a MIDI file.

teachcomputerscience.com

You might also like