Skip to content

Commit

Permalink
Make head switching consistent across frames
Browse files Browse the repository at this point in the history
  • Loading branch information
valadaptive committed Aug 19, 2023
1 parent cdcd25c commit 8949c74
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions app/ntsc.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ def __init__(self, precise: bool, random: NumpyRandom):

self._vhs_head_switching = False # turn this on only on frames height 486 pixels or more
self._head_switching_speed = 0 # 0..100 this is /1000 increment for _vhs_head_switching_point 0 is static
self._vhs_head_switching_point = 1.0 - (4.5 + 0.01) / 262.5 # 4 scanlines NTSC up from vsync
self._vhs_head_switching_phase = (1.0 - 0.01) / 262.5 # 4 scanlines NTSC up from vsync
self._vhs_head_switching_phase_noise = 1.0 / 500 / 262.5 # 1/500th of a scanline

Expand Down Expand Up @@ -332,7 +331,7 @@ def video_chroma_phase_noise(self, yiq: numpy.ndarray, field: int, video_chroma_
U[y, :] = u
V[y, :] = v

def vhs_head_switching(self, yiq: numpy.ndarray, field: int = 0):
def vhs_head_switching(self, yiq: numpy.ndarray, field: int, frameno: int):
_, height, width = yiq.shape
fY, fI, fQ = yiq
twidth = width + width // 10
Expand All @@ -343,9 +342,10 @@ def vhs_head_switching(self, yiq: numpy.ndarray, field: int = 0):
noise = x / 1000000000.0 - 1.0
noise *= self._vhs_head_switching_phase_noise

vhs_head_switching_point = (self._head_switching_speed / 1000) * frameno

t = twidth * (262.5 if self._output_ntsc else 312.5)
p = int(fmod(self._vhs_head_switching_point + noise, 1.0) * t)
self._vhs_head_switching_point += self._head_switching_speed/1000
p = int(fmod(vhs_head_switching_point + noise, 1.0) * t)
y = int(p // twidth * 2) + field
p = int(fmod(self._vhs_head_switching_phase + noise, 1.0) * t)
x = p % twidth
Expand Down Expand Up @@ -588,7 +588,7 @@ def composite_layer(self, dst: numpy.ndarray, src: numpy.ndarray, field: int, fi
self.video_noise(yiq, field, self._video_noise)

if self._vhs_head_switching:
self.vhs_head_switching(yiq, field)
self.vhs_head_switching(yiq, field, frameno)

if not self._nocolor_subcarrier:
self.chroma_from_luma(yiq, field, fieldno, self._subcarrier_amplitude_back)
Expand Down

0 comments on commit 8949c74

Please sign in to comment.