Skip to content

Commit faf9137

Browse files
committed
QD: Re-indent mk_qd script and add new parameter to round up byte values to block size.
1 parent 38aa3c9 commit faf9137

File tree

1 file changed

+52
-34
lines changed

1 file changed

+52
-34
lines changed

scripts/mk_qd.py

Lines changed: 52 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,41 +9,59 @@
99

1010
import sys,struct,argparse
1111

12+
def round_up(x, y):
13+
return (x + y - 1) & ~(y - 1)
14+
1215
def main(argv):
13-
parser = argparse.ArgumentParser(
14-
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
15-
parser.add_argument("--lead-in", type=float, default=0.5,
16-
help="lead-in, seconds")
17-
parser.add_argument("--window", type=float, default=5.5,
18-
help="data window, seconds")
19-
parser.add_argument("--total", type=float, default=8.0,
20-
help="total length, seconds")
21-
parser.add_argument("outfile", help="output filename")
22-
args = parser.parse_args(argv[1:])
23-
24-
bit_ms = 0.004916
25-
total_bytes = int(args.total * 1000.0 / bit_ms / 8)
26-
window_bytes = int(args.window * 1000.0 / bit_ms / 8)
27-
init_bytes = int(args.lead_in * 1000.0 / bit_ms / 8)
28-
29-
assert (2*init_bytes + window_bytes) < total_bytes, "Window too large"
30-
print("Lead-In: %.2f sec -> %u bytes" % (args.lead_in, init_bytes))
31-
print("Window: %.2f sec -> %u bytes" % (args.window, window_bytes))
32-
print("TOTAL: %.2f sec -> %u bytes" % (args.total, total_bytes))
33-
34-
# Header
35-
out_f = open(args.outfile, "wb")
36-
out_f.write(struct.pack("<3x2s3x", b"QD"))
37-
out_f.write(bytearray(b'\x00'*(512-8)))
38-
39-
# Track
40-
out_f.write(struct.pack("<4I", 1024, total_bytes, init_bytes,
41-
init_bytes + window_bytes))
42-
out_f.write(bytearray(b'\x00'*(512-16)))
43-
44-
# Data
45-
blocks = (total_bytes + 511) // 512
46-
out_f.write(bytearray(b'\x11'*(blocks*512)))
16+
parser = argparse.ArgumentParser(
17+
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
18+
parser.add_argument("--lead-in", type=float, default=0.5,
19+
help="lead-in, seconds")
20+
parser.add_argument("--window", type=float, default=5.5,
21+
help="data window, seconds")
22+
parser.add_argument("--total", type=float, default=8.0,
23+
help="total length, seconds")
24+
parser.add_argument("--round", action="store_true",
25+
help="round values up to 512-byte block size")
26+
parser.add_argument("outfile", help="output filename")
27+
args = parser.parse_args(argv[1:])
28+
29+
lead_in, window, total = args.lead_in, args.window, args.total
30+
31+
assert lead_in >= 0.1, "Insufficient lead-in"
32+
assert total - window - lead_in >= 0.1, "Insufficient lead-out"
33+
34+
bit_ms = 0.004916
35+
total_bytes = int(total * 1000.0 / bit_ms / 8)
36+
window_bytes = int(window * 1000.0 / bit_ms / 8)
37+
init_bytes = int(lead_in * 1000.0 / bit_ms / 8)
38+
39+
if args.round:
40+
total_bytes = round_up(total_bytes, 512)
41+
window_bytes = round_up(window_bytes, 512)
42+
init_bytes = round_up(init_bytes, 512)
43+
44+
print("Lead-In: %.2f sec -> %u bytes" % (lead_in, init_bytes))
45+
print("Window: %.2f sec -> %u bytes" % (window, window_bytes))
46+
print("TOTAL: %.2f sec -> %u bytes" % (total, total_bytes))
47+
48+
# Header
49+
out_f = open(args.outfile, "wb")
50+
out_f.write(struct.pack("<3x2s3x", b"QD"))
51+
out_f.write(bytearray(b'\x00'*(512-8)))
52+
53+
# Track
54+
out_f.write(struct.pack("<4I", 1024, total_bytes, init_bytes,
55+
init_bytes + window_bytes))
56+
out_f.write(bytearray(b'\x00'*(512-16)))
57+
58+
# Data
59+
blocks = (total_bytes + 511) // 512
60+
out_f.write(bytearray(b'\x11'*(blocks*512)))
4761

4862
if __name__ == "__main__":
4963
main(sys.argv)
64+
65+
# Local variables:
66+
# python-indent: 4
67+
# End:

0 commit comments

Comments
 (0)