1 of 98

ELEN0450 · Multimedia Systems

Lecture 8

Audio digitization & compression

How sound becomes bits, and how we drop the bits the ear won't miss

www.viulab.be

2 of 98

Recap: where we are in the pipeline

Reminder

Last lecture: How we hear, capture, and reproduce analog sound

Sound as a wave, analyzing frequencies, hearing and rooms, microphones, loudspeakers, and analog storage

This lecture: How we digitize sound and compress it

Representation

Digitization

Acquisition Capture

Compression Storage

Distribution Transmission

Display

Render

3 of 98

Scope of the course

3

Analog path

Digital path

Physical scene

Light, sound, motion

Capture

Lens, sensor, microphone

Analog signal

Continuous in time and amplitude

Analog storage and transport

Film, vinyl, tape, broadcast

Rendering

Display, loudspeaker, print

Synthesis

Graphics, audio, generative

Digital signal representation

ADC, samples,

pixels, bit depth

Source coding

compression

JPEG, AAC, MP4

Storage

Container, disc, network

Transmission and decoding

Network, Inverse transform, DAC

Human perception

Visual and auditory systems

Sampling and quantization

Perceptual models drive the coding stage: chroma subsampling, quantization tables, masking thresholds

Scope

4 of 98

What you'll be able to do after today's class

Objective

Explain sampling and aliasing with the DTFT, and choose a sampling rate

Compute the SQNR, justify dither, and describe how a CD stores PCM

Build a Huffman code and compare its average length with the entropy

Explain predictive coding (DPCM) and speech coding (LPC, CELP)

Explain how masking drives bit allocation in MP3 and AAC

Understand the MIDI format

5 of 98

Table of content

ELEN0450 · Multimedia Systems

1

Basics of multimedia

2

Graphics & image representation

3

Colorimetry & color spaces

4

Analog image & video

5

Camera model & digital sensors

6

Analog and digital displays

7

Acoustics, microphones & speakers

8

Audio digitization & compression

9

Digital image compression

10

Digital video compression

11

Transmission protocols

12

Internet distribution

From pressure to samples

– Discrete Fourier analysis

– Nyquist and aliasing

– Reconstruction and sampling rates

From samples to bits

– Quantization and SQNR

– Dither, µ-law and bitrates

– Storing PCM: the compact disc

Lossless coding

– Entropy and Huffman coding

– Prediction coding

Perceptual coding

– Masking and critical bands

– MPEG audio and MP3

– AAC and today's codecs

– The MIDI format

6 of 98

From a voltage to numbers

6

Problem statement

A microphone delivers a continuous voltage, but a computer only stores and sends numbers.

An analog-to-digital converter (ADC) filters, samples and quantizes the voltage into bits.

Each block of this chain sets a hard limit on audio quality

7 of 98

What the ear asks of a digital system

7

Reminder

We hear from about 20 Hz to 20 kHz (Lecture 7).

About 120 dB separate the threshold in quiet from the threshold of pain.

The frequency range sets the sampling rate; the level range sets the number of bits

https://www.sound2020.org/sound/audible/

https://lms.eduqode.com/courses/science-grade-vi-2/lesson/audible-frequency-range-2-3/?page_tab=overview

8 of 98

Sampling a signal

8

Definition

 

9 of 98

Reminder: Fourier analysis, from analog to digital

9

Reminder

Lecture 7:

  • the Fourier series analyses continuous periodic signals
  • the Fourier transform continuous aperiodic ones

Sampled signals have discrete counterparts: the discrete Fourier series (DFS) and the discrete-time Fourier transform (DTFT).

 

 

10 of 98

Discrete Fourier series (DFS)

10

Mathematical definition

 

11 of 98

Discrete-time Fourier transform (DTFT)

11

Mathematical definition

 

12 of 98

In practice: the DTFT and the FFT

12

 

Property

13 of 98

Sampling seen in the spectrum

13

Mathematical definition

 

 

14 of 98

The Nyquist-Shannon sampling theorem

14

Property

 

 

15 of 98

Aliasing

15

Idea

 

16 of 98

Worked: a 15 kHz tone sampled at 16 kHz

16

Example

 

17 of 98

The anti-aliasing filter

17

Process

 

18 of 98

Listen: aliasing

18

Examples

A sweep from 50 Hz to 20 kHz, resampled at 8 kHz without and with an anti-alias filter.

