edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching0 forksRust370.3 MiBb63bf80Tahinli6 days ago3937 commits
| 1 | #!/usr/bin/env python3 |
| 2 | """Measures the Layer II bit-allocation tables (ISO 11172-3 Table 3-B.2a..d and the |
| 3 | ISO 13818-3 LSF table) out of an oracle decoder instead of copying them from anyone. |
| 4 | |
| 5 | Method: a mono frame whose only non-zero bits are the allocation code `c` of subband |
| 6 | `s` decodes (all sample bits zero) to a constant -(L-1)/L * scalefactor in that subband, |
| 7 | L being the number of quantiser levels the code selects. Layer I's allocation is known |
| 8 | from the standard (nb = a+1 bits, L = 2^nb - 1), so a Layer I frame with allocation 14 |
| 9 | in the same subband calibrates the oracle's gain for that subband. The ratio of the two |
| 10 | steady-state energies gives L. The per-subband bit widths (nbal) were found by setting one allocation bit at a |
| 11 | time and watching where the oracle stops reacting (a constant subband input only |
| 12 | excites lines at multiples of fs/32, so adjacent subbands pair up in frequency, and the |
| 13 | run lengths of the pairs give the widths). |
| 14 | |
| 15 | Usage: measure.py > table.txt (needs ffmpeg with the mp2 decoder) |
| 16 | """ |
| 17 | |
| 18 | |
| 19 | = 12 # 2^(1-12/3) = 0.125, keeps the output clear of clipping |
| 20 | = |
| 21 | |
| 22 | |
| 23 | return |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | # (version byte1, rate idx, bitrate idx, rate Hz) giving each table in a mono stream |
| 32 | = |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | , , , = |
| 42 | = |
| 43 | return 144 * * 1000 // |
| 44 | |
| 45 | |
| 46 | = ; = 0 |
| 47 | |
| 48 | |
| 49 | |= 0x80 >> |
| 50 | += 1 |
| 51 | |
| 52 | |
| 53 | , , , = |
| 54 | = |
| 55 | = |
| 56 | ; ; ; |
| 57 | |
| 58 | |
| 59 | |
| 60 | # scfsi 0: three scalefactors |
| 61 | |
| 62 | return |
| 63 | |
| 64 | |
| 65 | = |
| 66 | ; ; ; |
| 67 | |
| 68 | |
| 69 | |
| 70 | return |
| 71 | |
| 72 | |
| 73 | = |
| 74 | |
| 75 | = |
| 76 | . |
| 77 | return |
| 78 | |
| 79 | |
| 80 | return |
| 81 | |
| 82 | return |
| 83 | |
| 84 | |
| 85 | = / 64.0 # cycles per sample, for a stream sampled at hz |
| 86 | = |
| 87 | = |
| 88 | return * 2 / / |
| 89 | |
| 90 | = |
| 91 | |
| 92 | |
| 93 | = |
| 94 | = / # per unit of |v|, scalefactor included |
| 95 | return |
| 96 | |
| 97 | = |
| 98 | |
| 99 | |
| 100 | = |
| 101 | |
| 102 | |
| 103 | = |
| 104 | |
| 105 | |
| 106 | ; continue |
| 107 | = |
| 108 | = |
| 109 | |
| 110 | ; continue |
| 111 | = |
| 112 | = / |
| 113 | = 1.0 / |
| 114 | = |
| 115 | = < 0.3 |
| 116 | |
| 117 | |
| 118 |