Commit Graph

26 Commits

Author SHA1 Message Date
kris
0a3c81c8c6 - have Bitmap.apply() update the memory representation instead of
requiring callers to keep track of it

- stop trying to cache content_deltas, I think it results in losing
  deltas.  Instead just recompute the deltas for each page as we need
  it.  This is fast enough in practice.

- track the average fill rate for the additional offsets we emit.
  This should be close to 3 if we're succeeding in finding enough
  collateral work

- overhaul how we pass in the target memory maps.  The previous way
  didn't make sense: we weren't actually encoding for the target video
  frame, but were using an inconsistent mix of old and new frames.  I
  think this was causing image artifacting because we were aiming for
  the wrong thing.

- Add some debugging assertions that were used to track this down.
2023-01-17 21:39:05 +00:00
kris
451523bdef Support for custom output bitrate, e.g. to target //gs in 2.8MHz mode.
For some reason playback speed is only about 1.6x (probably due to
slowing down accesses to the I/O page to 1MHz, so as not to mess up
hardware timings), but happily this comes within 3% of being 44100/2.
2019-07-14 22:05:20 +01:00
kris
f3d03a1b87 Update comments and fix some bugs
make_edit_distance
- use MASKED_DOTS since it does not have a simple relationship to the
  HEADER_BITS/BODY_BITS for HGR
- try disabling transposition distances for Damerau-Levenshtein, this
  may give better quality

screen
- introduce separate notion of MASKED_DOTS which is the number of
  (coloured) pixels we can extract from MASKED_BITS.  For HGR this is
  not the same.
- fix bug in _fix_array_neighbours that was not fixing headers for HGR
- don't cache everything in byte_pair_differences, it's effectively
  unbounded.  Using 1M for LRU size seems to work just as well in
  practise, without leaking memory.
- fix bug in _diff_weights when comparing content, we want to evaluate
  the effect of storing content byte in each offset separately, not
  cumulatively.
- add a consistency check function (not currently wired up) to assert
  that headers/footers are in sync across columns
- HGR should have 16 body bits, this was causing headers not to
  propagate correctly to/from neighbouring column
- add test case for this bug

video
- Use 8 random bits consistently, using 16 in some places may have
  introduced bias
- ignore palette bit when comparing 0x00 and 0x7f in sanity check
2019-07-11 23:40:00 +01:00
kris
b2c00784b0 Minor code cleanups 2019-06-21 22:08:22 +01:00
kris
2cda5ea22c Merge branch 'dhgr' of https://github.com/KrisKennaway/ii-vision into dhgr 2019-06-19 22:14:24 +01:00
kris
cf3c687a8f Fix merges after rebase 2019-06-19 22:10:15 +01:00
kris
edefe649f4 Parametrize the RGB palette to encode with, and support both NTSC and
IIGS palettes.

Move the palette diff_matrix generation into make_data_tables.py since
that is the only place it is used.

Demand-load the edit distance matrices when transcoding.
2019-06-19 22:06:54 +01:00
kris
33aa4d46c4 Rename FrameSequencer to FrameGrabber and break out into separate file.
Add a test case that the bmp2dhr output of input filenames containing
'.'  are handled correctly.

Break out video.Mode into video_mode.VideoMode to resolve circular
dependency.
2019-06-19 22:04:02 +01:00
kris
fd49736b71 FrameSequencer:
- Extract out a (File)FrameSequencer class from Video to encapsulate
the generation of still frames.  This also makes Video easier to test.

- Fix FileFrameSequencer.frames() to correctly handle filenames
  containing '.'

