Skip to content

Commit

Permalink
Fix eventcycles, add SPU Samples, allows much better performance
Browse files Browse the repository at this point in the history
EventCycles should work up to 2048 now, now that it is used by MDEC and Timer

SPU samples option was added, audio glitches will occur in some games unless samples is 1
  • Loading branch information
ZachCook authored and LibretroAdmin committed Nov 20, 2022
1 parent ec4d708 commit 798fab9
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 15 deletions.
10 changes: 10 additions & 0 deletions libretro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ int memfd;
#endif

uint32 EventCycles = 128;
uint8_t spu_samples = 1;

// CPU overclock factor (or 0 if disabled)
int32_t psx_overclock_factor = 0;
Expand Down Expand Up @@ -3200,6 +3201,15 @@ static void check_variables(bool startup)
}
else
EventCycles = 128;

var.key = BEETLE_OPT(dynarec_spu_samples);

if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
spu_samples = atoi(var.value);
}
else
spu_samples = 1;
#endif

var.key = BEETLE_OPT(cpu_freq_scale);
Expand Down
28 changes: 20 additions & 8 deletions libretro_core_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -1102,24 +1102,36 @@ struct retro_core_option_v2_definition option_defs_us[] = {
},
{
BEETLE_OPT(dynarec_eventcycles),
"Dynarec DMA/GPU Event Cycles",
NULL,
"Max cycles run by CPU before a GPU or DMA Update is checked, higher number will be faster, has much less impact on beetle interpreter than dynarec.",
"Dynarec DMA/GPU/MDEC/Timer Event Cycles",
NULL,
"Max cycles run by CPU before a GPU/DMA/MDEC/Timer Update is checked, higher number will be faster, has much less impact on beetle interpreter than dynarec.",
NULL,
"hacks",
{
{ "128", NULL },
{ "128", "128 (Default)" },
{ "256", NULL },
{ "384", NULL },
{ "512", NULL },
{ "640", NULL },
{ "768", NULL },
{ "896", NULL },
{ "1024", NULL },
{ "2048", NULL },
{ NULL, NULL },
},
"128"
},
{
BEETLE_OPT(dynarec_spu_samples),
"Dynarec SPU Samples",
NULL,
"Max SPU samples to run before a SPU Update is checked, higher number will be faster, but will cause sound glitches in some games with anything other than 1.",
NULL,
"hacks",
{
{ "1", "1 (Default)" },
{ "4", NULL },
{ "16", NULL },
{ NULL, NULL },
},
"1"
},
#endif
{
BEETLE_OPT(core_timing_fps),
Expand Down
6 changes: 4 additions & 2 deletions mednafen/psx/mdec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ static const uint8 ZigZag[64] =
0x2e, 0x27, 0x2f, 0x36, 0x3d, 0x3e, 0x37, 0x3f,
};

extern int32 EventCycles;

void MDEC_Power(void)
{
ClockCounter = 0;
Expand Down Expand Up @@ -527,11 +529,11 @@ void MDEC_Run(int32 clocks)

ClockCounter += clocks;

if(ClockCounter > 128)
if(ClockCounter > EventCycles)
{
//if(MDRPhase != 0)
// printf("SNORT: %d\n", ClockCounter);
ClockCounter = 128;
ClockCounter = EventCycles;
}

switch(MDRPhase + MDRPhaseBias)
Expand Down
9 changes: 5 additions & 4 deletions mednafen/psx/spu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
uint32_t IntermediateBufferPos;
int16_t IntermediateBuffer[4096][2];

extern uint8_t spu_samples;

static const int16 FIR_Table[256][4] =
{
Expand Down Expand Up @@ -746,8 +747,8 @@ int32 PS_SPU::UpdateFromCDC(int32 clocks)

while(clock_divider <= 0)
{
clock_divider += 768;
sample_clocks++;
clock_divider += spu_samples*768;
sample_clocks += spu_samples;
}

while(sample_clocks > 0)
Expand Down Expand Up @@ -1451,8 +1452,8 @@ int PS_SPU::StateAction(StateMem *sm, int load, int data_only)
Voices[i].LoopAddr &= 0x3FFFF;
}

if(clock_divider <= 0 || clock_divider > 768)
clock_divider = 768;
if(clock_divider <= 0 || clock_divider > spu_samples*768)
clock_divider = spu_samples*768;

RWAddr &= 0x3FFFF;
CWA &= 0x1FF;
Expand Down
4 changes: 3 additions & 1 deletion mednafen/psx/timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,11 @@ static bool hretrace;
static Timer Timers[3];
static int32_t lastts;

extern int32 EventCycles;

static uint32_t CalcNextEvent(void)
{
int32_t next_event = 1024; /**/
int32_t next_event = 8*EventCycles; /**/

unsigned i;
for(i = 0; i < 3; i++)
Expand Down

0 comments on commit 798fab9

Please sign in to comment.