音频处理Lec3:量化与压缩

量化 Quantization

引言 Intro

用于表示模拟值的比特越多,表示就越精确。通常比特数按 2n2^n 递增
The more bits used to represent an analog value, the more precise the representation would be!

量化将可用幅度范围分成 2N2^N 个离散级。
Quantization divides the available amplitude range into 2^N discrete levels.

位深越大,数字化版本中幅度变化可以越细微,但文件大小也随位深增加而增加。
The larger the bit depth, the more subtle the amplitude changes can be in a digitized version, but the file size also increases as the bit depth increases.

量化步长(Δ)是相邻级之间的距离。
The quantization step size (Δ) is the distance between adjacent levels.

量化步长公式 Quantization step size

Δ=vmax−vmin2N\begin{array}{rcl} \Delta=\cfrac{v_{max}-v_{min}}{2^N} \end{array}

例如,假如是2-bit 量化,我们就能分出4个level

LevelAmpliutude rangeQuantized value2-bit code30.5∼1.0+0.751120∼0.5+0.25101−0.5∼0−0.25010−1∼−0.5−0.7500\begin{array}{c|c|c|c} \hline \text{Level} & \text{Ampliutude range} & \text{Quantized value}&\text{2-bit code} \\ \hline 3 & 0.5\sim1.0 & +0.75&11 \\ 2 & 0\sim0.5 & +0.25 &10\\ 1 & -0.5\sim0 & -0.25&01\\ 0 & -1\sim-0.5 & -0.75&00 \\ \hline \end{array}

采样与量化的比较

对比项采样量化做什么把连续时间信号切成离散时刻把每个样点的幅度映到有限个电平控制参数采样率 fs(单位 Hz)位深 N(单位 bit)决定什么时间分辨率、可表示的频率范围幅度分辨率、量化误差损失丢失时间细节;可能混叠幅度误差更大;量化噪声常见取值8 kHz 或 44.1 kHz8-bit 或 16-bit\begin{array}{c|c|c} \hline \text{对比项} & \text{采样} & \text{量化} \\ \hline \text{做什么} & \text{把连续时间信号切成离散时刻} & \text{把每个样点的幅度映到有限个电平} \\ \hline \text{控制参数} & \text{采样率 }f_s\text{(单位 Hz)} & \text{位深 }N\text{(单位 bit)} \\ \hline \text{决定什么} & \text{时间分辨率、可表示的频率范围} & \text{幅度分辨率、量化误差} \\ \hline \text{损失} & \text{丢失时间细节;可能混叠} & \text{幅度误差更大;量化噪声} \\ \hline \text{常见取值} & \text{8 kHz 或 44.1 kHz} & \text{8-bit 或 16-bit} \\ \hline \end{array}


量化误差 Quantization Error

量化误差公式

eq[n]=x[n]−xq[n]\begin{array}{rcl} e_q[n]=x[n]−x_q[n] \end{array}

其中:

  • x[n]x[n] 是原始采样值 original sampled value
  • xq[n]x_q[n] 是量化值 quantized value
  • eq[n]e_q[n] 是量化误差 quantization error

例如对于一个2-bit 量化器,实际模拟信号在某采样瞬间幅度为 0.40 V,它会被表示为 0.25 V。因此量化误差为 0.40 V – 0.25 V = 0.15 V


量化与信噪比 Quantization and SNR

信噪比是正确(纯)信号功率与量化过程添加噪声之比,以分贝(dB)测量。
The signal-to-noise ratio is the ratio of the power of the correct (pure) signal to the noise added by the quantization process, which measured in decibels (dB).

SNR=PsignalPnoise=μσ\begin{array}{rcl} SNR =\dfrac {P_{signal}}{P_{noise}}=\dfrac{\mu}{\sigma} \end{array}

对于理想满量程正弦输入和均匀 N-bit 量化器,理论量化 SNR 约为 6.02Nbits+1.76dB6.02N_{bits} + 1.76 dB。
For an ideal full-scale sinusoidal input and a uniform N-bit quantizer, the theoretical quantization SNR is approximately 6.02Nbits+1.76dB6.02N_{bits} + 1.76 dB.


动态范围 Dynamic Range

动态范围是在给定位深下可表示的音频信号最大幅度与最小幅度之比。
Dynamic range is the ratio between the largest amplitude and the smallest amplitude of the audio signal that can be represented with a given bit depth.

