edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching0 forksRust370.3 MiB86fb0f3Tahinli7 days ago3927 commits
| 1 | //! DTS core sync words, stream word order conversion and the core frame |
| 2 | //! header (ETSI TS 102 114 section 5.3.1). |
| 3 | //! |
| 4 | //! [`parse_frame_header`] is the stable entry point for raw `.dts` sniffing: |
| 5 | //! it accepts any of the four stream layouts (16-bit big or little endian, |
| 6 | //! 14-bit big or little endian) and states the frame size, sample rate, |
| 7 | //! channel count and samples per frame without decoding any audio. |
| 8 | |
| 9 | use crateBits; |
| 10 | use ; |
| 11 | |
| 12 | /// Core sync word as it reads in canonical (16-bit, big-endian) order. |
| 13 | pub const SYNC_CORE: u32 = 0x7FFE_8001; |
| 14 | /// Core sync word in 16-bit little-endian word order. |
| 15 | pub const SYNC_CORE_LE: u32 = 0xFE7F_0180; |
| 16 | /// Core sync word in 14-bit-in-16, big-endian word order. |
| 17 | pub const SYNC_CORE_14_BE: u32 = 0x1FFF_E800; |
| 18 | /// Core sync word in 14-bit-in-16, little-endian word order. |
| 19 | pub const SYNC_CORE_14_LE: u32 = 0xFF1F_00E8; |
| 20 | /// DTS-HD extension substream sync word. |
| 21 | pub const SYNC_EXSS: u32 = 0x6458_2025; |
| 22 | |
| 23 | /// How the stream stores the canonical bit string. |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | /// Convert stream words to the canonical big-endian packed bit string. |
| 51 | /// |
| 52 | /// `data` starts at a core sync word. The output is appended to `out`. |
| 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 | /// Sample rate by `SFREQ` (Table 5-5); 0 marks a code the core does not use. |
| 95 | pub const SAMPLE_RATES: = |
| 96 | |
| 97 | ; |
| 98 | |
| 99 | /// Transmission bit rate by `RATE` (Table 5-7). The last three codes are |
| 100 | /// open (1), variable (2) and lossless (3) and carry no nominal rate. |
| 101 | pub const BIT_RATES: = |
| 102 | |
| 103 | |
| 104 | |
| 105 | ; |
| 106 | |
| 107 | /// Primary channels by `AMODE` (Table 5-4). |
| 108 | pub const CHANNELS: = ; |
| 109 | |
| 110 | /// Source PCM resolution by `PCMR` (Table 5-10); 0 marks a reserved code. |
| 111 | pub const PCM_RESOLUTION: = ; |
| 112 | |
| 113 | /// Everything the core frame header states. |
| 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 | /// Parse the core frame header at the start of `data`. |
| 181 | /// |
| 182 | /// `data` starts at a core sync word in any of the four stream layouts. A |
| 183 | /// short buffer is [`Error::NeedMore`]; anything that is not a valid core |
| 184 | /// frame header is [`Error::Corrupt`], which makes this usable as an "is this |
| 185 | /// DTS?" probe. Only the header is read, so a frame does not have to be |
| 186 | /// complete: the frame size is a statement about the frame to come. |
| 187 | |
| 188 | |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | pub |
| 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 | /// Length in bytes of the core frame starting at `data[0]`, as stored in the |
| 310 | /// stream (so 14-bit streams answer with the larger stored size). |
| 311 | |
| 312 | |
| 313 | |
| 314 | |
| 315 | /// Find the first core sync word in `data` and its stream layout. |
| 316 | |
| 317 | |
| 318 |