Without the filter, every tone above 4 kHz folds back: the pitch goes up and down.

original, 48 kHz

8 kHz, no filter

8 kHz, with filter

19 of 98

Note: why 44.1 kHz?

19

 

Note

20 of 98

Reconstruction in the DAC

20

Process

 

21 of 98

Common sampling rates

21

Overview

Sampling rate

Audio bandwidth

Typical use

8 kHz

300-3,400 Hz

Telephone (G.711), narrowband speech

16 kHz

50-7,000 Hz

Wideband speech: VoIP, HD voice

44.1 kHz

20 Hz-20 kHz

CD, music files and streaming

48 kHz

20 Hz-20 kHz

Video, broadcast, DVD, film production

96 or 192 kHz

beyond 40 kHz

Studio recording, high-resolution audio

22 of 98

Table of content

ELEN0450 · Multimedia Systems

1

Basics of multimedia

2

Graphics & image representation

3

Colorimetry & color spaces

4

Analog image & video

5

Camera model & digital sensors

6

Analog and digital displays

7

Acoustics, microphones & speakers

8

Audio digitization & compression

9

Digital image compression

10

Digital video compression

11

Transmission protocols

12

Internet distribution

From pressure to samples

– Discrete Fourier analysis

– Nyquist and aliasing

– Reconstruction and sampling rates

From samples to bits

– Quantization and SQNR

– Dither, µ-law and bitrates

– Storing PCM: the compact disc

Lossless coding

– Entropy and Huffman coding

– Prediction coding

Perceptual coding

– Masking and critical bands

– MPEG audio and MP3

– AAC and today's codecs

– The MIDI format

23 of 98

Uniform quantizer

23

Definition

 

24 of 98

Quantization noise

24

Property

 

25 of 98

Signal-to-quantization-noise ratio (SQNR)

25

Mathematical demo

 

26 of 98

Exercise: how many bits do we need?

26

Example

​

16 bits already exceed the useful range of home listening (a quiet room at 30 dB SPL, loud peaks at 110 dB SPL). Studios record with 24 bits for headroom. Beyond that range, the analog electronics are anyway noisier than the quantizer.

​

16 bits (CD): 98.1 dB

24 bits (studio): 146.2 dB

27 of 98

Listen: bit depth

27

Examples

The same clip quantized with 16, 8, 6 and 4 bits. At 6 and 4 bits the noise becomes audible, and the quiet tail of the last note turns into a buzzing sound.

16 bits

8 bits

6 bits

4 bits

28 of 98

Quiet signals: distortion instead of noise

28

Problem statement

When a signal is only a few steps tall, the error is no longer random: it repeats with the signal.

It is heard as harmonic distortion, and a sound smaller than half a step is simply rounded to silence.

Here: a 1 kHz tone of 1.3 steps, quantized with 6 bits

29 of 98

Dithering audio signals

29

Idea

Dithering adds a small random noise before quantizing: the dither.

  • TPDF (Triangular Probability Density Function) dither is the sum of two uniform distributions which makes the error independent of the signal.
  • In this case, distortion is traded for a constant, gentle hiss, and details smaller than one step survive on average.

Studios dither when they reduce 24-bit masters to 16 bits

30 of 98

Listen: dither

30

Examples

A tone that fades out over 6 seconds, quantized with 6 bits. Without dither it turns into a buzz and stops abruptly; with dither it fades smoothly into a steady hiss.

16 bits (reference)

6 bits, no dither

6 bits, TPDF dither

31 of 98

PCM and bitrate

31

Definition

 

32 of 98

The compact disc

32

Overview

Philips and Sony proposed the Compact Disk (CD) format in 1980; the first discs went on sale in 1982 in Japan and 1983 in Europe.

  • It stores 16-bit PCM at 44.1 kHz in stereo, 74 minutes on a 12 cm disc (80 minutes on later discs). Unlike tape, it allows random access and nothing touches the disc.
  • Pits pressed in a plastic substrate follow a spiral track, read by a laser from the inside out.

33 of 98

Table of content

ELEN0450 · Multimedia Systems

1

Basics of multimedia

2

Graphics & image representation

3

Colorimetry & color spaces

4

Analog image & video

5

Camera model & digital sensors

6

Analog and digital displays

7

Acoustics, microphones & speakers

8

Audio digitization & compression

9

Digital image compression

10

Digital video compression

11