DRdb=20log10⁡(AmaxAmin)\begin{array}{rcl} DR_{db}=20\log_{10}(\cfrac{A_{max}}{A_{min}}) \end{array}

简单来说,就是最响亮与最轻柔部分(dB)之间的差值。


压缩 Compression

为什么需要压缩?

  • 数字音频可能需要大量存储空间和传输带宽。Digital audio can require substantial storage space and transmission bandwidth.
  • 更高采样率、更大位深和更多声道会增加数据需求。Higher sampling rates, greater bit depths, and more channels increase data requirements.
  • 好处包括减少存储、降低带宽需求和更高效的流媒体。Benefits include reduced storage, lower bandwidth requirements, and more efficient streaming.

压缩方法:有损 lossy 和无损 lossless


未压缩音频格式 Uncompressed audio format

如果你需要以不危及音乐质量的方式分享音乐,使用未压缩音频格式。
if you need to share your music in a way that doesn’t jeopardize the quality of your music in any way, use an uncompressed audio format.

  • 优点:录音室音频质量不受妥协。
    PROS: Studio audio quality without compromise
  • 缺点:文件大,数字分享或邮件发送可能麻烦。
    CONS: Large File Size that can be troublesome when trying to share digitally or via email

WAV 和 AIFF 将是你最好的朋友。(PS:😄)

WAV

WAV 文件可使用未压缩的脉冲编码调制(PCM) 存储音频,保留编码样本值而不会因压缩丢失信息。
High-quality audio: WAV files can store audio using uncompressed PCM, preserving the encoded sample values without compression-related information loss.


AIFF

常见 AIFF 文件使用可配置采样率和位深存储未压缩的 PCM 音频,不会因此压缩丢失信息。
Common AIFF files store uncompressed PCM audio using configurable sampling rates and bit depths without compression-related information loss.


比较:WAV和AIFF

当包含相同 PCM 音频数据且采样率和位深匹配时,WAV 和 AIFF 可提供相同音频质量。
WAV and AIFF can deliver identical audio quality when they contain the same PCM audio data with matching sample rates and bit depths.

WAV 广泛用于 Windows 工作流,而 AIFF 与 Apple 和 Mac 工作流有历史关联。
Platform preference: WAV is widely used in Windows-based workflows, while AIFF has historical associations with Apple and Mac-based workflows.


压缩音频格式 Compressed audio format

如果你的意图是轻松快速分享音乐,选择压缩音频格式以获得小文件。
if your intent is to make sharing your music easy and fast, choose a compressed audio format that will provide you with small file size.

  • 优点:文件小,非常适合通过邮件、直接消息发送或存储在移动设备上。
    PROS: Small file size, perfect for sending via email, direct messages, or storing on mobile devices
  • 缺点:为获得更小文件,音频质量被妥协;文件越小,音质越差。
    CONS: To achieve smaller files, audio quality is compromised. The smaller the file, the worse the audio quality will be.

对于所有这些情况,选择压缩音频格式如 MP3 或 M4A。(PS:怎么不是最好的朋友了😄)


MP3 – 压缩且有损 Compressed and Lossy

MP3 通过丢弃感知上不太重要的选定音频信息来减小文件大小。
MP3 reduces file size by discarding selected audio information that is less perceptually important.

处理流程:

  • 输入音频信号:PCM 音频样本。
    Input Audio Signal; PCM audio samples
  • 滤波器组:将音频分成频率子带。
    Filter Bank; Divides audio into frequency subbands
  • MDCT 变换:将子带样本转换为频率系数。
    MDCT Transformation; Converts subband samples into frequency coefficients
  • 心理声学模型:确定感知上不太重要的音频信息。
    Psychoacoustic Model; Determines perceptually less important audio information
  • 量化:降低音频系数精度。
    Quantization; Reduces precision of audio coefficients
  • Huffman 编码:高效编码量化数据。
    Huffman Encoding; Encodes quantized data efficiently
  • MP3 比特流:压缩后的 MP3 文件。
    MP3 Bitstream; Compressed MP3 file


M4A – 压缩且有损 Compressed and Lossy

M4A 文件通常包含使用高级音频编码(AAC)编码的音频,这是一种有损压缩方法。
Audio encoding: M4A files commonly contain audio encoded using Advanced Audio Coding (AAC), a lossy compression method.

