Explore how computers store and playback sound
Use the Python programming language to see how digital audio works with interactive visualisations.
Test your understanding with programming exercises.
Before we start writing code, let's understand the problem we are trying to solve: translating sounds in the physical world into digital data.
In the real world, sound is a continuous wave of air pressure. When an object vibrates, like a guitar string or your vocal cords, it pushes and pulls the air molecules around it. These pressure changes travel through the air smoothly and gradually. We call this kind of sound a continuous, or analog signal.
Computers cannot directly process continuous sound waves. A computer is a digital machine: it can only store and process discrete numbers, specifically binary data (zeros and ones).
To record or play sound on a computer, we have to translate the kind of smooth physical sound waves we observe in the real world into a sequence of numbers. This translation process is called Analog-to-Digital Conversion (ADC).
Once our analog signal has been converted into digital form, we can use computers to process the audio, for example modifying its loudness or even transmitting it over the internet.
After processing, our digital audio signal will need to be converted back into analog form in order for it to be played back over headphones or loudspeakers.
Let's look at what happens when we make a call with a computer application like WhatsApp or Telegram. When you speak to a friend over the internet, your voice is processed through several steps:
Microphone: Your voice creates physical sound waves in the air. The microphone captures these pressure changes and turns them into a continuous electrical voltage. This is our analog signal.
ADC (Analog-to-Digital Converter): Your computer's audio hardware transforms the continuous electrical voltage from the microphone into a digital signal (a sequence of numbers).
3. Transmission: The digital signal is processed and transmitted across the internet to your friend's computer. At this stage, your voice is still just a collection of numbers.
4. DAC (Digital-to-Analog Converter): Your friend's computer receives the data. The audio hardware reads the list of numbers and translates them back into a continuous electrical voltage.
5. Playback: This voltage is sent to your friend's headphones, causing a membrane in their headphones or speakers to physically vibrate. This pushes the air, recreating the original sound waves for them to hear.
Remarkably, this entire, complex chain of operations happens in just a few thousandths of a second!
We are going to explore the key parts of the Analog-to-Digital Conversion process in the exercises below.
Specifically, you will experiment with in three stages:
Getting Started with Python: Learn the key concepts of programming in Python.
Sampling: How the computer takes snapshots of the analog sound signal over time.
Quantization: How the computer turns those signal snapshots into discrete numbers.
Using a Python programming environment, you will be able to implement and experiment with these important concepts. You will visualize digital audio data and hear the errors that occur when the Analog-to-Digital Conversion process goes wrong.
Please note that the three programming modules below are hosted as Jupyter Notebooks on Google Colab.
In order to access and run the code yourself, you will need to log into Google with an account when you click on the links below.
This notebook walks you through a brief introduction to key concepts in Python programming.
You will learn how to:
Run Python code in notebooks hosted on Google Colab
Work with basic Python concepts such as variables and functions
This notebook illustrates the process of sampling audio signals.
You will learn:
How the sampling process works
What can go wrong when sampling audio signals improperly
How to visually inspect a sampled waveform
This notebook explains the quantization process for digital audio signals.
You will learn:
How sound in the physical world can be captured and represented by an electrical voltage.
How signal samples can be mapped to a finite set of digital levels.
What quantization noise is and how it can degrade the quality of digital audio signals.
Congratulations! You have reached the end of this module. 🎉
As we have seen, sampling and quantization are the bridge between analog and digital audio.
They are the foundations of digital signal processing, enabling all of the advanced audio and multimedia technologies we use in our daily lives.
If you are curious to learn more about the topics we have covered, as well as other audio signal processing topics, we have included some useful resources below.
The Scientist and Engineer's Guide to Digital Signal Processing by Steven W. Smith, Ph.D. - A complete and free online textbook, covering all Digital Signal Processing topics, including sampling and quantization.
Speech Processing Online Textbook by Aalto University - An introduction to modern speech processing algorithms and methods. Also includes a section about sampling and quantization.
Coding: A Practical Guide - Basic Python programming guide by the University of York.
learnpython - More advanced and complete Python programming course.