fixed YM2612 reset on "soft reset"

small optimizations & fixes in FIR resampler code
This commit is contained in:
ekeeke31 2010-01-27 07:20:44 +00:00
parent f734e2fade
commit f44d38b537
5 changed files with 61 additions and 29 deletions

View File

@ -146,6 +146,7 @@ void gen_reset(uint32 hard_reset)
/* Reset CPUs */ /* Reset CPUs */
resetline = -1; resetline = -1;
gen_running = 1; gen_running = 1;
fm_reset(0);
m68k_pulse_reset(); m68k_pulse_reset();
z80_reset(); z80_reset();
} }
@ -214,8 +215,8 @@ void gen_reset_w(uint32 state)
} }
/* Reset Z80 & YM2612 */ /* Reset Z80 & YM2612 */
fm_reset(mcycles_68k);
z80_reset(); z80_reset();
fm_reset();
/* update Z80 bus status */ /* update Z80 bus status */
zstate &= 2; zstate &= 2;

View File

@ -53,7 +53,7 @@ static void gen_sinc(double rolloff, int width, double offset, double spacing, d
} }
} }
static int available( long input_count ) /*static int available( long input_count )
{ {
int cycle_count = input_count / input_per_cycle; int cycle_count = input_count / input_per_cycle;
int output_count = cycle_count * res * STEREO; int output_count = cycle_count * res * STEREO;
@ -74,6 +74,36 @@ static int available( long input_count )
} }
return output_count; return output_count;
} }
*/
int Fir_Resampler_avail()
{
long count = 0;
sample_t* in = buffer;
sample_t* end_pos = write_pos;
unsigned long skip = skip_bits >> imp_phase;
int remain = res - imp_phase;
if ( end_pos - in >= WIDTH * STEREO )
{
end_pos -= WIDTH * STEREO;
do
{
count++;
remain--;
in += (skip * STEREO) & STEREO;
skip >>= 1;
in += step;
if ( !remain )
{
skip = skip_bits;
remain = res;
}
}
while ( in <= end_pos );
}
return count;
}
int Fir_Resampler_initialize( int new_size ) int Fir_Resampler_initialize( int new_size )
{ {
@ -191,10 +221,10 @@ int Fir_Resampler_written( void )
} }
/* Number of output samples available */ /* Number of output samples available */
int Fir_Resampler_avail( void ) /*int Fir_Resampler_avail( void )
{ {
return available( write_pos - &buffer [WIDTH * STEREO] ); return available( write_pos - &buffer [WIDTH * STEREO] );
} }*/
void Fir_Resampler_write( long count ) void Fir_Resampler_write( long count )
{ {
@ -274,13 +304,14 @@ int Fir_Resampler_read( sample_t* out, long count )
return out - out_; return out - out_;
} }
/* fixed (Eke_Eke) */
int Fir_Resampler_input_needed( long output_count ) int Fir_Resampler_input_needed( long output_count )
{ {
long input_count = 0; long input_count = 0;
unsigned long skip = skip_bits >> imp_phase; unsigned long skip = skip_bits >> imp_phase;
int remain = res - imp_phase; int remain = res - imp_phase;
while ( (output_count) > 0 ) /* fixed (Eke_Eke) */ while ( (output_count) > 0 )
{ {
input_count += step + (skip & 1) * STEREO; input_count += step + (skip & 1) * STEREO;
skip >>= 1; skip >>= 1;
@ -289,13 +320,13 @@ int Fir_Resampler_input_needed( long output_count )
skip = skip_bits; skip = skip_bits;
remain = res; remain = res;
} }
output_count -= 2; output_count --;
} }
long input_extra = input_count - (write_pos - &buffer [WRITE_OFFSET]); long input_extra = input_count - (write_pos - &buffer [WRITE_OFFSET]);
if ( input_extra < 0 ) if ( input_extra < 0 )
input_extra = 0; input_extra = 0;
return input_extra; return (input_extra >> 1);
} }
int Fir_Resampler_skip_input( long count ) int Fir_Resampler_skip_input( long count )

View File

