|
From: <sba...@us...> - 2023-10-01 06:41:59
|
This is an automated email from the git hooks/post-receive-user script. sbaldovi pushed a commit to branch patches-142-currah-uspeech in repository fuse. View the commit online: https://sourceforge.net/p/fuse-emulator/fuse/ci/0302d3b972810d37d74f9adf03e7ccf56a1b441f/ commit 0302d3b972810d37d74f9adf03e7ccf56a1b441f Author: Sergio Baldoví <ser...@gm...> AuthorDate: Tue Sep 26 05:35:26 2023 +0200 Avoid the use of 64-bit integers We don't need an ever increasing tstate counter. Decrease it at the end of spectrum frames. --- peripherals/sound/sp0256.c | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/peripherals/sound/sp0256.c b/peripherals/sound/sp0256.c index 222d8595..979fdb2b 100644 --- a/peripherals/sound/sp0256.c +++ b/peripherals/sound/sp0256.c @@ -76,9 +76,6 @@ #define FIFO_ADDR ( 0x1800 << 3 ) /* SP0256 address of speech FIFO. */ -uint64_t sp0256_tstates; -uint64_t sp0256_now; - typedef struct lpc12_t { int rpt, cnt; /* Repeat counter, Period down-counter. */ uint32_t per, rng; /* Period, Amplitude, Random Number Generator */ @@ -98,7 +95,7 @@ typedef struct sp0256_t { int16_t *scratch; /* Scratch buffer for audio. */ uint32_t sc_head; /* Head/Tail pointer into scratch circular buf */ uint32_t sc_tail; /* Head/Tail pointer into scratch circular buf */ - uint64_t sound_current; + int32_t sound_current; lpc12_t filt; /* 12-pole filter */ int lrq; /* Load ReQuest. == 0 if we can accept a load */ @@ -1136,10 +1133,9 @@ sp0256_micro( sp0256_t *s ) static uint32_t sp0256_run( sp0256_t *s, uint32_t len ) { - /* TODO: use 32-bit types only */ - uint64_t until = sp0256_now + len; + int32_t sp0256_now = s->sound_current; + int32_t until = sp0256_now + len; int samples, did_samp, old_idx; - int n = 0; /* -------------------------------------------------------------------- */ /* If the rest of the machine hasn't caught up to us, just return. */ @@ -1212,10 +1208,9 @@ sp0256_run( sp0256_t *s, uint32_t len ) if( did_samp ) { int i; for( i = 0; i < did_samp; i++ ) { - sound_sp0256_write( sp0256_tstates + ( ( n + i ) * s->clock_per_samp ), + sound_sp0256_write( s->sound_current + ( i * s->clock_per_samp ), s->scratch[( i + old_idx ) & SCBUF_MASK] ); } - n += did_samp; } s->sound_current += did_samp * s->clock_per_samp; @@ -1448,17 +1443,16 @@ sp0256_end() } static void -sp0256_run_to( sp0256_t *s, uint64_t t ) +sp0256_run_to( sp0256_t *s, libspectrum_dword t ) { - int64_t periph_step; + uint32_t periph_step; + + while( s->sound_current < (int32_t) t ) { + int32_t len = t - s->sound_current; + if( len > 14934 ) len = 14934; - while( sp0256_tstates < t ) { - int64_t n = t - sp0256_tstates; - if( n > 14934 ) n = 14934; + periph_step = sp0256_run( s, len ); - periph_step = sp0256_run( s, n ); - sp0256_tstates += abs( periph_step ); - sp0256_now += abs( periph_step ); if( !periph_step ) { return; } @@ -1471,7 +1465,8 @@ sp0256_do_frame( void ) /* No op if it wasn't initialised yet */ if( !sp0256.scratch ) return; sp0256_run_to( &sp0256, machine_current->timings.tstates_per_frame ); - sp0256_tstates -= machine_current->timings.tstates_per_frame; + + sp0256.sound_current -= machine_current->timings.tstates_per_frame; } void |