sound, increase resolution for calculating psg sound

This commit is contained in:
kub 2021-10-02 09:32:57 +02:00
parent eb3b1f9d72
commit 86d6fb9a2f
3 changed files with 27 additions and 22 deletions

View file

@ -394,13 +394,11 @@ void NOINLINE ctl_write_z80reset(u32 d)
}
}
static int get_scanline(int is_from_z80);
static void psg_write_68k(u32 d)
{
// look for volume write and update if needed
if ((d & 0x90) == 0x90)
PsndDoPSG(Pico.m.scanline);
PsndDoPSG(z80_cycles_from_68k());
SN76496Write(d);
}
@ -408,8 +406,7 @@ static void psg_write_68k(u32 d)
static void psg_write_z80(u32 d)
{
if ((d & 0x90) == 0x90) {
int scanline = get_scanline(1);
PsndDoPSG(scanline);
PsndDoPSG(z80_cyclesDone());
}
SN76496Write(d);

View file

@ -914,9 +914,9 @@ PICO_INTERNAL void PsndExit(void);
PICO_INTERNAL void PsndReset(void);
PICO_INTERNAL void PsndStartFrame(void);
PICO_INTERNAL void PsndDoDAC(int cycle_to);
PICO_INTERNAL void PsndDoPSG(int line_to);
PICO_INTERNAL void PsndDoYM2413(int line_to);
PICO_INTERNAL void PsndDoFM(int line_to);
PICO_INTERNAL void PsndDoPSG(int cyc_to);
PICO_INTERNAL void PsndDoYM2413(int cyc_to);
PICO_INTERNAL void PsndDoFM(int cyc_to);
PICO_INTERNAL void PsndClear(void);
PICO_INTERNAL void PsndGetSamples(int y);
PICO_INTERNAL void PsndGetSamplesMS(int y);

View file

@ -161,20 +161,24 @@ PICO_INTERNAL void PsndDoDAC(int cyc_to)
Pico.snd.dac_val = dout;
}
PICO_INTERNAL void PsndDoPSG(int line_to)
PICO_INTERNAL void PsndDoPSG(int cyc_to)
{
int pos, len;
int stereo = 0;
// Q16, number of samples since last call
len = ((line_to+1) * Pico.snd.smpl_mult) - Pico.snd.psg_pos;
if (len <= 0)
return;
// number of samples to fill in buffer (Q20)
len = (cyc_to * Pico.snd.clkl_mult) - Pico.snd.psg_pos;
// update position and calculate buffer offset and length
pos = (Pico.snd.psg_pos+0x8000) >> 16;
pos = (Pico.snd.psg_pos+0x80000) >> 20;
Pico.snd.psg_pos += len;
len = ((Pico.snd.psg_pos+0x8000) >> 16) - pos;
len = ((Pico.snd.psg_pos+0x80000) >> 20) - pos;
// avoid loss of the 1st sample of a new block (Q rounding issues)
if (pos+len == 0)
len = 1, Pico.snd.psg_pos += 0x80000;
if (len <= 0)
return;
if (!PicoIn.sndOut || !(PicoIn.opt & POPT_EN_PSG))
return;
@ -187,21 +191,25 @@ PICO_INTERNAL void PsndDoPSG(int line_to)
}
#if 0
PICO_INTERNAL void PsndDoYM2413(int line_to)
PICO_INTERNAL void PsndDoYM2413(int cyc_to)
{
int pos, len;
int stereo = 0;
short *buf;
// Q16, number of samples since last call
len = ((line_to+1) * Pico.snd.smpl_mult) - Pico.snd.ym2413_pos;
if (len <= 0)
return;
// number of samples to fill in buffer (Q20)
len = (cyc_to * Pico.snd.clkl_mult) - Pico.snd.ym2413_pos;
// update position and calculate buffer offset and length
pos = (Pico.snd.ym2413_pos+0x8000) >> 16;
pos = (Pico.snd.ym2413_pos+0x80000) >> 20;
Pico.snd.ym2413_pos += len;
len = ((Pico.snd.ym2413_pos+0x8000) >> 16) - pos;
len = ((Pico.snd.ym2413_pos+0x80000) >> 20) - pos;
// avoid loss of the 1st sample of a new block (Q rounding issues)
if (pos+len == 0)
len = 1, Pico.snd.ym2413_pos += 0x80000;
if (len <= 0)
return;
if (!PicoIn.sndOut || !(PicoIn.opt & POPT_EN_YM2413))
return;