mlua-pulse 0.1.0

Lua-friendly music composition and audio export bindings built on tunes and mlua
Documentation
# 响度标准化


## 你会学到什么


- 区分 peak、RMS、target dBFS 和 true peak。
- 使用导出选项统一 WAV/FLAC 响度。
- 理解 MIDI velocity gain 为什么不是音频标准化。
- 避免用标准化掩盖削波、刺耳和混音失衡。

## 适合谁读


当你觉得示例音量忽大忽小、MIDI 很小声、WAV/FLAC 太响或有爆音时读本章。

## 前置知识


- [混音]../02-sound-design/mixing.md
- [WAV、FLAC、MIDI]wav-flac-midi.md

## 心智模型


响度标准化发生在最终离线渲染后。它不会改变编曲关系,只会整体缩放输出。peak 关注最高采样点,RMS 关注整体能量,true peak ceiling 用来防止标准化后瞬态越界。

标准化像最后的电平校准,不是修音器。已经削波的轨道无法通过标准化恢复。

## 最小可运行例子


```lua
local options = {
  sample_rate = 44100,
  normalize = "rms",
  target_db = -16.0,
  true_peak_db = -1.0,
  flac_bits_per_sample = 16,
  midi_velocity_gain = 2.0,
  midi_min_velocity = 0.6,
}

song:export_wav("output/final.wav", options)
song:export_flac("output/final.flac", options)
song:export_midi("output/final.mid", options)
```

## 参数和边界


`normalize = "peak"` 把最高采样峰值对齐到 `target_db`。适合防止削波和快速草稿,但听感响度未必统一。

`normalize = "rms"` 把整体能量推向 `target_db`,再用 `true_peak_db` 限制峰值。普通示例建议 `target_db = -16.0`,温柔钢琴可用 `-18.0..-16.0`,电子示例可用 `-16.0..-15.0`,true peak 建议 `-1.0`。

MIDI 没有音频响度。`midi_velocity_gain` 范围建议 `1.5..3.0`,`midi_min_velocity` 建议 `0.45..0.7`。过高会压平动态。

## 常见陷阱


标准化后还是刺耳,说明问题在频谱或音色,不在整体响度。先降高频轨、加低通、减少 reverb/delay mix。

标准化后还是有电流声,可能是源头已经削波或事件太密。先降低轨道音量和合成器亮度。

MIDI 小声不是 `normalize` 的问题。外部 MIDI 播放器使用自己的音源,应该调 velocity 相关选项。

## 进阶用法


可以先导出 peak draft 检查瞬态,再导出 RMS final:

```lua
song:export_wav("output/draft.wav", { normalize = "peak", target_db = -1.0 })
song:export_wav("output/final.wav", { normalize = "rms", target_db = -16.0, true_peak_db = -1.0 })
```

如果作品后续还要进入 DAW 混音,目标可以更低,例如 `-18 dBFS`,true peak 留到 `-3..-1 dBFS`。如果直接分享示例,`-16 dBFS` 更容易保持一致。

## 相关章节


- [混音]../02-sound-design/mixing.md
- [故障排查]troubleshooting.md
- [Lua API]../06-reference/lua-api.md
- [Rust API]../06-reference/rust-api.md