在可比比特率下,AAC 通常能提供比 MP3 更好的感知音频质量,尽管结果取决于编码器、比特率和音频内容。
AAC can often deliver better perceived audio quality than MP3 at comparable bitrates, although results depend on the encoder, bitrate, and audio content.

更小文件大小:有损 AAC 压缩减少存储和传输音频所需数据量。
Smaller file sizes: Lossy AAC compression reduces the amount of data needed to store and transmit audio.

MP3 仍有特别广泛的传统兼容性,而 M4A 支持取决于设备、软件和文件中包含的编解码器。
Limitations: MP3 still has particularly broad legacy compatibility, while M4A support depends on the device, software, and codec contained in the file.

对比项MP3M4A(AAC)设备兼容性现代电脑、手机、播放器普遍支持现代电脑、手机、播放器普遍支持旧设备、旧软件和音频系统更广旧设备上不如 MP3 普遍音频质量可比比特率下感知质量通常不如 AAC可比比特率下感知质量往往更好文件大小有损压缩;同等听感下文件往往更大有损压缩;同等听感下文件可能更小突出优势对旧设备与旧系统的兼容性特别广压缩更高效,同比特率下质量可能更好实际选择优先考虑广泛兼容时选 MP3要高效压缩、给定比特率下更好听感时选\begin{array}{c|c|c} \hline \text{对比项} & \text{MP3} & \text{M4A(AAC)} \\ \hline \text{设备兼容性} & \text{现代电脑、手机、播放器普遍支持} & \text{现代电脑、手机、播放器普遍支持} \\ & \text{旧设备、旧软件和音频系统更广} & \text{旧设备上不如 MP3 普遍} \\ \hline \text{音频质量} & \text{可比比特率下感知质量通常不如 AAC} & \text{可比比特率下感知质量往往更好} \\ \hline \text{文件大小} & \text{有损压缩;同等听感下文件往往更大} & \text{有损压缩;同等听感下文件可能更小} \\ \hline \text{突出优势} & \text{对旧设备与旧系统的兼容性特别广} & \text{压缩更高效,同比特率下质量可能更好} \\ \hline \text{实际选择} & \text{优先考虑广泛兼容时选 MP3} & \text{要高效压缩、给定比特率下更好听感时选} \\ \hline \end{array}


FLAC – 无损压缩 Lossless compression

FLAC 减小音频文件大小,同时保留所有原始数字音频数据,允许比特完美重建。
FLAC reduces audio file size while preserving all original digital audio data, allowing bit-perfect reconstruction.

FLAC 精确保留原始编码音频样本,适合归档、高质量播放和音频分发。
FLAC preserves the original encoded audio samples exactly, making it suitable for archiving, high-quality playback, and audio distribution.

对比项MP3FLAC压缩方式有损:永久丢弃部分音频信息以减小体积无损:不丢失原始数字样本;可精确重建原理用心理声学/听觉模型去掉感知上不太重要的信息压缩的是数据本身,不靠扔掉听感信息听感与伪影低比特率或压得过狠时伪影明显;无有损压缩伪影高频、钹、混响、复杂乐段可能刺耳或失真文件大小通常更小(取决于比特率)通常比 MP3 大,比未压缩 PCM 小高分辨率受有损编码与比特率限制支持不同采样率、位深,含 24-bit/192 kHz\begin{array}{c|c|c} \hline \text{对比项} & \text{MP3} & \text{FLAC} \\ \hline \text{压缩方式} & \text{有损:永久丢弃部分音频信息以减小体积} & \text{无损:不丢失原始数字样本;可精确重建}\\ \hline \text{原理} & \text{用心理声学/听觉模型去掉感知上不太重要的信息} & \text{压缩的是数据本身,不靠扔掉听感信息} \\ \hline \text{听感与伪影} & \text{低比特率或压得过狠时伪影明显;} & \text{无有损压缩伪影} \\ & \text{高频、钹、混响、复杂乐段可能刺耳或失真} & \\ \hline \text{文件大小} & \text{通常更小(取决于比特率)} & \text{通常比 MP3 大,比未压缩 PCM 小} \\ \hline \text{高分辨率} & \text{受有损编码与比特率限制} & \text{支持不同采样率、位深,含 24-bit/192 kHz} \\ \hline \end{array}

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!