Skip to content

Commit

Permalink
Fix bug where field was not recoverable due to noise
Browse files Browse the repository at this point in the history
If CRT_DO_VSYNC was disabled and the noise was high, the field was being incorrectly determined since it was still scanning the noisy signal to find out which field it is. This patch makes it so if CRT_DO_VSYNC is disabled, the field is determined before noise is added to the signal.
  • Loading branch information
LMP88959 authored Oct 18, 2023
1 parent 79ceb94 commit 1eb49fd
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions crt_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,26 @@ crt_demodulate(struct CRT *v, int noise)
huecs >>= 11;

rn = v->rn;
#if !CRT_DO_VSYNC
/* determine field before we add noise,
* otherwise it's not reliably recoverable
*/
for (i = -CRT_VSYNC_WINDOW; i < CRT_VSYNC_WINDOW; i++) {
line = POSMOD(v->vsync + i, CRT_VRES);
sig = v->analog + line * CRT_HRES;
s = 0;
for (j = 0; j < CRT_HRES; j++) {
s += sig[j];
if (s <= (CRT_VSYNC_THRESH * SYNC_LEVEL)) {
goto found_field;
}
}
}
found_field:
/* if vsync signal was in second half of line, odd field */
field = (j > (CRT_HRES / 2));
v->vsync = -3;
#endif
#if ((CRT_SYSTEM == CRT_SYSTEM_NTSCVHS) && CRT_VHS_NOISE)
line = ((rand() % 8) - 4) + 14;
#endif
Expand All @@ -346,6 +366,7 @@ crt_demodulate(struct CRT *v, int noise)
}
v->rn = rn;

#if CRT_DO_VSYNC
/* Look for vertical sync.
*
* This is done by integrating the signal and
Expand All @@ -370,13 +391,11 @@ crt_demodulate(struct CRT *v, int noise)
}
}
vsync_found:
#if CRT_DO_VSYNC
v->vsync = line; /* vsync found (or gave up) at this line */
#else
v->vsync = -3;
#endif
/* if vsync signal was in second half of line, odd field */
field = (j > (CRT_HRES / 2));
#endif

#if CRT_DO_BLOOM
max_e = (128 + (noise / 2)) * AV_LEN;
prev_e = (16384 / 8);
Expand Down

0 comments on commit 1eb49fd

Please sign in to comment.