edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching0 forksRust370.3 MiB231663eTahinli3 months ago1475 commits
| 1 | #!/usr/bin/env python3 |
| 2 | """Black-box derivation of the ISO/IEC 14496-3 AAC-LC Huffman codebooks. |
| 3 | |
| 4 | Clean-room: no AAC implementation source is read. The only oracle is ffmpeg's |
| 5 | `aac` decoder driven as a black box. We synthesise ADTS frames whose spectral |
| 6 | payload is a bit string we choose, decode them, invert the (windowed) MDCT to |
| 7 | recover the quantised spectrum, and learn the prefix code from bits -> tuple. |
| 8 | |
| 9 | Frame shape (mono, 48 kHz, ONLY_LONG, sine window): |
| 10 | SCE(3)=0 tag(4)=0 global_gain(8) ics_info section_data sf_data flags spectral |
| 11 | max_sfb=2 gives one section of 8 coefficients, so the spectral field always |
| 12 | outlives the probe prefix and the trailing all-ones run lands on an END element |
| 13 | (id 7 = 0b111). The ones run is bounded -- a long 0xFF tail makes ffmpeg's ADTS |
| 14 | parser resync on a false 0xFFF sync word. |
| 15 | """ |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | = 48000 |
| 22 | = 1024 |
| 23 | = 96 # bits of `1` filler after the probe, then zero padding |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | = |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | return |
| 34 | |
| 35 | |
| 36 | |
| 37 | return |
| 38 | |
| 39 | |
| 40 | return |
| 41 | |
| 42 | |
| 43 | |
| 44 | = // 8 |
| 45 | = |
| 46 | = |
| 47 | |
| 48 | = 0 |
| 49 | |
| 50 | = | |
| 51 | |
| 52 | return |
| 53 | |
| 54 | |
| 55 | |
| 56 | = |
| 57 | # sync, MPEG-4, layer, no CRC |
| 58 | # AAC-LC |
| 59 | # original, home, copyright id/start |
| 60 | |
| 61 | return + |
| 62 | |
| 63 | |
| 64 | |
| 65 | = |
| 66 | # SCE, instance tag |
| 67 | |
| 68 | # ONLY_LONG, sine window |
| 69 | # one section covering every band |
| 70 | |
| 71 | # pulse / tns / gain-control absent |
| 72 | |
| 73 | return |
| 74 | |
| 75 | |
| 76 | |
| 77 | = |
| 78 | |
| 79 | # max_sfb = 0: nothing coded |
| 80 | # flags, END |
| 81 | return |
| 82 | |
| 83 | |
| 84 | # --- MDCT read-back --------------------------------------------------------- |
| 85 | |
| 86 | = None |
| 87 | |
| 88 | |
| 89 | |
| 90 | """Quantised-spectrum-proportional coefficients from 2048 output samples.""" |
| 91 | global _PINV |
| 92 | |
| 93 | = |
| 94 | |
| 95 | = |
| 96 | |
| 97 | = |
| 98 | = |
| 99 | = |
| 100 | = |
| 101 | = |
| 102 | |
| 103 | return @ |
| 104 | |
| 105 | |
| 106 | |
| 107 | """One 2048-sample block per probe frame, or None when ffmpeg refused it.""" |
| 108 | = |
| 109 | = |
| 110 | = |
| 111 | |
| 112 | |
| 113 | = |
| 114 | |
| 115 | |
| 116 | |
| 117 | = |
| 118 | = // |
| 119 | = |
| 120 | |
| 121 | |
| 122 | return None, |
| 123 | return , |
| 124 | |
| 125 | |
| 126 | |
| 127 | = |
| 128 | , = |
| 129 | |
| 130 | |
| 131 | |
| 132 |