Transmission protocols

12

Internet distribution

From pressure to samples

– Discrete Fourier analysis

– Nyquist and aliasing

– Reconstruction and sampling rates

From samples to bits

– Quantization and SQNR

– Dither, µ-law and bitrates

– Storing PCM: the compact disc

Lossless coding

– Entropy and Huffman coding

– Prediction coding

Perceptual coding

– Masking and critical bands

– MPEG audio and MP3

– AAC and today's codecs

– The MIDI format

34 of 98

Why lossless coding works

34

Reminder

Lecture 1: raw media is huge, so we remove redundancy. In audio: statistical redundancy (some values are more frequent) and correlation (successive samples are alike).

Lossless coding removes only these and the decoder can rebuild every sample bit for bit.

35 of 98

Huffman coding

35

Algorithm

Objective, replace repeating symbols by short code words and rare ones by longer ones.

  • Create one leaf per symbol, weighted by its probability.
  • Merge the two least probable nodes into a parent weighted by their sum; repeat until a single root remains.
  • Read each codeword along the path from the root: 0 on one branch, 1 on the other.

Huffman (1952): the shortest average length among codes with a whole number of bits per symbol

36 of 98

Example: Huffman code of prediction residuals

36

Example

Residual values after quantization of 0, +1, −1, +2, −2 with probabilities 0.50, 0.15, 0.15, 0.10 and 0.10

Symbol

Probability

Codeword

Length (bits)

Probability × length

0

0.50

0

1

0.50

+1

0.15

100

3

0.45

−1

0.15

101

3

0.45

+2

0.10

110

3

0.30

−2

0.10

111

3

0.30

 

37 of 98

Run-length coding

37

Definition

Replace each run of identical values by a pair (value, run length).

Worth it only for long runs: digital silence, fax pages, and the zeros of quantized transform coefficients in JPEG (Lecture 9).

38 of 98

Raw PCM samples barely compress

38

Problem statement

An entropy coder that treats the 16-bit samples of a piano clip as independent still needs H = 11.5 bits per sample: a gain of only 1.4 : 1.

The samples take thousands of different values, but successive samples are strongly correlated: that is the redundancy to exploit.

39 of 98

Predictive coding

39

Idea

 

40 of 98

DPCM: prediction with a quantizer

40

Process

 

41 of 98

Table of content

ELEN0450 · Multimedia Systems

1

Basics of multimedia

2

Graphics & image representation

3

Colorimetry & color spaces

4

Analog image & video

5

Camera model & digital sensors

6

Analog and digital displays

7

Acoustics, microphones & speakers

8

Audio digitization & compression

9

Digital image compression

10

Digital video compression

11

Transmission protocols

12

Internet distribution

From pressure to samples

– Discrete Fourier analysis

– Nyquist and aliasing

– Reconstruction and sampling rates

From samples to bits

– Quantization and SQNR

– Dither, µ-law and bitrates

– Storing PCM: the compact disc

Lossless coding

– Entropy and Huffman coding

– Prediction coding

Perceptual coding

– Masking and critical bands

– MPEG audio and MP3

– AAC and today's codecs

– The MIDI format

42 of 98

11 : 1 without audible loss?

42

Problem statement

Some entropy-based algorithms (FLAC) can compress the piano clip only 4.1:1. But, streaming services deliver music at 128 to 320 kbit/s, i.e., 4.4:1 to 11:1.

The only way: let the waveform change but keep the error where the ear cannot detect it.

43 of 98

Objective of perceptual coding

43

Objective

Reduce an audio file size while keeping reasonable quality.

 

 

 

 

 

 

 

 

44 of 98

Threshold in quiet

44

Reminder

A tone is heard only if its level exceeds the threshold in quiet, lowest around 3 to 4 kHz.

Any noise below this curve is inaudible, whatever its origin.

45 of 98

Critical bands and the Bark scale

45

Definition

The cochlea analyses sound with overlapping band-pass filters. Within one critical band, sounds interact strongly and mask each other.

About 24 bands cover the hearing range: about 100 Hz wide below 500 Hz, then wider and wider.

46 of 98

Frequency masking

46

Definition

A loud sound raises the threshold at nearby frequencies: weaker components there become inaudible.

  • Masking spreads further towards high frequencies than towards low ones and widens as the masker gets louder.

47 of 98

Listen: masking

47

Examples

