edith
Clone
https://git.tahinli.com/Tahinli/edith.git
0 watching0 forksRust18.3 MiBb8aec29Tahinli2 months ago966 commits
| 1 | //! The master limiter: one ceiling the whole mix is held under, applied where |
| 2 | //! the lanes are summed and nowhere else ([`crate::audio::mix`]). |
| 3 | //! |
| 4 | //! A mix is an add, and two lanes at full scale add past full scale: what used |
| 5 | //! to happen there was a hard `clamp`, which is a squared-off waveform and the |
| 6 | //! worst-sounding thing an editor can do to a hot timeline. This holds the sum |
| 7 | //! down *before* it reaches the clamp instead, and the clamp stays behind it as |
| 8 | //! the backstop it always was. |
| 9 | //! |
| 10 | //! Per sample, no FFT, no allocation while it runs: |
| 11 | //! |
| 12 | //! * **Lookahead.** The mix is written into a delay line [`LOOKAHEAD_MS`] long |
| 13 | //! and read out of it that much later, so the gain a peak needs is already in |
| 14 | //! force by the time the peak itself is emitted. No attack overshoot -- the |
| 15 | //! first sample over the ceiling is the first sample held under it, which is |
| 16 | //! what makes the peak of an exported file a *measurement* and not a hope. |
| 17 | //! * **Linked channels.** One gain for the frame, off the loudest channel in |
| 18 | //! it: a per-channel gain would move the stereo image every time one side |
| 19 | //! peaked. |
| 20 | //! * **Soft knee.** [`KNEE_DB`] wide and centred on the ceiling, so the gain |
| 21 | //! comes in gradually instead of switching on at one sample and off at the |
| 22 | //! next. The knee's own curve never lets the output past the ceiling (at the |
| 23 | //! centre it is already `KNEE_DB/8` under it), which is what keeps the |
| 24 | //! guarantee a hard knee would give. |
| 25 | //! * **Release**, not a per-sample snap back: `RELEASE_MS` of exponential |
| 26 | //! recovery, so one loud transient does not pump the whole bar around it. |
| 27 | //! |
| 28 | //! The latency is *taken out again*, not paid: the first `lookahead` frames of |
| 29 | //! output -- the empty delay line -- are dropped, so what comes out is sample |
| 30 | //! aligned with what went in and the sound stays locked to the picture. What |
| 31 | //! that costs is the last couple of milliseconds of the timeline's tail, which |
| 32 | //! is the trade every lookahead limiter makes. |
| 33 | |
| 34 | /// How far ahead the gain looks. 2 ms is ~96 frames at 48 kHz: long enough to |
| 35 | /// ride a transient in smoothly, short enough that the tail it eats is nothing. |
| 36 | const LOOKAHEAD_MS: f32 = 2.0; |
| 37 | /// How wide the knee is, centred on the ceiling. |
| 38 | const KNEE_DB: f32 = 6.0; |
| 39 | /// How fast the gain comes back once the loud part is over. |
| 40 | const RELEASE_MS: f32 = 120.0; |
| 41 | |
| 42 | /// What a project's master limiter is set to: a ceiling in dBFS and whether it |
| 43 | /// is in circuit at all. Off by default -- a timeline nobody has asked to limit |
| 44 | /// mixes exactly as it always did, down to the bit. |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | /// dBFS as an amplitude. `db_to_linear(0.0)` is exactly 1.0, which is what |
| 88 | /// keeps a flat setting a bit-exact passthrough. |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | /// One running limiter: the delay line, the peak window and the gain. |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 | |
| 167 | |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | |
| 216 | |
| 217 | |
| 218 | |
| 219 | |
| 220 | |
| 221 | |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | |
| 227 | |
| 228 | |
| 229 | |
| 230 | |
| 231 | |
| 232 | |
| 233 | |
| 234 | |
| 235 | |
| 236 | |
| 237 | |
| 238 | |
| 239 | |
| 240 | |
| 241 | |
| 242 | |
| 243 | |
| 244 | |
| 245 | |
| 246 | |
| 247 | |
| 248 | |
| 249 | |
| 250 | |
| 251 | |
| 252 | |
| 253 | |
| 254 | |
| 255 | |
| 256 | |
| 257 | |
| 258 | |
| 259 | |
| 260 | |
| 261 | |
| 262 | |
| 263 | |
| 264 | |
| 265 | |
| 266 | |
| 267 | |
| 268 | |
| 269 | |
| 270 | |
| 271 | |
| 272 | |
| 273 | |
| 274 | |
| 275 | |
| 276 | |
| 277 | |
| 278 | |
| 279 | |
| 280 | |
| 281 | |
| 282 | |
| 283 | |
| 284 | |
| 285 | |
| 286 | |
| 287 | |
| 288 | |
| 289 | |
| 290 | |
| 291 | |
| 292 | |
| 293 | |
| 294 | |
| 295 | |
| 296 | |
| 297 | |
| 298 | |
| 299 | |
| 300 | |
| 301 | |
| 302 | |
| 303 | |
| 304 | |
| 305 | |
| 306 | |
| 307 | |
| 308 | |
| 309 | |
| 310 | |
| 311 | |
| 312 | |
| 313 | |
| 314 | |
| 315 | |
| 316 | |
| 317 | |
| 318 | |
| 319 | |
| 320 | |
| 321 | |
| 322 | |
| 323 | |
| 324 | |
| 325 | |
| 326 | |
| 327 | |
| 328 | |
| 329 | |
| 330 | |
| 331 | |
| 332 | |
| 333 | |
| 334 | |
| 335 | |
| 336 | |
| 337 | |
| 338 | |
| 339 | |
| 340 | |
| 341 | |
| 342 | |
| 343 | |
| 344 | |
| 345 | |
| 346 | |
| 347 | |
| 348 | |
| 349 |