Parametrize options by command-line flags
This commit is contained in:
parent
4090c502a8
commit
d4bc2d45e5
|
@ -23,19 +23,16 @@
|
|||
# net-neutral position. When looking ahead we can also (partially)
|
||||
# compensate for this "dead" period by pre-positioning.
|
||||
|
||||
import argparse
|
||||
import collections
|
||||
import functools
|
||||
import sys
|
||||
import librosa
|
||||
import numpy
|
||||
from eta import ETA
|
||||
from typing import Tuple
|
||||
|
||||
import opcodes
|
||||
|
||||
|
||||
# TODO: add flags to parametrize options
|
||||
|
||||
# We simulate the speaker voltage trajectory resulting from applying multiple
|
||||
# voltage profiles, compute the resulting squared error relative to the target
|
||||
# waveform, and pick the best one.
|
||||
|
@ -226,29 +223,37 @@ def preprocess(
|
|||
return data
|
||||
|
||||
|
||||
def main(argv):
|
||||
serve_file = argv[1]
|
||||
step = int(argv[2])
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--clock", choices=['pal', 'ntsc'],
|
||||
help="Whether target machine clock speed is PAL ("
|
||||
"1015657Hz) or NTSC (1020484)",
|
||||
required=True)
|
||||
# TODO: implement 6502
|
||||
parser.add_argument("--cpu", choices=['6502', '65c02'], default='65c02',
|
||||
help="Target machine CPU type")
|
||||
parser.add_argument("--step_size", type=int,
|
||||
help="Delta encoding step size")
|
||||
# TODO: if we're not looking ahead beyond the longest (non-slowpath) opcode
|
||||
# then this will reduce quality, e.g. two opcodes may truncate to the
|
||||
# same prefix, but have different results when we apply them fully.
|
||||
lookahead_steps = int(argv[3])
|
||||
out = argv[4]
|
||||
parser.add_argument("--lookahead_cycles", type=int,
|
||||
help="Number of clock cycles to look ahead in audio "
|
||||
"stream.")
|
||||
parser.add_argument("input", type=str, help="input audio file to convert")
|
||||
parser.add_argument("output", type=str, help="output audio file")
|
||||
args = parser.parse_args()
|
||||
|
||||
# Effective clock rate, including every-65 cycle "long cycle" that takes
|
||||
# 16/14 as long.
|
||||
#
|
||||
# NTSC: 1020484
|
||||
# PAL //c: 1015625
|
||||
sample_rate = 1015657 # PAL
|
||||
sample_rate = 1015657 if args.clock == 'pal' else 1020484 # NTSC
|
||||
|
||||
with open(out, "wb+") as f:
|
||||
with open(args.output, "wb+") as f:
|
||||
for opcode in audio_bytestream(
|
||||
preprocess(serve_file, sample_rate), step, lookahead_steps,
|
||||
sample_rate):
|
||||
preprocess(args.input, sample_rate), args.step_size,
|
||||
args.lookahead_cycles, sample_rate):
|
||||
f.write(bytes([opcode.value]))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(sys.argv)
|
||||
main()
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import argparse
|
||||
import enum
|
||||
import itertools
|
||||
import numpy
|
||||
|
@ -161,23 +162,29 @@ def sort_by_opcode_count(
|
|||
reverse=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--max_cycles", default=25,
|
||||
help="Maximum cycle length of player opcodes")
|
||||
parser.add_argument("opcodes", default=["NOP3", "STA"], nargs="+",
|
||||
choices=Opcode.__members__.keys(),
|
||||
help="6502 opcodes to use when generating player "
|
||||
"opcodes")
|
||||
args = parser.parse_args()
|
||||
|
||||
opcodes = set(Opcode.__members__[op] for op in args.opcodes)
|
||||
non_nops = [Opcode.STA, Opcode.INC, Opcode.INCX, Opcode.STAX,
|
||||
Opcode.JMP_INDIRECT]
|
||||
|
||||
player_ops = sort_by_opcode_count(all_opcode_combinations(
|
||||
max_cycles=19, # TODO: flag
|
||||
opcodes=[
|
||||
Opcode.NOP,
|
||||
Opcode.NOP3,
|
||||
# Opcode.NOPNOP,
|
||||
Opcode.STA,
|
||||
# Opcode.INC,
|
||||
# Opcode.INCX
|
||||
# Opcode.STAX
|
||||
],
|
||||
start_opcodes=non_nops), non_nops)
|
||||
max_cycles=args.max_cycles, opcodes=opcodes, start_opcodes=non_nops),
|
||||
non_nops)
|
||||
generate_player(
|
||||
player_ops,
|
||||
opcode_filename="opcodes_generated.py",
|
||||
player_filename="player/player_generated.s"
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
Loading…
Reference in New Issue