edith
Clone
https://git.tahinli.com/Tahinli/edith.git
0 watching0 forksRust18.3 MiBff99ad6Tahinli6 days ago1055 commits
| 1 | //! `AudioSession::open_at` must produce exactly the tail of a full run: same |
| 2 | //! samples, same absolute `start_sample` numbering, no gaps at the splice. |
| 3 | |
| 4 | use PathBuf; |
| 5 | |
| 6 | use ; |
| 7 | |
| 8 | const RATE: u32 = 44100; |
| 9 | const CHANNELS: usize = 2; |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | /// Drains a session into one flat interleaved buffer, checking as it goes that |
| 18 | /// chunks are contiguous and that the first one lands on `want_start`. |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | /// Largest per-sample difference, and where it is. |
| 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 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | /// The seek lands on the second it was asked for, in *content*, ten and twenty |
| 114 | /// seconds into a file that has a cue table. |
| 115 | /// |
| 116 | /// That is not what one symphonia seek gives on a Matroska file: it goes |
| 117 | /// through the cues and lands on the first frame at or past the *cluster* the |
| 118 | /// cue names, which on this fixture is up to 4.99 s later than the request |
| 119 | /// (asking 25.0 s landed the reader at 29.987 s) and on a 5.1 Opus film was |
| 120 | /// 1.47 s at 600 s and 3.39 s at 610 s. Nothing downstream can recover samples |
| 121 | /// the reader is already past, so the film simply played from there while the |
| 122 | /// timeline said otherwise -- sound against picture, after every scrub. |
| 123 | /// |
| 124 | /// The chirp is what makes that measurable without a reference decode: 200 Hz |
| 125 | /// rising 160 Hz a second, so the frequency of a quarter second of audio names |
| 126 | /// the second of the file it was cut from. |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | /// ...and the *second* segment of one session lands too. Two clips of one file |
| 142 | /// is two seeks on one reader, which is where symphonia's mkv reader gives up |
| 143 | /// altogether: it hands out the frames left over from the first landing and |
| 144 | /// then reads on from wherever its iterator ended up -- measured on a film as |
| 145 | /// the second seek playing the *first cluster* of it, 0.094 s in, whatever it |
| 146 | /// was asked for. |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 | /// Where in `test_seek_chirp.mkv` a stream of samples was cut from, by the |
| 167 | /// frequency of its first quarter second: the chirp starts at 200 Hz and rises |
| 168 | /// 160 Hz a second, and zero crossings date it without a reference decode. |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | /// A real film, which is where the desync was measured and where the fixture |
| 184 | /// cannot follow: a 5 GB AV1 remux with a 5.1 Opus track and a cue table, seeked |
| 185 | /// to three seconds spread across two hours and correlated against ffmpeg's |
| 186 | /// decode of the same window. |
| 187 | /// |
| 188 | /// The chirp fixture above proves the rule on 30 seconds of one cluster layout. |
| 189 | /// This proves it where it broke: `fix(audio): a seek into a Matroska lands on |
| 190 | /// the second it asked for` measured +1.473 s at 600 s and +3.394 s at 610 s on |
| 191 | /// this file and left no runnable check behind it, so a regression would come |
| 192 | /// back the way the original did -- through the ears, after a scrub. |
| 193 | /// |
| 194 | /// Skipped, not failed, without the film or without ffmpeg: a claim about a |
| 195 | /// library cannot be made by a machine that does not have it. |
| 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 | /// The 5.1 **AAC** film: the multichannel seat `ec-aac` took over from |
| 260 | /// `rusty_aac`, exercised on the kind of track it exists for -- a BluRay |
| 261 | /// remux's 48 kHz AAC-LC 5.1, decoded, folded to the pair the timeline |
| 262 | /// carries, seeked across the film, and correlated against ffmpeg's own decode |
| 263 | /// of the same window. A wrong channel order, a wrong rate, or a fold that |
| 264 | /// lost a side all move the correlation; a seat that refuses the track fails |
| 265 | /// the open. |
| 266 | /// |
| 267 | /// Skipped, not failed, where the film or ffmpeg is not -- it is a 4K remux |
| 268 | /// named by the local `real_library.toml`, not a fixture in this repository. |
| 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 | /// `dur` seconds of `path`'s first audio track from `start`, decoded by ffmpeg, |
| 329 | /// summed to mono at `rate`. The reference this engine's own landing is measured |
| 330 | /// against, because a decoder cannot be its own witness about where it landed. |
| 331 | |
| 332 | |
| 333 | |
| 334 | |
| 335 | |
| 336 | |
| 337 | |
| 338 | |
| 339 | |
| 340 | |
| 341 | |
| 342 | |
| 343 | |
| 344 | |
| 345 | |
| 346 | |
| 347 | |
| 348 | |
| 349 | |
| 350 | |
| 351 | /// Where in `reference` the `probe` sits, and how well: the offset in samples of |
| 352 | /// the best normalised cross-correlation, which is 1.0 for the same content and |
| 353 | /// falls away fast for anything else. |
| 354 | /// |
| 355 | /// Coarse then fine, because the naive product over a ten-second window at |
| 356 | /// 48 kHz is 3e10 multiplies: both signals are averaged down by [`DECIMATE`] |
| 357 | /// first -- a crude low-pass, and the peak of a correlation is broad -- then the |
| 358 | /// winner is refined at full rate over the one block around it. The normalisation |
| 359 | /// is what makes the two comparable at all, since this fold is 7.7 dB quieter |
| 360 | /// than ffmpeg's. |
| 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 | /// The best normalised cross-correlation of `probe` over `reference`, at `step` |
| 386 | /// samples: `(score, offset)`. Both are mean-removed; the denominator is each |
| 387 | /// window's own energy, so a level difference between the two decoders cannot |
| 388 | /// move the peak. |
| 389 | |
| 390 | |
| 391 | |
| 392 | |
| 393 | |
| 394 | |
| 395 | |
| 396 | |
| 397 | |
| 398 | |
| 399 | |
| 400 | |
| 401 | |
| 402 | |
| 403 | |
| 404 | |
| 405 | |
| 406 | |
| 407 | |
| 408 | |
| 409 | |
| 410 | |
| 411 | |
| 412 | |
| 413 | |
| 414 | |
| 415 | |
| 416 | |
| 417 | |
| 418 | |
| 419 | |
| 420 | |
| 421 | |
| 422 |