@ -148,7 +148,7 @@ void sound_init(void)
Fir_Resampler_time_ratio(mclk / (double)snd.sample_rate / (144.0 * 7.0)); Fir_Resampler_time_ratio(mclk / (double)snd.sample_rate / (144.0 * 7.0));
} }
#ifdef LOG_SOUND #ifdef LOGSOUND
error("%d mcycles per PSG samples\n", psg_cycles_ratio); error("%d mcycles per PSG samples\n", psg_cycles_ratio);
error("%d mcycles per FM samples\n", fm_cycles_ratio); error("%d mcycles per FM samples\n", fm_cycles_ratio);
#endif #endif
@ -172,26 +172,26 @@ int sound_update(unsigned int cycles)
/* number of available samples */ /* number of available samples */
int size = snd.psg.pos - snd.psg.buffer; int size = snd.psg.pos - snd.psg.buffer;
#ifdef LOG_SOUND #ifdef LOGSOUND
error("%d PSG samples available\n",snd.psg.pos - snd.psg.buffer); error("%d PSG samples available\n",size);
#endif #endif
/* FM resampling */ /* FM resampling */
if (config.hq_fm) if (config.hq_fm)
{ {
/* resynchronize FM & PSG chips */
int remain = Fir_Resampler_input_needed(size << 1) >> 1;
/* get remaining FM samples */ /* get remaining FM samples */
int remain = Fir_Resampler_input_needed(size);
if (remain > 0) if (remain > 0)
{ {
/* resynchronize FM & PSG chips */
YM2612Update(Fir_Resampler_buffer(), remain); YM2612Update(Fir_Resampler_buffer(), remain);
Fir_Resampler_write(remain << 1); Fir_Resampler_write(remain << 1);
} }
fm_cycles_count = psg_cycles_count; fm_cycles_count = psg_cycles_count;
#ifdef LOG_SOUND #ifdef LOGSOUND
error("%d FM samples available\n",Fir_Resampler_written() >> 1); error("%d FM samples available\n",Fir_Resampler_written() >> 1);
#endif #endif
} }
@ -200,21 +200,21 @@ int sound_update(unsigned int cycles)
/* run FM chip until end of frame */ /* run FM chip until end of frame */
fm_update(cycles); fm_update(cycles);
#ifdef LOG_SOUND #ifdef LOGSOUND
error("%d FM samples available\n",(snd.fm.pos - snd.fm.buffer)>>1); error("%d FM samples available\n",(snd.fm.pos - snd.fm.buffer)>>1);
#endif #endif
} }
#ifdef LOG_SOUND #ifdef LOGSOUND
error("%lu PSG cycles run\n",psg_cycles_count); error("%lu PSG cycles run\n",psg_cycles_count);
error("%lu FM cycles run \n",fm_cycles_count); error("%lu FM cycles run \n",fm_cycles_count);
#endif #endif
/* adjust PSG & FM cycle counts */ /* adjust PSG & FM cycle counts */
psg_cycles_count -= (cycles << 11); psg_cycles_count -= (cycles << 11);
fm_cycles_count -= (cycles << 11); fm_cycles_count -= (cycles << 11);
#ifdef LOG_SOUND #ifdef LOGSOUND
error("%lu PSG cycles left\n",psg_cycles_count); error("%lu PSG cycles left\n",psg_cycles_count);
error("%lu FM cycles left\n",fm_cycles_count); error("%lu FM cycles left\n",fm_cycles_count);
#endif #endif
@ -222,10 +222,10 @@ int sound_update(unsigned int cycles)
return size; return size;
} }
/* Reset FM chip during 68k execution */ /* Reset FM chip */
void fm_reset(void) void fm_reset(unsigned int cycles)
{ {
fm_update(mcycles_68k); fm_update(cycles);
YM2612ResetChip(); YM2612ResetChip();
} }

View File

@ -28,7 +28,7 @@
extern void sound_init(void); extern void sound_init(void);
extern void sound_reset(void); extern void sound_reset(void);
extern int sound_update(unsigned int cycles); extern int sound_update(unsigned int cycles);
extern void fm_reset(void); extern void fm_reset(unsigned int cycles);
extern void fm_write(unsigned int cycles, unsigned int address, unsigned int data); extern void fm_write(unsigned int cycles, unsigned int address, unsigned int data);
extern unsigned int fm_read(unsigned int cycles, unsigned int address); extern unsigned int fm_read(unsigned int cycles, unsigned int address);
extern void psg_write(unsigned int cycles, unsigned int data); extern void psg_write(unsigned int cycles, unsigned int data);

View File

@ -84,7 +84,7 @@ int audio_update (void)
/* resample into FM output buffer */ /* resample into FM output buffer */
Fir_Resampler_read(fm,size); Fir_Resampler_read(fm,size);
#ifdef LOG_SOUND #ifdef LOGSOUND
error("%d FM samples remaining\n",Fir_Resampler_written() >> 1); error("%d FM samples remaining\n",Fir_Resampler_written() >> 1);
#endif #endif
} }
@ -93,7 +93,7 @@ int audio_update (void)
/* adjust remaining samples in FM output buffer*/ /* adjust remaining samples in FM output buffer*/
snd.fm.pos -= (size << 1); snd.fm.pos -= (size << 1);
#ifdef LOG_SOUND #ifdef LOGSOUND
error("%d FM samples remaining\n",(snd.fm.pos - snd.fm.buffer)>>1); error("%d FM samples remaining\n",(snd.fm.pos - snd.fm.buffer)>>1);
#endif #endif
} }
@ -101,7 +101,7 @@ int audio_update (void)
/* adjust remaining samples in PSG output buffer*/ /* adjust remaining samples in PSG output buffer*/
snd.psg.pos -= size; snd.psg.pos -= size;
#ifdef LOG_SOUND #ifdef LOGSOUND
error("%d PSG samples remaining\n",snd.psg.pos - snd.psg.buffer); error("%d PSG samples remaining\n",snd.psg.pos - snd.psg.buffer);
#endif #endif
@ -155,7 +155,7 @@ int audio_update (void)
memcpy(snd.fm.buffer, fm, (snd.fm.pos - snd.fm.buffer) << 1); memcpy(snd.fm.buffer, fm, (snd.fm.pos - snd.fm.buffer) << 1);
memcpy(snd.psg.buffer, psg, (snd.psg.pos - snd.psg.buffer) << 1); memcpy(snd.psg.buffer, psg, (snd.psg.pos - snd.psg.buffer) << 1);
#ifdef LOG_SOUND #ifdef LOGSOUND
error("%d samples returned\n\n",size); error("%d samples returned\n\n",size);
#endif #endif
@ -398,7 +398,7 @@ int system_frame (int do_skip)
if (line == vdp_height) if (line == vdp_height)
{ {
/* render overscan */ /* render overscan */
if (line < end_line) if (!do_skip && (line < end_line))
render_line(line, 1); render_line(line, 1);
/* update inputs (doing this here fix Warriors of Eternal Sun) */ /* update inputs (doing this here fix Warriors of Eternal Sun) */
@ -439,7 +439,7 @@ int system_frame (int do_skip)
else else
{ {
/* render overscan */ /* render overscan */
if ((line < end_line) || (line >= start_line)) if (!do_skip && ((line < end_line) || (line >= start_line)))
render_line(line, 1); render_line(line, 1);
/* clear any pending Z80 interrupt */ /* clear any pending Z80 interrupt */