edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching0 forksRust370.3 MiB8a5feaaTahinli2 months ago3162 commits
| 1 | //! MP3 — MPEG-1/2/2.5 Layer III — decoding and encoding for the edith_codecs |
| 2 | //! family. |
| 3 | //! |
| 4 | //! Three ways in, smallest first: |
| 5 | //! |
| 6 | //! - [`Mp3Reader`] over a byte stream: push bytes, take frames. It skips ID3v2 |
| 7 | //! and the Xing/gapless/VBRI header frame, resyncs over junk, and keeps the bit |
| 8 | //! reservoir across frames. |
| 9 | //! - [`Mp3Decoder`], the [`ec_core::Decoder`] contract, for a container that |
| 10 | //! hands out one Layer III frame per packet. |
| 11 | //! - [`Mp3Encoder`]: interleaved PCM in, CBR Layer III frames out, with a |
| 12 | //! Xing/Info header carrying the encoder delay and padding — so a decoder |
| 13 | //! that honours it hands back exactly the samples that went in, with no |
| 14 | //! leading or trailing silence. |
| 15 | //! |
| 16 | //! **Where the constants came from.** Layer III's Huffman code tables and its |
| 17 | //! 512-tap polyphase window are normative data no formula produces. Rather |
| 18 | //! than copy them out of an existing implementation, `scripts/mp3-tables/` |
| 19 | //! *measures* them: it writes legal frames whose main-data bits it chooses, |
| 20 | //! decodes them with the oracle, and reads the answer back through a model of the |
| 21 | //! decode chain. Every code tree is walked to a leaf, checked for a Kraft sum |
| 22 | //! of exactly 1 and for complete, duplicate-free coverage of its value grid; |
| 23 | //! the window is least-squares fitted to a residual of 1.6e-6. The measured |
| 24 | //! scalefactor band widths agreed with the published MPEG-1 layouts exactly, |
| 25 | //! which is the cross-check that the rig itself was right. |
| 26 | //! |
| 27 | //! Everything else — side info, the bit reservoir, requantisation, stereo |
| 28 | //! coupling, the block windows, the psychoacoustic model — is written from the |
| 29 | //! standards (ISO/IEC 11172-3 and 13818-3). |
| 30 | //! |
| 31 | //! Free-format streams are refused by name rather than guessed at, since their |
| 32 | //! frame length is only knowable by scanning to the next sync word. |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | pub use ; |
| 48 | pub use ; |
| 49 | pub use ; |
| 50 | |
| 51 | use ; |
| 52 | use ; |
| 53 | use ; |
| 54 | use ; |
| 55 | |
| 56 | /// The [`ec_core::Decoder`] seat for MP3: one packet is one or more Layer III |
| 57 | /// frames, which is how Matroska, MP4 and the family's own probe deliver them. |
| 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 | |
| 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 | /// Codec parameters for a Layer III stream of this shape. |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 |