Commit Graph

102 Commits

Author SHA1 Message Date
kris
10fa4bc72d Proof of concept DHGR encoding/playback
- Every time we process an ACK opcode, toggle page 1/page 2 soft
  switches to steer subsequent writes between MAIN and AUX memory
- while I'm here, squeeze out some unnecessary operations from the
  buffer management

On the player side, this is implemented by maintaining two screen
memory maps, and alternating between opcode streams for each of them.
This is using entirely the wrong colour model for errors, but
surprisingly it already works pretty well in practise (and the frame
rate is acceptable on test videos)

DHGR/HGR could be made runtime selectable by adding a header byte that
determines whether to set the DHGR soft switches before initiating
the decode loop.

While I'm in here, fix op_terminate to clear keyboard strobe before
waiting.
2019-03-27 21:37:06 +00:00
kris
d4a27444c6 Merge remote-tracking branch 'origin/master' 2019-03-24 00:15:16 +00:00
kris
21a4ac0186 Fix video termination logic 2019-03-24 00:14:41 +00:00
KrisKennaway
bb3f2e4a4c
Add some more details 2019-03-24 00:03:04 +00:00
KrisKennaway
403915d783
Create README.md 2019-03-23 23:48:55 +00:00
kris
dd422d1156 Fix tests 2019-03-23 22:05:36 +00:00
kris
13fb9c3125 Clean up module and abort import if we are unable to find the address
of an opcode.
2019-03-23 22:01:49 +00:00
kris
531a6ae345 Allow player to exit cleanly
- can't emit Terminate opcode in the middle of the bytestream
- pad the TCP stream to next 2k boundary when emitting terminate opcode,
  since the player will block until receiving this much data.
2019-03-23 21:46:35 +00:00
kris
8ffc8efaac Install RESET handler that exits to ProDOS
Implement op_terminate which waits for a keypress and then exits.
2019-03-23 21:45:13 +00:00
kris
8174d853f9 Downsize image using LANCZOS resampler. 2019-03-22 00:06:29 +00:00
kris
f37d07914d Print input frame rate, and default to every_n_video_frames=2 which
gives better quality without compromising frame rate too much.
2019-03-21 23:25:51 +00:00
kris
eebbccf711 Add some docstrings
Clean up naming in edit_distance

In video encoder, when we emit additional offsets as part of an opcode,
reinsert back into the priority heapq if the new edit distance is
nonzero, in case we get the chance to fix it up later in the frame.

Also make sure to zero out the diff_weights and content_deltas
so we don't consider the offset again as a side-effect of some other
opcode.

Instead of prioritizing side-effect offsets by their previous update
priority, prioritize by those with the lowest (error - edit) delta i.e.
not introducing too much error relative to their edit distance.
2019-03-21 22:56:45 +00:00
kris
fe10f98128 Support skipping frames from the input video to increase output
image quality at the expense of frame rate.
2019-03-21 22:43:02 +00:00
kris
8bdad22162 Stop ticking cycles as part of emitting the opcodes, we are counting
them externally in audio.py now.

