| 1 | |
| 2 | |
| 3 | |
| 4 | import sys |
| 5 | import numpy as np |
| 6 | from mp3probe import BitWriter, Granule, frame_bytes, ffmpeg_decode |
| 7 | from probe_engine import GLOBAL_GAIN, SCALE |
| 8 | |
| 9 | TABLE1 = [(1, 0b1), (3, 0b001), (2, 0b01), (3, 0b000)] |
| 10 | SC = 13 |
| 11 | SLEN = 3 |
| 12 | NBANDS = 21 |
| 13 | |
| 14 | |
| 15 | def probe_bits(band): |
| 16 | bw = BitWriter() |
| 17 | for b in range(NBANDS): |
| 18 | bw.w(7 if b == band else 0, SLEN) |
| 19 | ln, code = TABLE1[3] |
| 20 | for _ in range(288): |
| 21 | bw.w(code, ln) |
| 22 | bw.w(0, 1) |
| 23 | bw.w(0, 1) |
| 24 | return bw.bits |
| 25 | |
| 26 | |
| 27 | def main(): |
| 28 | Minv = np.load("Minv.npy") |
| 29 | for srate_idx, srate in enumerate([44100, 48000, 32000]): |
| 30 | stream = b"" |
| 31 | for band in range(NBANDS): |
| 32 | bits = probe_bits(band) |
| 33 | g = Granule(part2_3_length=len(bits), big_values=288, |
| 34 | global_gain=GLOBAL_GAIN, scalefac_compress=SC, |
| 35 | table_select=(1, 1, 1)) |
| 36 | stream += frame_bytes([g, Granule()], [bits, []], srate_idx=srate_idx) |
| 37 | stream += frame_bytes([Granule(), Granule()], [[], []], srate_idx=srate_idx) |
| 38 | pcm, err = ffmpeg_decode(stream) |
| 39 | assert not err.strip(), err |
| 40 | edges = [0] |
| 41 | for band in range(NBANDS): |
| 42 | xr = (pcm[band * 2304:(band + 1) * 2304] @ Minv)[:576] |
| 43 | att = np.abs(xr) / SCALE |
| 44 | low = np.where(att < 0.5)[0] |
| 45 | if len(low) == 0: |
| 46 | print(f" {srate}: band {band} showed no attenuation") |
| 47 | continue |
| 48 | edges.append(int(low[-1]) + 1) |
| 49 | widths = [edges[i + 1] - edges[i] for i in range(len(edges) - 1)] |
| 50 | widths.append(576 - edges[-1]) |
| 51 | print(f"{srate} long widths ({sum(widths)}): {widths}") |
| 52 | return 0 |
| 53 | |
| 54 | |
| 55 | if __name__ == "__main__": |
| 56 | sys.exit(main()) |