- Temporarily switch to the BMP2DHR NTSC palette (#5) for evaluation.

Video:
- Temporarily hardcode DHGR decoding

- Optimize _heapify_priorities() by using numpy to vectorize the
  construction of the list of tuples.  This requires changing the
  random nonce to an int so the intermediate array has a uniform type.

- Use the efficient 28-bit representation of DHGR (aux, main, aux,
  main) tuples introduced in DHGRBitmap to evaluate diffs

- Switch to np.int type for accumulating diffs, and random.randint(0,
  10000) instead of float for nonce values.

- Fix/improve some of the error evaluation in _index_changes:
  - skip offsets whose diffs have already been cleared
  - hoist some stuff out of _compute_error into the parent

- Add some validation that when we run out of work to do with a frame,
  the source and target memory maps should be equal.  This isn't
  happening sometimes, i.e. there is a bug.
2019-06-19 22:02:13 +01:00
kris
5dcbca4aae Exit gracefully when running out of video frames 2019-06-19 21:54:07 +01:00
kris
38663088ef Remove CycleCounter, it's unused 2019-06-19 21:51:45 +01:00
kris
bd0aa6ad6b Simplify the accounting of audio ticks in video framing, and fix an off-by-one that was causing audio and video to become desynchronized.
Switch from 14340Hz to 14700Hz, which is 44100/3 i.e. a divisor of the
most common audio input sample rate.  This gives better quality
(and/or faster to encode) audio quality at the cost of producing <2%
faster playback.
2019-06-19 21:47:49 +01:00
kris
ca817999f6 Parametrize the RGB palette to encode with, and support both NTSC and
IIGS palettes.

Move the palette diff_matrix generation into make_data_tables.py since
that is the only place it is used.

Demand-load the edit distance matrices when transcoding.
2019-06-15 21:02:00 +01:00
kris
549752e112 Rename FrameSequencer to FrameGrabber and break out into separate file.
Add a test case that the bmp2dhr output of input filenames containing
'.'  are handled correctly.

Break out video.Mode into video_mode.VideoMode to resolve circular
dependency.
2019-06-14 21:59:39 +01:00
kris
ec65684221 FrameSequencer:
- Extract out a (File)FrameSequencer class from Video to encapsulate
the generation of still frames.  This also makes Video easier to test.

- Fix FileFrameSequencer.frames() to correctly handle filenames
  containing '.'

- Temporarily switch to the BMP2DHR NTSC palette (#5) for evaluation.

Video:
- Temporarily hardcode DHGR decoding

- Optimize _heapify_priorities() by using numpy to vectorize the
  construction of the list of tuples.  This requires changing the
  random nonce to an int so the intermediate array has a uniform type.

- Use the efficient 28-bit representation of DHGR (aux, main, aux,
  main) tuples introduced in DHGRBitmap to evaluate diffs

- Switch to np.int type for accumulating diffs, and random.randint(0,
  10000) instead of float for nonce values.

- Fix/improve some of the error evaluation in _index_changes:
  - skip offsets whose diffs have already been cleared
  - hoist some stuff out of _compute_error into the parent

- Add some validation that when we run out of work to do with a frame,
  the source and target memory maps should be equal.  This isn't
  happening sometimes, i.e. there is a bug.
2019-06-14 00:12:26 +01:00
kris
721eb3112d Fix bug with DHGR bank switching: we were emitting the last writes to
a bank after switching to the new one, which caused video corruption.
2019-06-12 21:37:30 +01:00
kris
782156967b Add --video_mode HGR|DHGR option to support both video modes uniformly. 2019-04-25 17:38:04 +01:00
kris
de8747ff37 Emit the video header and add an assertion to help make sure we don't
break the stream framing.
2019-04-25 16:28:06 +01:00
kris
33ac880d29 Improve comment about stream padding 2019-03-28 23:47:38 +00:00
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
21a4ac0186 Fix video termination logic 2019-03-24 00:14:41 +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
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
5411793ea4 factor out State and CycleCounter to a new machine module and rename 2019-03-21 16:48:02 +00:00
kris
fb47e48e4a Fix imports and point to player debug symbols 2019-03-21 16:24:40 +00:00
kris
bbfcacd674 Move transcoder to new location 2019-03-21 16:10:16 +00:00