Add some docstrings
2019-03-21 22:42:09 +00:00
kris
ce078f493f Start to flesh out function docstrings, add some more type annotations. 2019-03-21 22:41:05 +00:00
kris
da2e2476e7 Rename tests and clean up a bit. Still don't pass. 2019-03-21 17:21:43 +00:00
kris
5a5c761183 Remove _END from opcode.
Don't set cls in outer module scope
2019-03-21 17:15:44 +00:00
kris
84e14efc57 Fix 2019-03-21 16:51:33 +00:00
kris
5411793ea4 factor out State and CycleCounter to a new machine module and rename 2019-03-21 16:48:02 +00:00
kris
cf493e782c Add module docstrings 2019-03-21 16:42:47 +00:00
kris
5d4148daaf No need to store opcode _END any more 2019-03-21 16:35:42 +00:00
kris
7164f20eab Oops fix byte ordering for port 2019-03-21 16:35:12 +00:00
kris
fb47e48e4a Fix imports and point to player debug symbols 2019-03-21 16:24:40 +00:00
kris
d55ee0e170 Rename binary 2019-03-21 16:23:56 +00:00
kris
bbfcacd674 Move transcoder to new location 2019-03-21 16:10:16 +00:00
kris
4ae5e7a153 Move player to new location 2019-03-21 16:09:23 +00:00
kris
2f88408c23 Style 2019-03-21 16:04:26 +00:00
kris
0d54f182f5 Whitespace 2019-03-21 16:02:18 +00:00
kris
44c1216542 Rename byte_to_colour_string -> byte_to_nominal_colour_string and
introduce an attempt at post-processing the colour artefacting that
results in coalescing adjacent '1' bits into white pixels.  This is
an incomplete modeling even of this artefact, let alone the other
various fringing weirdness that happens for e.g. NTSC rendering (which
is not faithfully reproduced by Apple //GS RGB display, so hard for me
to test further)
2019-03-21 15:59:56 +00:00
kris
4c168721bb - Don't hardcode clock speed
- Commented-out experimentation with using hitherdither library to
use yliluoma dithering (see
https://bisqwit.iki.fi/story/howto/dither/jy/) instead of the
(error-diffusion) based BMP2DHR which introduces a lot of noise between
frames since it is easily perturbed.

Unfortunately apart from being extremely slow, it also doesn't give
good results, even for (simulated) DHGR palette.  There's a lot of
banding and for HGR the available colours are just too far apart in
colour space.

This is even without (somehow) applying the HGR colour constraints.

- Also return the priority from _compute_error as preparation for
reinserting the offset back into the priority heap, in case we can do
a better job later.  In order to do this properly we need to compute
both the error edit distance and the "true" edit distance and only
insert the priority of the latter.
2019-03-21 15:57:09 +00:00
kris
8f6aa019b6 Remove old player 2019-03-21 15:43:09 +00:00
kris
065d9dddf8 Move server file into subdir 2019-03-21 15:37:51 +00:00
kris
0732e2c067 Remove unneeded assert 2019-03-21 15:36:29 +00:00
kris
c4ed5f3d0a Remove files no longer in use. 2019-03-21 15:35:55 +00:00
kris
c8942ba138 Add cc65's LOADER.SYSTEM to the base disk image so we can use it to
bootstrap the player.
2019-03-21 15:28:41 +00:00
kris
341c645c12 Reorder a bit to put the configurable bits at the top. 2019-03-21 15:27:24 +00:00
kris
c53cf76df0 Switch to argparse and parametrize some flags 2019-03-21 15:26:00 +00:00
kris
0a9e83fa22 Listen on all interfaces, switch to port 1977 and use argparse instead
of sys.argv.
2019-03-21 15:25:06 +00:00
kris
92e1247c63 Add more comments and clean up timings for op_ack. Magically,
this all fits in exact multiples of 36/37 ticks!
2019-03-15 22:42:33 +00:00
kris
b3ba069b2d - Improve comments and clean up a bit
- un-orphan the code that sets up 5 connection retries

- Pad CHECKRECV loop to 36,37,36,37 tick cycles
2019-03-15 22:18:03 +00:00
kris
fffd05f4d1 Don't schedule a NOP for TCP frame padding; instead just have the ACK
include the 2 dummy reads.
2019-03-15 21:09:45 +00:00
kris
7343aa39ed Fix 2019-03-15 21:08:31 +00:00
kris
2092ef0926 - Add some comments
- Change ACK code to perform two dummy stream reads rather than relying
  on a preceding NOP to pad the TCP frame to 2K.  This fixes the timing
  issue that was causing most of the low-frequency ticks.

- Ticks still aren't perfectly aligned during the ACK slow path but
  it's almost good enough, i.e. probably no need to actually bother
  optimizing the slow path more.
2019-03-15 21:08:06 +00:00
kris
4cb45efb2c Remove old video-only opcode support. 2019-03-14 23:05:47 +00:00
kris
d90b865b16 Style cleanups 2019-03-14 23:05:15 +00:00
kris
01ffd034eb Move edit distance functions into separate module and clean up
partially.

Slight optimization to not heapppush() many times, instead build a
regular list and then heapify.
2019-03-14 22:32:52 +00:00
kris
e0ac37fe4a Style 2019-03-14 22:31:07 +00:00
kris
976e26f159 Vectorize the computation of diff weights, by precomputing a map
of all possible weights.  We encode the two 8-bit inputs into a single
16 bit value instead of dealing with an array of tuples.

Fix an important bug in _compute_delta: old and is_odd were transposed
so we weren't actually subtracting the old deltas!  Surprisingly,
when I accidentally fixed this bug in the vectorized version, the video
encoding was much worse!  This turned out to be because the edit
distance metric allowed reducing diffs by turning on pixels, which
meant it would tend to do this when "minimizing error" in a way that
was visually unappealing.

To remedy this, introduce a separate notion of substitution cost for
errors, and weight pixel colour changes more highly to discourage them
unless absolutely necessary.  This gives very good quality results!

Also vectorize the selection of page offsets and priorities having
a negative error delta, instead of heapifying the entire page.

Also it turns out to be a bit faster to compute (and memoize) the delta
between a proposed content byte and the entire target screen at once,
since we'll end up recomputing the same content diffs multiple times.

(Committing messy version in case I want to revisit some of those
interim versions)
2019-03-14 22:08:50 +00:00
kris
ede453d292 Remove vestige of standalone audio encoder. 2019-03-14 21:52:57 +00:00
kris
19ffa000f9 fix 2019-03-14 21:45:40 +00:00