edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching0 forksRust370.3 MiB5a2f5efTahinli3 months ago1409 commits
| 1 | //! Drop-in replacement for the `rusty_vorbis` 0.1.1 surface the replica |
| 2 | //! consumes, implemented over [`ec_vorbis`]. |
| 3 | //! |
| 4 | //! It carries the incumbent's package name and version so the swap is a |
| 5 | //! `[patch.crates-io]` entry and nothing else. The scope is the API |
| 6 | //! `engine/src/export.rs` calls (`export.rs:2850-2862`): |
| 7 | //! |
| 8 | //! ```no_run |
| 9 | //! let mut encoder = rusty_vorbis::VorbisEncoder::new(rusty_vorbis::VorbisEncoderConfig { |
| 10 | //! bitrate_bps: rusty_vorbis::BITRATE_NOMINAL, |
| 11 | //! quality: 0.85, |
| 12 | //! }); |
| 13 | //! encoder.push_pcm_s16(&[0i16; 2048], 2, 48_000).unwrap(); |
| 14 | //! encoder.finish(); |
| 15 | //! loop { |
| 16 | //! match encoder.next_packet() { |
| 17 | //! Ok(packet) => { let _ = (&packet.data, packet.pts, packet.duration); } |
| 18 | //! Err(rusty_vorbis::Error::Eof) => break, |
| 19 | //! Err(e) => panic!("{e}"), |
| 20 | //! } |
| 21 | //! } |
| 22 | //! ``` |
| 23 | //! |
| 24 | //! Two of the incumbent's behaviours are deliberately *not* reproduced, because |
| 25 | //! they are the defects this replacement exists to remove — both are corrections |
| 26 | //! the replica currently applies by hand at `export.rs:2762-2815` and can delete: |
| 27 | //! |
| 28 | //! * **No pre-roll hop.** The incumbent's first audio packet advanced the |
| 29 | //! granule by a full block hop while decoding to nothing, so every caller had |
| 30 | //! to feed a hop of silence and subtract a hop from every granule. Here the |
| 31 | //! first block is centred on input sample 0 and [`EncodedPacket::pts`] is the |
| 32 | //! true granule, so a caller writes what it is given. |
| 33 | //! * **No stereo-only setup header.** The incumbent shipped one embedded stereo |
| 34 | //! profile and refused mono ("bad coupling channels") and anything wider. Here |
| 35 | //! the setup header is written per stream for whatever channel count is |
| 36 | //! pushed, so mono stays mono and 5.1 stays 5.1. |
| 37 | //! |
| 38 | //! The last packet's `pts` is the input's own sample count, so a file decodes to |
| 39 | //! exactly as many samples as went in; the caller does not have to state the |
| 40 | //! tail granule itself either. |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | use Error as EcError; |
| 46 | use ; |
| 47 | |
| 48 | /// Short block size, as a power of two, that this encoder states. |
| 49 | pub const BS0_LOG2: u8 = 11; |
| 50 | /// Long block size, as a power of two. |
| 51 | pub const BS1_LOG2: u8 = 11; |
| 52 | /// The nominal bitrate the replica asks for. |
| 53 | pub const BITRATE_NOMINAL: i32 = 128_000; |
| 54 | |
| 55 | /// Errors this encoder can answer. |
| 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 | /// This crate's result type. |
| 97 | pub type Result<T> = Result; |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | /// One packet out of the encoder. |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | /// How the encoder is set up. |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | /// The incumbent's `[0, 1]` quality scale from Vorbis's own `-q` scale. |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | /// Vorbis encoder over [`ec_vorbis`]. |
| 145 | /// |
| 146 | /// Channel count and sample rate arrive with the first push, exactly as they do |
| 147 | /// in the incumbent, so the encoder is built lazily and the setup header is |
| 148 | /// written for the layout that actually turns up. |
| 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 |