A pulsed 1 kHz tone alone, then the same tone inside a narrow band of noise centered on 1 kHz and 17 dB louder, then a 2.5 kHz tone with the same noise. Inside the band the tone disappears.

1 kHz tone alone

same tone + noise band

2.5 kHz tone + noise band

48 of 98

Temporal masking

48

Property

Masking also acts in time: a loud sound hides weaker sounds that follow it for 50 to 200 ms (post-masking), and even those just before it, for a few milliseconds (pre-masking).

Codecs rely on post-masking and must keep their noise from spreading ahead of an attack.

49 of 98

MPEG audio overview

49

Overview

MPEG audio compression takes advantage of psychoacoustic models, constructing a large multidimensional lookup table to transmit masked frequency components using fewer bits.

Principle:

1. Apply a filter bank to the input to break it into its frequency components

2. In parallel, apply a psychoacoustic model to the data for bit allocation block

3. The number of bits allocated (which is a parameter to choose) are used to quantize the info from the filter bank, providing the compression

Time to frequency analysis

Psychoacoustic modeling

Bit allocation and coding

Bitstream formatting

Audio (PCM)

input

Encoded bitstream

Where we drop information

50 of 98

MPEG I layers

50

Idea

MPEG I audio offers three compatible layers (MP1, MP2, MP3):

  • Each succeeding layer can understand the lower layers
  • Each succeeding layer offers more complexity in the psychoacoustic model and better compression for a given level of audio quality
  • But each succeeding layer is accompanied by extra delay

The objective of MPEG layers: a good tradeoff between quality and bitrate

MPEG I layer 3: Designed to offer high quality at low bit rates.

Adds a more sophisticated perceptual model.

MPEG I layer 2: short amount of time to encode and therefore still used in live broadcast

MPEG I layer 1: was intended for the Digital Compact Cassette, but is now virtually obsolete

51 of 98

MPEG Audio compression algorithm

51

Algorithm

 

52 of 98

Hide the noise under the masking threshold

52

Idea

A masking threshold, based on a psychoacoustic model, combines the threshold in quiet with the masking of every spectral component of the window.

In each subband, quantization noise may rise up to this threshold.

The signal-to-mask ratio (SMR) tells how many dB of SNR each band really needs.

53 of 98

Bit allocation

53

Algorithm

 

54 of 98

The MPEG-I audio encoder

54

 

Summary

55 of 98

MPEG-1 audio: three layers

55

Overview

Layer

Filter bank

Frame

Bitrates

Near-CD quality

Where

I

32 subbands

384 samples

32–448 kbit/s

≈ 384 kbit/s

Digital Compact Cassette

II (MP2)

32 subbands

1,152 samples

32–384 kbit/s

≈ 192–256 kbit/s

DAB radio, DVB, Video CD

III (MP3)

32 subbands + MDCT

1,152 samples

32–320 kbit/s

≈ 128 kbit/s

Internet, portable players

Note

At 64 kbit/s per channel, listeners rate Layer II between 2.1 and 2.6 and Layer III between 3.6 and 3.8 on a 1 to 5 scale for audio quality.

56 of 98

Example: a 4-minute song

56

Example

 

57 of 98

Listen: MP3 bitrates

57

Examples

A piano clip at five bitrates. At 64 and 32 kbit/s the high frequencies disappear and the sound becomes watery; at 320 kbit/s the difference is very hard to hear.

original PCM

MP3, 320 kbit/s

MP3, 128 kbit/s

MP3, 64 kbit/s

MP3, 32 kbit/s

58 of 98

How do we measure audio quality?

58

Definition

Method

Principle

Result

MOS (ITU-T P.800)

Listeners rate each clip from 1 (bad) to 5 (excellent)

Mean opinion score

ABX test

Blind choice: is X the original A or the coded B?

Audible difference or not

MUSHRA (ITU-R BS.1534)

Several versions side by side, with a hidden reference and a low-pass anchor

Score from 0 to 100

PEAQ (ITU-R BS.1387)

A hearing model compares the coded and the original signals

Objective difference grade

Note

The SNR is useless here: a good perceptual codec has a poor SNR but sounds identical to the original.

59 of 98

Audio codecs today

59

Overview

Codec

Year

Type

Typical bitrate

Where you meet it

FLAC

2001

Lossless (prediction + Rice codes)

25–70 % of PCM

Archives, lossless streaming

MP3

1993

