. adjusted synchronization between PSG & FM cores (better avoid generating additional samples)

This commit is contained in:
ekeeke31 2012-04-08 17:54:02 +00:00
parent 39dc73d406
commit 868f14dc44
3 changed files with 18 additions and 14 deletions

View File

@ -325,7 +325,7 @@ int SN76489_Update(INT16 *buffer, int clock_length)
return blip_read_samples(blip, buffer);
}
int SN76489_Sync(unsigned int samples)
int SN76489_Clocks(int length)
{
return blip_clocks_needed(blip, samples);
}
return blip_clocks_needed(blip, length);
}

View File

@ -17,6 +17,7 @@ extern uint8 *SN76489_GetContextPtr(void);
extern int SN76489_GetContextSize(void);
extern void SN76489_Write(int data);
extern int SN76489_Update(INT16 *buffer, int clock_length);
extern int SN76489_Sync(unsigned int samples);
extern int SN76489_Clocks(int length);
extern void SN76489_BoostNoise(int boost);
#endif /* _SN76489_H_ */

View File

@ -271,14 +271,14 @@ int sound_context_load(uint8 *state)
/* End of frame update, return the number of samples run so far. */
int sound_update(unsigned int cycles)
{
int size, delta;
int size, avail;
/* run PSG & FM chips until end of frame */
cycles <<= 11;
psg_update(cycles);
fm_update(cycles);
/* return available FM samples */
/* check number of available FM samples */
if (config.hq_fm)
{
size = Fir_Resampler_avail();
@ -291,22 +291,25 @@ int sound_update(unsigned int cycles)
error("%d FM samples available\n",size);
#endif
/* compare with number of PSG samples available */
delta = size - (snd.psg.pos - snd.psg.buffer);
/* check number of available PSG samples */
avail = snd.psg.pos - snd.psg.buffer;
#ifdef LOGSOUND
error("%d PSG samples available\n", snd.psg.pos - snd.psg.buffer);
error("%d PSG samples available\n", avail);
#endif
/* resynchronize FM & PSG chips */
if (delta > 0)
if (size > avail)
{
/* PSG chip is late, get needed samples */
snd.psg.pos += SN76489_Update(snd.psg.pos, SN76489_Sync(delta));
/* FM chip is ahead */
fm_cycles_count += SN76489_Clocks(size - avail) * psg_cycles_ratio;
/* return number of available samples */
size = avail;
}
else
{
/* PSG chip is ahead, adjust clocks count */
psg_cycles_count += (SN76489_Sync(-delta) * psg_cycles_ratio);
/* PSG chip is ahead */
psg_cycles_count += SN76489_Clocks(avail - size) * psg_cycles_ratio;
}
#ifdef LOGSOUND