edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching0 forksRust370.3 MiB42021c7Tahinli5 days ago3994 commits
| 1 | #!/usr/bin/env python3 |
| 2 | """Splice E-AC-3 dependent substreams onto an independent stream (test-fixture tool). |
| 3 | |
| 4 | usage: splice-eac3-dependent.py <independent.eac3> <dependent.eac3> <chanmap-hex> <out.eac3> <dep.convsnr.txt> |
| 5 | |
| 6 | ffmpeg's E-AC-3 encoder stops at 5.1, so a 7.1 fixture cannot be encoded directly. This |
| 7 | builds one from two ordinary encodes: each output packet is one independent syncframe |
| 8 | followed by one dependent syncframe. The dependent frame is the second stream's frame with |
| 9 | strmtyp set to 1 (dependent) and the 16-bit custom channel map (Table E2.5) inserted where |
| 10 | bsi() reads it, the one field a dependent header carries and an independent one does not. |
| 11 | The map is written bit 15 first, so 0x8000 is L and 0x0001 is LFE. |
| 12 | |
| 13 | The dependent source is an independent frame, and an independent frame carries fields a |
| 14 | dependent one does not: convexpstr in audfrm() and convsnroffste in each audblk(). Their |
| 15 | bit positions come from the table in <dep.convsnr.txt> (one "position flag" row per block, |
| 16 | six per frame, recorded by the crate's own parser from the dependent source; see |
| 17 | gen-ac3dep-fixtures.sh). Both streams must have the same frame count. |
| 18 | |
| 19 | Asserts the other preconditions: the source frames are independent, six blocks per frame, |
| 20 | no AHT, and no mixing metadata (mixmdate = 0). |
| 21 | """ |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | , = , 0 |
| 28 | |
| 29 | |
| 30 | = 0 |
| 31 | |
| 32 | = |
| 33 | = | |
| 34 | += 1 |
| 35 | return |
| 36 | |
| 37 | |
| 38 | |
| 39 | return |
| 40 | |
| 41 | |
| 42 | |
| 43 | """Pack bits to bytes, zero-padding to a whole 16-bit word (frames are even-sized).""" |
| 44 | = |
| 45 | |
| 46 | |
| 47 | = |
| 48 | |
| 49 | = 0 |
| 50 | |
| 51 | = | |
| 52 | |
| 53 | return |
| 54 | |
| 55 | |
| 56 | |
| 57 | = 0 |
| 58 | |
| 59 | assert == b, |
| 60 | = + 1 |
| 61 | *= 2 |
| 62 | yield |
| 63 | += |
| 64 | |
| 65 | |
| 66 | |
| 67 | """Bit span [start, end) of the convexpstr fields in an independent 6-block audfrm(). |
| 68 | |
| 69 | Annex E sends convexpstr (5 bits per full-bandwidth channel) in independent substreams |
| 70 | only. Walks audfrm() the way eac3.rs does, for the case the splice supports: six blocks, |
| 71 | no AHT, expstre set. |
| 72 | """ |
| 73 | = |
| 74 | , = , |
| 75 | += 2 |
| 76 | assert == 0, |
| 77 | += 2 + 8 # snroffststr, then transproce..spxattene (eight flags) |
| 78 | = * 6 |
| 79 | |
| 80 | = * 6 |
| 81 | = |
| 82 | += 1 |
| 83 | |
| 84 | = |
| 85 | += 1 |
| 86 | |
| 87 | = |
| 88 | += 1 |
| 89 | |
| 90 | = |
| 91 | |
| 92 | |
| 93 | |
| 94 | += 2 # cplexpstr |
| 95 | += 2 * # chexpstr per channel |
| 96 | |
| 97 | |
| 98 | += 5 # frmcplexpstr |
| 99 | += 5 * # frmchexpstr per channel |
| 100 | |
| 101 | += 6 # lfeexpstr per block |
| 102 | = |
| 103 | += 5 * # convexpstr, present because numblkscod == 3 |
| 104 | return , |
| 105 | |
| 106 | |
| 107 | # Full-bandwidth channels per acmod (Table 5.8). |
| 108 | = |
| 109 | |
| 110 | |
| 111 | |
| 112 | = |
| 113 | = |
| 114 | = 16 |
| 115 | assert == 0, |
| 116 | # substreamid |
| 117 | # frmsiz, rewritten below |
| 118 | = |
| 119 | |
| 120 | # fscod2 |
| 121 | = 3 |
| 122 | |
| 123 | = |
| 124 | assert == 3, |
| 125 | = |
| 126 | = |
| 127 | # bsid |
| 128 | # dialnorm |
| 129 | |
| 130 | # compr |
| 131 | |
| 132 | # dialnorm2 |
| 133 | |
| 134 | # compr2 |
| 135 | = |
| 136 | = |
| 137 | # Walk bsi() past mixmdate (asserted zero), infomdate and addbsi to audfrm(). |
| 138 | = |
| 139 | assert == 0, |
| 140 | += 1 |
| 141 | # infomdate: flag, bsmod(3), copyrightb, origbs, then mode-dependent fields |
| 142 | += 1 + 3 + 1 + 1 |
| 143 | |
| 144 | += 4 # dsurmod, dheadphonmod |
| 145 | |
| 146 | += 2 # dsurexmod |
| 147 | # mixlevel |
| 148 | += 1 + 5 + 2 + 1 |
| 149 | |
| 150 | += 1 |
| 151 | |
| 152 | |
| 153 | += 1 + 5 + 2 + 1 |
| 154 | |
| 155 | += 1 |
| 156 | |
| 157 | += 1 # sourcefscod |
| 158 | |
| 159 | += 1 |
| 160 | # addbsi |
| 161 | += 1 + 6 |
| 162 | = |
| 163 | += * 8 |
| 164 | |
| 165 | += 1 |
| 166 | = |
| 167 | , = |
| 168 | |
| 169 | # Independent-only fields to drop: convexpstr in audfrm(), and convsnroffste (a flag, plus |
| 170 | # ten bits of convsnroffst when set) at the start of each audblk()'s bit allocation. |
| 171 | = |
| 172 | |
| 173 | |
| 174 | |
| 175 | = + + # strmtyp = 1, substreamid kept |
| 176 | += + # chanmap present |
| 177 | = |
| 178 | |
| 179 | += |
| 180 | = |
| 181 | += |
| 182 | = |
| 183 | = // 2 - 1 |
| 184 | assert < 2048, |
| 185 | = |
| 186 | return |
| 187 | |
| 188 | |
| 189 | |
| 190 | """Per-frame lists of (bit position, flag) for convsnroffste, six blocks per frame.""" |
| 191 | |
| 192 | = |
| 193 | assert == 6 * , |
| 194 | return |
| 195 | |
| 196 | |
| 197 | |
| 198 | , , , , = |
| 199 | = |
| 200 | |
| 201 | = |
| 202 | |
| 203 | = |
| 204 | assert == , f |
| 205 | = |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 |