Perceptual (subbands + MDCT)

128–320 kbit/s

Downloads, podcasts

AAC, HE-AAC

1997, 2003

Perceptual (MDCT), SBR

32–256 kbit/s

YouTube, Apple Music, DAB+, DVB

Vorbis

2002

Perceptual (MDCT)

96–320 kbit/s

Video games, Spotify (historically)

Dolby Digital (AC-3)

1992

Perceptual (MDCT), 5.1 channels

384–640 kbit/s

Cinema, DVD, digital TV

Opus

2012

SILK + CELT

6–510 kbit/s

WebRTC calls, Discord, YouTube

60 of 98

Summary

60

Summary

 

61 of 98

Audio: where each stage lands

Stage

Analog

Digital

Transduction

Microphone, continuous voltage

Microphone, preamplifier, ADC

Representation

1D voltage waveform

PCM samples, 44.1 or 48 kHz, 16 or 24 bit

Digitisation

Transducer and medium set the bandwidth

Anti-alias filter, Nyquist rate, dither

Coding

Pre-emphasis (RIAA), companding (Dolby NR)

MP3, AAC

Storage media

Vinyl groove, magnetic tape, compact cassette

CD-DA, flash, HDD, cloud

Transmission

AM and FM radio, telephone line

DAB+, IP audio, WebRTC

Distribution

Broadcast schedule, record retail

On demand streaming, adaptive bitrate, podcast feeds

Rendering

Amplifier, loudspeaker, headphones

DAC, amplifier, stereo to Ambisonics or binaural

Perception

Human hearing system

Overview

61

62 of 98

Next time and further reading

62

• Lecture 9: Digital image compression (Ch. 7.5, 8 and 9)

• Sources: Fundamentals of Multimedia, Ch. 6.1, 6.3, 7, 13 and 14

• ULiège course notes: Introduction to audio and video techniques, Ch. 3 (J.-J. Embrechts)

• Xiph.org, Digital Show & Tell (2013); IETF RFC 6716 (Opus); FLAC format specification

• Questions?

63 of 98

Table of content

ELEN0450 · Multimedia Systems

1

Basics of multimedia

2

Graphics & image representation

3

Colorimetry & color spaces

4

Analog image & video

5

Camera model & digital sensors

6

Analog and digital displays

7

Acoustics, microphones & speakers

8

Audio digitization & compression

9

Digital image compression

10

Digital video compression

11

Transmission protocols

12

Internet distribution

From pressure to samples

– Discrete Fourier analysis

– Nyquist and aliasing

– Reconstruction and sampling rates

From samples to bits

– Quantization and SQNR

– Dither, µ-law and bitrates

– Storing PCM: the compact disc

Lossless coding

– Entropy and Huffman coding

– Prediction coding

Perceptual coding

– Masking and critical bands

– MPEG audio and MP3

– AAC and today's codecs

– The MIDI format

64 of 98

Extra slides

64

65 of 98

Worked: the DFS of an 8-sample period

65

Example

 

66 of 98

Type of signals and their frequency analysis

66

​

Continuous-time signals (CT)

Discrete-time signals (DT)

​

Time-domain

Frequency-domain

Time-domain

Frequency-domain

Periodic

​

​

​

​

​

Aperiodic

​

​

​

​

​

Fourier series (FS)

Fourier Transforms (FT)

 

CTFS

 

ICTFS

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

…

…

…

…

 

 

 

 

CTFT

 

ICTFT

 

 

 

 

 

 

 

DTFS

IDTFS

 

 

 

 

 

 

 

 

DTFT

IDTFT

 

[SOURCE] Manolakis and Ingle, Applied Digital Signal Processing: Theory and Practice, page 170.

Summary

67 of 98

Table of content

ELEN0450 · Multimedia Systems

1

Basics of multimedia

2

Graphics & image representation

3

Colorimetry & color spaces

4

Analog image & video

5

Camera model & digital sensors

6

Analog and digital displays

7

Acoustics, microphones & speakers

8

Audio digitization & compression

9

Digital image compression

10

Digital video compression

11

Transmission protocols

12

Internet distribution

From pressure to samples

– Discrete Fourier analysis

– Nyquist and aliasing

– Reconstruction and sampling rates

From samples to bits

– Quantization and SQNR

– Dither, µ-law and bitrates

– Storing PCM: the compact disc

Lossless coding

– Entropy and Huffman coding

