Working version of encoder. This reproduces the clicking that happens from end-of-frame, so we will need a new strategy

This commit is contained in:
kris 2022-05-16 21:11:17 +01:00
parent 33ce46a19c
commit b97a625d7d
3 changed files with 369 additions and 199 deletions

View File

@ -33,6 +33,8 @@ from eta import ETA
import opcodes
import lookahead
# We simulate the speaker voltage trajectory resulting from applying multiple
# voltage profiles, compute the resulting squared error relative to the target
@ -99,6 +101,56 @@ def frame_horizon(frame_offset: int, lookahead_steps: int):
return frame_offset
class Speaker:
def __init__(self, sample_rate: float, freq: float, damping: float):
self.sample_rate = sample_rate
self.freq = freq
self.damping = damping
dt = numpy.float64(1 / sample_rate)
w = numpy.float64(freq * 2 * numpy.pi * dt)
d = damping * dt
e = numpy.exp(d)
c1 = 2 * e * numpy.cos(w)
c2 = e * e
t0 = (1 - 2 * e * numpy.cos(w) + e * e) / (d * d + w * w)
t = d * d + w * w - numpy.pi * numpy.pi
t1 = (1 + 2 * e * numpy.cos(w) + e * e) / numpy.sqrt(t * t + 4 * d * d *
numpy.pi * numpy.pi)
b2 = (t1 - t0) / (t1 + t0)
b1 = b2 * dt * dt * (t0 + t1) / 2
self.c1 = c1
self.c2 = c2
self.b1 = b1
self.b2 = b2
# print(dt, w, d, e, c1,c2,b1,b2)
self.scale = numpy.float64(1 / 1000) # TODO: analytic expression
def evolve(self, y1, y2, voltage1, voltage2, voltages):
output = numpy.zeros_like(voltages, dtype=numpy.float64)
x1 = numpy.full((1, voltages.shape[0]), voltage1,
dtype=numpy.float32)
x2 = numpy.full((1, voltages.shape[0]), voltage2,
dtype=numpy.float32)
for i in range(voltages.shape[1]):
# print(i)
y = self.c1 * y1 - self.c2 * y2 + self.b1 * x1 + self.b2 * x2
output[:, i] = y
y2 = y1
y1 = y
x2 = x1
x1 = voltages[:, i] # XXX does this really always lag?
# print(output)
return output
def audio_bytestream(data: numpy.ndarray, step: int, lookahead_steps: int,
sample_rate: int, is_6502: bool):
"""Computes optimal sequence of player opcodes to reproduce audio data."""
@ -112,39 +164,60 @@ def audio_bytestream(data: numpy.ndarray, step: int, lookahead_steps: int,
opcodes.Opcode.END_OF_FRAME, is_6502)), dtype=numpy.float32)]))
# Starting speaker position and applied voltage.
position = 0.0
voltage = -1.0
# position = 0.0
voltage1 = voltage2 = -1.0
toggles = 0
all_partial_positions = {}
# Precompute partial_positions so we don't skew ETA during encoding.
for i in range(2048):
for voltage in [-1.0, 1.0]:
opcode_hash, _, voltages = opcodes.candidate_opcodes(
frame_horizon(i, lookahead_steps), lookahead_steps, is_6502)
delta_powers, partial_positions = _partial_positions(
voltage * voltages, step)
# These matrices usually have more rows than columns, so store
# then in column-major order which optimizes for this.
delta_powers = numpy.asfortranarray(delta_powers)
partial_positions = numpy.asfortranarray(
partial_positions)
sp = Speaker(sample_rate, freq=3875, damping=-1210)
#
# print(sp.evolve(0, 0, 1.0, 1.0, numpy.full((1, 10000), 1.0)) * sp.scale)
# assert False
all_partial_positions[opcode_hash, voltage] = (
delta_powers, partial_positions)
# all_partial_positions = {}
# # Precompute partial_positions so we don't skew ETA during encoding.
# for i in range(2048):
# for voltage in [-1.0, 1.0]:
# opcode_hash, _, voltages = opcodes.candidate_opcodes(
# frame_horizon(i, lookahead_steps), lookahead_steps, is_6502)
# print(i, voltages.shape[0])
# delta_powers, partial_positions = _partial_positions(
# voltage * voltages, step)
#
# # These matrices usually have more rows than columns, so store
# # then in column-major order which optimizes for this.
# delta_powers = numpy.asfortranarray(delta_powers)
# partial_positions = numpy.asfortranarray(
# partial_positions)
#
# all_partial_positions[opcode_hash, voltage] = (
# delta_powers, partial_positions)
#
# opcode_partial_positions = {}
# all_opcodes = opcodes.Opcode.__members__.values()
# for op in set(all_opcodes) - {opcodes.Opcode.EXIT}:
# voltages = opcodes.voltage_schedule(op, is_6502)
# for voltage in [-1.0, 1.0]:
# delta_powers, partial_positions = _partial_positions(
# voltage * voltages, step)
# assert delta_powers.shape == partial_positions.shape
# assert delta_powers.shape[-1] == opcodes.cycle_length(op, is_6502)
# opcode_partial_positions[op, voltage] = (
# delta_powers, partial_positions, voltage * voltages[-1])
opcode_partial_positions = {}
all_opcodes = opcodes.Opcode.__members__.values()
for op in set(all_opcodes) - {opcodes.Opcode.EXIT}:
voltages = opcodes.voltage_schedule(op, is_6502)
for voltage in [-1.0, 1.0]:
delta_powers, partial_positions = _partial_positions(
voltage * voltages, step)
assert delta_powers.shape == partial_positions.shape
assert delta_powers.shape[-1] == opcodes.cycle_length(op, is_6502)
opcode_partial_positions[op, voltage] = (
delta_powers, partial_positions, voltage * voltages[-1])
# XXX
# Smoothing window N --> log_2 N bit resolution
# - 64
# Maintain last N voltages
# Lookahead window L
# Compute all opcodes for window L
# Compute all voltage schedules for window L
# Compute moving average over combined voltage schedule and minimize error
# XXX band pass filter first - to speaker range? no point trying to
# model frequencies that can't be produced
# old method was basically an exponential moving average, another way of
# smoothing square waveform
total_err = 0.0 # Total squared error of audio output
frame_offset = 0 # Position in 2048-byte TCP frame
@ -153,29 +226,42 @@ def audio_bytestream(data: numpy.ndarray, step: int, lookahead_steps: int,
next_tick = 0 # Value of i at which we should next update eta
# Keep track of how many opcodes we schedule
opcode_counts = collections.defaultdict(int)
y1 = y2 = 0.0 # last 2 speaker positions
while i < int(dlen / 1):
# print(i, dlen)
if i >= next_tick:
eta.print_status()
next_tick = int(eta.i * dlen / 1000)
# Compute all possible opcode sequences for this frame offset
opcode_hash, candidate_opcodes, _ = opcodes.candidate_opcodes(
opcode_hash, candidate_opcodes, voltages = opcodes.candidate_opcodes(
frame_horizon(frame_offset, lookahead_steps), lookahead_steps,
is_6502)
all_positions = sp.evolve(y1, y2, voltage1, voltage2, voltage1
* voltages)
# print(all_positions, all_positions.shape)
# Look up the precomputed partial values for these candidate opcode
# sequences.
delta_powers, partial_positions = all_partial_positions[opcode_hash,
voltage]
# Compute matrix of new speaker positions for candidate opcode
# sequences.
all_positions = new_positions(position, partial_positions, delta_powers)
# delta_powers, partial_positions = all_partial_positions[opcode_hash,
# voltage]
# # Compute matrix of new speaker positions for candidate opcode
# # sequences.
# all_positions = new_positions(position, partial_positions, delta_powers)
# opcode_idx, _ = lookahead.moving_average(
# smoothed_window, voltage * voltages, data[i:i + lookahead_steps],
# lookahead_steps)
assert all_positions.shape[1] == lookahead_steps
# Pick the opcode sequence that minimizes the total squared error
# relative to the data waveform. This total_error() call is where
# about 75% of CPU time is spent.
opcode_idx = numpy.argmin(
total_error(all_positions, data[i:i + lookahead_steps])).item()
total_error(
all_positions * sp.scale, data[i:i + lookahead_steps])).item()
# Next opcode
opcode = candidate_opcodes[opcode_idx][0]
opcode_length = opcodes.cycle_length(opcode, is_6502)
@ -183,24 +269,36 @@ def audio_bytestream(data: numpy.ndarray, step: int, lookahead_steps: int,
toggles += opcodes.TOGGLES[opcode]
# Apply this opcode to evolve the speaker position
delta_powers, partial_positions, last_voltage = \
opcode_partial_positions[opcode, voltage]
all_positions = new_positions(position, partial_positions, delta_powers)
assert len(all_positions) == opcode_length
voltage = last_voltage
position = all_positions[-1]
total_err += total_error(
all_positions, data[i:i + opcode_length]).item()
opcode_voltages = (voltage1 * opcodes.voltage_schedule(
opcode, is_6502)).reshape((1, -1))
all_positions = sp.evolve(y1, y2, voltage1, voltage2, opcode_voltages)
yield opcode
# delta_powers, partial_positions, last_voltage = \
# opcode_partial_positions[opcode, voltage]
# all_positions = new_positions(position, partial_positions, delta_powers)
assert all_positions.shape[0] == 1
assert all_positions.shape[1] == opcode_length
voltage1 = opcode_voltages[0, -1]
voltage2 = opcode_voltages[0, -2]
y1 = all_positions[0, -1]
y2 = all_positions[0, -2]
# print(y1, y2, all_positions[0] * sp.scale)
total_err += total_error(
all_positions[0] * sp.scale, data[i:i + opcode_length]).item()
# print(all_positions[0] * sp.scale, data[i:i + opcode_length])
for v in all_positions[0]:
yield v * sp.scale
# print(v * sp.scale)
i += opcode_length
frame_offset = (frame_offset + 1) % 2048
# Make sure we have at least 2k left in stream so player will do a
# complete read.
for _ in range(frame_offset % 2048, 2048):
yield opcodes.Opcode.EXIT
# for _ in range(frame_offset % 2048, 2048):
# yield opcodes.Opcode.EXIT
eta.done()
print("Total error %f" % total_err)
toggles_per_sec = toggles / dlen * sample_rate
@ -226,6 +324,9 @@ def preprocess(
return data
import soundfile as sf
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--clock", choices=['pal', 'ntsc'],
@ -258,12 +359,20 @@ def main():
# 16/14 as long.
sample_rate = 1015657 if args.clock == 'pal' else 1020484 # NTSC
with open(args.output, "wb+") as f:
for opcode in audio_bytestream(
preprocess(args.input, sample_rate, args.normalization,
args.norm_percentile), args.step_size,
args.lookahead_cycles, sample_rate, args.cpu == '6502'):
f.write(bytes([opcode.value]))
# with open(args.output, "wb+") as f:[d20+
output = numpy.array(list(audio_bytestream(
preprocess(args.input, sample_rate, args.normalization,
args.norm_percentile), args.step_size,
args.lookahead_cycles, sample_rate, args.cpu == '6502')),
dtype=numpy.float32)
output_rate = 44100 # int(sample_rate / 4)
output = librosa.resample(output, orig_sr=sample_rate,
target_sr=output_rate)
with sf.SoundFile(
args.output, "w", output_rate, channels=1, format='WAV') \
as f:
f.write(output)
# f.write(bytes([opcode.value]))
if __name__ == "__main__":

View File

@ -9,40 +9,40 @@ class Opcode(enum.Enum):
TICK_09 = 0x09
TICK_0c = 0x0c
TICK_0f = 0x0f
TICK_10 = 0x10
TICK_17 = 0x17
TICK_1a = 0x1a
TICK_1b = 0x1b
TICK_23 = 0x23
TICK_26 = 0x26
TICK_12 = 0x12
TICK_14 = 0x14
TICK_1f = 0x1f
TICK_24 = 0x24
TICK_27 = 0x27
TICK_2a = 0x2a
TICK_2e = 0x2e
TICK_31 = 0x31
TICK_2f = 0x2f
TICK_32 = 0x32
TICK_35 = 0x35
TICK_3a = 0x3a
TICK_3d = 0x3d
TICK_46 = 0x46
TICK_49 = 0x49
TICK_4c = 0x4c
TICK_51 = 0x51
TICK_54 = 0x54
TICK_57 = 0x57
TICK_5d = 0x5d
TICK_67 = 0x67
TICK_72 = 0x72
TICK_7c = 0x7c
TICK_87 = 0x87
TICK_34 = 0x34
TICK_3b = 0x3b
TICK_3e = 0x3e
TICK_40 = 0x40
TICK_47 = 0x47
TICK_4a = 0x4a
TICK_4b = 0x4b
TICK_53 = 0x53
TICK_56 = 0x56
TICK_62 = 0x62
TICK_6a = 0x6a
TICK_6d = 0x6d
TICK_75 = 0x75
TICK_80 = 0x80
TICK_8a = 0x8a
TICK_8b = 0x8b
TICK_91 = 0x91
TICK_94 = 0x94
TICK_95 = 0x95
TICK_9c = 0x9c
TICK_a5 = 0xa5
EXIT = 0xaf
SLOWPATH = 0xb2
TICK_9f = 0x9f
TICK_a2 = 0xa2
TICK_a4 = 0xa4
TICK_ae = 0xae
TICK_b5 = 0xb5
TICK_b8 = 0xb8
TICK_bf = 0xbf
TICK_c9 = 0xc9
EXIT = 0xd2
END_OF_FRAME = 0xd5
VOLTAGE_SCHEDULE = {
@ -50,38 +50,80 @@ VOLTAGE_SCHEDULE = {
Opcode.TICK_03: numpy.array((1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0), dtype=numpy.float32),
Opcode.TICK_06: numpy.array((1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0), dtype=numpy.float32),
Opcode.TICK_09: numpy.array((1.0, 1.0, 1.0, 1.0, 1.0, 1.0), dtype=numpy.float32),
Opcode.TICK_0c: numpy.array((1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0), dtype=numpy.float32),
Opcode.TICK_0f: numpy.array((1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0), dtype=numpy.float32),
Opcode.TICK_10: numpy.array((1.0, 1.0, 1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0), dtype=numpy.float32),
Opcode.TICK_17: numpy.array((1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0), dtype=numpy.float32),
Opcode.TICK_1a: numpy.array((1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0), dtype=numpy.float32),
Opcode.TICK_1b: numpy.array((1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0), dtype=numpy.float32),
Opcode.TICK_23: numpy.array((1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0), dtype=numpy.float32),
Opcode.TICK_26: numpy.array((1.0, 1.0, 1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0), dtype=numpy.float32),
Opcode.TICK_27: numpy.array((1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0), dtype=numpy.float32),
Opcode.TICK_2a: numpy.array((1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0), dtype=numpy.float32),
Opcode.TICK_2e: numpy.array((1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0), dtype=numpy.float32),
Opcode.TICK_31: numpy.array((1.0, 1.0, 1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0), dtype=numpy.float32),
Opcode.TICK_32: numpy.array((1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0), dtype=numpy.float32),
Opcode.TICK_35: numpy.array((1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0), dtype=numpy.float32),
Opcode.TICK_3a: numpy.array((1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0), dtype=numpy.float32),
Opcode.TICK_3d: numpy.array((1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0), dtype=numpy.float32),
Opcode.TICK_46: numpy.array((1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0), dtype=numpy.float32),
Opcode.TICK_49: numpy.array((1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0), dtype=numpy.float32),
Opcode.TICK_4c: numpy.array((1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0), dtype=numpy.float32),
Opcode.TICK_51: numpy.array((1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0), dtype=numpy.float32),
Opcode.TICK_54: numpy.array((1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0), dtype=numpy.float32),
Opcode.TICK_57: numpy.array((1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0), dtype=numpy.float32),
Opcode.TICK_5d: numpy.array((1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0), dtype=numpy.float32),
Opcode.TICK_67: numpy.array((1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0), dtype=numpy.float32),
Opcode.TICK_72: numpy.array((1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0), dtype=numpy.float32),
Opcode.TICK_7c: numpy.array((1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0), dtype=numpy.float32),
Opcode.TICK_87: numpy.array((1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0), dtype=numpy.float32),
Opcode.TICK_8a: numpy.array((1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0), dtype=numpy.float32),
Opcode.TICK_8b: numpy.array((1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0), dtype=numpy.float32),
Opcode.TICK_91: numpy.array((1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0), dtype=numpy.float32),
Opcode.TICK_94: numpy.array((1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0), dtype=numpy.float32),
Opcode.TICK_95: numpy.array((1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0), dtype=numpy.float32),
Opcode.TICK_9c: numpy.array((1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0), dtype=numpy.float32),
Opcode.TICK_a5: numpy.array((1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0), dtype=numpy.float32),
Opcode.TICK_0c: numpy.array((1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0), dtype=numpy.float32),
Opcode.TICK_0f: numpy.array((1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0), dtype=numpy.float32),
Opcode.TICK_12: numpy.array((1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0), dtype=numpy.float32),
Opcode.TICK_14: numpy.array((1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0), dtype=numpy.float32),
Opcode.TICK_1f: numpy.array((1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0), dtype=numpy.float32),
Opcode.TICK_24: numpy.array((1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0), dtype=numpy.float32),
Opcode.TICK_27: numpy.array((1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0), dtype=numpy.float32),
Opcode.TICK_2a: numpy.array((1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0), dtype=numpy.float32),
Opcode.TICK_2f: numpy.array((1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0), dtype=numpy.float32),
Opcode.TICK_32: numpy.array((1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0), dtype=numpy.float32),
Opcode.TICK_34: numpy.array((1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0), dtype=numpy.float32),
Opcode.TICK_3b: numpy.array((1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0), dtype=numpy.float32),
Opcode.TICK_3e: numpy.array((1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0), dtype=numpy.float32),
Opcode.TICK_40: numpy.array((1.0, 1.0, 1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0), dtype=numpy.float32),
Opcode.TICK_47: numpy.array((1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0), dtype=numpy.float32),
Opcode.TICK_4a: numpy.array((1.0, 1.0, 1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0), dtype=numpy.float32),
Opcode.TICK_4b: numpy.array((1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0), dtype=numpy.float32),
Opcode.TICK_53: numpy.array((1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0), dtype=numpy.float32),
Opcode.TICK_56: numpy.array((1.0, 1.0, 1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0), dtype=numpy.float32),
Opcode.TICK_62: numpy.array((1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0), dtype=numpy.float32),
Opcode.TICK_6a: numpy.array((1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0), dtype=numpy.float32),
Opcode.TICK_6d: numpy.array((1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0), dtype=numpy.float32),
Opcode.TICK_75: numpy.array((1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0), dtype=numpy.float32),
Opcode.TICK_80: numpy.array((1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0), dtype=numpy.float32),
Opcode.TICK_8a: numpy.array((1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0), dtype=numpy.float32),
Opcode.TICK_95: numpy.array((1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0), dtype=numpy.float32),
Opcode.TICK_9f: numpy.array((1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0), dtype=numpy.float32),
Opcode.TICK_a2: numpy.array((1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0), dtype=numpy.float32),
Opcode.TICK_a4: numpy.array((1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0), dtype=numpy.float32),
Opcode.TICK_ae: numpy.array((1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0), dtype=numpy.float32),
Opcode.TICK_b5: numpy.array((1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0), dtype=numpy.float32),
Opcode.TICK_b8: numpy.array((1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0), dtype=numpy.float32),
Opcode.TICK_bf: numpy.array((1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0), dtype=numpy.float32),
Opcode.TICK_c9: numpy.array((1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0), dtype=numpy.float32),
}
TOGGLES = {
Opcode.TICK_00: 3,
Opcode.TICK_03: 2,
Opcode.TICK_06: 1,
Opcode.TICK_09: 0,
Opcode.TICK_0c: 2,
Opcode.TICK_0f: 1,
Opcode.TICK_12: 0,
Opcode.TICK_14: 0,
Opcode.TICK_1f: 0,
Opcode.TICK_24: 2,
Opcode.TICK_27: 1,
Opcode.TICK_2a: 0,
Opcode.TICK_2f: 2,
Opcode.TICK_32: 1,
Opcode.TICK_34: 1,
Opcode.TICK_3b: 2,
Opcode.TICK_3e: 1,
Opcode.TICK_40: 1,
Opcode.TICK_47: 2,
Opcode.TICK_4a: 1,
Opcode.TICK_4b: 1,
Opcode.TICK_53: 2,
Opcode.TICK_56: 1,
Opcode.TICK_62: 1,
Opcode.TICK_6a: 2,
Opcode.TICK_6d: 1,
Opcode.TICK_75: 2,
Opcode.TICK_80: 2,
Opcode.TICK_8a: 2,
Opcode.TICK_95: 2,
Opcode.TICK_9f: 1,
Opcode.TICK_a2: 0,
Opcode.TICK_a4: 0,
Opcode.TICK_ae: 0,
Opcode.TICK_b5: 1,
Opcode.TICK_b8: 0,
Opcode.TICK_bf: 1,
Opcode.TICK_c9: 1,
}

View File

@ -7,126 +7,145 @@ tick_06: ; voltages (1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0)
tick_09: ; voltages (1.0, 1.0, 1.0, 1.0, 1.0, 1.0)
JMP (WDATA)
tick_0c: ; voltages (1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)
tick_0c: ; voltages (1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)
STA $C030
tick_0f: ; voltages (1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0)
tick_0f: ; voltages (1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0)
STA $C030
tick_12: ; voltages (1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)
STA zpdummy
tick_14: ; voltages (1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)
NOP
tick_10: ; voltages (1.0, 1.0, 1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0)
JMP (WDATA)
STA $C030
STA $C030
NOP
tick_1f: ; voltages (1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)
STA zpdummy
JMP (WDATA)
tick_24: ; voltages (1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)
STA $C030
tick_27: ; voltages (1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0)
STA $C030
tick_2a: ; voltages (1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)
NOP
NOP
JMP (WDATA)
tick_2f: ; voltages (1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)
STA $C030
tick_32: ; voltages (1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0)
STA zpdummy
tick_34: ; voltages (1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0)
STA $C030
NOP
JMP (WDATA)
tick_3b: ; voltages (1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)
STA $C030
tick_3e: ; voltages (1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0)
STA zpdummy
tick_40: ; voltages (1.0, 1.0, 1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0)
NOP
STA $C030
JMP (WDATA)
tick_17: ; voltages (1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)
tick_47: ; voltages (1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)
STA $C030
tick_1a: ; voltages (1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0)
tick_4a: ; voltages (1.0, 1.0, 1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0)
NOP
tick_1b: ; voltages (1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0)
tick_4b: ; voltages (1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0)
STA $C030
STA zpdummy
JMP (WDATA)
tick_53: ; voltages (1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)
STA $C030
tick_56: ; voltages (1.0, 1.0, 1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0)
NOP
STA $C030
NOP
JMP (WDATA)
STA $C030
NOP
tick_62: ; voltages (1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0)
STA zpdummy
STA $C030
JMP (WDATA)
tick_23: ; voltages (1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)
tick_6a: ; voltages (1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)
STA $C030
tick_26: ; voltages (1.0, 1.0, 1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0)
tick_6d: ; voltages (1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0)
NOP
tick_27: ; voltages (1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0)
STA $C030
tick_2a: ; voltages (1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)
NOP
JMP (WDATA)
tick_2e: ; voltages (1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)
STA $C030
tick_31: ; voltages (1.0, 1.0, 1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0)
NOP
tick_32: ; voltages (1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0)
STA $C030
tick_35: ; voltages (1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)
STA zpdummy
JMP (WDATA)
tick_3a: ; voltages (1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)
STA $C030
tick_3d: ; voltages (1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0)
STA zpdummy
STA $C030
NOP
JMP (WDATA)
tick_46: ; voltages (1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)
STA $C030
tick_49: ; voltages (1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0)
STA $C030
tick_4c: ; voltages (1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)
NOP
NOP
JMP (WDATA)
tick_51: ; voltages (1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)
STA $C030
tick_54: ; voltages (1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0)
STA $C030
tick_57: ; voltages (1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)
NOP
STA zpdummy
JMP (WDATA)
tick_5d: ; voltages (1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)
STA $C030
NOP
STA $C030
JMP (WDATA)
tick_67: ; voltages (1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)
STA $C030
STA zpdummy
STA $C030
JMP (WDATA)
tick_72: ; voltages (1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)
STA $C030
STA $C030
NOP
JMP (WDATA)
tick_7c: ; voltages (1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)
tick_75: ; voltages (1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)
STA $C030
STA $C030
STA zpdummy
JMP (WDATA)
tick_87: ; voltages (1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0)
tick_80: ; voltages (1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)
STA $C030
STA $C030
tick_8a: ; voltages (1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)
NOP
tick_8b: ; voltages (1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)
NOP
NOP
NOP
JMP (WDATA)
tick_91: ; voltages (1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0)
tick_8a: ; voltages (1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)
STA $C030
tick_94: ; voltages (1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)
NOP
tick_95: ; voltages (1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)
NOP
NOP
STA zpdummy
STA $C030
JMP (WDATA)
tick_9c: ; voltages (1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0)
tick_95: ; voltages (1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)
STA $C030
NOP
NOP
NOP
STA $C030
JMP (WDATA)
tick_a5: ; voltages (1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0)
tick_9f: ; voltages (1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0)
STA $C030
NOP
NOP
tick_a2: ; voltages (1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)
STA zpdummy
tick_a4: ; voltages (1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)
NOP
NOP
NOP
JMP (WDATA)
; 175 bytes
STA $C030
NOP
tick_ae: ; voltages (1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)
STA zpdummy
NOP
NOP
JMP (WDATA)
tick_b5: ; voltages (1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0)
STA $C030
tick_b8: ; voltages (1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)
NOP
NOP
NOP
NOP
JMP (WDATA)
tick_bf: ; voltages (1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0)
STA $C030
STA zpdummy
NOP
NOP
JMP (WDATA)
tick_c9: ; voltages (1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0)
STA $C030
NOP
NOP
NOP
JMP (WDATA)
; 210 bytes