diff --git a/src/extra/NTSC-CRT/crt_core.c b/src/extra/NTSC-CRT/crt_core.c index 844a25a94..34e7cb0ab 100644 --- a/src/extra/NTSC-CRT/crt_core.c +++ b/src/extra/NTSC-CRT/crt_core.c @@ -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 @@ -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 @@ -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); diff --git a/src/extra/NTSC-CRT/crt_core.h b/src/extra/NTSC-CRT/crt_core.h index a77b24eed..4df5e6369 100644 --- a/src/extra/NTSC-CRT/crt_core.h +++ b/src/extra/NTSC-CRT/crt_core.h @@ -24,7 +24,7 @@ extern "C" { /* library version */ #define CRT_MAJOR 2 #define CRT_MINOR 3 -#define CRT_PATCH 0 +#define CRT_PATCH 1 #define CRT_SYSTEM_NTSC 0 /* standard NTSC */ diff --git a/src/extra/PAL-CRT/README.md b/src/extra/PAL-CRT/README.md index fea6de060..216d87a4d 100644 --- a/src/extra/PAL-CRT/README.md +++ b/src/extra/PAL-CRT/README.md @@ -154,6 +154,13 @@ pal_demodulate(&crt, noise); field++; ``` +------ + +### Emulators +These emulators have this PAL filter as an option: +puNES: https://github.com/punesemu/puNES +BeesNES: https://github.com/L-Spiro/BeesNES + ------ If you have any questions feel free to leave a comment on YouTube OR join the King's Crook Discord server :) diff --git a/src/extra/PAL-CRT/pal_core.c b/src/extra/PAL-CRT/pal_core.c index d8587a8d2..5d9153359 100644 --- a/src/extra/PAL-CRT/pal_core.c +++ b/src/extra/PAL-CRT/pal_core.c @@ -305,6 +305,26 @@ pal_demodulate(struct PAL_CRT *c, int noise) pitch = c->outw * bpp; rn = c->rn; +#if !PAL_DO_VSYNC + /* determine field before we add noise, + * otherwise it's not reliably recoverable + */ + for (i = -VSYNC_WINDOW; i < VSYNC_WINDOW; i++) { + line = POSMOD(c->vsync + i, PAL_VRES); + sig = c->analog + line * PAL_HRES; + s = 0; + for (j = 0; j < PAL_HRES; j++) { + s += sig[j]; + if (s <= (125 * SYNC_LEVEL)) { + goto found_field; + } + } + } +found_field: + /* if vsync signal was in second half of line, odd field */ + field = (j > (PAL_HRES / 2)); + c->vsync = -3; +#endif for (i = 0; i < PAL_INPUT_SIZE; i++) { rn = (214019 * rn + 140327895); @@ -315,7 +335,7 @@ pal_demodulate(struct PAL_CRT *c, int noise) c->inp[i] = s; } c->rn = rn; - +#if PAL_DO_VSYNC /* Look for vertical sync. * * This is done by integrating the signal and @@ -340,13 +360,10 @@ pal_demodulate(struct PAL_CRT *c, int noise) } } vsync_found: -#if PAL_DO_VSYNC c->vsync = line; /* vsync found (or gave up) at this line */ -#else - c->vsync = -3; -#endif /* if vsync signal was in second half of line, odd field */ field = (j > (PAL_HRES / 2)); +#endif #if PAL_DO_BLOOM max_e = (128 + (noise / 2)) * AV_LEN; diff --git a/src/extra/PAL-CRT/pal_core.h b/src/extra/PAL-CRT/pal_core.h index 988ff8bf4..f1abfe3a3 100644 --- a/src/extra/PAL-CRT/pal_core.h +++ b/src/extra/PAL-CRT/pal_core.h @@ -26,7 +26,7 @@ extern "C" { /* library version */ #define PAL_MAJOR 1 #define PAL_MINOR 2 -#define PAL_PATCH 0 +#define PAL_PATCH 1 #define PAL_SYSTEM_PAL 0 /* 'standard' PAL */ #define PAL_SYSTEM_NES 1 /* decode 6 or 9-bit NES pixels */