– Prediction and FLAC

Speech coding

– ADPCM and linear prediction

– CELP and Opus

Perceptual coding

– Masking and critical bands

– MPEG audio and MP3

– AAC and today's codecs

– The MIDI format

68 of 98

Telephone speech: most samples are small

68

Problem statement

Telephony allows only 8 bits per sample at 8 kHz, i.e., 64 kbit/s: 256 uniform levels spread over the whole range.

Speech spends most of its time at low amplitude: loud peaks get levels they rarely use, quiet sounds get only a few.

69 of 98

µ-law and A-law companding

69

Mathematical definition

 

70 of 98

µ-law keeps the SQNR almost constant

70

Property

With uniform 8 bits, the SQNR drops by 1 dB for every dB of level: quiet talkers sound noisy.

With µ-law, the SQNR stays between about 35 and 39 dB from −40 to 0 dBFS. At −30 dBFS: 20.6 dB uniform, 36.8 dB µ-law.

71 of 98

Listen: µ-law

71

Examples

Quiet speech (peaks at −20 dBFS), sampled at 8 kHz and coded with 8 bits: uniform steps against µ-law steps.

16 bits (reference)

8 bits, uniform

8 bits, µ-law

72 of 98

Audio quality versus data rate

72

Overview

Quality

Sampling rate (kHz)

Bits per sample

Channels

Uncompressed (kB/s)

Bandwidth (Hz)

Telephone

8

8

Mono

8

200–3,400

AM radio

11.025

8

Mono

11.0

100–5,500

FM radio

22.05

16

Stereo

88.2

20–11,000

CD

44.1

16

Stereo

176.4

5–20,000

DVD audio

192 (max)

24 (max)

Up to 6

1,200 (max)

0–96,000 (max)

73 of 98

Reading the pits with a laser

73

Principle

 

Source: J.-J. Embrechts, Introduction to Audio and Video Techniques, ULiège, Ch. 3 (after Pohlmann)

74 of 98

Channel coding: eight-to-fourteen modulation

74

A pit cannot be shorter than the laser spot, and the player recovers its clock from the pit edges.

EFM (Eight-to-Fourteen Modulation) maps each byte to a 14-bit word whose 1s are separated by 2 to 10 zeros; 3 merging bits keep the rule between words.

Pits and lands are therefore 3 to 11 channel bits long (0.83 to 3.05 µm), and each byte takes 17 channel bits.

Property

75 of 98

Error correction: CIRC

75

Idea

A scratch or a speck of dust destroys thousands of consecutive bits: a burst error.

The cross-interleaved Reed-Solomon code (CIRC) adds parity (24 audio bytes become 32) and interleaves the bytes over many frames: a burst becomes isolated errors that the codes correct.

It corrects about 4,000 consecutive bits (2.5 mm of track) and conceals up to 12,300 bits (7.7 mm) by interpolating the missing samples.

76 of 98

Exercise: the CD frame and its bitrate

76

Example

 

77 of 98

Information and entropy

77

Definition

 

78 of 98

Exercise: a 4-symbol source

78

Example

 

79 of 98

Arithmetic coding

79

Idea

 

80 of 98

ADPCM: adapt the quantizer to the signal

80

Idea

 

81 of 98

Worked: DPCM step by step

81

Example

 

n

1

2

3

4

5

​

130

150

140

200

230

​

130

130

142

144

167

​

0

20

−2

56

63

​

0

24

−8

56

56

​

130

154

134

200

223

82 of 98

FLAC: Free Lossless Audio Codec

82

Process

 

83 of 98

MP3: a hybrid filter bank

83

Process

Layer III splits each of the 32 subbands again with an MDCT into 18 lines: 576 frequency lines per granule, two granules per frame.

Each line is about 38 Hz wide at 44.1 kHz, fine enough to follow the narrow critical bands at low frequencies.

84 of 98

The source-filter model of speech

84

Principle

 

85 of 98

Linear predictive coding (LPC)

85

Mathematical definition

 

86 of 98

CELP: analysis by synthesis

86

Process

Code-excited linear prediction keeps the LPC filter but searches for the best excitation: a pitch contribution (adaptive codebook) plus a few pulses (fixed codebook).

The encoder synthesizes candidates and keeps those that minimize the perceptually weighted error.

G.729 at 8 kbit/s (10 ms frames) for VoIP; AMR from 4.75 to 12.2 kbit/s in GSM and 3G phones.

