SMS: Some clean up and speed up

This commit is contained in:
alyosha-tas 2019-02-24 11:02:59 -06:00
parent 13152d670f
commit 7630be7e93
3 changed files with 76 additions and 88 deletions

View File

@ -90,8 +90,8 @@ namespace BizHawk.Emulation.Cores.Sega.GGHawkLink
* *
*/ */
L.PSG.generate_sound(1); L.PSG.generate_sound();
R.PSG.generate_sound(1); R.PSG.generate_sound();
int s_L = L.PSG.current_sample_L; int s_L = L.PSG.current_sample_L;
int s_R = L.PSG.current_sample_R; int s_R = L.PSG.current_sample_R;

View File

@ -38,6 +38,9 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem
} }
} }
// not savestated variables
int s_L, s_R;
public bool FrameAdvance(IController controller, bool render, bool rendersound) public bool FrameAdvance(IController controller, bool render, bool rendersound)
{ {
_controller = controller; _controller = controller;
@ -87,10 +90,11 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem
for (int j = 0; j < Vdp.IPeriod; j++) for (int j = 0; j < Vdp.IPeriod; j++)
{ {
Cpu.ExecuteOne(); Cpu.ExecuteOne();
PSG.generate_sound(1);
int s_L = PSG.current_sample_L; PSG.generate_sound();
int s_R = PSG.current_sample_R;
s_L = PSG.current_sample_L;
s_R = PSG.current_sample_R;
if (s_L != old_s_L) if (s_L != old_s_L)
{ {

View File

@ -171,11 +171,9 @@ namespace BizHawk.Emulation.Cores.Components
} }
} }
public void generate_sound(int cycles_to_do) public void generate_sound()
{ {
// there are 16 cpu cycles for every psg cycle // there are 16 cpu cycles for every psg cycle
for (int i = 0; i < cycles_to_do; i++)
{
psg_clock++; psg_clock++;
if (psg_clock == 16) if (psg_clock == 16)
@ -193,16 +191,11 @@ namespace BizHawk.Emulation.Cores.Components
noise_bit = noise.Bit(0); noise_bit = noise.Bit(0);
if (noise_type) if (noise_type)
{ {
int bit = (noise & 1) ^ ((noise >> 1) & 1); noise = (((noise & 1) ^ ((noise >> 1) & 1)) << 14) | (noise >> 1);
noise = noise >> 1;
noise |= bit << 14;
} }
else else
{ {
int bit = noise & 1; noise = ((noise & 1) << 14) | (noise >> 1);
noise = noise >> 1;
noise |= bit << 14;
} }
if (noise_rate == 0) if (noise_rate == 0)
@ -244,30 +237,21 @@ namespace BizHawk.Emulation.Cores.Components
} }
// now calculate the volume of each channel and add them together // now calculate the volume of each channel and add them together
// the magic number 42 is to make the volume comparable to the MSG volume current_sample_L = (A_L ? (A_up ? LogScale[Chan_vol[0]] * 42 : 0) : 0);
int v_L;
int v_R;
v_L = (A_L ? (A_up ? LogScale[Chan_vol[0]] * 42 : 0) : 0); current_sample_L += (B_L ? (B_up ? LogScale[Chan_vol[1]] * 42 : 0) : 0);
v_L += (B_L ? (B_up ? LogScale[Chan_vol[1]] * 42 : 0) : 0); current_sample_L += (C_L ? (C_up ? LogScale[Chan_vol[2]] * 42 : 0) : 0);
v_L += (C_L ? (C_up ? LogScale[Chan_vol[2]] * 42 : 0) : 0); current_sample_L += (noise_L ? (noise_bit ? LogScale[Chan_vol[3]] * 42 : 0) : 0);
v_L += (noise_L ? (noise_bit ? LogScale[Chan_vol[3]] * 42 : 0) : 0); current_sample_R = (A_R ? (A_up ? LogScale[Chan_vol[0]] * 42 : 0) : 0);
v_R = (A_R ? (A_up ? LogScale[Chan_vol[0]] * 42 : 0) : 0); current_sample_R += (B_R ? (B_up ? LogScale[Chan_vol[1]] * 42 : 0) : 0);
v_R += (B_R ? (B_up ? LogScale[Chan_vol[1]] * 42 : 0) : 0); current_sample_R += (C_R ? (C_up ? LogScale[Chan_vol[2]] * 42 : 0) : 0);
v_R += (C_R ? (C_up ? LogScale[Chan_vol[2]] * 42 : 0) : 0); current_sample_R += (noise_R ? (noise_bit ? LogScale[Chan_vol[3]] * 42 : 0) : 0);
v_R += (noise_R ? (noise_bit ? LogScale[Chan_vol[3]] * 42 : 0) : 0);
current_sample_L = v_L;
current_sample_R = v_R;
}
} }
} }
} }