edith
Clone
https://git.tahinli.com/Tahinli/edith.git
0 watching0 forksRust18.3 MiBff99ad6Tahinli6 days ago1055 commits
| 1 | //! The per-clip equalizer where it has to be true: in the samples playback |
| 2 | //! feeds the device and in the samples an export writes, which are the same |
| 3 | //! samples by construction — both come off `AudioSession::open_mixed_streams_eq` |
| 4 | //! and the filter runs inside the per-lane worker, per segment, before the mix. |
| 5 | //! |
| 6 | //! Everything here goes through the *front door*: a `Project` is edited with |
| 7 | //! `set_eq` and then read exactly as `PlaybackSession::seek` reads it |
| 8 | //! (`audio_segments_from` + `audio_eqs_from` handed to the same opener), or |
| 9 | //! exported through `engine::export::start`. Nothing calls `EqState` directly — |
| 10 | //! `eq.rs`'s own unit tests own the filter maths; what is checked here is the |
| 11 | //! wiring: that a curve reaches its clip, only its clip, and reaches it the same |
| 12 | //! way in both directions. |
| 13 | //! |
| 14 | //! The fixtures are a 440 Hz / 880 Hz stereo tone (`gen_fixtures.sh`), so a low |
| 15 | //! shelf with its corner above both tones is a flat +12 dB on everything |
| 16 | //! audible: the expected RMS ratio is 10^(12/20) ≈ 3.98, and it is asserted as a |
| 17 | //! ratio, never as a level. |
| 18 | //! |
| 19 | //! No picture is decoded, so nothing here needs the hardware plugin. |
| 20 | |
| 21 | use ; |
| 22 | use ; |
| 23 | |
| 24 | use ; |
| 25 | use ; |
| 26 | use ; |
| 27 | use FitPolicy; |
| 28 | use Scratch; |
| 29 | use ; |
| 30 | |
| 31 | const RATE: u32 = 44_100; |
| 32 | const FPS: f64 = 30.0; |
| 33 | |
| 34 | /// +12 dB below 2 kHz: above both fixture tones, so every audible sample in |
| 35 | /// them is lifted by the shelf's full gain. |
| 36 | const BOOST_DB: f32 = 12.0; |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 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 | |
| 88 | /// One video clip and `audio` on `A1`, from `test_av.mp4` alone. |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | /// What the device would be fed: the exact call `PlaybackSession::seek` makes, |
| 105 | /// drained to the end. This *is* the feeder path minus the ring buffer. |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | /// Root mean square of `[from, to)` seconds of the interleaved stereo stream. |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | /// The shelf's own gain, to within a fifth of a dB either way -- the filter is |
| 135 | /// exact, the tone is not perfectly band-limited, and the fixtures' 1 Hz pulse |
| 136 | /// makes any window a mixture. |
| 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 | /// Samples of a written file back through the engine's own reader. |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | /// The whole claim in one line: a clip given a band comes out of the feeder |
| 181 | /// path that much louder than the same clip without it -- and a project nobody |
| 182 | /// has equalized comes out of the *new* opener bit for bit what the old one |
| 183 | /// gave, which is the identity promise the rest of the engine rests on. |
| 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 | /// The reason the filter lives in the worker and not over the mix: two clips |
| 226 | /// with different settings must not bleed into each other. One second boosted, |
| 227 | /// one second not, on one lane, out of one decoder. |
| 228 | |
| 229 | |
| 230 | |
| 231 | |
| 232 | |
| 233 | |
| 234 | |
| 235 | |
| 236 | |
| 237 | |
| 238 | |
| 239 | |
| 240 | |
| 241 | |
| 242 | |
| 243 | |
| 244 | |
| 245 | |
| 246 | |
| 247 | |
| 248 | |
| 249 | |
| 250 | /// Two lanes, a band on one of them: the sum must differ by exactly what that |
| 251 | /// lane's own samples changed by, which is only true if each lane is filtered |
| 252 | /// before it is added. Filtering the mix instead would smear the curve over the |
| 253 | /// other lane as well, and this is the difference that would show it. |
| 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 | /// The export half of the same claim, through `export::start`: what is written |
| 300 | /// is what is heard, so both audio-only formats carry the boost at the same |
| 301 | /// ratio the feeder path measured. Both, because both are lossless and both are |
| 302 | /// one `run_audio` -- a FLAC that disagreed with the WAV beside it would be the |
| 303 | /// writer, and this is where that would show. |
| 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 | /// An mp4 export *copies* AAC packets and no filter can reach a copy, so an |
| 348 | /// equalized lane is decoded, mixed and encoded again instead |
| 349 | /// (`export::encode_audio`). The claim is the same one the WAV makes: the boost |
| 350 | /// is in the file, on the clip that was given it and on no other -- and the |
| 351 | /// track still starts where the picture does, which is what the encoder's own |
| 352 | /// priming packet is for. |
| 353 | |
| 354 | |
| 355 | |
| 356 | |
| 357 | |
| 358 | |
| 359 | |
| 360 | |
| 361 | |
| 362 | |
| 363 | |
| 364 | |
| 365 | |
| 366 | |
| 367 | |
| 368 | |
| 369 | |
| 370 | |
| 371 | |
| 372 | |
| 373 | |
| 374 | |
| 375 | |
| 376 | |
| 377 | |
| 378 | |
| 379 | |
| 380 | |
| 381 | |
| 382 | |
| 383 | |
| 384 | |
| 385 | |
| 386 | |
| 387 | |
| 388 | |
| 389 | |
| 390 | |
| 391 | |
| 392 | |
| 393 | |
| 394 | |
| 395 | |
| 396 | |
| 397 | |
| 398 | |
| 399 | |
| 400 | |
| 401 | |
| 402 | |
| 403 | |
| 404 | |
| 405 | |
| 406 | |
| 407 | |
| 408 | |
| 409 | |
| 410 | |
| 411 | /// A band moved while the timeline is playing: `PlaybackSession::set_eq` writes |
| 412 | /// the project and reseeks, and a reseek rebuilds the workers from |
| 413 | /// `audio_eqs_from`. This is that mechanism without a sound device -- the edit, |
| 414 | /// then the very list the reopen is built from, then the samples it yields. |
| 415 | |
| 416 | |
| 417 | |
| 418 | |
| 419 | |
| 420 | |
| 421 | |
| 422 | |
| 423 | |
| 424 | |
| 425 | |
| 426 | |
| 427 | |
| 428 | |
| 429 | |
| 430 | |
| 431 | |
| 432 | |
| 433 | |
| 434 | |
| 435 | |
| 436 | |
| 437 | |
| 438 | |
| 439 | |
| 440 | |
| 441 | |
| 442 | |
| 443 |