edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching0 forksRust370.3 MiBe63caffTahinli3 months ago103 commits
| 1 | //! The one set of transforms every edith_codecs audio and video coder uses. |
| 2 | //! |
| 3 | //! AAC, Vorbis, Opus/CELT, MP3 and the JPEG-class video paths all reduce to the |
| 4 | //! same three kernels, so they live here once: a power-of-two complex [`Fft`] |
| 5 | //! (with a real-input wrapper), the DCT family built on top of it, and |
| 6 | //! [`Mdct`] — the lapped transform those codecs actually call — routed through |
| 7 | //! an `N/4`-point FFT. |
| 8 | //! |
| 9 | //! Contracts worth knowing before implementing against this crate: |
| 10 | //! |
| 11 | //! - **The FFT is never optional.** There is no feature flag, no fallback, no |
| 12 | //! `O(n²)` path anywhere: a codec that links this crate gets the fast |
| 13 | //! transform or does not compile. Two incumbent crates shipped an `O(n²)` |
| 14 | //! transform behind a default-off feature and ran 40x slower than the |
| 15 | //! product needed; that failure mode is designed out rather than tested for. |
| 16 | //! - **Plans own their scratch.** [`Fft`], [`Dct`], [`Dct4`] and [`Mdct`] are |
| 17 | //! built once per size and then reused; the transform methods take `&mut |
| 18 | //! self` and allocate nothing. Clone a plan to use it from another thread. |
| 19 | //! - **Sizes are checked at construction, not per call.** A bad size is API |
| 20 | //! misuse and panics in the constructor; the hot path has no error branch. |
| 21 | //! - **`f32` and `f64` are the same code.** Twiddles are always computed in |
| 22 | //! `f64` and rounded once, so the `f32` plans keep the accuracy their table |
| 23 | //! allows. |
| 24 | //! - **Inverses are scaled.** [`Fft::inverse`] divides by `n`, so a forward |
| 25 | //! followed by an inverse returns the input. [`Mdct`] follows the usual |
| 26 | //! codec convention (`2/N` on the inverse) and reconstructs exactly under |
| 27 | //! overlap-add with any Princen-Bradley window from [`window`]. |
| 28 | //! |
| 29 | //! [`remap`] sits beside them for the same reason: it is the pixel arithmetic an |
| 30 | //! encode does when a clip's YUV matrix is not the one the output declares, and |
| 31 | //! it belongs with the transforms rather than in a container crate. |
| 32 | //! |
| 33 | //! Hot loops are vectorised with the `wide` crate through [`Real`]; the scalar |
| 34 | //! and SIMD paths are the same expressions over the same data layout, so |
| 35 | //! neither can drift from the other in correctness. |
| 36 | //! |
| 37 | //! No unsafe, no allocation on the transform path, and no dependencies beyond |
| 38 | //! `wide` and the family IR. |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | pub use ; |
| 50 | pub use ; |
| 51 | pub use Mdct; |
| 52 | pub use remap; |
| 53 | pub use Window; |
| 54 | |
| 55 | use Debug; |
| 56 | use ; |
| 57 | |
| 58 | /// The sample types the transforms are generic over: `f32` and `f64`. |
| 59 | /// |
| 60 | /// The trait exists to give one implementation of each transform for both |
| 61 | /// precisions *including* its SIMD form: [`Real::Lanes`] is the widest `wide` |
| 62 | /// vector for the type, and the kernels fall back to scalar code on the |
| 63 | /// remainder of a row. Implementing it for anything else is not supported — |
| 64 | /// the transforms assume IEEE-754 binary arithmetic. |
| 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 | |
| 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 | /// Multiplies `data` by `factor` in place, vectorised. |
| 187 | pub |
| 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 |