87 of 98

Opus: one codec from speech to music

87

Overview

Standardized by the IETF in 2012 (RFC 6716), open and royalty-free.

Combines SILK (linear prediction, from Skype) for speech and CELT (MDCT transform coding) for music: 6 to 510 kbit/s, frames from 2.5 to 60 ms, 26.5 ms of delay by default.

Used in WebRTC calls (Google Meet, Discord) and for YouTube audio.

88 of 98

Listen: speech codecs

88

Examples

The same sentence through several codecs. G.711 and G.726 stop at 4 kHz; Opus at 32 kbit/s keeps up to 8 kHz with half the bitrate of G.711; the LPC vocoder keeps only the formants and the pitch.

original (16 kHz)

G.711, 64 kbit/s

G.726, 32 kbit/s

Opus, 32 kbit/s

Opus, 16 kbit/s

Opus, 8 kbit/s

LPC vocoder

89 of 98

Speech codecs at a glance

89

Overview

Codec

Year

Technique

Sampling

Bitrate

Typical use

G.711

1972

PCM, µ-law or A-law

8 kHz

64 kbit/s

Telephone network

G.726

1990

ADPCM

8 kHz

16–40 kbit/s

DECT cordless phones

LPC-10 (FS1015)

1984

LPC vocoder

8 kHz

2.4 kbit/s

Secure military voice

G.729

1996

CS-ACELP

8 kHz

8 kbit/s

Voice over IP

AMR-NB, AMR-WB

1999, 2001

ACELP

8 or 16 kHz

4.75–23.85 kbit/s

GSM, 3G, HD voice

Opus

2012

SILK + CELT

8–48 kHz

6–510 kbit/s

WebRTC, Discord

90 of 98

Pre-echo

90

Problem statement

Quantization noise spreads over the whole transform window. Before a sharp attack the window starts in silence, where nothing masks it: an audible pre-echo. (Noise exaggerated here: 10 dB SNR per block.)

original

long window (2,048 samples)

short window (256 samples)

91 of 98

Window switching

91

Idea

Stationary sound: long windows for a fine frequency resolution. Attack detected: short windows, so that the noise stays within the pre-masking interval.

Transition windows (start, stop) keep perfect reconstruction. MP3: 18 lines per long block, 3 × 6 per short block. AAC: 2,048 samples or 8 × 256.

92 of 98

Inside MP3: quantization and coding

92

Idea

 

93 of 98

Joint stereo

93

Idea

 

94 of 98

AAC and HE-AAC

94

Overview

AAC (MPEG-2 in 1997, then MPEG-4): a pure MDCT with 1,024 lines (8 × 128 for attacks), temporal noise shaping and better entropy coding. AAC at 96 kbit/s is comparable to MP3 at 128 kbit/s.

HE-AAC adds spectral band replication (SBR): the core codes the low band, the decoder rebuilds the high band from it with a few kbit/s of envelope data.

Used by YouTube, Apple Music, DAB+ radio and DVB television.

95 of 98

MIDI: notes instead of sound

95

Definition

MIDI (1983) is a technical standard that describes a communication protocol, digital interface, and electrical connectors that connect a wide variety of electronic musical instruments, computers, and related audio devices for playing, editing, and recording music.

A message is a status byte plus one or two 7-bit data bytes: Note On and Off, Program Change (instrument), Control Change (pedal, volume), Pitch Bend. Note 60 is middle C; a Note On takes 0.96 ms on the wire.

Sits on the synthesis branch of the scope diagram

MIDI 1.0 Detailed Specification (MIDI Manufacturers Association); the receiver makes the sound

96 of 98

The synthesizer decides how it sounds

96

Examples

The file fixes the notes, the synthesizer makes the sound: the same 467 bytes through an additive wavetable, through two-operator FM (Yamaha DX7, the OPL chips of 1990s sound cards), and through a 12.5 % pulse.

General MIDI (1991) fixes 128 instrument numbers and reserves channel 10 for drums, so a file sounds roughly as intended anywhere.

Tiny files and instant editing, but no voice and no room

additive wavetable

two-operator FM

12.5 % pulse

97 of 98

How the Game Boy made sound

97

Examples

 

Pulse chanels

wave channel

noise: 15-bit, slow, 7-bit

all four channels

98 of 98

Old-school video game music

98

Examples