aboutsummaryrefslogtreecommitdiff
path: root/source/nds
diff options
context:
space:
mode:
authorNebuleon Fumika2013-02-01 18:27:03 -0500
committerNebuleon Fumika2013-02-01 18:27:03 -0500
commit30fe9eaf6ab8b0701419949a4415736675d15377 (patch)
tree1209039b2d19ef7099686b3420ea9bba8855d3aa /source/nds
parent58948ffd1d05084f3d84bc12a2e75144741b292c (diff)
downloadsnes9x2005-30fe9eaf6ab8b0701419949a4415736675d15377.tar.gz
snes9x2005-30fe9eaf6ab8b0701419949a4415736675d15377.tar.bz2
snes9x2005-30fe9eaf6ab8b0701419949a4415736675d15377.zip
While killing time between frames, process audio instead of doing nothing. Also correctly fill the buffer with silence when returning from pause. This reduces or eliminates crackling.
The emulator kills time in two circumstances: * In automatic frameskip mode, without fast forwarding, the emulator kills time if it rendered a frame early. * In manual frameskip mode, without fast forwarding, the emulator kills time to wait for the next rendered frame.
Diffstat (limited to 'source/nds')
-rw-r--r--source/nds/entry.cpp37
1 files changed, 24 insertions, 13 deletions
diff --git a/source/nds/entry.cpp b/source/nds/entry.cpp
index c0c8efa..a55c10d 100644
--- a/source/nds/entry.cpp
+++ b/source/nds/entry.cpp
@@ -675,12 +675,13 @@ void S9xSyncSpeed ()
else // Early
{
skip_rate = 0;
- ds2_setCPUclocklevel(0);
if (syncdif > 0)
- // TODO Turn this delay into a ProcessSound loop?
- udelay(syncdif * 128 / 3 /* times 42 + 2/3 microseconds */);
- set_cpu_clock(clock_speed_number);
- S9xProcessSound (0);
+ {
+ do {
+ S9xProcessSound (0);
+ syncdif = sync_next - getSysTime();
+ } while (syncdif > 0);
+ }
IPPU.RenderThisFrame = TRUE;
sync_next += frame_time;
@@ -709,11 +710,10 @@ void S9xSyncSpeed ()
syncdif = sync_next - syncnow;
if (syncdif > 0)
{
- ds2_setCPUclocklevel(0);
- // TODO Turn this delay into a ProcessSound loop?
- udelay(syncdif * 128 / 3 /* times 42 + 2/3 microseconds */);
- set_cpu_clock(clock_speed_number);
- S9xProcessSound (0);
+ do {
+ S9xProcessSound (0);
+ syncdif = sync_next - getSysTime();
+ } while (syncdif > 0);
// After that little delay, what time is it?
syncnow = getSysTime();
}
@@ -910,8 +910,6 @@ unsigned int LastSoundEmissionTime = 0;
void S9xProcessSound (unsigned int)
{
- unsigned short *audiobuff;
-
if (so.mute_sound || !game_enable_audio)
return;
@@ -921,6 +919,8 @@ void S9xProcessSound (unsigned int)
return;
}
+ unsigned short *audiobuff;
+
unsigned int Now = getSysTime();
if (Now - LastSoundEmissionTime >= SOUND_EMISSION_INTERVAL)
{
@@ -933,7 +933,18 @@ void S9xProcessSound (unsigned int)
audiobuff = (unsigned short*)ds2_getAudiobuff();
} while (audiobuff == NULL); //There are audio queue in sending or wait to send
- memset(audiobuff, 0, DS2_BUFFER_SIZE);
+ memset(audiobuff, 0, DS2_BUFFER_SIZE
+#ifndef FOREVER_STEREO
+ << (so.stereo ? 1 : 0)
+#else
+ << 1
+#endif
+#ifndef FOREVER_16_BIT_SOUND
+ << (so.sixteen_bit ? 1 : 0)
+#else
+ << 1
+#endif
+ );
ds2_updateAudio();
// And then the real audio. (fall through)