Skip to content

Commit

Permalink
Updated LMP88959 filters.
Browse files Browse the repository at this point in the history
  • Loading branch information
punesemu committed Nov 3, 2023
1 parent c2168f6 commit 353a412
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 11 deletions.
27 changes: 23 additions & 4 deletions src/extra/NTSC-CRT/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
2 changes: 1 addition & 1 deletion src/extra/NTSC-CRT/crt_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
7 changes: 7 additions & 0 deletions src/extra/PAL-CRT/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 :)
Expand Down
27 changes: 22 additions & 5 deletions src/extra/PAL-CRT/pal_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/extra/PAL-CRT/pal_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 353a412

Please sign in to comment.